Blame view

components/List.tsx 1.38 KB
c9a263f8   王强   init
1
2
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
36
37
38
39
40
41
42
43
44
45
46
  import React from "react";
  import { Divider, message, Popconfirm, Popover, Table } from "antd";
  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) => (
            <>
              <a>编辑</a>
              <Divider type="vertical" />
              <Popconfirm title={<span>确定删除?</span>} onConfirm={() => deleteItem(record.id || -1)}>
                <a style={{ color: 'red' }}>删除</a>
              </Popconfirm>
            </>
          )}
        />
      </Table>
    );
  }