|
@ -4,14 +4,16 @@ |
|
|
<el-button-group> |
|
|
<el-button-group> |
|
|
<!-- 切换后状态显示 primary 样式否则是默认样式 --> |
|
|
<!-- 切换后状态显示 primary 样式否则是默认样式 --> |
|
|
<el-button |
|
|
<el-button |
|
|
:type="activeTab === 'add' ? 'primary' : 'default'" |
|
|
|
|
|
@click="goToAdd" |
|
|
|
|
|
|
|
|
:type="activeTab === 'addCoinRecharge' ? 'primary' : 'default'" |
|
|
|
|
|
@click="navigateTo('addCoinRecharge')" |
|
|
|
|
|
:disabled="!hasAdd" |
|
|
> |
|
|
> |
|
|
新增充值 |
|
|
新增充值 |
|
|
</el-button> |
|
|
</el-button> |
|
|
<el-button |
|
|
<el-button |
|
|
:type="activeTab === 'detail' ? 'primary' : 'default'" |
|
|
|
|
|
@click="goToDetail" |
|
|
|
|
|
|
|
|
:type="activeTab === 'coinRechargeDetail' ? 'primary' : 'default'" |
|
|
|
|
|
@click="navigateTo('coinRechargeDetail')" |
|
|
|
|
|
:disabled="!hasDetail" |
|
|
> |
|
|
> |
|
|
金币充值明细 |
|
|
金币充值明细 |
|
|
</el-button> |
|
|
</el-button> |
|
@ -23,79 +25,65 @@ |
|
|
|
|
|
|
|
|
<script setup> |
|
|
<script setup> |
|
|
import {onMounted, ref, watch} from 'vue'; |
|
|
import {onMounted, ref, watch} from 'vue'; |
|
|
import {useRouter, useRoute} from 'vue-router'; |
|
|
|
|
|
|
|
|
import {useRoute, useRouter} from 'vue-router'; |
|
|
import {storeToRefs} from "pinia"; |
|
|
import {storeToRefs} from "pinia"; |
|
|
import {useAdminStore} from "@/store/index.js"; |
|
|
import {useAdminStore} from "@/store/index.js"; |
|
|
|
|
|
import {hasMenuPermission, permissionMapping} from "@/utils/menuTreePermission.js"; |
|
|
|
|
|
|
|
|
const router = useRouter();// 获取路由实例 |
|
|
|
|
|
const route = useRoute();// 获取当前路由信息 |
|
|
|
|
|
// 定义响应式变量 activeTab 来跟踪当前激活的标签 |
|
|
|
|
|
const activeTab = ref(route.name === 'coinRechargeDetail' ? 'detail' : 'add'); |
|
|
|
|
|
//也就是说如果当前在coinConsumeDetail页面,那么就是detail,否则默认情况都展示add页面 |
|
|
|
|
|
//此时获取到的路由信息是coinConsume,所以默认是add |
|
|
|
|
|
|
|
|
const router = useRouter(); |
|
|
|
|
|
const route = useRoute(); |
|
|
const adminStore = useAdminStore(); |
|
|
const adminStore = useAdminStore(); |
|
|
const {menuTree} = storeToRefs(adminStore); |
|
|
const {menuTree} = storeToRefs(adminStore); |
|
|
|
|
|
|
|
|
const goToAdd = () => { |
|
|
|
|
|
// 点击按钮时更新 activeTab 为 add |
|
|
|
|
|
activeTab.value = 'add'; |
|
|
|
|
|
router.push({name: 'addCoinRecharge'}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const goToDetail = () => { |
|
|
|
|
|
// 点击按钮时更新 activeTab 为 detail |
|
|
|
|
|
activeTab.value = 'detail'; |
|
|
|
|
|
router.push({name: 'coinRechargeDetail'}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const activeTab = ref(''); |
|
|
|
|
|
const hasAdd = ref(false); |
|
|
|
|
|
const hasDetail = ref(false); |
|
|
// 导航方法 |
|
|
// 导航方法 |
|
|
const navigateTo = (name) => { |
|
|
const navigateTo = (name) => { |
|
|
activeTab.value = name; |
|
|
activeTab.value = name; |
|
|
if (name === 'add') { |
|
|
|
|
|
router.push({name: 'addCoinRecharge'}); |
|
|
|
|
|
} else if (name === 'detail') { |
|
|
|
|
|
router.push({name: 'coinRechargeDetail'}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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 getDefaultRoute = () => { |
|
|
|
|
|
if (!menuTree.value) return 'add'; |
|
|
|
|
|
const hasRecharge = hasMenuPermission(menuTree.value, '提交金币充值'); |
|
|
|
|
|
return hasRecharge ? 'add' : 'detail'; |
|
|
|
|
|
|
|
|
// 初始化权限状态 |
|
|
|
|
|
const initPermissions = () => { |
|
|
|
|
|
if (!menuTree.value || !menuTree.value.length) return; |
|
|
|
|
|
|
|
|
|
|
|
hasAdd.value = hasMenuPermission(menuTree.value, permissionMapping.Submit_Gold_Coin_Recharge); |
|
|
|
|
|
hasDetail.value = hasMenuPermission(menuTree.value, permissionMapping.View_Gold_Coin_Recharge_Details); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 默认跳转逻辑 |
|
|
|
|
|
const getDefaultAuditRoute = () => { |
|
|
|
|
|
initPermissions(); |
|
|
|
|
|
if (hasAdd.value) return 'addCoinRecharge'; |
|
|
|
|
|
if (hasDetail.value) return 'coinRechargeDetail'; |
|
|
|
|
|
return 'addCoinRecharge'; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// 监听路由变化更新标签状态 |
|
|
// 监听路由变化更新标签状态 |
|
|
watch(() => route.name, (newName) => { |
|
|
watch(() => route.name, (newName) => { |
|
|
if (newName === 'add' || newName === 'detail') { |
|
|
|
|
|
|
|
|
initPermissions() |
|
|
|
|
|
if (newName === 'addCoinRecharge' || newName === 'coinRechargeDetail') { |
|
|
activeTab.value = newName; |
|
|
activeTab.value = newName; |
|
|
} else if (newName === 'coinRecharge') { |
|
|
} else if (newName === 'coinRecharge') { |
|
|
const defaultRoute = getDefaultRoute(); |
|
|
|
|
|
|
|
|
// 每次访问 /coinConsume 都进行默认跳转 |
|
|
|
|
|
const defaultRoute = getDefaultAuditRoute(); |
|
|
navigateTo(defaultRoute); |
|
|
navigateTo(defaultRoute); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 初始化逻辑 |
|
|
// 初始化逻辑 |
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
|
|
|
initPermissions() |
|
|
if (route.name === 'coinRecharge') { |
|
|
if (route.name === 'coinRecharge') { |
|
|
const defaultRoute = getDefaultRoute(); |
|
|
|
|
|
|
|
|
const defaultRoute = getDefaultAuditRoute(); |
|
|
navigateTo(defaultRoute); |
|
|
navigateTo(defaultRoute); |
|
|
} else { |
|
|
} else { |
|
|
// 非父路由初始化当前标签状态 |
|
|
// 非父路由初始化当前标签状态 |
|
|
if (route.name === 'add' || route.name === 'detail') { |
|
|
|
|
|
|
|
|
if (route.name === 'addCoinRecharge' || route.name === 'coinRechargeDetail') { |
|
|
activeTab.value = route.name; |
|
|
activeTab.value = route.name; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
</script> |
|
|
</script> |