完善用户菜单权限,显示营收数据
This commit is contained in:
@@ -313,9 +313,22 @@ export const getVerificationCodePhone = (
|
|||||||
export const getUserOwnedMenus = (
|
export const getUserOwnedMenus = (
|
||||||
data: InputUserOwnedMenus
|
data: InputUserOwnedMenus
|
||||||
): Promise<UserOwnedMenusResponse> => {
|
): 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>(
|
return request.post<UserOwnedMenusResponse>(
|
||||||
`/api/auth/user/owned/menus`,
|
`/api/auth/user/owned/menus`,
|
||||||
data
|
data,
|
||||||
|
{
|
||||||
|
headers,
|
||||||
|
}
|
||||||
).then(res => res.data);
|
).then(res => res.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { useEffect, useMemo, useState } from 'react';
|
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 { B1_ROWS, B1_SUMMARY, NORTH3_ROWS, NORTH3_SUMMARY } from '../../data/mockData';
|
||||||
import { Card, CardContent, CardHeader, InfoCard } from '../ui';
|
import { Card, CardContent, CardHeader, InfoCard } from '../ui';
|
||||||
|
|
||||||
|
const APP_ID = 'b2b49e91d21446aeb14579930f732985';
|
||||||
|
|
||||||
type HomeStatItem = { label: string; value: number };
|
type HomeStatItem = { label: string; value: number };
|
||||||
type RevenueStatItem = { label: string; value: string | number };
|
type RevenueStatItem = { label: string; value: string | number };
|
||||||
|
|
||||||
@@ -22,6 +24,7 @@ export const HomeSection = () => {
|
|||||||
{ label: '完成百分比', value: '0%' },
|
{ label: '完成百分比', value: '0%' },
|
||||||
{ label: '当日缺口', value: '¥ 0' },
|
{ label: '当日缺口', value: '¥ 0' },
|
||||||
]);
|
]);
|
||||||
|
const [showRevenueStats, setShowRevenueStats] = useState(false);
|
||||||
|
|
||||||
const currencyFormatter = useMemo(() => new Intl.NumberFormat('zh-CN', {
|
const currencyFormatter = useMemo(() => new Intl.NumberFormat('zh-CN', {
|
||||||
style: 'currency',
|
style: 'currency',
|
||||||
@@ -66,6 +69,35 @@ export const HomeSection = () => {
|
|||||||
});
|
});
|
||||||
}, [currencyFormatter]);
|
}, [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 (
|
return (
|
||||||
<div className='space-y-6'>
|
<div className='space-y-6'>
|
||||||
<Card>
|
<Card>
|
||||||
@@ -79,6 +111,7 @@ export const HomeSection = () => {
|
|||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{showRevenueStats && (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>今日营收统计</CardHeader>
|
<CardHeader>今日营收统计</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
@@ -89,6 +122,7 @@ export const HomeSection = () => {
|
|||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className='grid grid-cols-2 gap-4'>
|
<div className='grid grid-cols-2 gap-4'>
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user