index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. this.teacherInfo = res.data || {}
  54. if (this.teacherInfo.lockFlag == 1) {
  55. setTimeout(() => {
  56. Toast('该老师已被冻结')
  57. }, 100)
  58. return
  59. }
  60. } catch {}
  61. },
  62. methods: {
  63. async onSendCode() {
  64. // 发送验证码
  65. if (this.teacherInfo.lockFlag == 1) {
  66. return Toast('该老师已被冻结')
  67. }
  68. if (!checkPhone(this.username)) {
  69. return Toast('请输入正确的手机号码')
  70. }
  71. if (!this.checked) {
  72. return Toast('请阅读并同意协议')
  73. }
  74. this.imgCodeStatus = true
  75. },
  76. previewProtocol(type: string) {
  77. if (type === 'user') {
  78. this.$router.push({
  79. path: '/registerProtocol',
  80. query: {
  81. showHeader: 1
  82. }
  83. })
  84. } else if (type === 'privacy') {
  85. this.$router.push({
  86. path: '/privacyProtocol',
  87. query: {
  88. showHeader: 1
  89. }
  90. })
  91. }
  92. },
  93. async onLoginSuccess(isUpdate: boolean = false) {
  94. try {
  95. const res = await request.get('/api-student/open/bindTeacher', {
  96. params: {
  97. phone: this.username,
  98. userId: this.id,
  99. isUpdate
  100. }
  101. })
  102. this.changeInfo = res.data || {}
  103. const { old, now } = res.data
  104. if (!isUpdate && now && old && now.userId !== old.userId) {
  105. this.teacherChangeStatus = true
  106. } else {
  107. if (old && old.userId === now.userId) {
  108. setTimeout(() => {
  109. Toast('您已绑定该老师')
  110. }, 100)
  111. } else {
  112. setTimeout(() => {
  113. Toast('您已成功绑定老师')
  114. }, 100)
  115. this.$router.push('/inviteSuccess')
  116. }
  117. }
  118. } catch {}
  119. }
  120. },
  121. render() {
  122. return (
  123. <div class={styles.login}>
  124. <div class={styles.loginTitle}>
  125. <img src={logo} alt="" />
  126. <p>
  127. <span class={styles.txt}>酷乐秀</span>
  128. <span>你的器乐学习好帮手</span>
  129. </p>
  130. </div>
  131. <div class={styles.teacherInfo}>
  132. <div class={styles.teacherLogo}>
  133. <img src={this.teacherInfo.avatar || iconTeacher} alt="" />
  134. </div>
  135. <div class={styles.teacherName}>
  136. <span>{this.teacherInfo.username}</span>{' '}
  137. 老师邀请您注册酷乐秀一起体验器乐学习的乐趣吧!
  138. </div>
  139. </div>
  140. <CellGroup class={styles.margin34} border={false}>
  141. <Row style={{ marginBottom: '16px' }}>
  142. <Col span={24} class={styles.formTitle}>
  143. 手机号
  144. </Col>
  145. <Col span={24} class="van-hairline--bottom">
  146. <Field
  147. v-model={this.username}
  148. name="手机号"
  149. placeholder="请输入您的手机号"
  150. type="tel"
  151. maxlength={11}
  152. />
  153. </Col>
  154. </Row>
  155. <div class={styles.itips}>未注册的手机号码将自动注册酷乐秀账号</div>
  156. </CellGroup>
  157. <div class={styles.margin34}>
  158. <Button
  159. round
  160. block
  161. type="primary"
  162. disabled={!this.codeDisable}
  163. onClick={this.onSendCode}
  164. >
  165. 获取短信验证码
  166. </Button>
  167. </div>
  168. <div class={styles.protocol}>
  169. <Checkbox
  170. v-model={this.checked}
  171. v-slots={{
  172. icon: (props: any) => (
  173. <Icon
  174. class={styles.boxStyle}
  175. name={props.checked ? activeButtonIcon : inactiveButtonIcon}
  176. size="15"
  177. />
  178. )
  179. }}
  180. >
  181. 我已阅读并同意
  182. </Checkbox>
  183. <span
  184. class={styles.protocolText}
  185. onClick={() => {
  186. this.previewProtocol('user')
  187. }}
  188. >
  189. 《用户注册协议》
  190. </span>
  191. <span
  192. class={styles.protocolText}
  193. onClick={() => {
  194. this.previewProtocol('privacy')
  195. }}
  196. >
  197. 《隐私政策》
  198. </span>
  199. </div>
  200. <ColPopup v-model={this.imgCodeStatus}>
  201. {this.imgCodeStatus && (
  202. <InviteCode
  203. phone={this.username}
  204. onLoginSuccess={this.onLoginSuccess}
  205. />
  206. )}
  207. </ColPopup>
  208. <Popup show={this.teacherChangeStatus} round>
  209. <TeacherChange
  210. changeInfo={this.changeInfo}
  211. onClose={() => {
  212. this.teacherChangeStatus = false
  213. this.$router.push('/inviteSuccess')
  214. }}
  215. onChangeTeacher={(isUpdate: boolean) => {
  216. this.onLoginSuccess(isUpdate)
  217. }}
  218. />
  219. </Popup>
  220. </div>
  221. )
  222. }
  223. })