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.

102 lines
2.7 KiB

4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
3 months ago
2 months ago
4 months ago
3 months ago
4 months ago
2 months ago
2 months ago
3 months ago
4 months ago
2 months ago
4 months ago
  1. <template>
  2. <div>
  3. <div style="height:4vh;width:82vw;">
  4. <el-button-group>
  5. <el-button
  6. class="no-active-btn"
  7. :class="{ 'active-btn': activeTab === 'rechargeAudit' }"
  8. @click="navigateTo('rechargeAudit')"
  9. v-if="hasRecharge"
  10. >
  11. 充值审核
  12. </el-button>
  13. <el-button
  14. class="no-active-btn"
  15. :class="{ 'active-btn': activeTab === 'refundAudit' }"
  16. @click="navigateTo('refundAudit')"
  17. v-if="hasRefund"
  18. >
  19. 退款审核
  20. </el-button>
  21. </el-button-group>
  22. </div>
  23. <router-view></router-view>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { ref, watch, onMounted } from 'vue';
  28. import { useRouter, useRoute } from 'vue-router';
  29. import { storeToRefs } from 'pinia';
  30. import { useAdminStore } from '@/store/index.js';
  31. import { hasMenuPermission, permissionMapping } from "@/utils/menuTreePermission.js";
  32. import { ElMessage } from 'element-plus';
  33. const router = useRouter();
  34. const route = useRoute();
  35. const adminStore = useAdminStore();
  36. const { menuTree } = storeToRefs(adminStore);
  37. const activeTab = ref('');
  38. const hasRecharge = ref(false);
  39. const hasRefund = ref(false);
  40. // 导航方法
  41. const navigateTo = (name) => {
  42. if(name == 'rechargeAudit'){
  43. if(!hasRecharge){
  44. ElMessage.error('您暂无充值审核操作权限')
  45. return;
  46. }
  47. }else if(name = 'refundAudit'){
  48. if(!hasRefund){
  49. ElMessage.error('您暂无退款审核操作权限')
  50. return;
  51. }
  52. }
  53. activeTab.value = name;
  54. router.push({ name });
  55. };
  56. // 初始化权限状态
  57. const initPermissions = () => {
  58. if (!menuTree.value || !menuTree.value.length) return;
  59. hasRecharge.value = hasMenuPermission(menuTree.value, permissionMapping.rechargeAudit);
  60. hasRefund.value = hasMenuPermission(menuTree.value, permissionMapping.refundAudit);
  61. };
  62. // 默认跳转逻辑
  63. const getDefaultAuditRoute = () => {
  64. initPermissions();
  65. if (hasRecharge.value) return 'rechargeAudit';
  66. if (hasRefund.value) return 'refundAudit';
  67. return 'rechargeAudit';
  68. };
  69. // 监听路由变化更新标签状态
  70. watch(() => route.name, (newName) => {
  71. initPermissions()
  72. if (newName === 'rechargeAudit' || newName === 'refundAudit') {
  73. activeTab.value = newName;
  74. } else if (newName === 'audit') {
  75. // 每次访问 /audit 都进行默认跳转
  76. const defaultRoute = getDefaultAuditRoute();
  77. navigateTo(defaultRoute);
  78. }
  79. });
  80. // 初始化逻辑
  81. onMounted(() => {
  82. initPermissions()
  83. if (route.name === 'audit') {
  84. const defaultRoute = getDefaultAuditRoute();
  85. navigateTo(defaultRoute);
  86. } else {
  87. // 非父路由初始化当前标签状态
  88. if (route.name === 'rechargeAudit' || route.name === 'refundAudit') {
  89. activeTab.value = route.name;
  90. }
  91. }
  92. });
  93. </script>