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.

121 lines
3.1 KiB

6 months ago
3 months ago
3 months ago
3 months ago
6 months ago
3 months ago
6 months ago
3 months ago
6 months ago
3 months ago
6 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <div class="fatherTop">
  3. <el-button-group>
  4. <el-button
  5. class="no-active-btn"
  6. :class="{ 'active-btn': activeTab === 'coinConsumeDetail' }"
  7. @click="navigateTo('coinConsumeDetail')"
  8. v-if="hasDetail"
  9. >
  10. {{ $t('consume.coinConsumeDetail') }}
  11. </el-button>
  12. <el-button
  13. class="no-active-btn"
  14. :class="{ 'active-btn': activeTab === 'addCoinConsume' }"
  15. @click="navigateTo('addCoinConsume')"
  16. v-if="hasAdd"
  17. >
  18. {{ $t('consume.addCoinConsume') }}
  19. </el-button>
  20. </el-button-group>
  21. </div>
  22. <div>
  23. <router-view></router-view>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { onMounted, ref, watch } from 'vue';
  28. import { useRoute, useRouter } 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 { useI18n } from 'vue-i18n';
  33. const router = useRouter();
  34. const route = useRoute();
  35. const adminStore = useAdminStore();
  36. const { menuTree } = storeToRefs(adminStore);
  37. const activeTab = ref('');
  38. const hasAdd = ref(false);
  39. const hasDetail = ref(false);
  40. // 导航方法
  41. const navigateTo = (name) => {
  42. activeTab.value = name;
  43. router.push({ name });
  44. };
  45. // 初始化权限状态
  46. const initPermissions = () => {
  47. if (!menuTree.value || !menuTree.value.length) return;
  48. hasAdd.value = hasMenuPermission(menuTree.value, permissionMapping.add_gold_coin_consumption);
  49. hasDetail.value = hasMenuPermission(menuTree.value, permissionMapping.gold_coin_consumption_details);
  50. };
  51. // 默认跳转逻辑
  52. const getDefaultAuditRoute = () => {
  53. initPermissions();
  54. if (hasDetail.value) return 'coinConsumeDetail';
  55. if (hasAdd.value) return 'addCoinConsume';
  56. return 'coinConsumeDetail';
  57. };
  58. // 监听路由变化更新标签状态
  59. watch(() => route.name, (newName) => {
  60. initPermissions()
  61. if (newName === 'addCoinConsume' || newName === 'coinConsumeDetail') {
  62. activeTab.value = newName;
  63. } else if (newName === 'coinConsume') {
  64. // 每次访问 /coinConsume 都进行默认跳转
  65. const defaultRoute = getDefaultAuditRoute();
  66. navigateTo(defaultRoute);
  67. }
  68. });
  69. // 初始化逻辑
  70. onMounted(() => {
  71. initPermissions()
  72. if (route.name === 'coinConsume') {
  73. const defaultRoute = getDefaultAuditRoute();
  74. navigateTo(defaultRoute);
  75. } else {
  76. // 非父路由初始化当前标签状态
  77. if (route.name === 'addCoinConsume' || route.name === 'coinConsumeDetail') {
  78. activeTab.value = route.name;
  79. }
  80. }
  81. });
  82. </script>
  83. <style scoped lang="scss">
  84. /* 自定义按钮组布局 */
  85. .fatherTop {
  86. height: 4vh;
  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>