index.vue 6.0 KB

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