feat(dcauth): 新增后台手机号与设备认证登录
登录链路改为账号密码 + 短信验证码 + DCAuth 设备签名,并新增后台手机号绑定、 登录日志、设备绑定与重置接口。
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Result,
|
||||
Select,
|
||||
Space,
|
||||
Switch,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
@@ -27,7 +28,10 @@ import {
|
||||
fetchAdminRolePermissions,
|
||||
fetchAdminUsers,
|
||||
resetAdminUserPassword,
|
||||
resetAdminUserDevice,
|
||||
updateAdminUserDisplayName,
|
||||
updateAdminUserPhone,
|
||||
updateAdminUserTestAccount,
|
||||
updateAdminUserRole,
|
||||
updateAdminUserStatus,
|
||||
updateAdminRolePermissions,
|
||||
@@ -53,6 +57,8 @@ type CreateUserForm = {
|
||||
username: string
|
||||
password: string
|
||||
role: AdminRole
|
||||
phone?: string
|
||||
testAccount?: boolean
|
||||
}
|
||||
|
||||
type DisplayNameForm = {
|
||||
@@ -129,6 +135,8 @@ export default function AdminUsersPage() {
|
||||
password: values.password.trim(),
|
||||
role: values.role,
|
||||
status: 'active',
|
||||
phone: values.phone?.trim() || '',
|
||||
testAccount: values.testAccount === true,
|
||||
})
|
||||
message.success('后台用户已创建')
|
||||
createForm.resetFields()
|
||||
@@ -293,6 +301,101 @@ export default function AdminUsersPage() {
|
||||
})
|
||||
}
|
||||
|
||||
function openBindPhoneModal(item: AdminUserListItem) {
|
||||
const form = ModalFormStore.create<{ phone: string }>()
|
||||
|
||||
modal.confirm({
|
||||
title: '绑定手机号',
|
||||
content: (
|
||||
<Form
|
||||
layout="vertical"
|
||||
preserve={false}
|
||||
initialValues={{ phone: item.phone || '' }}
|
||||
ref={form.bind}
|
||||
className="modal-form"
|
||||
>
|
||||
<Form.Item
|
||||
name="phone"
|
||||
label={`${displayNameOf(item)} 的登录手机号`}
|
||||
rules={[
|
||||
{ required: true, message: '请输入手机号' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的 11 位手机号' },
|
||||
]}
|
||||
extra="绑定后该账号必须使用账号密码 + 短信验证码 + 本机 DCAuth 登录"
|
||||
>
|
||||
<Input placeholder="11 位手机号" maxLength={11} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
),
|
||||
okText: '保存',
|
||||
cancelText: '取消',
|
||||
centered: true,
|
||||
onOk: async () => {
|
||||
const values = await form.validate()
|
||||
setActionLoadingId(item.userId)
|
||||
try {
|
||||
await updateAdminUserPhone(item.userId, { phone: values.phone.trim() })
|
||||
message.success('手机号已绑定')
|
||||
await reloadUsers()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '绑定手机号失败')
|
||||
} finally {
|
||||
setActionLoadingId(null)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function confirmResetDevice(item: AdminUserListItem) {
|
||||
if (!item.deviceBound) return
|
||||
modal.confirm({
|
||||
title: '重置设备绑定',
|
||||
content: `确认解除 ${displayNameOf(item)} 的当前设备吗?解绑后该账号需要重新完成首次设备绑定。`,
|
||||
okText: '确认解绑',
|
||||
cancelText: '取消',
|
||||
okButtonProps: { danger: true },
|
||||
centered: true,
|
||||
onOk: async () => {
|
||||
setActionLoadingId(item.userId)
|
||||
try {
|
||||
await resetAdminUserDevice(item.userId)
|
||||
message.success('设备绑定已重置')
|
||||
await reloadUsers()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '重置设备失败')
|
||||
} finally {
|
||||
setActionLoadingId(null)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function confirmToggleTestAccount(item: AdminUserListItem) {
|
||||
const next = !item.testAccount
|
||||
modal.confirm({
|
||||
title: next ? '设为技术测试账号' : '取消技术测试账号',
|
||||
content: next
|
||||
? `确认让 ${displayNameOf(item)} 跳过短信验证码和 DCAuth 设备验证,仅使用账号密码登录吗?仅建议用于技术测试。`
|
||||
: `确认恢复 ${displayNameOf(item)} 的完整安全登录流程吗?`,
|
||||
okText: next ? '设为测试账号' : '恢复正式账号',
|
||||
cancelText: '取消',
|
||||
okButtonProps: { danger: next },
|
||||
centered: true,
|
||||
onOk: async () => {
|
||||
setActionLoadingId(item.userId)
|
||||
try {
|
||||
await updateAdminUserTestAccount(item.userId, { testAccount: next })
|
||||
message.success(next ? '已设为技术测试账号' : '已恢复正式账号')
|
||||
await reloadUsers()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '更新测试账号设置失败')
|
||||
} finally {
|
||||
setActionLoadingId(null)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function applyFilters(values: UserFilterForm) {
|
||||
setSearchParams(cleanParams({ ...values, page: 1, pageSize }))
|
||||
}
|
||||
@@ -334,6 +437,33 @@ export default function AdminUsersPage() {
|
||||
minWidth: 140,
|
||||
render: (value: string) => <Typography.Text type="secondary">{value}</Typography.Text>,
|
||||
},
|
||||
{
|
||||
title: '手机号',
|
||||
dataIndex: 'phone',
|
||||
width: 150,
|
||||
render: (value: string) =>
|
||||
value ? (
|
||||
<Typography.Text>{value}</Typography.Text>
|
||||
) : (
|
||||
<Tag color="orange">未绑定</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '登录设备',
|
||||
dataIndex: 'deviceBound',
|
||||
width: 210,
|
||||
render: (_: boolean, row) =>
|
||||
row.deviceBound ? (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Typography.Text>{row.machineCodeMask || row.deviceIdMasked}</Typography.Text>
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
绑定于 {formatAdminDateTime(row.deviceBoundAt || '')}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
) : (
|
||||
<Tag>未绑定</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '角色',
|
||||
dataIndex: 'role',
|
||||
@@ -343,8 +473,13 @@ export default function AdminUsersPage() {
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 140,
|
||||
render: (value) => <StatusTag value={value} />,
|
||||
width: 170,
|
||||
render: (value, row) => (
|
||||
<Space wrap>
|
||||
<StatusTag value={value} />
|
||||
{row.testAccount ? <Tag color="purple">技术测试</Tag> : null}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
@@ -360,7 +495,7 @@ export default function AdminUsersPage() {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 390,
|
||||
width: 760,
|
||||
render: (_, row) => {
|
||||
const isCurrent = row.userId === currentUserId
|
||||
const roleMenuItems: MenuProps['items'] = USER_ROLE_OPTIONS.map((item) => ({
|
||||
@@ -377,6 +512,26 @@ export default function AdminUsersPage() {
|
||||
>
|
||||
改名
|
||||
</Button>
|
||||
<Button
|
||||
loading={actionLoadingId === row.userId}
|
||||
onClick={() => openBindPhoneModal(row)}
|
||||
>
|
||||
绑定手机号
|
||||
</Button>
|
||||
<Button
|
||||
disabled={!row.deviceBound}
|
||||
danger
|
||||
loading={actionLoadingId === row.userId}
|
||||
onClick={() => confirmResetDevice(row)}
|
||||
>
|
||||
重置设备
|
||||
</Button>
|
||||
<Button
|
||||
loading={actionLoadingId === row.userId}
|
||||
onClick={() => confirmToggleTestAccount(row)}
|
||||
>
|
||||
{row.testAccount ? '取消测试账号' : '设为测试账号'}
|
||||
</Button>
|
||||
<Dropdown
|
||||
disabled={isCurrent}
|
||||
menu={{
|
||||
@@ -412,7 +567,7 @@ export default function AdminUsersPage() {
|
||||
<section className="page-stack">
|
||||
<PageHeader
|
||||
title="后台用户"
|
||||
description="管理员可维护后台账号、姓名、角色和启停状态,避免继续使用单一口令。"
|
||||
description="管理员可维护后台账号、姓名、手机号、测试账号、角色、设备绑定和启停状态。"
|
||||
/>
|
||||
|
||||
<Card className="users-action-card">
|
||||
@@ -462,7 +617,7 @@ export default function AdminUsersPage() {
|
||||
<Form<CreateUserForm>
|
||||
form={createForm}
|
||||
layout="inline"
|
||||
initialValues={{ role: 'operator' }}
|
||||
initialValues={{ role: 'operator', testAccount: false }}
|
||||
onFinish={submitCreate}
|
||||
className="filter-form users-action-form"
|
||||
>
|
||||
@@ -470,20 +625,28 @@ export default function AdminUsersPage() {
|
||||
<Input placeholder="姓名(可中文)" className="users-input-md" maxLength={32} />
|
||||
</Form.Item>
|
||||
<Form.Item name="username" rules={[{ required: true, message: '请输入新账号' }]}>
|
||||
<Input placeholder="登录账号(英文/数字)" className="users-input-md" />
|
||||
<Input placeholder="登录账号(中文/英文/数字)" className="users-input-md" />
|
||||
</Form.Item>
|
||||
<Form.Item name="password" rules={[{ required: true, message: '请输入新密码' }, { min: 8, message: '密码至少 8 位' }]}>
|
||||
<Input.Password placeholder="新密码,至少 8 位" className="users-input-lg" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="password"
|
||||
name="phone"
|
||||
rules={[
|
||||
{ required: true, message: '请输入新密码' },
|
||||
{ min: 8, message: '密码至少 8 位' },
|
||||
{
|
||||
pattern: /^1[3-9]\d{9}$/,
|
||||
message: '请输入正确的 11 位手机号',
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input.Password placeholder="新密码,至少 8 位" className="users-input-lg" />
|
||||
<Input placeholder="绑定手机号(可选)" className="users-input-md" maxLength={11} />
|
||||
</Form.Item>
|
||||
<Form.Item name="role" rules={[{ required: true, message: '请选择角色' }]}>
|
||||
<Select options={USER_ROLE_OPTIONS} className="users-select-sm" />
|
||||
</Form.Item>
|
||||
<Form.Item name="testAccount" valuePropName="checked">
|
||||
<Switch checkedChildren="技术测试" unCheckedChildren="正式账号" />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" icon={<PlusOutlined />} loading={creating}>
|
||||
新增用户
|
||||
@@ -516,7 +679,7 @@ export default function AdminUsersPage() {
|
||||
columns={columns}
|
||||
dataSource={data?.items || []}
|
||||
locale={{ emptyText: <Empty description="暂无用户" /> }}
|
||||
scroll={{ x: 1220 }}
|
||||
scroll={{ x: 1680 }}
|
||||
pagination={buildAdminTablePagination({
|
||||
current: data?.pagination.page || page,
|
||||
pageSize: data?.pagination.pageSize || pageSize,
|
||||
|
||||
Reference in New Issue
Block a user