feat: 1:优化token查询页 2:用户管理页面新增修改密码功能 3:调整景区与二维码关系
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import { Modal, Popconfirm, Space, Tag, message } from 'antd';
|
||||
import { ProTable, type ActionType } from '@ant-design/pro-components';
|
||||
import { GradientButton } from '@/components/ui';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import QrcodeForm, { QrcodeItem } from '../../Qrcode/components/QrcodeForm';
|
||||
|
||||
export interface QrcodeListModalProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
tourismId: number;
|
||||
tourismName?: string;
|
||||
}
|
||||
|
||||
const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, tourismId, tourismName }) => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<QrcodeItem | undefined>(undefined);
|
||||
|
||||
const title = useMemo(
|
||||
() => `打卡点二维码列表${tourismName ? `(${tourismName})` : ''}`,
|
||||
[tourismName],
|
||||
);
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 56 },
|
||||
{ title: '名称', dataIndex: 'name' },
|
||||
{ title: '链接', dataIndex: 'url', ellipsis: true },
|
||||
{ title: '类型', dataIndex: 'type' },
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: (v: number) => (
|
||||
<Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 160,
|
||||
render: (_: any, record: QrcodeItem) => (
|
||||
<Space>
|
||||
<a
|
||||
onClick={() => {
|
||||
setCurrent(record);
|
||||
setEditOpen(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>
|
||||
<Popconfirm
|
||||
title={`确认删除二维码【${record.name}】?`}
|
||||
onConfirm={async () => {
|
||||
const hide = message.loading('正在删除...');
|
||||
try {
|
||||
await ordersApi.deleteQrcode(record.id!);
|
||||
message.success('删除成功');
|
||||
actionRef.current?.reload();
|
||||
} catch (e) {
|
||||
message.error('删除失败');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<a style={{ color: '#1677ff' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
title={title}
|
||||
open={open}
|
||||
onCancel={() => onOpenChange(false)}
|
||||
footer={null}
|
||||
width={1000}
|
||||
destroyOnClose
|
||||
>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<GradientButton
|
||||
size="middle"
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
新增
|
||||
</GradientButton>
|
||||
</div>
|
||||
|
||||
<ProTable<QrcodeItem>
|
||||
rowKey="id"
|
||||
actionRef={actionRef}
|
||||
request={(p) => ordersApi.qrcodeListByTourism({ ...(p as any), tourismId })}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
toolBarRender={false}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
{/* 新增二维码 */}
|
||||
<QrcodeForm
|
||||
title="新增二维码"
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateQrcode({ ...values, tourismId });
|
||||
message.success('新增成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 编辑二维码 */}
|
||||
<QrcodeForm
|
||||
title="编辑二维码"
|
||||
open={editOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateQrcode({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default QrcodeListModal;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import React from 'react';
|
||||
import { ModalForm, ProFormText } from '@ant-design/pro-components';
|
||||
import type { UserItem } from '@/services/system';
|
||||
|
||||
export interface ChangePasswordModalProps {
|
||||
visible: boolean;
|
||||
user?: UserItem;
|
||||
onVisibleChange: (v: boolean) => void;
|
||||
onFinish: (values: { newPassword: string; confirmPassword: string }) => Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码弹窗(支持管理员为任意用户设置新密码)
|
||||
*/
|
||||
const ChangePasswordModal: React.FC<ChangePasswordModalProps> = ({ visible, user, onVisibleChange, onFinish }) => {
|
||||
return (
|
||||
<ModalForm<{ newPassword: string; confirmPassword: string }>
|
||||
title={`修改密码${user?.username ? ` - ${user.username}` : ''}`}
|
||||
visible={visible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
onFinish={onFinish}
|
||||
>
|
||||
<ProFormText
|
||||
name="newPassword"
|
||||
label="新密码"
|
||||
fieldProps={{ type: 'password', autoComplete: 'new-password' }}
|
||||
rules={[
|
||||
{ required: true, message: '请输入新密码' },
|
||||
{ min: 6, message: '密码长度不能少于6位' },
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="confirmPassword"
|
||||
label="确认新密码"
|
||||
fieldProps={{ type: 'password', autoComplete: 'new-password' }}
|
||||
rules={[
|
||||
{ required: true, message: '请再次输入新密码' },
|
||||
({ getFieldValue }) => ({
|
||||
validator(_, value) {
|
||||
if (!value || getFieldValue('newPassword') === value) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(new Error('两次输入的密码不一致'));
|
||||
},
|
||||
}),
|
||||
]}
|
||||
/>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChangePasswordModal;
|
||||
|
||||
Reference in New Issue
Block a user