
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"><el-form-item label="选择文件" prop="fileList"><el-upload ref="upload" action="#" :auto-upload="false" :on-change="handleFileChange":on-exceed="handleExceed" :on-remove="handleFileRemove" :file-list="ruleForm.fileList" drag :multiple="true" :limit="1" accept=".jpg,.jpeg,.png,.pdf,.doc,.docx"><i class="el-icon-upload"></i><div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div><div class="el-upload__tip" slot="tip">只能上传docx/doc/pdf/png/jpg/jpeg文件,且不超过200MB</div></el-upload></el-form-item>
</el-form><span slot="footer" class="dialog-footer"><el-button @click="dialogImportVisible = false">取 消</el-button><el-button type="primary" @click="handleImportSure('ruleForm')">解 析</el-button></span>
ruleForm: {fileList: [],
},
rules: {fileList: [{ required: true, message: '请上传附件', trigger: 'change' }],
},
handleFileChange(file, fileList) {const isLt200M = file.size / 1024 / 1024 < 200;if (!isLt200M) {this.$message.error('文件大小不能超过200MB');this.ruleForm.fileList = this.ruleForm.fileList.filter(item => item.uid !== file.uid);return false;}this.ruleForm.fileList = fileList;this.$refs.ruleForm.clearValidate(['fileList']);
},
handleFileRemove(file, fileList) {this.ruleForm.fileList = fileList;
},
handleExceed() {this.$modal.msgError(`上传文件数量不能超过 1 个!`);
},
handleImportSure(formName) {this.$refs[formName].validate((valid) => {if (valid) {} else {console.log('error submit!!', this.ruleForm.fileList);return false;}})
},