فهرست منبع

fix: 解决用户id与导入置灰bug

kuanghua liu 1 سال پیش
والد
کامیت
234acaf5a4
1فایلهای تغییر یافته به همراه69 افزوده شده و 9 حذف شده
  1. 69 9
      src/views/system/user/component/AddUser.vue

+ 69 - 9
src/views/system/user/component/AddUser.vue

@@ -20,6 +20,8 @@
           :auto-upload="false"
           :on-exceed="handleExceed"
           :before-upload="beforeUpload"
+          :on-change="handleChange"
+          :on-remove="handleRemove"
           :on-success="handleUploadSuccess"
           style="width: 384px; height: 192px; border-radius: 8px"
         >
@@ -27,16 +29,29 @@
           <div class="el-upload__text">
             <div style="font-size: 16px">点击或将文件拖拽到这里上传</div>
             <div style="font-size: 14px; color: rgba(0, 0, 0, 0.45)"
-              >文件只支持:.xlsx .xls .仅支持上传一个文件</div
+              >文件支持.xlsx .xls格式,仅支持上传一个文件</div
             ></div
           >
         </el-upload>
         <div style="margin-top: 52px; display: flex">
-          <el-button @click="handleDownloadInfoForm" style="margin-right: 10px; margin-left: auto"
+          <!-- <el-button @click="handleDownloadInfoForm" style="margin-right: 10px; margin-left: auto"
             >组织/用户id信息</el-button
-          >
+          > -->
+          <el-icon :size="18" style="margin-top: 7px; margin-left: auto">
+            <Download />
+          </el-icon>
+          <el-tooltip content="点击下载场景字段对应的code信息" placement="top" effect="light">
+            <span
+              style="color: #409efc; margin-top: 6px; margin-right: 12px; cursor: pointer"
+              @click="handleDownloadInfoForm"
+              >场景code信息查询</span
+            >
+          </el-tooltip>
+
           <el-button @click="handleDownload" style="margin-right: 10px">下载模板</el-button>
-          <el-button type="primary" @click="handleImport">导入</el-button></div
+          <el-button type="primary" @click="handleImport" :disabled="isImportEnable"
+            >导入</el-button
+          ></div
         ></div
       >
     </el-card>
@@ -145,7 +160,7 @@
 
 <script setup lang="ts">
   // import { Close, Document, CircleCheck, Warning } from '@element-plus/icons-vue';
-  import { Close, Document } from '@element-plus/icons-vue';
+  import { Close, Document, Download } from '@element-plus/icons-vue';
   import { ref } from 'vue';
   import { genFileId, ElMessage } from 'element-plus';
   import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
@@ -180,7 +195,7 @@
   //更多
   // const showMore = ref(false);
 
-  const isSuc = ref<boolean>(true);
+  // const isSuc = ref<boolean>(true);
   // const errDetail = ref<string[]>([]);
   const errDetail = ref<string[]>([]);
   // const sucCount = ref<number>(0);
@@ -269,11 +284,45 @@
   };
 
   const handleUploadSuccess = (response, _file, _fileList) => {
-    isSuc.value = response.data.isSuc;
+    console.log(response);
+    // isSuc.value = response.data.isSuc;
     errDetail.value = response.data.errorList;
     successCount.value = response.data.successCount || 0;
     errorCount.value = response.data.errorCount || 0;
 
+    try {
+      if (errDetail.value.length > 0) {
+        errDetail.value.forEach((item, index) => {
+          if (item.indexOf('【添加失败】') >= 0) {
+            errDetail.value[index] = item.replace(
+              '【添加失败】',
+              '<span style="color: #ff4d4f">【添加失败】</span>',
+            );
+          } else if (item.indexOf('【添加成功】') >= 0) {
+            errDetail.value[index] = item.replace(
+              '【添加成功】',
+              '<span style="color: #52c41a">【添加成功】</span>',
+            );
+          }
+        });
+      }
+
+      if (successCount.value != 0 && errorCount.value === 0 && errDetail.value.length === 0) {
+        ElMessage({
+          message: '添加成功', // 1.全部添加成功 —— failCount === 0
+          type: 'success',
+        });
+        emits('update:modelValue', true);
+      }
+      cardVisible.value = false;
+    } catch (error) {
+      ElMessage({
+        message: response.message,
+        type: 'error',
+      });
+      emits('update:modelValue', false);
+    }
+
     DialogVisible.value = true;
 
     // if (isSuc.value) {
@@ -283,7 +332,7 @@
     //   DialogVisibleSuc.value = false;
     //   DialogVisibleErr.value = true;
     // }
-    cardVisible.value = false;
+    // cardVisible.value = false;
   };
 
   // const handleRightComfirm = () => {
@@ -305,6 +354,17 @@
     upload.value!.handleStart(file);
   };
 
+  //用于没有上传文件时导入按钮置灰
+  const isImportEnable = ref<boolean>(true);
+
+  const handleChange = () => {
+    isImportEnable.value = false;
+  };
+
+  const handleRemove = () => {
+    isImportEnable.value = true;
+  };
+
   //对话框
 </script>
 
@@ -327,7 +387,7 @@
     border-radius: 50%;
     background: #ff4d4f;
     vertical-align: middle;
-    margin-left: 30px;
+    /* margin-left: 30px; */
     margin-right: 8px;
   }