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.

478 lines
20 KiB

6 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 weeks ago
4 months ago
2 months ago
4 months ago
1 month ago
4 months ago
4 months ago
4 weeks ago
4 weeks ago
4 weeks ago
2 months ago
4 weeks ago
1 month 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
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 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 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
4 weeks ago
2 months ago
4 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
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. path: '/moneyManage',
  290. name: 'moneyManage',
  291. meta: { permissionId: 58 },
  292. children: [
  293. // 收款明细
  294. {
  295. path: 'receiveDetail',
  296. name: "receiveDetail",
  297. meta: { permissionId: 74 },
  298. children:[
  299. // 客服页面
  300. {
  301. path: 'receiveService',
  302. name: "receiveService",
  303. component: () => import("../views/moneyManage/receiveDetail/receiveDetail.vue"),
  304. meta: { permissionId: 60 }
  305. },
  306. // 地区财务及地区负责人页面
  307. {
  308. path: 'receiveArea',
  309. name: "receiveArea",
  310. component: () => import("../views/moneyManage/receiveDetail/receiveDetail.vue"),
  311. meta: { permissionId: [67,79] }
  312. },
  313. //总部管理员及财务
  314. {
  315. path: 'receiveHead',
  316. name: "receiveHead",
  317. component: () => import("../views/moneyManage/receiveDetail/receiveDetail.vue"),
  318. meta: { permissionId: 91 }
  319. },
  320. ]
  321. },
  322. // 退款明细
  323. {
  324. path: 'refundDetail',
  325. name: "refundDetail",
  326. component: () => import("../views/moneyManage/refundDetail/refundDetail.vue"),
  327. meta: { permissionId: 98 },
  328. children: [
  329. // 客服页面
  330. {
  331. path: 'refundService',
  332. name: "refundService",
  333. component: () => import("../views/moneyManage/refundDetail/refundService.vue"),
  334. meta: { permissionId: 99 }
  335. },
  336. // 地区财务页面
  337. {
  338. path: 'refundFinance',
  339. name: "refundFinance",
  340. component: () => import("../views/moneyManage/refundDetail/refundFinance.vue"),
  341. meta: { permissionId: 103 }
  342. },
  343. // 地区负责人页面
  344. {
  345. path: 'refundCharge',
  346. name: "refundCharge",
  347. component: () => import("../views/moneyManage/refundDetail/refundCharge.vue"),
  348. meta: { permissionId: 107 }
  349. },
  350. //总部管理员及财务
  351. {
  352. path: 'refundHeader',
  353. name: "refundHeader",
  354. component: () => import("../views/moneyManage/refundDetail/refundHeader.vue"),
  355. meta: { permissionId: 111 }
  356. },
  357. ]
  358. },
  359. // 执行明细
  360. {
  361. path: 'executor',
  362. name: "executor",
  363. component: () => import("../views/moneyManage/executor/executor.vue"),
  364. meta: { permissionId: 115 }
  365. },
  366. ]
  367. },
  368. // 没有权限
  369. {
  370. path: '/noPermission',
  371. name: "noPermission",
  372. component: () => import("../views/noPermissionPage.vue")
  373. }
  374. ]
  375. },
  376. // 跳转页面(无需权限)
  377. {
  378. path: '/PasswordSuccess',
  379. name: "PasswordSuccess",
  380. component: () => import("../components/PasswordSuccess.vue")
  381. }
  382. ];
  383. // 创建路由实例
  384. const router = createRouter({
  385. history: createWebHashHistory(),
  386. routes
  387. });
  388. // 工具函数:从菜单树提取所有权限ID
  389. const getAllPermissionIds = (menuTree) => {
  390. let permissionIds = [];
  391. const traverse = (menuList) => {
  392. menuList.forEach(menu => {
  393. permissionIds.push(menu.id);
  394. if (menu.children && menu.children.length > 0) {
  395. traverse(menu.children);
  396. }
  397. });
  398. };
  399. traverse(menuTree);
  400. return permissionIds;
  401. };
  402. // 全局路由守卫
  403. router.beforeEach(async (to, from, next) => {
  404. const adminStore = useAdminStore()
  405. const { adminData, menuTree } = storeToRefs(adminStore)
  406. const token = localStorage.getItem("token");
  407. const machineId = localStorage.getItem("machineId");
  408. // 1. 未登录:强制跳转到登录页
  409. if (to.name !== "login" && !token) {
  410. next(`/login?machineId=${machineId || ''}`);
  411. return;
  412. }
  413. // 2. 已登录:处理权限验证
  414. if (token) {
  415. // 获取管理员信息
  416. let roleId = null;
  417. console.log('路由的adminData:', adminData.value)
  418. try {
  419. roleId = adminData.value.roleId;
  420. if (!roleId) {
  421. localStorage.removeItem('token'); // 清除token,强制重新登录
  422. next(`/login?machineId=${machineId || ''}`);
  423. return;
  424. }
  425. } catch (error) {
  426. localStorage.removeItem('token'); // 清除token,强制重新登录
  427. adminStore.clearState()
  428. next(`/login?machineId=${machineId || ''}`);
  429. return;
  430. }
  431. let userPermissionIds = [];
  432. // 拿权限id
  433. userPermissionIds = getAllPermissionIds(menuTree.value)
  434. console.log("userPermissionIds", userPermissionIds)
  435. // 2.4 权限验证(逻辑不变)
  436. console.log('to.meta:', to.meta)
  437. const requiresPermission = to.meta && to.meta.permissionId;
  438. if (requiresPermission) {
  439. const hasPermission = Array.isArray(requiresPermission)
  440. ? requiresPermission.some(id => userPermissionIds.includes(id))
  441. : userPermissionIds.includes(requiresPermission);
  442. if (!hasPermission) {
  443. next('/noPermission');
  444. return;
  445. }
  446. }
  447. }
  448. // 3. 正常跳转
  449. next();
  450. });
  451. export default router;