diff --git a/src/store/index.js b/src/store/index.js index de91a35..cab0bfe 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,6 +6,7 @@ export const useAdminStore = defineStore('admin', { adminData: null, // 用户信息 menuTree: [], // 菜单权限树 marketList: {}, // 市场列表 + flag: 0, //员工数据开关状态,0=不包含员工数据,1=包含员工数据 }), actions: { // 设置用户信息并同步到localStorage @@ -24,11 +25,18 @@ export const useAdminStore = defineStore('admin', { localStorage.setItem('marketList', JSON.stringify(list)) }, + // 设置员工数据开关状态(使用数字0和1) + setFlag(flag) { + this.flag = flag + localStorage.setItem('flag', JSON.stringify(flag)) + }, + // 从localStorage初始化数据 initFromLocalStorage() { const adminData = localStorage.getItem('adminData') const menuTree = localStorage.getItem('menuTree') const marketList = localStorage.getItem('marketList') + const flag = localStorage.getItem('flag') if (adminData) { this.adminData = JSON.parse(adminData) @@ -41,6 +49,10 @@ export const useAdminStore = defineStore('admin', { if (marketList) { this.marketList = JSON.parse(marketList) } + + if (flag) { + this.flag = JSON.parse(flag) + } }, // 清空状态并移除localStorage数据 @@ -48,9 +60,11 @@ export const useAdminStore = defineStore('admin', { this.adminData = null this.menuTree = [] this.marketList = {} + this.flag = 0 localStorage.removeItem('adminData') localStorage.removeItem('menuTree') localStorage.removeItem('marketList') + localStorage.removeItem('flag') // localStorage.removeItem('token') } } diff --git a/src/views/consume/bean/beanConsume.vue b/src/views/consume/bean/beanConsume.vue index ea2c360..df8141d 100644 --- a/src/views/consume/bean/beanConsume.vue +++ b/src/views/consume/bean/beanConsume.vue @@ -3,8 +3,8 @@ @@ -72,26 +72,26 @@ const navigateTo = (name) => { const initPermissions = () => { if (!menuTree.value || !menuTree.value.length) return; - hasAdd.value = hasMenuPermission(menuTree.value, permissionMapping.addBeanConsume); - hasLive.value = hasMenuPermission(menuTree.value, permissionMapping.beanZBDetail); - hasFan.value = hasMenuPermission(menuTree.value, permissionMapping.beanTFDetail); - hasArticleVideo.value = hasMenuPermission(menuTree.value, permissionMapping.beanSPWZDetail); + hasAdd.value = hasMenuPermission(menuTree.value, permissionMapping.add_gold_bean_consumption); + hasLive.value = hasMenuPermission(menuTree.value, permissionMapping.gold_bean_live_details); + hasFan.value = hasMenuPermission(menuTree.value, permissionMapping.gold_bean_fan_details); + hasArticleVideo.value = hasMenuPermission(menuTree.value, permissionMapping.gold_bean_video_details); }; // 默认跳转逻辑 const getDefaultAuditRoute = () => { initPermissions(); - if (hasAdd.value) return 'addBeanConsume'; + if (hasAdd.value) return 'add_gold_bean_consumption'; if (hasLive.value) return 'liveStream'; if (hasFan.value) return 'dieHardFan'; if (hasArticleVideo.value) return 'articleVideo'; - return 'addBeanConsume'; + return 'add_gold_bean_consumption'; }; // 监听路由变化更新标签状态 watch(() => route.name, (newName) => { initPermissions() - if (newName=== 'addBeanConsume' || newName === 'liveStream' || newName === 'dieHardFan' || newName === 'articleVideo') { + if (newName=== 'add_gold_bean_consumption' || newName === 'liveStream' || newName === 'dieHardFan' || newName === 'articleVideo') { activeTab.value = newName; } else if (newName === 'beanConsume') { // 每次访问 /beanConsume 都进行默认跳转 @@ -108,7 +108,7 @@ onMounted(() => { navigateTo(defaultRoute); } else { // 非父路由初始化当前标签状态 - if (route.name=== 'addBeanConsume' || route.name === 'liveStream' || route.name === 'dieHardFan' || route.name === 'articleVideo') { + if (route.name=== 'add_gold_bean_consumption' || route.name === 'liveStream' || route.name === 'dieHardFan' || route.name === 'articleVideo') { activeTab.value = route.name; } } diff --git a/src/views/home.vue b/src/views/home.vue index b692dfe..5910196 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -79,7 +79,7 @@ const menuList = ref([]) // 获取仓库实例 const adminStore = useAdminStore() // 解构状态(保持响应式) 获得 adminData(用户信息) 和 menuTree(菜单树) -const { adminData, menuTree } = storeToRefs(adminStore) +const { adminData, menuTree, flag } = storeToRefs(adminStore) // 筛选权限菜单 ,menuTree 是组件通信拿的 menuList.value = filterMenu(menuTree.value) @@ -156,6 +156,13 @@ function logout() { ElMessage.success('退出成功') } +// 切换员工数据开关状态 +const toggleFlag = () => { + const newFlag = flag.value === 1 ? 0 : 1 + adminStore.setFlag(newFlag) + ElMessage.success(newFlag === 1 ? '员工数据已隐藏' : '员工数据已显示') + console.log('flag',newFlag) +} @@ -243,6 +250,10 @@ function logout() {