原生滑动通过

原生滑动通过

components/swipterBar/index.vue

<template>
  <div class="drag" ref="dragDiv">
    <div class="drag_bg"></div>
    <div class="drag_text">{{ confirmWords }}</div>
    <div
      ref="moveDiv"
      @mousedown="mousedownFn($event)"
      :class="{ handler_ok_bg: confirmSuccess }"
      class="handler handler_bg"
      style="position: absolute; top: 0px; left: 0px"
    ></div>
  </div>
</template>

<script>
export default {
  name: "swipterBar",
  props: ["ISuccessed"],
  data() {
    return {
      beginClientX: 0 /*距离屏幕左端距离*/,
      mouseMoveStata: false /*触发拖动状态 判断*/,
      maxwidth: "" /*拖动最大宽度,依据滑块宽度算出来的*/,
      confirmWords: "拖动滑块验证" /*滑块文字*/,
      confirmSuccess: false,
    };
  },
  updated() {},
  methods: {
    returnBegin() {
      this.mouseMoveStata = false;
      this.beginClientX = 0;
      this.confirmWords = "拖动滑块验证";
      this.confirmSuccess = false;
      let timer = setTimeout(() => {
        this.maxwidth =
          this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth;
        console.log(this.maxwidth, "this.maxwidth");
      }, 100);
      if (window.addEventListener) {
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mousemove", this.mouseMoveFn);
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mouseup", this.moseUpFn);
      } else {
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mouseup", () => {});
      }
      document
        .getElementsByTagName("html")[0]
        .addEventListener("mousemove", this.mouseMoveFn);
      document
        .getElementsByTagName("html")[0]
        .addEventListener("mouseup", this.moseUpFn);
      document.getElementsByClassName("handler")[0].style.left = 0 + "px";
      document.getElementsByClassName("drag_bg")[0].style.width = 0 + "px";
    },
    mousedownFn: function (e) {
      if (!this.confirmSuccess) {
        e.preventDefault && e.preventDefault(); //阻止文字选中等 浏览器默认事件
        this.mouseMoveStata = true;
        this.beginClientX = e.clientX;
      }
    }, //mousedoen 事件
    successFunction() {
      this.confirmSuccess = true;
      this.confirmWords = "验证通过";
      if (window.addEventListener) {
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mousemove", this.mouseMoveFn);
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mouseup", this.moseUpFn);
      } else {
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mouseup", () => {});
      }
      document.getElementsByClassName("drag_text")[0].style.color = "#fff";
      document.getElementsByClassName("handler")[0].style.left =
        this.maxwidth + "px";
      document.getElementsByClassName("drag_bg")[0].style.width =
        this.maxwidth + "px";
      this.$emit("ISuccessed");
    }, //验证成功函数
    mouseMoveFn(e) {
      if (this.mouseMoveStata) {
        let width = e.clientX - this.beginClientX;
        if (width > 0 && width <= this.maxwidth) {
          document.getElementsByClassName("handler")[0].style.left =
            width + "px";
          document.getElementsByClassName("drag_bg")[0].style.width =
            width + "px";
        } else if (width > this.maxwidth) {
          this.successFunction();
        }
      }
    }, //mousemove事件
    moseUpFn(e) {
      this.mouseMoveStata = false;
      var width = e.clientX - this.beginClientX;
      if (width < this.maxwidth) {
        document.getElementsByClassName("handler")[0].style.left = 0 + "px";
        document.getElementsByClassName("drag_bg")[0].style.width = 0 + "px";
      }
    }, //mouseup事件
  },
  mounted() {
    var that = this;
    window.onresize = function () {
      that.returnBegin();
    };
  },
  activated() {
    this.returnBegin();
  },
};
</script>

<style lang="less" scoped>
.drag {
  position: relative;
  background-color: #e8e8e8;
  width: 100%;
  height: 34px;
  line-height: 34px;
  text-align: center;
  .drag_bg {
    background-color: #7ac23c;
    height: 34px;
    width: 0px;
  }
  .drag_text {
    position: absolute;
    top: 0px;
    width: 100%;
    text-align: center;
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
    -o-user-select: none;
    -ms-user-select: none;
  }
  .handler {
    width: 40px;
    height: 32px;
    border: 1px solid #ccc;
    cursor: move;
  }
  .handler_bg {
    height: 34px;
    background: #fff
      url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJ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tZW50SUQ9InhtcC5kaWQ6NGQ4ZTVmOTMtOTZiNC00ZTVkLThhY2ItN2U2ODhmMjE1NmU2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+YiRG4AAAALFJREFUeNpi/P//PwMlgImBQkA9A+bOnfsIiBOxKcInh+yCaCDuByoswaIOpxwjciACFegBqZ1AvBSIS5OTk/8TkmNEjwWgQiUgtQuIjwAxUF3yX3xyGIEIFLwHpKyAWB+I1xGSwxULIGf9A7mQkBwTlhBXAFLHgPgqEAcTkmNCU6AL9d8WII4HOvk3ITkWJAXWUMlOoGQHmsE45ViQ2KuBuASoYC4Wf+OUYxz6mQkgwAAN9mIrUReCXgAAAABJRU5ErkJggg==")
      no-repeat center;
  }
  .handler_ok_bg {
    height: 34px;
    background: #fff
      url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMu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iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==")
      no-repeat center;
  }
}
</style>

userlogin.vue

<template>
  <div class="content">
    <h2>欢迎登录</h2>
    <div class="tab">
      <span :class="[tabIndex === 0 ? 'active' : '']" @click="changeTab(0)"
        >学员登录</span
      >
      <span :class="[tabIndex === 1 ? 'active' : '']" @click="changeTab(1)"
        >管理登录</span
      >
    </div>
    <el-form
      class="login-form"
      :rules="loginRules"
      ref="loginForm"
      :model="loginForm"
      label-width="74px"
    >
      <el-form-item prop="username" label="用户名" class="usernamebox">
        <el-input
          size="medium"
          @keyup.enter.native="handleLogin"
          v-model="loginForm.username"
          auto-complete="off"
          placeholder="请输入用户名"
        />
      </el-form-item>
      <el-form-item prop="password" label="密码">
        <el-input
          size="medium"
          @keyup.enter.native="handleLogin"
          :type="passwordType"
          v-model="loginForm.password"
          auto-complete="off"
          placeholder="请输入密码"
        />
      </el-form-item>
      <el-form-item prop="code" label="验证码">
        <el-row :span="24">
          <el-col :span="15">
            <el-input
              size="medium"
              @keyup.enter.native="handleLogin"
              :maxlength="code.len"
              v-model="loginForm.code"
              auto-complete="off"
              placeholder="请输入验证码"
            />
          </el-col>
          <el-col :span="9">
            <div class="login-code">
              <span
                class="login-code-img"
                @click="refreshCode"
                v-if="code.type == 'text'"
                >{{ code.value }}</span
              >
              <img
                :src="code.src"
                class="login-code-img"
                @click="refreshCode"
                v-else
              />
            </div>
          </el-col>
        </el-row>
      </el-form-item>
      <!-- <div v-show="tabIndex === 0" class="codey">
        <swipterbar ref="swipterbar" @ISuccessed="ISuccessed" />
      </div> -->
    </el-form>
    <div class="msg">{{ msg }}</div>
    <el-button
      type="primary"
      @click.native.prevent="handleLogin"
      class="login-submit"
      >立即登录</el-button
    >
    <div class="theWay">
      <a href="#"></a>
      <a href="#">忘记密码</a>
    </div>
  </div>
</template>

<script>
import { randomLenNum } from "@/util/util";
import { getLoginHint } from "@/api/students/login";
// import swipterbar from "@/components/swipterBar";
import { mapGetters } from "vuex";
export default {
  name: "userlogin",
  // components: {
  //   swipterbar,
  // },
  data() {
    return {
      tabIndex: 0,
      confirmSuccessIs: false,
      msg: "",
      loginForm: {
        username: "",
        password: "",
        code: "",
        redomStr: "",
      },
      checked: false,
      code: {
        src: "/code",
        value: "",
        len: 4,
        type: "image",
      },
      loginRules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, message: "密码长度最少为6位", trigger: "blur" },
        ],
        code: [{ required: true, message: "请输入验证码", trigger: "blur" }],
      },
      passwordType: "password",
    };
  },
  created() {
    this.refreshCode();
  },
  // activated() {
  // this.confirmSuccessIs = false;
  // },
  mounted() {},
  computed: {
    ...mapGetters(["tagWel"]),
  },
  props: [],
  methods: {
    // ISuccessed() {
    //   console.log("父组件被调用了");
    //   this.confirmSuccessIs = true;
    // },
    changeTab(e) {
      // this.$refs.swipterbar.returnBegin();
      this.msg = "";
      this.tabIndex = e;
    },
    refreshCode() {
      this.loginForm.code = "";
      this.loginForm.randomStr = randomLenNum(this.code.len, true);
      this.code.type === "text"
        ? (this.code.value = randomLenNum(this.code.len))
        : (this.code.src = `${this.codeUrl}?randomStr=${this.loginForm.randomStr}`);
    },
    showPassword() {
      this.passwordType == ""
        ? (this.passwordType = "password")
        : (this.passwordType = "");
    },
    showConfirm(data, index, code) {
      this.$Modal.confirm({
        title: data[index].title,
        content: data[index].template,
        okText: "确定",
        cancelText: "取消",
        onOk: () => {
          if (data[index].url) {
            // windows.location.href = data[index].url
            this.$router.push({ path: `${data[index].url}` });
            // this.$router.push({ path: `/stu?code=${data[index].url}` });
          }
        },
        onCancel: () => {
          const next = index + 1;
          if (data[next]) {
            setTimeout((res) => {
              this.showConfirm(data, next, code);
            }, 600);
          }
        },
      });
    },
    handleLogin() {
      this.msg = "";
      if (this.tabIndex === 1) {
        this.loginRules.code[0].required = false;
      }
      // if (this.tabIndex === 0 && !this.confirmSuccessIs) {
      //   this.msg='请进行滑动验证';
      //   return false;
      // }
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          if (this.tabIndex === 0) {
            this.Empty()
            this.$store
              .dispatch("StudentLogin", this.loginForm)
              .then((res) => {
                if (res.code === 10005) {
                  this.$router.push({
                    path: `/stu/dashboard?code=${res.code}`,
                  });
                } else {
                  this.$router.push({ path: `/stu?code=${res.code}` });
                  getLoginHint().then((resLogin) => {
                    if (resLogin.data.length) {
                      this.showConfirm(resLogin.data, 0, res.code);
                    }
                  });
                }
                // this.$router.push({ path: `/stu?code=${res.code}` });
              })
              .catch((err) => {
                if (
                  err == "账号或密码错误" ||
                  err == "当前用户处于待审核状态" ||
                  err == "验证码不能为空" ||
                  err == "用户名或密码错误"
                ) {
                  this.msg = err;
                  // this.confirmSuccessIs = false;
                  // this.$refs.swipterbar.returnBegin();
                }
              });
          } else {
            this.$store
              .dispatch("LoginByUsername", this.loginForm)
              .then((res) => {
                // if(Boolean(res.base_province)){
                //   this.$alert('请批量导入已招募的学员,并提醒学员收到注册码后请及时登录线上培训平台完善个人信息。', '注册通知', {
                //     confirmButtonText: '知道了',
                //     callback: action => {
                //       this.$alert('培训大纲已发布最新版本,请及时下载最新版培训大纲文件查看', '通知', {
                //         confirmButtonText: '知道了',
                //         callback: action => {
                //           this.message()
                //         }
                //       });
                //     }
                //   });
                // }else{
                this.message();
                // }
                this.$router.push({ path: this.tagWel.value });
              })
              .catch((err) => {
                this.refreshCode();
                if (
                  err == "验证码不合法" ||
                  err == "验证码不能为空" ||
                  err == "用户名或密码错误"
                ) {
                  this.msg = err;
                }
                
              });
          }
        }
      });
    },
    message() {
      // this.$store.dispatch('GetAdminMessageNum').then(numRes=>{
      //   if(numRes!==0){
      //     this.$confirm('你有未阅读系统消息,请及时阅读。', '通知', {
      //       confirmButtonText: '确定',
      //       cancelButtonText: '取消'
      //     }).then(() => {
      //       this.$router.push({path: "/wel/notice"});
      //     })
      //   }
      // })
    },
    //清空input事件
    Empty(){
      this.loginForm={
        username: "",
        password: "",
        code: "",
        redomStr: "",
      },
      this.$refs.loginForm.resetFields();
    },
    created: function () {
      console.log("建立");
    },
  },
};
</script>
<style lang="less" scoped>
.content {
  width: 100%;
  padding: 0 36px;
  height: 100%;
  display: block;
  @media screen and (max-width: 1300px) {
    margin-top: -50px;
  }
}
h2 {
  font-size: 40px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #333333;
  line-height: 36px;
  @media screen and (max-width: 1300px) {
    width: 100%;
  }
}
.tab {
  width: 80%;
  color: #999999;
  font-size: 18px;
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  font-family: "MicrosoftYaHei";
  @media screen and (max-width: 1300px) {
    width: 100%;
  }
  span {
    display: inline-block;
    padding: 50px 0 12px;
    cursor: pointer;
  }
  .active {
    color: #026e9f;
    border-bottom: 2px solid #026e9f;
  }
}
.login-form {
  border-top: 2px solid #eeeeee;
  margin-top: -2px;
}
.usernamebox {
  margin-top: 30px;
}
.el-form-item--small:nth-child(3) {
  margin-bottom: 0;
}
.el-form {
  width: 80%;
  @media screen and (max-width: 1300px) {
    width: 100%;
  }
}
.el-form-item__label {
  line-height: 50px;
  height: 50px;
}
.usernamewdh {
  margin-bottom: 18px;
  &:nth-child(1) {
    margin-top: 16px;
  }
}
.msg {
  font-size: 18px;
  color: red;
  text-align: center;
  height: 30px;
}
.content .el-button {
  height: 36px;
  width: 80%;
  @media screen and (max-width: 1300px) {
    width: 100%;
  }
}
.codey {
  height: 40px;
}
.theWay {
  width: 80%;
  @media screen and (max-width: 1300px) {
    width: 100%;
    margin-left: 0;
  }
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  a {
    font-size: 14px;
    color: #666;
    &:hover {
      color: #6794c7;
    }
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

圥忈&&丅佽&&扗虖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值