diff --git a/.env.development b/.env.development index eda493a..66e737f 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ -## 开发环境变量配置 +## 开发环境 # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV='development' diff --git a/.env.production b/.env.production index 661e9ce..383b8fe 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ -## 生产环境变量配置 +## 生产环境 NODE_ENV='production' VITE_APP_TITLE = '有来商城管理系统' diff --git a/.env.staging b/.env.staging index 42c4fa6..2745dc0 100644 --- a/.env.staging +++ b/.env.staging @@ -1,6 +1,6 @@ -## 模拟环境变量配置 -NODE_ENV='staging' +## 模拟环境 +NODE_ENV='production' VITE_APP_TITLE = '有来商城管理系统' VITE_APP_PORT = 9527 -VITE_APP_BASE_API = '/stage-api' +VITE_APP_BASE_API = '/prod--api' diff --git a/src/components/TreeSelect/index.vue b/src/components/TreeSelect/index.vue index db3dd43..00e2d5e 100644 --- a/src/components/TreeSelect/index.vue +++ b/src/components/TreeSelect/index.vue @@ -111,8 +111,8 @@ function clearSelected() { allNode.forEach((element) => element.classList.remove('is-current')) } -onMounted(() => { - nextTick(() => { +function initHandle(){ + nextTick(() => { const selectedValue = modelValue.value; if (selectedValue !== null && typeof (selectedValue) !== "undefined") { const node = proxy.$refs.selectTree.getNode(selectedValue) @@ -125,6 +125,10 @@ onMounted(() => { } } }) +} + +onMounted(() => { + initHandle(); }) watch(modelValue, () => { diff --git a/src/env.d.ts b/src/env.d.ts index faadf80..272014d 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -7,11 +7,13 @@ declare module '*.vue' { export default component } - -// 环境变量智能提示 +// 环境变量 TypeScript的智能提示 interface ImportMetaEnv { - NODE_ENV:string, VITE_APP_TITLE: string, VITE_APP_PORT: string, VITE_APP_BASE_API: string +} + +interface ImportMeta { + readonly env: ImportMetaEnv } \ No newline at end of file diff --git a/src/utils/request.ts b/src/utils/request.ts index 03a7501..c52aaec 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -5,7 +5,7 @@ import {useUserStoreHook} from "@/store/modules/user"; // 创建 axios 实例 const service = axios.create({ - baseURL: import.meta.env.VITE_APP_BASE_API as any, + baseURL: import.meta.env.VITE_APP_BASE_API, timeout: 50000, headers: {'Content-Type': 'application/json;charset=utf-8'} }) @@ -28,7 +28,6 @@ service.interceptors.request.use( // 响应拦截器 service.interceptors.response.use( ({data}) => { - // 对响应数据做点什么 const {code, msg} = data; if (code === '00000') { return data; diff --git a/tsconfig.json b/tsconfig.json index c42f1ed..4ccc46b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,14 +10,12 @@ "resolveJsonModule": true, "esModuleInterop": true, "lib": ["esnext", "dom"], - "baseUrl": "./", "paths": { "@/*": ["src/*"] }, - "extends": "./tsconfig.extends.json", - "skipLibCheck": true, // element-plus 生产打包报错,通过此配置修改 TS 不对第三方依赖类型检查 - "allowSyntheticDefaultImports": true // 默认导入 + "skipLibCheck": true, // 不对第三方依赖类型检查 ,element-plus 生产打包报错 }, - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] + "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], + "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/tsconfig.node.json b/tsconfig.node.json index ca75d55..1fd3396 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -2,7 +2,9 @@ "compilerOptions": { "composite": true, "module": "esnext", - "moduleResolution": "node" + "moduleResolution": "node", + + "allowSyntheticDefaultImports": true // 默认导入 }, "include": ["vite.config.ts"] } \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 575c3a0..fd72273 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,7 @@ import {UserConfig, ConfigEnv, loadEnv} from 'vite' import vue from '@vitejs/plugin-vue' import viteSvgIcons from 'vite-plugin-svg-icons'; -// 如果编辑器提示 path 模块找不到,则可以安装一下 @types/node -> npm i @types/node -D +// 如果编辑器提示 path 模块找不到,则可以安装一下 @types/node -> npm install @types/node --save-dev import path from 'path' // @see: https://gitee.com/holysheng/vite2-config-description/blob/master/vite.config.ts @@ -38,7 +38,7 @@ export default ({command, mode}: ConfigEnv): UserConfig => { resolve: { // Vite 设置别名路径 alias: { - "@": path.resolve("./src"), // 相对路径别名配置,@表示src + "@": path.resolve("./src"), // @ 代替 src } } }