Browse Source

(*) 巡检记录导出功能

master
liujiangyong 1 year ago
parent
commit
698eceeca8
  1. 37
      web/client/src/sections/patrolManage/containers/patrolRecord.js
  2. 4
      web/client/src/sections/projectRegime/containers/qrCode.js

37
web/client/src/sections/patrolManage/containers/patrolRecord.js

@ -3,8 +3,9 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Form, Input, Select, Button, Table, Modal, DatePicker, Checkbox, Row, Col, Collapse } from 'antd'; import { Form, Input, Select, Button, Table, Modal, DatePicker, message, Row, Col, Collapse, Popconfirm } from 'antd';
import moment from "moment"; import moment from "moment";
import XLSX from 'xlsx';
import Uploads from '$components/Uploads'; import Uploads from '$components/Uploads';
import '../style.less' import '../style.less'
@ -20,6 +21,7 @@ const PatrolRecord = (props) => {
const [limits, setLimits] = useState() const [limits, setLimits] = useState()
const format = 'YYYY-MM-DD HH:mm:ss' const format = 'YYYY-MM-DD HH:mm:ss'
const [search, setSearch] = useState({ name: null, time: [moment().add(-7, 'd').format(format), moment().format(format)], state: 'null' }) const [search, setSearch] = useState({ name: null, time: [moment().add(-7, 'd').format(format), moment().format(format)], state: 'null' })
const [exportLoading, setExportLoading] = useState(false)
useEffect(() => { useEffect(() => {
record(search) record(search)
@ -36,6 +38,34 @@ const PatrolRecord = (props) => {
}) })
} }
const exportRecord = () => {
if (tableList.length === 0) {
message.warning('没有数据可以导出')
return
}
setExportLoading(true)
const workbook = XLSX.utils.book_new(); // 新建工作簿
let data = [['结构物名称', '巡检计划', '巡检点位', '巡检人', '巡检单位', '巡检频次', '上次巡检日期', '本次巡检日期', '巡检结果']];
for (const item of tableList) {
data.push([
item.points?.project?.name || '--',
item.patrolPlan?.name || '--',
item.points?.itemData?.name || '--',
item.points?.user?.name || '--',
item.points?.user?.department?.name || '--',
item.points?.frequency || '--',
item.lastInspectionTime ? moment(item.lastInspectionTime).format('YYYY-MM-DD HH:mm:ss') : '--',
moment(item.inspectionTime).format('YYYY-MM-DD HH:mm:ss'),
!item.alarm ? '正常' : '异常',
])
}
const worksheet = XLSX.utils.aoa_to_sheet(data); // 从二维数组新建工作表
XLSX.utils.book_append_sheet(workbook, worksheet, "sheet1"); // 将工作表添加到工作簿
XLSX.writeFile(workbook, '巡检记录.xlsx'); // 将工作簿数据建立为./xlsx文件(浏览器环境下会直接下载)
message.success('导出成功')
setExportLoading(false)
}
const columns = [{ const columns = [{
title: '结构物名称', title: '结构物名称',
dataIndex: 'name', dataIndex: 'name',
@ -163,9 +193,8 @@ const PatrolRecord = (props) => {
{ value: true, label: '异常' }]} /> { value: true, label: '异常' }]} />
</Form.Item> </Form.Item>
<Form.Item wrapperCol={{}}> <Form.Item wrapperCol={{}}>
<Button type="primary" htmlType="submit"> <Button type="primary" htmlType="submit" style={{ marginRight: 16 }}>搜索</Button>
搜索 <Button type="primary" onClick={exportRecord} loading={exportLoading}>导出</Button>
</Button>
</Form.Item> </Form.Item>
</Form> </Form>
</div> </div>

4
web/client/src/sections/projectRegime/containers/qrCode.js

@ -36,6 +36,10 @@ const QrCode = (props) => {
} }
const batchDownload = () => { const batchDownload = () => {
if (tableList.length === 0) {
message.warning('没有数据可以导出')
return
}
setDownloading(true) setDownloading(true)
let promiseArr = [], nameArr = [] let promiseArr = [], nameArr = []
tableList.forEach(l => { tableList.forEach(l => {

Loading…
Cancel
Save