Browse Source

新增用户 导入用户修改

duy 1 tuần trước cách đây
mục cha
commit
ffabd2ec85
1 tập tin đã thay đổi với 41 bổ sung10 xóa
  1. 41 10
      src/views/system/user.vue

+ 41 - 10
src/views/system/user.vue

@@ -334,6 +334,7 @@
             :option="excelOption"
             v-model="excelForm"
             :upload-after="uploadAfter"
+             ref="excelForm"
           >
             <template slot="excelTemplate">
               <el-button
@@ -642,10 +643,16 @@ export default {
                 label: "登录账号",
                 prop: "account",
                 rules: [{
-                  required: true,
-                  message: "请输入登录账号",
-                  trigger: "blur"
-                }],
+                // 动态校验:若手机号为空则账号必填,否则可选(后续会自动用手机号填充)
+                validator: (rule, value, callback) => {
+                  if (!value && !this.form.phone) {
+                    callback(new Error("请输入登录账号")); // 账号和手机号都为空时提示
+                  } else {
+                    callback(); // 有一个不为空则通过
+                  }
+                },
+                trigger: "blur"
+              }],
               },
               {
                 label: '密码',
@@ -1012,6 +1019,7 @@ export default {
       this.form.deptName = this.addData.deptId
       const column = this.findObject(this.option.group, 'deptId')
       column.value = this.addData.deptId
+
       this.$refs.crud.rowAdd()
     },
     addProject(type) {//确定添加参建项目
@@ -1337,7 +1345,10 @@ export default {
     },
     rowSave(row, done, loading) { //新增保存
       console.log('保存',this.fromss.projectAndUserList);
-
+       // 新增时:若未输入登录账号但输入了手机号,则自动用手机号作为登录账号
+      if (!row.account && row.phone) {
+        row.account = row.phone; // 将手机号赋值给登录账号
+      }
         let projectAndUserList = []
         this.fromss.projectAndUserList.forEach(val => {
           if (val.dataInfo.length > 0) {
@@ -1530,10 +1541,23 @@ export default {
       this.excelBox = true;
     },
     uploadAfter(res, done, loading, column) {
-      window.console.log(column);
-      this.excelBox = false;
-      this.refreshChange();
-      done();
+      // window.console.log(column);
+      // this.excelBox = false;
+      // this.refreshChange();
+      // done();
+        // 关闭导入弹窗
+        this.excelBox = false;
+        // 刷新数据列表
+        this.refreshChange();
+        // 重置上传表单中的文件字段
+        if (this.$refs.excelForm) {
+          // 清空上传的文件
+          this.excelForm.excelFile = null;
+          // 通知表单组件更新
+          this.$refs.excelForm.resetFields(['excelFile']);
+          this.excelForm.isCovered=0
+        }
+        done();
     },
     handleExport() {
       this.$confirm("是否导出用户数据?", "提示", {
@@ -1564,7 +1588,14 @@ export default {
             this.form.postId = this.form.postId.split(",");
           }
         });
-      } else {
+      }else if (type === 'add') {
+        // 新增时设置默认账号和密码
+     
+        this.form.password = 'user123456';
+        this.form.password2 = 'user123456';
+      
+      }
+       else {
         this.form.tenantId = this.addData.tenantId
       }