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.

566 lines
23 KiB

7 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
4 months ago
6 months ago
6 months ago
6 months ago
4 months ago
3 months ago
4 months ago
4 months ago
6 months ago
6 months ago
6 months ago
6 months ago
2 months ago
6 months ago
6 months ago
6 months ago
3 months ago
2 months ago
6 months ago
6 months ago
4 months ago
4 months ago
4 months ago
4 months ago
6 months ago
6 months ago
4 months ago
4 months ago
5 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
2 months ago
6 months ago
6 months ago
7 months ago
6 months ago
7 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
3 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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. {
  239. path: '/userbean',
  240. name: "userbean",
  241. component: () => import("../views/usergold/bean/userbean.vue"),
  242. meta: {permissionId: 54}
  243. },
  244. {
  245. path: '/history',
  246. name: "history",
  247. component: () => import("../views/history/history.vue"),
  248. meta: {permissionId: 55},
  249. children: [
  250. {
  251. path: 'newHistory',
  252. name: "newHistory",
  253. component: () => import("../views/history/newHistory.vue"),
  254. meta: {permissionId: 56}
  255. },
  256. {
  257. path: 'oldHistory',
  258. name: "oldHistory",
  259. component: () => import("../views/history/oldHistory.vue"),
  260. meta: {permissionId: 57}
  261. }
  262. ]
  263. },
  264. // 权限管理
  265. {
  266. path: '/permissions',
  267. name: "permissions",
  268. component: () => import("../views/permissions/permissions.vue"),
  269. meta: {permissionId: 128},
  270. children: [
  271. // 用户权限
  272. {
  273. path: 'userPermission',
  274. name: "userPermission",
  275. component: () => import("../views/permissions/userPermission.vue"),
  276. meta: {permissionId: 129}
  277. },
  278. // 角色权限
  279. {
  280. path: 'rolePermission',
  281. name: "rolePermission",
  282. component: () => import("../views/permissions/rolePermission.vue"),
  283. meta: {permissionId: 130}
  284. }
  285. ]
  286. }
  287. ]
  288. },
  289. // 现金管理
  290. {
  291. path: '/moneyManage',
  292. name: 'moneyManage',
  293. meta: {permissionId: 58},
  294. children: [
  295. // 收款明细
  296. {
  297. path: 'receiveDetail',
  298. name: "receiveDetail",
  299. meta: {permissionId: 74},
  300. children: [
  301. // 客服页面
  302. {
  303. path: 'receiveService',
  304. name: "receiveService",
  305. component: () => import("../views/moneyManage/receiveDetail/receiveService.vue"),
  306. meta: {permissionId: 60}
  307. },
  308. // 地区负责人页面
  309. {
  310. path: 'receiveManager',
  311. name: "receiveManager",
  312. component: () => import("../views/moneyManage/receiveDetail/receiveManage.vue"),
  313. meta: {permissionId: [67, 79]}
  314. },
  315. {//地区财务
  316. path: 'receiveFinance',
  317. name: "receiveFinance",
  318. component: () => import("../views/moneyManage/receiveDetail/receiveFinance.vue"),
  319. meta: {permissionId: [67, 79]}
  320. },
  321. //总部管理员及财务
  322. {
  323. path: 'receiveHeader',
  324. name: "receiveHeader",
  325. component: () => import("../views/moneyManage/receiveDetail/receiveHead.vue"),
  326. meta: {permissionId: 91}
  327. },
  328. ]
  329. },
  330. // 退款明细
  331. {
  332. path: 'refundDetail',
  333. name: "refundDetail",
  334. component: () => import("../views/moneyManage/refundDetail/refundDetail.vue"),
  335. meta: {permissionId: 98},
  336. children: [
  337. // 客服页面
  338. {
  339. path: 'refundService',
  340. name: "refundService",
  341. component: () => import("../views/moneyManage/refundDetail/refundService.vue"),
  342. meta: {permissionId: 99}
  343. },
  344. // 地区财务页面
  345. {
  346. path: 'refundFinance',
  347. name: "refundFinance",
  348. component: () => import("../views/moneyManage/refundDetail/refundFinance.vue"),
  349. meta: {permissionId: 103}
  350. },
  351. // 地区负责人页面
  352. {
  353. path: 'refundCharge',
  354. name: "refundCharge",
  355. component: () => import("../views/moneyManage/refundDetail/refundCharge.vue"),
  356. meta: {permissionId: 107}
  357. },
  358. //总部管理员及财务
  359. {
  360. path: 'refundHeader',
  361. name: "refundHeader",
  362. component: () => import("../views/moneyManage/refundDetail/refundHeader.vue"),
  363. meta: {permissionId: 111}
  364. },
  365. ]
  366. },
  367. // 执行明细
  368. {
  369. path: 'executor',
  370. name: "executor",
  371. component: () => import("../views/moneyManage/executor/executor.vue"),
  372. meta: {permissionId: 115}
  373. },
  374. ]
  375. },
  376. // 频道管理
  377. {
  378. path: 'channelManage',
  379. name: 'channelManage',
  380. meta: {permissionId: 124},
  381. children: [
  382. // 打赏
  383. {
  384. path: 'reward',
  385. name: "reward",
  386. component: () => import("../views/channelManage/reward/reward.vue"),
  387. meta: {permissionId: 125}
  388. },
  389. // 铁粉
  390. {
  391. path: 'fans',
  392. name: "fans",
  393. component: () => import("../views/channelManage/fans/fans.vue"),
  394. meta: {permissionId: 126}
  395. },
  396. // 购物车
  397. {
  398. path: 'cart',
  399. name: "cart",
  400. component: () => import("../views/noPermissionPage.vue"),
  401. meta: {permissionId: 127}
  402. }
  403. ]
  404. },
  405. // 活动管理
  406. {
  407. path: 'activityManage',
  408. name: "activityManage",
  409. component: () => import("../views/activityManage/activity.vue"),
  410. meta: {permissionId: 119}
  411. },
  412. // 多语言配置
  413. {
  414. path: 'language',
  415. name: "language",
  416. component: () => import("../views/language/languageTranslate.vue"),
  417. meta: {permissionId: 146}
  418. },
  419. // 没有权限
  420. {
  421. path: '/noPermission',
  422. name: "noPermission",
  423. component: () => import("../views/noPermissionPage.vue")
  424. }
  425. ]
  426. },
  427. // 跳转页面(无需权限)
  428. {
  429. path: '/PasswordSuccess',
  430. name: "PasswordSuccess",
  431. component: () => import("../components/PasswordSuccess.vue")
  432. }
  433. ];
  434. // 创建路由实例
  435. const router = createRouter({
  436. history: createWebHashHistory(),
  437. routes
  438. });
  439. // 工具函数:从菜单树提取所有权限ID
  440. const getAllPermissionIds = (menuTree) => {
  441. let permissionIds = [];
  442. const traverse = (menuList) => {
  443. menuList.forEach(menu => {
  444. permissionIds.push(menu.id);
  445. if (menu.children && menu.children.length > 0) {
  446. traverse(menu.children);
  447. }
  448. });
  449. };
  450. traverse(menuTree);
  451. return permissionIds;
  452. };
  453. // 全局路由守卫
  454. router.beforeEach(async (to, from, next) => {
  455. const adminStore = useAdminStore()
  456. const {adminData, menuTree} = storeToRefs(adminStore)
  457. const token = localStorage.getItem("token");
  458. const machineId = localStorage.getItem("machineId");
  459. // 1. 未登录:强制跳转到登录页
  460. if (to.name !== "login" && !token) {
  461. next(`/login?machineId=${machineId || ''}`);
  462. return;
  463. }
  464. // 2. 已登录:处理权限验证
  465. if (token) {
  466. // 获取管理员信息
  467. let roleId = null;
  468. console.log('路由的adminData:', adminData.value)
  469. try {
  470. roleId = adminData.value.roleId;
  471. if (!roleId) {
  472. localStorage.removeItem('token'); // 清除token,强制重新登录
  473. next(`/login?machineId=${machineId || ''}`);
  474. return;
  475. }
  476. } catch (error) {
  477. localStorage.removeItem('token'); // 清除token,强制重新登录
  478. adminStore.clearState()
  479. next(`/login?machineId=${machineId || ''}`);
  480. return;
  481. }
  482. let userPermissionIds = [];
  483. // 拿权限id
  484. userPermissionIds = getAllPermissionIds(menuTree.value)
  485. console.log("userPermissionIds", userPermissionIds)
  486. // 2.4 权限验证(逻辑不变)
  487. console.log('to.meta:', to.meta)
  488. const requiresPermission = to.meta && to.meta.permissionId;
  489. if (requiresPermission) {
  490. const hasPermission = Array.isArray(requiresPermission)
  491. ? requiresPermission.some(id => userPermissionIds.includes(id))
  492. : userPermissionIds.includes(requiresPermission);
  493. if (!hasPermission) {
  494. next('/noPermission');
  495. return;
  496. }
  497. }
  498. }
  499. // 3. 正常跳转
  500. next();
  501. });
  502. const rawItems = ref([])
  503. // 全局后置守卫:每次路由切换后执行
  504. router.afterEach(async (to) => { // 接收to参数获取当前路由信息
  505. // 判断当前路由是否是登录页,如果是则直接返回不执行后续逻辑
  506. if (to.path === '/login') {
  507. return;
  508. }
  509. // 1. 从localStorage获取数据(localStorage存储的是字符串,需解析)
  510. const statusStr = localStorage.getItem('status');
  511. if (statusStr) {
  512. // 示例:如果原始字符串是逗号分隔的格式(如 "1,2,3"),可按分隔符拆分后遍历
  513. rawItems.value = statusStr.split(','); // 根据实际格式调整分隔符
  514. rawItems.value.forEach((item, index) => {
  515. console.log(`索引${index}`, item.trim()); // trim() 去除空格(可选)
  516. });
  517. } else {
  518. console.log('localStorage中无status数据');
  519. }
  520. try {
  521. // 执行/getMessage请求
  522. const newMessageRes = await API({
  523. url: '/getMessage',
  524. method: 'POST',
  525. data: {status: rawItems.value}
  526. });
  527. console.log('newMessageRes=======================:', newMessageRes.data)
  528. // 存入全局状态,供所有页面访问
  529. const messageStore = useMessageStore();
  530. // 过滤 flag=1的消息
  531. newMessageRes.data = newMessageRes.data.filter(item => item.flag !== 1);
  532. messageStore.setMessages(newMessageRes.data);
  533. } catch (error) {
  534. console.error('获取消息失败:', error);
  535. }
  536. });
  537. export default router;