fix bugs
This commit is contained in:
		| @@ -76,6 +76,7 @@ | ||||
| 						class="upload-area" | ||||
| 						:class="uploadOpen ? '' : 'height-48'" | ||||
| 						ref="uploadArea" | ||||
| 						:key="col.prop" | ||||
| 						v-if="col.upload"> | ||||
| 						<span class="close-icon" :class="uploadOpen ? 'open' : ''"> | ||||
| 							<el-button | ||||
| @@ -87,13 +88,18 @@ | ||||
| 						<el-upload | ||||
| 							class="upload-in-dialog" | ||||
| 							v-if="col.upload" | ||||
| 							:key="col.prop + '__el-upload'" | ||||
| 							:action="uploadUrl" | ||||
| 							:headers="uploadHeaders" | ||||
| 							:show-file-list="false" | ||||
| 							icon="el-icon-upload2" | ||||
| 							:disabled="disabled" | ||||
| 							:before-upload="beforeUpload" | ||||
| 							:on-success="handleUploadSuccess" | ||||
| 							:on-success=" | ||||
| 								(response, file, fileList) => { | ||||
| 									handleUploadSuccess(response, file, col.prop); | ||||
| 								} | ||||
| 							" | ||||
| 							v-bind="col.bind"> | ||||
| 							<el-button size="mini" :disabled="col.bind?.disabled || false"> | ||||
| 								<svg-icon | ||||
| @@ -108,10 +114,10 @@ | ||||
|  | ||||
| 						<uploadedFile | ||||
| 							class="file" | ||||
| 							v-for="file in form[col.prop] || []" | ||||
| 							v-for="file in form[col.prop]" | ||||
| 							:file="file" | ||||
| 							:key="file.fileUrl" | ||||
| 							@delete="!disabled && handleDeleteFile(file)" /> | ||||
| 							@delete="!disabled && handleDeleteFile(file, col.prop)" /> | ||||
| 					</div> | ||||
| 				</el-form-item> | ||||
| 			</el-col> | ||||
| @@ -152,12 +158,30 @@ const uploadedFile = { | ||||
| 		handleDelete() { | ||||
| 			this.$emit('delete', this.file); | ||||
| 		}, | ||||
| 		async handleDownload() { | ||||
| 			const data = await this.$axios({ | ||||
| 				url: this.file.fileUrl, | ||||
| 				method: 'get', | ||||
| 				responseType: 'blob', | ||||
| 			}); | ||||
|  | ||||
| 			await this.$message.success('开始下载'); | ||||
| 			// create download link | ||||
| 			const url = window.URL.createObjectURL(data); | ||||
| 			const link = document.createElement('a'); | ||||
| 			link.href = url; | ||||
| 			link.download = this.file.fileName; | ||||
| 			document.body.appendChild(link); | ||||
| 			link.click(); | ||||
| 			document.body.removeChild(link); | ||||
| 		}, | ||||
| 	}, | ||||
| 	mounted() {}, | ||||
| 	render: function (h) { | ||||
| 		return ( | ||||
| 			<div | ||||
| 				title={this.file.fileName} | ||||
| 				onClick={this.handleDownload} | ||||
| 				style={{ | ||||
| 					background: `url(${tupleImg}) no-repeat`, | ||||
| 					backgroundSize: '14px', | ||||
| @@ -205,7 +229,7 @@ export default { | ||||
| 			default: false, | ||||
| 		}, | ||||
| 		hasFiles: { | ||||
| 			type: Boolean, | ||||
| 			type: Boolean | Array, | ||||
| 			default: false, | ||||
| 		}, | ||||
| 		labelPosition: { | ||||
| @@ -251,7 +275,13 @@ export default { | ||||
| 			handler(val) { | ||||
| 				this.form = JSON.parse(JSON.stringify(val)); | ||||
| 				if (this.hasFiles) { | ||||
| 					this.form.files = this.form.files ?? []; | ||||
| 					if (typeof this.hasFiles == 'boolean' && this.hasFiles) { | ||||
| 						this.form.files = this.form.files ?? []; | ||||
| 					} else if (Array.isArray(this.hasFiles)) { | ||||
| 						this.hasFiles.forEach((prop) => { | ||||
| 							this.form[prop] = this.form[prop] ?? []; | ||||
| 						}); | ||||
| 					} | ||||
| 				} | ||||
| 			}, | ||||
| 			deep: true, | ||||
| @@ -348,7 +378,7 @@ export default { | ||||
| 									// 处理输入框数据 | ||||
| 									this.form[opt.prop] = response.data; | ||||
| 									// 更新下外部的 dataForm,防止code字段有数据也报空的bug | ||||
| 									this.$emit('update', this.form) | ||||
| 									this.$emit('update', this.form); | ||||
| 								} | ||||
| 							}); | ||||
| 						} | ||||
| @@ -377,11 +407,12 @@ export default { | ||||
| 		// 上传成功的特殊处理 | ||||
| 		beforeUpload() {}, | ||||
| 		// 上传前的验证规则可通过 bind 属性传入 | ||||
| 		handleUploadSuccess(response, file, fileList) { | ||||
| 			this.form.files.push({ | ||||
| 		handleUploadSuccess(response, file, prop) { | ||||
| 			console.log('[handleUploadSuccess]', response, file, prop); | ||||
| 			this.form[prop].push({ | ||||
| 				fileName: file.name, | ||||
| 				fileUrl: response.data, | ||||
| 				fileType: 2, | ||||
| 				fileType: prop == 'files' ? 2 : 1, | ||||
| 			}); | ||||
| 			this.$modal.msgSuccess('上传成功'); | ||||
| 			this.$emit('update', this.form); | ||||
| @@ -395,8 +426,8 @@ export default { | ||||
| 			this.uploadOpen = !this.uploadOpen; | ||||
| 		}, | ||||
|  | ||||
| 		handleDeleteFile(file) { | ||||
| 			this.form.files = this.form.files.filter( | ||||
| 		handleDeleteFile(file, prop) { | ||||
| 			this.form[prop] = this.form[prop].filter( | ||||
| 				(item) => item.fileUrl != file.fileUrl | ||||
| 			); | ||||
| 			this.$emit('update', this.form); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user