初始化项目
This commit is contained in:
49
.github/copilot-instructions.md
vendored
Normal file
49
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<!-- .github/copilot-instructions.md -->
|
||||
# 快速上手(供 AI 助手)
|
||||
|
||||
此项目是一个基于 Vue 3 + Vite 的 Web 前端(Element Plus UI)。下面的说明帮助 AI 编码/补全助手快速理解项目结构、运行方式、常见约定和注意点,以便生成正确、可运行的改动。
|
||||
|
||||
- 运行 / 构建
|
||||
- 安装依赖: `npm install`
|
||||
- 开发: `npm run dev`(本地 dev server 默认端口在 `vite.config.js` 中配置为 63615)
|
||||
- 生产构建: `npm run build`
|
||||
- 预览产物: `npm run preview`
|
||||
- 修复 lint: `npm run lint`
|
||||
|
||||
- 核心技术栈(来自 `package.json`)
|
||||
- Vue 3, Vite, Vue Router 4, Vuex 4
|
||||
- Element Plus (UI)、axios(HTTP)、vue-i18n
|
||||
|
||||
- 关键文件/位置(示例引用)
|
||||
- `src/main.js`:应用入口。全局注入 `$http`(axios 实例)和 `config`(来自 `public/config.js`),并挂载 ElementPlus 与 i18n。
|
||||
- `src/router/index.js`:路由定义与路由守卫。认证依赖 `localStorage.token`;有 Admin 特权判断(username 为 Admin 或 MoMoWen)。添加页面通常在 `src/pages/*` 中创建并在此处引入。
|
||||
- `src/axios.js`:导出默认 axios 实例与 `createAxiosInstance(urlnum)` 工厂函数。注意:
|
||||
- baseURL 来源:`public/config.js` 的 `ApiList`(index 默认 0)或 `import.meta.env.VITE_API_BASE_URL`。
|
||||
- 请求拦截器会为非 Login/Login 请求附带 `Authorization: Bearer <token>`(从 localStorage 读取)。
|
||||
- 响应拦截器实现了简单的 401 处理与 `refreshToken()` 的自动尝试(依赖 rememberedUsername/rememberedPassword 存储)。
|
||||
- `public/config.js`:运行时 API 列表与资源地址(更新测试或新服务地址请在这里调整或通过 env 覆盖)。
|
||||
|
||||
- 项目约定与注意事项(基于代码可观测行为)
|
||||
- 认证:token 存在于 `localStorage.token`。路由守卫依赖该字段。如果生成与登录/认证相关的修改,请保持兼容性。
|
||||
- 自动刷新 Token:`src/axios.js` 会尝试在响应后刷新 token(会读取 `rememberedUsername` 与 `rememberedPassword`)。不要移除这些本地键,除非同步修改登录逻辑。
|
||||
- Axios 用法:默认 export 是已配置实例(供现有代码使用 `this.$http` 或 `app.config.globalProperties.$http`)。若需要对不同 API host 调用,请使用 `createAxiosInstance(n)`。
|
||||
- 路由/页面:新页面放到 `src/pages/<name>/index.vue` 并在 `src/router/index.js` 中按现有模式引入与注册。
|
||||
- 全局注入:`main.js` 使用 `app.provide('config', config)`,生成的自动补全可参考 `config.ApiList`、`config.Api` 等字段。
|
||||
|
||||
- 编辑/调试建议(对生成代码很重要)
|
||||
- 本地运行 dev 后打开 `http://localhost:63615`(或 Vite 提示的端口)。
|
||||
- 推荐编辑器/插件:VSCode + Volar(项目 README 推荐)。
|
||||
|
||||
- 示例片段(如何安全地添加 API 调用)
|
||||
- 使用默认实例(与现有代码兼容):
|
||||
- 在组件中直接使用 `this.$http.get('Some/Endpoint')`(或 `import axios from '@/axios'` 然后 `axios.get(...)`)。
|
||||
- 使用备用 base URL:
|
||||
- `import { createAxiosInstance } from '@/axios'
|
||||
const api2 = createAxiosInstance(1)
|
||||
api2.get('Some/Endpoint')`
|
||||
|
||||
- 变更约束(AI 应遵守以避免破坏现有行为)
|
||||
- 不要删除或重命名 `localStorage` 中的 key(如: `token`, `username`, `rememberedUsername`, `rememberedPassword`, `lastAutoLoginTime`),除非同时更新登录与刷新流程。
|
||||
- 保持 `Login/Login` 在 axios 拦截器中作为例外路径(或同时更新拦截器逻辑)。
|
||||
|
||||
若你需要我把某部分扩展为示例代码补丁(比如为某个新页面、API 或路由添加实现),告诉我目标文件与预期行为,我会生成并应用补丁;之后请告知额外运行/测试步骤或后端约束。
|
||||
Reference in New Issue
Block a user