index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. try {
  71. this.formData.authUserId = this.authUserId
  72. const res = await this.$http.api.customLogin(this.formData)
  73. this.$store.dispatch('user/login', res.data)
  74. this.$setStorage(this.routePrefix, 'userInfo', res.data)
  75. // 关闭登录窗口
  76. this.onClose()
  77. } catch (error) {
  78. console.log(error)
  79. }
  80. },
  81. // 关闭登录窗口
  82. onClose() {
  83. this.$store.commit('app/HIDE_LOGIN')
  84. },
  85. async onSend() {
  86. if (this.sendStatus > 0) return
  87. // 验证手机号是否合法
  88. if (!isMobile(this.formData.mobile)) {
  89. this.$toast('请输入正确的手机号')
  90. return
  91. }
  92. try {
  93. // 发送验证码
  94. const res = await this.$http.api.sendVerifyCode({
  95. mobile: this.formData.mobile,
  96. authUserId: this.authUserId,
  97. type: 1,
  98. })
  99. this.$toast('验证码已发送')
  100. // 开启倒计时
  101. this.countdown()
  102. } catch (error) {
  103. console.log(error)
  104. }
  105. },
  106. countdown() {
  107. this.sendStatus = 30
  108. this.timer = setInterval(() => {
  109. if (this.sendStatus === 0) {
  110. clearInterval(this.timer)
  111. return
  112. }
  113. this.sendStatus--
  114. }, 1000)
  115. },
  116. },
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. @media screen and (min-width: 768px) {
  121. .wrapper {
  122. height: 100vh;
  123. .block {
  124. position: relative;
  125. width: 532px;
  126. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  127. border-radius: 45px;
  128. .close {
  129. position: absolute;
  130. right: 16px;
  131. top: 16px;
  132. width: 24px;
  133. height: 24px;
  134. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  135. center no-repeat;
  136. background-size: 24px 24px;
  137. cursor: pointer;
  138. }
  139. .logo {
  140. width: 294px;
  141. height: 57px;
  142. margin: 98px 0 82px;
  143. }
  144. .form-item {
  145. position: relative;
  146. width: 464px;
  147. input {
  148. width: 464px;
  149. height: 50px;
  150. display: block;
  151. padding: 16px 24px;
  152. font-size: 14px;
  153. border: 1px solid #000000;
  154. box-sizing: border-box;
  155. background: transparent;
  156. font-size: 19px;
  157. }
  158. .code {
  159. padding-right: 220px;
  160. }
  161. .send {
  162. position: absolute;
  163. right: 18px;
  164. top: 50%;
  165. transform: translateY(-50%);
  166. font-size: 16px;
  167. color: #a62645;
  168. cursor: pointer;
  169. }
  170. }
  171. .submit {
  172. width: 200px;
  173. height: 58px;
  174. margin: 0 auto;
  175. background: #000;
  176. font-size: 16px;
  177. color: #fff;
  178. text-align: center;
  179. line-height: 58px;
  180. cursor: pointer;
  181. margin-top: 39px;
  182. margin-bottom: 59px;
  183. }
  184. }
  185. }
  186. }
  187. @media screen and (max-width: 768px) {
  188. .wrapper {
  189. height: 100vh;
  190. .block {
  191. position: relative;
  192. width: 76vw;
  193. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  194. border-radius: 4.5vw;
  195. .close {
  196. position: absolute;
  197. right: 2.4vw;
  198. top: 2.4vw;
  199. width: 5.6vw;
  200. height: 5.6vw;
  201. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  202. center no-repeat;
  203. background-size: 4.8vw 4.8vw;
  204. cursor: pointer;
  205. }
  206. .logo {
  207. width: 42vw;
  208. height: 8.2vw;
  209. margin: 14vw 0 11.6vw;
  210. }
  211. .form-item {
  212. position: relative;
  213. width: 66.1vw;
  214. input {
  215. width: 66.1vw;
  216. height: 7.1vw;
  217. display: block;
  218. padding: 2.2vw 3.4vw;
  219. font-size: 2.7vw;
  220. border: 0.1vw solid #000;
  221. background: transparent;
  222. box-sizing: border-box;
  223. font-size: 2.7vw;
  224. }
  225. .code {
  226. padding-right: 30vw;
  227. }
  228. .send {
  229. position: absolute;
  230. right: 3vw;
  231. top: 50%;
  232. transform: translateY(-50%);
  233. font-size: 3.2vw;
  234. color: #bc1724;
  235. cursor: pointer;
  236. }
  237. }
  238. .submit {
  239. width: 28.4vw;
  240. height: 8.2vw;
  241. margin: 0 auto;
  242. background: #000;
  243. font-size: 3.2vw;
  244. color: #fff;
  245. text-align: center;
  246. line-height: 8.2vw;
  247. margin-top: 5.6vw;
  248. margin-bottom: 8.4vw;
  249. }
  250. }
  251. }
  252. }
  253. </style>