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.

117 lines
3.2 KiB

4 months ago
3 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
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 class="custom-button-group">
  5. <el-button :type="activeTab === 'rechargeAudit' ? 'primary' : 'default'" @click="navigateTo('rechargeAudit')" class="custom-tab-button"
  6. v-if="hasRecharge">
  7. 充值审核
  8. </el-button>
  9. <el-button :type="activeTab === 'refundAudit' ? 'primary' : 'default'" @click="navigateTo('refundAudit')" class="custom-tab-button"
  10. v-if="hasRefund">
  11. 退款审核
  12. </el-button>
  13. </el-button-group>
  14. </div>
  15. <router-view></router-view>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { ref, watch, onMounted } from 'vue';
  20. import { useRouter, useRoute } from 'vue-router';
  21. import { storeToRefs } from 'pinia';
  22. import { useAdminStore } from '@/store/index.js';
  23. import { hasMenuPermission, permissionMapping } from "@/utils/menuTreePermission.js";
  24. import { ElMessage } from 'element-plus';
  25. const router = useRouter();
  26. const route = useRoute();
  27. const adminStore = useAdminStore();
  28. const { menuTree } = storeToRefs(adminStore);
  29. const activeTab = ref('');
  30. const hasRecharge = ref(false);
  31. const hasRefund = ref(false);
  32. // 导航方法
  33. const navigateTo = (name) => {
  34. if(name == 'rechargeAudit'){
  35. if(!hasRecharge){
  36. ElMessage.error('您暂无充值审核操作权限')
  37. return;
  38. }
  39. }else if(name = 'refundAudit'){
  40. if(!hasRefund){
  41. ElMessage.error('您暂无退款审核操作权限')
  42. return;
  43. }
  44. }
  45. activeTab.value = name;
  46. router.push({ name });
  47. };
  48. // 初始化权限状态
  49. const initPermissions = () => {
  50. if (!menuTree.value || !menuTree.value.length) return;
  51. hasRecharge.value = hasMenuPermission(menuTree.value, permissionMapping.rechargeAudit);
  52. hasRefund.value = hasMenuPermission(menuTree.value, permissionMapping.refundAudit);
  53. };
  54. // 默认跳转逻辑
  55. const getDefaultAuditRoute = () => {
  56. initPermissions();
  57. if (hasRecharge.value) return 'rechargeAudit';
  58. if (hasRefund.value) return 'refundAudit';
  59. return 'rechargeAudit';
  60. };
  61. // 监听路由变化更新标签状态
  62. watch(() => route.name, (newName) => {
  63. initPermissions()
  64. if (newName === 'rechargeAudit' || newName === 'refundAudit') {
  65. activeTab.value = newName;
  66. } else if (newName === 'audit') {
  67. // 每次访问 /audit 都进行默认跳转
  68. const defaultRoute = getDefaultAuditRoute();
  69. navigateTo(defaultRoute);
  70. }
  71. });
  72. // 初始化逻辑
  73. onMounted(() => {
  74. initPermissions()
  75. if (route.name === 'audit') {
  76. const defaultRoute = getDefaultAuditRoute();
  77. navigateTo(defaultRoute);
  78. } else {
  79. // 非父路由初始化当前标签状态
  80. if (route.name === 'rechargeAudit' || route.name === 'refundAudit') {
  81. activeTab.value = route.name;
  82. }
  83. }
  84. });
  85. </script>
  86. <style scoped lang="scss">
  87. /* 自定义按钮组布局 */
  88. .custom-button-group {
  89. display: flex;
  90. margin-bottom: 16px;
  91. gap: 8px;
  92. }
  93. :deep(.el-button.custom-tab-button) {
  94. border-radius: 4px;
  95. transition: all 0.3s ease;
  96. }
  97. // 自定义tab按钮激活样式
  98. :deep(.el-button.custom-tab-button.el-button--primary) {
  99. background-color: #2741DE !important;
  100. border-color: #2741DE !important;
  101. color: #F3FAFE !important;
  102. }
  103. /* 鼠标悬停效果 */
  104. :deep(.el-button.custom-tab-button:hover:not(.is-disabled)) {
  105. opacity: 0.8;
  106. }
  107. </style>