index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 { browser, 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. import OWxTip from '@/components/the-wx-tip'
  26. import { postMessage } from '@/helpers/native-message'
  27. export default defineComponent({
  28. name: 'login',
  29. data() {
  30. const query = this.$route.query
  31. return {
  32. id: query.id,
  33. username: '',
  34. teacherInfo: {} as any, // 当前老师信息
  35. imgCodeStatus: false,
  36. checked: false,
  37. teacherChangeStatus: false,
  38. changeInfo: {} as any, // 更换老师信息
  39. showTips: false,
  40. navBarHeight: 0
  41. }
  42. },
  43. computed: {
  44. codeDisable() {
  45. console.log(this.username ? true : false)
  46. return (this as any).username ? true : false
  47. }
  48. },
  49. async mounted() {
  50. removeAuth()
  51. postMessage({ api: 'getNavHeight' }, res => {
  52. const { content } = res as any
  53. const dpi = content.dpi || 2
  54. if (content.navHeight) {
  55. const navHeight = content.navHeight / dpi
  56. this.navBarHeight = navHeight
  57. }
  58. })
  59. try {
  60. const res = await request.get('/api-student/open/getTeacher', {
  61. params: {
  62. userId: this.id
  63. }
  64. })
  65. this.teacherInfo = res.data || {}
  66. if (this.teacherInfo.lockFlag == 1) {
  67. setTimeout(() => {
  68. Toast('该老师已被冻结')
  69. }, 100)
  70. return
  71. }
  72. } catch {}
  73. },
  74. methods: {
  75. onBack() {
  76. if (browser().isApp) {
  77. postMessage({ api: 'goBack' })
  78. } else {
  79. this.$router.back()
  80. }
  81. },
  82. async onSendCode() {
  83. // 发送验证码
  84. if (this.teacherInfo.lockFlag == 1) {
  85. return Toast('该老师已被冻结')
  86. }
  87. if (!checkPhone(this.username)) {
  88. return Toast('请输入正确的手机号码')
  89. }
  90. if (!this.checked) {
  91. return Toast('请阅读并同意协议')
  92. }
  93. try {
  94. const { data } = await request.get(
  95. '/api-student/open/checkPhone?phone=' + this.username
  96. )
  97. console.log(data)
  98. if (data) {
  99. this.imgCodeStatus = true
  100. } else {
  101. this.showTips = true
  102. }
  103. } catch {
  104. //
  105. }
  106. },
  107. previewProtocol(type: string) {
  108. if (type === 'user') {
  109. this.$router.push({
  110. path: '/registerProtocol',
  111. query: {
  112. showHeader: 1
  113. }
  114. })
  115. } else if (type === 'privacy') {
  116. this.$router.push({
  117. path: '/privacyProtocol',
  118. query: {
  119. showHeader: 1
  120. }
  121. })
  122. }
  123. },
  124. async onLoginSuccess(isUpdate = false) {
  125. try {
  126. const res = await request.get('/api-student/open/bindTeacher', {
  127. params: {
  128. phone: this.username,
  129. userId: this.id,
  130. isUpdate
  131. }
  132. })
  133. this.changeInfo = res.data || {}
  134. const { old, now } = res.data
  135. if (!isUpdate && now && old && now.userId !== old.userId) {
  136. this.teacherChangeStatus = true
  137. } else {
  138. if (old && old.userId === now.userId) {
  139. setTimeout(() => {
  140. Toast('您已绑定该老师')
  141. }, 100)
  142. } else {
  143. setTimeout(() => {
  144. Toast('您已成功绑定老师')
  145. }, 100)
  146. this.$router.push('/inviteSuccess')
  147. }
  148. }
  149. } catch {}
  150. }
  151. },
  152. render() {
  153. return (
  154. <div class={styles.login}>
  155. <Icon
  156. name="arrow-left"
  157. class={styles.backIcon}
  158. style={{
  159. top: `calc(${this.navBarHeight}px + 12px)`
  160. }}
  161. onClick={this.onBack}
  162. />
  163. <div class={styles.loginTitle}>
  164. <img src={logo} alt="" />
  165. <p>
  166. <span class={styles.txt}>酷乐秀</span>
  167. <span>你的器乐学习好帮手</span>
  168. </p>
  169. </div>
  170. <div class={styles.teacherInfo}>
  171. <div class={styles.teacherLogo}>
  172. <img src={this.teacherInfo.avatar || iconTeacher} alt="" />
  173. </div>
  174. <div class={styles.teacherName}>
  175. <span>{this.teacherInfo.username}</span>{' '}
  176. 老师邀请您注册酷乐秀一起体验器乐学习的乐趣吧!
  177. </div>
  178. </div>
  179. <CellGroup class={styles.margin34} border={false}>
  180. <Row style={{ marginBottom: '16px' }}>
  181. <Col span={24} class={styles.formTitle}>
  182. 手机号
  183. </Col>
  184. <Col span={24} class="van-hairline--bottom">
  185. <Field
  186. v-model={this.username}
  187. name="手机号"
  188. placeholder="请输入您的手机号"
  189. type="tel"
  190. maxlength={11}
  191. />
  192. </Col>
  193. </Row>
  194. <div class={styles.itips}>未注册的手机号码将自动注册酷乐秀账号</div>
  195. </CellGroup>
  196. <div class={styles.margin34}>
  197. <Button
  198. round
  199. block
  200. type="primary"
  201. disabled={!this.codeDisable}
  202. onClick={this.onSendCode}
  203. >
  204. 获取短信验证码
  205. </Button>
  206. </div>
  207. <div class={styles.protocol}>
  208. <Checkbox
  209. v-model={this.checked}
  210. v-slots={{
  211. icon: (props: any) => (
  212. <Icon
  213. class={styles.boxStyle}
  214. name={props.checked ? activeButtonIcon : inactiveButtonIcon}
  215. size="15"
  216. />
  217. )
  218. }}
  219. >
  220. 我已阅读并同意
  221. </Checkbox>
  222. <span
  223. class={styles.protocolText}
  224. onClick={() => {
  225. this.previewProtocol('user')
  226. }}
  227. >
  228. 《用户注册协议》
  229. </span>
  230. <span
  231. class={styles.protocolText}
  232. onClick={() => {
  233. this.previewProtocol('privacy')
  234. }}
  235. >
  236. 《隐私政策》
  237. </span>
  238. </div>
  239. <ColPopup v-model={this.imgCodeStatus}>
  240. {this.imgCodeStatus && (
  241. <InviteCode
  242. phone={this.username}
  243. onLoginSuccess={this.onLoginSuccess}
  244. />
  245. )}
  246. </ColPopup>
  247. <Popup show={this.teacherChangeStatus} round>
  248. <TeacherChange
  249. changeInfo={this.changeInfo}
  250. onClose={() => {
  251. this.teacherChangeStatus = false
  252. this.$router.push('/inviteSuccess')
  253. }}
  254. onChangeTeacher={(isUpdate: boolean) => {
  255. this.onLoginSuccess(isUpdate)
  256. }}
  257. />
  258. </Popup>
  259. {/* 是否在微信中打开 */}
  260. <OWxTip
  261. show={this.showTips}
  262. message={'您已绑定机构,无法再绑定老师'}
  263. showButton={true}
  264. buttonText="确定"
  265. onConfirm={() => {
  266. this.showTips = false
  267. }}
  268. />
  269. </div>
  270. )
  271. }
  272. })