功能:完善登录安全与客服手动下单
This commit is contained in:
@@ -4,11 +4,15 @@ import { Outlet, useLocation, useNavigate } from 'react-router-dom'
|
||||
import {
|
||||
Layout,
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Space,
|
||||
Typography,
|
||||
Avatar,
|
||||
Tag,
|
||||
Button,
|
||||
message,
|
||||
Tooltip,
|
||||
} from 'antd'
|
||||
import {
|
||||
@@ -18,6 +22,7 @@ import {
|
||||
DashboardOutlined,
|
||||
DownOutlined,
|
||||
FileTextOutlined,
|
||||
KeyOutlined,
|
||||
LogoutOutlined,
|
||||
MenuOutlined,
|
||||
OrderedListOutlined,
|
||||
@@ -27,6 +32,7 @@ import {
|
||||
WalletOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { useAuth } from '../store/auth'
|
||||
import { authApi } from '../api'
|
||||
import type { MenuProps } from 'antd'
|
||||
|
||||
const { Header, Sider, Content } = Layout
|
||||
@@ -207,6 +213,9 @@ export default function MainLayout() {
|
||||
return localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === 'true'
|
||||
})
|
||||
const { user, logout, isAdmin, merchant, merchantPermissions } = useAuth()
|
||||
const [passwordOpen, setPasswordOpen] = useState(false)
|
||||
const [passwordSaving, setPasswordSaving] = useState(false)
|
||||
const [passwordForm] = Form.useForm()
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const isDocsPage = location.pathname.startsWith('/open-api')
|
||||
@@ -265,6 +274,25 @@ export default function MainLayout() {
|
||||
navigate(child.path)
|
||||
}
|
||||
|
||||
const submitPasswordChange = async () => {
|
||||
try {
|
||||
const values = await passwordForm.validateFields()
|
||||
setPasswordSaving(true)
|
||||
await authApi.changePassword({
|
||||
current_password: values.current_password,
|
||||
new_password: values.new_password,
|
||||
})
|
||||
setPasswordOpen(false)
|
||||
passwordForm.resetFields()
|
||||
logout()
|
||||
navigate('/login')
|
||||
} catch (e) {
|
||||
message.error(e instanceof Error ? e.message : '密码修改失败')
|
||||
} finally {
|
||||
setPasswordSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const userMenu: MenuProps['items'] = [
|
||||
{
|
||||
key: 'user-info',
|
||||
@@ -277,6 +305,12 @@ export default function MainLayout() {
|
||||
),
|
||||
},
|
||||
{ type: 'divider' },
|
||||
{
|
||||
key: 'change-password',
|
||||
icon: <KeyOutlined />,
|
||||
label: '修改密码',
|
||||
onClick: () => setPasswordOpen(true),
|
||||
},
|
||||
{
|
||||
key: 'logout',
|
||||
icon: <LogoutOutlined style={{ color: '#dc2626' }} />,
|
||||
@@ -412,6 +446,32 @@ export default function MainLayout() {
|
||||
<Outlet />
|
||||
</div>
|
||||
</Content>
|
||||
<Modal
|
||||
title="修改密码"
|
||||
open={passwordOpen}
|
||||
confirmLoading={passwordSaving}
|
||||
onOk={submitPasswordChange}
|
||||
onCancel={() => {
|
||||
setPasswordOpen(false)
|
||||
passwordForm.resetFields()
|
||||
}}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={passwordForm} layout="vertical" style={{ marginTop: 16 }}>
|
||||
<Form.Item name="current_password" label="当前密码" rules={[{ required: true, message: '请输入当前密码' }]}>
|
||||
<Input.Password autoComplete="current-password" />
|
||||
</Form.Item>
|
||||
<Form.Item name="new_password" label="新密码" rules={[{ required: true, min: 8, message: '新密码至少 8 位' }]}>
|
||||
<Input.Password autoComplete="new-password" />
|
||||
</Form.Item>
|
||||
<Form.Item name="confirm_password" label="确认新密码" dependencies={['new_password']} rules={[
|
||||
{ required: true, message: '请再次输入新密码' },
|
||||
({ getFieldValue }) => ({ validator: (_, value) => !value || getFieldValue('new_password') === value ? Promise.resolve() : Promise.reject(new Error('两次输入的密码不一致')) }),
|
||||
]}>
|
||||
<Input.Password autoComplete="new-password" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Layout>
|
||||
</Layout>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user