AppRegister.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="login">
  3. <div class="logo">
  4. <img src="../../assets/images/logo.png" alt="">
  5. </div>
  6. <div class="container">
  7. <div class="input-group">
  8. <input type="number" placeholder="请输入手机号" class="input" v-model="phoneNumber" pattern="[0-9]">
  9. </div>
  10. <div class="input-group" style="margin-bottom: .05rem;">
  11. <input type="text" placeholder="请输入验证码" class="input" v-model="code" >
  12. <span class="code-text" v-show="countDownStatus" @click="onSendCode">{{ codeText }}</span>
  13. <span class="code-text" v-show="!countDownStatus">
  14. <van-count-down
  15. ref="countdown"
  16. :auto-start="false"
  17. :time="countDownTime"
  18. @finish="onFinished"
  19. format="ss秒" />
  20. </span>
  21. </div>
  22. <div class="agreeProtocol">
  23. <van-checkbox v-model="agreeStatus"></van-checkbox>
  24. <i style="font-style: normal;" @click="agreeStatus = !agreeStatus">阅读并同意</i> <span @click="onToProtocol">《用户协议》</span>
  25. </div>
  26. <van-button round size="large" @click="onCodeLogin" >注册并登录</van-button>
  27. <span class="login-change" @click="onUrlLogin">登录</span>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import {sendSms, smsLogin, queryUserByPhone } from '@/api/app'
  33. export default {
  34. name: 'login',
  35. data() {
  36. let query = localStorage.getItem('getRegister')
  37. query = query ? JSON.parse(query) : {}
  38. localStorage.removeItem('getRegister')
  39. return {
  40. groupId: this.$route.query.groupId,
  41. // codeDisable: true, // 验证码登录按钮状态
  42. countDownStatus: true, // 到计时状态
  43. phoneNumber: query.phoneNumber ? query.phoneNumber : null,
  44. isRegister: 0, // 默认没有注册
  45. code: query.code ? query.code : null,
  46. codeText: '获取验证码',
  47. countDownTime: 1000 * 120, // 倒计时时间
  48. isClick: false,
  49. agreeStatus: query.agreeStatus ? query.agreeStatus : false
  50. }
  51. },
  52. mounted() {
  53. // 登录时删除无用的token
  54. localStorage.removeItem('userInfo')
  55. localStorage.removeItem('Authorization')
  56. },
  57. methods: {
  58. codeBlur() {
  59. setTimeout(() => {
  60. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
  61. window.scrollTo(0, Math.max(scrollHeight - 1, 0));
  62. }, 100);
  63. },
  64. onToProtocol() {
  65. localStorage.setItem('getRegister', JSON.stringify({
  66. phoneNumber: this.phoneNumber,
  67. code: this.code,
  68. agreeStatus: this.agreeStatus
  69. }))
  70. this.$router.push({
  71. path: '/userProtocol',
  72. query: {
  73. groupId: this.groupId,
  74. }
  75. })
  76. },
  77. onUrlLogin() {
  78. this.$router.push({
  79. path: '/appLogin',
  80. query: {
  81. groupId: this.groupId
  82. }
  83. })
  84. },
  85. onSendCode() { // 发送验证码
  86. if(!this.checkPhone(this.phoneNumber)) {
  87. return
  88. }
  89. queryUserByPhone({ mobile: this.phoneNumber }).then(res => {
  90. let result = res.data
  91. if(result.code == 200) {
  92. this.isRegister = result.data
  93. if(result.data == 1) {
  94. this.$toast('用户已存在')
  95. return
  96. } else {
  97. sendSms({
  98. mobile: this.phoneNumber
  99. }).then(res => {
  100. let result = res.data
  101. if(result.code == 200) {
  102. this.countDownStatus = false
  103. this.$refs.countdown.start() // 倒计时开始
  104. } else {
  105. this.$toast(result.msg)
  106. }
  107. })
  108. }
  109. }
  110. })
  111. },
  112. onCodeLogin() { // 短信登录
  113. if(!this.phoneNumber) {
  114. this.$toast('请输入手机号')
  115. return
  116. } else if(!this.checkPhone(this.phoneNumber)) {
  117. return
  118. }
  119. if(!this.code) {
  120. this.$toast('请输入验证码')
  121. return
  122. }
  123. if(!this.agreeStatus) {
  124. this.$toast('请先阅读并同意用户协议')
  125. return
  126. }
  127. if(this.isClick) {
  128. return
  129. }
  130. this.isClick = true
  131. queryUserByPhone({ mobile: this.phoneNumber }).then(res => {
  132. let result = res.data
  133. if(result.code == 200) {
  134. this.isRegister = result.data
  135. if(result.data == 1) {
  136. this.$toast('用户已存在')
  137. this.isClick = false
  138. return
  139. } else {
  140. this.onLogin()
  141. }
  142. }
  143. })
  144. },
  145. onLogin() {
  146. let params = {
  147. clientId: 'student',
  148. clientSecret: 'student',
  149. phone: this.phoneNumber,
  150. smsCode: this.code,
  151. channel: 'H5',
  152. isLessee: 'true'
  153. }
  154. smsLogin(params).then(sms => {
  155. let s = sms.data
  156. this.isClick = false
  157. // 保存用户信息
  158. if(s.code == 200) {
  159. let auth = s.data.authentication
  160. localStorage.setItem('userInfo', auth.token_type + ' ' + auth.access_token)
  161. if(s.password) {
  162. this.$router.push({
  163. path: '/classDetail',
  164. query: {
  165. groupId: this.groupId
  166. }
  167. })
  168. } else {
  169. this.$router.push({
  170. path: '/appSetInfo',
  171. query: {
  172. groupId: this.groupId
  173. }
  174. })
  175. }
  176. } else {
  177. this.$toast(s.msg)
  178. }
  179. })
  180. },
  181. onFinished() { // 倒计时结束
  182. this.countDownStatus = true
  183. this.$refs.countdown.reset()
  184. },
  185. checkPhone(phoneNumber) {
  186. let result = true
  187. if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneNumber))){
  188. this.$toast('手机号输入有误')
  189. result = false
  190. }
  191. return result
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang='less' scoped>
  197. @import url("../../assets/commonLess/variable.less");
  198. .login {
  199. min-height: 100vh;
  200. background: linear-gradient(to bottom, #15938B, #6dbeba);
  201. }
  202. .container {
  203. padding: 0 .48rem;
  204. }
  205. .agreeProtocol {
  206. font-size: .14rem;
  207. display: flex;
  208. align-items: center;
  209. // color: #333333;
  210. color: #fff;
  211. padding: .05rem .06rem .15rem;
  212. .van-checkbox {
  213. padding-right: .08rem;
  214. }
  215. /deep/.van-checkbox__icon .van-icon {
  216. // border-color: #14928A;
  217. background: #fff;
  218. }
  219. /deep/.van-checkbox__icon--checked .van-icon {
  220. color: #14928A;
  221. background-color: #fff;
  222. border-color: #fff;
  223. }
  224. span {
  225. // color: #14928A;
  226. color: #fff;
  227. }
  228. }
  229. .logo {
  230. padding-top: 1rem;
  231. padding-bottom: .9rem;
  232. width: 1.6rem;
  233. margin: 0 auto;
  234. img {
  235. width: inherit;
  236. }
  237. }
  238. .input-group {
  239. position: relative;
  240. height: .44rem;
  241. border-radius: .5rem;
  242. border: .02rem solid @whiteColor;
  243. margin-bottom: .2rem;
  244. padding-left: .3rem;
  245. padding-right: .3rem;
  246. display: flex;
  247. align-items: center;
  248. .input {
  249. flex: 1;
  250. font-size: .14rem;
  251. color: @whiteColor;
  252. background: transparent;
  253. border: none;
  254. &::placeholder {
  255. color: @whiteColor;
  256. }
  257. }
  258. .code-text {
  259. position: absolute;
  260. right: 0;
  261. flex: 1;
  262. display: block;
  263. width: .94rem;
  264. text-align: center;
  265. border-left: .02rem solid @whiteColor;
  266. font-size: .14rem;
  267. color: @whiteColor;
  268. line-height: .3rem;
  269. height: .3rem;
  270. }
  271. }
  272. /deep/.van-count-down {
  273. font-size: .14rem;
  274. color: @whiteColor;
  275. line-height: .3rem;
  276. height: .3rem;
  277. }
  278. /deep/.van-button--large {
  279. height: .44rem;
  280. line-height: .42rem;
  281. color: @mColor;
  282. border: 0;
  283. }
  284. /deep/.van-button:active::before {
  285. opacity: 0.05;
  286. }
  287. /deep/.van-button--disabled {
  288. opacity: 1;
  289. color: rgba(0, 0, 0, 0.25);
  290. }
  291. .login-change {
  292. padding-top: .08rem;
  293. font-size: .14rem;
  294. color: @whiteColor;
  295. float: right;
  296. }
  297. </style>