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.

409 lines
17 KiB

4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 weeks ago
3 months ago
3 weeks ago
3 months ago
3 months ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
3 weeks ago
3 weeks ago
3 months ago
3 months ago
3 weeks ago
3 weeks ago
3 weeks ago
3 months ago
2 months ago
3 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 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 weeks ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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: 13 } //
  27. },
  28. //金币管理
  29. {
  30. path: '/goldManage',
  31. name: 'goldManage',
  32. children: [
  33. // 审核
  34. {
  35. path: '/audit',
  36. name: "audit",
  37. component: () => import("../views/audit/gold/audit.vue"),
  38. meta: { permissionId: 14 },
  39. // redirect: '/index',
  40. children: [
  41. // 充值审核
  42. {
  43. path: 'rechargeAudit',
  44. name: "rechargeAudit",
  45. component: () => import("../views/audit/gold/rechargeAudit.vue"),
  46. meta: { permissionId: [28,30,31,32,33,34,35] } // 对应"查看充值审核"id=11、"充值审批"id=12
  47. },
  48. // 退款审核
  49. {
  50. path: 'refundAudit',
  51. name: "refundAudit",
  52. component: () => import("../views/audit/gold/refundAudit.vue"),
  53. meta: { permissionId: [29,36,37,38,39,40,41] } // 对应"查看退款审核"id=13、"退款审批"id=14
  54. },
  55. ]
  56. }, {
  57. path: '/beanAudit',
  58. name: "beanAudit",
  59. component: () => import("../views/audit/bean/beanAudit.vue"),
  60. meta: { permissionId: 15 },
  61. children: [
  62. // 充值审核
  63. {
  64. path: 'addbeanAudit',
  65. name: "addbeanAudit",
  66. component: () => import("../views/audit/bean/beanAudit.vue"),
  67. meta: { permissionId: [42,43,44,45,46,47] } // 对应"查看充值审核"id=11、"充值审批"id=12
  68. },
  69. ]
  70. },
  71. // 金币消耗
  72. {
  73. path: '/coinConsume',
  74. name: "coinConsume",
  75. component: () => import("../views/consume/gold/coinConsume.vue"),
  76. // redirect: '/coinConsume/add',
  77. meta: { permissionId: 19 },
  78. children: [
  79. // 金币新增消耗
  80. {
  81. path: 'add',
  82. name: "addCoinConsume",
  83. component: () => import("../views/consume/gold/addCoinConsume.vue"),
  84. meta: { permissionId: 55 } // 对应"提交金币消耗"id=19
  85. },
  86. // 金币消耗明细详情
  87. {
  88. path: 'detail',
  89. name: "coinConsumeDetail",
  90. component: () => import("../views/consume/gold/coinConsumeDetail.vue"),
  91. meta: { permissionId: 56 } // 对应"查看金币消耗明细"id=20
  92. }
  93. ]
  94. },
  95. // 金豆消耗
  96. {
  97. path: '/beanConsume',
  98. name: "beanConsume",
  99. component: () => import("../views/consume/bean/beanConsume.vue"),
  100. meta: { permissionId: 20 },
  101. children: [
  102. // 金豆新增消耗
  103. {
  104. path: 'add',
  105. name: "addBeanConsume",
  106. component: () => import("../views/consume/bean/addBeanConsume.vue"),
  107. meta: { permissionId: 57 } // 对应"提交金豆消耗"id=49
  108. },
  109. // 直播
  110. {
  111. path: 'live',
  112. name: "liveStream",
  113. component: () => import("../views/consume/bean/liveStream.vue"),
  114. meta: { permissionId: 58 } // 对应"直播"id=50
  115. },
  116. // 铁粉
  117. {
  118. path: 'fan',
  119. name: "dieHardFan",
  120. component: () => import("../views/consume/bean/dieHardFan.vue"),
  121. meta: { permissionId: 59 } // 对应"铁粉"id=51
  122. },
  123. // 文章视频
  124. {
  125. path: 'article',
  126. name: "articleVideo",
  127. component: () => import("../views/consume/bean/articleVideo.vue"),
  128. meta: { permissionId: 60 } // 对应"文章视频"id=52
  129. }
  130. ]
  131. },
  132. // 汇率管理
  133. {
  134. path: '/rate',
  135. name: "rate",
  136. component: () => import("../views/managerecharge/rate.vue"),
  137. meta: { permissionId: [16,48,49] } // 对应"汇率查看"id=15、"汇率修改"id=16
  138. },
  139. // 金币充值
  140. {
  141. path: '/coinRecharge',
  142. name: "coinRecharge",
  143. component: () => import("../views/recharge/gold/coinRecharge.vue"),
  144. meta: { permissionId: 17 },
  145. // redirect: '/coinRecharge/add',
  146. children: [
  147. // 金币新增充值
  148. {
  149. path: 'add',
  150. name: "addCoinRecharge",
  151. component: () => import("../views/recharge/gold/addCoinRecharge.vue"),
  152. meta: { permissionId: 50 } // 对应"提交金币充值"id=17
  153. },
  154. // 金币充值明细详情
  155. {
  156. path: 'detail',
  157. name: "coinRechargeDetail",
  158. component: () => import("../views/recharge/gold/coinRechargeDetail.vue"),
  159. meta: { permissionId: 51 } // 对应"查看金币充值明细"id=18
  160. }
  161. ]
  162. },
  163. // 金豆充值
  164. {
  165. path: '/beanRecharge',
  166. name: "beanRecharge",
  167. component: () => import("../views/recharge/bean/beanRecharge.vue"),
  168. // redirect: '/coinRecharge/add',
  169. meta: { permissionId: 18 },
  170. children: [
  171. // 金豆新增充值
  172. {
  173. path: 'add',
  174. name: "addBeanRecharge",
  175. component: () => import("../views/recharge/bean/addBeanRecharge.vue"),
  176. meta: { permissionId: 52 } // 对应"提交金豆充值"id=46
  177. },
  178. // 金豆系统充值
  179. {
  180. path: 'system',
  181. name: "beanSystemRecharge",
  182. component: () => import("../views/recharge/bean/beanSystemRecharge.vue"),
  183. meta: { permissionId: 53 } // 对应"查看金豆系统充值明细"id=47
  184. },
  185. // 金豆线上充值
  186. {
  187. path: 'online',
  188. name: "beanOnlineRecharge",
  189. component: () => import("../views/recharge/bean/beanOnlineRecharge.vue"),
  190. meta: { permissionId: 54 } // 对应"查看金豆线上充值明细"id=48
  191. }
  192. ]
  193. },
  194. // 金币退款
  195. {
  196. path: '/coinRefund',
  197. name: "coinRefund",
  198. component: () => import("../views/refund/gold/coinRefund.vue"),
  199. meta: { permissionId: 9 },
  200. children: [
  201. // 金币新增退款
  202. {
  203. path: 'add',
  204. name: "addCoinRefund",
  205. component: () => import("../views/refund/gold/addCoinRefund.vue"),
  206. meta: { permissionId: 61 }
  207. },
  208. // 金币退款明细详情
  209. {
  210. path: 'detail',
  211. name: "coinRefundDetail",
  212. component: () => import("../views/refund/gold/coinRefundDetail.vue"),
  213. meta: { permissionId: 62 }
  214. }
  215. ]
  216. },
  217. // 客户账户明细
  218. {
  219. path: '/usergold',
  220. name: "usergold",
  221. component: () => import("../views/usergold/gold/clientCount.vue"),
  222. meta: { permissionId: 10 },
  223. children: [
  224. // 金币明细
  225. {
  226. path: 'detail',
  227. name: "clientCountDetail",
  228. component: () => import("../views/usergold/gold/clientCountDetail.vue"),
  229. meta: { permissionId: 63 }
  230. },
  231. // 金币余额
  232. {
  233. path: 'balance',
  234. name: "clientCountBalance",
  235. component: () => import("../views/usergold/gold/clientCountBalance.vue"),
  236. meta: { permissionId: 64 }
  237. },
  238. ]
  239. },
  240. // {
  241. // path: 'userbean',
  242. // name: "userbean",
  243. // component: () => import("../views/usergold/bean/userbean.vue"),
  244. // meta: { permissionId: 45 }
  245. // },
  246. {
  247. path: '/history',
  248. name: "history",
  249. component: () => import("../views/history/history.vue"),
  250. meta: { permissionId: 12 },
  251. children: [
  252. // {
  253. // path: 'newHistory',
  254. // name: "newHistory",
  255. // component: () => import("../views/history/newHistory.vue"),
  256. // meta: { permissionId: 12 }
  257. // },
  258. // {
  259. // path: 'oldHistory',
  260. // name: "oldHistory",
  261. // component: () => import("../views/history/oldHistory.vue"),
  262. // meta: { permissionId: 12 }
  263. // }
  264. ]
  265. },
  266. // 权限管理
  267. {
  268. path: '/permissions',
  269. name: "permissions",
  270. component: () => import("../views/permissions/permissions.vue"),
  271. meta: { permissionId: 11 },
  272. children: [
  273. // 用户权限
  274. {
  275. path: 'userPermission',
  276. name: "userPermission",
  277. component: () => import("../views/permissions/userPermission.vue"),
  278. meta: { permissionId: [24,65,66,67,68,69] }
  279. },
  280. // 角色权限
  281. {
  282. path: 'rolePermission',
  283. name: "rolePermission",
  284. component: () => import("../views/permissions/rolePermission.vue"),
  285. meta: { permissionId: [25,70,71,72] }
  286. },
  287. ]
  288. },
  289. ]
  290. },
  291. {
  292. path:'moneyManage',
  293. name:'moneyManage',
  294. children:[
  295. ]
  296. },
  297. // 没有权限
  298. {
  299. path: '/noPermission',
  300. name: "noPermission",
  301. component: () => import("../views/noPermissionPage.vue")
  302. }
  303. ]
  304. },
  305. // 跳转页面(无需权限)
  306. {
  307. path: '/PasswordSuccess',
  308. name: "PasswordSuccess",
  309. component: () => import("../components/PasswordSuccess.vue")
  310. }
  311. ];
  312. // 创建路由实例
  313. const router = createRouter({
  314. history: createWebHashHistory(),
  315. routes
  316. });
  317. // 工具函数:从菜单树提取所有权限ID
  318. const getAllPermissionIds = (menuTree) => {
  319. let permissionIds = [];
  320. const traverse = (menuList) => {
  321. menuList.forEach(menu => {
  322. permissionIds.push(menu.id);
  323. if (menu.children && menu.children.length > 0) {
  324. traverse(menu.children);
  325. }
  326. });
  327. };
  328. traverse(menuTree);
  329. return permissionIds;
  330. };
  331. // 全局路由守卫
  332. router.beforeEach(async (to, from, next) => {
  333. const adminStore = useAdminStore()
  334. const { adminData, menuTree } = storeToRefs(adminStore)
  335. const token = localStorage.getItem("token");
  336. const machineId = localStorage.getItem("machineId");
  337. // 1. 未登录:强制跳转到登录页
  338. if (to.name !== "login" && !token) {
  339. next(`/login?machineId=${machineId || ''}`);
  340. return;
  341. }
  342. // 2. 已登录:处理权限验证
  343. if (token) {
  344. // 获取管理员信息
  345. let roleId = null;
  346. console.log('路由的adminData:', adminData.value)
  347. try {
  348. roleId = adminData.value.roleId;
  349. if (!roleId) {
  350. localStorage.removeItem('token'); // 清除token,强制重新登录
  351. next(`/login?machineId=${machineId || ''}`);
  352. return;
  353. }
  354. } catch (error) {
  355. localStorage.removeItem('token'); // 清除token,强制重新登录
  356. adminStore.clearState()
  357. next(`/login?machineId=${machineId || ''}`);
  358. return;
  359. }
  360. let userPermissionIds = [];
  361. // 拿权限id
  362. userPermissionIds = getAllPermissionIds(menuTree.value)
  363. console.log("userPermissionIds",userPermissionIds)
  364. // 2.4 权限验证(逻辑不变)
  365. console.log('to.meta:', to.meta)
  366. const requiresPermission = to.meta && to.meta.permissionId;
  367. if (requiresPermission) {
  368. const hasPermission = Array.isArray(requiresPermission)
  369. ? requiresPermission.some(id => userPermissionIds.includes(id))
  370. : userPermissionIds.includes(requiresPermission);
  371. if (!hasPermission) {
  372. next('/noPermission');
  373. return;
  374. }
  375. }
  376. }
  377. // 3. 正常跳转
  378. next();
  379. });
  380. export default router;