update 上传

This commit is contained in:
g7hoo 2022-08-12 17:03:55 +08:00
parent 302d1832df
commit a9265d6708
3 changed files with 40 additions and 4 deletions

View File

@ -1,6 +1,7 @@
<template>
<div class="base-upload" style="border-radius: 8px; margin-top: 38px; padding: 0; max-height: 500px;">
<el-upload class="yd-upload" :action="$http.adornUrl(url)" multiple name="files" :file-list="fileList" :on-remove="handleRemove" :before-remove="beforeRemove">
<el-upload class="yd-upload" action="#" :http-request="handleUpload" multiple :file-list="fileList" :on-remove="handleRemove" :before-remove="beforeRemove">
<!-- <el-upload class="yd-upload" :action="$http.adornUrl(url)" multiple name="files" :data="extraParams" :file-list="fileList" :on-remove="handleRemove" :before-remove="beforeRemove"> -->
<el-button size="small" type="primary">{{ buttonContent }}</el-button>
<div v-if="tip" slot="tip" class="el-upload__tip">{{ tip }}</div>
</el-upload>
@ -16,6 +17,10 @@ export default {
tip: {
type: String,
default: null
},
extraParams: {
type: Object,
default: () => ({})
}
},
data() {
@ -24,6 +29,30 @@ export default {
}
},
methods: {
/** 自定义上传行为 */
handleUpload(file) {
const formData = new FormData()
let files = file.file
formData.append('files', files)
this.$http({
url: this.$http.adornUrl(this.url),
method: 'POST',
data: formData,
params: {
typeCode: this.extraParams.typeCode
}
}).then(({ data: res }) => {
if (res && res.code === 0) {
console.log(this.fileList)
this.fileList.splice(0)
res.data.forEach(item => {
this.fileList.push(item) // <==
})
// TODO: files[]
}
})
},
beforeRemove(file, filelist) {
return this.$confirm(`确定移除 ${file.name}?`)
},

View File

@ -85,7 +85,8 @@ const addOrUpdateConfigs = {
label: '上传资料',
component: () => import('@/components/base-upload'),
props: { // props
url: "/monitoring/attachment/uploadFileFormData?typeCode=EquipmentTypeFile",
url: "/monitoring/attachment/uploadFileFormData",
extraParams: { typeCode: 123 },
buttonContent: '点击上传',
tip: '上传文件大小不要超过 2mb (2048kb)'
}

View File

@ -57,7 +57,7 @@ import AddOrUpdate from '@/components/base-dialog/addOrUpdate'
// import AddOrUpdate from './qualityInspectionRecord-add-or-update'
import BaseTable from '@/components/base-table'
import TableOperateComponent from '@/components/base-table/components/operationComponent'
import TableTextComponent from '@/components/base-table/components/detailComponent'
// import TableTextComponent from '@/components/base-table/components/detailComponent'
const tableConfigs = [
{ prop: 'createTime', name: '添加时间' },
@ -78,7 +78,13 @@ const tableConfigs = [
{ prop: 'operations', name: '操作', fixed: 'right', width: 180, subcomponent: TableOperateComponent, options: ['edit', 'delete'] }
]
const addOrUpdateConfigs = {}
const addOrUpdateConfigs = {
type: 'dialog',
infoUrl: '/monitoring/qualityInspectionRecord',
fields: [
{name: '', label: '检测类型', type: 'select', options: []}
]
}
export default {
data() {