List.tsx 1.38 KB
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>
  );
}