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.

107 lines
3.1 KiB

8 months ago
8 months ago
  1. <template>
  2. <div class="main">
  3. <div style="height: 4vh;">
  4. <!-- 这里放置标签切换的按钮 -->
  5. <el-button-group class="custom-button-group">
  6. <!-- 切换后状态显示 primary 样式否则是默认样式 -->
  7. <el-button
  8. class="no-active-btn"
  9. :class="{ 'active-btn': activeTab === 'clientCountDetail' }"
  10. @click="navigateTo('clientCountDetail')"
  11. :disabled="!hasDetail"
  12. v-if="hasDetail"
  13. >
  14. {{ $t('clientCount.clientCountDetail') }}
  15. </el-button>
  16. <el-button
  17. class="no-active-btn"
  18. :class="{ 'active-btn': activeTab === 'clientCountBalance' }"
  19. @click="navigateTo('clientCountBalance')"
  20. :disabled="!hasBalance" v-if="hasBalance"
  21. >
  22. {{ $t('clientCount.clientCountBalance') }}
  23. </el-button>
  24. </el-button-group>
  25. <!-- 渲染子路由组件 -->
  26. </div>
  27. <div style="flex: 1; display: flex; flex-direction: column; overflow: hidden;">
  28. <router-view></router-view>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup>
  33. import {onMounted, ref, watch} from 'vue';
  34. import {useRoute, useRouter} from 'vue-router';
  35. import {storeToRefs} from "pinia";
  36. import {useAdminStore} from "@/store/index.js";
  37. import {hasMenuPermission, permissionMapping} from "@/utils/menuTreePermission.js";
  38. // 国际化
  39. import { useI18n } from 'vue-i18n'
  40. const router = useRouter();
  41. const route = useRoute();
  42. const adminStore = useAdminStore();
  43. const {menuTree} = storeToRefs(adminStore);
  44. const activeTab = ref('');
  45. const hasDetail = ref(false);
  46. const hasBalance = ref(false);
  47. // 导航方法
  48. const navigateTo = (name) => {
  49. activeTab.value = name;
  50. router.push({name});
  51. };
  52. // 初始化权限状态
  53. const initPermissions = () => {
  54. if (!menuTree.value || !menuTree.value.length) return;
  55. hasDetail.value = hasMenuPermission(menuTree.value, permissionMapping.gold_coin_customer_bill);
  56. hasBalance.value = hasMenuPermission(menuTree.value, permissionMapping.gold_coin_customer_balance);
  57. };
  58. // 默认跳转逻辑
  59. const getDefaultAuditRoute = () => {
  60. initPermissions();
  61. if (hasDetail.value) return 'clientCountDetail';
  62. if (hasBalance.value) return 'clientCountBalance';
  63. return 'clientCountDetail';
  64. };
  65. // 监听路由变化更新标签状态
  66. watch(() => route.name, (newName) => {
  67. initPermissions()
  68. if (newName === 'clientCountDetail' || newName === 'clientCountBalance') {
  69. activeTab.value = newName;
  70. } else if (newName === 'usergold') {
  71. // 每次访问 /coinConsume 都进行默认跳转
  72. const defaultRoute = getDefaultAuditRoute();
  73. navigateTo(defaultRoute);
  74. }
  75. });
  76. // 初始化逻辑
  77. onMounted(() => {
  78. initPermissions()
  79. if (route.name === 'usergold') {
  80. const defaultRoute = getDefaultAuditRoute();
  81. navigateTo(defaultRoute);
  82. } else {
  83. // 非父路由初始化当前标签状态
  84. if (route.name === 'clientCountDetail' || route.name === 'clientCountBalance') {
  85. activeTab.value = route.name;
  86. }
  87. }
  88. });
  89. </script>
  90. <style>
  91. .main{
  92. display: flex;
  93. flex-direction: column;
  94. width: 100%;
  95. height: 100%;
  96. }
  97. </style>