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.
86 lines
2.3 KiB
86 lines
2.3 KiB
<template>
|
|
<div>
|
|
<el-button-group>
|
|
<el-button
|
|
:type="activeTab === 'rechargeAudit' ? 'primary' : 'default'"
|
|
@click="navigateTo('rechargeAudit')"
|
|
:disabled="!hasRecharge"
|
|
>
|
|
充值审核
|
|
</el-button>
|
|
<el-button
|
|
:type="activeTab === 'refundAudit' ? 'primary' : 'default'"
|
|
@click="navigateTo('refundAudit')"
|
|
:disabled="!hasRefund"
|
|
>
|
|
退款审核
|
|
</el-button>
|
|
</el-button-group>
|
|
<router-view></router-view>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import {ref, watch, onMounted} from 'vue';
|
|
import {useRouter, useRoute} from 'vue-router';
|
|
import {storeToRefs} from 'pinia';
|
|
import {useAdminStore} from '@/store/index.js';
|
|
import {hasMenuPermission, permissionMapping} from "@/utils/menuTreePermission.js";
|
|
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
const adminStore = useAdminStore();
|
|
const {menuTree} = storeToRefs(adminStore);
|
|
|
|
const activeTab = ref('');
|
|
const hasRecharge = ref(false);
|
|
const hasRefund = ref(false);
|
|
// 导航方法
|
|
const navigateTo = (name) => {
|
|
activeTab.value = name;
|
|
router.push({name});
|
|
};
|
|
|
|
|
|
// 初始化权限状态
|
|
const initPermissions = () => {
|
|
if (!menuTree.value || !menuTree.value.length) return;
|
|
|
|
hasRecharge.value = hasMenuPermission(menuTree.value, permissionMapping.Recharge_Audit);
|
|
hasRefund.value = hasMenuPermission(menuTree.value, permissionMapping.Refund_Audit);
|
|
};
|
|
|
|
// 默认跳转逻辑
|
|
const getDefaultAuditRoute = () => {
|
|
initPermissions();
|
|
if (hasRecharge.value) return 'rechargeAudit';
|
|
if (hasRefund.value) return 'refundAudit';
|
|
return 'rechargeAudit';
|
|
};
|
|
|
|
// 监听路由变化更新标签状态
|
|
watch(() => route.name, (newName) => {
|
|
initPermissions()
|
|
if (newName === 'rechargeAudit' || newName === 'refundAudit') {
|
|
activeTab.value = newName;
|
|
} else if (newName === 'audit') {
|
|
// 每次访问 /audit 都进行默认跳转
|
|
const defaultRoute = getDefaultAuditRoute();
|
|
navigateTo(defaultRoute);
|
|
}
|
|
});
|
|
|
|
// 初始化逻辑
|
|
onMounted(() => {
|
|
initPermissions()
|
|
if (route.name === 'audit') {
|
|
const defaultRoute = getDefaultAuditRoute();
|
|
navigateTo(defaultRoute);
|
|
} else {
|
|
// 非父路由初始化当前标签状态
|
|
if (route.name === 'rechargeAudit' || route.name === 'refundAudit') {
|
|
activeTab.value = route.name;
|
|
}
|
|
}
|
|
});
|
|
</script>
|