index.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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: 'package-audit',
  157. name: 'PackageAudit',
  158. component: () => import('@/views/PackageAudit.vue'),
  159. meta: { title: '套餐审核', perm: 'audit:package' }
  160. },
  161. {
  162. path: 'guide-audit',
  163. name: 'GuideAudit',
  164. component: () => import('@/views/GuideAudit.vue'),
  165. meta: { title: '成长规划师审核', perm: 'audit:guide' }
  166. },
  167. {
  168. path: 'operation-logs',
  169. name: 'OperationLogs',
  170. component: () => import('@/views/OperationLogs.vue'),
  171. meta: { title: '操作日志', perm: 'system:logs' }
  172. },
  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: 'vendor-review',
  194. name: 'VendorReview',
  195. component: () => import('@/views/admin/VendorReview.vue'),
  196. meta: { title: '服务商审核', perm: 'audit:vendor' }
  197. },
  198. {
  199. path: 'butler-review',
  200. name: 'ButlerReview',
  201. component: () => import('@/views/admin/ButlerReview.vue'),
  202. meta: { title: '管家审核', perm: 'audit:vendor' }
  203. },
  204. {
  205. path: 'product-manage',
  206. name: 'ProductManage',
  207. component: () => import('@/views/admin/ProductManage.vue'),
  208. meta: { title: '商品管理', perm: 'commerce:products' }
  209. },
  210. {
  211. path: 'product-edit',
  212. name: 'ProductEdit',
  213. component: () => import('@/views/admin/ProductEdit.vue'),
  214. meta: { title: '商品编辑', perm: 'commerce:products' }
  215. },
  216. {
  217. path: 'assessment-products',
  218. name: 'AssessmentProducts',
  219. component: () => import('@/views/admin/AssessmentProducts.vue'),
  220. meta: { title: '测评商品管理', perm: 'commerce:products' }
  221. },
  222. {
  223. path: 'assessment-plan-rules',
  224. name: 'AssessmentPlanRules',
  225. component: () => import('@/views/admin/AssessmentPlanRules.vue'),
  226. meta: { title: '方案生成规则', perm: 'plan:rules' }
  227. },
  228. {
  229. path: 'plan-management',
  230. name: 'PlanManagement',
  231. component: () => import('@/views/admin/PlanManagement.vue'),
  232. meta: { title: '方案管理', perm: 'plan:manage' }
  233. },
  234. {
  235. path: 'category-manage',
  236. name: 'CategoryManage',
  237. component: () => import('@/views/admin/CategoryManage.vue'),
  238. meta: { title: '商品分类', perm: 'commerce:category' }
  239. },
  240. {
  241. path: 'order-manage',
  242. name: 'OrderManage',
  243. component: () => import('@/views/admin/OrderManage.vue'),
  244. meta: { title: '订单管理', perm: 'commerce:orders' }
  245. },
  246. {
  247. path: 'pending-refund',
  248. name: 'PendingRefund',
  249. component: () => import('@/views/admin/PendingRefund.vue'),
  250. meta: { title: '待退款管理', perm: 'commerce:orders' }
  251. },
  252. {
  253. path: 'order-detail/:orderNo',
  254. name: 'OrderDetail',
  255. component: () => import('@/views/admin/OrderDetail.vue'),
  256. meta: { title: '订单详情', perm: 'commerce:orders' }
  257. },
  258. {
  259. path: 'sys-config',
  260. name: 'SysConfig',
  261. component: () => import('@/views/admin/SysConfig.vue'),
  262. meta: { title: '系统配置', perm: 'system:config' }
  263. },
  264. {
  265. path: 'energy-sandbox',
  266. name: 'EnergySandbox',
  267. component: () => import('@/views/admin/EnergySandbox.vue'),
  268. meta: { title: '五维能量', perm: 'energy' }
  269. },
  270. {
  271. path: 'energy-rule',
  272. name: 'EnergyRuleManagement',
  273. component: () => import('@/views/admin/EnergyRuleManagement.vue'),
  274. meta: { title: '能量规则管理', perm: 'energy' }
  275. },
  276. // ========== 文章管理 ==========
  277. {
  278. path: 'article-categories',
  279. name: 'ArticleCategory',
  280. component: () => import('@/views/admin/ArticleCategory.vue'),
  281. meta: { title: '文章分类', perm: 'articles:categories' }
  282. },
  283. {
  284. path: 'article-manage',
  285. name: 'ArticleManage',
  286. component: () => import('@/views/admin/ArticleManage.vue'),
  287. meta: { title: '文章管理', perm: 'articles:manage' }
  288. },
  289. {
  290. path: 'article-edit',
  291. name: 'ArticleEdit',
  292. component: () => import('@/views/admin/ArticleEdit.vue'),
  293. meta: { title: '文章编辑', perm: 'articles:manage' }
  294. },
  295. {
  296. path: 'knowledge-tags',
  297. name: 'KnowledgeTag',
  298. component: () => import('@/views/admin/KnowledgeTag.vue'),
  299. meta: { title: '知识标签', perm: 'articles:categories' }
  300. },
  301. // ========== 佣金推荐系统 ==========
  302. {
  303. path: 'product-profit-rate',
  304. name: 'ProductProfitRate',
  305. component: () => import('@/views/admin/ProductProfitRate.vue'),
  306. meta: { title: '产品利润率', perm: 'commerce:profit-rate' }
  307. },
  308. {
  309. path: 'product-ppoint',
  310. name: 'ProductPpointManage',
  311. component: () => import('@/views/admin/ProductPpointManage.vue'),
  312. meta: { title: 'P点配置', perm: 'commerce:ppoint' }
  313. },
  314. {
  315. path: 'withdraw-audit',
  316. name: 'WithdrawAudit',
  317. component: () => import('@/views/admin/WithdrawAudit.vue'),
  318. meta: { title: '提现审核', perm: 'audit:withdraw' }
  319. },
  320. {
  321. path: 'education-systems',
  322. name: 'EducationSystems',
  323. component: () => import('@/views/admin/EducationSystems.vue'),
  324. meta: { title: '教育体系管理', perm: 'system:education' }
  325. },
  326. {
  327. path: 'supply-system',
  328. name: 'SupplySystemList',
  329. component: () => import('@/views/admin/supply-system/List.vue'),
  330. meta: { title: '供应商体系', perm: 'system:supply' }
  331. },
  332. {
  333. path: 'supply-system/create',
  334. name: 'SupplySystemCreate',
  335. component: () => import('@/views/admin/supply-system/Form.vue'),
  336. meta: { title: '新建体系', perm: 'system:supply' }
  337. },
  338. {
  339. path: 'supply-system/:id',
  340. name: 'SupplySystemDetail',
  341. component: () => import('@/views/admin/supply-system/Detail.vue'),
  342. meta: { title: '体系详情', perm: 'system:supply' },
  343. props: true
  344. },
  345. {
  346. path: 'supplier-products',
  347. name: 'SupplierProducts',
  348. component: () => import('@/views/admin/SupplierProductManage.vue'),
  349. meta: { title: '商品管理', perm: 'commerce:product' }
  350. },
  351. {
  352. path: 'supply-system/:id/edit',
  353. name: 'SupplySystemEdit',
  354. component: () => import('@/views/admin/supply-system/Form.vue'),
  355. meta: { title: '编辑体系', perm: 'system:supply' },
  356. props: true
  357. },
  358. {
  359. path: 'supply-hierarchy/change-requests',
  360. name: 'SupplyHierarchyChangeRequests',
  361. component: () => import('@/views/admin/supply-hierarchy/ChangeRequest.vue'),
  362. meta: { title: '更换上级审核', perm: 'system:supply' }
  363. },
  364. // ========== 供应商管理 (supplier_admin) ==========
  365. {
  366. path: 'supply-manage',
  367. name: 'SupplyManage',
  368. component: () => import('@/views/admin/supply-manage/List.vue'),
  369. meta: { title: '供应商管理', perm: 'supply:manage' }
  370. },
  371. {
  372. path: 'supply-manage/create',
  373. name: 'SupplyManageCreate',
  374. component: () => import('@/views/admin/supply-manage/Form.vue'),
  375. meta: { title: '新增供应商', perm: 'supply:manage' }
  376. },
  377. {
  378. path: 'supply-manage/:id',
  379. name: 'SupplyManageDetail',
  380. component: () => import('@/views/admin/supply-manage/Detail.vue'),
  381. meta: { title: '供应商详情', perm: 'supply:manage' },
  382. props: true
  383. },
  384. {
  385. path: 'supply-manage/:id/edit',
  386. name: 'SupplyManageEdit',
  387. component: () => import('@/views/admin/supply-manage/Form.vue'),
  388. meta: { title: '编辑供应商', perm: 'supply:manage' },
  389. props: true
  390. },
  391. {
  392. path: 'zodiac-configs',
  393. name: 'ZodiacConfigs',
  394. component: () => import('@/views/admin/ZodiacConfigs.vue'),
  395. meta: { title: '星座配置', perm: 'system:config' }
  396. },
  397. {
  398. path: 'bazi-configs',
  399. name: 'BaziConfigs',
  400. component: () => import('@/views/admin/BaziConfigs.vue'),
  401. meta: { title: '八字配置', perm: 'system:config' }
  402. },
  403. {
  404. path: 'blood-type-configs',
  405. name: 'BloodTypeConfigs',
  406. component: () => import('@/views/admin/BloodTypeConfigs.vue'),
  407. meta: { title: '血型配置', perm: 'system:config' }
  408. },
  409. {
  410. path: 'relationship-types',
  411. name: 'RelationshipTypes',
  412. component: () => import('@/views/admin/RelationshipTypes.vue'),
  413. meta: { title: '关系类型配置', perm: 'system:config' }
  414. },
  415. // ========== 饮食管理 (admin) ==========
  416. {
  417. path: 'foods',
  418. name: 'Foods',
  419. component: () => import('@/views/admin/Foods.vue'),
  420. meta: { title: '食材管理', perm: 'diet:foods' }
  421. },
  422. {
  423. path: 'recipes',
  424. name: 'Recipes',
  425. component: () => import('@/views/admin/Recipes.vue'),
  426. meta: { title: '食谱管理', perm: 'diet:recipes' }
  427. },
  428. {
  429. path: 'seasonal-foods',
  430. name: 'SeasonalFoods',
  431. component: () => import('@/views/admin/SeasonalFoods.vue'),
  432. meta: { title: '应季食材', perm: 'diet:seasonal' }
  433. },
  434. {
  435. path: 'my-families',
  436. name: 'MyFamilies',
  437. component: () => import('@/views/teacher/FamilyList.vue'),
  438. meta: { title: '我的家庭', perm: 'service:family' }
  439. },
  440. {
  441. path: 'growth-records',
  442. name: 'GrowthRecords',
  443. component: () => import('@/views/teacher/GrowthRecords.vue'),
  444. meta: { title: '成长记录', perm: 'growth:records' }
  445. },
  446. {
  447. path: 'growth-plans',
  448. name: 'GrowthPlans',
  449. component: () => import('@/views/teacher/GrowthPlans.vue'),
  450. meta: { title: '成长计划', perm: 'growth:plans' }
  451. },
  452. {
  453. path: 'health-reports',
  454. name: 'HealthReports',
  455. component: () => import('@/views/nutritionist/HealthReports.vue'),
  456. meta: { title: '健康报告', perm: 'health:reports' }
  457. },
  458. {
  459. path: 'health-report-audit',
  460. name: 'HealthReportAudit',
  461. component: () => import('@/views/health/HealthReportAudit.vue'),
  462. meta: { title: '报告草稿审核', perm: 'health:reports' }
  463. },
  464. {
  465. path: 'health-indicators',
  466. name: 'HealthIndicators',
  467. component: () => import('@/views/nutritionist/HealthIndicators.vue'),
  468. meta: { title: '健康指标', perm: 'health:indicators' }
  469. },
  470. {
  471. path: 'health-checkins',
  472. name: 'HealthCheckins',
  473. component: () => import('@/views/nutritionist/HealthCheckins.vue'),
  474. meta: { title: '健康打卡', perm: 'health:checkins' }
  475. },
  476. {
  477. path: 'emotion-alert',
  478. name: 'EmotionAlertManage',
  479. component: () => import('@/views/admin/EmotionAlertManage.vue'),
  480. meta: { title: '情绪告警管理', perm: 'health:checkins' }
  481. },
  482. {
  483. path: 'nutrition-mappings',
  484. name: 'NutritionMappings',
  485. component: () => import('@/views/nutritionist/NutritionMappings.vue'),
  486. meta: { title: '营养素映射管理', perm: 'health:mappings' }
  487. },
  488. {
  489. path: 'activities',
  490. name: 'Activities',
  491. component: () => import('@/views/admin/Activities.vue'),
  492. meta: { title: '活动列表', perm: 'activity:list' }
  493. },
  494. {
  495. path: 'activity-edit',
  496. name: 'ActivityEdit',
  497. component: () => import('@/views/admin/ActivityEdit.vue'),
  498. meta: { title: '活动编辑', perm: 'activity:list' }
  499. },
  500. {
  501. path: 'activity-review',
  502. name: 'ActivityReview',
  503. component: () => import('@/views/admin/ActivityReview.vue'),
  504. meta: { title: '活动审核', perm: 'activity:review' }
  505. },
  506. {
  507. path: 'activity-registration-review',
  508. name: 'ActivityRegistrationReview',
  509. component: () => import('@/views/admin/ActivityRegistrationReview.vue'),
  510. meta: { title: '活动报名审核', perm: 'activity:review' }
  511. },
  512. // ========== 维度配置 + 知识库管理 ==========
  513. {
  514. path: 'coupon',
  515. name: 'CouponManagement',
  516. component: () => import('@/views/admin/CouponManagement'),
  517. meta: { title: '优惠券管理', perm: 'marketing:coupon' }
  518. },
  519. {
  520. path: 'promotion',
  521. name: 'PromotionManagement',
  522. component: () => import('@/views/admin/PromotionManagement'),
  523. meta: { title: '推广管理', perm: 'marketing:promotion' }
  524. },
  525. {
  526. path: 'family-earnings',
  527. name: 'FamilyEarnings',
  528. component: () => import('@/views/admin/FamilyEarnings.vue'),
  529. meta: { title: '家庭收益管理', perm: 'marketing:promotion' }
  530. },
  531. {
  532. path: 'family-earnings-withdraw',
  533. name: 'FamilyEarningsWithdraw',
  534. component: () => import('@/views/admin/FamilyEarningsWithdraw.vue'),
  535. meta: { title: '家庭收益提现审核', perm: 'audit:withdraw' }
  536. },
  537. {
  538. path: 'dimension-config',
  539. name: 'DimensionConfig',
  540. component: () => import('@/views/admin/dimension'),
  541. meta: { title: '维度配置', perm: 'system:config' }
  542. },
  543. {
  544. path: 'knowledge-base',
  545. name: 'KnowledgeBase',
  546. component: () => import('@/views/admin/knowledge'),
  547. meta: { title: '知识库管理', perm: 'system:config' }
  548. },
  549. // ========== 健康维度配置 ==========
  550. {
  551. path: 'health-norm-config',
  552. name: 'HealthNormConfig',
  553. component: () => import('@/views/admin/dimension-config'),
  554. meta: { title: '健康常模配置', perm: 'system:config' }
  555. },
  556. {
  557. path: 'health-data-source',
  558. name: 'HealthDataSource',
  559. component: () => import('@/views/admin/data-source-config'),
  560. meta: { title: '健康数据源配置', perm: 'system:config' }
  561. },
  562. {
  563. path: 'health-energy-config',
  564. name: 'HealthEnergyConfig',
  565. component: () => import('@/views/admin/HealthEnergyConfig'),
  566. meta: { title: '七维能量配置', perm: 'system:config' }
  567. },
  568. {
  569. path: 'energy-config',
  570. name: 'EnergyConfig',
  571. component: () => import('@/views/admin/energy-config/WuxingConfig'),
  572. meta: { title: '五行能量配置', perm: 'system:config' }
  573. },
  574. {
  575. path: 'indicators',
  576. name: 'IndicatorManage',
  577. component: () => import('@/views/admin/indicators'),
  578. meta: { title: '指标管理', perm: 'system:config' }
  579. },
  580. // ========== 虚拟服务商团队管理 ==========
  581. {
  582. path: 'virtual-teams',
  583. name: 'VirtualTeamList',
  584. component: () => import('@/views/admin/VirtualTeamList'),
  585. meta: { title: '虚拟团队管理', perm: 'system:config' }
  586. },
  587. {
  588. path: 'virtual-team-detail/:systemId',
  589. name: 'VirtualTeamDetail',
  590. component: () => import('@/views/admin/VirtualTeamDetail'),
  591. meta: { title: '团队成员管理', perm: 'system:config' },
  592. props: true
  593. },
  594. // ========== 电商供应商管理 ==========
  595. {
  596. path: 'ecom-supplier',
  597. name: 'EcomSupplierManage',
  598. component: () => import('@/views/admin/EcomSupplierManage'),
  599. meta: { title: '电商供应商管理', perm: 'ecom:supplier' }
  600. }
  601. ]
  602. }
  603. ]
  604. const router = new VueRouter({
  605. mode: 'history',
  606. base: process.env.BASE_URL,
  607. routes
  608. })
  609. // Token 验证缓存:避免 redirect 链中重复调用 /api/admin-auth/info
  610. let tokenValidationCache = { token: '', timestamp: 0 }
  611. const TOKEN_CACHE_TTL = 30000 // 30秒内不重复验证
  612. async function validateToken(token) {
  613. try {
  614. const baseURL = process.env.VUE_APP_BASE_API || ''
  615. const res = await axios.post(`${baseURL}/api/admin-auth/info`, {}, {
  616. headers: { Authorization: `Bearer ${token}` },
  617. validateStatus: () => true
  618. })
  619. return res.status === 200 && res.data?.code === 200
  620. } catch (e) {
  621. return false
  622. }
  623. }
  624. router.beforeEach(async (to, from, next) => {
  625. const token = localStorage.getItem('token')
  626. const role = localStorage.getItem('role')
  627. // 1. 登录页允许访问
  628. if (to.path === '/login') {
  629. // 如果已有token和role,直接跳转到对应首页
  630. if (token && role === 'teacher') {
  631. return next('/teacher-dashboard')
  632. }
  633. return next()
  634. }
  635. // 2. 无Token强制跳转
  636. if (!token) {
  637. return next('/login')
  638. }
  639. // 3. Token有效性验证 (使用缓存避免 redirect 链重复调用)
  640. const now = Date.now()
  641. let isValid = false
  642. if (tokenValidationCache.token === token && (now - tokenValidationCache.timestamp) < TOKEN_CACHE_TTL) {
  643. isValid = true
  644. } else {
  645. isValid = await validateToken(token)
  646. if (isValid) {
  647. tokenValidationCache = { token, timestamp: now }
  648. }
  649. }
  650. if (!isValid) {
  651. tokenValidationCache = { token: '', timestamp: 0 }
  652. localStorage.clear()
  653. return next('/login')
  654. }
  655. // 3.5 规划师访问 /dashboard → 跳转规划师仪表板
  656. if (role === 'teacher' && to.path === '/dashboard') {
  657. return next('/teacher-dashboard')
  658. }
  659. // 4. 权限检查:如果路由有 perm 要求,检查用户权限
  660. const requiredPerm = to.meta && to.meta.perm
  661. if (requiredPerm) {
  662. const rolesStr = localStorage.getItem('roles')
  663. const roles = rolesStr ? JSON.parse(rolesStr) : [localStorage.getItem('role')]
  664. const perms = getEffectivePermissions(roles)
  665. if (!hasPermission(perms, requiredPerm)) {
  666. console.warn('Access denied: insufficient permissions for', to.name)
  667. return next({ path: '/', query: { accessDenied: 'no-permission' }, replace: true })
  668. }
  669. }
  670. return next()
  671. })
  672. // Suppress navigation guard redirect errors (teacher/admin route cross-access)
  673. const originalPush = VueRouter.prototype.push
  674. VueRouter.prototype.push = function push(location) {
  675. return originalPush.call(this, location).catch(err => err)
  676. }
  677. export default router