|
@@ -0,0 +1,198 @@
|
|
|
+import {Divider, message, Modal, Tooltip} 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 {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";
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 删除节点
|
|
|
+ * @param fields
|
|
|
+ */
|
|
|
+const handleRemove = async (fields: TableListItem) => {
|
|
|
+ const hide = message.loading('正在删除');
|
|
|
+ try {
|
|
|
+ await service.delete(fields);
|
|
|
+ hide();
|
|
|
+ message.success('删除成功,即将刷新');
|
|
|
+ return true;
|
|
|
+ } 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 deleteMemory = async (record:any) => {
|
|
|
+ await handleRemove(record);
|
|
|
+ if (actionRef.current) {
|
|
|
+ actionRef.current.reload();
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ 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: 'back',
|
|
|
+ width: 150,
|
|
|
+ hideInSearch: true,
|
|
|
+ render: (text, row) => {
|
|
|
+ const show = getTextFromHtml(row.back);
|
|
|
+ return (<>
|
|
|
+ <Tooltip title={show}>
|
|
|
+ <span>{show.substring(0, 10)}</span>
|
|
|
+ </Tooltip>
|
|
|
+ </>);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '间隔时间',
|
|
|
+ dataIndex: 'period',
|
|
|
+ width: 100,
|
|
|
+ hideInSearch: true,
|
|
|
+ hideInForm: true,
|
|
|
+ render: (text, row) => {
|
|
|
+ return (<>
|
|
|
+ <span>{minuteToDay(row.period)}</span>
|
|
|
+ </>);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '提醒时间',
|
|
|
+ dataIndex: 'remindTime',
|
|
|
+ valueType: 'dateTime',
|
|
|
+ width: 150,
|
|
|
+ hideInSearch: true,
|
|
|
+ hideInForm: true,
|
|
|
+ sorter:true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '更新时间',
|
|
|
+ dataIndex: 'updateTime',
|
|
|
+ valueType: 'dateTime',
|
|
|
+ width: 150,
|
|
|
+ hideInSearch: true,
|
|
|
+ hideInForm: true,
|
|
|
+ sorter:true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'option',
|
|
|
+ width: 100,
|
|
|
+ valueType: 'option',
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
+ render: (_, record, index, action) => (
|
|
|
+ <>
|
|
|
+ <a
|
|
|
+ onClick={() => {
|
|
|
+ setFormValues(record);
|
|
|
+ setModalVisible(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 修改
|
|
|
+ </a>
|
|
|
+ <Divider type="vertical"/>
|
|
|
+ <a
|
|
|
+ onClick={async () => {
|
|
|
+ confirm({
|
|
|
+ title: '确定删除吗?',
|
|
|
+ icon: <ExclamationCircleOutlined />,
|
|
|
+ content: '删除后无法恢复',
|
|
|
+ okText: '确定',
|
|
|
+ okType: 'danger',
|
|
|
+ cancelText: '取消',
|
|
|
+ onOk() {
|
|
|
+ deleteMemory(record);
|
|
|
+ },
|
|
|
+ onCancel() {
|
|
|
+ console.log('Cancel');
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </a>
|
|
|
+ </>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ return (
|
|
|
+ <PageHeaderWrapper title={false}>
|
|
|
+ <ProTable<TableListItem>
|
|
|
+ search={false}
|
|
|
+ headerTitle="查询表格"
|
|
|
+ actionRef={actionRef}
|
|
|
+ rowKey="id"
|
|
|
+ onChange={(_, _filter, _sorter) => {
|
|
|
+ const sorterResult = _sorter as SorterResult<TableListItem>;
|
|
|
+ if (sorterResult.field) {
|
|
|
+ setSorter(`${sorterResult.field}_${sorterResult.order}`);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ pagination={{
|
|
|
+ defaultPageSize: 10,
|
|
|
+ }}
|
|
|
+ params={{
|
|
|
+ sorter,
|
|
|
+ }}
|
|
|
+ request={async (params = {}) => {
|
|
|
+ const res = await service.queryList(params);
|
|
|
+ return {
|
|
|
+ data: res.data.list,
|
|
|
+ page: params.current,
|
|
|
+ success: true,
|
|
|
+ total: res.data.total,
|
|
|
+ };
|
|
|
+ }}
|
|
|
+ columns={columns}
|
|
|
+ rowSelection={{}}
|
|
|
+ />
|
|
|
+ {modelVisible ? (
|
|
|
+ <UpdateForm
|
|
|
+ onCancel={(refresh) => {
|
|
|
+ setModalVisible(false);
|
|
|
+ if (refresh && actionRef.current) {
|
|
|
+ actionRef.current.reload();
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ modalVisible={modelVisible}
|
|
|
+ values={formValues}>
|
|
|
+ </UpdateForm>
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ </PageHeaderWrapper>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default TableList;
|