| | |
| | | :on-preview="handlePreview" |
| | | :on-remove="handleRemove" |
| | | :file-list="fileList" |
| | | :on-change="handleFileChange" |
| | | :auto-upload="false" |
| | | multiple |
| | | accept=".jpg,.png" |
| | | > |
| | | <el-button slot="trigger" size="small" type="primary">选择文件</el-button> |
| | | <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button> |
| | | <el-button style="margin-left: 10px;" size="small" type="danger" @click="clearFileList">清空列表</el-button> |
| | | <div slot="tip" class="el-upload__tip">可上传JPG等格式文件,单个文件不超过50MB</div> |
| | | </el-upload> |
| | | </el-dialog> |
| | |
| | | return { |
| | | importDialogVisible: false, |
| | | fileList: [], |
| | | uploadUrl: process.env.VUE_APP_BASE_API +'/system/materials/upload', // 替换为实际的上传接口 |
| | | uploadUrl: process.env.VUE_APP_BASE_API +'/system/materials/upload/'+this.recordId, // 替换为实际的上传接口 |
| | | headers: { |
| | | Authorization: 'Bearer ' + getToken() |
| | | }, |
| | |
| | | const recordId = this.$route.params && this.$route.params.recordId |
| | | //alert(recordId) |
| | | this.recordId = recordId; |
| | | |
| | | this.uploadUrl = process.env.VUE_APP_BASE_API +'/system/materials/upload/'+this.recordId |
| | | // alert('Bearer ' + getToken()) |
| | | this.reset() |
| | | this.form.securityLevel = '普通' // 设置对话框表单默认值 |
| | |
| | | handlePreview(file) { |
| | | console.log(file) |
| | | }, |
| | | handleFileChange(file, fileList) { |
| | | console.log('当前文件列表:', fileList); |
| | | this.fileList = fileList; |
| | | }, |
| | | // 提交上传 |
| | | submitUpload() { |
| | | // 获取当前选择的文件数量 |
| | | const fileCount = this.fileList.length |
| | | if (fileCount === 0) { |
| | | this.$modal.msgWarning('请先选择文件再上传') |
| | | return |
| | | } |
| | | if(fileCount!==this.total) |
| | | { |
| | | this.$modal.msgWarning('请选择与记录数一致的文件') |
| | | return |
| | | } |
| | | // 执行上传 |
| | | this.$refs.upload.submit() |
| | | }, |
| | | clearFileList() { |
| | | this.fileList = []; |
| | | this.$modal.msgSuccess('已清空上传列表'); |
| | | }, |
| | | handleKeyDown(e) { |
| | | // 在keydown事件中更早地阻止默认行为 |
| | |
| | | // } |
| | | const formData = new FormData(); |
| | | formData.append('file', file); |
| | | formData.append('recordId', this.recordId) |
| | | alert(this.recordId) |
| | | // formData.append('recordId', this.recordId) |
| | | // alert(this.recordId) |
| | | console.log(file) |
| | | |
| | | // 显示加载中状态 |