index.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { getPostsList, deletePosts, updatePosts } from "@/services/posts";
  2. import { queryTable } from "@/utils/request";
  3. import { PageContainer, ProTable } from "@ant-design/pro-components";
  4. import { useNavigate } from "react-router-dom";
  5. import { Button, message, Popconfirm } from "antd";
  6. import { useRef, useState, useEffect } from "react";
  7. const regex = /(<([^>]+)>)/gi;
  8. const EmergencyPlanList = (props) => {
  9. const { type } = props;
  10. const actionRef = useRef();
  11. const navigate = useNavigate();
  12. const updata = (row) => {
  13. if (row.id) {
  14. updatePosts(row.id, { status: row.status === 1 ? 0 : 1 }).then((res) => {
  15. actionRef.current.reload();
  16. });
  17. }
  18. };
  19. const handleDelete = (id) => {
  20. if (id) {
  21. deletePosts(id).then((res) => {
  22. actionRef.current.reload();
  23. });
  24. }
  25. };
  26. const columns = [
  27. {
  28. title: "内容名称",
  29. dataIndex: "title",
  30. },
  31. {
  32. title: "发布内容",
  33. dataIndex: "detail",
  34. search: false,
  35. ellipsis: true,
  36. width: "50%",
  37. renderText: (text) => text.replace(regex, ""),
  38. },
  39. {
  40. title: "状态",
  41. dataIndex: "status",
  42. valueType: "select",
  43. valueEnum: {
  44. 0: { text: "未发布", status: "Error" },
  45. 1: { text: "已发布", status: "Processing" },
  46. },
  47. },
  48. {
  49. title: "发布人",
  50. dataIndex: "createPerson",
  51. search: false,
  52. },
  53. {
  54. title: "操作",
  55. valueType: "option",
  56. width: 200,
  57. render: (_, record) => [
  58. <Button
  59. key={4}
  60. style={{ padding: 0 }}
  61. type="link"
  62. onClick={() => {
  63. updata(record);
  64. }}
  65. >
  66. {record.status === 1 ? "下架" : "发布"}
  67. </Button>,
  68. <Button
  69. key={1}
  70. style={{ padding: 0 }}
  71. type="link"
  72. onClick={() => {
  73. navigate(`/cms/emergency-plan/detail?id=${record.id}`);
  74. }}
  75. >
  76. 详情
  77. </Button>,
  78. <Button
  79. key={2}
  80. style={{ padding: 0 }}
  81. type="link"
  82. onClick={() => {
  83. navigate(`/cms/emergency-plan/edit?id=${record.id}`);
  84. }}
  85. >
  86. 修改
  87. </Button>,
  88. <Popconfirm
  89. key={3}
  90. title="您是否确认删除 ?"
  91. onConfirm={() => handleDelete(record.id)}
  92. okText="确定"
  93. cancelText="取消"
  94. >
  95. {/* manualPush */}
  96. <Button style={{ padding: 0 }} type="link">
  97. 删除
  98. </Button>
  99. </Popconfirm>,
  100. ],
  101. },
  102. ];
  103. return (
  104. <PageContainer>
  105. <ProTable
  106. actionRef={actionRef}
  107. rowKey="id"
  108. toolBarRender={() => [
  109. <Button
  110. key="2"
  111. type="primary"
  112. onClick={() => {
  113. navigate("/cms/emergency-plan/edit");
  114. }}
  115. >
  116. 新增
  117. </Button>,
  118. ]}
  119. // search={false}
  120. params={{ type: 'emergency-plan' }}
  121. request={queryTable(getPostsList)}
  122. columns={columns}
  123. />
  124. </PageContainer>
  125. );
  126. };
  127. export default EmergencyPlanList;