diff --git a/react-ui/src/app.tsx b/react-ui/src/app.tsx index 1dca4371..c0ea08c5 100644 --- a/react-ui/src/app.tsx +++ b/react-ui/src/app.tsx @@ -37,8 +37,7 @@ export async function getInitialState(): Promise { ...response.user, avatar: response.user.avatar || require('@/assets/img/avatar-default.png'), permissions: response.permissions, - roles: response.roles, - roleNames: response.user.roles, + roleNames: response.roles, } as API.CurrentUser; } catch (error) { console.error('getInitialState', error); diff --git a/react-ui/src/components/RightContent/AvatarDropdown.tsx b/react-ui/src/components/RightContent/AvatarDropdown.tsx index f36ccf09..55e11bf1 100644 --- a/react-ui/src/components/RightContent/AvatarDropdown.tsx +++ b/react-ui/src/components/RightContent/AvatarDropdown.tsx @@ -1,4 +1,5 @@ import { clearSessionToken } from '@/access'; +import DefaultAvatar from '@/assets/img/avatar-default.png'; import { getLabelStudioUrl } from '@/services/developmentEnvironment'; import { setRemoteMenu } from '@/services/session'; import { logout } from '@/services/system/auth'; @@ -56,7 +57,14 @@ const AvatarLogo = () => { }, }; }); - return ; + return ( + + ); }; const AvatarDropdown: React.FC = ({ menu }) => { diff --git a/react-ui/src/pages/User/Center/components/BaseInfo/index.tsx b/react-ui/src/pages/User/Center/components/BaseInfo/index.tsx index 7e95caae..ab43794b 100644 --- a/react-ui/src/pages/User/Center/components/BaseInfo/index.tsx +++ b/react-ui/src/pages/User/Center/components/BaseInfo/index.tsx @@ -1,91 +1,107 @@ +import KFModal from '@/components/KFModal'; import { updateUserProfile } from '@/services/system/user'; -import { ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components'; -import { FormattedMessage, useIntl } from '@umijs/max'; -import { Form, message, Row } from 'antd'; +import { to } from '@/utils/promise'; +import { Form, Input, message, Radio } from 'antd'; import React from 'react'; export type BaseInfoProps = { - values: Partial | undefined; + values: Partial; + open: boolean; + onFinished?: (isSuccess: boolean) => void; }; -const BaseInfo: React.FC = (props) => { +const BaseInfo: React.FC = ({ open, onFinished, values: initialValues }) => { const [form] = Form.useForm(); - const intl = useIntl(); - const handleFinish = async (values: Record) => { - const data = { ...props.values, ...values } as API.CurrentUser; - const resp = await updateUserProfile(data); - if (resp.code === 200) { + const handleFinish = async (formData: Record) => { + const data = { userId: initialValues.userId, ...formData } as API.CurrentUser; + const [res] = await to(updateUserProfile(data)); + if (res) { message.success('修改成功'); - } else { - message.warning(resp.msg); + onFinished?.(true); } }; return ( - <> - - - - ), - }, - ]} - /> - - - - ), - }, - ]} - /> - - - , - }, - ]} - /> - - - onFinished?.(false)} + destroyOnClose + > +
+ + + + + + + + + + + + + + = (props) => { value: '1', }, ]} - name="sex" - label={intl.formatMessage({ - id: 'system.user.sex', - defaultMessage: 'sex', - })} - width="xl" - rules={[ - { - required: false, - message: , - }, - ]} /> - - - + +
+ ); }; diff --git a/react-ui/src/pages/User/Center/components/ResetPassword/index.tsx b/react-ui/src/pages/User/Center/components/ResetPassword/index.tsx index bdc4da5f..cbc93ba4 100644 --- a/react-ui/src/pages/User/Center/components/ResetPassword/index.tsx +++ b/react-ui/src/pages/User/Center/components/ResetPassword/index.tsx @@ -1,81 +1,89 @@ +import KFModal from '@/components/KFModal'; import { updateUserPwd } from '@/services/system/user'; -import { ProForm, ProFormText } from '@ant-design/pro-components'; -import { FormattedMessage, useIntl } from '@umijs/max'; -import { Form, message } from 'antd'; -import React from 'react'; +import { to } from '@/utils/promise'; +import { Form, Input, message } from 'antd'; -const ResetPassword: React.FC = () => { +export type ResetPasswordProps = { + open: boolean; + onFinished?: (isSuccess: boolean) => void; +}; + +const ResetPassword = ({ open, onFinished }: ResetPasswordProps) => { const [form] = Form.useForm(); - const intl = useIntl(); const handleFinish = async (values: Record) => { - const resp = await updateUserPwd(values.oldPassword, values.newPassword); - if (resp.code === 200) { - message.success('密码重置成功。'); - } else { - message.warning(resp.msg); + const [res] = await to(updateUserPwd(values.oldPassword, values.newPassword)); + if (res) { + message.success('密码重置成功'); + onFinished?.(true); } }; const checkPassword = (_rule: any, value: string) => { const login_password = form.getFieldValue('newPassword'); - if (value === login_password) { - return Promise.resolve(); + if (!value) { + return Promise.reject(new Error('请输入确认密码')); + } else if (value !== login_password) { + return Promise.reject(new Error('两次密码输入不一致')); } - return Promise.reject(new Error('两次密码输入不一致')); + return Promise.resolve(); }; return ( - <> - - onFinished?.(false)} + destroyOnClose + > +
+ , + message: '请输入旧密码', }, ]} - /> - + + + , + message: '请输入新密码', }, ]} - /> - + + + , - }, - { validator: checkPassword }, - ]} - /> - - + label="确认密码" + required + rules={[{ validator: checkPassword }]} + > + + +
+ ); }; diff --git a/react-ui/src/pages/User/Center/Center.less b/react-ui/src/pages/User/Center/index.less similarity index 53% rename from react-ui/src/pages/User/Center/Center.less rename to react-ui/src/pages/User/Center/index.less index df81b500..5897ca51 100644 --- a/react-ui/src/pages/User/Center/Center.less +++ b/react-ui/src/pages/User/Center/index.less @@ -2,7 +2,7 @@ position: relative; display: inline-block; height: 120px; - margin-bottom: 16px; + margin-bottom: 30px; text-align: center; & > img { @@ -30,31 +30,34 @@ } } -.teamTitle { - margin-bottom: 12px; - color: @heading-color; - font-weight: 500; -} +.user-center { + height: calc(100% - 50px - 120px); + padding: 30px; + background: white; + border-radius: 8px; + width: 50%; + margin: 60px auto 0; + display: flex; + flex-direction: column; + align-items: center; + overflow-y: auto; -.team { :global { - .ant-avatar { - margin-right: 12px; + .ant-list { + width: 100%; + + .ant-list-item { + height: 80px; + border-block-end: 1px solid rgba(5, 5, 5, 0.06); + font-size: 16px; + } } } - a { - display: block; - margin-bottom: 24px; - overflow: hidden; - color: @text-color; - white-space: nowrap; - text-overflow: ellipsis; - word-break: break-all; - transition: color 0.3s; - - &:hover { - color: @primary-color; - } + &__buttons { + display: flex; + align-items: center; + margin-top: 60px; + flex-direction: row; } } diff --git a/react-ui/src/pages/User/Center/index.tsx b/react-ui/src/pages/User/Center/index.tsx index 2e38a984..dbc0f812 100644 --- a/react-ui/src/pages/User/Center/index.tsx +++ b/react-ui/src/pages/User/Center/index.tsx @@ -1,6 +1,9 @@ -import { getUserInfo } from '@/services/session'; +import DefaultAvatar from '@/assets/img/avatar-default.png'; +import PageTitle from '@/components/PageTitle'; +import { to } from '@/utils/promise'; import { ClusterOutlined, + HeartOutlined, MailOutlined, ManOutlined, MobileOutlined, @@ -8,45 +11,52 @@ import { UserOutlined, } from '@ant-design/icons'; import { PageLoading } from '@ant-design/pro-components'; -import { useRequest } from '@umijs/max'; -import { Card, Col, Divider, List, Row } from 'antd'; -import React, { useState } from 'react'; -import styles from './Center.less'; +import { useModel } from '@umijs/max'; +import { List } from 'antd'; +import { useCallback, useState } from 'react'; +import { flushSync } from 'react-dom'; import AvatarCropper from './components/AvatarCropper'; -import BaseInfo from './components/BaseInfo'; -import ResetPassword from './components/ResetPassword'; +import BaseInfoModal from './components/BaseInfo'; +import ResetPasswordModal from './components/ResetPassword'; +import styles from './index.less'; -const operationTabList = [ - { - key: 'base', - tab: 基本资料, - }, - { - key: 'password', - tab: 重置密码, - }, -]; +const Center = () => { + const [cropperModalOpen, setCropperModalOpen] = useState(false); + const [infoModalOpen, setInfoModalOpen] = useState(false); + const [resetModalOpen, setRestModalOpen] = useState(false); -export type tabKeyType = 'base' | 'password'; + const { initialState, setInitialState } = useModel('@@initialState'); + const { currentUser, fetchUserInfo } = initialState || {}; -const Center: React.FC = () => { - const [tabKey, setTabKey] = useState('base'); + const refreshUserInfo = useCallback(async () => { + if (fetchUserInfo) { + const [res] = await to(fetchUserInfo()); + if (res) { + flushSync(() => { + setInitialState((s) => ({ ...s, currentUser: res })); + }); + } + } + }, [setInitialState, fetchUserInfo]); - const [cropperModalOpen, setCropperModalOpen] = useState(false); + const handleBaseInfoChange = (success: boolean) => { + setInfoModalOpen(false); - // 获取用户信息 - const { data: userInfo, loading } = useRequest(async () => { - return { data: await getUserInfo() }; - }); - if (loading) { - return
loading...
; - } + if (success) { + refreshUserInfo(); + } + }; - const currentUser = userInfo?.user; + const handleResetPassword = (success: boolean) => { + setRestModalOpen(false); + if (success) { + } + }; // 渲染用户信息 const renderUserInfo = ({ userName, + nickName, phonenumber, email, sex, @@ -65,6 +75,17 @@ const Center: React.FC = () => {
{userName}
+ +
+ + 昵称 +
+
{nickName}
+
{
{dept?.deptName}
+ +
+ + 角色 +
+
{currentUser?.roles?.map((item: any) => item.roleName)?.join(',')}
+
); }; - // 渲染tab切换 - const renderChildrenByTabKey = (tabValue: tabKeyType) => { - if (tabValue === 'base') { - return ; - } - if (tabValue === 'password') { - return ; - } - return null; - }; - if (!currentUser) { return ; } return ( -
- - - - {!loading && ( -
-
{ - setCropperModalOpen(true); - }} - > - -
- {renderUserInfo(currentUser)} - -
-
角色
- - {currentUser.roles && - currentUser.roles.map((item: any) => ( - - - {item.roleName} - - ))} - -
-
- )} -
- - - { - setTabKey(_tabKey as tabKeyType); - }} +
+ +
+
{ + setCropperModalOpen(true); + }} + > + +
+ {renderUserInfo(currentUser)} + {/*
+ + +
*/} +
+ { setCropperModalOpen(false); @@ -185,6 +184,17 @@ const Center: React.FC = () => { open={cropperModalOpen} data={currentUser.avatar} /> + + + +
); }; diff --git a/react-ui/src/pages/Workspace/components/UserSpace/index.tsx b/react-ui/src/pages/Workspace/components/UserSpace/index.tsx index dcfa7698..69a868df 100644 --- a/react-ui/src/pages/Workspace/components/UserSpace/index.tsx +++ b/react-ui/src/pages/Workspace/components/UserSpace/index.tsx @@ -31,7 +31,7 @@ function UserSpace({ users = [] }: UserSpaceProps) { } >
{currentUser?.nickName}
-
{currentUser?.roleNames?.[0]?.roleName}
+
{currentUser?.roles?.[0]?.roleName}