|
|
@@ -16,11 +16,13 @@
|
|
|
|
|
|
- **框架**: Vue 3.5.13 + TypeScript 5.8.3
|
|
|
- **UI 组件库**: Element Plus 2.9.8
|
|
|
-- **构建工具**: Vite 7.0.9
|
|
|
-- **状态管理**: Pinia
|
|
|
-- **路由管理**: Vue Router 4
|
|
|
-- **HTTP 客户端**: Axios
|
|
|
-- **代码风格**: ESLint + Prettier
|
|
|
+- **构建工具**: Vite 6.3.2
|
|
|
+- **状态管理**: Pinia 3.0.2
|
|
|
+- **路由管理**: Vue Router 4.5.0
|
|
|
+- **HTTP 客户端**: Axios 1.8.4
|
|
|
+- **代码风格**: ESLint 9.21.0 + Prettier 3.5.2
|
|
|
+- **样式预处理**: SCSS (Sass 1.87.0)
|
|
|
+- **原子化 CSS**: UnoCSS 66.0.0
|
|
|
- **Node.js**: 20.15.x+ (推荐 20.15.0)
|
|
|
- **npm**: 10.7.x+
|
|
|
|
|
|
@@ -37,31 +39,47 @@
|
|
|
|
|
|
基于 Art Design Pro 的设计语言,追求现代化、精致、用户友好的界面体验。注重细节、动效和用户交互的流畅性。
|
|
|
|
|
|
-### 颜色系统
|
|
|
+### 颜色系统 🎨
|
|
|
|
|
|
-#### 主色调 (Primary Colors)
|
|
|
+#### 主色调 (Primary Colors) - 2025 年最新版本
|
|
|
|
|
|
```css
|
|
|
---art-primary: 93, 135, 255; /* 主品牌色 - 蓝色 */
|
|
|
---art-secondary: 73, 190, 255; /* 辅助色 - 天蓝色 */
|
|
|
---art-success: 19, 222, 185; /* 成功色 - 绿色 */
|
|
|
---art-warning: 255, 174, 31; /* 警告色 - 橙色 */
|
|
|
---art-error: 250, 137, 107; /* 错误色 - 红色 */
|
|
|
---art-info: 83, 155, 255; /* 信息色 - 蓝色 */
|
|
|
---art-danger: 255, 77, 79; /* 危险色 - 红色 */
|
|
|
+/* 亮色主题 */
|
|
|
+:root {
|
|
|
+ --art-primary: 50, 50, 222; /* 主品牌色 - 深蓝色 #3232de */
|
|
|
+ --art-secondary: 73, 190, 255; /* 辅助色 - 天蓝色 #49beff */
|
|
|
+ --art-success: 0, 167, 58; /* 成功色 - 绿色 #00a73a */
|
|
|
+ --art-warning: 142, 91, 0; /* 警告色 - 橙色 #8e5b00 */
|
|
|
+ --art-error: 250, 137, 107; /* 错误色 - 红色 #fa896b */
|
|
|
+ --art-info: 0, 75, 178; /* 信息色 - 蓝色 #004bb2 */
|
|
|
+ --art-danger: 255, 77, 79; /* 危险色 - 红色 #ff4d4f */
|
|
|
+}
|
|
|
+
|
|
|
+/* 暗色主题 */
|
|
|
+html.dark {
|
|
|
+ --art-primary: 93, 135, 255; /* 主品牌色 - 亮蓝色 #5d87ff */
|
|
|
+ --art-secondary: 73, 190, 255; /* 辅助色 - 天蓝色 #49beff */
|
|
|
+ --art-success: 19, 222, 185; /* 成功色 - 绿色 #13deb9 */
|
|
|
+ --art-warning: 255, 174, 31; /* 警告色 - 橙色 #ffae1f */
|
|
|
+ --art-error: 250, 137, 107; /* 错误色 - 红色 #fa896b */
|
|
|
+ --art-info: 83, 155, 255; /* 信息色 - 蓝色 #539bff */
|
|
|
+ --art-danger: 255, 77, 79; /* 危险色 - 红色 #ff4d4f */
|
|
|
+}
|
|
|
```
|
|
|
|
|
|
#### 背景色系统
|
|
|
|
|
|
```css
|
|
|
/* 浅色主题 */
|
|
|
---art-bg-color: #fafbfc; /* 页面底色 */
|
|
|
---art-main-bg-color: #ffffff; /* 主要内容背景 */
|
|
|
---art-bg-primary: 236, 242, 255; /* 主色背景 */
|
|
|
---art-bg-secondary: 232, 247, 255; /* 辅助背景 */
|
|
|
---art-bg-success: 230, 255, 250; /* 成功背景 */
|
|
|
---art-bg-warning: 254, 245, 229; /* 警告背景 */
|
|
|
---art-bg-error: 253, 237, 232; /* 错误背景 */
|
|
|
+:root {
|
|
|
+ --art-bg-color: #fafbfc; /* 页面底色 */
|
|
|
+ --art-main-bg-color: #ffffff; /* 主要内容背景 */
|
|
|
+ --art-bg-primary: 236, 242, 255; /* 主色背景 */
|
|
|
+ --art-bg-secondary: 232, 247, 255; /* 辅助背景 */
|
|
|
+ --art-bg-success: 230, 255, 250; /* 成功背景 */
|
|
|
+ --art-bg-warning: 254, 245, 229; /* 警告背景 */
|
|
|
+ --art-bg-error: 253, 237, 232; /* 错误背景 */
|
|
|
+}
|
|
|
|
|
|
/* 暗色主题 */
|
|
|
html.dark {
|
|
|
@@ -70,7 +88,23 @@ html.dark {
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-### 轮廓式按钮设计系统
|
|
|
+#### 灰色系统
|
|
|
+
|
|
|
+```css
|
|
|
+:root {
|
|
|
+ --art-gray-100: #f9f9f9; /* 浅灰 */
|
|
|
+ --art-gray-200: #f1f1f4; /* 较浅灰 */
|
|
|
+ --art-gray-300: #dbdfe9; /* 中浅灰 */
|
|
|
+ --art-gray-400: #c4cada; /* 中灰 */
|
|
|
+ --art-gray-500: #99a1b7; /* 中深灰 */
|
|
|
+ --art-gray-600: #78829d; /* 深灰 */
|
|
|
+ --art-gray-700: #4b5675; /* 较深灰 */
|
|
|
+ --art-gray-800: #252f4a; /* 很深灰 */
|
|
|
+ --art-gray-900: #071437; /* 最深灰 */
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 轮廓式按钮设计系统 🔘
|
|
|
|
|
|
#### 🎨 设计理念
|
|
|
|
|
|
@@ -91,6 +125,89 @@ html.dark {
|
|
|
- **点击状态**: 98%缩放 + 0.1s 快速过渡 + 背景透明度变为 15%
|
|
|
- **禁用状态**: 50%透明度,禁用所有交互和变换
|
|
|
|
|
|
+### 🔘 列表页面按钮使用规范(2025 年最新标准)
|
|
|
+
|
|
|
+#### 工具栏按钮规范
|
|
|
+
|
|
|
+```vue
|
|
|
+<!-- 标准工具栏按钮配置 -->
|
|
|
+<template #header>
|
|
|
+ <el-row :gutter="10" class="mb8">
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <!-- ✅ 第一个新增按钮:必须使用 type="primary" -->
|
|
|
+ <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <!-- ✅ 其他按钮:不添加type,使用默认样式 -->
|
|
|
+ <el-button icon="Edit" :disabled="single" @click="handleUpdate()">修改</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button icon="Delete" :disabled="multiple" @click="handleDelete()">删除</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button icon="Download" @click="handleExport">导出</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+</template>
|
|
|
+```
|
|
|
+
|
|
|
+#### 操作列按钮规范
|
|
|
+
|
|
|
+```vue
|
|
|
+<!-- 表格操作列按钮配置 -->
|
|
|
+<el-table-column label="操作" align="center" width="160">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-tooltip content="修改" placement="top">
|
|
|
+ <!-- ✅ 操作列按钮:统一使用 link type="primary" -->
|
|
|
+ <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip content="删除" placement="top">
|
|
|
+ <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+</el-table-column>
|
|
|
+```
|
|
|
+
|
|
|
+#### 按钮使用规范总结
|
|
|
+
|
|
|
+| 位置 | 按钮类型 | 样式规范 | 示例 |
|
|
|
+| -------------------- | ---------------- | ---------------------- | -------------------------------------------------------------- |
|
|
|
+| 工具栏第一个新增按钮 | 新增 | `type="primary" plain` | `<el-button type="primary" plain icon="Plus">新增</el-button>` |
|
|
|
+| 工具栏其他按钮 | 修改/删除/导出等 | 无 type(默认) | `<el-button icon="Edit">修改</el-button>` |
|
|
|
+| 表格操作列 | 所有操作按钮 | `link type="primary"` | `<el-button link type="primary" icon="Edit"></el-button>` |
|
|
|
+| 弹窗底部 | 确认按钮 | `type="primary"` | `<el-button type="primary">确定</el-button>` |
|
|
|
+| 弹窗底部 | 取消按钮 | 无 type(默认) | `<el-button>取消</el-button>` |
|
|
|
+
|
|
|
+### 圆角系统
|
|
|
+
|
|
|
+```css
|
|
|
+:root {
|
|
|
+ --border-radius-xs: 4px; /* 超小元素 (checkbox等) */
|
|
|
+ --border-radius-sm: 6px; /* 小元素 (下拉选项、关闭按钮等) */
|
|
|
+ --border-radius-md: 8px; /* 表单控件 (input、select、button等) */
|
|
|
+ --border-radius-lg: 12px; /* 容器组件 (card、table、dialog等) */
|
|
|
+ --border-radius-xl: 12px;
|
|
|
+ --border-radius-2xl: 16px;
|
|
|
+ --border-radius-full: 50%;
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 间距系统
|
|
|
+
|
|
|
+```css
|
|
|
+:root {
|
|
|
+ --space-xs: 4px;
|
|
|
+ --space-sm: 8px;
|
|
|
+ --space-md: 12px;
|
|
|
+ --space-lg: 16px;
|
|
|
+ --space-xl: 20px;
|
|
|
+ --space-2xl: 24px;
|
|
|
+ --space-3xl: 32px;
|
|
|
+ --space-4xl: 48px;
|
|
|
+ --space-5xl: 64px;
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
## 3. 组件开发规范
|
|
|
|
|
|
### Vue 组件结构标准
|
|
|
@@ -175,10 +292,25 @@ onMounted(() => {
|
|
|
<template #header>
|
|
|
<el-row :gutter="10" class="mb8">
|
|
|
<el-col :span="1.5">
|
|
|
+ <!-- ✅ 第一个新增按钮:type="primary" plain -->
|
|
|
<el-button type="primary" plain icon="Plus" @click="handleAdd">
|
|
|
新增
|
|
|
</el-button>
|
|
|
</el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <!-- ✅ 其他按钮:无type,使用默认样式 -->
|
|
|
+ <el-button icon="Edit" :disabled="single" @click="handleUpdate()">
|
|
|
+ 修改
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button icon="Delete" :disabled="multiple" @click="handleDelete()">
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button icon="Download" @click="handleExport">导出</el-button>
|
|
|
+ </el-col>
|
|
|
<right-toolbar
|
|
|
v-model:showSearch="showSearch"
|
|
|
@queryTable="getList"
|
|
|
@@ -192,7 +324,23 @@ onMounted(() => {
|
|
|
<!-- 数据列 -->
|
|
|
<el-table-column label="操作" align="center" width="160">
|
|
|
<template #default="scope">
|
|
|
- <!-- 操作按钮 -->
|
|
|
+ <el-tooltip content="修改" placement="top">
|
|
|
+ <!-- ✅ 操作列按钮:link type="primary" -->
|
|
|
+ <el-button
|
|
|
+ link
|
|
|
+ type="primary"
|
|
|
+ icon="Edit"
|
|
|
+ @click="handleUpdate(scope.row)"
|
|
|
+ ></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip content="删除" placement="top">
|
|
|
+ <el-button
|
|
|
+ link
|
|
|
+ type="primary"
|
|
|
+ icon="Delete"
|
|
|
+ @click="handleDelete(scope.row)"
|
|
|
+ ></el-button>
|
|
|
+ </el-tooltip>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
@@ -238,7 +386,9 @@ onMounted(() => {
|
|
|
</el-row>
|
|
|
|
|
|
<el-form-item>
|
|
|
+ <!-- ✅ 提交按钮:type="primary" -->
|
|
|
<el-button type="primary" @click="submitForm">提交</el-button>
|
|
|
+ <!-- ✅ 重置按钮:无type,使用默认样式 -->
|
|
|
<el-button @click="resetForm">重置</el-button>
|
|
|
</el-form-item>
|
|
|
</el-card>
|
|
|
@@ -498,156 +648,138 @@ export default moduleRouter;
|
|
|
|
|
|
## 7. 项目架构规范
|
|
|
|
|
|
-### 目录结构标准
|
|
|
+### 目录结构
|
|
|
|
|
|
```
|
|
|
web/src/
|
|
|
├── api/ # API接口定义
|
|
|
-│ ├── [module]/ # 按模块分类
|
|
|
-│ │ ├── index.ts # API接口
|
|
|
+│ ├── [module]/
|
|
|
+│ │ ├── index.ts # 接口方法
|
|
|
│ │ └── types.ts # 类型定义
|
|
|
-│ └── types.ts # 通用类型定义
|
|
|
-├── assets/ # 静态资源
|
|
|
-│ ├── icons/ # SVG图标
|
|
|
-│ ├── images/ # 图片资源
|
|
|
-│ └── styles/ # 全局样式
|
|
|
-├── components/ # 通用组件
|
|
|
-│ ├── [ComponentName]/ # 组件目录
|
|
|
-│ │ ├── index.vue # 组件主文件
|
|
|
-│ │ └── types.ts # 组件类型
|
|
|
-│ └── index.ts # 组件导出
|
|
|
-├── composables/ # 组合式函数
|
|
|
-├── directive/ # 自定义指令
|
|
|
-├── hooks/ # 自定义钩子
|
|
|
+├── assets/ # 静态资源
|
|
|
+│ ├── images/ # 图片资源
|
|
|
+│ └── styles/ # 样式文件
|
|
|
+│ ├── art-variables.scss # Art Design Pro 变量
|
|
|
+│ ├── art-element-ui.scss # Element Plus 样式定制
|
|
|
+│ ├── art-global.scss # 全局样式
|
|
|
+│ ├── art-dark.scss # 暗色主题
|
|
|
+│ └── index.scss # 样式入口
|
|
|
+├── components/ # 全局组件
|
|
|
+├── hooks/ # 组合式函数
|
|
|
├── layout/ # 布局组件
|
|
|
├── plugins/ # 插件配置
|
|
|
├── router/ # 路由配置
|
|
|
-│ ├── modules/ # 路由模块
|
|
|
-│ └── index.ts # 路由入口
|
|
|
├── stores/ # 状态管理
|
|
|
-│ ├── modules/ # Store模块
|
|
|
-│ └── index.ts # Store入口
|
|
|
├── types/ # 全局类型定义
|
|
|
├── utils/ # 工具函数
|
|
|
-│ ├── request.ts # HTTP请求封装
|
|
|
-│ ├── auth.ts # 认证工具
|
|
|
-│ └── index.ts # 工具导出
|
|
|
-├── views/ # 页面视图
|
|
|
-│ ├── [module]/ # 按模块分类
|
|
|
-│ │ ├── index.vue # 列表页面
|
|
|
-│ │ ├── form.vue # 表单页面
|
|
|
-│ │ └── components/ # 页面组件
|
|
|
-│ └── layout/ # 布局页面
|
|
|
-├── App.vue # 应用入口
|
|
|
-└── main.ts # 主入口文件
|
|
|
+├── views/ # 页面组件
|
|
|
+└── main.ts # 应用入口
|
|
|
```
|
|
|
|
|
|
-## 8. 代码规范
|
|
|
+### 文件命名规范
|
|
|
|
|
|
-### 命名规范
|
|
|
+- **组件文件**: PascalCase,如 `UserForm.vue`
|
|
|
+- **页面文件**: kebab-case,如 `user-list.vue`
|
|
|
+- **工具文件**: camelCase,如 `formatUtils.ts`
|
|
|
+- **类型文件**: PascalCase,如 `UserTypes.ts`
|
|
|
|
|
|
-- **文件命名**: 使用 kebab-case (如: user-list.vue)
|
|
|
-- **组件命名**: 使用 PascalCase (如: UserList)
|
|
|
-- **方法命名**: 使用 camelCase (如: getUserList)
|
|
|
-- **常量命名**: 使用 UPPER_SNAKE_CASE (如: API_BASE_URL)
|
|
|
-- **CSS 类名**: 使用 kebab-case (如: .user-list-container)
|
|
|
+## 8. 样式开发规范
|
|
|
|
|
|
-### ESLint 配置
|
|
|
+### SCSS 变量使用
|
|
|
|
|
|
-```typescript
|
|
|
-// .eslintrc.js
|
|
|
-module.exports = {
|
|
|
- extends: ['@vue/eslint-config-typescript', '@vue/eslint-config-prettier'],
|
|
|
- rules: {
|
|
|
- // Vue规则
|
|
|
- 'vue/multi-word-component-names': 'off',
|
|
|
- 'vue/no-v-html': 'off',
|
|
|
-
|
|
|
- // TypeScript规则
|
|
|
- '@typescript-eslint/no-unused-vars': 'error',
|
|
|
- '@typescript-eslint/no-explicit-any': 'warn',
|
|
|
-
|
|
|
- // 通用规则
|
|
|
- 'no-console': 'warn',
|
|
|
- 'no-debugger': 'error',
|
|
|
- },
|
|
|
-};
|
|
|
+```scss
|
|
|
+// 使用 Art Design Pro 变量系统
|
|
|
+.custom-component {
|
|
|
+ background-color: var(--art-main-bg-color);
|
|
|
+ border: 1px solid var(--art-border-color);
|
|
|
+ border-radius: var(--border-radius-lg);
|
|
|
+ padding: var(--space-lg);
|
|
|
+
|
|
|
+ .title {
|
|
|
+ color: var(--art-text-gray-900);
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: 500;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content {
|
|
|
+ color: var(--art-text-gray-700);
|
|
|
+ margin-top: var(--space-md);
|
|
|
+ }
|
|
|
+}
|
|
|
```
|
|
|
|
|
|
-### Prettier 配置
|
|
|
-
|
|
|
-```json
|
|
|
-{
|
|
|
- "semi": true,
|
|
|
- "singleQuote": true,
|
|
|
- "trailingComma": "none",
|
|
|
- "tabWidth": 2,
|
|
|
- "useTabs": false,
|
|
|
- "printWidth": 100,
|
|
|
- "endOfLine": "lf"
|
|
|
-}
|
|
|
+### UnoCSS 工具类
|
|
|
+
|
|
|
+```vue
|
|
|
+<template>
|
|
|
+ <!-- 使用原子化CSS类 -->
|
|
|
+ <div class="p-4 bg-white rounded-lg shadow-md">
|
|
|
+ <h3 class="text-lg font-medium text-gray-900 mb-4">标题</h3>
|
|
|
+ <p class="text-gray-700">内容</p>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
```
|
|
|
|
|
|
-## 9. 性能优化
|
|
|
+## 9. 性能优化规范
|
|
|
|
|
|
-### 代码分割
|
|
|
+### 组件懒加载
|
|
|
|
|
|
```typescript
|
|
|
-// 路由懒加载
|
|
|
-const Home = () => import('@/views/home/index.vue');
|
|
|
+// 路由级别的懒加载
|
|
|
+const UserList = () => import('@/views/user/index.vue');
|
|
|
|
|
|
-// 组件懒加载
|
|
|
-const LazyComponent = defineAsyncComponent(() => import('@/components/LazyComponent.vue'));
|
|
|
+// 组件级别的懒加载
|
|
|
+const AsyncComponent = defineAsyncComponent(() => import('@/components/HeavyComponent.vue'));
|
|
|
```
|
|
|
|
|
|
-### 缓存策略
|
|
|
+### 图片优化
|
|
|
|
|
|
-```typescript
|
|
|
-// HTTP缓存
|
|
|
-import { ElMessage } from 'element-plus';
|
|
|
-
|
|
|
-const request = axios.create({
|
|
|
- timeout: 10000,
|
|
|
- headers: {
|
|
|
- 'Cache-Control': 'no-cache'
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-// 组件缓存
|
|
|
-<router-view v-slot="{ Component }">
|
|
|
- <keep-alive :include="cachedViews">
|
|
|
- <component :is="Component" :key="route.path" />
|
|
|
- </keep-alive>
|
|
|
-</router-view>
|
|
|
+```vue
|
|
|
+<template>
|
|
|
+ <!-- 使用适当的图片格式和尺寸 -->
|
|
|
+ <img :src="imageSrc" :alt="imageAlt" loading="lazy" width="200" height="150" />
|
|
|
+</template>
|
|
|
```
|
|
|
|
|
|
-## 10. 错误处理
|
|
|
+## 10. 开发最佳实践
|
|
|
|
|
|
-### 全局错误处理
|
|
|
+### 代码规范
|
|
|
+
|
|
|
+1. **组件命名**: 使用 PascalCase
|
|
|
+2. **方法命名**: 使用 camelCase,语义化命名
|
|
|
+3. **常量命名**: 使用 UPPER_SNAKE_CASE
|
|
|
+4. **注释规范**: 使用 JSDoc 格式
|
|
|
+
|
|
|
+### 错误处理
|
|
|
|
|
|
```typescript
|
|
|
-// main.ts
|
|
|
-app.config.errorHandler = (err, vm, info) => {
|
|
|
- console.error('全局错误:', err);
|
|
|
- ElMessage.error('系统异常,请联系管理员');
|
|
|
+// API错误处理
|
|
|
+const handleSubmit = async () => {
|
|
|
+ try {
|
|
|
+ loading.value = true;
|
|
|
+ await submitData(formData);
|
|
|
+ ElMessage.success('操作成功');
|
|
|
+ } catch (error) {
|
|
|
+ console.error('提交失败:', error);
|
|
|
+ ElMessage.error('操作失败');
|
|
|
+ } finally {
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
};
|
|
|
+```
|
|
|
|
|
|
-// 请求错误处理
|
|
|
-request.interceptors.response.use(
|
|
|
- (response) => {
|
|
|
- const { code, msg } = response.data;
|
|
|
- if (code === 200) {
|
|
|
- return response.data;
|
|
|
- } else {
|
|
|
- ElMessage.error(msg || '请求失败');
|
|
|
- return Promise.reject(new Error(msg));
|
|
|
- }
|
|
|
- },
|
|
|
- (error) => {
|
|
|
- ElMessage.error('网络异常');
|
|
|
- return Promise.reject(error);
|
|
|
- },
|
|
|
-);
|
|
|
+### 类型安全
|
|
|
+
|
|
|
+```typescript
|
|
|
+// 严格的类型定义
|
|
|
+interface UserForm {
|
|
|
+ name: string;
|
|
|
+ email: string;
|
|
|
+ status: 0 | 1;
|
|
|
+}
|
|
|
+
|
|
|
+// 类型断言
|
|
|
+const user = data as UserForm;
|
|
|
```
|
|
|
|
|
|
## 11. 测试规范
|
|
|
@@ -655,137 +787,58 @@ request.interceptors.response.use(
|
|
|
### 单元测试
|
|
|
|
|
|
```typescript
|
|
|
-// tests/components/UserList.spec.ts
|
|
|
+// 使用 Vitest 进行单元测试
|
|
|
+import { describe, it, expect } from 'vitest';
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
-import UserList from '@/components/UserList/index.vue';
|
|
|
+import UserForm from '@/components/UserForm.vue';
|
|
|
|
|
|
-describe('UserList', () => {
|
|
|
+describe('UserForm', () => {
|
|
|
it('should render correctly', () => {
|
|
|
- const wrapper = mount(UserList, {
|
|
|
- props: {
|
|
|
- users: [],
|
|
|
- },
|
|
|
- });
|
|
|
+ const wrapper = mount(UserForm);
|
|
|
expect(wrapper.exists()).toBe(true);
|
|
|
});
|
|
|
});
|
|
|
```
|
|
|
|
|
|
-### E2E 测试
|
|
|
+## 12. 构建与部署
|
|
|
|
|
|
-```typescript
|
|
|
-// e2e/user.spec.ts
|
|
|
-import { test, expect } from '@playwright/test';
|
|
|
-
|
|
|
-test('用户列表页面', async ({ page }) => {
|
|
|
- await page.goto('/user/list');
|
|
|
- await expect(page.locator('.user-list')).toBeVisible();
|
|
|
-});
|
|
|
-```
|
|
|
+### 环境配置
|
|
|
|
|
|
-## 主题色规范
|
|
|
-
|
|
|
-### 1. 基础主题色值
|
|
|
-
|
|
|
-#### Light 主题
|
|
|
+```typescript
|
|
|
+// .env.development
|
|
|
+VITE_APP_BASE_API = '/dev-api';
|
|
|
+VITE_APP_PORT = 80;
|
|
|
|
|
|
-```scss
|
|
|
-// 主色调
|
|
|
---art-primary: 50, 50, 222; // 深蓝色,用于主要按钮、链接等
|
|
|
---art-secondary: 73, 190, 255; // 次要蓝色
|
|
|
---art-success: 0, 167, 58; // 成功色
|
|
|
---art-warning: 142, 91, 0; // 警告色
|
|
|
---art-danger: 255, 77, 79; // 危险色
|
|
|
---art-info: 0, 75, 178; // 信息色
|
|
|
---art-error: 250, 137, 107; // 错误色
|
|
|
-
|
|
|
-// 文本颜色
|
|
|
---art-text-gray-600: #333333; // 主要文本
|
|
|
---art-text-gray-700: #000000; // 强调文本
|
|
|
+// .env.production
|
|
|
+VITE_APP_BASE_API = '/prod-api';
|
|
|
+VITE_APP_PORT = 80;
|
|
|
```
|
|
|
|
|
|
-#### Dark 主题
|
|
|
+### 构建优化
|
|
|
|
|
|
-```scss
|
|
|
-// 主色调
|
|
|
---art-primary: 93, 135, 255; // 亮蓝色
|
|
|
---art-bg-color: #070707; // 背景色
|
|
|
---art-main-bg-color: #161618; // 主要背景色
|
|
|
+```typescript
|
|
|
+// vite.config.ts
|
|
|
+export default defineConfig({
|
|
|
+ build: {
|
|
|
+ rollupOptions: {
|
|
|
+ output: {
|
|
|
+ chunkFileNames: 'js/[name]-[hash].js',
|
|
|
+ entryFileNames: 'js/[name]-[hash].js',
|
|
|
+ assetFileNames: '[ext]/[name]-[hash].[ext]',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+});
|
|
|
```
|
|
|
|
|
|
-### 2. 使用规范
|
|
|
-
|
|
|
-1. **变量使用方式**
|
|
|
-
|
|
|
- ```scss
|
|
|
- // 正确用法
|
|
|
- color: rgb(var(--art-primary));
|
|
|
- background-color: rgb(var(--art-bg-primary));
|
|
|
-
|
|
|
- // 错误用法
|
|
|
- color: var(--art-primary); // ❌ 缺少rgb()
|
|
|
- ```
|
|
|
-
|
|
|
-2. **Element Plus 组件主题**
|
|
|
-
|
|
|
- ```scss
|
|
|
- // 全局变量
|
|
|
- --el-color-primary: rgb(var(--art-primary)) !important;
|
|
|
- --el-text-color-regular: #000000 !important;
|
|
|
- ```
|
|
|
-
|
|
|
-3. **菜单组件样式**
|
|
|
- ```scss
|
|
|
- --el-menu-hover-bg-color: rgb(var(--art-primary)) !important;
|
|
|
- --el-menu-active-color: rgb(var(--art-primary)) !important;
|
|
|
- ```
|
|
|
-
|
|
|
-### 3. 主题切换
|
|
|
-
|
|
|
-1. **Light/Dark 主题切换**
|
|
|
-
|
|
|
- - 通过添加/移除 `html.dark` 类实现
|
|
|
- - 自动继承对应主题的所有变量
|
|
|
-
|
|
|
-2. **响应式设计**
|
|
|
- - 所有颜色必须使用 CSS 变量
|
|
|
- - 禁止使用硬编码的颜色值
|
|
|
+---
|
|
|
|
|
|
-### 4. 辅助工具类
|
|
|
+## 总结
|
|
|
|
|
|
-```scss
|
|
|
-// 背景色
|
|
|
-.bg-primary {
|
|
|
- background-color: rgb(var(--art-bg-primary)) !important;
|
|
|
-}
|
|
|
-.bg-success {
|
|
|
- background-color: rgb(var(--art-bg-success)) !important;
|
|
|
-}
|
|
|
-.bg-warning {
|
|
|
- background-color: rgb(var(--art-bg-warning)) !important;
|
|
|
-}
|
|
|
-.bg-danger {
|
|
|
- background-color: rgb(var(--art-bg-danger)) !important;
|
|
|
-}
|
|
|
-
|
|
|
-// 文本颜色
|
|
|
-.text-primary {
|
|
|
- color: rgb(var(--art-primary)) !important;
|
|
|
-}
|
|
|
-.text-success {
|
|
|
- color: rgb(var(--art-success)) !important;
|
|
|
-}
|
|
|
-.text-warning {
|
|
|
- color: rgb(var(--art-warning)) !important;
|
|
|
-}
|
|
|
-.text-danger {
|
|
|
- color: rgb(var(--art-danger)) !important;
|
|
|
-}
|
|
|
-```
|
|
|
+本规范文档涵盖了杭州第一技师学院智慧校园管理系统前端开发的所有核心规范,包括最新的品牌色配置和统一的按钮使用规范。开发者应严格遵循这些规范,确保代码质量和用户体验的一致性。
|
|
|
|
|
|
-### 5. 注意事项
|
|
|
+**🔴 重要提醒**:
|
|
|
|
|
|
-1. 所有新增组件必须使用主题变量系统
|
|
|
-2. 禁止使用硬编码的颜色值
|
|
|
-3. 确保 Light/Dark 主题下都有良好的显示效果
|
|
|
-4. Element Plus 组件的主题配置必须通过全局变量覆盖
|
|
|
+1. **按钮规范**: 工具栏第一个新增按钮必须使用 `type="primary" plain`,其他按钮使用默认样式
|
|
|
+2. **颜色系统**: 使用最新的 Art Design Pro 颜色变量
|
|
|
+3. **文档同步**: 代码变更后必须同步更新相关文档
|