publicOpinion.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import {Button, Table} from "antd";
  2. import {useEffect, useState} from "react";
  3. import ModalHooks from "./components/publicOpinionModal.jsx";
  4. import "./publicOpinion.scss";
  5. import axios from "@/utils/axios.js";
  6. import {useDispatch} from 'react-redux';
  7. import {setDictData} from '@/store/reducer.js';
  8. const {Column} = Table;
  9. export default function PublicOpinion() {
  10. // 顶部两个搜索
  11. const [inputVal, setInputVal] = useState("");
  12. const [keyVal, setKeyVal] = useState("");
  13. // 页面数据
  14. const [data, setData] = useState([]);
  15. // 是否展示弹框
  16. const [isModalOpen, setIsModalOpen] = useState(false);
  17. const [row, setRow] = useState({});
  18. // 新增用户页面
  19. function addUser() {
  20. setRow([]);
  21. setIsModalOpen(true);
  22. }
  23. // 关闭页面
  24. function closeModal() {
  25. setIsModalOpen(false);
  26. // 置空input,然后存reduce
  27. setInputVal('')
  28. setKeyVal('')
  29. getData()
  30. dispatch(setDictData(data))
  31. }
  32. // 点击修改的回调
  33. function modify(data) {
  34. setRow(data);
  35. setIsModalOpen(true);
  36. }
  37. // reduce状态
  38. const dispatch = useDispatch();
  39. // 获取数据
  40. async function getData() {
  41. let {data} = await axios.get("/homePage/getBusWarning", {params: {type: inputVal, name: keyVal}});
  42. data.warningSummary = JSON.parse(data.warningSummary)
  43. for (const item of data.warningSummary) {
  44. data[Object.keys(item)[0]] = item[Object.keys(item)[0]]
  45. }
  46. console.log(data)
  47. setData([data]);
  48. }
  49. /**
  50. * 删除页面
  51. * @param data 删除每一条数据
  52. * @returns {Promise<void>}
  53. */
  54. async function deleteRow(data) {
  55. let {code} = await axios.get('/dict/deleteKey', {params: {id: data.id}})
  56. if (code === 200) {
  57. await getData()
  58. }
  59. }
  60. const columns = [
  61. {
  62. title: '报警总数',
  63. dataIndex: 'warningNum',
  64. key: 'id',
  65. },
  66. {
  67. title: '报警企业总数',
  68. dataIndex: 'companyNum',
  69. key: 'id',
  70. },
  71. {
  72. title: '待反馈数量',
  73. dataIndex: 'feedbackNum',
  74. key: 'id',
  75. },
  76. {
  77. title: '待解除数量',
  78. dataIndex: 'secureNum',
  79. key: 'id',
  80. },
  81. {
  82. title: '事故',
  83. dataIndex: 'accident',
  84. key: 'id',
  85. },
  86. {
  87. title: '舆情',
  88. dataIndex: 'sentiment',
  89. key: 'id',
  90. },
  91. {
  92. title: '高风险',
  93. dataIndex: 'risk',
  94. key: 'id',
  95. },
  96. {
  97. title: '汛情',
  98. dataIndex: 'flood',
  99. key: 'id',
  100. },
  101. {
  102. title: '网络检查',
  103. dataIndex: 'network',
  104. key: 'id',
  105. },
  106. {
  107. title: '火险',
  108. dataIndex: 'fire',
  109. key: 'id',
  110. },
  111. {
  112. title: '驾驶员报警',
  113. dataIndex: 'warning',
  114. key: 'id',
  115. },
  116. {
  117. title: '充电',
  118. dataIndex: 'charge',
  119. key: 'id',
  120. },
  121. {
  122. title: '电池高温',
  123. dataIndex: 'battery',
  124. key: 'id',
  125. },
  126. {
  127. title: '操作',
  128. render: (text, record) => (
  129. <div className="btn">
  130. <Button type="primary" onClick={() => modify(record)}>
  131. 修改
  132. </Button>
  133. </div>
  134. )
  135. },
  136. ];
  137. useEffect(() => {
  138. getData();
  139. }, []);
  140. return (
  141. <div className="user">
  142. <Table
  143. dataSource={data}
  144. pagination={false}
  145. scroll={{y: 700}}
  146. bordered={true}
  147. rowKey="id"
  148. columns={columns}
  149. // expandable={{
  150. // expandedRowRender,
  151. //
  152. // }}
  153. >
  154. <Column
  155. title="操作"
  156. width="170px"
  157. dataIndex="id"
  158. key="id"
  159. render={(text, record) => (
  160. <div className="btn">
  161. <Button type="primary" onClick={() => modify(record)}>
  162. 修改
  163. </Button>
  164. </div>
  165. )}
  166. />
  167. </Table>
  168. <ModalHooks
  169. isModalOpen={isModalOpen}
  170. closeModal={closeModal}
  171. row={row}
  172. ></ModalHooks>
  173. </div>
  174. );
  175. }