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 }) header.sort((a, b) => { return a.index - b.index })
const fileName = `${modalOption.n}_${moment().format('YYYYMMDDHHmmss')}` + '.csv' 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); const fileData = fs.readFileSync(filePath);
ctx.status = 200; ctx.status = 200;

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

@ -21,7 +21,7 @@ module.exports = dc => {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
comment: "上报类型 巡查:patrol / 养护:conserve", comment: "上报类型",
primaryKey: false, primaryKey: false,
field: "report_type", field: "report_type",
autoIncrement: false autoIncrement: false
@ -31,7 +31,7 @@ module.exports = dc => {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
comment: "工程类型 道路:road / 桥梁:birdge / 涵洞:culvert", comment: "工程类型",
primaryKey: false, primaryKey: false,
field: "project_type", field: "project_type",
autoIncrement: false 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.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-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 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`) const fileDirPath = path.join(__dirname, `../../downloadFiles`)
makeDir(fileDirPath) makeDir(fileDirPath)
const file = new xlsx.File(); const file = new xlsx.File();
@ -57,6 +57,33 @@ async function simpleExcelDown ({ data = [], header = [], fileName = moment().fo
for (let h of header) { for (let h of header) {
const cell = row.addCell(); const cell = row.addCell();
cell.value = data[i][h.key]; 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 cell.style = style
} }
} }

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

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

Loading…
Cancel
Save