This commit is contained in:
zhaotiantian
2023-12-04 13:59:23 +08:00
5 changed files with 61 additions and 37 deletions
+2
View File
@@ -0,0 +1,2 @@
// 王昊地址
VITE_GLOB_API_URL=http://192.168.1.16
+3
View File
@@ -0,0 +1,3 @@
VITE_GLOB_API_URL=http://cqyt.dev.yg.dt.io
+23 -16
View File
@@ -1,25 +1,32 @@
import axios from "axios"; import axios from 'axios';
import requestURL from './url'; import requestURL from './url';
let token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWRlbnRpZmllciI6ImU5Y2EyM2Q2OGQ4ODRkNGViYjE5ZDA3ODg5NzI3ZGFlIiwiZXhwIjoxNzAyMDA1MDQ4fQ.M1Xlecj3eUOgZUSofOlyBMoxJ5F01KH-tgJxaV2Femc\n' import { getAppEnvConfig } from '../utils/env.ts';
const { VITE_GLOB_API_URL } = getAppEnvConfig();
let token =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWRlbnRpZmllciI6ImU5Y2EyM2Q2OGQ4ODRkNGViYjE5ZDA3ODg5NzI3ZGFlIiwiZXhwIjoxNzAyMDA1MDQ4fQ.M1Xlecj3eUOgZUSofOlyBMoxJ5F01KH-tgJxaV2Femc\n';
const service = axios.create({ const service = axios.create({
baseURL: requestURL, baseURL: VITE_GLOB_API_URL,
timeout: 50000, timeout: 50000,
headers: { headers: {
// 设置后端需要的传参类型 // 设置后端需要的传参类型
'Content-Type': 'application/json;charset=UTF-8', 'Content-Type': 'application/json;charset=UTF-8',
'X-Access-Token':token 'X-Access-Token': token,
} },
}) });
export const get = (url, params) => { export const get = (url, params) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
service.get(url, {params: params}).then(res => { service
if (res.data.code === 200) { .get(url, { params: params })
resolve(res.data); .then((res) => {
} else { if (res.data.code === 200) {
reject(res.data); resolve(res.data);
} } else {
}).catch(err => { reject(res.data);
reject(err.data); }
}) })
.catch((err) => {
reject(err.data);
});
}); });
} };
+7
View File
@@ -0,0 +1,7 @@
export function getAppEnvConfig() {
const ENV = import.meta.env;
const { VITE_GLOB_API_URL } = ENV;
return {
VITE_GLOB_API_URL,
};
}
+26 -21
View File
@@ -1,26 +1,31 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue';
import {resolve} from 'path'; import { resolve } from 'path';
function pathResolve(dir: string) { function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir); return resolve(process.cwd(), '.', dir);
} }
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
css: { css: {
preprocessorOptions:{ preprocessorOptions: {
less: { less: {
javascriptEnabled: true javascriptEnabled: true,
} },
} },
}, },
resolve: { resolve: {
alias: [ alias: [
{ {
find: /\/@\//, find: /\/@\//,
replacement: pathResolve('src') + '/', replacement: pathResolve('src') + '/',
}, },
], ],
}, },
}) server: {
host: true,
https: false,
},
});