北京经济技术开发区经开区虚拟城市项目-【前端】-Web
lixuliang
2024-04-12 dbb352c9d988dfac83da979023fe81a0a02f88e9
src/components/login.vue
@@ -9,7 +9,6 @@
        :model="loginForm"
        :rules="rules"
        ref="loginForm"
        @keyup.enter.native="submitForm('loginForm')"
      >
        <el-form-item prop="loginname">
          <div class="user-box">
@@ -54,6 +53,7 @@
                class="nobr"
                autocomplete="off"
                clearable
                @keyup.enter.native="submitForm('loginForm')"
              >
              </el-input>
            </div>
@@ -108,7 +108,6 @@
  },
  created() {},
  mounted() {
    window.addEventListener("keydown", this.keyDown);
    // if (
    //   window.location.href.match(/=(\S*)#/) &&
    //   window.location.href.match(/=(\S*)#/)[1] != ""
@@ -125,68 +124,55 @@
      this.passCAFree();
    }
  },
  destroyed() {
    // 销毁事件
    window.removeEventListener("keydown", this.keyDown, false);
  },
  methods: {
    // 点击回车键登录
    keyDown(e) {
      // 回车则执行登录方法 enter键的ASCII是13
      if (e.keyCode == 13 || e.keyCode == 100) {
        this.submitForm("loginForm"); // 定义的登录方法
      }
    },
    // 账号密码登录
    submitForm(formName) {
      this.$router.push("/index");
      // this.$refs[formName].validate((valid) => {
      //   if (valid) {
      //     const loading = this.$loading({
      //       lock: true,
      //       text: "Loading",
      //       spinner: "el-icon-loading",
      //       background: "rgba(0, 0, 0, 0.7)",
      //     });
      //     login({
      //       username: this.loginForm.loginname,
      //       password: this.loginForm.password,
      //     })
      //       .then((res) => {
      //         loading.close();
      //         if (res.code !== 200) {
      //           this.$message.error(res.msg);
      //         } else {
      //           let tokenData = res.token;
      //           let times = new Date().getTime();
      //           window.localStorage.setItem("TokenTime", times);
      //           window.localStorage.setItem("TokenKey", tokenData);
      //           this.$router.push("/index");
      //         }
      //       })
      //       .catch((error) => {
      //         //网络超时异常处理
      //         loading.close();
      //         if (
      //           error.code === "ECONNABORTED" ||
      //           error.message === "Network Error" ||
      //           error.message.includes("timeout")
      //         ) {
      //           this.$message.error("请求超时,请稍后重试");
      //         }
      //         return Promise.resolve(error.response);
      //         // reject(error);
      //       });
      //     // //如果登录失败,需要刷新验证码的
      //     // this.$refs.refresh.createdCode();
      //     // this.validCode = ""; //清空验证码输入框的内容
      //   } else {
      //     // console.log("error submit!!");
      //     return false;
      //   }
      // });
      // this.$router.push("/index");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          login({
            username: this.loginForm.loginname,
            password: this.loginForm.password,
          })
            .then((res) => {
              loading.close();
              if (res.code !== 200) {
                this.$message.error(res.msg);
              } else {
                let tokenData = res.token;
                let times = new Date().getTime();
                window.localStorage.setItem("TokenTime", times);
                window.localStorage.setItem("TokenKey", tokenData);
                this.$router.push("/index");
              }
            })
            .catch((error) => {
              //网络超时异常处理
              loading.close();
              if (
                error.code === "ECONNABORTED" ||
                error.message === "Network Error" ||
                error.message.includes("timeout")
              ) {
                this.$message.error("请求超时,请稍后重试");
              }
              return Promise.resolve(error.response);
              // reject(error);
            });
          // //如果登录失败,需要刷新验证码的
          // this.$refs.refresh.createdCode();
          // this.validCode = ""; //清空验证码输入框的内容
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    // CA免密登录
    passCAFree() {
@@ -417,7 +403,7 @@
  bottom: -160px;
  animation: square 20s linear infinite;
  border-radius: 45%;
  box-shadow: 0px 0px 10px rgba(255,255,255,0.5);
  box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.5);
}
.bg-squares li:nth-child(1) {