import { PageContainer, ProForm, ProFormText, } from '@ant-design/pro-components'; import { history, useAccess } from '@umijs/max'; import { App, Button, Card, Col, Descriptions, type DescriptionsProps, Row, Space, Tag, Typography, } from 'antd'; import React, { useEffect } from 'react'; import { clearAccessToken } from '@/access'; import PasswordLevel from '@/components/PasswordLevel'; import useUserInfo from '@/hooks/useUserInfo'; import { changeUserPass } from '@/services/api'; import { $t } from '@/utils/i18n'; const { Text } = Typography; const Profile: React.FC = () => { const { userInfo, setUserInfo } = useUserInfo(); const { isGlobalCompany } = useAccess(); const userCompany = userInfo?.company; const { message: antdMessage, modal } = App.useApp(); const roleList = () => { return ( {userInfo?.roleList?.map((item) => ( {item?.mark || '-'} )) || '-'} ); }; const items: DescriptionsProps['items'] = [ { key: '1', span: 'filled', label: $t('form.user.displayName'), children: userInfo?.nickName || '-', }, { key: '2', span: 'filled', label: $t('table.username'), children: userInfo?.username || '-', }, { key: '3', span: 'filled', label: $t('form.user.email'), children: userInfo?.email || '-', }, { key: '4', span: 'filled', label: $t('table.role'), children: roleList(), }, { key: '5', span: 'filled', label: $t('table.company'), children: userCompany?.name || '-', }, ]; useEffect(() => { if (!isGlobalCompany) { items.push({ key: '6', span: 'filled', label: $t('table.validityEndTime'), children: userCompany?.validityEndTime ? ( {userCompany.validityEndTime} {userCompany?.validityStatus === 2 && ( {$t('pages.company.expired')} )} ) : ( $t('pages.company.permanent') ), }); } }, [userCompany, isGlobalCompany]); const changePasswordSuccessHadle = async () => { let countdown = 5; let timer: NodeJS.Timeout | null = null; const modalData = { title: $t('pages.changePasswordSuccess'), okText: `${$t('pages.goLogin')}(${countdown}S)`, centered: true, onOk: () => { history.replace('/login'); instance.destroy(); }, }; const instance = modal.info({ ...modalData, }); timer = setInterval(() => { countdown--; instance.update({ okText: `${$t('pages.goLogin')}(${countdown}S)`, }); if (countdown <= 0) { if (timer) { clearInterval(timer); timer = null; history.replace('/login'); instance.destroy(); } } }, 1000); clearAccessToken(); setUserInfo(undefined); localStorage.removeItem('changePassTimestamp'); }; return ( { const { code, message } = await changeUserPass(values); if (code === 200) { await changePasswordSuccessHadle(); } else { antdMessage.error(message); } }} submitter={{ render: () => { return [ , ]; }, }} > e.target.value.trim()} /> } getValueFromEvent={(e) => e.target.value.trim()} /> e.target.value.trim()} rules={[ { required: true, message: $t('form.required') }, ({ getFieldValue }) => ({ validator(_, value) { if (!value || getFieldValue('newPassword') === value) { return Promise.resolve(); } return Promise.reject( new Error($t('form.password.passwordNotMatch')), ); }, }), ]} /> ); }; export default Profile;