南昌市物联网技防平台-前端
liuyg
2021-04-28 33298bf2b94d3e100e82aa1a1d41c7a414193e3b
Merge branch 'master' of http://192.168.0.105:10010/r/jfpt-Vue
1 files modified
466 ■■■■ changed files
src/page/login/codelogin.vue 466 ●●●● patch | view | raw | blame | history
src/page/login/codelogin.vue
@@ -51,15 +51,17 @@
        <i slot="prefix" class="icon-shouji"/>
      </el-input>
    </el-form-item>
    <el-select v-model="loginForm.deptid" placeholder="请选择部门" style="width: 580px;">
      <el-option
        v-for="item in options"
        :key="item.code"
        :label="item.deptname"
        :value="item.deptid">
      </el-option>
      <i slot="prefix" class="icon-yonghu"/>
    </el-select>
    <!--    <el-select v-model="loginForm.deptid" placeholder="请选择部门" style="width: 580px;">-->
    <!--      <el-option-->
    <!--        v-for="item in options"-->
    <!--        :key="item.code"-->
    <!--        :label="item.deptname"-->
    <!--        :value="item.deptid">-->
    <!--      </el-option>-->
    <!--      <i slot="prefix" class="icon-yonghu"/>-->
    <!--    </el-select>-->
    <avue-input-tree style="width:580px !important" default-expand-all v-model="loginForm.deptid" placeholder="请选择部门" type="tree"
                     :dic="dic"></avue-input-tree>
    <div style="margin-top: 16px">
      <el-radio v-model="loginForm.sex" label="0" border size="medium">男</el-radio>
      <el-radio v-model="loginForm.sex" label="1" border size="medium">女</el-radio>
@@ -68,222 +70,266 @@
      <el-button size="small"
                 type="primary"
                 @click.native.prevent="handleLogin"
                 class="z-login-submit">{{$t('login.zc')}}</el-button>
                 class="z-login-submit">{{ $t('login.zc') }}
      </el-button>
      <el-button size="small"
                 @click.native.prevent="gbs"
                 class="z-login-submit">{{$t('login.gb')}}</el-button>
                 class="z-login-submit">{{ $t('login.gb') }}
      </el-button>
    </el-form-item>
  </el-form>
</template>
<script>
  import { isvalidatemobile } from "@/util/validate";
  import {inster} from "@/api/zc/zc";
  import {fetch,ss} from "@/api/system/dept";
  import { mapGetters } from "vuex";
  export default {
    name: "codelogin",
    data() {
      const validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          callback();
        }
      };
      const validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.loginForm.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      const validatePhone = (rule, value, callback) => {
        if (isvalidatemobile(value)[0]) {
          callback(new Error(isvalidatemobile(value)[1]));
        } else {
          callback();
        }
      };
      const validateCode = (rule, value, callback) => {
        if (value.length !== 4) {
          callback(new Error("请输入4位数的验证码"));
        } else {
          callback();
        }
      };
import {isvalidatemobile} from "@/util/validate";
import {inster} from "@/api/zc/zc";
import {fetch, ss} from "@/api/system/dept";
import {mapGetters} from "vuex";
export default {
  name: "codelogin",
  data() {
    const validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        callback();
      }
    };
    const validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.loginForm.password) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    const validatePhone = (rule, value, callback) => {
      if (isvalidatemobile(value)[0]) {
        callback(new Error(isvalidatemobile(value)[1]));
      } else {
        callback();
      }
    };
    const validateCode = (rule, value, callback) => {
      if (value.length !== 4) {
        callback(new Error("请输入4位数的验证码"));
      } else {
        callback();
      }
    };
    return {
      msgText: "",
      msgTime: "",
      dic: [],
      msgKey: false,
      loginForm: {
        phone: "",
        username: "",
        sname: "",
        password: "",
        sex: null,
        deptid: '',
        password2: ""
      },
      value: '',
      options: [],
      loginRules: {
        phone: [{required: true, trigger: "blur", validator: validatePhone}],
        code: [{required: true, trigger: "blur", validator: validateCode}],
        password: [{required: true, validator: validatePass, trigger: 'blur'}],
        password2: [{required: true, validator: validatePass2, trigger: 'blur'}],
        username: [
          {required: true, message: "请输入用户名", trigger: "blur"}
        ],
      },
      passwordType: "password",
      passwordTypes: "password2"
    };
  },
  created() {
    this.msgText = this.config.MSGINIT;
    this.msgTime = this.config.MSGTIME;
  },
  mounted() {
    var that = this;
    //this.allmedia();
    ss().then(res => {
      that.dic = that.ergodicData(res.data.data)
    });
  },
  computed: {
    ...mapGetters(["tagWel"]),
    config() {
      return {
        msgText: "",
        msgTime: "",
        msgKey: false,
        loginForm: {
          phone: "",
          username: "",
          sname: "",
          password: "",
          sex: null,
          deptid:'',
          password2:""
        },
        value:'',
        options: [],
        loginRules: {
          phone: [{ required: true, trigger: "blur", validator: validatePhone }],
          code: [{ required: true, trigger: "blur", validator: validateCode }],
          password: [{required: true, validator: validatePass, trigger: 'blur'}],
          password2: [{required: true, validator: validatePass2, trigger: 'blur'}],
          username: [
            {required: true, message: "请输入用户名", trigger: "blur"}
          ],
        },
        passwordType: "password",
        passwordTypes: "password2"
        MSGINIT: this.$t("login.msgText"),
        MSGSCUCCESS: this.$t("login.msgSuccess"),
        MSGTIME: 60
      };
    },
    created() {
      this.msgText = this.config.MSGINIT;
      this.msgTime = this.config.MSGTIME;
    },
    mounted() {
      this.allmedia();
    },
    computed: {
      ...mapGetters(["tagWel"]),
      config() {
        return {
          MSGINIT: this.$t("login.msgText"),
          MSGSCUCCESS: this.$t("login.msgSuccess"),
          MSGTIME: 60
        };
      }
    },
    props: [],
    methods: {
      clearValidate(formName) {
        this.$refs[formName].clearValidate();
      },
      async allmedia() {
        ss().then(res => {
           res.data.data.forEach(element => {
             this.options.push({deptname:element.dept_name,deptid:element.deptid});
           })
        });
        // let res = await fetch('/api/blade-system/dept/selectInfo');
        // res.data.forEach(element => {
        //   this.options.push({deptname:element.dept_name,deptid:element.deptid});
        // })
      },
      refreshCode(row) {
        inster(row).then(res => {
          this.loginForm.phone=""
          this.loginForm.username=""
          this.loginForm.sname=""
          this.loginForm.sex=null
          this.loginForm.password=""
          this.loginForm.password2=""
          this.loginForm.deptid=""
          this.$notify({
            title: '注册成功,待审核',
            type: 'warning'
          });
        })
        var z = document.querySelector('.z');
        z.style.display = 'none';
        this.clearValidate('loginForm')
        this.clearValidate('loginForm')
      },
      gb() {
        this.loginForm.phone=""
        this.loginForm.username=""
        this.loginForm.sname=""
        this.loginForm.sex=null
        this.loginForm.password=""
        this.loginForm.password2=""
        this.loginForm.deptid=""
        var zs = document.querySelector('.z');
        zs.style.display = 'none';
        this.clearValidate('loginForm')
      },
      handleSend() {
        if (this.msgKey) return;
        this.msgText = this.msgTime + this.config.MSGSCUCCESS;
        this.msgKey = true;
        const time = setInterval(() => {
          this.msgTime--;
          this.msgText = this.msgTime + this.config.MSGSCUCCESS;
          if (this.msgTime === 0) {
            this.msgTime = this.config.MSGTIME;
            this.msgText = this.config.MSGINIT;
            this.msgKey = false;
            clearInterval(time);
          }
        }, 1000);
      },
      showPassword() {
        this.passwordType === ""
          ? (this.passwordType = "password")
          : (this.passwordType = "");
      },
      showPasswords() {
        this.passwordType === ""
          ? (this.passwordType = "password2")
          : (this.passwordType = "");
      },
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.refreshCode(this.loginForm);
            this.message('dahsiofhiusa');
            return Promise.reject(new Error("注册成功,待审核"));
          }
        });
      },
      gbs(){
        this.gb();
      }
    }
  },
  props: [],
  methods: {
    ergodicData(val) {
      var arr = [];
      arr.push({label: val[0].title, value: val[0].value, id: val[0].id, parent_id: val[0].parent_id});
      if (val.length > 1) {
        val.forEach((item, index) => {
          if (index > 0) {
            var ind = true;
            var arrInd = 0;
            arr.forEach((it, i) => {
              if (item.parent_id == it.id) {
                ind = false;
                arrInd = i;
                return
              }
            })
            if (ind == false) {
              if (arr[arrInd].children && arr[arrInd].children.length > 0) {
                arr[arrInd].children.push({label: item.title, value: item.value, id: item.id, parent_id: item.parent_id});
              } else {
                arr[arrInd].children = [];
                arr[arrInd].children.push({label: item.title, value: item.value, id: item.id, parent_id: item.parent_id});
              }
            } else {
              arr.push({label: item.title, value: item.value, id: item.id, parent_id: item.parent_id});
            }
          }
        })
      }
  };
      return arr;
    },
    clearValidate(formName) {
      this.$refs[formName].clearValidate();
    },
    async allmedia() {
      ss().then(res => {
        res.data.data.forEach(element => {
          this.options.push({deptname: element.dept_name, deptid: element.deptid});
        })
      });
      // let res = await fetch('/api/blade-system/dept/selectInfo');
      // res.data.forEach(element => {
      //   this.options.push({deptname:element.dept_name,deptid:element.deptid});
      // })
    },
    refreshCode(row) {
      console.log(this.loginForm)
      inster(row).then(res => {
        this.loginForm.phone = ""
        this.loginForm.username = ""
        this.loginForm.sname = ""
        this.loginForm.sex = null
        this.loginForm.password = ""
        this.loginForm.password2 = ""
        this.loginForm.deptid = ""
        this.$notify({
          title: '注册成功,待审核',
          type: 'warning'
        });
      })
      var z = document.querySelector('.z');
      z.style.display = 'none';
      this.clearValidate('loginForm')
      this.clearValidate('loginForm')
    },
    gb() {
      this.loginForm.phone = ""
      this.loginForm.username = ""
      this.loginForm.sname = ""
      this.loginForm.sex = null
      this.loginForm.password = ""
      this.loginForm.password2 = ""
      this.loginForm.deptid = ""
      var zs = document.querySelector('.z');
      zs.style.display = 'none';
      this.clearValidate('loginForm')
    },
    handleSend() {
      if (this.msgKey) return;
      this.msgText = this.msgTime + this.config.MSGSCUCCESS;
      this.msgKey = true;
      const time = setInterval(() => {
        this.msgTime--;
        this.msgText = this.msgTime + this.config.MSGSCUCCESS;
        if (this.msgTime === 0) {
          this.msgTime = this.config.MSGTIME;
          this.msgText = this.config.MSGINIT;
          this.msgKey = false;
          clearInterval(time);
        }
      }, 1000);
    },
    showPassword() {
      this.passwordType === ""
        ? (this.passwordType = "password")
        : (this.passwordType = "");
    },
    showPasswords() {
      this.passwordType === ""
        ? (this.passwordType = "password2")
        : (this.passwordType = "");
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        console.log(valid)
        if (valid) {
          this.refreshCode(this.loginForm);
          this.message('dahsiofhiusa');
          return Promise.reject(new Error("注册成功,待审核"));
        }
      });
    },
    gbs() {
      this.gb();
    }
  }
};
</script>
<style>
  .msg-text {
    display: block;
    width: 60px;
    font-size: 12px;
    text-align: center;
    cursor: pointer;
  }
  .msg-text.display {
    color: #ccc;
  }
.msg-text {
  display: block;
  width: 60px;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
}
  .z-login-submit-prv {
    margin-top: 20px;
    padding: 0 10%;
    box-sizing: border-box;
  }
.msg-text.display {
  color: #ccc;
}
  .z-login-submit-prv>div {
    width: 80%;
    display: flex;
  }
.z-login-submit-prv {
  margin-top: 20px;
  padding: 0 10%;
  box-sizing: border-box;
}
  .z-login-submit {
    flex: 1;
    height: 45px;
    border: 1px solid #409EFF;
    background: none;
    font-size: 18px;
    letter-spacing: 2px;
    font-weight: 300;
    color: #409EFF;
    cursor: pointer;
    font-family: "neo";
    -webkit-transition: 0.25s;
    transition: 0.25s;
  }
.z-login-submit-prv > div {
  width: 80%;
  display: flex;
}
.z-login-submit {
  flex: 1;
  height: 45px;
  border: 1px solid #409EFF;
  background: none;
  font-size: 18px;
  letter-spacing: 2px;
  font-weight: 300;
  color: #409EFF;
  cursor: pointer;
  font-family: "neo";
  -webkit-transition: 0.25s;
  transition: 0.25s;
}
</style>