index.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { defineComponent } from 'vue'
  2. import {
  3. CellGroup,
  4. Field,
  5. Button,
  6. Row,
  7. Col,
  8. Toast,
  9. Checkbox,
  10. Icon,
  11. Popup
  12. } from 'vant'
  13. import { checkPhone } from '@/helpers/validate'
  14. import request from '@/helpers/request'
  15. import { setLogin, state } from '@/state'
  16. import { removeAuth, setAuth } from '@/helpers/utils'
  17. import styles from './index.module.less'
  18. import logo from './images/logo.png'
  19. import iconTeacher from '@/common/images/icon_teacher.png'
  20. import activeButtonIcon from '@common/images/icon_checkbox.png'
  21. import inactiveButtonIcon from '@common/images/icon_checkbox_default.png'
  22. import ColPopup from '@/components/col-popup'
  23. import InviteCode from './invite-code'
  24. import TeacherChange from './teacher-change'
  25. export default defineComponent({
  26. name: 'login',
  27. data() {
  28. const query = this.$route.query
  29. return {
  30. id: query.id,
  31. username: '',
  32. teacherInfo: {} as any, // 当前老师信息
  33. imgCodeStatus: false,
  34. checked: false,
  35. teacherChangeStatus: false,
  36. changeInfo: {} as any // 更换老师信息
  37. }
  38. },
  39. computed: {
  40. codeDisable() {
  41. console.log(this.username ? true : false)
  42. return (this as any).username ? true : false
  43. }
  44. },
  45. async mounted() {
  46. removeAuth()
  47. try {
  48. const res = await request.get('/api-student/open/getTeacher', {
  49. params: {
  50. userId: this.id
  51. }
  52. })
  53. console.log(res)
  54. this.teacherInfo = res.data || {}
  55. } catch {}
  56. },
  57. methods: {
  58. async onSendCode() {
  59. // 发送验证码
  60. if (!checkPhone(this.username)) {
  61. return Toast('请输入正确的手机号码')
  62. }
  63. if (!this.checked) {
  64. return Toast('请阅读并同意协议')
  65. }
  66. this.imgCodeStatus = true
  67. },
  68. previewProtocol(type: string) {
  69. if (type === 'user') {
  70. this.$router.push({
  71. path: '/registerProtocol',
  72. query: {
  73. showHeader: 1
  74. }
  75. })
  76. } else if (type === 'privacy') {
  77. this.$router.push({
  78. path: '/privacyProtocol',
  79. query: {
  80. showHeader: 1
  81. }
  82. })
  83. }
  84. },
  85. async onLoginSuccess(isUpdate: boolean = false) {
  86. try {
  87. const res = await request.get('/api-student/open/bindTeacher', {
  88. params: {
  89. phone: this.username,
  90. userId: this.id,
  91. isUpdate
  92. }
  93. })
  94. this.changeInfo = res.data || {}
  95. const { old, now } = res.data
  96. if (!isUpdate && now && old && now.userId !== old.userId) {
  97. this.teacherChangeStatus = true
  98. } else {
  99. this.$router.push('/inviteSuccess')
  100. }
  101. } catch {}
  102. }
  103. },
  104. render() {
  105. return (
  106. <div class={styles.login}>
  107. <div class={styles.loginTitle}>
  108. <img src={logo} alt="" />
  109. <p>
  110. <span class={styles.txt}>酷乐秀</span>
  111. <span>你的器乐学习好帮手</span>
  112. </p>
  113. </div>
  114. <div class={styles.teacherInfo}>
  115. <div class={styles.teacherLogo}>
  116. <img src={this.teacherInfo.avatar || iconTeacher} alt="" />
  117. </div>
  118. <div class={styles.teacherName}>
  119. <span>{this.teacherInfo.realName}</span>{' '}
  120. 老师邀请您注册酷乐秀一起体验器乐学习的乐趣吧!
  121. </div>
  122. </div>
  123. <CellGroup class={styles.margin34} border={false}>
  124. <Row style={{ marginBottom: '16px' }}>
  125. <Col span={24} class={styles.formTitle}>
  126. 手机号
  127. </Col>
  128. <Col span={24} class="van-hairline--bottom">
  129. <Field
  130. v-model={this.username}
  131. name="手机号"
  132. placeholder="请输入您的手机号"
  133. type="tel"
  134. maxlength={11}
  135. />
  136. </Col>
  137. </Row>
  138. <div class={styles.itips}>未注册的手机号码将自动注册酷乐秀账号</div>
  139. </CellGroup>
  140. <div class={styles.margin34}>
  141. <Button
  142. round
  143. block
  144. type="primary"
  145. disabled={!this.codeDisable}
  146. onClick={this.onSendCode}
  147. >
  148. 获取短信验证码
  149. </Button>
  150. </div>
  151. <div class={styles.protocol}>
  152. <Checkbox
  153. v-model={this.checked}
  154. v-slots={{
  155. icon: (props: any) => (
  156. <Icon
  157. class={styles.boxStyle}
  158. name={props.checked ? activeButtonIcon : inactiveButtonIcon}
  159. size="15"
  160. />
  161. )
  162. }}
  163. >
  164. 我已阅读并同意
  165. </Checkbox>
  166. <span
  167. class={styles.protocolText}
  168. onClick={() => {
  169. this.previewProtocol('user')
  170. }}
  171. >
  172. 《用户注册协议》
  173. </span>
  174. <span
  175. class={styles.protocolText}
  176. onClick={() => {
  177. this.previewProtocol('privacy')
  178. }}
  179. >
  180. 《隐私政策》
  181. </span>
  182. </div>
  183. <ColPopup v-model={this.imgCodeStatus}>
  184. {this.imgCodeStatus && (
  185. <InviteCode
  186. phone={this.username}
  187. onLoginSuccess={this.onLoginSuccess}
  188. />
  189. )}
  190. </ColPopup>
  191. <Popup show={this.teacherChangeStatus} round>
  192. <TeacherChange
  193. changeInfo={this.changeInfo}
  194. onClose={() => {
  195. this.teacherChangeStatus = false
  196. this.$router.push('/inviteSuccess')
  197. }}
  198. onChangeTeacher={(isUpdate: boolean) => {
  199. this.onLoginSuccess(isUpdate)
  200. }}
  201. />
  202. </Popup>
  203. </div>
  204. )
  205. }
  206. })