Compare commits
No commits in common. "3a1c04686a350318c6df9a8bd24eb9fb2d75a60d" and "c32c8d5e4ff6261da30390f4f7281586cd32e3cc" have entirely different histories.
3a1c04686a
...
c32c8d5e4f
@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { PageContainer } from '@ant-design/pro-components';
|
import { PageContainer } from '@ant-design/pro-components';
|
||||||
import { Table, Button, Modal, Form, Input, Tag, Space, Popconfirm, message, Avatar } from 'antd';
|
import { Table, Button, Modal, Form, Input, Tag, Space, Popconfirm, message, Avatar } from 'antd';
|
||||||
import { listAllPostsUsingGet, updatePostUsingPost, deletePostUsingPost, addPostUsingPost } from '@/services/hebi/postController';
|
import { listAllPostsUsingGet, updatePostUsingPost, deletePostUsingPost, addPostUsingPost } from '@/services/hebi/postController';
|
||||||
import dayjs from 'dayjs'; // 新增
|
|
||||||
|
|
||||||
const ForumAdmin: React.FC = () => {
|
const ForumAdmin: React.FC = () => {
|
||||||
const [posts, setPosts] = useState<any[]>([]);
|
const [posts, setPosts] = useState<any[]>([]);
|
||||||
@ -117,7 +116,6 @@ const ForumAdmin: React.FC = () => {
|
|||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
dataIndex: 'createTime',
|
dataIndex: 'createTime',
|
||||||
width: 180,
|
width: 180,
|
||||||
render: (time: string) => time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : '-',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
|
@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import { PageContainer } from '@ant-design/pro-components';
|
import { PageContainer } from '@ant-design/pro-components';
|
||||||
import { Table, Button, Modal, Form, Input, Space, Popconfirm, message, Avatar, Select } from 'antd';
|
import { Table, Button, Modal, Form, Input, Space, Popconfirm, message, Avatar, Select } from 'antd';
|
||||||
import { listUserByPageUsingPost, updateUserUsingPost, deleteUserUsingPost, addUserUsingPost } from '@/services/hebi/userController';
|
import { listUserByPageUsingPost, updateUserUsingPost, deleteUserUsingPost, addUserUsingPost } from '@/services/hebi/userController';
|
||||||
import dayjs from 'dayjs'; // 新增
|
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
|
|
||||||
@ -168,7 +167,6 @@ const UserManage: React.FC = () => {
|
|||||||
dataIndex: 'createTime',
|
dataIndex: 'createTime',
|
||||||
width: 180,
|
width: 180,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: (time: string) => time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : '-',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { PageContainer, ProCard } from '@ant-design/pro-components';
|
import { PageContainer, ProCard } from '@ant-design/pro-components';
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
@ -23,73 +23,15 @@ import {
|
|||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { useModel } from '@umijs/max';
|
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 { countChartsUsingGet } from '@/services/hebi/chartController'; // 新增
|
|
||||||
import dayjs from 'dayjs'; // 新增
|
|
||||||
|
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
|
|
||||||
const UserInfo: React.FC = () => {
|
const UserInfo: React.FC = () => {
|
||||||
const { initialState } = useModel('@@initialState');
|
const { initialState } = useModel('@@initialState');
|
||||||
const { currentUser } = initialState || {};
|
const { currentUser } = initialState || {};
|
||||||
const [userInfo, setUserInfo] = useState<any>(null);
|
|
||||||
const [passwordVisible, setPasswordVisible] = useState(false);
|
const [passwordVisible, setPasswordVisible] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [apiCallCount, setApiCallCount] = useState<number>(0); // 新增
|
|
||||||
|
|
||||||
// 拉取用户信息
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchUserInfo = async () => {
|
|
||||||
if (!currentUser?.id) return;
|
|
||||||
const res = await getUserByIdUsingGet({ id: currentUser.id });
|
|
||||||
if (res && res.code === 0 && res.data) {
|
|
||||||
setUserInfo(res.data);
|
|
||||||
form.setFieldsValue({
|
|
||||||
userName: res.data.userName,
|
|
||||||
email: res.data.userAccount, // 假设 userAccount 是邮箱
|
|
||||||
phone: res.data.userProfile, // 假设 userProfile 存手机号(如有 phone 字段请替换)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchUserInfo();
|
|
||||||
}, [currentUser?.id, form]);
|
|
||||||
|
|
||||||
// 拉取API调用次数
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchApiCallCount = async () => {
|
|
||||||
const res = await countChartsUsingGet();
|
|
||||||
if (res && res.code === 0) {
|
|
||||||
setApiCallCount(res.data || 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchApiCallCount();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// 处理基本信息更新
|
|
||||||
const handleInfoUpdate = async (values: any) => {
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
const res = await updateUserUsingPost({
|
|
||||||
id: userInfo.id,
|
|
||||||
userName: values.userName,
|
|
||||||
userAvatar: userInfo.userAvatar,
|
|
||||||
userProfile: values.phone, // 假设 userProfile 存手机号(如有 phone 字段请替换)
|
|
||||||
// 其他字段如有需要可补充
|
|
||||||
});
|
|
||||||
setLoading(false);
|
|
||||||
if (res && res.code === 0) {
|
|
||||||
message.success('信息更新成功');
|
|
||||||
// 更新本地 userInfo
|
|
||||||
setUserInfo({ ...userInfo, userName: values.userName, userProfile: values.phone });
|
|
||||||
} else {
|
|
||||||
message.error(res?.message || '信息更新失败');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
setLoading(false);
|
|
||||||
message.error('信息更新失败');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 处理头像上传
|
// 处理头像上传
|
||||||
const handleAvatarUpload: UploadProps['onChange'] = async (info) => {
|
const handleAvatarUpload: UploadProps['onChange'] = async (info) => {
|
||||||
@ -116,6 +58,17 @@ const UserInfo: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 处理基本信息更新
|
||||||
|
const handleInfoUpdate = async (values: any) => {
|
||||||
|
try {
|
||||||
|
// 这里应该调用更新用户信息的API
|
||||||
|
// await updateUserInfo(values);
|
||||||
|
message.success('信息更新成功');
|
||||||
|
} catch (error) {
|
||||||
|
message.error('信息更新失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
<ProCard split="vertical">
|
<ProCard split="vertical">
|
||||||
@ -129,7 +82,7 @@ const UserInfo: React.FC = () => {
|
|||||||
<Space direction="vertical" size="large">
|
<Space direction="vertical" size="large">
|
||||||
<Avatar
|
<Avatar
|
||||||
size={120}
|
size={120}
|
||||||
src={userInfo?.userAvatar}
|
src={currentUser?.avatar}
|
||||||
icon={<UserOutlined />}
|
icon={<UserOutlined />}
|
||||||
/>
|
/>
|
||||||
<Button icon={<UploadOutlined />} loading={loading}>
|
<Button icon={<UploadOutlined />} loading={loading}>
|
||||||
@ -138,8 +91,8 @@ const UserInfo: React.FC = () => {
|
|||||||
</Space>
|
</Space>
|
||||||
</Upload>
|
</Upload>
|
||||||
<div style={{ marginTop: '16px' }}>
|
<div style={{ marginTop: '16px' }}>
|
||||||
<h2>{userInfo?.userName}</h2>
|
<h2>{currentUser?.name}</h2>
|
||||||
<Tag color="blue">{userInfo?.userRole || '普通用户'}</Tag>
|
<Tag color="blue">{currentUser?.role || '普通用户'}</Tag>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ProCard>
|
</ProCard>
|
||||||
@ -149,55 +102,66 @@ const UserInfo: React.FC = () => {
|
|||||||
<TabPane tab="基本信息" key="1">
|
<TabPane tab="基本信息" key="1">
|
||||||
<Form
|
<Form
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
form={form}
|
initialValues={currentUser}
|
||||||
initialValues={{
|
|
||||||
userName: userInfo?.userName,
|
|
||||||
email: userInfo?.userAccount,
|
|
||||||
phone: userInfo?.userProfile,
|
|
||||||
}}
|
|
||||||
onFinish={handleInfoUpdate}
|
onFinish={handleInfoUpdate}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="用户名"
|
label="用户名"
|
||||||
name="userName"
|
name="username"
|
||||||
rules={[{ required: true }]}
|
rules={[{ required: true }]}
|
||||||
>
|
>
|
||||||
<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' }]}
|
||||||
>
|
>
|
||||||
<Input prefix={<MailOutlined />} disabled />
|
<Input prefix={<MailOutlined />} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{/* <Form.Item label="手机" name="phone">
|
<Form.Item label="手机" name="phone">
|
||||||
<Input prefix={<PhoneOutlined />} />
|
<Input prefix={<PhoneOutlined />} />
|
||||||
</Form.Item> */}
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Button type="primary" htmlType="submit" loading={loading}>
|
<Button type="primary" htmlType="submit">
|
||||||
保存修改
|
保存修改
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
||||||
|
<TabPane tab="账号安全" key="2">
|
||||||
|
<Card>
|
||||||
|
<Descriptions>
|
||||||
|
<Descriptions.Item label="账号密码">
|
||||||
|
已设置
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
onClick={() => setPasswordVisible(true)}
|
||||||
|
>
|
||||||
|
修改密码
|
||||||
|
</Button>
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="手机验证">已绑定</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="邮箱验证">已验证</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
</Card>
|
||||||
|
</TabPane>
|
||||||
|
|
||||||
<TabPane tab="使用统计" key="3">
|
<TabPane tab="使用统计" key="3">
|
||||||
<Card>
|
<Card>
|
||||||
<Descriptions column={2}>
|
<Descriptions column={2}>
|
||||||
<Descriptions.Item label="注册时间">
|
<Descriptions.Item label="注册时间">
|
||||||
{userInfo?.createTime ? dayjs(userInfo.createTime).format('YYYY-MM-DD HH:mm:ss') : '-'}
|
{currentUser?.registerTime || '-'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="最后登录">
|
<Descriptions.Item label="最后登录">
|
||||||
{userInfo?.updateTime ? dayjs(userInfo.updateTime).format('YYYY-MM-DD HH:mm:ss') : '-'}
|
{currentUser?.lastLogin || '-'}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="API调用次数">
|
<Descriptions.Item label="API调用次数">
|
||||||
{apiCallCount}
|
{currentUser?.apiCalls || 0}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="分析次数">
|
<Descriptions.Item label="分析次数">
|
||||||
{apiCallCount*2|| 0}
|
{currentUser?.analysisCounts || 0}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
</Card>
|
</Card>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user