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.

127 lines
3.7 KiB

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