index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div class="ldm-login">
  3. <van-overlay :show="show" @click="show = false">
  4. <div class="wrapper flex justify-center items-center" @click.stop>
  5. <div class="block flex items-center flex-col">
  6. <div class="close" @click="onClose"></div>
  7. <img
  8. class="logo"
  9. src="https://static.caimei365.com/www/authentic/pc/ldm-logo-rect.png"
  10. alt=""
  11. />
  12. <div class="forlogoutm">
  13. <div class="form-item mb-4">
  14. <input
  15. type="text"
  16. placeholder="手机号"
  17. v-model="formData.mobile"
  18. maxlength="11"
  19. />
  20. </div>
  21. <div class="form-item mb-4">
  22. <input
  23. type="text"
  24. placeholder="验证码"
  25. class="code"
  26. v-model="formData.verifyCode"
  27. maxlength="6"
  28. />
  29. <span class="send" @click="onSend">{{ sendCodeBtnText }}</span>
  30. </div>
  31. <div class="submit" @click="onSubmit">登录</div>
  32. </div>
  33. </div>
  34. </div>
  35. </van-overlay>
  36. </div>
  37. </template>
  38. <script>
  39. import { mapGetters } from 'vuex'
  40. import { isMobile } from '@/utils/validator'
  41. export default {
  42. name: 'simple-login',
  43. data() {
  44. return {
  45. show: false,
  46. sendStatus: 0,
  47. formData: {
  48. authUserId: '',
  49. mobile: '',
  50. verifyCode: '',
  51. },
  52. timer: null,
  53. }
  54. },
  55. computed: {
  56. ...mapGetters(['loginVisiable', 'authUserId', 'routePrefix']),
  57. sendCodeBtnText() {
  58. return this.sendStatus === 0
  59. ? '发送验证码'
  60. : `再次发送${this.sendStatus}s`
  61. },
  62. },
  63. watch: {
  64. loginVisiable() {
  65. this.show = this.loginVisiable
  66. },
  67. },
  68. methods: {
  69. async onSubmit() {
  70. // 验证手机号是否合法
  71. if (!isMobile(this.formData.mobile)) {
  72. this.$toast('请输入正确的手机号')
  73. return
  74. }
  75. if (!this.formData.verifyCode) {
  76. this.$toast('请输入验证码')
  77. return
  78. }
  79. try {
  80. this.formData.authUserId = this.authUserId
  81. const res = await this.$http.api.customLogin(this.formData)
  82. this.$store.dispatch('user/login', res.data)
  83. this.$setStorage(this.routePrefix, 'userInfo', res.data)
  84. // 关闭登录窗口
  85. this.onClose()
  86. // 重定向
  87. const login_redicret = this.$getStorage(
  88. this.routePrefix,
  89. 'login_redicret'
  90. )
  91. if (login_redicret) {
  92. this.$router.push(login_redicret)
  93. }
  94. } catch (error) {
  95. console.log(error)
  96. }
  97. },
  98. // 关闭登录窗口
  99. onClose() {
  100. this.$store.commit('app/HIDE_LOGIN')
  101. this.formData.mobile = ''
  102. this.formData.verifyCode = ''
  103. this.formData.authUserId = ''
  104. },
  105. async onSend() {
  106. if (this.sendStatus > 0) return
  107. // 验证手机号是否合法
  108. if (!isMobile(this.formData.mobile)) {
  109. this.$toast('请输入正确的手机号')
  110. return
  111. }
  112. try {
  113. // 发送验证码
  114. const res = await this.$http.api.sendVerifyCode({
  115. mobile: this.formData.mobile,
  116. authUserId: this.authUserId,
  117. type: 1,
  118. })
  119. this.$toast('验证码已发送')
  120. // 开启倒计时
  121. this.countdown()
  122. } catch (error) {
  123. console.log(error)
  124. }
  125. },
  126. countdown() {
  127. this.sendStatus = 30
  128. this.timer = setInterval(() => {
  129. if (this.sendStatus === 0) {
  130. clearInterval(this.timer)
  131. return
  132. }
  133. this.sendStatus--
  134. }, 1000)
  135. },
  136. },
  137. }
  138. </script>
  139. <style scoped lang="scss">
  140. @media screen and (min-width: 768px) {
  141. .wrapper {
  142. height: 100vh;
  143. .block {
  144. position: relative;
  145. width: 532px;
  146. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  147. border-radius: 45px;
  148. .close {
  149. position: absolute;
  150. right: 16px;
  151. top: 16px;
  152. width: 24px;
  153. height: 24px;
  154. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  155. center no-repeat;
  156. background-size: 24px 24px;
  157. cursor: pointer;
  158. }
  159. .logo {
  160. width: 294px;
  161. height: 57px;
  162. margin: 98px 0 82px;
  163. }
  164. .form-item {
  165. position: relative;
  166. width: 464px;
  167. input {
  168. width: 464px;
  169. height: 50px;
  170. display: block;
  171. padding: 16px 24px;
  172. font-size: 14px;
  173. border: 1px solid #000000;
  174. box-sizing: border-box;
  175. background: transparent;
  176. font-size: 19px;
  177. }
  178. .code {
  179. padding-right: 220px;
  180. }
  181. .send {
  182. position: absolute;
  183. right: 18px;
  184. top: 50%;
  185. transform: translateY(-50%);
  186. font-size: 16px;
  187. @include themify($themes) {
  188. color: themed('color');
  189. }
  190. cursor: pointer;
  191. }
  192. }
  193. .submit {
  194. height: 58px;
  195. margin: 0 auto;
  196. background: #000;
  197. font-size: 16px;
  198. color: #fff;
  199. text-align: center;
  200. line-height: 58px;
  201. cursor: pointer;
  202. margin-top: 39px;
  203. margin-bottom: 59px;
  204. }
  205. }
  206. }
  207. }
  208. @media screen and (max-width: 768px) {
  209. .wrapper {
  210. height: 100vh;
  211. .block {
  212. position: relative;
  213. width: 76vw;
  214. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  215. border-radius: 4.5vw;
  216. .close {
  217. position: absolute;
  218. right: 2.4vw;
  219. top: 2.4vw;
  220. width: 5.6vw;
  221. height: 5.6vw;
  222. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  223. center no-repeat;
  224. background-size: 4.8vw 4.8vw;
  225. cursor: pointer;
  226. }
  227. .logo {
  228. width: 42vw;
  229. height: 8.2vw;
  230. margin: 14vw 0 11.6vw;
  231. }
  232. .form-item {
  233. position: relative;
  234. width: 66.1vw;
  235. input {
  236. width: 66.1vw;
  237. height: 7.1vw;
  238. display: block;
  239. padding: 2.2vw 3.4vw;
  240. font-size: 2.7vw;
  241. border: 0.1vw solid #000;
  242. background: transparent;
  243. box-sizing: border-box;
  244. font-size: 2.7vw;
  245. }
  246. .code {
  247. padding-right: 30vw;
  248. }
  249. .send {
  250. position: absolute;
  251. right: 3vw;
  252. top: 50%;
  253. transform: translateY(-50%);
  254. font-size: 3.2vw;
  255. @include themify($themes) {
  256. color: themed('color');
  257. }
  258. cursor: pointer;
  259. }
  260. }
  261. .submit {
  262. height: 8.2vw;
  263. margin: 0 auto;
  264. background: #000;
  265. font-size: 3.2vw;
  266. color: #fff;
  267. text-align: center;
  268. line-height: 8.2vw;
  269. margin-top: 5.6vw;
  270. margin-bottom: 8.4vw;
  271. }
  272. }
  273. }
  274. }
  275. </style>