Quellcode durchsuchen

Merge branch 'feature/master' into feature/develop

rainwer vor 7 Monaten
Ursprung
Commit
7979b3415c

+ 25 - 2
src/views/business/production/receiveResource/form.vue

@@ -36,7 +36,7 @@
             <el-col :span="24">
               <el-form-item label="选择文件" prop="files">
                 <el-upload v-if="visible" action="#" :http-request="upload" :before-upload="handleBeforeUpload" :with-credentials="true"
-                  :before-remove="removeFile" v-model:file-list="fileList" :accept="acceptType"
+                  :before-remove="removeFile" v-model:file-list="fileList" :on-exceed="onExceed" :on-error="onUploadError" :accept="acceptType"
                   :show-file-list="true" multiple :limit="5" drag style="width: 100%;">
                   <!-- <el-button size="small" type="primary" icon="Upload">上传文件</el-button> -->
                   <el-icon class="el-icon--upload"><upload-filled /></el-icon>
@@ -184,6 +184,19 @@
     acceptType
   } = toRefs(data);
 
+  function onUploadError(err) {
+    console.log('onUploadError', err)
+  }
+
+  function onExceed(files) {
+    console.log( fileList.value)
+    if(files.length + fileList.value.length> 5) {
+      proxy.$modal.msgError("单次最多上传5个文件")
+      return  false
+    }
+    return true
+  }
+
   function validateFiles(rule, value, callback) {
     if (!form.value.files || form.value.files.length == 0) {
       callback(new Error('请上传文件'))
@@ -273,7 +286,9 @@
 
         form.value.files.push(file)
         fileMap.value[param.file.uid] = file.fileUrl
-        if(fileList.value.findIndex(f => f.uid == param.file.uid) > 0) {
+        if(fileList.value.findIndex(f => f.uid == param.file.uid) < 0) {
+          console.log('fileList', fileList)
+          console.log('param.file.uid', param.file.uid)
           fileList.value.push(param.file)
         }
       } else {
@@ -286,7 +301,15 @@
     });
   }
 
+  const types = acceptType.value.split(',')
   function handleBeforeUpload(file) {
+    const fileExtension = file.name.split('.').pop().toLowerCase();
+    if(!types.includes('.'+fileExtension)) {
+      proxy.$modal.msgError("文件格式不正确");
+      return false;
+    }
+    
+    console.log('handleBeforeUpload',file)
     if(file.size > 15 * 1024 * 1024) {
       proxy.$modal.msgError("文件大小不能超过15M");
       return false;

+ 2 - 2
src/views/business/production/receiveResource/index.vue

@@ -290,13 +290,13 @@
   function handleDelete(row) {
     const _ids = row.id || ids.value;
     proxy.$modal
-      .confirm("是否确认删除选中的数据项?")
+      .confirm("是否确认作废选中的数据项?")
       .then(function () {
         return delFile(_ids);
       })
       .then(() => {
         getList();
-        proxy.$modal.msgSuccess("删除成功!");
+        proxy.$modal.msgSuccess("作废成功!");
       })
       .catch(() => { });
   }