From 0b06d3dd0ea48eabb6d3b3badd3f94e3eb118c41 Mon Sep 17 00:00:00 2001 From: Shu Guang <61069967+shuguangnet@users.noreply.github.com> Date: Sun, 18 May 2025 18:56:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=88=91=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=20&=20=E5=A4=B4=E5=83=8F=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.ts | 6 +++-- src/pages/Access/index.tsx | 22 ++++++++++++++++ src/pages/MyChart/index.tsx | 4 +-- src/pages/User/Info/index.tsx | 44 ++++++++++++++++++++++++++++--- src/pages/User/Register/index.tsx | 25 ++++-------------- 5 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 src/pages/Access/index.tsx diff --git a/config/routes.ts b/config/routes.ts index 50c6d7a..cb0d628 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -1,11 +1,13 @@ export default [ {path: '/user',layout: false,routes: [ { name: '登录', path: '/user/login', component: './User/Login' }, - { name: '注册', path: '/user/register', component: './User/Register' } + { name: '注册', path: '/user/register', component: './User/Register' }, + { name :"权限引导",path: '/user/access', component: './Access'}, ]}, - {path:"/", redirect: "/home"}, + {path:"/", redirect: "/user/access"}, { path: '/home', name :"首页", icon: "PieChartOutlined", component: './HomePage',access: 'canAdmin', }, + // { path: '/access', name :"权限引导", icon: "PieChartOutlined", component: './Access',hidden: true}, { path: '/add_chart', name :"智能分析", icon: "barChart", component: './AddChart' }, { path: '/add_async', name: "异步分析", icon: "DotChartOutlined", component: './AddChartAsync' }, { path: '/my_chart', name: "我的图表", icon: "PictureOutlined", component: './MyChart' }, diff --git a/src/pages/Access/index.tsx b/src/pages/Access/index.tsx new file mode 100644 index 0000000..ebe6725 --- /dev/null +++ b/src/pages/Access/index.tsx @@ -0,0 +1,22 @@ +// 负责处理默认重定向 +import { useEffect } from 'react'; +import { useModel } from 'umi'; +import { history } from '@@/core/history'; +export default () => { + const { initialState } = useModel('@@initialState'); + const { currentUser } = initialState || {}; + + useEffect(() => { + if (currentUser) { + // 获取用户角色,优先使用 currentUser.userRole + const userRole = currentUser?.userRole || currentUser?.data?.userRole; + // 根据用户角色重定向到不同页面 + history.push(userRole === 'user' ? '/add_chart' : '/home'); + + } else { + history.push('/user/login'); + } + }, [currentUser]); + + return
Loading...
; +}; diff --git a/src/pages/MyChart/index.tsx b/src/pages/MyChart/index.tsx index 01bdabc..e1b9a45 100644 --- a/src/pages/MyChart/index.tsx +++ b/src/pages/MyChart/index.tsx @@ -1,4 +1,4 @@ -import { listChartByPageUsingPost } from '@/services/hebi/chartController'; +import { listChartByPageUsingPost,listMyChartByPageUsingPost } from '@/services/hebi/chartController'; import { useModel } from '@@/exports'; import { Avatar, Card, Input, List, message, Result } from 'antd'; import ReactECharts from 'echarts-for-react'; @@ -30,7 +30,7 @@ const MyChartPage: React.FC = () => { const loadData = async () => { setLoading(true); try { - const res = await listChartByPageUsingPost(searchParams); + const res = currentUser?.userRole==='user'?await listMyChartByPageUsingPost(searchParams):await listChartByPageUsingPost(searchParams); if (res.data) { setChartList(res.data.records ?? []); setTotal(res.data.total ?? 0); diff --git a/src/pages/User/Info/index.tsx b/src/pages/User/Info/index.tsx index 78b9f56..0d34e3f 100644 --- a/src/pages/User/Info/index.tsx +++ b/src/pages/User/Info/index.tsx @@ -25,6 +25,7 @@ import { useModel } from '@umijs/max'; import type { UploadProps } from 'antd/es/upload'; import { getUserByIdUsingGet, updateUserUsingPost } from '@/services/hebi/userController'; import { countChartsUsingGet } from '@/services/hebi/chartController'; // 新增 +import { uploadFileUsingPost } from '@/services/hebi/fileController'; import dayjs from 'dayjs'; // 新增 const { TabPane } = Tabs; @@ -37,7 +38,7 @@ const UserInfo: React.FC = () => { const [loading, setLoading] = useState(false); const [form] = Form.useForm(); const [apiCallCount, setApiCallCount] = useState(0); // 新增 - + const [avatarUrl, setAvatarUrl] = useState(); // 拉取用户信息 useEffect(() => { const fetchUserInfo = async () => { @@ -73,7 +74,7 @@ const UserInfo: React.FC = () => { const res = await updateUserUsingPost({ id: userInfo.id, userName: values.userName, - userAvatar: userInfo.userAvatar, + userAvatar: avatarUrl||userInfo.userAvatar, userProfile: values.phone, // 假设 userProfile 存手机号(如有 phone 字段请替换) // 其他字段如有需要可补充 }); @@ -91,6 +92,39 @@ const UserInfo: React.FC = () => { } }; + const handleUploadChange = async (info: any) => { + if (info.file.status === 'uploading') { + return; + } + if (info.file.status === 'done') { + const response = info.file.response; + if (response.code === 0) { + setAvatarUrl(response.data); + message.success('头像上传成功'); + // 更新表单字段值 + form.setFieldValue('userAvatar', response.data); + } else { + message.error(response.message || '头像上传失败'); + } + } + }; + + const customRequest = async ({ file, onSuccess, onError }: any) => { + try { + const res = await uploadFileUsingPost(file, { + file, + biz: 'user_avatar', + }); + if (res.code === 0) { + onSuccess(res); + } else { + onError(new Error(res.message)); + } + } catch (error) { + onError(error); + } + }; + // 处理头像上传 const handleAvatarUpload: UploadProps['onChange'] = async (info) => { if (info.file.status === 'uploading') { @@ -124,12 +158,14 @@ const UserInfo: React.FC = () => { } />