From 67aa47adb8a90abcdb992cabfacdf677cdb4886b Mon Sep 17 00:00:00 2001 From: shijing Date: Thu, 24 Aug 2023 10:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=8B=E6=9C=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=96=B9=E5=BC=8F=E5=AF=86=E7=A0=81=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/model/auth.js | 7 ++ src/views/login/components/phoneForm.vue | 106 ++++++++++++++++++----- src/views/login/index.vue | 6 +- src/views/sys/user.vue | 16 ++-- 4 files changed, 103 insertions(+), 32 deletions(-) diff --git a/src/api/model/auth.js b/src/api/model/auth.js index 4bd884c7..ab74cd59 100644 --- a/src/api/model/auth.js +++ b/src/api/model/auth.js @@ -23,6 +23,13 @@ export default { return await http.post(this.url, data); } }, + login_sms_code: { + url: `${config.API_URL}/auth/login_sms_code/`, + name: "手机验证码登录", + req: async function(data={}){ + return await http.post(this.url, data); + } + }, reset_password: { url: `${config.API_URL}/auth/reset_password/`, name: "重置密码", diff --git a/src/views/login/components/phoneForm.vue b/src/views/login/components/phoneForm.vue index 470d12a9..22c6a79d 100644 --- a/src/views/login/components/phoneForm.vue +++ b/src/views/login/components/phoneForm.vue @@ -1,22 +1,22 @@ @@ -26,14 +26,23 @@ return { form: { phone: "", - yzm: "", + code: "", }, rules: { phone: [ - {required: true, message: this.$t('login.mobileError')} + {required: true, message: this.$t('login.mobileError')}, + {validator: (rule, value, callback) => { + let reg = /^1[3456789]\d{9}$/; + if (reg.test(value)) { + callback(); + }else{ + callback(new Error('请输入正确的手机号')); + } + }} + ], - yzm: [ - {required: true, message: this.$t('login.smsError')} + code: [ + { required: true, message: "请输入验证码" } ] }, disabled: false, @@ -42,28 +51,77 @@ } }, mounted() { - + }, methods: { async getYzm(){ + let that = this; var validate = await this.$refs.loginForm.validateField("phone").catch(()=>{}) if(!validate){ return false } - - this.$message.success(this.$t('login.smsSent')) - this.disabled = true - this.time = 60 - var t = setInterval(() => { - this.time -= 1 - if(this.time < 1){ - clearInterval(t) - this.disabled = false - this.time = 0 - } - },1000) + this.$API.auth.sms_code.req({phone:that.form.phone}).then(res=>{ + this.$message.success(this.$t('login.smsSent')) + this.disabled = true; + this.time = 60 + var t = setInterval(() => { + this.time -= 1 + if(this.time < 1){ + clearInterval(t) + this.disabled = false + this.time = 0 + } + },1000) + }).catch(err=>{ + this.disabled = false; + this.$message.warning(err) + }) }, async login(){ - var validate = await this.$refs.loginForm.validate().catch(()=>{}) - if(!validate){ return false } + let that = this; + this.$refs.loginForm.validate(async (valid) => { + if (valid) { + this.$API.auth.login_sms_code.req(that.form).then(res=>{ + that.$TOOL.cookie.set("TOKEN", res.access, { + expires: that.form.autologin ? 24 * 60 * 60 : 0, + }); + that.$TOOL.data.set("TOKEN", res.access); + that.$TOOL.data.set("TOKEN_REFRESH", res.refresh); + that.$TOOL.cookie.set("TOKEN_REFRESH", res.refresh); + that.$TOOL.data.set("TOKEN_TIME", new Date().getTime()); + that.$API.auth.info.get().then(res1=>{ + that.$TOOL.data.set("USER_INFO", res1); + that.$TOOL.data.set("PERMISSIONS", Object.keys(res1.perms)); + if(this.$TOOL.data.get('BASE_INFO').base.base_name_short=='托克逊能管'){//托克逊 + this.$router.replace({ + path: "/dashboard_enm", + }); + }else{//曲阳金隅 + that.$API.am.area.list.req({page_size:999}).then(res => { + if (res.err_msg) { + } else { + debugger; + let areaList = res.results; + that.$TOOL.data.set("qyjyAreaList", areaList); + if(res1.type==='employee'){ + this.$router.replace({ + path: "/", + }); + }else{ + this.$router.replace({ + path: "/rpm/rpj", + }); + } + that.$message.success("Login Success 登录成功"); + that.islogin = false; + } + }) + } + }) + }).catch(err=>{ + this.disabled = false; + this.$message.warning(err) + }) + } + }) } } } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 009c2bab..a75dbf09 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -26,11 +26,11 @@ - - --> +