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.

114 lines
5.6 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 weeks ago
2 months ago
3 weeks ago
2 months ago
  1. import { createRouter, createWebHashHistory } from 'vue-router';
  2. import axios from "axios";
  3. const router = createRouter({
  4. history: createWebHashHistory(),
  5. routes: [
  6. { path: '/workspace', name: "workspace", component: () => import("../views/workspace/index.vue") },
  7. { path: '/', redirect: "/login" },
  8. {path: "/login",name: "login",component: () => import("../views/login.vue"),},
  9. // { path: '/test', component: () => import("../views/z.vue") },
  10. {
  11. meta: { requireAuth: true },
  12. path: '/', component: () => import("../views/home.vue"),
  13. children: [
  14. // 工作台
  15. { path: '/workspace/:area?', name: "workspace", component: () => import("../views/workspace/index.vue") },
  16. // 充值审核
  17. { path: '/rechargeAudit', name: "rechargeAudit", component: () => import("../views/audit/rechargeAudit.vue") },
  18. // 退款审核
  19. { path: '/refundAudit', name: "refundAudit", component: () => import("../views/audit/refundAudit.vue") },
  20. // 金币消耗
  21. { path: '/coinConsume', name: "coinConsume", component: () => import("../views/consume/coinConsume.vue"),
  22. redirect: '/coinConsume/add',// 重定向到新增消耗页面
  23. children: [
  24. // 金币新增消耗
  25. { path: 'add', name: "addCoinConsume", component: () => import("../views/consume/addCoinConsume.vue") },
  26. // 金币消耗明细详情
  27. { path: 'detail', name: "coinConsumeDetail", component: () => import("../views/consume/coinConsumeDetail.vue") }
  28. ]
  29. },
  30. // 金豆消耗
  31. { path: '/beanConsume', name: "beanConsume", component: () => import("../views/consume/beanConsume.vue") },
  32. // 汇率管理
  33. { path: '/rate', name: "rate", component: () => import("../views/managerecharge/rate.vue") },
  34. // 金币充值
  35. { path: '/coinRecharge', name: "coinRecharge", component: () => import("../views/recharge/coinRecharge.vue"),
  36. redirect: '/coinRecharge/add',// 重定向到新增充值页面
  37. children: [
  38. // 金币新增充值
  39. { path: 'add', name: "addCoinRecharge", component: () => import("../views/recharge/addCoinRecharge.vue") },
  40. // 金币充值明细详情
  41. { path: 'detail', name: "coinRechargeDetail", component: () => import("../views/recharge/coinRechargeDetail.vue") }
  42. ]
  43. },
  44. // 金豆充值
  45. { path: '/beanRecharge', name: "beanRecharge", component: () => import("../views/recharge/beanRecharge.vue") },
  46. // 金币退款
  47. { path: '/coinRefund', name: "coinRefund", component: () => import("../views/refund/coinRefund.vue"),
  48. redirect: '/coinRefund/add',// 重定向到新增退款页面
  49. children: [
  50. // 金币新增消耗
  51. { path: 'add', name: "addCoinRefund", component: () => import("../views/refund/addCoinRefund.vue") },
  52. // 金币消耗明细详情
  53. { path: 'detail', name: "coinRefundDetail", component: () => import("../views/refund/coinRefundDetail.vue") }
  54. ]
  55. },
  56. // 金豆退款
  57. { path: '/beanRefund', name: "beanRefund", component: () => import("../views/refund/beanRefund.vue") },
  58. // 客户账户明细
  59. { path: '/usergold', name: "usergold", component: () => import("../views/usergold/clientCount.vue"),
  60. redirect: '/usergold/detail',// 重定向到客户账户明细页面
  61. children: [
  62. // 金币明细
  63. { path: 'detail', name: "clientCountDetail", component: () => import("../views/usergold/clientCountDetail.vue") },
  64. // 金币余额
  65. { path: 'balance', name: "clientCountBalance", component: () => import("../views/usergold/clientCountBalance.vue") },
  66. ]
  67. },
  68. // 权限管理
  69. { path: '/permissions', name: "permissions", component: () => import("../views/permissions/permission.vue") },
  70. // 没有权限
  71. { path: '/noPermission', name: "noPermission", component: () => import("../views/noPermissionPage.vue") }
  72. ]
  73. },
  74. // 跳转页面
  75. { path: '/PasswordSuccess', name: "PasswordSuccess", component: () => import("../components/PasswordSuccess.vue") },
  76. ]
  77. });
  78. // 全局拦截器 token 过期拦截
  79. axios.interceptors.response.use(
  80. response => response,
  81. error => {
  82. if (error.response && error.response.status === 401) {
  83. // 清除本地存储的token
  84. localStorage.removeItem('token');
  85. // 跳转到登录页
  86. router.push({
  87. name: 'login',
  88. query: { machineId: localStorage.getItem('machineId'), expired: true }
  89. });
  90. }
  91. return Promise.reject(error);
  92. }
  93. );
  94. router.beforeEach((to, from, next) => {
  95. const token = localStorage.getItem("token");
  96. const machineId = localStorage.getItem("machineId");
  97. if (to.name != "login" && !token) {
  98. next('/login?machineId=' + machineId);
  99. }
  100. next();
  101. })
  102. export default router;