login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="login">
  3. <div class="contain">
  4. <div class="header">
  5. <div class="back">
  6. <tui-icon name="arrowleft" color="#000" :size="30" @click="handleBack"></tui-icon>
  7. </div>
  8. <div class="bg-box">
  9. <img src="./image/bg.png" alt="">
  10. </div>
  11. <div class="title-box">
  12. <h2>您好!</h2>
  13. <p>欢迎进入全球家具原材料交易平台</p>
  14. </div>
  15. </div>
  16. <div class="main">
  17. <div class="ipt">
  18. <tui-form ref="refLoginForm" :show-message="false">
  19. <tui-input v-model="loginQuery.phone" placeholder="请输入手机号"></tui-input>
  20. <div class="code-box">
  21. <tui-input v-model="loginQuery.verificationCode" :maxlength="4" placeholder="请输入验证码"></tui-input>
  22. <div class="code">
  23. <tui-countdown-verify
  24. ref="refLoginVerify" color="#EF530E" border-color="transparent"
  25. :size="28" :seconds="60" @send="handleSendVerify"
  26. ></tui-countdown-verify>
  27. </div>
  28. </div>
  29. <div class="text">
  30. <p>还没有账号?</p>
  31. <span @click="go('/pages/register/index')">立即注册</span>
  32. </div>
  33. </tui-form>
  34. </div>
  35. <div class="btn-list">
  36. <tui-form-button color="#fff" background="#EF530E" @click="handleLogin">验证码一键登陆</tui-form-button>
  37. <tui-form-button
  38. style="display: none;" color="#EF530E"
  39. background="rgba(234, 91, 29, 0.1)"
  40. >
  41. 密码登陆
  42. </tui-form-button>
  43. </div>
  44. </div>
  45. </div>
  46. <footer>
  47. <p>登录即代表你已阅读并同意</p>
  48. <span>《用户服务协议》</span>
  49. </footer>
  50. </div>
  51. </template>
  52. <script>
  53. import { T_REDIRECT_TYPE, T_STORAGE_KEY } from '../../constant'
  54. import { getVerifyCodeApi } from '../../api/anotherTFInterface'
  55. import { CHANGE_IS_IN_MINIPROGRAM } from '../../store/modules/type'
  56. import { getUrlCode } from '../../utils'
  57. export default {
  58. name: 'Login',
  59. data() {
  60. return {
  61. loginType: 'verificationCode', // password,verificationCode
  62. loginQuery: {
  63. phone: '',
  64. verificationCode: '',
  65. password: ''
  66. }
  67. }
  68. },
  69. onLoad(options) {
  70. if (options.to) uni.setStorageSync(T_REDIRECT_TYPE, options.to)
  71. if (options.miniProgram) {
  72. this.$store.commit(`app/${CHANGE_IS_IN_MINIPROGRAM}`, !!options.miniProgram)
  73. }
  74. },
  75. onShow() {
  76. const userInfo = uni.getStorageSync(T_STORAGE_KEY)
  77. if (userInfo && userInfo.token) {
  78. uni.switchTab({
  79. url: '/'
  80. })
  81. } else if (this.$store.state.app.terminal === 3) {
  82. const code = getUrlCode().code
  83. if (code) this.handleWXLogin()
  84. }
  85. },
  86. methods: {
  87. handleBack() {
  88. uni.navigateBack()
  89. },
  90. // 获取验证码
  91. handleSendVerify() {
  92. if (!this.loginQuery.phone) {
  93. this.$refs.refLoginVerify.reset()
  94. return this.$showToast('请填写手机号')
  95. }
  96. if (!/^1[3-9]\d{9}$/.test(this.loginQuery.phone)) {
  97. this.$refs.refLoginVerify.reset()
  98. return this.$showToast('请输入正确的手机号')
  99. }
  100. getVerifyCodeApi({ phone: this.loginQuery.phone })
  101. .then((res) => {
  102. this.$refs.refLoginVerify.success()
  103. this.$showToast('发送成功,请注意查看手机短信')
  104. })
  105. .catch(() => {
  106. this.$refs.refLoginVerify.reset()
  107. })
  108. },
  109. // 点击登录
  110. handleLogin() {
  111. const validateRules = [ {
  112. name: 'phone',
  113. rule: ['required', 'isMobile'],
  114. msg: ['请输入手机号', '请输入正确的手机号']
  115. } ]
  116. let loginFilterQuery
  117. if (this.loginType === 'verificationCode') {
  118. validateRules.push({
  119. name: 'verificationCode',
  120. rule: ['required', 'isNum'],
  121. msg: [ '请输入验证码' ]
  122. })
  123. loginFilterQuery = {
  124. phone: this.loginQuery.phone,
  125. verificationCode: this.loginQuery.verificationCode
  126. }
  127. } else if (this.loginType === 'password') {
  128. validateRules.push({
  129. name: 'password',
  130. rule: ['required', 'isEnAndNo'],
  131. msg: ['请输入密码', '密码为8~20位英文和数字组合']
  132. })
  133. loginFilterQuery = {
  134. phone: this.loginQuery.phone,
  135. password: this.loginQuery.password
  136. }
  137. }
  138. this.$refs.refLoginForm
  139. .validate(this.loginQuery, validateRules)
  140. .then(() => {
  141. this.$store.dispatch('auth/phoneLoginRegisterAction', {
  142. isAfter: true,
  143. loginData: {
  144. type: 2, // 1注册,2登录
  145. ...loginFilterQuery
  146. }
  147. })
  148. })
  149. .catch((e) => {
  150. this.$showToast(JSON.stringify(e.errorMsg))
  151. })
  152. },
  153. async handleAliPayLogin() {
  154. await this.$store.dispatch('auth/aliPayLoginAction', { isAfter: true })
  155. },
  156. async handleWXLogin() {
  157. await this.$store.dispatch('auth/wxLoginAction', { isAfter: true })
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .login {
  164. .contain {
  165. width: 100%;
  166. position: relative;
  167. .header {
  168. position: relative;
  169. .back {
  170. position: absolute;
  171. top: 80rpx;
  172. left: 35rpx;
  173. }
  174. .bg-box {
  175. width: 100%;
  176. height: 636rpx;
  177. img {
  178. width: 100%;
  179. height: 100%;
  180. display: block;
  181. }
  182. }
  183. .title-box {
  184. position: absolute;
  185. left: 35rpx;
  186. top: 280rpx;
  187. h2 {
  188. font-size: 42rpx;
  189. font-weight: bold;
  190. }
  191. p {
  192. font-size: 32rpx;
  193. margin-top: 15rpx;
  194. }
  195. }
  196. }
  197. .main {
  198. width: 100%;
  199. height: 200rpx;
  200. position: absolute;
  201. left: 0;
  202. top: 550rpx;
  203. border-radius: 40rpx 40rpx 0 0;
  204. background-color: rgb(255, 255, 255);
  205. padding: 60rpx 40rpx;
  206. box-sizing: border-box;
  207. .ipt {
  208. .code-box {
  209. position: relative;
  210. .code {
  211. position: absolute;
  212. right: 0;
  213. top: 50%;
  214. transform: translateY(-50%);
  215. }
  216. }
  217. .text {
  218. margin-top: 30rpx;
  219. display: flex;
  220. font-size: 24rpx;
  221. margin-left: 30rpx;
  222. p {
  223. color: #646466;
  224. }
  225. span {
  226. color: #397BFF;
  227. }
  228. }
  229. }
  230. .btn-list {
  231. margin-top: 120rpx;
  232. display: flex;
  233. flex-direction: column;
  234. gap: 50rpx;
  235. }
  236. }
  237. }
  238. footer {
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. width: 100%;
  243. position: fixed;
  244. left: 0;
  245. bottom: 100rpx;
  246. font-size: 24rpx;
  247. p {
  248. color: #888889;
  249. }
  250. span {
  251. font-weight: 500;
  252. }
  253. }
  254. }
  255. </style>