login-cert.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { defineComponent } from 'vue'
  2. import { CellGroup, Field, Button, CountDown, Row, Col, Toast, Checkbox, Icon } from 'vant'
  3. import ImgCode from '@/components/col-img-code'
  4. import { checkPhone } from '@/helpers/validate'
  5. import request from '@/helpers/request'
  6. import { setLogin, state } from '@/state'
  7. import { removeAuth, setAuth } from '@/helpers/utils'
  8. import styles from './login-cert.module.less'
  9. import topBg from './image-cert/top.png'
  10. import activeButtonIcon from '@common/images/icon_checkbox.png'
  11. import inactiveButtonIcon from '@common/images/icon_checkbox_default.png'
  12. export default defineComponent({
  13. name: 'login',
  14. data() {
  15. return {
  16. checked: false,
  17. username: '',
  18. password: '',
  19. smsCode: '',
  20. countDownStatus: true, // 是否发送验证码
  21. countDownTime: 1000 * 120, // 倒计时时间
  22. countDownRef: null as any, // 倒计时实例
  23. imgCodeStatus: false
  24. }
  25. },
  26. computed: {
  27. codeDisable() {
  28. let status = true
  29. this.username && this.smsCode && this.checked && (status = false)
  30. return status
  31. }
  32. },
  33. mounted() {
  34. removeAuth()
  35. this.directNext()
  36. },
  37. methods: {
  38. previewProtocol(type: string) {
  39. if (type === 'user') {
  40. this.$router.push({
  41. path: '/registerProtocol',
  42. query: {
  43. showHeader: 1
  44. }
  45. })
  46. } else if (type === 'privacy') {
  47. this.$router.push({
  48. path: '/privacyProtocol',
  49. query: {
  50. showHeader: 1
  51. }
  52. })
  53. }
  54. },
  55. directNext() {
  56. if (state.user.status === 'login' || state.user.status === 'error') {
  57. const { returnUrl, isRegister, ...rest } = this.$route.query
  58. this.$router.replace({
  59. path: '/teacherCert',
  60. query: {
  61. ...rest
  62. }
  63. })
  64. }
  65. },
  66. async onLogin() {
  67. try {
  68. let res = await request.post('/api-auth/smsLogin', {
  69. requestType: 'form',
  70. data: {
  71. clientId: 'teacher',
  72. clientSecret: 'teacher',
  73. phone: this.username,
  74. smsCode: this.smsCode,
  75. isSurportRegister: true
  76. }
  77. })
  78. const { authentication } = res.data
  79. setAuth(authentication.token_type + ' ' + authentication.access_token)
  80. let userCash = await request.get('/api-teacher/teacher/queryUserInfo', {
  81. initRequest: true // 初始化接口
  82. })
  83. setLogin(userCash.data)
  84. this.directNext()
  85. } catch {}
  86. },
  87. async onSendCode() {
  88. // 发送验证码
  89. if (!checkPhone(this.username)) {
  90. return Toast('请输入正确的手机号码')
  91. }
  92. this.imgCodeStatus = true
  93. },
  94. onCodeSend() {
  95. this.countDownStatus = false
  96. this.countDownRef.start()
  97. },
  98. onFinished() {
  99. this.countDownStatus = true
  100. this.countDownRef.reset()
  101. }
  102. },
  103. render() {
  104. return (
  105. <div class={styles.login}>
  106. <img src={topBg} class={styles.topBg} />
  107. <div class={styles.content}>
  108. <CellGroup class={styles.cellGroup} border={false}>
  109. <Row style={{ marginBottom: '16px' }}>
  110. <Col span={24} class={styles.formTitle}>
  111. 手机号
  112. </Col>
  113. <Col span={24} class="van-hairline--bottom">
  114. <Field
  115. v-model={this.username}
  116. name="手机号"
  117. placeholder="请输入您的手机号"
  118. type="tel"
  119. maxlength={11}
  120. />
  121. </Col>
  122. </Row>
  123. <Row>
  124. <Col span={24} class={styles.formTitle}>
  125. 验证码
  126. </Col>
  127. <Col span={24} class="van-hairline--bottom">
  128. <Field
  129. v-model={this.smsCode}
  130. name="验证码"
  131. placeholder="请输入验证码"
  132. type="tel"
  133. maxlength={6}
  134. // @ts-ignore
  135. vSlots={{
  136. button: () =>
  137. this.countDownStatus ? (
  138. <span class={styles.codeText} onClick={this.onSendCode}>
  139. 发送验证码
  140. </span>
  141. ) : (
  142. <CountDown
  143. ref={this.countDownRef}
  144. auto-start={false}
  145. time={this.countDownTime}
  146. onFinish={this.onFinished}
  147. format="ss秒"
  148. />
  149. )
  150. }}
  151. />
  152. </Col>
  153. </Row>
  154. </CellGroup>
  155. </div>
  156. <div class={styles.margin34}>
  157. <div class={styles.protocol}>
  158. <Checkbox
  159. v-model={this.checked}
  160. v-slots={{
  161. icon: (props: any) => (
  162. <Icon
  163. class={styles.boxStyle}
  164. name={props.checked ? activeButtonIcon : inactiveButtonIcon}
  165. size="15"
  166. />
  167. )
  168. }}
  169. >
  170. 我已阅读并同意
  171. </Checkbox>
  172. <span
  173. class={styles.protocolText}
  174. onClick={() => {
  175. this.previewProtocol('user')
  176. }}
  177. >
  178. 《用户注册协议》
  179. </span>
  180. <span
  181. class={styles.protocolText}
  182. onClick={() => {
  183. this.previewProtocol('privacy')
  184. }}
  185. >
  186. 《隐私政策》
  187. </span>
  188. </div>
  189. <Button
  190. round
  191. block
  192. type="primary"
  193. disabled={this.codeDisable}
  194. onClick={this.onLogin}
  195. >
  196. 确认
  197. </Button>
  198. </div>
  199. {this.imgCodeStatus ? (
  200. <ImgCode
  201. v-model:value={this.imgCodeStatus}
  202. phone={this.username}
  203. onClose={() => {
  204. this.imgCodeStatus = false
  205. }}
  206. onSendCode={this.onCodeSend}
  207. />
  208. ) : null}
  209. </div>
  210. )
  211. }
  212. })