diff --git a/web-react/src/pages/business/house/info/form/base/drawing.jsx b/web-react/src/pages/business/house/info/form/base/drawing.jsx index 7654f80..9d0bbba 100644 --- a/web-react/src/pages/business/house/info/form/base/drawing.jsx +++ b/web-react/src/pages/business/house/info/form/base/drawing.jsx @@ -75,6 +75,7 @@ export default class drawing extends Component { this.setState({ showDrawingMaterialText: houseInfo.drawingMaterial.includes('100') }) } const codes = await getDictData('dic_house_storage_of_drawings') + console.log(codes) this.setState({ codes }) //#endregion this.form.current.setFieldsValue(this.record) diff --git a/web-react/src/pages/business/house/info/form/patrol/index.jsx b/web-react/src/pages/business/house/info/form/patrol/index.jsx index 368174e..79f7503 100644 --- a/web-react/src/pages/business/house/info/form/patrol/index.jsx +++ b/web-react/src/pages/business/house/info/form/patrol/index.jsx @@ -100,7 +100,7 @@ export default class index extends Component { {parts.map((item, i) => ( -
+
{item.title &&
{item.title}
} e.preventDefault()} > {parts.map((part, i) => ( - + ))} diff --git a/web-react/src/pages/business/house/info/form/patrol/inspection.jsx b/web-react/src/pages/business/house/info/form/patrol/inspection.jsx index d759fdf..7ed6b9d 100644 --- a/web-react/src/pages/business/house/info/form/patrol/inspection.jsx +++ b/web-react/src/pages/business/house/info/form/patrol/inspection.jsx @@ -1,7 +1,9 @@ import React, { Component } from 'react' -import { Form, Spin } from 'antd' -import { AntIcon } from 'components' +import { Col, Form, Input, Row, Spin, Upload } from 'antd' +import { AntIcon, PhotoPreview } from 'components' import { cloneDeep, isEqual } from 'lodash' +import { BlobToBase64, GetFileName, PreviewFile } from 'util/file' +import { api } from 'common/api' const initialValues = {} @@ -10,6 +12,8 @@ const layout = { wrapperCol: { flex: '1' }, } +const imageUploads = [{ key: 'settlementTiltFiles' }, { key: 'otherInfoFiles' }] + export default class inspection extends Component { state = { loading: true, @@ -20,6 +24,8 @@ export default class inspection extends Component { // 表单实例 form = React.createRef() + photoPreview = React.createRef() + // 初始化数据 record = {} @@ -61,6 +67,38 @@ export default class inspection extends Component { async fillData(params) { this.record = cloneDeep(params.record) //#region 从后端转换成前段所需格式 + if (this.record) { + const { patrolInfo } = this.record + const keys = imageUploads.map(p => p.key) + for (const key of keys) { + const fileValue = [] + const fileList = + !patrolInfo[key] || !patrolInfo[key].length ? [] : patrolInfo[key].split(',') + for (const fileId of fileList) { + try { + const file = await PreviewFile(fileId) + const base64 = await BlobToBase64(file) + fileValue.push({ + uid: fileId, + response: fileId, + name: file.name, + url: base64, + status: 'done', + }) + } catch { + const { data: file } = await api.sysFileInfoDetail({ id: fileId }) + fileValue.push({ + uid: fileId, + response: '文件已丢失', + name: file.fileOriginName, + status: 'error', + }) + } + } + + patrolInfo[key] = fileValue + } + } //#endregion this.form.current.setFieldsValue(this.record) @@ -81,6 +119,13 @@ export default class inspection extends Component { if (valid) { const postData = form.getFieldsValue() //#region 从前段转换后端所需格式 + const { patrolInfo } = postData + const keys = imageUploads.map(p => p.key) + for (const key of keys) { + patrolInfo[key] = patrolInfo[key] + .map(item => (item.uid.startsWith('rc-upload') ? item.response : item.uid)) + .join(',') + } //#endregion return postData } @@ -94,6 +139,52 @@ export default class inspection extends Component { * @param {*} allValues */ async onValuesChange(changedValues, allValues) {} + + async onFileUpload({ file, onProgress, onSuccess, onError }) { + onProgress({ + percent: 0, + }) + const fd = new FormData() + fd.append('file', file) + try { + const { data: fileId } = await api.sysFileInfoUpload(fd) + onSuccess(fileId) + } catch { + onError() + } + } + + async onFilePreview(file, key) { + const fileList = this.form.current + .getFieldValue(['patrolInfo', key]) + .filter(p => p.status === 'done') + const items = [] + for (const _file of fileList) { + const img = new Image() + const src = _file.url || _file.thumbUrl + img.src = src + items.push({ + src, + w: img.naturalWidth, + h: img.naturalHeight, + }) + } + this.photoPreview.current.initPhotoSwipe(items, { + index: fileList.indexOf(file), + }) + } + + async onFileDownload(file) { + const { data, headers } = await api.sysFileInfoDownload({ id: file.response }) + const url = window.URL.createObjectURL(data) + const fileName = GetFileName(headers['content-disposition']) + const a = document.createElement('a') + a.href = url + a.download = fileName + a.click() + window.URL.revokeObjectURL(url) + a.remove() + } //#endregion render() { @@ -108,7 +199,92 @@ export default class inspection extends Component { onValuesChange={(changedValues, allValues) => this.onValuesChange(changedValues, allValues) } - > + > + + + + + + + + { + if (Array.isArray(e)) { + return e + } + return e && e.fileList + }} + > + this.onFileUpload(e)} + showUploadList={{ + showRemoveIcon: true, + showDownloadIcon: true, + }} + onPreview={file => + this.onFilePreview(file, 'settlementTiltFiles') + } + onDownload={file => this.onFileDownload(file)} + > +
+ +
沉降倾斜照片
+
+
+
+ + + + + + + + { + if (Array.isArray(e)) { + return e + } + return e && e.fileList + }} + > + this.onFileUpload(e)} + showUploadList={{ + showRemoveIcon: true, + showDownloadIcon: true, + }} + onPreview={file => this.onFilePreview(file, 'otherInfoFiles')} + onDownload={file => this.onFileDownload(file)} + > +
+ +
其他情况照片
+
+
+
+ +
+ + + + + +
) } diff --git a/web-react/src/util/dic/index.js b/web-react/src/util/dic/index.js index 3c1ffbe..ba3e28e 100644 --- a/web-react/src/util/dic/index.js +++ b/web-react/src/util/dic/index.js @@ -7,14 +7,14 @@ const { getState, dispatch } = store const getDictData = async (...args) => { const dictData = getState('dictData') - let result = {} + let dict = {} const code = [] for (let i = 0; i < args.length; i++) { const codeName = toCamelCase(args[i]) if (!dictData.hasOwnProperty(codeName)) { code.push(args[i]) } else { - result[codeName] = dictData[codeName] + dict[codeName] = dictData[codeName] } } @@ -29,14 +29,17 @@ const getDictData = async (...args) => { value }) - result = { ...result, ...value } - - return result + dict = { ...dict, ...value } } catch { } } - return dictData + const result = {} + args.forEach(p => { + const codeName = toCamelCase(p) + result[codeName] = dict[codeName] + }) + return result } export default getDictData \ No newline at end of file