index.vue 6.1 KB

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