diff --git a/src/main.ts b/src/main.ts index e5388b2..795d7b9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,13 +12,13 @@ import VxeUI from 'vxe-pc-ui' import 'vxe-pc-ui/lib/style.css' import VxeUITable from 'vxe-table' import 'vxe-table/lib/style.css' - const a = createApp(App) - +import { useAdminStore } from '../src/store' // 全局注册 ElementPlus 图标 for (const [key, component] of Object.entries(ElementPlusIconsVue)) { a.component(key, component) } +const pinia = createPinia() // 使用 ElementPlus 和路由器 a.use(ElementPlus, { @@ -27,8 +27,12 @@ a.use(ElementPlus, { .use(router) .use(VxeUI) .use(VxeUITable) - .use(createPinia()) + .use(pinia) .mount('#app') +// 恢复localStorage数据 +const adminStore = useAdminStore() +adminStore.initFromLocalStorage() + // 注册 JsonExcel 组件 a.component('downloadExcel', JsonExcel) diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..2a86cd8 --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,45 @@ +// src/store/index.js +import { defineStore } from 'pinia' + +export const useAdminStore = defineStore('admin', { + state: () => ({ + adminData: null, // 用户信息 + menuTree: null, // 菜单权限树 + }), + actions: { + // 设置用户信息并同步到localStorage + setAdminData(info) { + this.adminData = info + localStorage.setItem('adminData', JSON.stringify(info)) + }, + + // 设置菜单树并同步到localStorage + setMenuTree(tree) { + this.menuTree = tree + localStorage.setItem('menuTree', JSON.stringify(tree)) + }, + + // 从localStorage初始化数据 + initFromLocalStorage() { + const adminData = localStorage.getItem('adminData') + const menuTree = localStorage.getItem('menuTree') + + if (adminData) { + this.adminData = JSON.parse(adminData) + } + + if (menuTree) { + this.menuTree = JSON.parse(menuTree) + } + }, + + // 清空状态并移除localStorage数据 + clearState() { + this.adminData = null + this.menuTree = null + localStorage.removeItem('adminData') + localStorage.removeItem('menuTree') + // localStorage.removeItem('token') + } + } +}) \ No newline at end of file diff --git a/src/utils/menu-utils.ts b/src/utils/menuUtils.js similarity index 56% rename from src/utils/menu-utils.ts rename to src/utils/menuUtils.js index 84212a0..451dda5 100644 --- a/src/utils/menu-utils.ts +++ b/src/utils/menuUtils.js @@ -1,4 +1,4 @@ -// 菜单树过滤 +// 菜单树过滤 (展示的? ) export function filterMenu(menuList) { return menuList // 过滤不是4级的 123 为菜单 @@ -36,6 +36,9 @@ export const getRoutePath = (menu) => { '审核页面': '/audit', '财务审核': '/audit', + '充值审核': '/audit/rechargeAudit', + '退款审核': '/audit/refundAudit', + '汇率管理': '/rate', '消耗管理': '/coinConsume', @@ -44,6 +47,7 @@ export const getRoutePath = (menu) => { '权限管理': '/permissions', '充值管理': '/coinRecharge', + '充值页面': '/coinRecharge', '退款管理': '/coinRefund', @@ -55,51 +59,4 @@ export const getRoutePath = (menu) => { // 未匹配的菜单默认使用id作为路由(可根据实际需求调整) return routeMap[menu.menuName] || '/noPermissionPage' -} - - -// 这是获取用户信息的接口 -const adminData = ref({ - name: '' -}) - -import API from "@/util/http.js"; -import {ref} from "vue"; - -export const getAdminData = async function () { - try { - const result = await API({url: '/admin/userinfo', data: {}}) - adminData.value = result - console.log('请求成功', result) - console.log('用户信息', adminData.value) - return result - } catch (error) { - console.log('请求失败', error) - } -} - - -// 权限检查函数 -export const hasPermission = (to, menuList) => { - if (!menuList || menuList.length === 0) return false; - - // 转换路由路径为菜单名称 - const routePath = to.path; - const menuName = Object.keys(getRoutePath).find(key => getRoutePath[key] === routePath); - - if (!menuName) return false; - - // 扁平化菜单树以便查找 - const flattenMenu = (menus) => { - return menus.reduce((acc, menu) => { - acc.push(menu); - if (menu.children) { - acc = acc.concat(flattenMenu(menu.children)); - } - return acc; - }, []); - }; - - const flatMenuList = flattenMenu(menuList); - return flatMenuList.some(menu => menu.menuName === menuName); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/views/home.vue b/src/views/home.vue index 9f6d8ef..da56eea 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -1,118 +1,37 @@ @@ -224,31 +73,44 @@ const handleClosePasswordDialog = () => { z-index: 100; /* 确保侧边栏在其他元素之上 */ "> - + diff --git a/src/views/login.vue b/src/views/login.vue index c24c406..b77bf3c 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -1,11 +1,12 @@