index.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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: 'teacher-proxy-report',
  188. name: 'TeacherProxyReport',
  189. component: () => import('@/views/teacher/ProxyReport.vue'),
  190. meta: { title: '代上传报告', requiresTeacher: true, perm: 'health:reports' }
  191. },
  192. {
  193. path: 'assessment-admin',
  194. name: 'AssessmentAdmin',
  195. component: () => import('@/views/admin/Assessment.vue'),
  196. meta: { title: '测评管理', perm: 'assessment:dan' }
  197. },
  198. {
  199. path: 'assessment-assign',
  200. name: 'AssessmentAssign',
  201. component: () => import('@/views/admin/AssessmentAssign.vue'),
  202. meta: { title: '待分配规划师', perm: 'assessment:dan' }
  203. },
  204. {
  205. path: 'assessment-orders',
  206. name: 'AssessmentOrders',
  207. component: () => import('@/views/admin/AssessmentOrders.vue'),
  208. meta: { title: '测评订单', perm: 'assessment:dan' }
  209. },
  210. {
  211. path: 'dan-execution',
  212. name: 'DanExecution',
  213. component: () => import('@/views/admin/DanExecution.vue'),
  214. meta: { title: 'DAN服务执行', perm: 'assessment:dan' }
  215. },
  216. {
  217. path: 'dan-settlement',
  218. name: 'DanSettlement',
  219. component: () => import('@/views/admin/DanSettlement.vue'),
  220. meta: { title: 'DAN结算管理', perm: 'assessment:dan' }
  221. },
  222. {
  223. path: 'product-manage',
  224. name: 'ProductManage',
  225. component: () => import('@/views/admin/ProductManage.vue'),
  226. meta: { title: '商品管理', perm: 'commerce:products' }
  227. },
  228. {
  229. path: 'inventory',
  230. name: 'InventoryManage',
  231. component: () => import('@/views/admin/InventoryManage.vue'),
  232. meta: { title: '库存管理', perm: 'commerce:products' }
  233. },
  234. {
  235. path: 'inventory/inbound-create',
  236. name: 'InventoryInboundCreate',
  237. component: () => import('@/views/admin/InventoryInboundCreate.vue'),
  238. meta: { title: '创建入库单', perm: 'commerce:products' }
  239. },
  240. {
  241. path: 'product-edit',
  242. name: 'ProductEdit',
  243. component: () => import('@/views/admin/ProductEdit.vue'),
  244. meta: { title: '商品编辑', perm: 'commerce:products' }
  245. },
  246. {
  247. path: 'assessment-products',
  248. name: 'AssessmentProducts',
  249. component: () => import('@/views/admin/AssessmentProducts.vue'),
  250. meta: { title: '测评商品管理', perm: 'commerce:products' }
  251. },
  252. {
  253. path: 'assessment-plan-rules',
  254. name: 'AssessmentPlanRules',
  255. component: () => import('@/views/admin/AssessmentPlanRules.vue'),
  256. meta: { title: '方案生成规则', perm: 'plan:rules' }
  257. },
  258. {
  259. path: 'plan-management',
  260. name: 'PlanManagement',
  261. component: () => import('@/views/admin/PlanManagement.vue'),
  262. meta: { title: '方案管理', perm: 'plan:manage' }
  263. },
  264. {
  265. path: 'category-manage',
  266. name: 'CategoryManage',
  267. component: () => import('@/views/admin/CategoryManage.vue'),
  268. meta: { title: '商品分类', perm: 'commerce:category' }
  269. },
  270. {
  271. path: 'order-manage',
  272. name: 'OrderManage',
  273. component: () => import('@/views/admin/OrderManage.vue'),
  274. meta: { title: '订单管理', perm: 'commerce:orders' }
  275. },
  276. {
  277. path: 'pending-refund',
  278. name: 'PendingRefund',
  279. component: () => import('@/views/admin/PendingRefund.vue'),
  280. meta: { title: '待退款管理', perm: 'commerce:orders' }
  281. },
  282. {
  283. path: 'order-detail/:orderNo',
  284. name: 'OrderDetail',
  285. component: () => import('@/views/admin/OrderDetail.vue'),
  286. meta: { title: '订单详情', perm: 'commerce:orders' }
  287. },
  288. {
  289. path: 'sys-config',
  290. name: 'SysConfig',
  291. component: () => import('@/views/admin/SysConfig.vue'),
  292. meta: { title: '系统配置', perm: 'system:config' }
  293. },
  294. {
  295. path: 'energy-sandbox',
  296. name: 'EnergySandbox',
  297. component: () => import('@/views/admin/EnergySandbox.vue'),
  298. meta: { title: '五维能量', perm: 'energy' }
  299. },
  300. {
  301. path: 'energy-rule',
  302. name: 'EnergyRuleManagement',
  303. component: () => import('@/views/admin/EnergyRuleManagement.vue'),
  304. meta: { title: '能量规则管理', perm: 'energy' }
  305. },
  306. {
  307. path: 'energy-behavior-config',
  308. name: 'EnergyBehaviorConfig',
  309. component: () => import('@/views/admin/EnergyBehaviorConfig.vue'),
  310. meta: { title: '能量行为配置', perm: 'energy' }
  311. },
  312. {
  313. path: 'challenge-score-config',
  314. name: 'ChallengeScoreConfig',
  315. component: () => import('@/views/admin/ChallengeScoreConfig.vue'),
  316. meta: { title: '挑战评分配置', perm: 'energy' }
  317. },
  318. // ========== 文章管理 ==========
  319. {
  320. path: 'article-categories',
  321. name: 'ArticleCategory',
  322. component: () => import('@/views/admin/ArticleCategory.vue'),
  323. meta: { title: '文章分类', perm: 'articles:categories' }
  324. },
  325. {
  326. path: 'article-manage',
  327. name: 'ArticleManage',
  328. component: () => import('@/views/admin/ArticleManage.vue'),
  329. meta: { title: '文章管理', perm: 'articles:manage' }
  330. },
  331. {
  332. path: 'article-edit',
  333. name: 'ArticleEdit',
  334. component: () => import('@/views/admin/ArticleEdit.vue'),
  335. meta: { title: '文章编辑', perm: 'articles:manage' }
  336. },
  337. {
  338. path: 'comment-review',
  339. name: 'CommentReview',
  340. component: () => import('@/views/admin/CommentReview.vue'),
  341. meta: { title: '评论审核', perm: 'articles:manage' }
  342. },
  343. {
  344. path: 'notice-manage',
  345. name: 'NoticeManage',
  346. component: () => import('@/views/admin/NoticeManage.vue'),
  347. meta: { title: '公告管理', perm: 'admin' }
  348. },
  349. {
  350. path: 'periodic-service-config',
  351. name: 'PeriodicServiceConfig',
  352. component: () => import('@/views/admin/PeriodicServiceConfig.vue'),
  353. meta: { title: '周期性服务配置', perm: 'admin' }
  354. },
  355. {
  356. path: 'knowledge-tags',
  357. name: 'KnowledgeTag',
  358. component: () => import('@/views/admin/KnowledgeTag.vue'),
  359. meta: { title: '知识标签', perm: 'articles:categories' }
  360. },
  361. {
  362. path: 'virtual-goods-config',
  363. name: 'VirtualGoodsConfig',
  364. component: () => import('@/views/admin/VirtualGoodsConfig.vue'),
  365. meta: { title: '虚拟支付道具', perm: 'system:config' }
  366. },
  367. {
  368. path: 'gates',
  369. name: 'Gates',
  370. component: () => import('@/views/admin/gates.vue'),
  371. meta: { title: '关卡配置', perm: 'system:config' }
  372. },
  373. // ========== 佣金推荐系统 ==========
  374. {
  375. path: 'product-profit-rate',
  376. name: 'ProductProfitRate',
  377. component: () => import('@/views/admin/ProductProfitRate.vue'),
  378. meta: { title: '产品利润率', perm: 'commerce:profit-rate' }
  379. },
  380. {
  381. path: 'product-ppoint',
  382. name: 'ProductPpointManage',
  383. component: () => import('@/views/admin/ProductPpointManage.vue'),
  384. meta: { title: 'P点配置', perm: 'commerce:ppoint' }
  385. },
  386. {
  387. path: 'cf-value',
  388. name: 'CfValueManage',
  389. component: () => import('@/views/admin/CfValueManage.vue'),
  390. meta: { title: 'CF值管理', perm: 'finance:cf-value' }
  391. },
  392. {
  393. path: 'supply-system',
  394. name: 'SupplySystemList',
  395. component: () => import('@/views/admin/supply-system/List.vue'),
  396. meta: { title: '供应商体系', perm: 'system:supply' }
  397. },
  398. {
  399. path: 'supply-system/create',
  400. name: 'SupplySystemCreate',
  401. component: () => import('@/views/admin/supply-system/Form.vue'),
  402. meta: { title: '新建体系', perm: 'system:supply' }
  403. },
  404. {
  405. path: 'supply-system/:id',
  406. name: 'SupplySystemDetail',
  407. component: () => import('@/views/admin/supply-system/Detail.vue'),
  408. meta: { title: '体系详情', perm: 'system:supply' },
  409. props: true
  410. },
  411. {
  412. path: 'supplier-products',
  413. name: 'SupplierProducts',
  414. component: () => import('@/views/admin/SupplierProductManage.vue'),
  415. meta: { title: '商品管理', perm: 'commerce:product' }
  416. },
  417. {
  418. path: 'supply-system/:id/edit',
  419. name: 'SupplySystemEdit',
  420. component: () => import('@/views/admin/supply-system/Form.vue'),
  421. meta: { title: '编辑体系', perm: 'system:supply' },
  422. props: true
  423. },
  424. {
  425. path: 'supply-hierarchy/change-requests',
  426. name: 'SupplyHierarchyChangeRequests',
  427. component: () => import('@/views/admin/supply-hierarchy/ChangeRequest.vue'),
  428. meta: { title: '更换上级审核', perm: 'system:supply' }
  429. },
  430. // ========== 供应商管理 (supplier_admin) ==========
  431. {
  432. path: 'supply-manage',
  433. name: 'SupplyManage',
  434. component: () => import('@/views/admin/supply-manage/List.vue'),
  435. meta: { title: '供应商管理', perm: 'supply:manage' }
  436. },
  437. {
  438. path: 'supply-manage/create',
  439. name: 'SupplyManageCreate',
  440. component: () => import('@/views/admin/supply-manage/Form.vue'),
  441. meta: { title: '新增供应商', perm: 'supply:manage' }
  442. },
  443. {
  444. path: 'supply-manage/:id',
  445. name: 'SupplyManageDetail',
  446. component: () => import('@/views/admin/supply-manage/Detail.vue'),
  447. meta: { title: '供应商详情', perm: 'supply:manage' },
  448. props: true
  449. },
  450. {
  451. path: 'supply-manage/:id/edit',
  452. name: 'SupplyManageEdit',
  453. component: () => import('@/views/admin/supply-manage/Form.vue'),
  454. meta: { title: '编辑供应商', perm: 'supply:manage' },
  455. props: true
  456. },
  457. {
  458. path: 'zodiac-configs',
  459. name: 'ZodiacConfigs',
  460. component: () => import('@/views/admin/ZodiacConfigs.vue'),
  461. meta: { title: '星座配置', perm: 'system:config' }
  462. },
  463. {
  464. path: 'bazi-configs',
  465. name: 'BaziConfigs',
  466. component: () => import('@/views/admin/BaziConfigs.vue'),
  467. meta: { title: '八字配置', perm: 'system:config' }
  468. },
  469. {
  470. path: 'blood-type-configs',
  471. name: 'BloodTypeConfigs',
  472. component: () => import('@/views/admin/BloodTypeConfigs.vue'),
  473. meta: { title: '血型配置', perm: 'system:config' }
  474. },
  475. // ========== 饮食管理 (admin) ==========
  476. {
  477. path: 'foods',
  478. name: 'Foods',
  479. component: () => import('@/views/admin/Foods.vue'),
  480. meta: { title: '食材管理', perm: 'diet:foods' }
  481. },
  482. {
  483. path: 'recipes',
  484. name: 'Recipes',
  485. component: () => import('@/views/admin/Recipes.vue'),
  486. meta: { title: '食谱管理', perm: 'diet:recipes' }
  487. },
  488. {
  489. path: 'my-families',
  490. name: 'MyFamilies',
  491. component: () => import('@/views/teacher/FamilyList.vue'),
  492. meta: { title: '我的家庭', perm: 'service:family' }
  493. },
  494. {
  495. path: 'growth-records',
  496. name: 'GrowthRecords',
  497. component: () => import('@/views/teacher/GrowthRecords.vue'),
  498. meta: { title: '成长记录', perm: 'growth:records' }
  499. },
  500. {
  501. path: 'growth-plans',
  502. name: 'GrowthPlans',
  503. component: () => import('@/views/teacher/GrowthPlans.vue'),
  504. meta: { title: '成长计划', perm: 'growth:plans' }
  505. },
  506. {
  507. path: 'health-reports',
  508. name: 'HealthReports',
  509. component: () => import('@/views/admin/UnifiedHealthReports.vue'),
  510. meta: { title: '健康报告', perm: 'health:reports' }
  511. },
  512. {
  513. path: 'health-indicators',
  514. name: 'HealthIndicators',
  515. component: () => import('@/views/nutritionist/HealthIndicators.vue'),
  516. meta: { title: '健康指标', perm: 'health:indicators' }
  517. },
  518. {
  519. path: 'health-checkins',
  520. name: 'HealthCheckinManage',
  521. component: () => import('@/views/admin/HealthCheckinManage.vue'),
  522. meta: { title: '健康打卡管理', perm: 'health:checkins' }
  523. },
  524. {
  525. path: 'emotion-alert',
  526. name: 'EmotionAlertManage',
  527. component: () => import('@/views/admin/EmotionAlertManage.vue'),
  528. meta: { title: '情绪告警管理', perm: 'health:checkins' }
  529. },
  530. {
  531. path: 'nutrition-mappings',
  532. name: 'NutritionMappings',
  533. component: () => import('@/views/nutritionist/NutritionMappings.vue'),
  534. meta: { title: '营养素映射管理', perm: 'health:mappings' }
  535. },
  536. {
  537. path: 'activities',
  538. name: 'Activities',
  539. component: () => import('@/views/admin/Activities.vue'),
  540. meta: { title: '活动列表', perm: 'activity:list' }
  541. },
  542. {
  543. path: 'activity-edit',
  544. name: 'ActivityEdit',
  545. component: () => import('@/views/admin/ActivityEdit.vue'),
  546. meta: { title: '活动编辑', perm: 'activity:list' }
  547. },
  548. {
  549. path: 'survey-templates',
  550. name: 'SurveyTemplates',
  551. component: () => import('@/views/admin/SurveyTemplates.vue'),
  552. meta: { title: '调研模板管理', perm: 'admin:all' }
  553. },
  554. {
  555. path: 'activity-review',
  556. name: 'ActivityReview',
  557. component: () => import('@/views/admin/ActivityReview.vue'),
  558. meta: { title: '活动审核', perm: 'activity:review' }
  559. },
  560. {
  561. path: 'activity-registration-review',
  562. name: 'ActivityRegistrationReview',
  563. component: () => import('@/views/admin/ActivityRegistrationReview.vue'),
  564. meta: { title: '活动报名审核', perm: 'activity:review' }
  565. },
  566. // ========== 维度配置 + 知识库管理 ==========
  567. {
  568. path: 'coupon',
  569. name: 'CouponManagement',
  570. component: () => import('@/views/admin/CouponManagement'),
  571. meta: { title: '优惠券管理', perm: 'marketing:coupon' }
  572. },
  573. {
  574. path: 'coupon-grant-log',
  575. name: 'CouponGrantLog',
  576. component: () => import('@/views/admin/CouponGrantLog.vue'),
  577. meta: { title: '发券记录', perm: 'marketing:coupon' }
  578. },
  579. {
  580. path: 'promotion',
  581. name: 'PromotionManagement',
  582. component: () => import('@/views/admin/PromotionManagement'),
  583. meta: { title: '推广管理', perm: 'marketing:promotion' }
  584. },
  585. {
  586. path: 'family-earnings',
  587. name: 'FamilyEarnings',
  588. component: () => import('@/views/admin/FamilyEarnings.vue'),
  589. meta: { title: '家庭收益管理', perm: 'marketing:promotion' }
  590. },
  591. {
  592. path: 'family-earnings-withdraw',
  593. name: 'FamilyEarningsWithdraw',
  594. component: () => import('@/views/admin/FamilyEarningsWithdraw.vue'),
  595. meta: { title: '家庭收益提现审核', perm: 'audit:withdraw' }
  596. },
  597. {
  598. path: 'dimension-config',
  599. name: 'DimensionConfig',
  600. component: () => import('@/views/admin/dimension'),
  601. meta: { title: '维度配置', perm: 'system:config' }
  602. },
  603. {
  604. path: 'knowledge-base',
  605. name: 'KnowledgeBase',
  606. component: () => import('@/views/admin/knowledge'),
  607. meta: { title: '知识库管理', perm: 'system:config' }
  608. },
  609. {
  610. path: 'health-knowledge',
  611. name: 'HealthKnowledge',
  612. component: () => import('@/views/admin/health-knowledge'),
  613. meta: { title: '健康知识库管理', perm: 'system:config' }
  614. },
  615. // ========== 健康维度配置 ==========
  616. {
  617. path: 'health-norm-config',
  618. name: 'HealthNormConfig',
  619. component: () => import('@/views/admin/dimension-config'),
  620. meta: { title: '健康常模配置', perm: 'system:config' }
  621. },
  622. {
  623. path: 'health-data-source',
  624. name: 'HealthDataSource',
  625. component: () => import('@/views/admin/data-source-config'),
  626. meta: { title: '健康数据源配置', perm: 'system:config' }
  627. },
  628. {
  629. path: 'health-energy-config',
  630. name: 'HealthEnergyConfig',
  631. component: () => import('@/views/admin/HealthEnergyConfig'),
  632. meta: { title: '七维能量配置', perm: 'system:config' }
  633. },
  634. {
  635. path: 'energy-config',
  636. name: 'EnergyConfig',
  637. component: () => import('@/views/admin/energy-config/WuxingConfig'),
  638. meta: { title: '五行能量配置', perm: 'system:config' }
  639. },
  640. {
  641. path: 'indicators',
  642. name: 'IndicatorManage',
  643. component: () => import('@/views/admin/indicators'),
  644. meta: { title: '指标管理', perm: 'system:config' }
  645. },
  646. // ========== 虚拟服务商团队管理 ==========
  647. {
  648. path: 'virtual-teams',
  649. name: 'VirtualTeamList',
  650. component: () => import('@/views/admin/VirtualTeamList'),
  651. meta: { title: '虚拟团队管理', perm: 'system:config' }
  652. },
  653. {
  654. path: 'virtual-team-detail/:systemId',
  655. name: 'VirtualTeamDetail',
  656. component: () => import('@/views/admin/VirtualTeamDetail'),
  657. meta: { title: '团队成员管理', perm: 'system:config' },
  658. props: true
  659. },
  660. // ========== 电商供应商管理 ==========
  661. {
  662. path: 'ecom-supplier',
  663. name: 'EcomSupplierManage',
  664. component: () => import('@/views/admin/EcomSupplierManage'),
  665. meta: { title: '电商供应商管理', perm: 'ecom:supplier' }
  666. },
  667. {
  668. path: 'badge-manage',
  669. name: 'BadgeManage',
  670. component: () => import('@/views/admin/BadgeManage'),
  671. meta: { title: '勋章管理', perm: 'system:config' }
  672. },
  673. // ========== 报告指纹解析系统 ==========
  674. {
  675. path: 'report-types',
  676. name: 'ReportTypeManagement',
  677. component: () => import('@/views/admin/ReportTypeManagement.vue'),
  678. meta: { title: '报告类型管理', perm: 'system:config' }
  679. },
  680. {
  681. path: 'report-parser-import',
  682. name: 'ReportParserImport',
  683. component: () => import('@/views/admin/ReportParserImport.vue'),
  684. meta: { title: '解析器导入管理', perm: 'system:config' }
  685. },
  686. {
  687. path: 'report-unknown-clusters',
  688. name: 'ReportUnknownCluster',
  689. component: () => import('@/views/admin/ReportUnknownCluster.vue'),
  690. meta: { title: '未知报告审核', perm: 'system:config' }
  691. },
  692. {
  693. path: 'report-auto-learn',
  694. name: 'ReportAutoLearn',
  695. component: () => import('@/views/admin/ReportAutoLearn.vue'),
  696. meta: { title: '报告自学习', perm: 'system:config' }
  697. },
  698. // ========== LangGraph AI 服务管理 ==========
  699. {
  700. path: 'langgraph-admin',
  701. name: 'LangGraphAdmin',
  702. component: () => import('@/views/admin/LangGraphAdmin.vue'),
  703. meta: { title: 'LangGraph 管理', perm: 'system:config' }
  704. },
  705. // ========== 营养产品管理 ==========
  706. {
  707. path: 'nutrition-products',
  708. name: 'NutritionProducts',
  709. component: () => import('@/views/admin/NutritionProducts.vue'),
  710. meta: { title: '营养产品管理', perm: 'health:*' }
  711. },
  712. {
  713. path: 'file-manage',
  714. name: 'FileManage',
  715. component: () => import('@/views/admin/FileManage'),
  716. meta: { title: '文件管理', perm: 'system:config' }
  717. }
  718. ]
  719. }
  720. ]
  721. const router = new VueRouter({
  722. mode: 'history',
  723. base: process.env.BASE_URL,
  724. routes
  725. })
  726. // Token 验证缓存:避免 redirect 链中重复调用 /api/admin-auth/info
  727. let tokenValidationCache = { token: '', timestamp: 0 }
  728. const TOKEN_CACHE_TTL = 30000 // 30秒内不重复验证
  729. async function validateToken(token) {
  730. try {
  731. const baseURL = process.env.VUE_APP_BASE_API || ''
  732. const res = await axios.post(`${baseURL}/api/admin-auth/info`, {}, {
  733. headers: { Authorization: `Bearer ${token}` },
  734. validateStatus: () => true
  735. })
  736. return res.status === 200 && res.data?.code === 200
  737. } catch (e) {
  738. return false
  739. }
  740. }
  741. router.beforeEach(async (to, from, next) => {
  742. const token = localStorage.getItem('token')
  743. const role = localStorage.getItem('role')
  744. // 1. 登录页允许访问
  745. if (to.path === '/login') {
  746. // 如果已有token和role,直接跳转到对应首页
  747. if (token && role === 'teacher') {
  748. return next('/teacher-dashboard')
  749. }
  750. return next()
  751. }
  752. // 2. 无Token强制跳转
  753. if (!token) {
  754. return next('/login')
  755. }
  756. // 3. Token有效性验证 (使用缓存避免 redirect 链重复调用)
  757. const now = Date.now()
  758. let isValid = false
  759. if (tokenValidationCache.token === token && (now - tokenValidationCache.timestamp) < TOKEN_CACHE_TTL) {
  760. isValid = true
  761. } else {
  762. isValid = await validateToken(token)
  763. if (isValid) {
  764. tokenValidationCache = { token, timestamp: now }
  765. }
  766. }
  767. if (!isValid) {
  768. tokenValidationCache = { token: '', timestamp: 0 }
  769. localStorage.clear()
  770. return next('/login')
  771. }
  772. // 3.5 规划师访问 /dashboard → 跳转规划师仪表板
  773. if (role === 'teacher' && to.path === '/dashboard') {
  774. return next('/teacher-dashboard')
  775. }
  776. // 4. 权限检查:如果路由有 perm 要求,检查用户权限
  777. const requiredPerm = to.meta && to.meta.perm
  778. if (requiredPerm) {
  779. const rolesStr = localStorage.getItem('roles')
  780. const roles = rolesStr ? JSON.parse(rolesStr) : [localStorage.getItem('role')]
  781. const perms = getEffectivePermissions(roles)
  782. if (!hasPermission(perms, requiredPerm)) {
  783. console.warn('Access denied: insufficient permissions for', to.name)
  784. return next({ path: '/403', replace: true })
  785. }
  786. }
  787. return next()
  788. })
  789. // Suppress navigation guard redirect errors (teacher/admin route cross-access)
  790. const originalPush = VueRouter.prototype.push
  791. VueRouter.prototype.push = function push(location) {
  792. return originalPush.call(this, location).catch(err => err)
  793. }
  794. export default router