123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876 |
- <template>
- <div class="reg">
- <header class="header">
- <div class="container">
- <img
- style="margin: 24px 0; width: 162px; height: 33px"
- v-if="header.companyLogo"
- :src="$tools.splitImgHost(header.companyLogo)"
- alt=""
- />
- <div v-else class="logo"></div>
- </div>
- </header>
- <section class="section">
- <div class="container">
- <div class="container-in">
- <div class="left-box"></div>
- <div class="right-box">
- <div class="login" v-if="state == 1">
- <div class="login__header">
- <div class="tabs">
- <div
- class="tab"
- :class="{ active: tabIndex == 0 }"
- @click="tabIndex = 0"
- >
- 普通登录
- </div>
- <div
- class="tab"
- :class="{ active: tabIndex == 1 }"
- @click="tabIndex = 1"
- >
- 手机快速登录
- </div>
- </div>
- </div>
- <div class="login__body">
- <div class="normal" v-if="tabIndex == 0">
- <el-form
- ref="loginForm"
- :rules="loginRules"
- :model="loginForm"
- >
- <div class="input">
- <el-form-item prop="account">
- <el-input
- placeholder="手机号/身份证号"
- v-model="loginForm.account"
- ></el-input>
- </el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="pwd"
- ><el-input
- placeholder="密码"
- type="pwd"
- v-model="loginForm.pwd"
- >
- <i
- slot="suffix"
- class="el-icon-view btn"
- ></i> </el-input
- ></el-form-item>
- </div>
- <div class="text">
- <a @click="state = 2">立即注册</a>
- <a @click="state = 3">找回密码</a>
- </div>
- <el-button
- class="submit"
- @click="login"
- type="primary"
- round
- :loading="islogin"
- >登录</el-button
- >
- </el-form>
- </div>
- <div class="phone" v-if="tabIndex == 1">
- <el-form
- ref="loginSmsForm"
- :rules="loginSmsRules"
- :model="loginSmsForm"
- >
- <div class="input">
- <el-form-item prop="tel"
- ><el-input
- placeholder="手机号"
- v-model="loginSmsForm.tel"
- ></el-input
- ></el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="code"
- ><el-input
- placeholder="短信验证码"
- v-model="loginSmsForm.code"
- >
- <span
- slot="suffix"
- @click="getLoginSms"
- class="btn"
- >{{
- countDown == 0
- ? "获取验证码"
- : `${countDown}秒重新获取`
- }}</span
- >
- </el-input></el-form-item
- >
- </div>
- <div class="text">
- <a @click="state = 2">立即注册</a>
- <a @click="state = 3">找回密码</a>
- </div>
- <el-button
- class="submit"
- @click="loginSms"
- :loading="isloginSms"
- type="primary"
- round
- >登录</el-button
- >
- </el-form>
- </div>
- </div>
- </div>
- <div class="register" v-if="state == 2">
- <el-form
- :model="registerForm"
- ref="registerForm"
- :rules="registerRules"
- >
- <div class="register__header">
- <div class="title">账号注册</div>
- </div>
- <div class="register__body">
- <div class="input">
- <el-form-item prop="tel"
- ><el-input
- placeholder="手机号"
- v-model="registerForm.tel"
- ></el-input
- ></el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="code">
- <el-input
- placeholder="获取验证码"
- v-model="registerForm.code"
- >
- <span class="btn" slot="suffix" @click="getRegisterSms">
- {{
- registerCountDown == 0
- ? "获取验证码"
- : `${registerCountDown}秒重新获取`
- }}
- </span>
- </el-input>
- </el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="pwd"
- ><el-input placeholder="密码" v-model="registerForm.pwd">
- <i class="el-icon-view"></i> </el-input
- ></el-form-item>
- </div>
- <div class="text">
- 已有账号?
- <a @click="state = 1">去登录</a>
- </div>
- <div class="checkbox">
- <el-form-item prop="read">
- <div>
- <input type="checkbox" v-model="registerForm.read" />
- 我已认真阅读并同意
- </div>
- <div>
- <a>《用户使用协议》</a>
- 及
- <a>《个人信息保护政策》</a>
- </div>
- </el-form-item>
- </div>
- <el-button
- class="submit"
- @click="register"
- type="primary"
- round
- :loading="isRegister"
- >注册</el-button
- >
- </div>
- </el-form>
- </div>
- <div class="findpwd" v-if="state == 3">
- <el-form
- :model="forgetForm"
- :rules="forgetRules"
- ref="forgetForm"
- >
- <div class="findpwd__header">
- <div class="title">找回密码</div>
- </div>
- <div class="findpwd__body">
- <div class="input">
- <el-form-item prop="tel"
- ><el-input placeholder="手机号" v-model="forgetForm.tel">
- </el-input
- ></el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="code">
- <el-input
- placeholder="短信验证码"
- v-model="forgetForm.code"
- >
- <span class="btn" slot="suffix">获取验证码</span>
- </el-input></el-form-item
- >
- </div>
- <div class="input">
- <el-form-item prop="pwd">
- <el-input placeholder="密码" v-model="forgetForm.pwd">
- <i class="el-icon-view btn" slot="suffix"></i>
- </el-input>
- </el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="pwdAgain"
- ><el-input
- placeholder="再次输入密码"
- v-model="forgetForm.pwdAgain"
- >
- <i
- class="el-icon-view btn"
- slot="suffix"
- ></i> </el-input
- ></el-form-item>
- </div>
- <div class="text">
- <a @click="state = 1">登录</a>
- <a @click="state = 2">注册</a>
- </div>
- <el-button
- class="submit"
- type="primary"
- :loading="isForget"
- round
- @click="forget"
- >确定</el-button
- >
- </div>
- </el-form>
- </div>
- <div class="findpwd" v-if="state == 4">
- <el-form :model="bindForm" :rules="bindRules" ref="bindForm">
- <div class="findpwd__header">
- <div class="title">关联学员身份</div>
- </div>
- <div class="findpwd__body">
- <div class="input">
- <el-form-item prop="realname"
- ><el-input
- placeholder="真实姓名"
- v-model="bindForm.realname"
- >
- </el-input
- ></el-form-item>
- </div>
- <div class="input">
- <el-form-item prop="idCard">
- <el-input
- placeholder="身份证号码"
- v-model="bindForm.idCard"
- >
- </el-input
- ></el-form-item>
- </div>
- <el-button
- class="submit"
- type="primary"
- :loading="isBind"
- round
- @click="bind"
- >确定</el-button
- >
- <div class="bind-next" @click="nextBind">下次再关联</div>
- </div>
- </el-form>
- </div>
- </div>
- </div>
- </div>
- </section>
- <Footer></Footer>
- </div>
- </template>
- <script>
- import Footer from "@/components/footer/index";
- import { mapGetters } from "vuex";
- import { mapMutations } from "vuex";
- export default {
- name: "login",
- components: {
- Footer,
- },
- data() {
- const pwdAgainCheck = async (rule, value, callback) => {
- if (!value) {
- return callback(new Error("请再次输入新密码"));
- } else if (this.forgetForm.pwd != this.forgetForm.pwdAgain) {
- return callback(new Error("两次输入密码不一致!"));
- } else {
- callback();
- }
- };
- return {
- state: 1, //1登录 2注册 3找回密码 4绑定学员身份
- tabIndex: 0,
- loginForm: {},
- loginSmsForm: {},
- registerForm: {},
- forgetForm: {},
- bindForm: {},
- countDown: 0,
- countDownTimer: null,
- registerCountDown: 0,
- registerCountDownTimer: null,
- forgetCountDown: 0,
- forgetCountDownTimer: null,
- getLoginCodeLock: false,
- getRegisterCodeLock: false,
- getForgetCodeLock: false,
- getBindCodeLock: false,
- loginRules: {
- account: [
- { required: true, trigger: "blur", message: "请输入手机号/身份证号" },
- ],
- pwd: [{ required: true, trigger: "blur", message: "请输入密码" }],
- },
- loginSmsRules: {
- code: [{ required: true, trigger: "blur", message: "请输入验证码" }],
- tel: [{ required: true, trigger: "blur", message: "请输入手机号" }],
- },
- forgetRules: {
- code: [{ required: true, trigger: "blur", message: "请输入验证码" }],
- tel: [{ required: true, trigger: "blur", message: "请输入手机号" }],
- pwd: [{ required: true, trigger: "blur", message: "请输入新密码" }],
- pwdAgain: [
- {
- required: true,
- validator: pwdAgainCheck,
- trigger: "blur",
- },
- ],
- },
- registerRules: {
- code: [{ required: true, trigger: "blur", message: "请输入验证码" }],
- tel: [{ required: true, trigger: "blur", message: "请输入手机号" }],
- pwd: [{ required: true, trigger: "blur", message: "请输入密码" }],
- read: [{ required: true, trigger: "blur", message: "请勾选服务协议" }],
- },
- bindRules: {
- realname: [
- { required: true, trigger: "blur", message: "请输入真实姓名" },
- ],
- idCard: [
- { required: true, trigger: "blur", message: "请输入身份证号" },
- ],
- },
- islogin: false,
- isloginSms: false,
- isRegister: false,
- isForget: false,
- isBind: false,
- user_account: "",
- token: "",
- };
- },
- computed: {
- ...mapGetters(["header"]),
- },
- mounted() {
- this.state = this.$route.query.state || 1;
- },
- methods: {
- ...mapMutations(["setUserInfo"]),
- /**
- * 账号密码登录
- */
- login() {
- this.$refs.loginForm.validate((valid) => {
- if (valid) {
- this.islogin = true;
- this.$request
- .login(this.loginForm)
- .then((res) => {
- if (res.data.full_info) {
- localStorage.setItem("user_account", res.data.user_account);
- localStorage.setItem("token", res.data.token);
- this.getInfo();
- } else {
- this.user_account = res.data.user_account;
- this.token = res.data.token;
- this.islogin = false;
- this.state = 4;
- }
- })
- .catch((err) => {
- this.islogin = false;
- this.$message({
- message: err.msg,
- type: "error",
- });
- });
- }
- });
- },
- /**
- * 获取登录短信
- */
- getLoginSms() {
- this.$refs.loginSmsForm.validateField("tel", (valid) => {
- if (!valid) {
- if (this.countDown == 0) {
- if (this.getLoginCodeLock) {
- return;
- }
- this.getLoginCodeLock = true;
- this.$request
- .getLoginSms({ tel: this.loginSmsForm.tel })
- .then((res) => {
- this.getLoginCodeLock = false;
- this.$message({
- message: `验证码已发送`,
- type: "success",
- });
- this.countDown = 60;
- this.countDownTimer = setInterval(() => {
- if (this.countDown == 0) {
- clearInterval(this.countDownTimer);
- } else {
- this.countDown--;
- }
- }, 1000);
- })
- .catch((err) => {
- this.getLoginCodeLock = false;
- });
- }
- }
- });
- },
- /**
- * 手机号登录
- */
- loginSms() {
- this.$refs.loginSmsForm.validate((valid) => {
- if (valid) {
- this.isloginSms = true;
- this.$request
- .loginSms(this.loginSmsForm)
- .then((res) => {
- if (res.data.full_info) {
- localStorage.setItem("user_account", res.data.user_account);
- localStorage.setItem("token", res.data.token);
- this.getInfo();
- } else {
- this.user_account = res.data.user_account;
- this.token = res.data.token;
- this.isloginSms = false;
- this.state = 4;
- }
- })
- .catch((err) => {
- this.isloginSms = false;
- this.$message({
- message: err.msg,
- type: "error",
- });
- });
- }
- });
- },
- /**
- * 获取用户登录信息
- */
- getInfo() {
- this.$request
- .getInfo()
- .then((res) => {
- this.isRegister = false;
- this.islogin = false;
- this.isloginSms = false;
- this.setUserInfo(res.data);
- this.$router.replace("/");
- })
- .catch((err) => {
- this.isRegister = false;
- this.islogin = false;
- this.isloginSms = false;
- this.$message({
- message: err.msg,
- type: "error",
- });
- });
- },
- /**
- * 注册
- */
- register() {
- this.$refs.registerForm.validate((valid) => {
- if (valid) {
- this.isRegister = true;
- this.$request
- .registerUser(this.registerForm)
- .then((res) => {
- //自动登录
- this.autoLogin();
- })
- .catch((err) => (this.isRegister = false));
- }
- });
- },
- /**
- * 获取注册验证码
- */
- getRegisterSms() {
- this.$refs.registerForm.validateField("tel", (valid) => {
- if (!valid) {
- if (this.registerCountDown == 0) {
- if (this.getRegisterCodeLock) {
- return;
- }
- this.getRegisterCodeLock = true;
- this.$request
- .getLoginSms({ tel: this.loginSmsForm.tel })
- .then((res) => {
- this.getRegisterCodeLock = false;
- this.$message({
- message: `验证码已发送`,
- type: "success",
- });
- this.registerCountDown = 60;
- this.registerCountDownTimer = setInterval(() => {
- if (this.registercountDown == 0) {
- clearInterval(this.registerCountDownTimer);
- } else {
- this.registerCountDown--;
- }
- }, 1000);
- })
- .catch((err) => {
- this.$message({
- message: err.msg,
- type: "error",
- });
- this.getRegisterCodeLock = false;
- });
- }
- }
- });
- },
- /**
- * 注册后自动登录并跳转绑定身份信息
- */
- autoLogin() {
- let loginForm = JSON.parse(JSON.stringify(this.registerForm));
- loginForm.account = loginForm.tel;
- this.$request
- .login(loginForm)
- .then((res) => {
- if (res.data.full_info) {
- //信息完善,获取用户信息
- localStorage.setItem("user_account", res.data.user_account);
- localStorage.setItem("token", res.data.token);
- this.getInfo();
- } else {
- //不完善,跳转完善信息页面
- this.user_account = res.data.user_account;
- this.token = res.data.token;
- this.isRegister = false;
- this.state = 4;
- }
- })
- .catch((err) => {
- this.isRegister = false;
- this.$message({
- message: err.msg,
- type: "error",
- });
- });
- },
- forget() {
- this.$refs.forgetForm.validate((valid) => {
- if (valid) {
- this.isForget = true;
- this.$request
- .forgetUser(this.forgetForm)
- .then((res) => {
- this.isForget = false;
- this.$message({
- message: "修改成功",
- type: "success",
- });
- this.$refs.forgetForm.resetFields();
- })
- .catch((err) => (this.isForget = false));
- }
- });
- },
- nextBind() {
- this.state = 1;
- this.user_account = "";
- this.token = "";
- },
- bind() {
- this.$refs.bindForm.validate((valid) => {
- if (valid) {
- this.isBind = true;
- let bindForm = JSON.parse(JSON.stringify(this.bindForm));
- bindForm.token = this.token;
- this.$request
- .bindIdCard(this.bindForm)
- .then((res) => {
- this.isBind = false;
- this.$message({
- message: "关联成功",
- type: "success",
- });
- localStorage.setItem("user_account", this.user_account);
- localStorage.setItem("token", this.token);
- this.getInfo();
- this.$router.replace("/");
- })
- .catch((err) => {
- this.isBind = false;
- this.$message({
- message: err.msg,
- type: "error",
- });
- });
- }
- });
- },
- },
- };
- </script>
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style scoped lang="scss">
- .reg {
- .header {
- box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.04);
- overflow: hidden;
- .logo {
- margin: 24px 0;
- width: 162px;
- height: 33px;
- background: url("~@/assets/logo.png") no-repeat center;
- }
- }
- .section {
- background: #f2f7ff;
- .container-in {
- width: 100%;
- height: 507px;
- }
- .left-box {
- float: left;
- width: 496px;
- height: 318px;
- background: green;
- margin-top: 95px;
- margin-left: 152px;
- }
- .right-box {
- float: right;
- width: 348px;
- height: 427px;
- background: #ffffff;
- box-shadow: 0px 0px 13px 3px rgba(63, 141, 253, 0.1);
- border-radius: 8px;
- margin-top: 40px;
- margin-right: 140px;
- .el-form-item {
- margin: 0;
- }
- .login {
- &__header {
- border-bottom: 2px solid #eee;
- .tabs {
- display: flex;
- width: 100%;
- .tab {
- cursor: pointer;
- text-align: center;
- color: #999;
- flex: 1;
- height: 42px;
- line-height: 42px;
- position: relative;
- &.active {
- &::after {
- content: "";
- display: block;
- position: absolute;
- width: 138px;
- height: 2px;
- background: #3f8dfd;
- border-radius: 0px;
- bottom: -2px;
- left: 50%;
- margin-left: -69px;
- }
- }
- }
- }
- }
- &__body {
- padding: 16px 24px 0;
- overflow: hidden;
- .input {
- margin-top: 24px;
- .btn {
- font-size: 14px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #3f8dfd;
- white-space: nowrap;
- cursor: pointer;
- }
- }
- .text {
- margin-top: 24px;
- display: flex;
- justify-content: space-between;
- }
- .submit {
- margin-top: 40px;
- width: 300px;
- }
- }
- }
- .register {
- &__header {
- border-bottom: 2px solid #eee;
- .title {
- height: 42px;
- line-height: 42px;
- text-align: center;
- color: #999;
- }
- }
- &__body {
- padding: 0 24px;
- overflow: hidden;
- .input {
- margin-top: 24px;
- .btn {
- font-size: 14px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #3f8dfd;
- white-space: nowrap;
- cursor: pointer;
- }
- }
- .text {
- margin-top: 10px;
- text-align: right;
- a {
- color: #3f8dfd;
- }
- }
- .checkbox {
- margin-top: 10px;
- a {
- color: #3f8dfd;
- }
- /deep/ .el-form-item__content {
- line-height: 20px;
- }
- }
- .submit {
- margin-top: 20px;
- width: 300px;
- }
- }
- }
- }
- .findpwd {
- &__header {
- border-bottom: 2px solid #eee;
- .title {
- height: 42px;
- line-height: 42px;
- text-align: center;
- color: #999;
- }
- }
- &__body {
- padding: 0 24px;
- overflow: hidden;
- .input {
- margin-top: 24px;
- .btn {
- font-size: 14px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #3f8dfd;
- white-space: nowrap;
- cursor: pointer;
- }
- }
- .text {
- margin-top: 14px;
- display: flex;
- justify-content: space-between;
- }
- .submit {
- margin-top: 30px;
- width: 300px;
- }
- .bind-next {
- font-size: 14px;
- text-align: center;
- color: #999;
- margin-top: 10px;
- cursor: pointer;
- }
- }
- }
- }
- }
- </style>
|