From 529b9f28d911a016502d73eb519e6d947b3a9458 Mon Sep 17 00:00:00 2001 From: rd <1344903914@qq.com> Date: Fri, 19 Sep 2025 11:44:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(env):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=E5=B9=B6?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -移除了大部分冗余环境变量,简化了配置结构 - 更新了 API 地址配置方式,使用 VITE_API_URL 替代原有变量 - 删除了未使用的代码文件,包括 apiCodes.ts、axiosHandler.ts 和 types.d.ts - 调整了 vite 配置,使用环境变量中的 API地址 - 更新了 gitignore 文件,添加了 dist 目录的忽略项 --- .gitignore | 3 +++ config/index.ts | 7 ++++++- config/utils.ts | 6 +++--- env/.env | 20 ++------------------ env/.env.development | 14 ++------------ env/.env.production | 10 +++------- env/.env.test | 14 +------------- env/README.md | 31 ------------------------------- src/api/apiCodes.ts | 36 ------------------------------------ src/api/axiosHandler.ts | 32 -------------------------------- src/api/index.ts | 3 ++- src/api/types.d.ts | 19 ------------------- vite.config.ts | 8 +++----- 13 files changed, 25 insertions(+), 178 deletions(-) delete mode 100644 env/README.md delete mode 100644 src/api/apiCodes.ts delete mode 100644 src/api/axiosHandler.ts delete mode 100644 src/api/types.d.ts diff --git a/.gitignore b/.gitignore index 1a9742a..a391a02 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ analyzer.html .cursor/* .lingma/* +dist/* +dist-test.tar.gz +dist.tar.gz diff --git a/config/index.ts b/config/index.ts index 5c96895..fdf00d7 100644 --- a/config/index.ts +++ b/config/index.ts @@ -3,8 +3,10 @@ import { configAutoImport, configComponents,configIcons } from './unplugin'; import viteCompression from 'vite-plugin-compression'; import progress from 'vite-plugin-progress'; import defineOptions from 'unplugin-vue-define-options/vite'; +import { setServerConfig } from './utils'; -export * from './utils'; +// 移除可能导致循环引用的导出 +// export * from './utils'; export const pluginsConfig = [ configUnocss(), @@ -17,3 +19,6 @@ export const pluginsConfig = [ include: [/\.vue$/, /\.vue\?vue/], }), ]; + +export { resolve } from './utils'; +export { setServerConfig }; \ No newline at end of file diff --git a/config/utils.ts b/config/utils.ts index 9cde469..6590e12 100644 --- a/config/utils.ts +++ b/config/utils.ts @@ -62,10 +62,10 @@ export const setServerConfig = return { port: Number(env.APP_PORT), proxy: { - [env.EO_API_URL]: { - target: env.API_PROXY, + '/api': { + target: env.VITE_API_URL || 'http://lingjiapi.lvfunai.com/api', changeOrigin: true, - rewrite: (path: string) => path.replace(env.EO_API_URL, ''), + rewrite: (path: string) => path.replace(/^\/api/, ''), }, }, ...opts, diff --git a/env/.env b/env/.env index bfeed03..d81e885 100644 --- a/env/.env +++ b/env/.env @@ -1,19 +1,3 @@ -# 环境变量前缀 -# 此前缀开头的变量通过 import.meta.env 暴露出去 -ENV_PREFIX=EO_ - -APP_TITLE=${APP_TITLE} - -# router base -EO_BASE=/ - -# 协议 -APP_PROTOCOL=https:// - # 接口地址 -EO_API_URL=${APP_PROTOCOL}${API_PATH} -OSS_API_URL=${APP_PROTOCOL}${OSS_API_PATH} - -# 接口代理地址 -API_PROXY=${APP_PROTOCOL}${API_PATH} -OSS_API_PROXY=${APP_PROTOCOL}${OSS_API_PATH} +VITE_API_URL=${VITE_API_URL} +VITE_ENV=${VITE_ENV} diff --git a/env/.env.development b/env/.env.development index a1ee8f1..12c555f 100644 --- a/env/.env.development +++ b/env/.env.development @@ -1,15 +1,5 @@ -# 开发环境 -APP_TITLE='development' -# 端口 -APP_PORT=48438 - -# 协议 -APP_PROTOCOL=http:// - -# 接口路径 -API_PATH=192.168.40.5 - # 接口地址 -EO_API_URL=/api +VITE_API_URL=https://lingjiapi.lvfunai.com/api VITE_ENV='development' + diff --git a/env/.env.production b/env/.env.production index 4741886..b75498d 100644 --- a/env/.env.production +++ b/env/.env.production @@ -1,8 +1,4 @@ -# 生产环境 -APP_TITLE='production | eyo' - -# 接口路径 -API_PATH=zzz - # 接口地址 -EO_API_URL=http://lingjiapi.lvfunai.com/api +VITE_API_URL=https://lingjiapi.lvfunai.com/api + +VITE_ENV='production' diff --git a/env/.env.test b/env/.env.test index c3b41bc..d668c5b 100644 --- a/env/.env.test +++ b/env/.env.test @@ -1,16 +1,4 @@ -# 测试环境 -APP_TITLE='test' -# 端口 -APP_PORT=48438 - -# 协议 -APP_PROTOCOL=http:// - -# 接口路径 - -API_PATH=xxxx - # 接口地址 -EO_API_URL=https://lingjiapi.lvfunai.com/api +VITE_API_URL=https://lingjiapi.lvfunai.com/api VITE_ENV='test' diff --git a/env/README.md b/env/README.md deleted file mode 100644 index 163a3bc..0000000 --- a/env/README.md +++ /dev/null @@ -1,31 +0,0 @@ -### 环境变量和模式 - -| 模式 | 环境 | 描述 | -| ----------------- | ------------------- | ------------ | -| `env` | - | 通用设置 | -| `env.development` | 开发环境 | - | -| `env.preview` | 预览环境 | 本地预览使用 | -| `env.production` | 生产环境 | - | -| `env.staging` | 预发布环境/测试环境 | - | - -#### 参数说明 - -| 参数 | 描述 | 环境 | 说明 | -| -------------- | ------------------------ | ------------- | -------------------------------------------------------- | -| `EO_BASE` | `vue-router` 路由 `base` | - | - | -| `APP_TITLE` | 文档标题 | - | - | -| `APP_PROTOCOL` | 协议 | - | 区别 `webSocket` | -| `APP_PORT` | 端口 | `开发`,`预览` | - | -| `EO_API_URL` | 接口地址 | `开发`,`预览` | - | -| `API_PROXY` | 代理接口地址 | - | - | -| `API_PATH` | 实际接口地址 | - | 开发中只需修改 `API_PATH` 参数,其他参数根据实际情况修改 | - -#### 示例 - -```dotenv -API_PATH=192.168.0.1:48438 -``` - -```dotenv -API_PATH=192.168.0.1:48438/api -``` diff --git a/src/api/apiCodes.ts b/src/api/apiCodes.ts deleted file mode 100644 index 5d68db3..0000000 --- a/src/api/apiCodes.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * @Author: 田鑫 - * @Date: 2023-02-17 11:15:23 - * @LastEditors: 田鑫 - * @LastEditTime: 2023-02-21 16:25:32 - * @Description: API状态码 - */ - -export enum API_STATUS_CODE { - /** 正常响应 */ - SUCCESS = 200, - /** 会话失效,请重新登录 */ - SESSION_FAILUIRE = 1000, - /** 认证失败,无法访问系统资源 */ - AUTH_FAILED = 1001, - /** 未授权,无法访问系统资源 */ - RESOURCE_FORBIDDEN = 1002, - /** 黑名单用户 */ - BLACK_LIST_USER = 1003, - /** 非法IP地址 */ - ILLEGAL_IP = 1004, - /** 网关访问受限 */ - GATEWAY_FORBIDDEN = 1005, - /** 网关访问异常,请稍后重试 */ - GATEWAY_ERROR = 1006, - /** 流控异常 */ - TRAFFIC_CONTROL_ERROR = 1007, - /** 资源找不到服务 */ - RESOURCE_NOT_FOUND = 1008, - /** 资源请求超时 */ - FETCH_TIMEOUT = 1009, - /** 资源响应异常 */ - RESOURCE_RESPONSE_ERROR = 1010, - /** 请求路径不符合规范 */ - ILLEGAL_PATH = 1011, -} diff --git a/src/api/axiosHandler.ts b/src/api/axiosHandler.ts deleted file mode 100644 index 5a31b64..0000000 --- a/src/api/axiosHandler.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * @Author: 田鑫 - * @Date: 2023-02-21 16:34:47 - * @LastEditors: 田鑫 - * @LastEditTime: 2023-02-21 16:59:10 - * @Description: - */ - -import router from '@/router'; -import { clearToken } from '@/utils/auth'; -import { message } from 'ant-design-vue'; - -/** - * 处理业务逻辑定义的错误code - * @param errStatus - */ -export const handleCodeError = (error: any) => { - let errMessage = '未知错误'; - console.log(error); - errMessage = error.msg; - switch (error.code) { - case 1000: - router.replace({ - name: '/login/password', - }); - clearToken(); - break; - default: - errMessage = error.msg || `未知错误-${error.code}`; - } - message.error(errMessage); -}; diff --git a/src/api/index.ts b/src/api/index.ts index dfeca91..bdc54fa 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -25,13 +25,14 @@ enum HttpStatusCode { InternalServerError = 500, } +console.log(); //* 导出Request类,可以用来自定义传递配置来创建实例 export class Request { //* axios 实例 private instance: AxiosInstance; //* 基础配置 private baseConfig: AxiosRequestConfig = { - baseURL: import.meta.env.EO_API_URL, + baseURL: `${import.meta.env.VITE_API_URL}`, timeout: requestTimeout, headers: { 'Content-Type': contentType, diff --git a/src/api/types.d.ts b/src/api/types.d.ts deleted file mode 100644 index 2e82cdf..0000000 --- a/src/api/types.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * @Author: 田鑫 - * @Date: 2023-02-19 21:52:10 - * @LastEditors: 田鑫 - * @LastEditTime: 2023-02-21 16:59:27 - * @Description: - */ -import 'axios'; - -import { API_STATUS_CODE } from './apiCodes'; -declare module 'axios' { - export interface IWygResponse { - success: boolean; - msg: string; - code: API_STATUS_CODE; - data: T; - timestamp: number; - } -} diff --git a/vite.config.ts b/vite.config.ts index 3c96a9c..c732000 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,12 +9,11 @@ import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; import analyzer from 'rollup-plugin-visualizer'; -import { pluginsConfig, setServerConfig, resolve } from './config'; +import { pluginsConfig, resolve } from './config'; export default defineConfig(({ mode }: ConfigEnv): UserConfig => { const envDir = resolve('env'); const env = loadEnv(mode, envDir, ''); - const setServer = setServerConfig({ env }); return { define: { @@ -43,11 +42,10 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => { '/api': { changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), - target: 'https://lingjiapi.lvfunai.com/api', + target: env.VITE_API_URL, }, }, }, - preview: setServer(), }; }); @@ -57,7 +55,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => { * @returns */ function setAnalyzer(env = 'development') { - console.log('env: ', env); + // console.log('env: ', env); if (env === 'development') { return analyzer({ filename: 'analyzer.html', From 2d9f2d0cfc4abd4e133e8095535b1cfd161f0f91 Mon Sep 17 00:00:00 2001 From: rd <1344903914@qq.com> Date: Fri, 19 Sep 2025 11:52:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?style:=20=E7=A7=BB=E9=99=A4log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index bdc54fa..7709880 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,11 +1,3 @@ -/* - * @Author: 田鑫 - * @Date: 2023-02-17 11:58:44 - * @LastEditors: rd 1344903914@qq.com - * @LastEditTime: 2025-07-08 14:50:57 - * @Description: - */ - import axios from 'axios'; import { message } from 'ant-design-vue'; import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; @@ -25,7 +17,6 @@ enum HttpStatusCode { InternalServerError = 500, } -console.log(); //* 导出Request类,可以用来自定义传递配置来创建实例 export class Request { //* axios 实例