|
@@ -1,39 +1,35 @@
|
|
|
import { defineComponent } from 'vue';
|
|
|
-import { CellGroup, Field, Button, CountDown, showToast } from 'vant';
|
|
|
-import ImgCode from '@/components/m-img-code';
|
|
|
+import { CellGroup, Field, Button, showToast } from 'vant';
|
|
|
import request from '@/helpers/request';
|
|
|
import { setLogin, state } from '@/state';
|
|
|
import { checkPhone } from '@/helpers/utils';
|
|
|
+import loginLogo from './images/login-logo.png';
|
|
|
+import iconPhone from './images/icon-phone.png';
|
|
|
+import iconPassword from './images/icon-password.png';
|
|
|
import { storage } from '@/helpers/storage';
|
|
|
import { ACCESS_TOKEN } from '@/store/mutation-types';
|
|
|
import styles from './login.module.less';
|
|
|
+import MPopup from '@/components/m-popup';
|
|
|
+import Code from './code';
|
|
|
+import router from '@/router';
|
|
|
|
|
|
type loginType = 'PWD' | 'SMS';
|
|
|
export default defineComponent({
|
|
|
name: 'layout-login',
|
|
|
data() {
|
|
|
+ const { isRegister } = this.$route.query;
|
|
|
return {
|
|
|
+ isRegister: isRegister as any,
|
|
|
loginType: 'SMS' as loginType,
|
|
|
username: '',
|
|
|
password: '',
|
|
|
smsCode: '',
|
|
|
countDownStatus: true, // 是否发送验证码
|
|
|
countDownTime: 1000 * 120, // 倒计时时间
|
|
|
- // countDownRef: null as any, // 倒计时实例
|
|
|
- imgCodeStatus: false
|
|
|
+ imgCodeStatus: false,
|
|
|
+ isAgree: true
|
|
|
};
|
|
|
},
|
|
|
- computed: {
|
|
|
- codeDisable() {
|
|
|
- let status = true;
|
|
|
- if (this.loginType === 'PWD') {
|
|
|
- this.username && this.password && (status = false);
|
|
|
- } else {
|
|
|
- this.username && this.smsCode && (status = false);
|
|
|
- }
|
|
|
- return status;
|
|
|
- }
|
|
|
- },
|
|
|
mounted() {
|
|
|
storage.remove(ACCESS_TOKEN);
|
|
|
this.directNext();
|
|
@@ -53,7 +49,9 @@ export default defineComponent({
|
|
|
},
|
|
|
async onLogin() {
|
|
|
try {
|
|
|
- // let res: any
|
|
|
+ if (!checkPhone(this.username)) {
|
|
|
+ return showToast('请输入正确的手机号码');
|
|
|
+ }
|
|
|
const forms: any = {
|
|
|
username: this.username,
|
|
|
client_id: 'cooleshow-student',
|
|
@@ -75,7 +73,6 @@ export default defineComponent({
|
|
|
initRequest: true // 初始化接口
|
|
|
});
|
|
|
setLogin(userCash.data);
|
|
|
-
|
|
|
this.directNext();
|
|
|
} catch (e: any) {
|
|
|
//
|
|
@@ -84,21 +81,14 @@ export default defineComponent({
|
|
|
},
|
|
|
async onSendCode() {
|
|
|
// 发送验证码
|
|
|
+ if (!this.isAgree) {
|
|
|
+ return showToast('请阅读并同意以下协议');
|
|
|
+ }
|
|
|
if (!checkPhone(this.username)) {
|
|
|
return showToast('请输入正确的手机号码');
|
|
|
}
|
|
|
this.imgCodeStatus = true;
|
|
|
},
|
|
|
- onCodeSend() {
|
|
|
- this.countDownStatus = false;
|
|
|
- this.$nextTick(() => {
|
|
|
- (this.$refs.countDownRef as any).start();
|
|
|
- });
|
|
|
- },
|
|
|
- onFinished() {
|
|
|
- this.countDownStatus = true;
|
|
|
- (this.$refs.countDownRef as any).reset();
|
|
|
- },
|
|
|
onChange() {
|
|
|
if (this.loginType === 'PWD') {
|
|
|
this.loginType = 'SMS';
|
|
@@ -110,78 +100,108 @@ export default defineComponent({
|
|
|
render() {
|
|
|
return (
|
|
|
<div class={[styles.login]}>
|
|
|
- <div class={styles.logo}>{/* <img src={logo} /> */}</div>
|
|
|
- <CellGroup class={styles.container} border={false}>
|
|
|
- <Field
|
|
|
- v-model={this.username}
|
|
|
- name="手机号"
|
|
|
- placeholder="请输入您的手机号"
|
|
|
- type="tel"
|
|
|
- class={styles['input-group']}
|
|
|
- maxlength={11}
|
|
|
- autocomplete="off"
|
|
|
- />
|
|
|
+ <div class={styles.loginContainer}>
|
|
|
+ <img src={loginLogo} class={styles.logo} />
|
|
|
|
|
|
- {this.loginType === 'PWD' ? (
|
|
|
- <Field
|
|
|
- v-model={this.password}
|
|
|
- type="password"
|
|
|
- name="密码"
|
|
|
- class={styles['input-group']}
|
|
|
- placeholder="请输入密码"
|
|
|
- autocomplete="off"
|
|
|
- />
|
|
|
- ) : (
|
|
|
+ <CellGroup class={styles.container} border={false}>
|
|
|
<Field
|
|
|
- v-model={this.smsCode}
|
|
|
- name="验证码"
|
|
|
- placeholder="请输入验证码"
|
|
|
+ v-model={this.username}
|
|
|
+ name="手机号"
|
|
|
+ placeholder="请输入您的手机号"
|
|
|
type="tel"
|
|
|
class={styles['input-group']}
|
|
|
- maxlength={6}
|
|
|
+ maxlength={11}
|
|
|
autocomplete="off"
|
|
|
- v-slots={{
|
|
|
- button: () =>
|
|
|
- this.countDownStatus ? (
|
|
|
- <span class={styles.codeText} onClick={this.onSendCode}>
|
|
|
- 获取验证码
|
|
|
- </span>
|
|
|
- ) : (
|
|
|
- <CountDown
|
|
|
- ref="countDownRef"
|
|
|
- auto-start={false}
|
|
|
- time={this.countDownTime}
|
|
|
- onFinish={this.onFinished}
|
|
|
- format="ss秒"
|
|
|
- />
|
|
|
- )
|
|
|
+ border={false}>
|
|
|
+ {{
|
|
|
+ 'left-icon': () => (
|
|
|
+ <img src={iconPhone} class={styles.iconPhone} />
|
|
|
+ )
|
|
|
}}
|
|
|
- />
|
|
|
- )}
|
|
|
- </CellGroup>
|
|
|
- <div class={styles.margin34}>
|
|
|
- <Button
|
|
|
- round
|
|
|
- block
|
|
|
- disabled={this.codeDisable}
|
|
|
- onClick={this.onLogin}>
|
|
|
- 提交
|
|
|
- </Button>
|
|
|
- <span class={styles['login-change']} onClick={this.onChange}>
|
|
|
- {this.loginType === 'PWD' ? '验证码登录' : '密码登录'}
|
|
|
- </span>
|
|
|
+ </Field>
|
|
|
+
|
|
|
+ {this.loginType === 'PWD' && (
|
|
|
+ <Field
|
|
|
+ v-model={this.password}
|
|
|
+ type="password"
|
|
|
+ name="密码"
|
|
|
+ class={styles['input-group']}
|
|
|
+ placeholder="请输入密码"
|
|
|
+ autocomplete="off"
|
|
|
+ border={false}>
|
|
|
+ {{
|
|
|
+ 'left-icon': () => (
|
|
|
+ <img src={iconPassword} class={styles.iconPassword} />
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </Field>
|
|
|
+ )}
|
|
|
+
|
|
|
+ <div class={styles.btnGroup}>
|
|
|
+ <Button
|
|
|
+ round
|
|
|
+ block
|
|
|
+ class={styles.primaryButton}
|
|
|
+ onClick={() => {
|
|
|
+ if (this.loginType === 'PWD') {
|
|
|
+ this.onLogin();
|
|
|
+ } else {
|
|
|
+ this.onSendCode();
|
|
|
+ }
|
|
|
+ }}>
|
|
|
+ {this.loginType === 'PWD' ? '登录' : '获取短信验证码'}
|
|
|
+ </Button>
|
|
|
+
|
|
|
+ <Button
|
|
|
+ round
|
|
|
+ block
|
|
|
+ type="default"
|
|
|
+ class={styles['login-change']}
|
|
|
+ onClick={this.onChange}>
|
|
|
+ {this.loginType === 'PWD' ? '短信登录' : '密码登录'}
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {this.loginType === 'SMS' && (
|
|
|
+ <div
|
|
|
+ class={styles.protocol}
|
|
|
+ onClick={() => (this.isAgree = !this.isAgree)}>
|
|
|
+ <i
|
|
|
+ class={[
|
|
|
+ styles.iconChecked,
|
|
|
+ this.isAgree ? styles.active : ''
|
|
|
+ ]}></i>
|
|
|
+ 我已阅读并同意
|
|
|
+ <span
|
|
|
+ onClick={(e: MouseEvent) => {
|
|
|
+ e.stopPropagation();
|
|
|
+
|
|
|
+ router.push('/preview-protocol');
|
|
|
+ }}>
|
|
|
+ 《用户注册协议》
|
|
|
+ </span>
|
|
|
+ 和
|
|
|
+ <span
|
|
|
+ onClick={(e: MouseEvent) => {
|
|
|
+ e.stopPropagation();
|
|
|
+
|
|
|
+ router.push('/privacy-protocol');
|
|
|
+ }}>
|
|
|
+ 《隐私政策》
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+ </CellGroup>
|
|
|
</div>
|
|
|
|
|
|
- {this.imgCodeStatus ? (
|
|
|
- <ImgCode
|
|
|
- v-model:value={this.imgCodeStatus}
|
|
|
+ <MPopup v-model:modelValue={this.imgCodeStatus}>
|
|
|
+ <Code
|
|
|
phone={this.username}
|
|
|
- onClose={() => {
|
|
|
- this.imgCodeStatus = false;
|
|
|
- }}
|
|
|
- onSendCode={this.onCodeSend}
|
|
|
+ isRegister={this.isRegister}
|
|
|
+ onClose={() => (this.imgCodeStatus = false)}
|
|
|
+ onConfirm={this.directNext}
|
|
|
/>
|
|
|
- ) : null}
|
|
|
+ </MPopup>
|
|
|
</div>
|
|
|
);
|
|
|
}
|