From 70a5d3ae7bf1509afab3dcffe7de68710fa8c089 Mon Sep 17 00:00:00 2001 From: MustangDeng <670124965@qq.com> Date: Thu, 16 Jun 2022 20:58:54 +0800 Subject: [PATCH] fix bug 48 - 56 --- .../components/importModal/modalStep1.js | 46 ++++++++++++++----- .../programme/defaultSlideForm.js | 4 +- .../socialSecurityBenefits/programme/index.js | 6 --- pc4mobx/hrmSalary/stores/programme.js | 17 ++++--- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/pc4mobx/hrmSalary/components/importModal/modalStep1.js b/pc4mobx/hrmSalary/components/importModal/modalStep1.js index 567d5b6c..ee1d23f8 100644 --- a/pc4mobx/hrmSalary/components/importModal/modalStep1.js +++ b/pc4mobx/hrmSalary/components/importModal/modalStep1.js @@ -14,7 +14,8 @@ export default class ModalStep1 extends React.Component { this.state = { datetime: "", taxAgentId: "", - hasData: "0" + hasData: "0", + fileList: [] } } @@ -23,6 +24,36 @@ export default class ModalStep1 extends React.Component { fetchTaxAgentOption(); } + handleChange(info) { + let fileList = info.fileList; + + // 1. 上传列表数量的限制 + // 只显示最近上传的一个,旧的会被新的顶掉 + fileList = fileList.slice(-1); + // 2. 读取远程路径并显示链接 + fileList = fileList.map((file) => { + if (file.response) { + // 组件会将 file.url 作为链接进行展示 + file.url = file.response.url; + } + return file; + }); + + // 3. 按照服务器返回信息筛选成功上传的文件 + fileList = fileList.filter((file) => { + if (file.response) { + return file.response.status === 1; + } + return true; + }); + + if(fileList && fileList.length > 0 && fileList[0].response && fileList[0].response.status === 1) { + this.props.onFileIdChange(fileList[0].response.data.fileid) + } + + this.setState({ fileList }); + } + render() { const { datetime, taxAgentId, hasData } = this.state const { taxAgentStore: {taxAgentOption}, isInit } = this.props; @@ -35,16 +66,7 @@ export default class ModalStep1 extends React.Component { multiple: false, action: "/api/doc/upload/uploadFile", //上传地址 onChange: (info) => { - const { status } = info.file; - if (status !== 'uploading') { - //获得服务端返回的资源url - console.log(info.file.response.data); - } - if (status === 'done') { - this.props.onFileIdChange(info.file.response.data.fileid) - } else if (status === 'error') { - message.error(`${info.file.name} file upload failed.`); - } + this.handleChange(info) }, }; return ( @@ -66,7 +88,7 @@ export default class ModalStep1 extends React.Component { 导入excel