index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. @include useTheme() {
  143. height: 100vh;
  144. .block {
  145. position: relative;
  146. width: 532px;
  147. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  148. border-radius: 45px;
  149. .close {
  150. position: absolute;
  151. right: 16px;
  152. top: 16px;
  153. width: 24px;
  154. height: 24px;
  155. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  156. center no-repeat;
  157. background-size: 24px 24px;
  158. cursor: pointer;
  159. }
  160. .logo {
  161. width: 294px;
  162. height: 57px;
  163. margin: 98px 0 82px;
  164. }
  165. .form-item {
  166. position: relative;
  167. width: 464px;
  168. input {
  169. width: 464px;
  170. height: 50px;
  171. display: block;
  172. padding: 16px 24px;
  173. font-size: 14px;
  174. border: 1px solid #000000;
  175. box-sizing: border-box;
  176. background: transparent;
  177. font-size: 19px;
  178. }
  179. .code {
  180. padding-right: 220px;
  181. }
  182. .send {
  183. position: absolute;
  184. right: 18px;
  185. top: 50%;
  186. transform: translateY(-50%);
  187. font-size: 16px;
  188. color: fetch('color');
  189. cursor: pointer;
  190. }
  191. }
  192. .submit {
  193. height: 58px;
  194. margin: 0 auto;
  195. background: #000;
  196. font-size: 16px;
  197. color: #fff;
  198. text-align: center;
  199. line-height: 58px;
  200. cursor: pointer;
  201. margin-top: 39px;
  202. margin-bottom: 59px;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. @media screen and (max-width: 768px) {
  209. .wrapper {
  210. @include useTheme() {
  211. height: 100vh;
  212. .block {
  213. position: relative;
  214. width: 76vw;
  215. background: linear-gradient(180deg, #d7dbe6, #ffffff);
  216. border-radius: 4.5vw;
  217. .close {
  218. position: absolute;
  219. right: 2.4vw;
  220. top: 2.4vw;
  221. width: 5.6vw;
  222. height: 5.6vw;
  223. background: url(https://static.caimei365.com/www/authentic/h5/icon-close.png)
  224. center no-repeat;
  225. background-size: 4.8vw 4.8vw;
  226. cursor: pointer;
  227. }
  228. .logo {
  229. width: 42vw;
  230. height: 8.2vw;
  231. margin: 14vw 0 11.6vw;
  232. }
  233. .form-item {
  234. position: relative;
  235. width: 66.1vw;
  236. input {
  237. width: 66.1vw;
  238. height: 7.1vw;
  239. display: block;
  240. padding: 2.2vw 3.4vw;
  241. font-size: 2.7vw;
  242. border: 0.1vw solid #000;
  243. background: transparent;
  244. box-sizing: border-box;
  245. font-size: 2.7vw;
  246. }
  247. .code {
  248. padding-right: 30vw;
  249. }
  250. .send {
  251. position: absolute;
  252. right: 3vw;
  253. top: 50%;
  254. transform: translateY(-50%);
  255. font-size: 3.2vw;
  256. color: fetch('color');
  257. cursor: pointer;
  258. }
  259. }
  260. .submit {
  261. height: 8.2vw;
  262. margin: 0 auto;
  263. background: #000;
  264. font-size: 3.2vw;
  265. color: #fff;
  266. text-align: center;
  267. line-height: 8.2vw;
  268. margin-top: 5.6vw;
  269. margin-bottom: 8.4vw;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. </style>