完善用户菜单权限,显示营收数据

This commit is contained in:
xianyi
2025-12-17 09:58:37 +08:00
parent c376f9344b
commit 1c15d4b892
2 changed files with 59 additions and 12 deletions

View File

@@ -313,9 +313,22 @@ export const getVerificationCodePhone = (
export const getUserOwnedMenus = (
data: InputUserOwnedMenus
): Promise<UserOwnedMenusResponse> => {
// 从 localStorage 获取 accessToken
const accessToken = typeof window !== 'undefined'
? localStorage.getItem('accessToken')
: null;
const headers: Record<string, string> = {};
if (accessToken) {
headers.Authorization = `Bearer ${accessToken}`;
}
return request.post<UserOwnedMenusResponse>(
`/api/auth/user/owned/menus`,
data
data,
{
headers,
}
).then(res => res.data);
};

View File

@@ -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 (
<div className='space-y-6'>
<Card>
@@ -79,16 +111,18 @@ export const HomeSection = () => {
</CardContent>
</Card>
<Card>
<CardHeader></CardHeader>
<CardContent>
<div className='grid grid-cols-3 gap-3'>
{revenueStats.map(({ label, value }) => (
<InfoCard key={label} label={label} value={value} />
))}
</div>
</CardContent>
</Card>
{showRevenueStats && (
<Card>
<CardHeader></CardHeader>
<CardContent>
<div className='grid grid-cols-3 gap-3'>
{revenueStats.map(({ label, value }) => (
<InfoCard key={label} label={label} value={value} />
))}
</div>
</CardContent>
</Card>
)}
<div className='grid grid-cols-2 gap-4'>
<Card>