index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. color: #a62645;
  188. cursor: pointer;
  189. }
  190. }
  191. .submit {
  192. height: 58px;
  193. margin: 0 auto;
  194. background: #000;
  195. font-size: 16px;
  196. color: #fff;
  197. text-align: center;
  198. line-height: 58px;
  199. cursor: pointer;
  200. margin-top: 39px;
  201. margin-bottom: 59px;
  202. }
  203. }
  204. }
  205. }
  206. @media screen and (max-width: 768px) {
  207. .wrapper {
  208. height: 100vh;
  209. .block {
  210. position: relative;
  211. width: 76vw;
  212. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  213. border-radius: 4.5vw;
  214. .close {
  215. position: absolute;
  216. right: 2.4vw;
  217. top: 2.4vw;
  218. width: 5.6vw;
  219. height: 5.6vw;
  220. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  221. center no-repeat;
  222. background-size: 4.8vw 4.8vw;
  223. cursor: pointer;
  224. }
  225. .logo {
  226. width: 42vw;
  227. height: 8.2vw;
  228. margin: 14vw 0 11.6vw;
  229. }
  230. .form-item {
  231. position: relative;
  232. width: 66.1vw;
  233. input {
  234. width: 66.1vw;
  235. height: 7.1vw;
  236. display: block;
  237. padding: 2.2vw 3.4vw;
  238. font-size: 2.7vw;
  239. border: 0.1vw solid #000;
  240. background: transparent;
  241. box-sizing: border-box;
  242. font-size: 2.7vw;
  243. }
  244. .code {
  245. padding-right: 30vw;
  246. }
  247. .send {
  248. position: absolute;
  249. right: 3vw;
  250. top: 50%;
  251. transform: translateY(-50%);
  252. font-size: 3.2vw;
  253. color: #bc1724;
  254. cursor: pointer;
  255. }
  256. }
  257. .submit {
  258. height: 8.2vw;
  259. margin: 0 auto;
  260. background: #000;
  261. font-size: 3.2vw;
  262. color: #fff;
  263. text-align: center;
  264. line-height: 8.2vw;
  265. margin-top: 5.6vw;
  266. margin-bottom: 8.4vw;
  267. }
  268. }
  269. }
  270. }
  271. </style>