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.

683 lines
29 KiB

10 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
7 months ago
9 months ago
9 months ago
9 months ago
7 months ago
6 months ago
7 months ago
7 months ago
9 months ago
9 months ago
9 months ago
9 months ago
5 months ago
9 months ago
9 months ago
9 months ago
6 months ago
5 months ago
9 months ago
9 months ago
7 months ago
7 months ago
7 months ago
7 months ago
9 months ago
9 months ago
7 months ago
7 months ago
9 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
2 weeks ago
5 months ago
5 months ago
9 months ago
9 months ago
10 months ago
9 months ago
10 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
6 months ago
9 months ago
9 months ago
2 weeks ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. import {createRouter, createWebHashHistory} from 'vue-router';
  2. import {storeToRefs} from "pinia";
  3. import {useAdminStore, useMessageStore} from "@/store/index.js";
  4. import API from '@/util/http.js';
  5. import {ref} from "vue";
  6. // 路由定义(包含权限映射 meta.permissionId)
  7. const routes = [
  8. {
  9. path: '/',
  10. redirect: "/login"
  11. },
  12. {
  13. path: "/login",
  14. name: "login",
  15. component: () => import("../views/login.vue"),
  16. },
  17. {
  18. meta: {requireAuth: true},
  19. path: '/',
  20. component: () => import("../views/home.vue"),
  21. children: [
  22. // 工作台
  23. {
  24. path: 'workbench',
  25. name: "workbench",
  26. component: () => import("../views/workspace/index.vue"),
  27. meta: {permissionId: 2}
  28. },
  29. //金币管理
  30. {
  31. path: '/goldManage',
  32. name: 'goldManage',
  33. meta: {permissionId: 3},
  34. children: [
  35. // 审核
  36. {
  37. path: '/audit',
  38. name: "audit",
  39. component: () => import("../views/audit/gold/audit.vue"),
  40. meta: {permissionId: 4},
  41. children: [
  42. // 充值审核
  43. {
  44. path: 'rechargeAudit',
  45. name: "rechargeAudit",
  46. component: () => import("../views/audit/gold/rechargeAudit.vue"),
  47. meta: {permissionId: [6, 7, 8, 9, 10, 11, 12]}
  48. },
  49. // 退款审核
  50. {
  51. path: 'refundAudit',
  52. name: "refundAudit",
  53. component: () => import("../views/audit/gold/refundAudit.vue"),
  54. meta: {permissionId: [13, 14, 15, 16, 17, 18, 19]}
  55. },
  56. ]
  57. }, {
  58. path: '/beanAudit',
  59. name: "beanAudit",
  60. component: () => import("../views/audit/bean/beanAudit.vue"),
  61. meta: {permissionId: 20},
  62. children: [
  63. // 充值审核
  64. {
  65. path: 'addbeanAudit',
  66. name: "addbeanAudit",
  67. component: () => import("../views/audit/bean/beanAudit.vue"),
  68. meta: {permissionId: [21, 22, 23, 24, 25, 26]}
  69. },
  70. ]
  71. },
  72. // 金币消耗
  73. {
  74. path: '/coinConsume',
  75. name: "coinConsume",
  76. component: () => import("../views/consume/gold/coinConsume.vue"),
  77. meta: {permissionId: 39},
  78. children: [
  79. // 金币新增消耗
  80. {
  81. path: 'add',
  82. name: "addCoinConsume",
  83. component: () => import("../views/consume/gold/addCoinConsume.vue"),
  84. meta: {permissionId: 41}
  85. },
  86. // 金币消耗明细详情
  87. {
  88. path: 'detail',
  89. name: "coinConsumeDetail",
  90. component: () => import("../views/consume/gold/coinConsumeDetail.vue"),
  91. meta: {permissionId: 40}
  92. }
  93. ]
  94. },
  95. // 金豆消耗
  96. {
  97. path: '/beanConsume',
  98. name: "beanConsume",
  99. component: () => import("../views/consume/bean/beanConsume.vue"),
  100. meta: {permissionId: 42},
  101. children: [
  102. // 金豆新增消耗
  103. {
  104. path: 'add',
  105. name: "addBeanConsume",
  106. component: () => import("../views/consume/bean/addBeanConsume.vue"),
  107. meta: {permissionId: 46}
  108. },
  109. // 直播
  110. {
  111. path: 'live',
  112. name: "liveStream",
  113. component: () => import("../views/consume/bean/liveStream.vue"),
  114. meta: {permissionId: 43}
  115. },
  116. // 铁粉
  117. {
  118. path: 'fan',
  119. name: "dieHardFan",
  120. component: () => import("../views/consume/bean/dieHardFan.vue"),
  121. meta: {permissionId: 44}
  122. },
  123. // 文章视频
  124. {
  125. path: 'article',
  126. name: "articleVideo",
  127. component: () => import("../views/consume/bean/articleVideo.vue"),
  128. meta: {permissionId: 45}
  129. }
  130. ]
  131. },
  132. // 汇率管理
  133. {
  134. path: '/rate',
  135. name: "rate",
  136. component: () => import("../views/managerecharge/rate.vue"),
  137. meta: {permissionId: [27, 28, 29]}
  138. },
  139. // 金币充值
  140. {
  141. path: '/coinRecharge',
  142. name: "coinRecharge",
  143. component: () => import("../views/recharge/gold/coinRecharge.vue"),
  144. meta: {permissionId: 31},
  145. children: [
  146. // 金币新增充值
  147. {
  148. path: 'add',
  149. name: "addCoinRecharge",
  150. component: () => import("../views/recharge/gold/addCoinRecharge.vue"),
  151. meta: {permissionId: 33}
  152. },
  153. // 金币充值明细
  154. {
  155. path: 'detail',
  156. name: "coinRechargeDetail",
  157. component: () => import("../views/recharge/gold/coinRechargeDetail.vue"),
  158. meta: {permissionId: 32}
  159. }
  160. ]
  161. },
  162. // 金豆充值
  163. {
  164. path: '/beanRecharge',
  165. name: "beanRecharge",
  166. component: () => import("../views/recharge/bean/beanRecharge.vue"),
  167. meta: {permissionId: 34},
  168. children: [
  169. // 金豆新增充值
  170. {
  171. path: 'add',
  172. name: "addBeanRecharge",
  173. component: () => import("../views/recharge/bean/addBeanRecharge.vue"),
  174. meta: {permissionId: 37}
  175. },
  176. // 金豆系统充值
  177. {
  178. path: 'system',
  179. name: "beanSystemRecharge",
  180. component: () => import("../views/recharge/bean/beanSystemRecharge.vue"),
  181. meta: {permissionId: 35}
  182. },
  183. // 金豆线上充值
  184. {
  185. path: 'online',
  186. name: "beanOnlineRecharge",
  187. component: () => import("../views/recharge/bean/beanOnlineRecharge.vue"),
  188. meta: {permissionId: 36}
  189. }
  190. ]
  191. },
  192. // 金币退款
  193. {
  194. path: '/coinRefund',
  195. name: "coinRefund",
  196. component: () => import("../views/refund/gold/coinRefund.vue"),
  197. meta: {permissionId: 47},
  198. children: [
  199. // 金币新增退款
  200. {
  201. path: 'add',
  202. name: "addCoinRefund",
  203. component: () => import("../views/refund/gold/addCoinRefund.vue"),
  204. meta: {permissionId: 48}
  205. },
  206. // 金币退款明细详情
  207. {
  208. path: 'detail',
  209. name: "coinRefundDetail",
  210. component: () => import("../views/refund/gold/coinRefundDetail.vue"),
  211. meta: {permissionId: 49}
  212. }
  213. ]
  214. },
  215. // 金币客户账户明细
  216. {
  217. path: '/usergold',
  218. name: "usergold",
  219. component: () => import("../views/usergold/gold/clientCount.vue"),
  220. meta: {permissionId: 51},
  221. children: [
  222. // 金币明细
  223. {
  224. path: 'detail',
  225. name: "clientCountDetail",
  226. component: () => import("../views/usergold/gold/clientCountDetail.vue"),
  227. meta: {permissionId: 52}
  228. },
  229. // 金币余额
  230. {
  231. path: 'balance',
  232. name: "clientCountBalance",
  233. component: () => import("../views/usergold/gold/clientCountBalance.vue"),
  234. meta: {permissionId: 53}
  235. },
  236. // 客户钱包
  237. {
  238. path: 'wallet',
  239. name: "clientCountWallet",
  240. component: () => import("../views/usergold/gold/clientCountWallet.vue"),
  241. meta: {permissionId: 150}
  242. }
  243. ]
  244. },
  245. {
  246. path: '/userbean',
  247. name: "userbean",
  248. component: () => import("../views/usergold/bean/userbean.vue"),
  249. meta: {permissionId: 54}
  250. },
  251. {
  252. path: '/history',
  253. name: "history",
  254. component: () => import("../views/history/history.vue"),
  255. meta: {permissionId: 55},
  256. children: [
  257. {
  258. path: 'newHistory',
  259. name: "newHistory",
  260. component: () => import("../views/history/newHistory.vue"),
  261. meta: {permissionId: 56}
  262. },
  263. {
  264. path: 'oldHistory',
  265. name: "oldHistory",
  266. component: () => import("../views/history/oldHistory.vue"),
  267. meta: {permissionId: 57}
  268. }
  269. ]
  270. },
  271. // 权限管理
  272. {
  273. path: '/permissions',
  274. name: "permissions",
  275. component: () => import("../views/permissions/permissions.vue"),
  276. meta: {permissionId: 128},
  277. children: [
  278. // 用户权限
  279. {
  280. path: 'userPermission',
  281. name: "userPermission",
  282. component: () => import("../views/permissions/userPermission.vue"),
  283. meta: {permissionId: 129}
  284. },
  285. // 角色权限
  286. {
  287. path: 'rolePermission',
  288. name: "rolePermission",
  289. component: () => import("../views/permissions/rolePermission.vue"),
  290. meta: {permissionId: 130}
  291. }
  292. ]
  293. }
  294. ]
  295. },
  296. // 现金管理
  297. {
  298. path: '/moneyManage',
  299. name: 'moneyManage',
  300. meta: {permissionId: 58},
  301. children: [
  302. // 收款明细
  303. {
  304. path: 'receiveDetail',
  305. name: "receiveDetail",
  306. meta: {permissionId: 59},
  307. children: [
  308. // 收款提交
  309. {
  310. path: 'receiveService',
  311. name: "receiveService",
  312. component: () => import("../views/moneyManage/receiveDetail/receiveService.vue"),
  313. meta: {permissionId: [60, 61, 62, 63, 64, 65, 66]}
  314. },
  315. // 收款处理(负责人)
  316. {
  317. path: 'receiveManager',
  318. name: "receiveManager",
  319. component: () => import("../views/moneyManage/receiveDetail/receiveManage.vue"),
  320. meta: {permissionId: [79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90]}
  321. },
  322. {//收款处理
  323. path: 'receiveFinance',
  324. name: "receiveFinance",
  325. component: () => import("../views/moneyManage/receiveDetail/receiveFinance.vue"),
  326. meta: {permissionId: [67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]}
  327. },
  328. //总部管理员及财务(移除)
  329. // {
  330. // path: 'receiveHeader',
  331. // name: "receiveHeader",
  332. // component: () => import("../views/moneyManage/receiveDetail/receiveHead.vue"),
  333. // meta: {permissionId: 91}
  334. // },
  335. ]
  336. },
  337. // 退款明细
  338. {
  339. path: 'refundDetail',
  340. name: "refundDetail",
  341. component: () => import("../views/moneyManage/refundDetail/refundDetail.vue"),
  342. meta: {permissionId: 98},
  343. children: [
  344. // 退款提交
  345. {
  346. path: 'refundService',
  347. name: "refundService",
  348. component: () => import("../views/moneyManage/refundDetail/refundService.vue"),
  349. meta: {permissionId: [99, 100, 101, 102]}
  350. },
  351. // 退款审批
  352. {
  353. path: 'refundFinance',
  354. name: "refundFinance",
  355. component: () => import("../views/moneyManage/refundDetail/refundFinance.vue"),
  356. meta: {permissionId: [103, 104, 105, 106]}
  357. },
  358. // 退款审批(负责人)
  359. {
  360. path: 'refundCharge',
  361. name: "refundCharge",
  362. component: () => import("../views/moneyManage/refundDetail/refundCharge.vue"),
  363. meta: {permissionId: [107, 108, 109, 110]}
  364. },
  365. // 退款审批(总部财务)
  366. {
  367. path: 'refundHeader',
  368. name: "refundHeader",
  369. component: () => import("../views/moneyManage/refundDetail/refundHeader.vue"),
  370. meta: {permissionId: [111, 112, 113, 114]}
  371. },
  372. ]
  373. },
  374. // 退款执行
  375. {
  376. path: 'executor',
  377. name: "executor",
  378. component: () => import("../views/moneyManage/executor/executor.vue"),
  379. meta: {permissionId: [115, 116, 117, 118]}
  380. },
  381. // 财务核算
  382. {
  383. path: 'financialAccount',
  384. name: "financialAccount",
  385. meta: {permissionId: 147},
  386. children: [
  387. // 资金流水
  388. {
  389. path: 'cashFlow',
  390. name: "cashFlow",
  391. component: () => import("../views/moneyManage/financialAccount/cashFlow.vue"),
  392. meta: {permissionId: 148}
  393. },
  394. // 业绩归属
  395. {
  396. path: 'performanceAttribution',
  397. name: "performanceAttribution",
  398. component: () => import("../views/moneyManage/financialAccount/performanceAttribution.vue"),
  399. meta: {permissionId: 149}
  400. },
  401. ]
  402. }
  403. ]
  404. },
  405. // 钱包管理
  406. {
  407. path: 'walletManage',
  408. name: 'walletManage',
  409. meta: {permissionId: 150},
  410. children: [
  411. // 钱包余额
  412. {
  413. path: 'walletBalance',
  414. name: "walletBalance",
  415. component: () => import("../views/walletManage/WalletBalance.vue"),
  416. meta: {permissionId: 151}
  417. },
  418. // 钱包明细
  419. {
  420. path: 'walletDetail',
  421. name: "walletDetail",
  422. meta: {permissionId: 152},
  423. children: [
  424. // 香港钱包
  425. {
  426. path: 'hkWallet',
  427. name: "hkWallet",
  428. component: () => import("../views/walletManage/walletDetail/HKWallet.vue"),
  429. meta: {permissionId: 153}
  430. },
  431. //新加坡HC钱包
  432. {
  433. path: 'sgWalletHC',
  434. name: "sgWalletHC",
  435. component: () => import("../views/walletManage/walletDetail/SGWalletHC.vue"),
  436. meta: {permissionId: 154}
  437. },
  438. //马来钱包
  439. {
  440. path: 'myWallet',
  441. name: "myWallet",
  442. component: () => import("../views/walletManage/walletDetail/MyWallet.vue"),
  443. meta: {permissionId: 155}
  444. },
  445. // 新加坡CM钱包
  446. {
  447. path: 'sgWalletCM',
  448. name: "sgWalletCM",
  449. component: () => import("../views/walletManage/walletDetail/SGWalletCM.vue"),
  450. meta: {permissionId: 156}
  451. },
  452. // 加拿大钱包
  453. {
  454. path: 'caWallet',
  455. name: "caWallet",
  456. component: () => import("../views/walletManage/walletDetail/CAWallet.vue"),
  457. meta: {permissionId: 157}
  458. },
  459. //泰国HS钱包
  460. {
  461. path: 'thWalletHS',
  462. name: "thWalletHS",
  463. component: () => import("../views/walletManage/walletDetail/THWalletHS.vue"),
  464. meta: {permissionId: 158}
  465. },
  466. //泰国HA钱包
  467. {
  468. path: 'thWalletHA',
  469. name: "thWalletHA",
  470. component: () => import("../views/walletManage/walletDetail/THWalletHA.vue"),
  471. meta: {permissionId: 159}
  472. },
  473. //越南钱包
  474. {
  475. path: 'vnWallet',
  476. name: "vnWallet",
  477. component: () => import("../views/walletManage/walletDetail/VNWallet.vue"),
  478. meta: {permissionId: 160}
  479. },
  480. //北京钱包
  481. {
  482. path: 'bjWallet',
  483. name: "bjWallet",
  484. component: () => import("../views/walletManage/walletDetail/BJWallet.vue"),
  485. meta: {permissionId: 161}
  486. },
  487. ]
  488. },
  489. ]
  490. },
  491. // 频道管理
  492. {
  493. path: 'channelManage',
  494. name: 'channelManage',
  495. meta: {permissionId: 124},
  496. children: [
  497. // 打赏
  498. {
  499. path: 'reward',
  500. name: "reward",
  501. component: () => import("../views/channelManage/reward/reward.vue"),
  502. meta: {permissionId: 125}
  503. },
  504. // 铁粉
  505. {
  506. path: 'fans',
  507. name: "fans",
  508. component: () => import("../views/channelManage/fans/fans.vue"),
  509. meta: {permissionId: 126}
  510. },
  511. // 购物车
  512. {
  513. path: 'cart',
  514. name: "cart",
  515. component: () => import("../views/noPermissionPage.vue"),
  516. meta: {permissionId: 127}
  517. }
  518. ]
  519. },
  520. // 活动管理
  521. {
  522. path: 'activityManage',
  523. name: "activityManage",
  524. component: () => import("../views/activityManage/activity.vue"),
  525. meta: {permissionId: 119}
  526. },
  527. // 多语言配置
  528. {
  529. path: 'language',
  530. name: "language",
  531. component: () => import("../views/language/languageTranslate.vue"),
  532. meta: {permissionId: 146}
  533. },
  534. // 没有权限
  535. {
  536. path: '/noPermission',
  537. name: "noPermission",
  538. component: () => import("../views/noPermissionPage.vue")
  539. }
  540. ]
  541. },
  542. // 跳转页面(无需权限)
  543. {
  544. path: '/PasswordSuccess',
  545. name: "PasswordSuccess",
  546. component: () => import("../components/PasswordSuccess.vue")
  547. }
  548. ];
  549. // 创建路由实例
  550. const router = createRouter({
  551. history: createWebHashHistory(),
  552. routes
  553. });
  554. // 工具函数:从菜单树提取所有权限ID
  555. const getAllPermissionIds = (menuTree) => {
  556. let permissionIds = [];
  557. const traverse = (menuList) => {
  558. menuList.forEach(menu => {
  559. permissionIds.push(menu.id);
  560. if (menu.children && menu.children.length > 0) {
  561. traverse(menu.children);
  562. }
  563. });
  564. };
  565. traverse(menuTree);
  566. return permissionIds;
  567. };
  568. // 全局路由守卫
  569. router.beforeEach(async (to, from, next) => {
  570. const adminStore = useAdminStore()
  571. const {adminData, menuTree} = storeToRefs(adminStore)
  572. const token = localStorage.getItem("token");
  573. const machineId = localStorage.getItem("machineId");
  574. // 1. 未登录:强制跳转到登录页
  575. if (to.name !== "login" && !token) {
  576. next(`/login?machineId=${machineId || ''}`);
  577. return;
  578. }
  579. // 2. 已登录:处理权限验证
  580. if (token) {
  581. // 获取管理员信息
  582. let roleId = null;
  583. console.log('路由的adminData:', adminData.value)
  584. try {
  585. roleId = adminData.value.roleId;
  586. if (!roleId) {
  587. localStorage.removeItem('token'); // 清除token,强制重新登录
  588. next(`/login?machineId=${machineId || ''}`);
  589. return;
  590. }
  591. } catch (error) {
  592. localStorage.removeItem('token'); // 清除token,强制重新登录
  593. adminStore.clearState()
  594. next(`/login?machineId=${machineId || ''}`);
  595. return;
  596. }
  597. let userPermissionIds = [];
  598. // 拿权限id
  599. userPermissionIds = getAllPermissionIds(menuTree.value)
  600. console.log("userPermissionIds", userPermissionIds)
  601. // 2.4 权限验证(逻辑不变)
  602. console.log('to.meta:', to.meta)
  603. const requiresPermission = to.meta && to.meta.permissionId;
  604. if (requiresPermission) {
  605. const hasPermission = Array.isArray(requiresPermission)
  606. ? requiresPermission.some(id => userPermissionIds.some(uid => String(uid) === String(id)))
  607. : userPermissionIds.some(uid => String(uid) === String(requiresPermission));
  608. if (!hasPermission) {
  609. next('/noPermission');
  610. return;
  611. }
  612. }
  613. }
  614. // 3. 正常跳转
  615. next();
  616. });
  617. const rawItems = ref([])
  618. // 全局后置守卫:每次路由切换后执行
  619. router.afterEach(async (to) => { // 接收to参数获取当前路由信息
  620. // 判断当前路由是否是登录页,如果是则直接返回不执行后续逻辑
  621. if (to.path === '/login') {
  622. return;
  623. }
  624. // 1. 从localStorage获取数据(localStorage存储的是字符串,需解析)
  625. const statusStr = localStorage.getItem('status');
  626. if (statusStr) {
  627. // 示例:如果原始字符串是逗号分隔的格式(如 "1,2,3"),可按分隔符拆分后遍历
  628. rawItems.value = statusStr.split(','); // 根据实际格式调整分隔符
  629. rawItems.value.forEach((item, index) => {
  630. console.log(`索引${index}`, item.trim()); // trim() 去除空格(可选)
  631. });
  632. } else {
  633. console.log('localStorage中无status数据');
  634. }
  635. try {
  636. // 执行/getMessage请求
  637. const newMessageRes = await API({
  638. url: '/getMessage',
  639. method: 'POST',
  640. data: {status: rawItems.value}
  641. });
  642. console.log('newMessageRes=======================:', newMessageRes.data)
  643. // 存入全局状态,供所有页面访问
  644. const messageStore = useMessageStore();
  645. // 过滤 flag=1的消息
  646. const list = Array.isArray(newMessageRes.data)
  647. ? newMessageRes.data
  648. : (Array.isArray(newMessageRes.data?.list) ? newMessageRes.data.list : []);
  649. messageStore.setMessages(list.filter(item => item.flag !== 1));
  650. } catch (error) {
  651. console.error('获取消息失败:', error);
  652. }
  653. });
  654. export default router;