index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="login-box">
  3. <div class="login-content">
  4. <div class="login-header mt-1 ml-1">
  5. <div class="left">
  6. <div ref="phone" :class="['left-qrCode', {'phone-switch': isPhone}]" @click="handlePhone">
  7. <div class="switch-tip">
  8. {{ isPhone ? '短信、密码登录/注册' : '微信扫码快速登录' }}
  9. </div>
  10. </div>
  11. </div>
  12. <div class="right mr-2 mt-3" v-if="showClose">
  13. <v-icon color="grey" size="30">mdi-close</v-icon>
  14. </div>
  15. </div>
  16. <div class="login-content-box mt-5">
  17. <div v-if="!isPhone" class="login-tab">
  18. <v-tabs v-model="tab" align-tabs="center" color="#00897B">
  19. <v-tab :value="1">短信登录</v-tab>
  20. <v-tab :value="2">密码登录</v-tab>
  21. </v-tabs>
  22. <v-window v-model="tab" class="mt-9">
  23. <!-- 验证码登录 -->
  24. <v-window-item :value="1">
  25. <phoneFrom ref="phoneRef"></phoneFrom>
  26. </v-window-item>
  27. <!-- 账号密码登录 -->
  28. <v-window-item :value="2">
  29. <passwordFrom ref="passRef"></passwordFrom>
  30. </v-window-item>
  31. </v-window>
  32. </div>
  33. <div v-else>
  34. <!-- 微信扫码登录 -->
  35. <qr-code></qr-code>
  36. </div>
  37. <v-btn v-if="!isPhone" :loading="loginLoading" color="primary" class="white--text mt-5" min-width="350" @click="handleLogin">
  38. {{ tab === 1 ? $t('login.register') : $t('login.login') }}
  39. </v-btn>
  40. <div class="login-tips mt-3">
  41. 登录/注册即代表您同意
  42. <span class="color" style="cursor: pointer;" @click="handleToUserAgreement">[用户协议]</span>
  43. <span class="color" style="cursor: pointer;" @click="handlePrivacyPolicy">[隐私政策]</span>
  44. </div>
  45. </div>
  46. </div>
  47. <v-snackbar v-model="tips.show" :color="tips.color" :timeout="1500" location="top">{{ tips.text }}</v-snackbar>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { ref, reactive } from 'vue'
  52. import passwordFrom from './components/passwordPage.vue'
  53. import phoneFrom from '@/components/VerificationCode'
  54. import qrCode from './components/qrCode.vue'
  55. import { userLocaleStore } from '@/store/user'
  56. import { useRouter } from 'vue-router'
  57. defineOptions({ name: 'login-index' })
  58. const router = useRouter()
  59. const phone = ref()
  60. let isPhone = ref(false)
  61. const handlePhone = () => {
  62. isPhone.value = !isPhone.value
  63. phone.value.style.backgroundPosition = isPhone.value ? '0 -80px' : '0 0'
  64. }
  65. const tab = ref(1)
  66. const showClose = ref(false)
  67. // 验证码登录
  68. const phoneRef = ref()
  69. const passRef = ref()
  70. const loginLoading = ref(false)
  71. const userStore = userLocaleStore()
  72. const tips = reactive({
  73. show: false,
  74. color: '',
  75. text: ''
  76. })
  77. const handleLogin = async () => {
  78. const { valid } = tab.value === 1 ? await phoneRef.value.phoneForm.validate() : await passRef.value.passwordForm.validate()
  79. if (!valid) return
  80. loginLoading.value = true
  81. try {
  82. if (tab.value === 1) {
  83. await userStore.handleSmsLogin(phoneRef.value.loginData)
  84. } else {
  85. await userStore.handlePasswordLogin(passRef.value.loginData)
  86. }
  87. tips.color = 'success'
  88. tips.text = '登录成功'
  89. tips.show = true
  90. router.push({ path: '/home' })
  91. } catch (error) {
  92. console.log(error, 'error-login')
  93. alert(error.msg)
  94. } finally {
  95. loginLoading.value = false
  96. }
  97. }
  98. // 隐私、用户协议
  99. const handleToUserAgreement = () => {
  100. router.push({ path: '/userAgreement' })
  101. }
  102. const handlePrivacyPolicy = () => {
  103. router.push({ path: '/privacyPolicy' })
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .login-box {
  108. position: relative;
  109. width: 100%;
  110. height: 100%;
  111. background-image: url('https://www.menduner.com/images/userfiles/92d7e4a755e2428b94aab3636d5047f3/images/recruitment/adImages/2018/11/1920x940.jpg');
  112. background-size: cover;
  113. }
  114. .login-content {
  115. position: absolute;
  116. top: 50%;
  117. left: 50%;
  118. translate: -50% -50%;
  119. width: 450px;
  120. height: 430px;
  121. background-color: #fff;
  122. border-radius: 10px;
  123. }
  124. .login-header {
  125. display: flex;
  126. justify-content: space-between;
  127. align-items: center;
  128. height: 40px;
  129. }
  130. .login-content-box {
  131. padding: 0 50px;
  132. }
  133. .left {
  134. display: flex;
  135. }
  136. .left-qrCode {
  137. position: absolute;
  138. left: 8px;
  139. top: 8px;
  140. width: 40px;
  141. height: 40px;
  142. cursor: pointer;
  143. background: url('../../assets/login.png') 0 0/40px auto no-repeat;
  144. }
  145. .left-qrCode:hover {
  146. background-position: 0 -40px !important;
  147. }
  148. .left-qrCode.phone-switch {
  149. background-position: 0 -80px !important;
  150. }
  151. .left-qrCode.phone-switch:hover {
  152. background-position: 0 -120px !important;
  153. }
  154. .switch-tip {
  155. position: absolute;
  156. left: 60px;
  157. top: 4px;
  158. padding: 0 14px;
  159. border-radius: 4px;
  160. font-size: 12px;
  161. color: #666;
  162. line-height: 32px;
  163. text-align: center;
  164. background-color: #fff;
  165. box-shadow: 0 6px 13px 0 rgba(0,0,0,.1);
  166. white-space: nowrap;
  167. &::before {
  168. content: '';
  169. position: absolute;
  170. left: -5px;
  171. top: 50%;
  172. transform: translateY(-50%) rotate(45deg);
  173. width: 10px;
  174. height: 10px;
  175. background-color: #fff;
  176. box-shadow: 0 6px 13px 0 rgba(0,0,0,.1);
  177. }
  178. }
  179. .login-tips {
  180. width: 100%;
  181. font-size: 12px;
  182. text-align: center;
  183. }
  184. .color {
  185. color: var(--v-primary-base);
  186. }
  187. </style>