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.

597 lines
25 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
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
1 week 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: 'channelManage',
  408. name: 'channelManage',
  409. meta: {permissionId: 124},
  410. children: [
  411. // 打赏
  412. {
  413. path: 'reward',
  414. name: "reward",
  415. component: () => import("../views/channelManage/reward/reward.vue"),
  416. meta: {permissionId: 125}
  417. },
  418. // 铁粉
  419. {
  420. path: 'fans',
  421. name: "fans",
  422. component: () => import("../views/channelManage/fans/fans.vue"),
  423. meta: {permissionId: 126}
  424. },
  425. // 购物车
  426. {
  427. path: 'cart',
  428. name: "cart",
  429. component: () => import("../views/noPermissionPage.vue"),
  430. meta: {permissionId: 127}
  431. }
  432. ]
  433. },
  434. // 活动管理
  435. {
  436. path: 'activityManage',
  437. name: "activityManage",
  438. component: () => import("../views/activityManage/activity.vue"),
  439. meta: {permissionId: 119}
  440. },
  441. // 多语言配置
  442. {
  443. path: 'language',
  444. name: "language",
  445. component: () => import("../views/language/languageTranslate.vue"),
  446. meta: {permissionId: 146}
  447. },
  448. // 没有权限
  449. {
  450. path: '/noPermission',
  451. name: "noPermission",
  452. component: () => import("../views/noPermissionPage.vue")
  453. }
  454. ]
  455. },
  456. // 跳转页面(无需权限)
  457. {
  458. path: '/PasswordSuccess',
  459. name: "PasswordSuccess",
  460. component: () => import("../components/PasswordSuccess.vue")
  461. }
  462. ];
  463. // 创建路由实例
  464. const router = createRouter({
  465. history: createWebHashHistory(),
  466. routes
  467. });
  468. // 工具函数:从菜单树提取所有权限ID
  469. const getAllPermissionIds = (menuTree) => {
  470. let permissionIds = [];
  471. const traverse = (menuList) => {
  472. menuList.forEach(menu => {
  473. permissionIds.push(menu.id);
  474. if (menu.children && menu.children.length > 0) {
  475. traverse(menu.children);
  476. }
  477. });
  478. };
  479. traverse(menuTree);
  480. return permissionIds;
  481. };
  482. // 全局路由守卫
  483. router.beforeEach(async (to, from, next) => {
  484. const adminStore = useAdminStore()
  485. const {adminData, menuTree} = storeToRefs(adminStore)
  486. const token = localStorage.getItem("token");
  487. const machineId = localStorage.getItem("machineId");
  488. // 1. 未登录:强制跳转到登录页
  489. if (to.name !== "login" && !token) {
  490. next(`/login?machineId=${machineId || ''}`);
  491. return;
  492. }
  493. // 2. 已登录:处理权限验证
  494. if (token) {
  495. // 获取管理员信息
  496. let roleId = null;
  497. console.log('路由的adminData:', adminData.value)
  498. try {
  499. roleId = adminData.value.roleId;
  500. if (!roleId) {
  501. localStorage.removeItem('token'); // 清除token,强制重新登录
  502. next(`/login?machineId=${machineId || ''}`);
  503. return;
  504. }
  505. } catch (error) {
  506. localStorage.removeItem('token'); // 清除token,强制重新登录
  507. adminStore.clearState()
  508. next(`/login?machineId=${machineId || ''}`);
  509. return;
  510. }
  511. let userPermissionIds = [];
  512. // 拿权限id
  513. userPermissionIds = getAllPermissionIds(menuTree.value)
  514. console.log("userPermissionIds", userPermissionIds)
  515. // 2.4 权限验证(逻辑不变)
  516. console.log('to.meta:', to.meta)
  517. const requiresPermission = to.meta && to.meta.permissionId;
  518. if (requiresPermission) {
  519. const hasPermission = Array.isArray(requiresPermission)
  520. ? requiresPermission.some(id => userPermissionIds.some(uid => String(uid) === String(id)))
  521. : userPermissionIds.some(uid => String(uid) === String(requiresPermission));
  522. if (!hasPermission) {
  523. next('/noPermission');
  524. return;
  525. }
  526. }
  527. }
  528. // 3. 正常跳转
  529. next();
  530. });
  531. const rawItems = ref([])
  532. // 全局后置守卫:每次路由切换后执行
  533. router.afterEach(async (to) => { // 接收to参数获取当前路由信息
  534. // 判断当前路由是否是登录页,如果是则直接返回不执行后续逻辑
  535. if (to.path === '/login') {
  536. return;
  537. }
  538. // 1. 从localStorage获取数据(localStorage存储的是字符串,需解析)
  539. const statusStr = localStorage.getItem('status');
  540. if (statusStr) {
  541. // 示例:如果原始字符串是逗号分隔的格式(如 "1,2,3"),可按分隔符拆分后遍历
  542. rawItems.value = statusStr.split(','); // 根据实际格式调整分隔符
  543. rawItems.value.forEach((item, index) => {
  544. console.log(`索引${index}`, item.trim()); // trim() 去除空格(可选)
  545. });
  546. } else {
  547. console.log('localStorage中无status数据');
  548. }
  549. try {
  550. // 执行/getMessage请求
  551. const newMessageRes = await API({
  552. url: '/getMessage',
  553. method: 'POST',
  554. data: {status: rawItems.value}
  555. });
  556. console.log('newMessageRes=======================:', newMessageRes.data)
  557. // 存入全局状态,供所有页面访问
  558. const messageStore = useMessageStore();
  559. // 过滤 flag=1的消息
  560. const list = Array.isArray(newMessageRes.data)
  561. ? newMessageRes.data
  562. : (Array.isArray(newMessageRes.data?.list) ? newMessageRes.data.list : []);
  563. messageStore.setMessages(list.filter(item => item.flag !== 1));
  564. } catch (error) {
  565. console.error('获取消息失败:', error);
  566. }
  567. });
  568. export default router;