提交 5420e8ed 编写于 作者: 郝先瑞

refactor: 项目优化

上级 3a5399e7
## 开发环境变量配置
## 开发环境
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV='development'
......
## 生产环境变量配置
## 生产环境
NODE_ENV='production'
VITE_APP_TITLE = '有来商城管理系统'
......
## 模拟环境变量配置
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'
......@@ -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, () => {
......
......@@ -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
......@@ -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;
......
......@@ -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" }]
}
......@@ -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
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
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册