yxh
yxh
7 天以前 8022f7036945b75f82f2dfc43055623f81ed98f6
src/views/login.vue
@@ -96,6 +96,7 @@
  data() {
    return {
      codeUrl: "",
      authCode: "",
      cookiePassword: "",
      loginForm: {
        username: "",
@@ -120,7 +121,7 @@
      },
      loading: false,
      // 验证码开关
      captchaOnOff: false,
      captchaOnOff: true,
      // 注册开关
      register: false,
      redirect: undefined
@@ -137,6 +138,8 @@
  created() {
    this.getCode();
    this.getCookie();
    this.getAuthCode();
    // this.avoidLogin();
  },
  methods: {
    tip() {
@@ -151,6 +154,47 @@
          this.loginForm.uuid = res.uuid;
        }
      });
    },
    getAuthCode() {
      this.$dingtalk.runtime.permission.requestAuthCode({
        corpId: "dingd31f00f4fbc0ff5bf5bf40eda33b7ba0",
        onSuccess: result => {
          // 在这里处理授权成功后的逻辑,result中包含授权码等信息
          // this.authCode = result.codde;
          this.$message.success("成功获取授权码:" + result.code);
          this.avoidLogin(result.code);
        },
        onFail: err => {
          // 在这里处理授权失败后的逻辑
          this.$message({
            type: "error",
            message: err
          });
        }
      });
    },
    avoidLogin(authCode) {
      this.loading = true;
      // this.$message.error(authCode, "1号位");
      this.loginForm.authCode = authCode;
      this.$store
        .dispatch("Login", this.loginForm)
        .then(res => {
          if (this.$store.state.user.code == 200) {
            this.$router.push({ path: this.redirect || "/" }).catch(() => {});
          } else {
            this.loading = false;
            // this.$message.error(this.$store.state.user.msg);
          }
        })
        .catch(err => {
          console.log(err);
          this.loading = false;
          this.$message.error("免登陆失败请手动操作。");
          if (this.captchaOnOff) {
            this.getCode();
          }
        });
    },
    getCookie() {
      const username = Cookies.get("username");
@@ -182,12 +226,22 @@
          }
          this.$store
            .dispatch("Login", this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || "/" }).catch(() => {});
            .then(res => {
              console.log(this.$store.state.user.code, "44");
              console.log(this.$store.state.user.msg, "22");
              if (this.$store.state.user.code == 200) {
                this.$router
                  .push({ path: this.redirect || "/" })
                  .catch(() => {});
              } else {
                this.loading = false;
                this.$message.error(this.$store.state.user.msg);
              }
            })
            .catch(() => {
            .catch(err => {
              console.log(err);
              this.loading = false;
              this.$message.error("登陆失败请重试。");
              // this.$message.error("登陆失败请重试。");
              if (this.captchaOnOff) {
                this.getCode();
              }
@@ -205,6 +259,15 @@
  justify-content: center;
  align-items: center;
  height: 100%;
  background-position: center center;
  /* 背景图不平铺 */
  background-repeat: no-repeat;
  /* 当内容高度大于图片高度时,背景图像的位置相对于viewport固定 */
  background-attachment: fixed;
  /* 让背景图基于容器大小伸缩 */
  background-size: cover;
  /* 设置背景颜色,背景图加载过程中会显示背景色 */
  background-color: #464646;
  background-image: url("../assets/images/login-bgc.jpg");
  background-size: cover;
}