|
|
@ -4,14 +4,16 @@ |
|
|
|
<el-button-group> |
|
|
|
<!-- 切换后状态显示 primary 样式否则是默认样式 --> |
|
|
|
<el-button |
|
|
|
:type="activeTab === 'detail' ? 'primary' : 'default'" |
|
|
|
@click="goToAdd" |
|
|
|
:type="activeTab === 'clientCountDetail' ? 'primary' : 'default'" |
|
|
|
@click="navigateTo('clientCountDetail')" |
|
|
|
:disabled="!hasDetail" |
|
|
|
> |
|
|
|
金币明细 |
|
|
|
</el-button> |
|
|
|
<el-button |
|
|
|
:type="activeTab === 'balance' ? 'primary' : 'default'" |
|
|
|
@click="goToDetail" |
|
|
|
:type="activeTab === 'clientCountBalance' ? 'primary' : 'default'" |
|
|
|
@click="navigateTo('clientCountBalance')" |
|
|
|
:disabled="!haBalance" |
|
|
|
> |
|
|
|
金币余额 |
|
|
|
</el-button> |
|
|
@ -23,79 +25,65 @@ |
|
|
|
|
|
|
|
<script setup> |
|
|
|
import {onMounted, ref, watch} from 'vue'; |
|
|
|
import { useRouter, useRoute } from 'vue-router'; |
|
|
|
import {useAdminStore} from "@/store/index.js"; |
|
|
|
import {useRoute, useRouter} 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 router = useRouter();// 获取路由实例 |
|
|
|
const route = useRoute();// 获取当前路由信息 |
|
|
|
// 定义响应式变量 activeTab 来跟踪当前激活的标签 |
|
|
|
const activeTab = ref(route.name === 'clientCountBalance' ? 'balance' : 'detail'); |
|
|
|
|
|
|
|
|
|
|
|
const goToAdd = () => { |
|
|
|
// 点击按钮时更新 activeTab 为 add |
|
|
|
activeTab.value = 'detail'; |
|
|
|
router.push({ name: 'clientCountDetail' }); |
|
|
|
}; |
|
|
|
|
|
|
|
const goToDetail = () => { |
|
|
|
// 点击按钮时更新 activeTab 为 detail |
|
|
|
activeTab.value = 'balance'; |
|
|
|
router.push({ name: 'clientCountBalance' }); |
|
|
|
}; |
|
|
|
|
|
|
|
const activeTab = ref(''); |
|
|
|
const hasDetail = ref(false); |
|
|
|
const haBalance = ref(false); |
|
|
|
// 导航方法 |
|
|
|
const navigateTo = (name) => { |
|
|
|
activeTab.value = name; |
|
|
|
if (name === 'detail') { |
|
|
|
router.push({name: 'clientCountDetail'}); |
|
|
|
} else if (name === 'balance') { |
|
|
|
router.push({name: 'clientCountBalance'}); |
|
|
|
} |
|
|
|
router.push({name}); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 递归判断某个 menuName 是否存在 |
|
|
|
const hasMenuPermission = (tree, targetName) => { |
|
|
|
for (const node of tree) { |
|
|
|
if (node.menuName === targetName) return true; |
|
|
|
if (node.children && hasMenuPermission(node.children, targetName)) return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
}; |
|
|
|
// 初始化权限状态 |
|
|
|
const initPermissions = () => { |
|
|
|
if (!menuTree.value || !menuTree.value.length) return; |
|
|
|
|
|
|
|
// 默认路由判断 |
|
|
|
const getDefaultRoute = () => { |
|
|
|
if (!menuTree.value) return 'detail'; |
|
|
|
const hasRecharge = hasMenuPermission(menuTree.value, '查看金币明细'); |
|
|
|
return hasRecharge ? 'detail' : 'balance'; |
|
|
|
hasAdd.value = hasMenuPermission(menuTree.value, permissionMapping.View_Gold_Coin_Details); |
|
|
|
haBalance.value = hasMenuPermission(menuTree.value, permissionMapping.View_Gold_Coin_Balance); |
|
|
|
}; |
|
|
|
|
|
|
|
// 默认跳转逻辑 |
|
|
|
const getDefaultAuditRoute = () => { |
|
|
|
initPermissions(); |
|
|
|
if (hasAdd.value) return 'clientCountDetail'; |
|
|
|
if (hasDetail.value) return 'clientCountBalance'; |
|
|
|
return 'clientCountDetail'; |
|
|
|
}; |
|
|
|
|
|
|
|
// 监听路由变化更新标签状态 |
|
|
|
watch(() => route.name, (newName) => { |
|
|
|
if (newName === 'detail' || newName === 'balance') { |
|
|
|
initPermissions() |
|
|
|
if (newName === 'clientCountDetail' || newName === 'clientCountBalance') { |
|
|
|
activeTab.value = newName; |
|
|
|
} else if (newName === 'usergold') { |
|
|
|
const defaultRoute = getDefaultRoute(); |
|
|
|
// 每次访问 /coinConsume 都进行默认跳转 |
|
|
|
const defaultRoute = getDefaultAuditRoute(); |
|
|
|
navigateTo(defaultRoute); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 初始化逻辑 |
|
|
|
onMounted(() => { |
|
|
|
initPermissions() |
|
|
|
if (route.name === 'usergold') { |
|
|
|
const defaultRoute = getDefaultRoute(); |
|
|
|
const defaultRoute = getDefaultAuditRoute(); |
|
|
|
navigateTo(defaultRoute); |
|
|
|
} else { |
|
|
|
// 非父路由初始化当前标签状态 |
|
|
|
if (route.name === 'detail' || route.name === 'balance') { |
|
|
|
if (route.name === 'clientCountDetail' || route.name === 'clientCountBalance') { |
|
|
|
activeTab.value = route.name; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
</script> |
|
|
|
</script> |