index.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import { defineComponent } from 'vue'
  2. import styles from './index.module.less'
  3. import { ElButton, ElIcon, ElTabPane, ElTabs, ElTooltip } from 'element-plus'
  4. import Form from './components/form'
  5. import QrcodeVue from 'qrcode.vue'
  6. import QrLogin from './components/qr-login'
  7. import TeacherAuth from './components/teacher-auth'
  8. import { state } from '@/state'
  9. export const getAssetsHomeFile = (fileName: string) => {
  10. const path = `./images/${fileName}`
  11. const modules = import.meta.globEager('./images/*')
  12. return modules[path].default
  13. }
  14. export default defineComponent({
  15. name: 'Login',
  16. props: {
  17. onClose: {
  18. type: Function,
  19. default: () => {}
  20. }
  21. },
  22. data() {
  23. return {
  24. qrCodeDownLoad: 'http://dev.colexiu.com/student/#/download',
  25. type: 'login' as
  26. | 'login'
  27. | 'qr-login'
  28. | 'register'
  29. | 'register-success'
  30. | 'teacher-auth',
  31. registerType: 'teacher' as 'teacher' | 'student',
  32. loginType: 'teacher' as 'teacher' | 'student'
  33. }
  34. },
  35. methods: {
  36. onReset(type: 'login' | 'register') {
  37. if (type === 'login') {
  38. ;(this as any).$refs.teacherLogin &&
  39. (this as any).$refs.teacherLogin.onResetFields()
  40. ;(this as any).$refs.studentLogin &&
  41. (this as any).$refs.studentLogin.onResetFields()
  42. } else if (type === 'register') {
  43. ;(this as any).$refs.teacherRegister &&
  44. (this as any).$refs.teacherRegister.onResetFields()
  45. ;(this as any).$refs.studentRegister &&
  46. (this as any).$refs.studentRegister.onResetFields()
  47. }
  48. }
  49. },
  50. watch: {
  51. type(val: string) {
  52. // 切换登录类型时需要清除定时器
  53. if (val != 'qr-login') {
  54. clearInterval(state.loginPopupTimer)
  55. }
  56. }
  57. },
  58. render() {
  59. return (
  60. <div class={[styles.loginSection, 'relative']}>
  61. <i
  62. class={[
  63. styles.iconClose,
  64. 'w-9 h-9 rounded-full flex absolute -top-1 -right-[18px]'
  65. ]}
  66. onClick={() => {
  67. this.onClose()
  68. }}
  69. ></i>
  70. <img
  71. src={getAssetsHomeFile('register_bg.png')}
  72. class={[styles.loginBg, '-mt-[10px]']}
  73. />
  74. <div
  75. class={[
  76. styles.loginTabs,
  77. 'px-9 pt-5 pb-12 bg-white relative',
  78. this.type === 'qr-login' ? 'pb-4' : '',
  79. this.type === 'teacher-auth' ? 'px-6 pb-8' : ''
  80. ]}
  81. >
  82. {this.type === 'login' && (
  83. <>
  84. <div class={'absolute top-2 right-2 z-10'}>
  85. <div class={styles.toolTips}>
  86. <span>扫码登录更方便</span>
  87. <span class={styles.toolTips_arrow}></span>
  88. </div>
  89. <img
  90. src={getAssetsHomeFile('icon_qrcode_login.png')}
  91. class="w-14 h-14 cursor-pointer"
  92. onClick={() => {
  93. this.type = 'qr-login'
  94. }}
  95. />
  96. </div>
  97. <ElTabs v-model={this.loginType}>
  98. <ElTabPane label="老师登录" name="teacher">
  99. {this.loginType === 'teacher' && (
  100. <Form
  101. type="teacher-login"
  102. key="teacherLogin"
  103. ref="teacherLogin"
  104. onClose={() => {
  105. this.onClose()
  106. }}
  107. />
  108. )}
  109. </ElTabPane>
  110. <ElTabPane label="学员登录" name="student">
  111. {this.loginType === 'student' && (
  112. <Form
  113. type="student-login"
  114. key="studentLogin"
  115. ref="studentLogin"
  116. onClose={() => {
  117. this.onClose()
  118. }}
  119. />
  120. )}
  121. </ElTabPane>
  122. </ElTabs>
  123. <div class={[styles.scanTxt]}>
  124. 没有账号,
  125. <span
  126. class="cursor-pointer"
  127. onClick={() => {
  128. this.onReset('login')
  129. this.type = 'register'
  130. }}
  131. >
  132. 马上注册
  133. </span>
  134. </div>
  135. </>
  136. )}
  137. {this.type === 'qr-login' && (
  138. <>
  139. <QrLogin
  140. onChange={(type: any) => {
  141. this.type = type
  142. }}
  143. />
  144. <div class={[styles.scanTxt, 'pt-14 text-center']}>
  145. 没有账号,
  146. <span
  147. class="cursor-pointer"
  148. onClick={() => {
  149. this.type = 'register'
  150. }}
  151. >
  152. 马上注册
  153. </span>
  154. </div>
  155. </>
  156. )}
  157. {this.type === 'register' && (
  158. <>
  159. <ElTabs v-model={this.registerType}>
  160. <ElTabPane label="老师注册" name="teacher">
  161. {this.registerType === 'teacher' && (
  162. <Form
  163. type="teacher-register"
  164. key="teacher-register"
  165. ref="teacherRegister"
  166. onClose={() => {
  167. this.onClose()
  168. }}
  169. onChange={(type: any) => {
  170. this.type = type
  171. }}
  172. />
  173. )}
  174. </ElTabPane>
  175. <ElTabPane label="学员注册" name="student">
  176. {this.registerType === 'student' && (
  177. <Form
  178. type="student-register"
  179. key="student-register"
  180. ref="studentRegister"
  181. onClose={() => {
  182. this.onClose()
  183. }}
  184. onChange={(type: any) => {
  185. this.type = type
  186. }}
  187. />
  188. )}
  189. </ElTabPane>
  190. </ElTabs>
  191. <div class={[styles.scanTxt]}>
  192. 已有账号,
  193. <span
  194. class="cursor-pointer"
  195. onClick={() => {
  196. this.onReset('register')
  197. this.type = 'login'
  198. }}
  199. >
  200. 马上登录
  201. </span>
  202. </div>
  203. </>
  204. )}
  205. {this.type === 'register-success' && (
  206. <div class={'text-center pt-4'}>
  207. <QrcodeVue
  208. value={this.qrCodeDownLoad}
  209. class="mx-auto shadow-lg w-[138px] h-[138px] align-middle"
  210. />
  211. <h3 class="text-lg text=[#1a1a1a] pt-4 pb-2">注册成功</h3>
  212. <div class={[styles.scanTxt, 'leading-6']}>
  213. <p>恭喜您已成功注册酷乐秀老师账号!</p>
  214. <p>
  215. <span>下载酷乐秀老师端APP</span>发现更大的世界
  216. </p>
  217. </div>
  218. <ElButton
  219. type="primary"
  220. class="w-full mt-4"
  221. style={{ height: '40px' }}
  222. onClick={() => {
  223. if (this.registerType == 'teacher') {
  224. this.type = 'teacher-auth'
  225. } else {
  226. this.onClose()
  227. }
  228. }}
  229. >
  230. 知道了
  231. </ElButton>
  232. </div>
  233. )}
  234. {this.type === 'teacher-auth' && (
  235. <TeacherAuth
  236. onClose={() => {
  237. this.type = 'login'
  238. this.loginType = 'teacher'
  239. this.onClose()
  240. }}
  241. />
  242. )}
  243. </div>
  244. </div>
  245. )
  246. }
  247. })