Merge pull request 'optimize: ♻️ 请求部分放在配置项中,UUID生成报错问题' (#8) from dev into master
Reviewed-on: #8 ♻️ 请求部分放在配置项中,UUID生成报错问题
This commit is contained in:
commit
dfd1355ea0
6
.env
6
.env
|
@ -1,8 +1,12 @@
|
||||||
|
# 基础请求路径
|
||||||
|
VITE_BASE_API="/api"
|
||||||
|
# 模拟请求路径
|
||||||
|
VITE_MOCK_BASE_API="/mock"
|
||||||
# 线上环境接口地址
|
# 线上环境接口地址
|
||||||
VITE_APP_URL="http://localhost:8800"
|
VITE_APP_URL="http://localhost:8800"
|
||||||
# 线上环境接口地址
|
# 线上环境接口地址
|
||||||
VITE_APP_MOCK_URL="http://localhost:8800"
|
VITE_APP_MOCK_URL="http://localhost:8800"
|
||||||
# 端口号
|
# 端口号
|
||||||
VITE_APP_PORT=6262
|
VITE_PORT=6262
|
||||||
# 是否使用CDN加速
|
# 是否使用CDN加速
|
||||||
VITE_CDN=true
|
VITE_CDN=true
|
|
@ -1,8 +1,12 @@
|
||||||
|
# 基础请求路径
|
||||||
|
VITE_BASE_API="/api"
|
||||||
|
# 模拟请求路径
|
||||||
|
VITE_MOCK_BASE_API=/mock
|
||||||
# 线上环境接口地址
|
# 线上环境接口地址
|
||||||
VITE_APP_URL="http://localhost:8800"
|
VITE_APP_URL="http://localhost:8800"
|
||||||
# 线上环境接口地址
|
# 线上环境接口地址
|
||||||
VITE_APP_MOCK_URL="http://localhost:8800"
|
VITE_APP_MOCK_URL="http://localhost:8800"
|
||||||
# 端口号
|
# 端口号
|
||||||
VITE_APP_PORT=6262
|
VITE_PORT=6262
|
||||||
# 是否使用CDN加速
|
# 是否使用CDN加速
|
||||||
VITE_CDN=true
|
VITE_CDN=true
|
|
@ -1,8 +0,0 @@
|
||||||
# 线上环境接口地址
|
|
||||||
VITE_APP_URL="http://localhost:8800"
|
|
||||||
# 线上环境接口地址
|
|
||||||
VITE_APP_MOCK_URL="http://localhost:8800"
|
|
||||||
# 端口号
|
|
||||||
VITE_APP_PORT=6262
|
|
||||||
# 是否使用CDN加速
|
|
||||||
VITE_CDN=true
|
|
|
@ -60,7 +60,9 @@ const pathResolve = (dir = '.', metaUrl = import.meta.url) => {
|
||||||
const wrapperEnv = (envConf: Recordable): any => {
|
const wrapperEnv = (envConf: Recordable): any => {
|
||||||
// TODO 默认值
|
// TODO 默认值
|
||||||
const ret: any = {
|
const ret: any = {
|
||||||
VITE_APP_PORT: 6262,
|
VITE_BASE_API: '',
|
||||||
|
VITE_MOCK_BASE_API: '',
|
||||||
|
VITE_PORT: 6262,
|
||||||
VITE_APP_URL: '',
|
VITE_APP_URL: '',
|
||||||
VITE_APP_MOCK_URL: '',
|
VITE_APP_MOCK_URL: '',
|
||||||
VITE_CDN: false,
|
VITE_CDN: false,
|
||||||
|
|
23
src/App.vue
23
src/App.vue
|
@ -1,30 +1,29 @@
|
||||||
<template>
|
<template>
|
||||||
<RouterView />
|
<RouterView />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { userI18nStore } from "@/store/i18n.ts";
|
import { userI18nStore } from '@/store/i18n.ts';
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from 'vue-i18n';
|
||||||
import { onMounted } from "vue";
|
import { onMounted } from 'vue';
|
||||||
|
|
||||||
const i18nStore = userI18nStore();
|
const i18nStore = userI18nStore();
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 设置多语言内容
|
* * 设置多语言内容
|
||||||
*/
|
*/
|
||||||
const setI18n = async () => {
|
const setI18n = async () => {
|
||||||
await i18nStore.fetchI18n();
|
await i18nStore.fetchI18n();
|
||||||
const languageData = JSON.parse(localStorage.getItem("i18nStore") as any);
|
const languageData = JSON.parse(localStorage.getItem('i18nStore') as any);
|
||||||
const local = languageData.i18n.local;
|
const local = languageData.i18n.local;
|
||||||
|
|
||||||
// 初始化设置多语言内容
|
// 初始化设置多语言内容
|
||||||
i18n.locale.value = local;
|
i18n.locale.value = local;
|
||||||
i18n.mergeLocaleMessage(local, languageData.i18n[local]);
|
i18n.mergeLocaleMessage(local, languageData.i18n[local]);
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await setI18n();
|
await setI18n();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
22
src/main.ts
22
src/main.ts
|
@ -1,19 +1,17 @@
|
||||||
import directives from "@/directives";
|
import directives from '@/directives';
|
||||||
import i18n from "@/i18n/index.ts";
|
import i18n from '@/i18n/index.ts';
|
||||||
import { createPinia } from "pinia";
|
import { createPinia } from 'pinia';
|
||||||
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
|
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
|
||||||
import { createApp } from "vue";
|
import { createApp } from 'vue';
|
||||||
import App from "./App.vue";
|
import App from './App.vue';
|
||||||
import "./assets/css/index.scss";
|
import './assets/css/index.scss';
|
||||||
import "./assets/css/reset.css";
|
import './assets/css/reset.css';
|
||||||
import router from "./router";
|
import router from './router';
|
||||||
|
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
// ? pinia 持久化存储
|
// ? pinia 持久化存储
|
||||||
pinia.use(piniaPluginPersistedstate);
|
pinia.use(piniaPluginPersistedstate);
|
||||||
|
|
||||||
app.use(router).use(pinia).use(i18n).use(directives);
|
app.use(router).use(pinia).use(i18n).use(directives);
|
||||||
app.mount("#app");
|
app.mount('#app');
|
||||||
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
// 基础请求
|
|
||||||
export const BASE_API: string = '/api';
|
|
||||||
// mock数据
|
|
||||||
export const BASE_MOCK: string = '/mock';
|
|
|
@ -1,26 +1,25 @@
|
||||||
import { ResultEnum } from "@/enums/httpEnum";
|
import { ResultEnum } from '@/enums/httpEnum';
|
||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
import { BASE_MOCK } from "./config/servicePort";
|
|
||||||
|
|
||||||
const request = axios.create({
|
const request = axios.create({
|
||||||
baseURL: BASE_MOCK,
|
baseURL: import.meta.env.VITE_MOCK_BASE_API,
|
||||||
timeout: ResultEnum.TIMEOUT as number
|
timeout: ResultEnum.TIMEOUT as number,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
request.interceptors.request.use(config => {
|
request.interceptors.request.use(config => {
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
request.interceptors.response.use(
|
request.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return Promise.reject(new Error("网络错误"));
|
return Promise.reject(new Error('网络错误'));
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export default request;
|
export default request;
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
import { ResultEnum } from "@/enums/httpEnum";
|
import { ResultEnum } from '@/enums/httpEnum';
|
||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
import { BASE_API } from "./config/servicePort";
|
|
||||||
|
|
||||||
const request = axios.create({
|
const request = axios.create({
|
||||||
// 默认请求地址
|
// 默认请求地址
|
||||||
baseURL: BASE_API,
|
baseURL: import.meta.env.VITE_BASE_API,
|
||||||
// 设置超时时间
|
// 设置超时时间
|
||||||
timeout: ResultEnum.TIMEOUT as number
|
timeout: ResultEnum.TIMEOUT as number,
|
||||||
// 跨域允许携带凭证
|
// 跨域允许携带凭证
|
||||||
// withCredentials: true,
|
// withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
request.interceptors.request.use(config => {
|
request.interceptors.request.use(config => {
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
request.interceptors.response.use(
|
request.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
return response.data;
|
// 返回相应数据
|
||||||
},
|
return response.data;
|
||||||
error => {
|
},
|
||||||
console.log(error);
|
error => {
|
||||||
return Promise.reject(new Error("网络错误"));
|
console.log(error);
|
||||||
}
|
return Promise.reject(new Error('网络错误'));
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export default request;
|
export default request;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
/**
|
/**
|
||||||
* @description 获取localStorage
|
* @description 获取localStorage
|
||||||
* @param {String} key Storage名称
|
* @param {String} key Storage名称
|
||||||
|
@ -56,5 +55,5 @@ export const isType = (val: any) => {
|
||||||
* @returns UUID
|
* @returns UUID
|
||||||
*/
|
*/
|
||||||
export const getUUID = () => {
|
export const getUUID = () => {
|
||||||
return randomUUID();
|
return crypto.randomUUID();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
interface ImportMetaEnv {
|
|
||||||
readonly VITE_GLOB_APP_TITLE: string; // 定义标题
|
|
||||||
readonly VITE_PORT: number; // 定义端口号
|
|
||||||
readonly VITE_OPEN: boolean; // 运行 npm run dev 时自动打开浏览器
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*.vue' {
|
declare module '*.vue' {
|
||||||
import type { DefineComponent } from 'vue';
|
import type { DefineComponent } from 'vue';
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
||||||
|
|
Loading…
Reference in New Issue