|
@@ -1,13 +1,11 @@
|
|
|
-import {Divider, message, Modal, Tooltip} from 'antd';
|
|
|
+import {Button, Divider, Input, message, Modal, Radio} from 'antd';
|
|
|
import React, {useRef, useState} from 'react';
|
|
|
import {PageHeaderWrapper} from '@ant-design/pro-layout';
|
|
|
import ProTable, {ActionType, ProColumns} from '@ant-design/pro-table';
|
|
|
import {SorterResult} from 'antd/es/table/interface';
|
|
|
+import {ExclamationCircleOutlined, PlusOutlined} from "@ant-design/icons/lib";
|
|
|
import {TableListItem} from './data.d';
|
|
|
import service from './service';
|
|
|
-import UpdateForm from "@/pages/Memory/components/UpdateForm";
|
|
|
-import {getTextFromHtml, minuteToDay} from "@/utils/utils";
|
|
|
-import {ExclamationCircleOutlined} from "@ant-design/icons/lib";
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -17,28 +15,81 @@ import {ExclamationCircleOutlined} from "@ant-design/icons/lib";
|
|
|
const handleRemove = async (fields: TableListItem) => {
|
|
|
const hide = message.loading('正在删除');
|
|
|
try {
|
|
|
- await service.delete(fields);
|
|
|
+ const res = await service.delete(fields);
|
|
|
+ if (res.success) {
|
|
|
+ message.success('删除成功,即将刷新');
|
|
|
+ } else {
|
|
|
+ message.error('删除失败,请重试');
|
|
|
+ }
|
|
|
hide();
|
|
|
- message.success('删除成功,即将刷新');
|
|
|
- return true;
|
|
|
+ return res.success;
|
|
|
} catch (error) {
|
|
|
hide();
|
|
|
message.error('删除失败,请重试');
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
+/**
|
|
|
+ * 添加节点
|
|
|
+ * @param fields
|
|
|
+ */
|
|
|
+const handleAdd = async (fields: TableListItem) => {
|
|
|
+ const hide = message.loading('正在添加');
|
|
|
+ try {
|
|
|
+ const res = await service.register({...fields});
|
|
|
+ hide();
|
|
|
+ if (res.success) {
|
|
|
+ message.success('添加成功');
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ message.error('添加失败请重试!');
|
|
|
+ return false;
|
|
|
|
|
|
+ } catch (error) {
|
|
|
+ hide();
|
|
|
+ message.error('添加失败请重试!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 更新节点
|
|
|
+ * @param fields
|
|
|
+ */
|
|
|
+const handleUpdate = async (fields: TableListItem) => {
|
|
|
+ const hide = message.loading('正在配置');
|
|
|
+ try {
|
|
|
+ const res = await service.update(fields);
|
|
|
+ hide();
|
|
|
+ if (res.success) {
|
|
|
+ message.success('配置成功');
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ message.error('配置失败请重试!');
|
|
|
+ return false;
|
|
|
+ } catch (error) {
|
|
|
+ hide();
|
|
|
+ message.error('配置失败请重试!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
|
|
|
const TableList: React.FC<{}> = () => {
|
|
|
const [sorter, setSorter] = useState<string>('');
|
|
|
const [modelVisible, setModalVisible] = useState<boolean>(false);
|
|
|
+
|
|
|
const [formValues, setFormValues] = useState({});
|
|
|
const actionRef = useRef<ActionType>();
|
|
|
|
|
|
- const { confirm } = Modal;
|
|
|
+ // 重置表单
|
|
|
+ const [resetVisible, setResetVisible] = useState<boolean>(false);
|
|
|
+ const [resetLoading, setResetLoading] = useState<boolean>(false);
|
|
|
+ const [newPassword, setNewPassword] = useState<string>('');
|
|
|
|
|
|
- const deleteMemory = async (record:any) => {
|
|
|
+ const {confirm} = Modal;
|
|
|
+
|
|
|
+ const deleteMemory = async (record: any) => {
|
|
|
await handleRemove(record);
|
|
|
if (actionRef.current) {
|
|
|
actionRef.current.reload();
|
|
@@ -48,67 +99,67 @@ const TableList: React.FC<{}> = () => {
|
|
|
|
|
|
const columns: ProColumns<TableListItem>[] = [
|
|
|
{
|
|
|
- title: '正面',
|
|
|
- dataIndex: 'front',
|
|
|
- width: 150,
|
|
|
- hideInSearch: true,
|
|
|
- render: (text, row) => {
|
|
|
- const show = getTextFromHtml(row.front);
|
|
|
- return (<>
|
|
|
- <Tooltip title={show}>
|
|
|
- <span>{show.substring(0, 10)}</span>
|
|
|
- </Tooltip>
|
|
|
- </>);
|
|
|
- }
|
|
|
+ title: '用户名',
|
|
|
+ dataIndex: 'userName',
|
|
|
+ width: 100,
|
|
|
+ hideInSearch: false,
|
|
|
},
|
|
|
{
|
|
|
- title: '背面',
|
|
|
- dataIndex: 'back',
|
|
|
- width: 150,
|
|
|
+ title: '性别',
|
|
|
+ dataIndex: 'gender',
|
|
|
+ width: 50,
|
|
|
hideInSearch: true,
|
|
|
- render: (text, row) => {
|
|
|
- const show = getTextFromHtml(row.back);
|
|
|
- return (<>
|
|
|
- <Tooltip title={show}>
|
|
|
- <span>{show.substring(0, 10)}</span>
|
|
|
- </Tooltip>
|
|
|
- </>);
|
|
|
- }
|
|
|
+ renderFormItem: () => {
|
|
|
+ return (
|
|
|
+ <Radio.Group>
|
|
|
+ <Radio value="0">女</Radio>
|
|
|
+ <Radio value='1'>男</Radio>
|
|
|
+ </Radio.Group>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ valueEnum: {
|
|
|
+ '0': {text: '女'},
|
|
|
+ '1': {text: '男'}
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
- title: '间隔时间',
|
|
|
- dataIndex: 'period',
|
|
|
- width: 100,
|
|
|
+ title: '年龄',
|
|
|
+ dataIndex: 'age',
|
|
|
+ width: 50,
|
|
|
hideInSearch: true,
|
|
|
- hideInForm: true,
|
|
|
- render: (text, row) => {
|
|
|
- return (<>
|
|
|
- <span>{minuteToDay(row.period)}</span>
|
|
|
- </>);
|
|
|
- }
|
|
|
},
|
|
|
{
|
|
|
- title: '提醒时间',
|
|
|
- dataIndex: 'remindTime',
|
|
|
- valueType: 'dateTime',
|
|
|
- width: 150,
|
|
|
+ title: '手机号',
|
|
|
+ dataIndex: 'phone',
|
|
|
+ width: 80,
|
|
|
hideInSearch: true,
|
|
|
- hideInForm: true,
|
|
|
- sorter:true
|
|
|
},
|
|
|
{
|
|
|
- title: '更新时间',
|
|
|
- dataIndex: 'updateTime',
|
|
|
- valueType: 'dateTime',
|
|
|
- width: 150,
|
|
|
- hideInSearch: true,
|
|
|
- hideInForm: true,
|
|
|
- sorter:true
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ width: 80,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '角色',
|
|
|
+ dataIndex: 'roleId',
|
|
|
+ width: 80,
|
|
|
+ renderFormItem: () => {
|
|
|
+ return (
|
|
|
+ <Radio.Group>
|
|
|
+ <Radio value={1}>管理员</Radio>
|
|
|
+ <Radio value={2}>普通用户</Radio>
|
|
|
+ </Radio.Group>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ valueEnum: {
|
|
|
+ 1: {text: '管理员'},
|
|
|
+ 2: {text: '普通用户'}
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
title: '操作',
|
|
|
dataIndex: 'option',
|
|
|
- width: 100,
|
|
|
+ width: 150,
|
|
|
valueType: 'option',
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
render: (_, record, index, action) => (
|
|
@@ -126,7 +177,7 @@ const TableList: React.FC<{}> = () => {
|
|
|
onClick={async () => {
|
|
|
confirm({
|
|
|
title: '确定删除吗?',
|
|
|
- icon: <ExclamationCircleOutlined />,
|
|
|
+ icon: <ExclamationCircleOutlined/>,
|
|
|
content: '删除后无法恢复',
|
|
|
okText: '确定',
|
|
|
okType: 'danger',
|
|
@@ -142,6 +193,15 @@ const TableList: React.FC<{}> = () => {
|
|
|
>
|
|
|
删除
|
|
|
</a>
|
|
|
+ <Divider type="vertical"/>
|
|
|
+ <a
|
|
|
+ onClick={() => {
|
|
|
+ setFormValues(record);
|
|
|
+ setResetVisible(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 重置密码
|
|
|
+ </a>
|
|
|
</>
|
|
|
),
|
|
|
},
|
|
@@ -150,7 +210,7 @@ const TableList: React.FC<{}> = () => {
|
|
|
return (
|
|
|
<PageHeaderWrapper title={false}>
|
|
|
<ProTable<TableListItem>
|
|
|
- search={false}
|
|
|
+ // search={false}
|
|
|
headerTitle="查询表格"
|
|
|
actionRef={actionRef}
|
|
|
rowKey="id"
|
|
@@ -160,6 +220,7 @@ const TableList: React.FC<{}> = () => {
|
|
|
setSorter(`${sorterResult.field}_${sorterResult.order}`);
|
|
|
}
|
|
|
}}
|
|
|
+
|
|
|
pagination={{
|
|
|
defaultPageSize: 10,
|
|
|
}}
|
|
@@ -178,18 +239,57 @@ const TableList: React.FC<{}> = () => {
|
|
|
columns={columns}
|
|
|
rowSelection={{}}
|
|
|
/>
|
|
|
- {modelVisible ? (
|
|
|
- <UpdateForm
|
|
|
- onCancel={(refresh) => {
|
|
|
- setModalVisible(false);
|
|
|
- if (refresh && actionRef.current) {
|
|
|
- actionRef.current.reload();
|
|
|
+
|
|
|
+ <Modal
|
|
|
+ title="重置密码"
|
|
|
+ visible={resetVisible}
|
|
|
+ onOk={ async ()=>{
|
|
|
+ setResetLoading(true);
|
|
|
+ let res = await service.forceUpdatePassword({user_Id: formValues['id'], newPassword: newPassword});
|
|
|
+ if (res.success) {
|
|
|
+ message.success("修改成功");
|
|
|
+ setResetVisible(false);
|
|
|
+ } else {
|
|
|
+ message.error("修改失败");
|
|
|
+ }
|
|
|
+ setResetLoading(false);
|
|
|
+ }}
|
|
|
+ confirmLoading={resetLoading}
|
|
|
+ onCancel={()=>{setResetVisible(false)}}
|
|
|
+ >
|
|
|
+ <Input placeholder="新密码" value={newPassword} onChange={(e)=>setNewPassword(e.target.value)} />
|
|
|
+ </Modal>
|
|
|
+
|
|
|
+ <Modal
|
|
|
+ destroyOnClose
|
|
|
+ title={'id' in formValues ? '编辑' : '新建'}
|
|
|
+ visible={modelVisible}
|
|
|
+ onCancel={() => setModalVisible(false)}
|
|
|
+ footer={null}
|
|
|
+ >
|
|
|
+ <ProTable<TableListItem, TableListItem>
|
|
|
+ onSubmit={async (value) => {
|
|
|
+ let success = false;
|
|
|
+ if ('id' in formValues) {
|
|
|
+ value['id'] = formValues['id']
|
|
|
+ success = await handleUpdate(value);
|
|
|
+ } else {
|
|
|
+ success = await handleAdd(value);
|
|
|
+ }
|
|
|
+ if (success) {
|
|
|
+ setModalVisible(false);
|
|
|
+ if (actionRef.current) {
|
|
|
+ actionRef.current.reload();
|
|
|
+ }
|
|
|
}
|
|
|
}}
|
|
|
- modalVisible={modelVisible}
|
|
|
- values={formValues}>
|
|
|
- </UpdateForm>
|
|
|
- ) : null}
|
|
|
+ rowKey="id"
|
|
|
+ type="form"
|
|
|
+ columns={columns}
|
|
|
+ rowSelection={{}}
|
|
|
+ form={{initialValues: formValues}}
|
|
|
+ />
|
|
|
+ </Modal>
|
|
|
|
|
|
</PageHeaderWrapper>
|
|
|
);
|