index.vue 6.5 KB

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