Browse Source

导出字段

dev
巴林闲侠 2 years ago
parent
commit
d1cace07e7
  1. 2
      api/app/lib/controllers/data/index.js
  2. 4
      api/app/lib/models/report.js
  3. 6
      api/log/development.log
  4. 29
      api/utils/xlsxDownload.js
  5. 7
      web/client/src/sections/fillion/components/maintenanceTable.js

2
api/app/lib/controllers/data/index.js

@ -104,7 +104,7 @@ async function dataExport (ctx) {
header.sort((a, b) => { return a.index - b.index })
const fileName = `${modalOption.n}_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName })
const filePath = await xlsxDownload.simpleExcelDown({ data: exportData, header, fileName: fileName, exp })
const fileData = fs.readFileSync(filePath);
ctx.status = 200;

4
api/app/lib/models/report.js

@ -21,7 +21,7 @@ module.exports = dc => {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: "上报类型 巡查:patrol / 养护:conserve",
comment: "上报类型",
primaryKey: false,
field: "report_type",
autoIncrement: false
@ -31,7 +31,7 @@ module.exports = dc => {
type: DataTypes.STRING,
allowNull: false,
defaultValue: null,
comment: "工程类型 道路:road / 桥梁:birdge / 涵洞:culvert",
comment: "工程类型",
primaryKey: false,
field: "project_type",
autoIncrement: false

6
api/log/development.log

@ -10691,3 +10691,9 @@ headers: {}
2022-07-30 16:59:14.475 - debug: [FS-LOGGER] Init.
2022-07-30 16:59:14.573 - info: [FS-ATTACHMENT] Inject attachment mw into router.
2022-07-30 16:59:14.573 - info: [FS-AUTH] Inject auth and api mv into router.
2022-07-30 17:19:58.438 - debug: [FS-LOGGER] Init.
2022-07-30 17:19:58.538 - info: [FS-ATTACHMENT] Inject attachment mw into router.
2022-07-30 17:19:58.539 - info: [FS-AUTH] Inject auth and api mv into router.
2022-07-30 17:48:40.061 - debug: [FS-LOGGER] Init.
2022-07-30 17:48:40.152 - info: [FS-ATTACHMENT] Inject attachment mw into router.
2022-07-30 17:48:40.152 - info: [FS-AUTH] Inject auth and api mv into router.

29
api/utils/xlsxDownload.js

@ -16,7 +16,7 @@ async function makeDir (dir) {
}
}
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) {
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss'), exp } = {}) {
const fileDirPath = path.join(__dirname, `../../downloadFiles`)
makeDir(fileDirPath)
const file = new xlsx.File();
@ -57,6 +57,33 @@ async function simpleExcelDown ({ data = [], header = [], fileName = moment().fo
for (let h of header) {
const cell = row.addCell();
cell.value = data[i][h.key];
if (exp == 'patrol' || exp == 'maintenance') {
if (h.key == 'projectType') {
let type = data[i][h.key]
if (type == 'road') {
cell.value = '道路'
} else if (type == 'birdge') {
cell.value = '桥梁'
} else if (type == 'culvert') {
cell.value = '涵洞'
} else if (type == 'other') {
cell.value = '其他'
}
continue
}
if (h.key == 'reportType') {
let type = data[i][h.key]
if (type == 'patrol') {
cell.value = '巡查'
} else if (type == 'conserve') {
cell.value = '养护'
}
continue
}
}
cell.style = style
}
}

7
web/client/src/sections/fillion/components/maintenanceTable.js

@ -12,6 +12,7 @@ import moment from 'moment';
const DetailForm = (props) => {
const { visible, data, handleClose, loading } = props;
const [qndmn] = useState(localStorage.getItem('qndmn'));
const keyList = [
{ key: '编号', name: 'id' },
{ key: '工程类型', name: 'projectType' },
@ -37,7 +38,7 @@ const DetailForm = (props) => {
{
data[obj.name] && data[obj.name] instanceof Array ? data[obj.name].map(imgSrc => {
return <div style={{ width: '44%', margin: 6 }}>
<Image src={imgSrc} width={'100%'} style={{ marginBottom: 4 }} />
<Image src={qndmn + '/' + imgSrc} width={'100%'} style={{ marginBottom: 4 }} />
</div>
}) : '暂无图片'
}
@ -118,7 +119,7 @@ const DetailList = (props) => {
switch (text) {
case 'road': return '道路';
case 'bridge': return '桥梁';
case 'culvert ': return '涵洞';
case 'culvert': return '涵洞';
case 'other': return '其他';
default: return text;
}
@ -150,7 +151,7 @@ const DetailList = (props) => {
dataIndex: 'userName',
align: 'center',
render: (text, record) => {
return record.user.name
return record?.user?.name
}
}, {
title: '上报时间',

Loading…
Cancel
Save