123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import { getPostsList, deletePosts, updatePosts } from "@/services/posts";
- import { queryTable } from "@/utils/request";
- import { PageContainer, ProTable } from "@ant-design/pro-components";
- import { useNavigate } from "react-router-dom";
- import { Button, message, Popconfirm } from "antd";
- import { useRef, useState, useEffect } from "react";
-
- const regex = /(<([^>]+)>)/gi;
-
- const EmergencyPlanList = (props) => {
- const { type } = props;
-
- const actionRef = useRef();
- const navigate = useNavigate();
-
- const updata = (row) => {
- if (row.id) {
- updatePosts(row.id, { status: row.status === 1 ? 0 : 1 }).then((res) => {
- actionRef.current.reload();
- });
- }
- };
-
- const handleDelete = (id) => {
- if (id) {
- deletePosts(id).then((res) => {
- actionRef.current.reload();
- });
- }
- };
-
- const columns = [
- {
- title: "内容名称",
- dataIndex: "title",
- },
-
- {
- title: "发布内容",
- dataIndex: "detail",
- search: false,
- ellipsis: true,
- width: "50%",
- renderText: (text) => text.replace(regex, ""),
- },
- {
- title: "状态",
- dataIndex: "status",
- valueType: "select",
- valueEnum: {
- 0: { text: "未发布", status: "Error" },
- 1: { text: "已发布", status: "Processing" },
- },
- },
- {
- title: "发布人",
- dataIndex: "createPerson",
- search: false,
- },
- {
- title: "操作",
- valueType: "option",
- width: 200,
- render: (_, record) => [
- <Button
- key={4}
- style={{ padding: 0 }}
- type="link"
- onClick={() => {
- updata(record);
- }}
- >
- {record.status === 1 ? "下架" : "发布"}
- </Button>,
- <Button
- key={1}
- style={{ padding: 0 }}
- type="link"
- onClick={() => {
- navigate(`/cms/emergency-plan/detail?id=${record.id}`);
- }}
- >
- 详情
- </Button>,
- <Button
- key={2}
- style={{ padding: 0 }}
- type="link"
- onClick={() => {
- navigate(`/cms/emergency-plan/edit?id=${record.id}`);
- }}
- >
- 修改
- </Button>,
- <Popconfirm
- key={3}
- title="您是否确认删除 ?"
- onConfirm={() => handleDelete(record.id)}
- okText="确定"
- cancelText="取消"
- >
- {/* manualPush */}
- <Button style={{ padding: 0 }} type="link">
- 删除
- </Button>
- </Popconfirm>,
- ],
- },
- ];
-
- return (
- <PageContainer>
- <ProTable
- actionRef={actionRef}
- rowKey="id"
- toolBarRender={() => [
- <Button
- key="2"
- type="primary"
- onClick={() => {
- navigate("/cms/emergency-plan/edit");
- }}
- >
- 新增
- </Button>,
- ]}
- // search={false}
- params={{ type: 'emergency-plan' }}
- request={queryTable(getPostsList)}
- columns={columns}
- />
- </PageContainer>
- );
- };
-
- export default EmergencyPlanList;
|