| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import {Button, Table} from "antd";
- import {useEffect, useState} from "react";
- import ModalHooks from "./components/publicOpinionModal.jsx";
- import "./publicOpinion.scss";
- import axios from "@/utils/axios.js";
- import {useDispatch} from 'react-redux';
- import {setDictData} from '@/store/reducer.js';
- const {Column} = Table;
- export default function PublicOpinion() {
- // 顶部两个搜索
- const [inputVal, setInputVal] = useState("");
- const [keyVal, setKeyVal] = useState("");
- // 页面数据
- const [data, setData] = useState([]);
- // 是否展示弹框
- const [isModalOpen, setIsModalOpen] = useState(false);
- const [row, setRow] = useState({});
- // 新增用户页面
- function addUser() {
- setRow([]);
- setIsModalOpen(true);
- }
- // 关闭页面
- function closeModal() {
- setIsModalOpen(false);
- // 置空input,然后存reduce
- setInputVal('')
- setKeyVal('')
- getData()
- dispatch(setDictData(data))
- }
- // 点击修改的回调
- function modify(data) {
- setRow(data);
- setIsModalOpen(true);
- }
- // reduce状态
- const dispatch = useDispatch();
- // 获取数据
- async function getData() {
- let {data} = await axios.get("/homePage/getBusWarning", {params: {type: inputVal, name: keyVal}});
- data.warningSummary = JSON.parse(data.warningSummary)
- for (const item of data.warningSummary) {
- data[Object.keys(item)[0]] = item[Object.keys(item)[0]]
- }
- console.log(data)
- setData([data]);
- }
- /**
- * 删除页面
- * @param data 删除每一条数据
- * @returns {Promise<void>}
- */
- async function deleteRow(data) {
- let {code} = await axios.get('/dict/deleteKey', {params: {id: data.id}})
- if (code === 200) {
- await getData()
- }
- }
- const columns = [
- {
- title: '报警总数',
- dataIndex: 'warningNum',
- key: 'id',
- },
- {
- title: '报警企业总数',
- dataIndex: 'companyNum',
- key: 'id',
- },
- {
- title: '待反馈数量',
- dataIndex: 'feedbackNum',
- key: 'id',
- },
- {
- title: '待解除数量',
- dataIndex: 'secureNum',
- key: 'id',
- },
- {
- title: '事故',
- dataIndex: 'accident',
- key: 'id',
- },
- {
- title: '舆情',
- dataIndex: 'sentiment',
- key: 'id',
- },
- {
- title: '高风险',
- dataIndex: 'risk',
- key: 'id',
- },
- {
- title: '汛情',
- dataIndex: 'flood',
- key: 'id',
- },
- {
- title: '网络检查',
- dataIndex: 'network',
- key: 'id',
- },
- {
- title: '火险',
- dataIndex: 'fire',
- key: 'id',
- },
- {
- title: '驾驶员报警',
- dataIndex: 'warning',
- key: 'id',
- },
- {
- title: '充电',
- dataIndex: 'charge',
- key: 'id',
- },
- {
- title: '电池高温',
- dataIndex: 'battery',
- key: 'id',
- },
- {
- title: '操作',
- render: (text, record) => (
- <div className="btn">
- <Button type="primary" onClick={() => modify(record)}>
- 修改
- </Button>
- </div>
- )
- },
- ];
- useEffect(() => {
- getData();
- }, []);
- return (
- <div className="user">
- <Table
- dataSource={data}
- pagination={false}
- scroll={{y: 700}}
- bordered={true}
- rowKey="id"
- columns={columns}
- // expandable={{
- // expandedRowRender,
- //
- // }}
- >
- <Column
- title="操作"
- width="170px"
- dataIndex="id"
- key="id"
- render={(text, record) => (
- <div className="btn">
- <Button type="primary" onClick={() => modify(record)}>
- 修改
- </Button>
- </div>
- )}
- />
- </Table>
- <ModalHooks
- isModalOpen={isModalOpen}
- closeModal={closeModal}
- row={row}
- ></ModalHooks>
- </div>
- );
- }
|