index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Layout from '@/views/Layout.vue'
  4. import axios from 'axios'
  5. import { getEffectivePermissions, hasPermission } from '@/utils/permissions'
  6. Vue.use(VueRouter)
  7. const routes = [
  8. {
  9. path: '/login',
  10. name: 'Login',
  11. component: () => import('@/views/Login.vue')
  12. },
  13. {
  14. path: '/403',
  15. name: 'Forbidden',
  16. component: { template: '<div style="text-align:center;padding:100px"><h1>403</h1><p>权限不足</p><router-link to="/">返回首页</router-link></div>' },
  17. meta: { title: '权限不足' }
  18. },
  19. {
  20. path: '/',
  21. component: Layout,
  22. redirect: '/dashboard',
  23. children: [
  24. {
  25. path: 'dashboard',
  26. name: 'Dashboard',
  27. component: () => import('@/views/Dashboard.vue'),
  28. meta: { title: '首页', perm: 'dashboard' }
  29. },
  30. {
  31. path: 'teacher-dashboard',
  32. name: 'TeacherDashboard',
  33. component: () => import('@/views/TeacherDashboard.vue'),
  34. meta: { title: '规划师首页', requiresTeacher: true, perm: 'dashboard' }
  35. },
  36. {
  37. path: 'admin/dashboard',
  38. name: 'AdminDashboard',
  39. component: () => import('@/views/admin/Dashboard'),
  40. meta: { title: '数据大屏', roles: ['admin'] }
  41. },
  42. // 家庭管理
  43. {
  44. path: 'families',
  45. name: 'Families',
  46. component: () => import('@/views/Families.vue'),
  47. meta: { title: '家庭列表', perm: 'family:list' }
  48. },
  49. {
  50. path: 'children',
  51. name: 'Children',
  52. component: () => import('@/views/Children.vue'),
  53. meta: { title: '孩子管理', perm: 'family:children' }
  54. },
  55. {
  56. path: 'points',
  57. name: 'Points',
  58. component: () => import('@/views/Points.vue'),
  59. meta: { title: '积分管理', perm: 'family:points' }
  60. },
  61. {
  62. path: 'points-log',
  63. name: 'PointsLog',
  64. component: () => import('@/views/admin/PointsLog.vue'),
  65. meta: { title: '积分记录', perm: 'family:points' }
  66. },
  67. {
  68. path: 'membership-center',
  69. name: 'MembershipCenter',
  70. component: () => import('@/views/admin/MembershipCenter.vue'),
  71. meta: { title: '会员中心', perm: 'system:config' }
  72. },
  73. // 任务管理
  74. {
  75. path: 'tasks',
  76. name: 'Tasks',
  77. component: () => import('@/views/Tasks.vue'),
  78. meta: { title: '任务列表', perm: 'task:list' }
  79. },
  80. {
  81. path: 'task-templates',
  82. name: 'TaskTemplates',
  83. component: () => import('@/views/TaskTemplates.vue'),
  84. meta: { title: '任务模板', perm: 'task:templates' }
  85. },
  86. {
  87. path: 'growth-task',
  88. name: 'GrowthTaskManagement',
  89. component: () => import('@/views/admin/GrowthTaskManagement'),
  90. meta: { title: '成长任务管理', perm: 'task:list' }
  91. },
  92. // 奖励管理
  93. {
  94. path: 'rewards',
  95. name: 'Rewards',
  96. component: () => import('@/views/Rewards.vue'),
  97. meta: { title: '奖励列表', perm: 'family:rewards' }
  98. },
  99. {
  100. path: 'wishes',
  101. name: 'Wishes',
  102. component: () => import('@/views/Wishes.vue'),
  103. meta: { title: '心愿管理', perm: 'family:wishes' }
  104. },
  105. // 成长规划师管理
  106. {
  107. path: 'guide-packages',
  108. name: 'GuidePackages',
  109. component: () => import('@/views/GuidePackages.vue'),
  110. meta: { title: '成长规划师任务模板', requiresTeacher: true, perm: 'biz:packages' }
  111. },
  112. {
  113. path: 'guide-family-task',
  114. name: 'GuideFamilyTask',
  115. component: () => import('@/views/GuideFamilyTask.vue'),
  116. meta: { title: '家庭任务管理', requiresTeacher: true, perm: 'service:families' }
  117. },
  118. {
  119. path: 'teacher-consult',
  120. name: 'TeacherConsult',
  121. component: () => import('@/views/TeacherConsult.vue'),
  122. meta: { title: '家长咨询', requiresTeacher: true, perm: 'assessment:consult' }
  123. },
  124. {
  125. path: 'teacher-families',
  126. name: 'TeacherFamilies',
  127. component: () => import('@/views/teacher/TeacherFamilies.vue'),
  128. meta: { title: '我的家庭', requiresTeacher: true, perm: 'service:families' }
  129. },
  130. {
  131. path: 'teacher-team',
  132. name: 'TeacherTeam',
  133. component: () => import('@/views/teacher/TeacherTeam.vue'),
  134. meta: { title: '我的团队', requiresTeacher: true, perm: 'service:team' }
  135. },
  136. {
  137. path: 'teacher-packages',
  138. name: 'TeacherPackages',
  139. component: () => import('@/views/teacher/TeacherPackages.vue'),
  140. meta: { title: '任务模板管理', requiresTeacher: true, perm: 'biz:packages' }
  141. },
  142. {
  143. path: 'teacher-orders',
  144. name: 'TeacherOrders',
  145. component: () => import('@/views/teacher/TeacherOrders.vue'),
  146. meta: { title: '订单与佣金', requiresTeacher: true, perm: 'biz:orders' }
  147. },
  148. // 系统管理
  149. {
  150. path: 'users',
  151. name: 'Users',
  152. component: () => import('@/views/Users.vue'),
  153. meta: { title: '用户管理', perm: 'system:users' }
  154. },
  155. {
  156. path: 'review-center',
  157. name: 'ReviewCenter',
  158. component: () => import('@/views/admin/ReviewCenter.vue'),
  159. meta: { title: '审核中心', perm: 'audit' }
  160. },
  161. {
  162. path: 'operation-logs',
  163. name: 'OperationLogs',
  164. component: () => import('@/views/OperationLogs.vue'),
  165. meta: { title: '操作日志', perm: 'system:logs' }
  166. },
  167. // 服务管理(管理员)
  168. {
  169. path: 'service-role-applications',
  170. name: 'ServiceRoleApplications',
  171. component: () => import('@/views/service/ServiceRoleApplications.vue'),
  172. meta: { title: '服务角色申请审核', perm: 'audit' }
  173. },
  174. {
  175. path: 'teacher-messages',
  176. name: 'TeacherMessages',
  177. component: () => import('@/views/teacher/TeacherMessages.vue'),
  178. meta: { title: '消息中心', requiresTeacher: true, perm: 'messages' }
  179. },
  180. {
  181. path: 'teacher-assessment',
  182. name: 'TeacherAssessment',
  183. component: () => import('@/views/teacher/TeacherAssessment.vue'),
  184. meta: { title: 'DAN测评管理', requiresTeacher: true, perm: 'assessment:dan' }
  185. },
  186. {
  187. path: 'assessment-admin',
  188. name: 'AssessmentAdmin',
  189. component: () => import('@/views/admin/Assessment.vue'),
  190. meta: { title: '测评管理', perm: 'assessment:dan' }
  191. },
  192. {
  193. path: 'assessment-assign',
  194. name: 'AssessmentAssign',
  195. component: () => import('@/views/admin/AssessmentAssign.vue'),
  196. meta: { title: '待分配规划师', perm: 'assessment:dan' }
  197. },
  198. {
  199. path: 'assessment-orders',
  200. name: 'AssessmentOrders',
  201. component: () => import('@/views/admin/AssessmentOrders.vue'),
  202. meta: { title: '测评订单', perm: 'assessment:dan' }
  203. },
  204. {
  205. path: 'dan-execution',
  206. name: 'DanExecution',
  207. component: () => import('@/views/admin/DanExecution.vue'),
  208. meta: { title: 'DAN服务执行', perm: 'assessment:dan' }
  209. },
  210. {
  211. path: 'dan-settlement',
  212. name: 'DanSettlement',
  213. component: () => import('@/views/admin/DanSettlement.vue'),
  214. meta: { title: 'DAN结算管理', perm: 'assessment:dan' }
  215. },
  216. {
  217. path: 'product-manage',
  218. name: 'ProductManage',
  219. component: () => import('@/views/admin/ProductManage.vue'),
  220. meta: { title: '商品管理', perm: 'commerce:products' }
  221. },
  222. {
  223. path: 'product-edit',
  224. name: 'ProductEdit',
  225. component: () => import('@/views/admin/ProductEdit.vue'),
  226. meta: { title: '商品编辑', perm: 'commerce:products' }
  227. },
  228. {
  229. path: 'assessment-products',
  230. name: 'AssessmentProducts',
  231. component: () => import('@/views/admin/AssessmentProducts.vue'),
  232. meta: { title: '测评商品管理', perm: 'commerce:products' }
  233. },
  234. {
  235. path: 'assessment-plan-rules',
  236. name: 'AssessmentPlanRules',
  237. component: () => import('@/views/admin/AssessmentPlanRules.vue'),
  238. meta: { title: '方案生成规则', perm: 'plan:rules' }
  239. },
  240. {
  241. path: 'plan-management',
  242. name: 'PlanManagement',
  243. component: () => import('@/views/admin/PlanManagement.vue'),
  244. meta: { title: '方案管理', perm: 'plan:manage' }
  245. },
  246. {
  247. path: 'category-manage',
  248. name: 'CategoryManage',
  249. component: () => import('@/views/admin/CategoryManage.vue'),
  250. meta: { title: '商品分类', perm: 'commerce:category' }
  251. },
  252. {
  253. path: 'order-manage',
  254. name: 'OrderManage',
  255. component: () => import('@/views/admin/OrderManage.vue'),
  256. meta: { title: '订单管理', perm: 'commerce:orders' }
  257. },
  258. {
  259. path: 'pending-refund',
  260. name: 'PendingRefund',
  261. component: () => import('@/views/admin/PendingRefund.vue'),
  262. meta: { title: '待退款管理', perm: 'commerce:orders' }
  263. },
  264. {
  265. path: 'order-detail/:orderNo',
  266. name: 'OrderDetail',
  267. component: () => import('@/views/admin/OrderDetail.vue'),
  268. meta: { title: '订单详情', perm: 'commerce:orders' }
  269. },
  270. {
  271. path: 'sys-config',
  272. name: 'SysConfig',
  273. component: () => import('@/views/admin/SysConfig.vue'),
  274. meta: { title: '系统配置', perm: 'system:config' }
  275. },
  276. {
  277. path: 'energy-sandbox',
  278. name: 'EnergySandbox',
  279. component: () => import('@/views/admin/EnergySandbox.vue'),
  280. meta: { title: '五维能量', perm: 'energy' }
  281. },
  282. {
  283. path: 'energy-rule',
  284. name: 'EnergyRuleManagement',
  285. component: () => import('@/views/admin/EnergyRuleManagement.vue'),
  286. meta: { title: '能量规则管理', perm: 'energy' }
  287. },
  288. {
  289. path: 'energy-behavior-config',
  290. name: 'EnergyBehaviorConfig',
  291. component: () => import('@/views/admin/EnergyBehaviorConfig.vue'),
  292. meta: { title: '能量行为配置', perm: 'energy' }
  293. },
  294. // ========== 文章管理 ==========
  295. {
  296. path: 'article-categories',
  297. name: 'ArticleCategory',
  298. component: () => import('@/views/admin/ArticleCategory.vue'),
  299. meta: { title: '文章分类', perm: 'articles:categories' }
  300. },
  301. {
  302. path: 'article-manage',
  303. name: 'ArticleManage',
  304. component: () => import('@/views/admin/ArticleManage.vue'),
  305. meta: { title: '文章管理', perm: 'articles:manage' }
  306. },
  307. {
  308. path: 'article-edit',
  309. name: 'ArticleEdit',
  310. component: () => import('@/views/admin/ArticleEdit.vue'),
  311. meta: { title: '文章编辑', perm: 'articles:manage' }
  312. },
  313. {
  314. path: 'comment-review',
  315. name: 'CommentReview',
  316. component: () => import('@/views/admin/CommentReview.vue'),
  317. meta: { title: '评论审核', perm: 'articles:manage' }
  318. },
  319. {
  320. path: 'periodic-service-config',
  321. name: 'PeriodicServiceConfig',
  322. component: () => import('@/views/admin/PeriodicServiceConfig.vue'),
  323. meta: { title: '周期性服务配置', perm: 'admin' }
  324. },
  325. {
  326. path: 'knowledge-tags',
  327. name: 'KnowledgeTag',
  328. component: () => import('@/views/admin/KnowledgeTag.vue'),
  329. meta: { title: '知识标签', perm: 'articles:categories' }
  330. },
  331. // ========== 佣金推荐系统 ==========
  332. {
  333. path: 'product-profit-rate',
  334. name: 'ProductProfitRate',
  335. component: () => import('@/views/admin/ProductProfitRate.vue'),
  336. meta: { title: '产品利润率', perm: 'commerce:profit-rate' }
  337. },
  338. {
  339. path: 'product-ppoint',
  340. name: 'ProductPpointManage',
  341. component: () => import('@/views/admin/ProductPpointManage.vue'),
  342. meta: { title: 'P点配置', perm: 'commerce:ppoint' }
  343. },
  344. {
  345. path: 'supply-system',
  346. name: 'SupplySystemList',
  347. component: () => import('@/views/admin/supply-system/List.vue'),
  348. meta: { title: '供应商体系', perm: 'system:supply' }
  349. },
  350. {
  351. path: 'supply-system/create',
  352. name: 'SupplySystemCreate',
  353. component: () => import('@/views/admin/supply-system/Form.vue'),
  354. meta: { title: '新建体系', perm: 'system:supply' }
  355. },
  356. {
  357. path: 'supply-system/:id',
  358. name: 'SupplySystemDetail',
  359. component: () => import('@/views/admin/supply-system/Detail.vue'),
  360. meta: { title: '体系详情', perm: 'system:supply' },
  361. props: true
  362. },
  363. {
  364. path: 'supplier-products',
  365. name: 'SupplierProducts',
  366. component: () => import('@/views/admin/SupplierProductManage.vue'),
  367. meta: { title: '商品管理', perm: 'commerce:product' }
  368. },
  369. {
  370. path: 'supply-system/:id/edit',
  371. name: 'SupplySystemEdit',
  372. component: () => import('@/views/admin/supply-system/Form.vue'),
  373. meta: { title: '编辑体系', perm: 'system:supply' },
  374. props: true
  375. },
  376. {
  377. path: 'supply-hierarchy/change-requests',
  378. name: 'SupplyHierarchyChangeRequests',
  379. component: () => import('@/views/admin/supply-hierarchy/ChangeRequest.vue'),
  380. meta: { title: '更换上级审核', perm: 'system:supply' }
  381. },
  382. // ========== 供应商管理 (supplier_admin) ==========
  383. {
  384. path: 'supply-manage',
  385. name: 'SupplyManage',
  386. component: () => import('@/views/admin/supply-manage/List.vue'),
  387. meta: { title: '供应商管理', perm: 'supply:manage' }
  388. },
  389. {
  390. path: 'supply-manage/create',
  391. name: 'SupplyManageCreate',
  392. component: () => import('@/views/admin/supply-manage/Form.vue'),
  393. meta: { title: '新增供应商', perm: 'supply:manage' }
  394. },
  395. {
  396. path: 'supply-manage/:id',
  397. name: 'SupplyManageDetail',
  398. component: () => import('@/views/admin/supply-manage/Detail.vue'),
  399. meta: { title: '供应商详情', perm: 'supply:manage' },
  400. props: true
  401. },
  402. {
  403. path: 'supply-manage/:id/edit',
  404. name: 'SupplyManageEdit',
  405. component: () => import('@/views/admin/supply-manage/Form.vue'),
  406. meta: { title: '编辑供应商', perm: 'supply:manage' },
  407. props: true
  408. },
  409. {
  410. path: 'zodiac-configs',
  411. name: 'ZodiacConfigs',
  412. component: () => import('@/views/admin/ZodiacConfigs.vue'),
  413. meta: { title: '星座配置', perm: 'system:config' }
  414. },
  415. {
  416. path: 'bazi-configs',
  417. name: 'BaziConfigs',
  418. component: () => import('@/views/admin/BaziConfigs.vue'),
  419. meta: { title: '八字配置', perm: 'system:config' }
  420. },
  421. {
  422. path: 'blood-type-configs',
  423. name: 'BloodTypeConfigs',
  424. component: () => import('@/views/admin/BloodTypeConfigs.vue'),
  425. meta: { title: '血型配置', perm: 'system:config' }
  426. },
  427. // ========== 饮食管理 (admin) ==========
  428. {
  429. path: 'foods',
  430. name: 'Foods',
  431. component: () => import('@/views/admin/Foods.vue'),
  432. meta: { title: '食材管理', perm: 'diet:foods' }
  433. },
  434. {
  435. path: 'recipes',
  436. name: 'Recipes',
  437. component: () => import('@/views/admin/Recipes.vue'),
  438. meta: { title: '食谱管理', perm: 'diet:recipes' }
  439. },
  440. {
  441. path: 'seasonal-foods',
  442. name: 'SeasonalFoods',
  443. component: () => import('@/views/admin/SeasonalFoods.vue'),
  444. meta: { title: '应季食材', perm: 'diet:seasonal' }
  445. },
  446. {
  447. path: 'my-families',
  448. name: 'MyFamilies',
  449. component: () => import('@/views/teacher/FamilyList.vue'),
  450. meta: { title: '我的家庭', perm: 'service:family' }
  451. },
  452. {
  453. path: 'growth-records',
  454. name: 'GrowthRecords',
  455. component: () => import('@/views/teacher/GrowthRecords.vue'),
  456. meta: { title: '成长记录', perm: 'growth:records' }
  457. },
  458. {
  459. path: 'growth-plans',
  460. name: 'GrowthPlans',
  461. component: () => import('@/views/teacher/GrowthPlans.vue'),
  462. meta: { title: '成长计划', perm: 'growth:plans' }
  463. },
  464. {
  465. path: 'health-reports',
  466. name: 'HealthReports',
  467. component: () => import('@/views/nutritionist/HealthReports.vue'),
  468. meta: { title: '健康报告', perm: 'health:reports' }
  469. },
  470. {
  471. path: 'report-management',
  472. name: 'ReportManagement',
  473. component: () => import('@/views/admin/ReportManagement.vue'),
  474. meta: { title: '报告管理', perm: 'report:management' }
  475. },
  476. {
  477. path: 'health-report-audit',
  478. name: 'HealthReportAudit',
  479. component: () => import('@/views/health/HealthReportAudit.vue'),
  480. meta: { title: '报告草稿审核', perm: 'health:reports' }
  481. },
  482. {
  483. path: 'health-indicators',
  484. name: 'HealthIndicators',
  485. component: () => import('@/views/nutritionist/HealthIndicators.vue'),
  486. meta: { title: '健康指标', perm: 'health:indicators' }
  487. },
  488. {
  489. path: 'health-checkins',
  490. name: 'HealthCheckins',
  491. component: () => import('@/views/nutritionist/HealthCheckins.vue'),
  492. meta: { title: '健康打卡', perm: 'health:checkins' }
  493. },
  494. {
  495. path: 'emotion-alert',
  496. name: 'EmotionAlertManage',
  497. component: () => import('@/views/admin/EmotionAlertManage.vue'),
  498. meta: { title: '情绪告警管理', perm: 'health:checkins' }
  499. },
  500. {
  501. path: 'nutrition-mappings',
  502. name: 'NutritionMappings',
  503. component: () => import('@/views/nutritionist/NutritionMappings.vue'),
  504. meta: { title: '营养素映射管理', perm: 'health:mappings' }
  505. },
  506. {
  507. path: 'activities',
  508. name: 'Activities',
  509. component: () => import('@/views/admin/Activities.vue'),
  510. meta: { title: '活动列表', perm: 'activity:list' }
  511. },
  512. {
  513. path: 'activity-edit',
  514. name: 'ActivityEdit',
  515. component: () => import('@/views/admin/ActivityEdit.vue'),
  516. meta: { title: '活动编辑', perm: 'activity:list' }
  517. },
  518. {
  519. path: 'activity-review',
  520. name: 'ActivityReview',
  521. component: () => import('@/views/admin/ActivityReview.vue'),
  522. meta: { title: '活动审核', perm: 'activity:review' }
  523. },
  524. {
  525. path: 'activity-registration-review',
  526. name: 'ActivityRegistrationReview',
  527. component: () => import('@/views/admin/ActivityRegistrationReview.vue'),
  528. meta: { title: '活动报名审核', perm: 'activity:review' }
  529. },
  530. // ========== 维度配置 + 知识库管理 ==========
  531. {
  532. path: 'coupon',
  533. name: 'CouponManagement',
  534. component: () => import('@/views/admin/CouponManagement'),
  535. meta: { title: '优惠券管理', perm: 'marketing:coupon' }
  536. },
  537. {
  538. path: 'promotion',
  539. name: 'PromotionManagement',
  540. component: () => import('@/views/admin/PromotionManagement'),
  541. meta: { title: '推广管理', perm: 'marketing:promotion' }
  542. },
  543. {
  544. path: 'family-earnings',
  545. name: 'FamilyEarnings',
  546. component: () => import('@/views/admin/FamilyEarnings.vue'),
  547. meta: { title: '家庭收益管理', perm: 'marketing:promotion' }
  548. },
  549. {
  550. path: 'family-earnings-withdraw',
  551. name: 'FamilyEarningsWithdraw',
  552. component: () => import('@/views/admin/FamilyEarningsWithdraw.vue'),
  553. meta: { title: '家庭收益提现审核', perm: 'audit:withdraw' }
  554. },
  555. {
  556. path: 'dimension-config',
  557. name: 'DimensionConfig',
  558. component: () => import('@/views/admin/dimension'),
  559. meta: { title: '维度配置', perm: 'system:config' }
  560. },
  561. {
  562. path: 'knowledge-base',
  563. name: 'KnowledgeBase',
  564. component: () => import('@/views/admin/knowledge'),
  565. meta: { title: '知识库管理', perm: 'system:config' }
  566. },
  567. {
  568. path: 'health-knowledge',
  569. name: 'HealthKnowledge',
  570. component: () => import('@/views/admin/health-knowledge'),
  571. meta: { title: '健康知识库管理', perm: 'system:config' }
  572. },
  573. // ========== 健康维度配置 ==========
  574. {
  575. path: 'health-norm-config',
  576. name: 'HealthNormConfig',
  577. component: () => import('@/views/admin/dimension-config'),
  578. meta: { title: '健康常模配置', perm: 'system:config' }
  579. },
  580. {
  581. path: 'health-data-source',
  582. name: 'HealthDataSource',
  583. component: () => import('@/views/admin/data-source-config'),
  584. meta: { title: '健康数据源配置', perm: 'system:config' }
  585. },
  586. {
  587. path: 'health-energy-config',
  588. name: 'HealthEnergyConfig',
  589. component: () => import('@/views/admin/HealthEnergyConfig'),
  590. meta: { title: '七维能量配置', perm: 'system:config' }
  591. },
  592. {
  593. path: 'energy-config',
  594. name: 'EnergyConfig',
  595. component: () => import('@/views/admin/energy-config/WuxingConfig'),
  596. meta: { title: '五行能量配置', perm: 'system:config' }
  597. },
  598. {
  599. path: 'indicators',
  600. name: 'IndicatorManage',
  601. component: () => import('@/views/admin/indicators'),
  602. meta: { title: '指标管理', perm: 'system:config' }
  603. },
  604. // ========== 虚拟服务商团队管理 ==========
  605. {
  606. path: 'virtual-teams',
  607. name: 'VirtualTeamList',
  608. component: () => import('@/views/admin/VirtualTeamList'),
  609. meta: { title: '虚拟团队管理', perm: 'system:config' }
  610. },
  611. {
  612. path: 'virtual-team-detail/:systemId',
  613. name: 'VirtualTeamDetail',
  614. component: () => import('@/views/admin/VirtualTeamDetail'),
  615. meta: { title: '团队成员管理', perm: 'system:config' },
  616. props: true
  617. },
  618. // ========== 电商供应商管理 ==========
  619. {
  620. path: 'ecom-supplier',
  621. name: 'EcomSupplierManage',
  622. component: () => import('@/views/admin/EcomSupplierManage'),
  623. meta: { title: '电商供应商管理', perm: 'ecom:supplier' }
  624. },
  625. {
  626. path: 'badge-manage',
  627. name: 'BadgeManage',
  628. component: () => import('@/views/admin/BadgeManage'),
  629. meta: { title: '勋章管理', perm: 'system:config' }
  630. }
  631. ]
  632. }
  633. ]
  634. const router = new VueRouter({
  635. mode: 'history',
  636. base: process.env.BASE_URL,
  637. routes
  638. })
  639. // Token 验证缓存:避免 redirect 链中重复调用 /api/admin-auth/info
  640. let tokenValidationCache = { token: '', timestamp: 0 }
  641. const TOKEN_CACHE_TTL = 30000 // 30秒内不重复验证
  642. async function validateToken(token) {
  643. try {
  644. const baseURL = process.env.VUE_APP_BASE_API || ''
  645. const res = await axios.post(`${baseURL}/api/admin-auth/info`, {}, {
  646. headers: { Authorization: `Bearer ${token}` },
  647. validateStatus: () => true
  648. })
  649. return res.status === 200 && res.data?.code === 200
  650. } catch (e) {
  651. return false
  652. }
  653. }
  654. router.beforeEach(async (to, from, next) => {
  655. const token = localStorage.getItem('token')
  656. const role = localStorage.getItem('role')
  657. // 1. 登录页允许访问
  658. if (to.path === '/login') {
  659. // 如果已有token和role,直接跳转到对应首页
  660. if (token && role === 'teacher') {
  661. return next('/teacher-dashboard')
  662. }
  663. return next()
  664. }
  665. // 2. 无Token强制跳转
  666. if (!token) {
  667. return next('/login')
  668. }
  669. // 3. Token有效性验证 (使用缓存避免 redirect 链重复调用)
  670. const now = Date.now()
  671. let isValid = false
  672. if (tokenValidationCache.token === token && (now - tokenValidationCache.timestamp) < TOKEN_CACHE_TTL) {
  673. isValid = true
  674. } else {
  675. isValid = await validateToken(token)
  676. if (isValid) {
  677. tokenValidationCache = { token, timestamp: now }
  678. }
  679. }
  680. if (!isValid) {
  681. tokenValidationCache = { token: '', timestamp: 0 }
  682. localStorage.clear()
  683. return next('/login')
  684. }
  685. // 3.5 规划师访问 /dashboard → 跳转规划师仪表板
  686. if (role === 'teacher' && to.path === '/dashboard') {
  687. return next('/teacher-dashboard')
  688. }
  689. // 4. 权限检查:如果路由有 perm 要求,检查用户权限
  690. const requiredPerm = to.meta && to.meta.perm
  691. if (requiredPerm) {
  692. const rolesStr = localStorage.getItem('roles')
  693. const roles = rolesStr ? JSON.parse(rolesStr) : [localStorage.getItem('role')]
  694. const perms = getEffectivePermissions(roles)
  695. if (!hasPermission(perms, requiredPerm)) {
  696. console.warn('Access denied: insufficient permissions for', to.name)
  697. return next({ path: '/', query: { accessDenied: 'no-permission' }, replace: true })
  698. }
  699. }
  700. return next()
  701. })
  702. // Suppress navigation guard redirect errors (teacher/admin route cross-access)
  703. const originalPush = VueRouter.prototype.push
  704. VueRouter.prototype.push = function push(location) {
  705. return originalPush.call(this, location).catch(err => err)
  706. }
  707. export default router