forked from mt-fe-group/mt-yd-ui
update 上传
This commit is contained in:
parent
302d1832df
commit
a9265d6708
@ -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}?`)
|
||||
},
|
||||
|
@ -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)'
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user