diff --git a/空气质量预测/源码/管理端/iapip-ms/public/fts/imft.xlsx b/空气质量预测/源码/管理端/iapip-ms/public/fts/imft.xlsx index e744a72..d8f0bcd 100644 Binary files a/空气质量预测/源码/管理端/iapip-ms/public/fts/imft.xlsx and b/空气质量预测/源码/管理端/iapip-ms/public/fts/imft.xlsx differ diff --git a/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/materials.tsx b/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/materials.tsx index 267188c..97ee9ff 100644 --- a/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/materials.tsx +++ b/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/materials.tsx @@ -191,8 +191,7 @@ const ImportMaterialsModal: React.FC<{ onClick={async () => { setDownloading(true) try { - const file = await fetch('/fts/imft.xlsx') - // const file = await fetch('/iapip-ms/fts/imft.xlsx') + const file = await fetch('/iapip-ms/fts/imft.xlsx') const wb = new ExcelJS.Workbook() await wb.xlsx.load(await file.arrayBuffer()) const ws = wb.getWorksheet(1) @@ -200,9 +199,11 @@ const ImportMaterialsModal: React.FC<{ const categories = await api.config.getMtrlCatList() categories.forEach((fc, i) => { ws.getCell(1 + i, 43).value = fc.first_category + ws.getColumn(43).hidden = true ws.getColumn(44 + i).values = fc.second_categories.map( (sc) => sc.second_category ) + ws.getColumn(44 + i).hidden = true }) } await downloadXLSX( diff --git a/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/templates.tsx b/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/templates.tsx new file mode 100644 index 0000000..b54607b --- /dev/null +++ b/空气质量预测/源码/管理端/iapip-ms/src/components/import-file-modal/templates.tsx @@ -0,0 +1,270 @@ +import { ExcelValidator } from '@/common/excel-validator' +import { AnyObj, FROM_TYPE } from '@/common/types' +import { downloadXLSX, toNum } from '@/common/utils' +import api from '@/services/api' +import { ModalForm } from '@ant-design/pro-components' +import { Alert, Button, Divider, Tag, Upload, message, theme } from 'antd' +import { RcFile } from 'antd/es/upload' +import * as ExcelJS from 'exceljs' +import React, { useState } from 'react' +import ImportFile from '../apply-request-modal/import-file' + +const ImportTemplatesModal: React.FC<{ + title: string + trigger: JSX.Element +}> = ({ title, trigger }) => { + const { token } = theme.useToken() + const [open, setOpen] = useState(false) + const [downloading, setDownloading] = useState(false) + const [uploading, setUploading] = useState(false) + const [errMsg, setErrMsg] = useState() + const [parsedResult, setParseResult] = useState() + const [uploadFile, setUploadFile] = useState() + const beforeUpload = async (file: RcFile) => { + setUploading(true) + const msgKey = 'UPLOADING_TEMPLATES' + try { + message.open({ + key: msgKey, + type: 'loading', + content: '正在解析' + }) + const wb = new ExcelJS.Workbook() + await wb.xlsx.load(await file.arrayBuffer()) + const ws = wb.getWorksheet(1) + if (ws) { + const templates: AnyObj[] = [] + ws.getRows(6, 10)?.forEach((row, idx) => { + const id = row.getCell(1).value?.toString() + const name = row.getCell(2).value?.toString() + const category = row.getCell(3).value?.toString() + const province = row.getCell(4).value?.toString() + const city = row.getCell(5).value?.toString() + const constr_area = toNum(row.getCell(6).value?.toString()) + if (id && name && category && province && city && constr_area) { + templates.push({ + id, + idx: 6 + idx, + name, + category, + province, + city, + constr_area, + display: 1, + from: FROM_TYPE.IMPORT, + spaces: [] as AnyObj + }) + } + }) + ws.getRows(20, 500)?.forEach((row, idx) => { + const temp_id = row.getCell(2).value?.toString() + const name = row.getCell(5).value?.toString() + const category = row.getCell(6).value?.toString() + const area = toNum(row.getCell(7).value?.toString()) + const volume = toNum(row.getCell(8).value?.toString()) + const env_temp = toNum(row.getCell(9).value?.toString()) + const env_hum = toNum(row.getCell(10).value?.toString()) + const env_vent_rate = toNum(row.getCell(11).value?.toString()) + const apc_lmt_std_id = row.getCell(12).value?.toString() + if (temp_id && name && category && area && volume && apc_lmt_std_id) { + templates.find((temp) => { + if (temp.id === temp_id) { + temp.spaces.push({ + idx: 20 + idx, + name, + category, + layout: 0, + area, + volume, + env_temp, + env_hum, + env_vent_rate, + apc_lmt_std_id + }) + return true + } + return false + }) + } + }) + const excelValidator = new ExcelValidator() + if (await excelValidator.importTemplates(templates)) { + message.open({ + key: msgKey, + type: 'success', + content: '上传成功', + duration: 2 + }) + setErrMsg(undefined) + setParseResult(templates) + setUploadFile(file) + setUploading(false) + return file + } + setErrMsg(excelValidator.errorMessage) + } + } catch (err) {} + message.destroy(msgKey) + setUploading(false) + return false + } + return ( + setOpen(false) + }} + onOpenChange={(v) => { + if (!v) { + setParseResult(undefined) + setUploadFile(undefined) + } + }} + submitter={{ + render: () => ( +
+ {!parsedResult ? ( + <> + + + + + + ) : ( + <> + + + + + 确认导入 + + } + onFinish={async (data) => { + if (uploadFile) { + if (parsedResult.length) { + try { + await api.audit.importTemplates({ + file: uploadFile, + data: parsedResult, + qty: parsedResult.length, + desc: data.desc + }) + message.success('申请成功') + setOpen(false) + return true + } catch (err) {} + } else { + message.error('至少包含一条解析数据') + } + } else { + message.error('找不到上传文件,请重新上传') + } + return false + }} + /> + + )} +
+ ) + }} + trigger={React.cloneElement(trigger, { onClick: () => setOpen(true) })} + > + + {errMsg ? : ''} +
+ +
+ 1. 请下载文件模板, 并根据要求填写后上传文件进行解析 +
+
+ 2. 解析成功后, 确认解析数量是否一致, 点击确认即可导入 +
+
+ {parsedResult ? ( + <> + +
+
+ + +
+
+ + 解析成功, 请确认解析数量一致后点击确认导入 +
+
+ 共 + {parsedResult.length} + 条数据 +
+
+ + ) : ( + '' + )} + +
+ ) +} + +export default ImportTemplatesModal