From 0d46ad034ddcddf1c2e7ec1b5ce8c630e14c8366 Mon Sep 17 00:00:00 2001 From: xianyi Date: Mon, 26 Jan 2026 11:00:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 2 +- src/components/home/HomeSection.tsx | 23 ++++++++++------------- src/pages/ExamPage.tsx | 27 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 716b587..e4fe776 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1016,7 +1016,7 @@ export interface MenuItem { /** 组件 */ component?: string | null; /** 子菜单 */ - children?: MenuItem[] | string[]; + children?: MenuItem[]; } /** diff --git a/src/components/home/HomeSection.tsx b/src/components/home/HomeSection.tsx index 2d5fb6d..4be1aa6 100644 --- a/src/components/home/HomeSection.tsx +++ b/src/components/home/HomeSection.tsx @@ -97,21 +97,18 @@ export const HomeSection = () => { .then((res) => { console.log('获取用户菜单权限返回内容:', res); - // 检查菜单 children 中是否有 authCode === 'HisTijianPad_Btn_Tongji' 的项 - const menus = res.Data?.menus || []; + let authCode: string[] = []; + // 存储authCode + for (const child of res.Data?.menus?.[0]?.children || []) { + if (child.authCode) { + authCode.push(child.authCode); + } + } + localStorage.setItem('authCode', authCode.join(',')); + let hasPermission = false; - for (const menu of menus) { - if (menu.children && Array.isArray(menu.children)) { - for (const child of menu.children) { - if (typeof child === 'object' && child.authCode === 'HisTijianPad_Btn_Tongji') { - hasPermission = true; - break; - } - } - } - if (hasPermission) break; - } + hasPermission = authCode.includes('HisTijianPad_Btn_Tongji'); setShowRevenueStats(hasPermission); }) diff --git a/src/pages/ExamPage.tsx b/src/pages/ExamPage.tsx index 04e220f..75f16cb 100644 --- a/src/pages/ExamPage.tsx +++ b/src/pages/ExamPage.tsx @@ -4,7 +4,9 @@ import type { ExamClient, ExamModalTab } from '../data/mockData'; import { EXAM_TAGS } from '../data/mockData'; import { ExamSection } from '../components/exam/ExamSection'; import { ExamModal } from '../components/exam/ExamModal'; -import { getPhysicalExamCustomerList } from '../api'; +import { getPhysicalExamCustomerList, getUserOwnedMenus } from '../api'; + +const APP_ID = 'b2b49e91d21446aeb14579930f732985'; export const ExamPage = () => { const [searchValue, setSearchValue] = useState(''); @@ -16,6 +18,29 @@ export const ExamPage = () => { const [loading, setLoading] = useState(false); const [refreshSeq, setRefreshSeq] = useState(0); + // 进入页面时获取用户菜单权限 + useEffect(() => { + const token = localStorage.getItem('accessToken'); + if (!token) { + return; + } + getUserOwnedMenus({ app_id: APP_ID }) + .then((res) => { + console.log('获取用户菜单权限返回内容:', res); + let authCode: string[] = []; + // 存储authCode + for (const child of res.Data?.menus?.[0]?.children || []) { + if (child.authCode) { + authCode.push(child.authCode); + } + } + localStorage.setItem('authCode', authCode.join(',')); + }) + .catch((err) => { + console.error('获取用户菜单权限失败', err); + }); + }, []); + // 处理筛选标签切换(支持多选) const handleFilterChange = (tag: (typeof EXAM_TAGS)[number]) => { setExamFilterTags((prev) => {