You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

522 lines
21 KiB

6 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
2 months ago
4 months ago
1 month ago
4 months ago
4 months ago
4 weeks ago
2 months ago
4 weeks ago
1 month ago
2 months ago
2 months ago
4 months ago
4 months ago
4 weeks ago
4 weeks ago
4 weeks ago
4 months ago
4 months ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 months ago
4 months ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 months ago
1 month ago
4 weeks ago
4 weeks ago
4 weeks ago
4 months ago
4 weeks ago
4 weeks ago
4 weeks ago
4 months ago
2 months ago
4 weeks ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
4 months ago
4 months ago
4 weeks ago
4 weeks ago
4 weeks ago
2 months ago
2 months ago
4 months ago
1 month ago
4 weeks ago
1 month ago
2 months ago
2 months ago
4 weeks ago
2 months ago
2 months ago
3 weeks ago
2 months ago
4 weeks ago
2 months ago
1 month ago
4 weeks ago
1 month ago
2 months ago
1 month ago
2 months ago
4 weeks ago
2 months ago
1 month ago
4 weeks ago
2 months ago
1 month ago
2 months ago
1 month ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
4 weeks ago
3 weeks ago
4 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
1 month ago
4 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
  1. import { createRouter, createWebHashHistory } from 'vue-router';
  2. import axios from "axios";
  3. import { storeToRefs } from "pinia";
  4. import { useAdminStore } from "@/store/index.js";
  5. // 路由定义(包含权限映射 meta.permissionId)
  6. const routes = [
  7. {
  8. path: '/',
  9. redirect: "/login"
  10. },
  11. {
  12. path: "/login",
  13. name: "login",
  14. component: () => import("../views/login.vue"),
  15. },
  16. {
  17. meta: { requireAuth: true },
  18. path: '/',
  19. component: () => import("../views/home.vue"),
  20. children: [
  21. // 工作台
  22. {
  23. path: 'workbench',
  24. name: "workbench",
  25. component: () => import("../views/workspace/index.vue"),
  26. meta: { permissionId: 2 }
  27. },
  28. //金币管理
  29. {
  30. path: '/goldManage',
  31. name: 'goldManage',
  32. meta: { permissionId: 3 },
  33. children: [
  34. // 审核
  35. {
  36. path: '/audit',
  37. name: "audit",
  38. component: () => import("../views/audit/gold/audit.vue"),
  39. meta: { permissionId: 4 },
  40. children: [
  41. // 充值审核
  42. {
  43. path: 'rechargeAudit',
  44. name: "rechargeAudit",
  45. component: () => import("../views/audit/gold/rechargeAudit.vue"),
  46. meta: { permissionId: [6, 7, 8, 9, 10, 11, 12] }
  47. },
  48. // 退款审核
  49. {
  50. path: 'refundAudit',
  51. name: "refundAudit",
  52. component: () => import("../views/audit/gold/refundAudit.vue"),
  53. meta: { permissionId: [13, 14, 15, 16, 17, 18, 19] }
  54. },
  55. ]
  56. }, {
  57. path: '/beanAudit',
  58. name: "beanAudit",
  59. component: () => import("../views/audit/bean/beanAudit.vue"),
  60. meta: { permissionId: 20 },
  61. children: [
  62. // 充值审核
  63. {
  64. path: 'addbeanAudit',
  65. name: "addbeanAudit",
  66. component: () => import("../views/audit/bean/beanAudit.vue"),
  67. meta: { permissionId: [21, 22, 23, 24, 25, 26] }
  68. },
  69. ]
  70. },
  71. // 金币消耗
  72. {
  73. path: '/coinConsume',
  74. name: "coinConsume",
  75. component: () => import("../views/consume/gold/coinConsume.vue"),
  76. meta: { permissionId: 39 },
  77. children: [
  78. // 金币新增消耗
  79. {
  80. path: 'add',
  81. name: "addCoinConsume",
  82. component: () => import("../views/consume/gold/addCoinConsume.vue"),
  83. meta: { permissionId: 41 }
  84. },
  85. // 金币消耗明细详情
  86. {
  87. path: 'detail',
  88. name: "coinConsumeDetail",
  89. component: () => import("../views/consume/gold/coinConsumeDetail.vue"),
  90. meta: { permissionId: 40 }
  91. }
  92. ]
  93. },
  94. // 金豆消耗
  95. {
  96. path: '/beanConsume',
  97. name: "beanConsume",
  98. component: () => import("../views/consume/bean/beanConsume.vue"),
  99. meta: { permissionId: 42 },
  100. children: [
  101. // 金豆新增消耗
  102. {
  103. path: 'add',
  104. name: "addBeanConsume",
  105. component: () => import("../views/consume/bean/addBeanConsume.vue"),
  106. meta: { permissionId: 46 }
  107. },
  108. // 直播
  109. {
  110. path: 'live',
  111. name: "liveStream",
  112. component: () => import("../views/consume/bean/liveStream.vue"),
  113. meta: { permissionId: 43 }
  114. },
  115. // 铁粉
  116. {
  117. path: 'fan',
  118. name: "dieHardFan",
  119. component: () => import("../views/consume/bean/dieHardFan.vue"),
  120. meta: { permissionId: 44 }
  121. },
  122. // 文章视频
  123. {
  124. path: 'article',
  125. name: "articleVideo",
  126. component: () => import("../views/consume/bean/articleVideo.vue"),
  127. meta: { permissionId: 45 }
  128. }
  129. ]
  130. },
  131. // 汇率管理
  132. {
  133. path: '/rate',
  134. name: "rate",
  135. component: () => import("../views/managerecharge/rate.vue"),
  136. meta: { permissionId: [27, 28, 29] }
  137. },
  138. // 金币充值
  139. {
  140. path: '/coinRecharge',
  141. name: "coinRecharge",
  142. component: () => import("../views/recharge/gold/coinRecharge.vue"),
  143. meta: { permissionId: 31 },
  144. children: [
  145. // 金币新增充值
  146. {
  147. path: 'add',
  148. name: "addCoinRecharge",
  149. component: () => import("../views/recharge/gold/addCoinRecharge.vue"),
  150. meta: { permissionId: 33 }
  151. },
  152. // 金币充值明细
  153. {
  154. path: 'detail',
  155. name: "coinRechargeDetail",
  156. component: () => import("../views/recharge/gold/coinRechargeDetail.vue"),
  157. meta: { permissionId: 32 }
  158. }
  159. ]
  160. },
  161. // 金豆充值
  162. {
  163. path: '/beanRecharge',
  164. name: "beanRecharge",
  165. component: () => import("../views/recharge/bean/beanRecharge.vue"),
  166. meta: { permissionId: 34 },
  167. children: [
  168. // 金豆新增充值
  169. {
  170. path: 'add',
  171. name: "addBeanRecharge",
  172. component: () => import("../views/recharge/bean/addBeanRecharge.vue"),
  173. meta: { permissionId: 37 }
  174. },
  175. // 金豆系统充值
  176. {
  177. path: 'system',
  178. name: "beanSystemRecharge",
  179. component: () => import("../views/recharge/bean/beanSystemRecharge.vue"),
  180. meta: { permissionId: 35 }
  181. },
  182. // 金豆线上充值
  183. {
  184. path: 'online',
  185. name: "beanOnlineRecharge",
  186. component: () => import("../views/recharge/bean/beanOnlineRecharge.vue"),
  187. meta: { permissionId: 36 }
  188. }
  189. ]
  190. },
  191. // 金币退款
  192. {
  193. path: '/coinRefund',
  194. name: "coinRefund",
  195. component: () => import("../views/refund/gold/coinRefund.vue"),
  196. meta: { permissionId: 47 },
  197. children: [
  198. // 金币新增退款
  199. {
  200. path: 'add',
  201. name: "addCoinRefund",
  202. component: () => import("../views/refund/gold/addCoinRefund.vue"),
  203. meta: { permissionId: 48 }
  204. },
  205. // 金币退款明细详情
  206. {
  207. path: 'detail',
  208. name: "coinRefundDetail",
  209. component: () => import("../views/refund/gold/coinRefundDetail.vue"),
  210. meta: { permissionId: 49 }
  211. }
  212. ]
  213. },
  214. // 金币客户账户明细
  215. {
  216. path: '/usergold',
  217. name: "usergold",
  218. component: () => import("../views/usergold/gold/clientCount.vue"),
  219. meta: { permissionId: 51 },
  220. children: [
  221. // 金币明细
  222. {
  223. path: 'detail',
  224. name: "clientCountDetail",
  225. component: () => import("../views/usergold/gold/clientCountDetail.vue"),
  226. meta: { permissionId: 52 }
  227. },
  228. // 金币余额
  229. {
  230. path: 'balance',
  231. name: "clientCountBalance",
  232. component: () => import("../views/usergold/gold/clientCountBalance.vue"),
  233. meta: { permissionId: 53 }
  234. },
  235. ]
  236. },
  237. {
  238. path: '/userbean',
  239. name: "userbean",
  240. component: () => import("../views/usergold/bean/userbean.vue"),
  241. meta: { permissionId: 54 }
  242. },
  243. {
  244. path: '/history',
  245. name: "history",
  246. component: () => import("../views/history/history.vue"),
  247. meta: { permissionId: 55 },
  248. children: [
  249. {
  250. path: 'newHistory',
  251. name: "newHistory",
  252. component: () => import("../views/history/newHistory.vue"),
  253. meta: { permissionId: 56 }
  254. },
  255. {
  256. path: 'oldHistory',
  257. name: "oldHistory",
  258. component: () => import("../views/history/oldHistory.vue"),
  259. meta: { permissionId: 57 }
  260. }
  261. ]
  262. },
  263. // 权限管理
  264. {
  265. path: '/permissions',
  266. name: "permissions",
  267. component: () => import("../views/permissions/permissions.vue"),
  268. meta: { permissionId: 128 },
  269. children: [
  270. // 用户权限
  271. {
  272. path: 'userPermission',
  273. name: "userPermission",
  274. component: () => import("../views/permissions/userPermission.vue"),
  275. meta: { permissionId: 129 }
  276. },
  277. // 角色权限
  278. {
  279. path: 'rolePermission',
  280. name: "rolePermission",
  281. component: () => import("../views/permissions/rolePermission.vue"),
  282. meta: { permissionId: 130 }
  283. }
  284. ]
  285. }
  286. ]
  287. },
  288. // 现金管理
  289. {
  290. path: '/moneyManage',
  291. name: 'moneyManage',
  292. meta: { permissionId: 58 },
  293. children: [
  294. // 收款明细
  295. {
  296. path: 'receiveDetail',
  297. name: "receiveDetail",
  298. meta: { permissionId: 74 },
  299. children: [
  300. // 客服页面
  301. {
  302. path: 'receiveService',
  303. name: "receiveService",
  304. component: () => import("../views/moneyManage/receiveDetail/receiveService.vue"),
  305. meta: { permissionId: 60 }
  306. },
  307. // 地区负责人页面
  308. {
  309. path: 'receiveManager',
  310. name: "receiveManager",
  311. component: () => import("../views/moneyManage/receiveDetail/receiveManage.vue"),
  312. meta: { permissionId: [67, 79] }
  313. },
  314. {//地区财务
  315. path: 'receiveFinance',
  316. name: "receiveFinance",
  317. component: () => import("../views/moneyManage/receiveDetail/receiveFinance.vue"),
  318. meta: { permissionId: [67, 79] }
  319. },
  320. //总部管理员及财务
  321. {
  322. path: 'receiveHeader',
  323. name: "receiveHeader",
  324. component: () => import("../views/moneyManage/receiveDetail/receiveHead.vue"),
  325. meta: { permissionId: 91 }
  326. },
  327. ]
  328. },
  329. // 退款明细
  330. {
  331. path: 'refundDetail',
  332. name: "refundDetail",
  333. component: () => import("../views/moneyManage/refundDetail/refundDetail.vue"),
  334. meta: { permissionId: 98 },
  335. children: [
  336. // 客服页面
  337. {
  338. path: 'refundService',
  339. name: "refundService",
  340. component: () => import("../views/moneyManage/refundDetail/refundService.vue"),
  341. meta: { permissionId: 99 }
  342. },
  343. // 地区财务页面
  344. {
  345. path: 'refundFinance',
  346. name: "refundFinance",
  347. component: () => import("../views/moneyManage/refundDetail/refundFinance.vue"),
  348. meta: { permissionId: 103 }
  349. },
  350. // 地区负责人页面
  351. {
  352. path: 'refundCharge',
  353. name: "refundCharge",
  354. component: () => import("../views/moneyManage/refundDetail/refundCharge.vue"),
  355. meta: { permissionId: 107 }
  356. },
  357. //总部管理员及财务
  358. {
  359. path: 'refundHeader',
  360. name: "refundHeader",
  361. component: () => import("../views/moneyManage/refundDetail/refundHeader.vue"),
  362. meta: { permissionId: 111 }
  363. },
  364. ]
  365. },
  366. // 执行明细
  367. {
  368. path: 'executor',
  369. name: "executor",
  370. component: () => import("../views/moneyManage/executor/executor.vue"),
  371. meta: { permissionId: 115 }
  372. },
  373. ]
  374. },
  375. // 频道管理
  376. {
  377. path: 'channelManage',
  378. name: 'channelManage',
  379. meta: { permissionId: 124 },
  380. children: [
  381. // 打赏
  382. {
  383. path: 'reward',
  384. name: "reward",
  385. component: () => import("../views/channelManage/reward/reward.vue"),
  386. meta: { permissionId: 125 }
  387. },
  388. // 铁粉
  389. {
  390. path: 'fans',
  391. name: "fans",
  392. component: () => import("../views/channelManage/fans/fans.vue"),
  393. meta: { permissionId: 126 }
  394. },
  395. // 购物车
  396. {
  397. path: 'cart',
  398. name: "cart",
  399. component: () => import("../views/channelManage/cart/cart.vue"),
  400. meta: { permissionId: 127 }
  401. }
  402. ]
  403. },
  404. // 活动管理
  405. {
  406. path: 'activityManage',
  407. name: "activityManage",
  408. component: () => import("../views/activityManage/activity.vue"),
  409. meta: { permissionId: 119 }
  410. },
  411. // 没有权限
  412. {
  413. path: '/noPermission',
  414. name: "noPermission",
  415. component: () => import("../views/noPermissionPage.vue")
  416. }
  417. ]
  418. },
  419. // 跳转页面(无需权限)
  420. {
  421. path: '/PasswordSuccess',
  422. name: "PasswordSuccess",
  423. component: () => import("../components/PasswordSuccess.vue")
  424. }
  425. ];
  426. // 创建路由实例
  427. const router = createRouter({
  428. history: createWebHashHistory(),
  429. routes
  430. });
  431. // 工具函数:从菜单树提取所有权限ID
  432. const getAllPermissionIds = (menuTree) => {
  433. let permissionIds = [];
  434. const traverse = (menuList) => {
  435. menuList.forEach(menu => {
  436. permissionIds.push(menu.id);
  437. if (menu.children && menu.children.length > 0) {
  438. traverse(menu.children);
  439. }
  440. });
  441. };
  442. traverse(menuTree);
  443. return permissionIds;
  444. };
  445. // 全局路由守卫
  446. router.beforeEach(async (to, from, next) => {
  447. const adminStore = useAdminStore()
  448. const { adminData, menuTree } = storeToRefs(adminStore)
  449. const token = localStorage.getItem("token");
  450. const machineId = localStorage.getItem("machineId");
  451. // 1. 未登录:强制跳转到登录页
  452. if (to.name !== "login" && !token) {
  453. next(`/login?machineId=${machineId || ''}`);
  454. return;
  455. }
  456. // 2. 已登录:处理权限验证
  457. if (token) {
  458. // 获取管理员信息
  459. let roleId = null;
  460. console.log('路由的adminData:', adminData.value)
  461. try {
  462. roleId = adminData.value.roleId;
  463. if (!roleId) {
  464. localStorage.removeItem('token'); // 清除token,强制重新登录
  465. next(`/login?machineId=${machineId || ''}`);
  466. return;
  467. }
  468. } catch (error) {
  469. localStorage.removeItem('token'); // 清除token,强制重新登录
  470. adminStore.clearState()
  471. next(`/login?machineId=${machineId || ''}`);
  472. return;
  473. }
  474. let userPermissionIds = [];
  475. // 拿权限id
  476. userPermissionIds = getAllPermissionIds(menuTree.value)
  477. console.log("userPermissionIds", userPermissionIds)
  478. // 2.4 权限验证(逻辑不变)
  479. console.log('to.meta:', to.meta)
  480. const requiresPermission = to.meta && to.meta.permissionId;
  481. if (requiresPermission) {
  482. const hasPermission = Array.isArray(requiresPermission)
  483. ? requiresPermission.some(id => userPermissionIds.includes(id))
  484. : userPermissionIds.includes(requiresPermission);
  485. if (!hasPermission) {
  486. next('/noPermission');
  487. return;
  488. }
  489. }
  490. }
  491. // 3. 正常跳转
  492. next();
  493. });
  494. export default router;