feat(react19-migration): 阶段1 - 项目基础设施重建
- T1.1: 卸载 Vue 依赖,安装 React 19 + Ant Design 5 + Zustand 5 + AntV 全家桶 - T1.2: Vite 配置迁移 (plugin-vue → plugin-react, manualChunks 更新) - T1.3: TypeScript 配置迁移 (jsx: preserve → react-jsx, 移除 .vue) - T1.4: ESLint 配置迁移 (Vue 规则 → React/Hooks/Refresh 规则) - T1.5: 入口文件迁移 (main.ts → main.tsx, App.vue → App.tsx, div#app → div#root) 验证: npm run dev 成功启动空白 React 应用
This commit is contained in:
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
SECRET="NovalonManageSystemSecretKey2026"
|
||||
METHOD=$1
|
||||
URL=$2
|
||||
BODY=$3
|
||||
|
||||
TIMESTAMP=$(python3 -c "import time; print(int(time.time() * 1000))")
|
||||
NONCE="${TIMESTAMP}-$(head /dev/urandom | LC_ALL=C tr -dc 'a-z0-9' | head -c 13)"
|
||||
|
||||
PATH_PART=$(echo "$URL" | sed -E 's|^https?://[^/]+||' | sed 's|\?.*||')
|
||||
QUERY_PART=$(echo "$URL" | sed -E 's|^https?://[^/]+||' | sed -n 's|.*\?||p')
|
||||
|
||||
STRING_TO_SIGN="${METHOD}
|
||||
${PATH_PART}
|
||||
${QUERY_PART}
|
||||
${BODY}
|
||||
${TIMESTAMP}
|
||||
${NONCE}"
|
||||
|
||||
SIGNATURE=$(echo -n "$STRING_TO_SIGN" | openssl dgst -sha256 -hmac "$SECRET" -binary | base64)
|
||||
|
||||
echo "X-Signature: $SIGNATURE"
|
||||
echo "X-Timestamp: $TIMESTAMP"
|
||||
echo "X-Nonce: $NONCE"
|
||||
@@ -0,0 +1,230 @@
|
||||
# Dogfood Report: Novalon管理系统
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| **Date** | 2026-04-28 |
|
||||
| **App URL** | http://localhost:3002 |
|
||||
| **Session** | novalon-test |
|
||||
| **Scope** | 全应用探索性测试,重点关注用户旅程(User Journey) |
|
||||
|
||||
## Summary
|
||||
|
||||
| Severity | Count |
|
||||
|----------|-------|
|
||||
| Critical | 0 |
|
||||
| High | 1 |
|
||||
| Medium | 2 |
|
||||
| Low | 1 |
|
||||
| **Total** | **4** |
|
||||
|
||||
## Test Environment
|
||||
|
||||
- **Frontend**: http://localhost:3002 (Vue 3 + Vite)
|
||||
- **Gateway**: http://localhost:8080 (Spring Cloud Gateway)
|
||||
- **Backend**: http://localhost:8084 (Spring Boot)
|
||||
- **Database**: PostgreSQL on localhost:55432
|
||||
- **Test User**: admin / Test@123
|
||||
|
||||
## Test Execution Summary
|
||||
|
||||
### 服务状态验证
|
||||
- ✅ 后端服务 (8084): 正常运行
|
||||
- ✅ 网关服务 (8080): 正常运行
|
||||
- ✅ 前端服务 (3002): 正常运行
|
||||
- ✅ 数据库连接: 正常
|
||||
|
||||
### 数据库验证
|
||||
- ✅ 用户表: 7条记录
|
||||
- ✅ 角色表: 8条记录
|
||||
- ✅ 菜单表: 51条记录
|
||||
- ✅ 字典类型表: 8条记录
|
||||
- ✅ 系统配置表: 9条记录
|
||||
|
||||
### API测试结果
|
||||
- ✅ 登录API: 正常工作,返回JWT token
|
||||
- ✅ 用户管理API: 正常工作,需要签名验证
|
||||
- ✅ 角色管理API: 正常工作,需要签名验证
|
||||
- ✅ 菜单管理API: 正常工作,需要签名验证
|
||||
- ✅ 字典管理API: 正常工作,需要签名验证
|
||||
- ✅ 系统配置API: 正常工作,需要签名验证
|
||||
|
||||
### 日志监控结果
|
||||
- ✅ 后端日志: 无ERROR或Exception
|
||||
- ⚠️ 网关日志: 有配置警告,但不影响功能
|
||||
- ✅ 前端日志: 未发现异步功能错误
|
||||
|
||||
## Issues
|
||||
|
||||
### ISSUE-001: API签名验证机制导致测试困难
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| **Severity** | high |
|
||||
| **Category** | functional |
|
||||
| **URL** | http://localhost:8080/api/* |
|
||||
| **Repro Video** | N/A |
|
||||
|
||||
**Description**
|
||||
|
||||
所有API请求都需要签名验证(X-Signature, X-Timestamp, X-Nonce),这导致:
|
||||
1. 直接使用curl或Postman测试API时会被拒绝
|
||||
2. 测试脚本需要实现签名生成逻辑,增加了测试复杂度
|
||||
3. 签名验证失败时,错误信息不够友好
|
||||
|
||||
**Expected Behavior**
|
||||
- 应该提供测试模式,允许跳过签名验证
|
||||
- 或者提供测试工具/库来简化签名生成
|
||||
|
||||
**Actual Behavior**
|
||||
- API返回401错误,提示签名验证失败
|
||||
- 错误信息:`{"error": "Unauthorized", "code": "INVALID_SIGNATURE", "message": "Request signature verification failed. Please ensure you have included valid X-Signature, X-Timestamp, and X-Nonce headers."}`
|
||||
|
||||
**Impact**
|
||||
- 增加了API测试的复杂度
|
||||
- 影响开发效率
|
||||
- 可能导致测试覆盖率不足
|
||||
|
||||
---
|
||||
|
||||
### ISSUE-002: 网关配置警告
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| **Severity** | medium |
|
||||
| **Category** | console |
|
||||
| **URL** | N/A |
|
||||
| **Repro Video** | N/A |
|
||||
|
||||
**Description**
|
||||
|
||||
网关启动时出现多个配置警告:
|
||||
1. `management.endpoint.env.enabled` 配置项使用了不兼容的目标类型
|
||||
2. `management.endpoint.loggers.enabled` 配置项使用了不兼容的目标类型
|
||||
3. `management.endpoint.metrics.enabled` 配置项使用了不兼容的目标类型
|
||||
4. `management.metrics.web.server.request.autotime.enabled` 配置项应该全局配置
|
||||
|
||||
**Expected Behavior**
|
||||
- 网关启动时不应该有配置警告
|
||||
- 配置文件应该符合Spring Boot 3.x的最佳实践
|
||||
|
||||
**Actual Behavior**
|
||||
- 网关启动时出现多个配置警告
|
||||
- 虽然不影响功能,但可能会在未来的Spring Boot版本中导致问题
|
||||
|
||||
**Impact**
|
||||
- 配置警告可能导致未来的兼容性问题
|
||||
- 影响日志的可读性
|
||||
|
||||
---
|
||||
|
||||
### ISSUE-003: Playwright测试执行卡住
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| **Severity** | medium |
|
||||
| **Category** | functional |
|
||||
| **URL** | N/A |
|
||||
| **Repro Video** | N/A |
|
||||
|
||||
**Description**
|
||||
|
||||
执行Playwright测试时,测试进程似乎卡住,没有输出任何内容:
|
||||
- 运行 `npm run test:e2e:journeys` 后,进程一直处于运行状态
|
||||
- 没有测试输出,没有错误信息
|
||||
- 需要手动终止进程
|
||||
|
||||
**Expected Behavior**
|
||||
- 测试应该正常执行并输出结果
|
||||
- 如果有问题,应该输出错误信息
|
||||
|
||||
**Actual Behavior**
|
||||
- 测试进程卡住,无输出
|
||||
- 无法判断测试是否在运行
|
||||
|
||||
**Impact**
|
||||
- 无法执行自动化测试
|
||||
- 影响CI/CD流程
|
||||
- 无法验证代码质量
|
||||
|
||||
---
|
||||
|
||||
### ISSUE-004: 测试数据清理不彻底
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| **Severity** | low |
|
||||
| **Category** | functional |
|
||||
| **URL** | N/A |
|
||||
| **Repro Video** | N/A |
|
||||
|
||||
**Description**
|
||||
|
||||
数据库中存在测试用户数据,说明之前的测试没有正确清理:
|
||||
- 用户表中有多条 `testuser_*` 开头的测试用户
|
||||
- 这些数据可能是之前测试遗留的
|
||||
|
||||
**Expected Behavior**
|
||||
- 每次测试后应该清理测试数据
|
||||
- 数据库应该保持干净状态
|
||||
|
||||
**Actual Behavior**
|
||||
- 数据库中存在遗留的测试数据
|
||||
- 可能影响后续测试的结果
|
||||
|
||||
**Impact**
|
||||
- 可能导致测试结果不准确
|
||||
- 影响数据质量
|
||||
|
||||
---
|
||||
|
||||
## Recommendations
|
||||
|
||||
### 高优先级
|
||||
1. **简化API签名验证机制**:
|
||||
- 提供测试模式,允许跳过签名验证
|
||||
- 或者提供测试工具/库来简化签名生成
|
||||
- 改进错误信息,提供更详细的调试信息
|
||||
|
||||
### 中优先级
|
||||
2. **修复网关配置警告**:
|
||||
- 更新配置文件以符合Spring Boot 3.x的最佳实践
|
||||
- 参考Spring Boot官方文档更新配置项
|
||||
|
||||
3. **修复Playwright测试问题**:
|
||||
- 检查Playwright配置
|
||||
- 确保测试能够正常执行
|
||||
- 添加超时机制,避免测试卡住
|
||||
|
||||
### 低优先级
|
||||
4. **改进测试数据清理**:
|
||||
- 在测试套件中添加清理步骤
|
||||
- 使用事务回滚或数据库快照来隔离测试数据
|
||||
|
||||
## Test Coverage
|
||||
|
||||
### 已测试的功能模块
|
||||
- ✅ 用户登录
|
||||
- ✅ 用户管理(查询)
|
||||
- ✅ 角色管理(查询)
|
||||
- ✅ 菜单管理(查询)
|
||||
- ✅ 字典管理(查询)
|
||||
- ✅ 系统配置(查询)
|
||||
|
||||
### 未测试的功能模块
|
||||
- ❌ 用户管理(创建、编辑、删除)
|
||||
- ❌ 角色管理(创建、编辑、删除)
|
||||
- ❌ 字典管理(创建、编辑、删除)
|
||||
- ❌ 系统配置(创建、编辑、删除)
|
||||
- ❌ 文件管理
|
||||
- ❌ 通知管理
|
||||
- ❌ 日志管理
|
||||
|
||||
## Conclusion
|
||||
|
||||
本次dogfood测试发现了一些关键问题:
|
||||
1. API签名验证机制增加了测试复杂度,需要改进
|
||||
2. 网关配置存在警告,需要修复以避免未来的兼容性问题
|
||||
3. Playwright测试执行存在问题,需要修复
|
||||
4. 测试数据清理不彻底,需要改进
|
||||
|
||||
建议优先解决API签名验证问题,以便能够更有效地进行自动化测试。同时,修复网关配置警告和Playwright测试问题,确保测试套件能够正常运行。
|
||||
@@ -1,25 +1,26 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
node: true
|
||||
},
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:vue/vue3-recommended',
|
||||
'plugin:@typescript-eslint/recommended'
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:react/recommended',
|
||||
'plugin:react-hooks/recommended',
|
||||
'plugin:react/jsx-runtime',
|
||||
],
|
||||
parser: 'vue-eslint-parser',
|
||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
parser: '@typescript-eslint/parser',
|
||||
sourceType: 'module'
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: { jsx: true },
|
||||
},
|
||||
plugins: ['vue', '@typescript-eslint'],
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'vue/multi-word-component-names': 'off',
|
||||
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
||||
'react/prop-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'warn',
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }]
|
||||
}
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
||||
},
|
||||
settings: { react: { version: 'detect' } },
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<title>Novalon 管理系统</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Generated
+6636
-1183
File diff suppressed because it is too large
Load Diff
@@ -7,9 +7,9 @@
|
||||
"dev": "vite",
|
||||
"dev:local": "vite --mode development-local",
|
||||
"dev:test": "vite --mode test",
|
||||
"build": "vue-tsc && vite build",
|
||||
"build:test": "vue-tsc && vite build --mode test",
|
||||
"build:prod": "vue-tsc && vite build --mode production",
|
||||
"build": "tsc --noEmit && vite build",
|
||||
"build:test": "tsc --noEmit && vite build --mode test",
|
||||
"build:prod": "tsc --noEmit && vite build --mode production",
|
||||
"preview": "vite preview",
|
||||
"test": "vitest --run",
|
||||
"test:ui": "vitest --ui",
|
||||
@@ -29,41 +29,52 @@
|
||||
"test:parallel-opt": "playwright test parallel-optimization.spec.ts",
|
||||
"test:all-opt": "playwright test edge-cases.spec.ts performance-optimization.spec.ts parallel-optimization.spec.ts",
|
||||
"test:monitor": "node e2e/performanceMonitor.js report",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx --fix --ignore-path .gitignore",
|
||||
"type-check": "tsc --noEmit",
|
||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx --fix --ignore-path .gitignore",
|
||||
"format": "prettier --write src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"axios": "^1.6.2",
|
||||
"@ant-design/icons": "^6.2.2",
|
||||
"@ant-design/pro-components": "^2.8.10",
|
||||
"@antv/g2": "^5.4.8",
|
||||
"@antv/g6": "^5.1.0",
|
||||
"@antv/l7": "^2.25.4",
|
||||
"@antv/l7-maps": "^2.25.4",
|
||||
"@antv/s2": "^2.7.0",
|
||||
"antd": "^5.29.3",
|
||||
"axios": "^1.16.0",
|
||||
"crypto-js": "^4.2.0",
|
||||
"date-fns": "^4.1.0",
|
||||
"dayjs": "^1.11.10",
|
||||
"element-plus": "^2.13.5",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"pinia": "^3.0.4",
|
||||
"vue": "^3.5.26",
|
||||
"vue-i18n": "^9.8.0",
|
||||
"vue-router": "^4.6.4"
|
||||
"react": "^19.2.5",
|
||||
"react-dom": "^19.2.5",
|
||||
"react-router": "^7.14.2",
|
||||
"zustand": "^5.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.40.1",
|
||||
"@testing-library/jest-dom": "^6.9.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@testing-library/user-event": "^14.6.1",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/node": "^20.10.0",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
||||
"@typescript-eslint/parser": "^6.18.1",
|
||||
"@vitejs/plugin-vue": "^6.0.3",
|
||||
"@vitejs/plugin-react": "^5.2.0",
|
||||
"@vitest/coverage-v8": "^4.1.1",
|
||||
"@vitest/ui": "^4.0.16",
|
||||
"@vue/test-utils": "^2.4.3",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-vue": "^9.19.2",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"eslint-plugin-react-refresh": "^0.4.26",
|
||||
"jsdom": "^27.4.0",
|
||||
"prettier": "^3.1.1",
|
||||
"terser": "^5.46.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.3.1",
|
||||
"vitest": "^4.0.16",
|
||||
"vue-tsc": "^3.2.2"
|
||||
"vitest": "^4.0.16"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ConfigProvider } from 'antd'
|
||||
import zhCN from 'antd/locale/zh_CN'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<ConfigProvider locale={zhCN}>
|
||||
<div style={{ padding: 24 }}>
|
||||
<h1>Novalon Manage System</h1>
|
||||
<p>React 19 迁移进行中...</p>
|
||||
</div>
|
||||
</ConfigProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -1,6 +0,0 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
@@ -1,43 +0,0 @@
|
||||
<template>
|
||||
<el-sub-menu
|
||||
v-if="menu.children && menu.children.length > 0"
|
||||
:index="String(menu.id)"
|
||||
>
|
||||
<template #title>
|
||||
<el-icon v-if="menu.icon">
|
||||
<component :is="iconComponents[menu.icon]" />
|
||||
</el-icon>
|
||||
<span>{{ menu.name }}</span>
|
||||
</template>
|
||||
<menu-item
|
||||
v-for="child in menu.children"
|
||||
:key="child.id"
|
||||
:menu="child"
|
||||
/>
|
||||
</el-sub-menu>
|
||||
|
||||
<el-menu-item
|
||||
v-else
|
||||
:index="menu.path"
|
||||
>
|
||||
<el-icon v-if="menu.icon">
|
||||
<component :is="iconComponents[menu.icon]" />
|
||||
</el-icon>
|
||||
<span>{{ menu.name }}</span>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { MenuItem as MenuItemType } from '@/stores/permission'
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import { markRaw, type Component } from 'vue'
|
||||
|
||||
const iconComponents: Record<string, Component> = {}
|
||||
Object.keys(ElementPlusIconsVue).forEach(key => {
|
||||
iconComponents[key] = markRaw(ElementPlusIconsVue[key as keyof typeof ElementPlusIconsVue])
|
||||
})
|
||||
|
||||
defineProps<{
|
||||
menu: MenuItemType
|
||||
}>()
|
||||
</script>
|
||||
@@ -1,33 +0,0 @@
|
||||
import type { Directive, DirectiveBinding } from 'vue'
|
||||
import { usePermissionStore } from '@/stores/permission'
|
||||
|
||||
export const permissionDirective: Directive = {
|
||||
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
||||
const permissionStore = usePermissionStore()
|
||||
|
||||
const { arg, value } = binding
|
||||
const checkType = arg || 'permission'
|
||||
|
||||
if (!value) {
|
||||
console.warn('v-permission 指令需要提供权限值')
|
||||
el.style.display = 'none'
|
||||
return
|
||||
}
|
||||
|
||||
let hasAccess = false
|
||||
|
||||
if (checkType === 'role') {
|
||||
hasAccess = permissionStore.hasRole(value)
|
||||
} else if (checkType === 'permission') {
|
||||
hasAccess = permissionStore.hasPermission(value)
|
||||
} else {
|
||||
console.warn(`未知的权限检查类型: ${checkType}`)
|
||||
el.style.display = 'none'
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasAccess) {
|
||||
el.style.display = 'none'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
<template>
|
||||
<el-container class="default-layout">
|
||||
<el-aside
|
||||
:width="collapsed ? '64px' : '200px'"
|
||||
class="aside"
|
||||
>
|
||||
<div class="logo">
|
||||
<span v-if="!collapsed">Novalon</span>
|
||||
<span v-else>N</span>
|
||||
</div>
|
||||
<el-menu
|
||||
:default-active="activeMenu"
|
||||
class="menu"
|
||||
:collapse="collapsed"
|
||||
background-color="#f5f7fa"
|
||||
text-color="#606266"
|
||||
active-text-color="#409eff"
|
||||
router
|
||||
>
|
||||
<div v-if="menuTree.length === 0" style="padding: 20px; text-align: center; color: #999;">
|
||||
菜单加载中...
|
||||
</div>
|
||||
<menu-item
|
||||
v-for="menu in menuTree"
|
||||
:key="menu.id"
|
||||
:menu="menu"
|
||||
/>
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header class="header">
|
||||
<el-icon
|
||||
class="trigger"
|
||||
@click="collapsed = !collapsed"
|
||||
>
|
||||
<Fold v-if="!collapsed" />
|
||||
<Expand v-else />
|
||||
</el-icon>
|
||||
<div class="header-right">
|
||||
<el-dropdown @command="handleCommand">
|
||||
<el-avatar :size="32">
|
||||
{{ username }}
|
||||
</el-avatar>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="profile">
|
||||
个人中心
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
command="logout"
|
||||
divided
|
||||
>
|
||||
退出登录
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-header>
|
||||
<el-main class="content">
|
||||
<router-view />
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { Fold, Expand } from '@element-plus/icons-vue'
|
||||
import { usePermissionStore } from '@/stores/permission'
|
||||
import MenuItem from '@/components/MenuItem.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const collapsed = ref(false)
|
||||
const username = ref(localStorage.getItem('username') || 'Admin')
|
||||
const permissionStore = usePermissionStore()
|
||||
|
||||
const activeMenu = computed(() => route.path)
|
||||
const menuTree = computed(() => {
|
||||
return permissionStore.menus
|
||||
})
|
||||
|
||||
const handleCommand = (command: string) => {
|
||||
if (command === 'profile') {
|
||||
router.push('/profile')
|
||||
} else if (command === 'logout') {
|
||||
permissionStore.clearPermissionData()
|
||||
localStorage.clear()
|
||||
router.push('/login')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const token = localStorage.getItem('token')
|
||||
|
||||
if (!token) {
|
||||
router.push('/login')
|
||||
} else if (!permissionStore.loaded) {
|
||||
permissionStore.initFromStorage()
|
||||
|
||||
if (!permissionStore.loaded || permissionStore.menus.length === 0) {
|
||||
try {
|
||||
await permissionStore.fetchUserMenus()
|
||||
} catch (error) {
|
||||
console.error('获取用户菜单失败:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="css">
|
||||
.default-layout {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.aside {
|
||||
background-color: #f5f7fa;
|
||||
transition: width 0.3s;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #303133;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.menu {
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
|
||||
.trigger {
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
transition: color 0.3s;
|
||||
&:hover { color: #409eff; }
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
margin: 16px;
|
||||
padding: 16px;
|
||||
background: #fff;
|
||||
min-height: calc(100vh - 96px);
|
||||
}
|
||||
</style>
|
||||
@@ -1,22 +0,0 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import ElementPlus from 'element-plus'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
import 'element-plus/dist/index.css'
|
||||
import router from './router'
|
||||
import App from './App.vue'
|
||||
import './assets/styles.css'
|
||||
import { permissionDirective } from './directives/permission'
|
||||
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app.use(ElementPlus, {
|
||||
locale: zhCn,
|
||||
})
|
||||
|
||||
app.directive('permission', permissionDirective)
|
||||
|
||||
app.mount('#app')
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
import './assets/styles.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
)
|
||||
Vendored
-9
@@ -1,10 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_SIGNATURE_SECRET: string
|
||||
readonly VITE_API_BASE_URL?: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
|
||||
@@ -2,31 +2,24 @@
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
|
||||
/* Linting */
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
/* Path mapping */
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'path'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, 'src')
|
||||
@@ -20,26 +20,22 @@ export default defineConfig({
|
||||
secure: false
|
||||
}
|
||||
},
|
||||
hmr: {
|
||||
overlay: false
|
||||
},
|
||||
hmr: { overlay: false },
|
||||
cors: true
|
||||
},
|
||||
build: {
|
||||
target: 'esnext',
|
||||
minify: 'terser',
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true,
|
||||
drop_debugger: true
|
||||
}
|
||||
compress: { drop_console: true, drop_debugger: true }
|
||||
},
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
'vue-vendor': ['vue', 'vue-router', 'pinia'],
|
||||
'element-plus': ['element-plus'],
|
||||
'utils': ['axios']
|
||||
'react-vendor': ['react', 'react-dom', 'react-router'],
|
||||
'antd': ['antd'],
|
||||
'antv': ['@antv/g2', '@antv/g6', '@antv/l7', '@antv/s2'],
|
||||
'utils': ['axios', 'date-fns']
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -47,15 +43,6 @@ export default defineConfig({
|
||||
reportCompressedSize: false
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: ['vue', 'vue-router', 'pinia', 'element-plus', 'axios'],
|
||||
exclude: []
|
||||
},
|
||||
css: {
|
||||
devSourcemap: false,
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
additionalData: `@import "@/styles/variables.scss";`
|
||||
}
|
||||
}
|
||||
include: ['react', 'react-dom', 'react-router', 'zustand', 'antd', 'axios']
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user