|
@@ -0,0 +1,131 @@
|
|
|
+import { defineComponent } from 'vue'
|
|
|
+import { CellGroup, Field, Button, CountDown, Row, Col, Toast } from 'vant'
|
|
|
+import { checkPhone } from '@/helpers/validate'
|
|
|
+import request from '@/helpers/request'
|
|
|
+import { setLogin, state } from '@/state'
|
|
|
+import { removeAuth, setAuth } from '@/helpers/utils'
|
|
|
+import styles from './index.module.less'
|
|
|
+import logo from './images/logo.png'
|
|
|
+
|
|
|
+type loginType = 'PWD' | 'SMS'
|
|
|
+export default defineComponent({
|
|
|
+ name: 'login',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ loginType: 'SMS' as loginType,
|
|
|
+ username: '',
|
|
|
+ smsCode: '',
|
|
|
+ countDownStatus: true, // 是否发送验证码
|
|
|
+ countDownTime: 1000 * 120, // 倒计时时间
|
|
|
+ countDownRef: null as any, // 倒计时实例
|
|
|
+ imgCodeStatus: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ codeDisable() {
|
|
|
+ return (this as any).username ? true : false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ removeAuth()
|
|
|
+ this.directNext()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ directNext() {
|
|
|
+ if (state.user.status === 'login' || state.user.status === 'error') {
|
|
|
+ const { returnUrl, isRegister, ...rest } = this.$route.query
|
|
|
+ this.$router.replace({
|
|
|
+ path: returnUrl as any,
|
|
|
+ query: {
|
|
|
+ ...rest
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async onLogin() {
|
|
|
+ try {
|
|
|
+ let res = await request.post('/api-auth/smsLogin', {
|
|
|
+ requestType: 'form',
|
|
|
+ data: {
|
|
|
+ clientId: 'student',
|
|
|
+ clientSecret: 'student',
|
|
|
+ phone: this.username,
|
|
|
+ smsCode: this.smsCode
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const { authentication } = res.data
|
|
|
+ setAuth(authentication.token_type + ' ' + authentication.access_token)
|
|
|
+
|
|
|
+ let userCash = await request.get('/api-student/student/queryUserInfo', {
|
|
|
+ initRequest: true // 初始化接口
|
|
|
+ })
|
|
|
+ setLogin(userCash.data)
|
|
|
+
|
|
|
+ this.directNext()
|
|
|
+ } catch {}
|
|
|
+ },
|
|
|
+ async onSendCode() {
|
|
|
+ // 发送验证码
|
|
|
+ if (!checkPhone(this.username)) {
|
|
|
+ return Toast('请输入正确的手机号码')
|
|
|
+ }
|
|
|
+ this.imgCodeStatus = true
|
|
|
+ },
|
|
|
+ onCodeSend() {
|
|
|
+ this.countDownStatus = false
|
|
|
+ this.countDownRef.start()
|
|
|
+ },
|
|
|
+ onFinished() {
|
|
|
+ this.countDownStatus = true
|
|
|
+ this.countDownRef.reset()
|
|
|
+ },
|
|
|
+ onChange() {
|
|
|
+ if (this.loginType === 'PWD') {
|
|
|
+ this.loginType = 'SMS'
|
|
|
+ } else if (this.loginType === 'SMS') {
|
|
|
+ this.loginType = 'PWD'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ render() {
|
|
|
+ return (
|
|
|
+ <div class={styles.login}>
|
|
|
+ <div class={styles.loginTitle}>
|
|
|
+ <img src={logo} alt="" />
|
|
|
+ <p>
|
|
|
+ <span class={styles.txt}>酷乐秀</span>
|
|
|
+ <span>你的器乐学习好帮手</span>
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ <CellGroup class={styles.margin34} border={false}>
|
|
|
+ <Row style={{ marginBottom: '16px' }}>
|
|
|
+ <Col span={24} class={styles.formTitle}>
|
|
|
+ 手机号
|
|
|
+ </Col>
|
|
|
+ <Col span={24} class="van-hairline--bottom">
|
|
|
+ <Field
|
|
|
+ v-model={this.username}
|
|
|
+ name="手机号"
|
|
|
+ placeholder="请输入您的手机号"
|
|
|
+ type="tel"
|
|
|
+ maxlength={11}
|
|
|
+ />
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ </CellGroup>
|
|
|
+ <div class={styles.margin34}>
|
|
|
+ <Button
|
|
|
+ round
|
|
|
+ block
|
|
|
+ type="primary"
|
|
|
+ disabled={this.codeDisable}
|
|
|
+ onClick={this.onLogin}
|
|
|
+ >
|
|
|
+ 获取短信验证码
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+})
|