Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2db7793ab3 | ||
|
593f921ef4 | ||
|
b763c47e48 | ||
|
0b06d3dd0e |
@ -1,11 +1,13 @@
|
|||||||
export default [
|
export default [
|
||||||
{path: '/user',layout: false,routes: [
|
{path: '/user',layout: false,routes: [
|
||||||
{ name: '登录', path: '/user/login', component: './User/Login' },
|
{ 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: '/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_chart', name :"智能分析", icon: "barChart", component: './AddChart' },
|
||||||
{ path: '/add_async', name: "异步分析", icon: "DotChartOutlined", component: './AddChartAsync' },
|
{ path: '/add_async', name: "异步分析", icon: "DotChartOutlined", component: './AddChartAsync' },
|
||||||
{ path: '/my_chart', name: "我的图表", icon: "PictureOutlined", component: './MyChart' },
|
{ path: '/my_chart', name: "我的图表", icon: "PictureOutlined", component: './MyChart' },
|
||||||
|
22
src/pages/Access/index.tsx
Normal file
22
src/pages/Access/index.tsx
Normal file
@ -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 <div>Loading...</div>;
|
||||||
|
};
|
@ -1,4 +1,4 @@
|
|||||||
import { listChartByPageUsingPost } from '@/services/hebi/chartController';
|
import { listChartByPageUsingPost,listMyChartByPageUsingPost } from '@/services/hebi/chartController';
|
||||||
import { useModel } from '@@/exports';
|
import { useModel } from '@@/exports';
|
||||||
import { Avatar, Card, Input, List, message, Result } from 'antd';
|
import { Avatar, Card, Input, List, message, Result } from 'antd';
|
||||||
import ReactECharts from 'echarts-for-react';
|
import ReactECharts from 'echarts-for-react';
|
||||||
@ -30,7 +30,7 @@ const MyChartPage: React.FC = () => {
|
|||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await listChartByPageUsingPost(searchParams);
|
const res = currentUser?.userRole==='user'?await listMyChartByPageUsingPost(searchParams):await listChartByPageUsingPost(searchParams);
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
setChartList(res.data.records ?? []);
|
setChartList(res.data.records ?? []);
|
||||||
setTotal(res.data.total ?? 0);
|
setTotal(res.data.total ?? 0);
|
||||||
|
@ -25,6 +25,7 @@ import { useModel } from '@umijs/max';
|
|||||||
import type { UploadProps } from 'antd/es/upload';
|
import type { UploadProps } from 'antd/es/upload';
|
||||||
import { getUserByIdUsingGet, updateUserUsingPost } from '@/services/hebi/userController';
|
import { getUserByIdUsingGet, updateUserUsingPost } from '@/services/hebi/userController';
|
||||||
import { countChartsUsingGet } from '@/services/hebi/chartController'; // 新增
|
import { countChartsUsingGet } from '@/services/hebi/chartController'; // 新增
|
||||||
|
import { uploadFileUsingPost } from '@/services/hebi/fileController';
|
||||||
import dayjs from 'dayjs'; // 新增
|
import dayjs from 'dayjs'; // 新增
|
||||||
|
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
@ -37,7 +38,7 @@ const UserInfo: React.FC = () => {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [apiCallCount, setApiCallCount] = useState<number>(0); // 新增
|
const [apiCallCount, setApiCallCount] = useState<number>(0); // 新增
|
||||||
|
const [avatarUrl, setAvatarUrl] = useState<string>();
|
||||||
// 拉取用户信息
|
// 拉取用户信息
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUserInfo = async () => {
|
const fetchUserInfo = async () => {
|
||||||
@ -73,7 +74,7 @@ const UserInfo: React.FC = () => {
|
|||||||
const res = await updateUserUsingPost({
|
const res = await updateUserUsingPost({
|
||||||
id: userInfo.id,
|
id: userInfo.id,
|
||||||
userName: values.userName,
|
userName: values.userName,
|
||||||
userAvatar: userInfo.userAvatar,
|
userAvatar: avatarUrl||userInfo.userAvatar,
|
||||||
userProfile: values.phone, // 假设 userProfile 存手机号(如有 phone 字段请替换)
|
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) => {
|
const handleAvatarUpload: UploadProps['onChange'] = async (info) => {
|
||||||
if (info.file.status === 'uploading') {
|
if (info.file.status === 'uploading') {
|
||||||
@ -124,12 +158,14 @@ const UserInfo: React.FC = () => {
|
|||||||
<Upload
|
<Upload
|
||||||
name="avatar"
|
name="avatar"
|
||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
onChange={handleAvatarUpload}
|
// onChange={handleAvatarUpload}
|
||||||
|
customRequest={customRequest}
|
||||||
|
onChange={handleUploadChange}
|
||||||
>
|
>
|
||||||
<Space direction="vertical" size="large">
|
<Space direction="vertical" size="large">
|
||||||
<Avatar
|
<Avatar
|
||||||
size={120}
|
size={120}
|
||||||
src={userInfo?.userAvatar}
|
src={avatarUrl || userInfo?.userAvatar}
|
||||||
icon={<UserOutlined />}
|
icon={<UserOutlined />}
|
||||||
/>
|
/>
|
||||||
<Button icon={<UploadOutlined />} loading={loading}>
|
<Button icon={<UploadOutlined />} loading={loading}>
|
||||||
@ -165,7 +201,7 @@ const UserInfo: React.FC = () => {
|
|||||||
<Input prefix={<UserOutlined />} />
|
<Input prefix={<UserOutlined />} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="用户名"
|
label="账号"
|
||||||
name="email"
|
name="email"
|
||||||
// rules={[{ required: true, type: 'email' }]}
|
// rules={[{ required: true, type: 'email' }]}
|
||||||
>
|
>
|
||||||
|
@ -94,10 +94,11 @@ useEffect(()=>{
|
|||||||
message.success(defaultLoginSuccessMessage);
|
message.success(defaultLoginSuccessMessage);
|
||||||
await fetchUserInfo();
|
await fetchUserInfo();
|
||||||
// 登录成功后,设置刷新标记并刷新页面
|
// 登录成功后,设置刷新标记并刷新页面
|
||||||
const urlParams = new URL(window.location.href).searchParams;
|
// const urlParams = new URL(window.location.href).searchParams;
|
||||||
history.push(urlParams.get('redirect') || '/');
|
// history.push(urlParams.get('redirect') || '/');
|
||||||
sessionStorage.setItem('avatar_refreshed', '1');
|
sessionStorage.setItem('avatar_refreshed', '1');
|
||||||
window.location.href = urlParams.get('redirect') || '/';
|
window.location.href = '/user/access';
|
||||||
|
history.push('/user/access');
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
message.error(res.message);
|
message.error(res.message);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Footer } from '@/components';
|
import { Footer } from '@/components';
|
||||||
import { userRegisterUsingPost } from '@/services/hebi/userController';
|
import { userRegisterUsingPost } from '@/services/hebi/userController';
|
||||||
|
import { uploadFileUsingPost } from '@/services/hebi/fileController';
|
||||||
import { LockOutlined, PictureOutlined, UserOutlined } from '@ant-design/icons';
|
import { LockOutlined, PictureOutlined, UserOutlined } from '@ant-design/icons';
|
||||||
import { ProForm, ProFormText } from '@ant-design/pro-components';
|
import { ProForm, ProFormText } from '@ant-design/pro-components';
|
||||||
import { Helmet, history, Link } from '@umijs/max';
|
import { Helmet, history, Link } from '@umijs/max';
|
||||||
@ -62,7 +63,7 @@ const Register: React.FC = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await userRegisterUsingPost({ ...values, userAvatar: avatarUrl });
|
const res = await userRegisterUsingPost({ ...values, userAvatar: 'http://img-oss.shuguangwl.com/2025/05/18/6829ae97cee35.png' });
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
message.success('注册成功!');
|
message.success('注册成功!');
|
||||||
history.push('/user/login');
|
history.push('/user/login');
|
||||||
@ -81,6 +82,8 @@ const Register: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<Helmet>
|
<Helmet>
|
||||||
@ -111,25 +114,7 @@ const Register: React.FC = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ProForm.Item
|
|
||||||
name="userAvatar"
|
|
||||||
rules={[{ required: true, message: '请上传头像' }]}
|
|
||||||
className={styles.avatarUploader}
|
|
||||||
>
|
|
||||||
<Upload
|
|
||||||
name="avatar"
|
|
||||||
listType="picture-card"
|
|
||||||
showUploadList={false}
|
|
||||||
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
|
|
||||||
onChange={(info) => {
|
|
||||||
if (info.file.status === 'done') {
|
|
||||||
setAvatarUrl(info.file.response.url);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{avatarUrl ? <Avatar src={avatarUrl} size={64} /> : uploadButton}
|
|
||||||
</Upload>
|
|
||||||
</ProForm.Item>
|
|
||||||
|
|
||||||
<ProFormText
|
<ProFormText
|
||||||
name="userAccount"
|
name="userAccount"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user