Blame view

components/List.tsx 1.4 KB
c9a263f8   王强   init
1
  import React from "react";
4022eef8   王强   fix
2
  import { Divider, message, Popconfirm, Table } from "antd";
c9a263f8   王强   init
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  import { delete<feewee>替换name</feewee>Api } from "../api";
  import { useStore } from "../index";
  
  export default function List() {
    const { pagination, setCurrent, setOpen } = useStore();
  
    function editItem(item: <feewee>替换name</feewee>.ListVO) {
      setCurrent(item);
      setOpen(true);
    }
  
    function deleteItem(id: number) {
      const hide = message.loading('删除中,请稍后...', 0);
      delete<feewee>替换name</feewee>Api(id)
        .then((res) => {
          hide();
          message.success(res.result);
          pagination.setLoading(true);
        })
        .catch((error) => {
          hide();
          message.error(error.message);
        });
    }
  
    return (
      <Table dataSource={pagination.list} rowKey="id" loading={pagination.loading} pagination={pagination.paginationConfig}>
        <Table.Column title="name" align="left" dataIndex="name" />
        <Table.Column
          title="操作"
          align="left"
          render={(record: <feewee>替换name</feewee>.ListVO) => (
            <>
4022eef8   王强   fix
36
              <a onClick={() => editItem(record)}>编辑</a>
c9a263f8   王强   init
37
38
39
40
41
42
43
44
45
46
              <Divider type="vertical" />
              <Popconfirm title={<span>确定删除?</span>} onConfirm={() => deleteItem(record.id || -1)}>
                <a style={{ color: 'red' }}>删除</a>
              </Popconfirm>
            </>
          )}
        />
      </Table>
    );
  }