From 1c15d4b8929fb188724f5880d795f6e75f3f3477 Mon Sep 17 00:00:00 2001 From: xianyi Date: Wed, 17 Dec 2025 09:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=94=A8=E6=88=B7=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=9D=83=E9=99=90=EF=BC=8C=E6=98=BE=E7=A4=BA=E8=90=A5?= =?UTF-8?q?=E6=94=B6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/his.ts | 15 +++++++- src/components/home/HomeSection.tsx | 56 +++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/api/his.ts b/src/api/his.ts index 3ef0f49..ef7efda 100644 --- a/src/api/his.ts +++ b/src/api/his.ts @@ -313,9 +313,22 @@ export const getVerificationCodePhone = ( export const getUserOwnedMenus = ( data: InputUserOwnedMenus ): Promise => { + // 从 localStorage 获取 accessToken + const accessToken = typeof window !== 'undefined' + ? localStorage.getItem('accessToken') + : null; + + const headers: Record = {}; + if (accessToken) { + headers.Authorization = `Bearer ${accessToken}`; + } + return request.post( `/api/auth/user/owned/menus`, - data + data, + { + headers, + } ).then(res => res.data); }; diff --git a/src/components/home/HomeSection.tsx b/src/components/home/HomeSection.tsx index ed9ae6a..abd7c2a 100644 --- a/src/components/home/HomeSection.tsx +++ b/src/components/home/HomeSection.tsx @@ -1,8 +1,10 @@ import { useEffect, useMemo, useState } from 'react'; -import { getRevenueStatistics, getTodayExamStatistics } from '../../api'; +import { getRevenueStatistics, getTodayExamStatistics, getUserOwnedMenus } from '../../api'; import { B1_ROWS, B1_SUMMARY, NORTH3_ROWS, NORTH3_SUMMARY } from '../../data/mockData'; import { Card, CardContent, CardHeader, InfoCard } from '../ui'; +const APP_ID = 'b2b49e91d21446aeb14579930f732985'; + type HomeStatItem = { label: string; value: number }; type RevenueStatItem = { label: string; value: string | number }; @@ -22,6 +24,7 @@ export const HomeSection = () => { { label: '完成百分比', value: '0%' }, { label: '当日缺口', value: '¥ 0' }, ]); + const [showRevenueStats, setShowRevenueStats] = useState(false); const currencyFormatter = useMemo(() => new Intl.NumberFormat('zh-CN', { style: 'currency', @@ -66,6 +69,35 @@ export const HomeSection = () => { }); }, [currencyFormatter]); + useEffect(() => { + getUserOwnedMenus({ app_id: APP_ID }) + .then((res) => { + console.log('获取用户菜单权限返回内容:', res); + + // 检查菜单 children 中是否有 authCode === 'HisTijianPad_Btn_Tongji' 的项 + const menus = res.Data?.menus || []; + 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; + } + + setShowRevenueStats(hasPermission); + }) + .catch((err) => { + console.error('获取用户菜单权限失败', err); + setShowRevenueStats(false); + }); + }, []); + return (
@@ -79,16 +111,18 @@ export const HomeSection = () => { - - 今日营收统计 - -
- {revenueStats.map(({ label, value }) => ( - - ))} -
-
-
+ {showRevenueStats && ( + + 今日营收统计 + +
+ {revenueStats.map(({ label, value }) => ( + + ))} +
+
+
+ )}