index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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="primary">
  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. </div>
  48. </template>
  49. <script setup>
  50. import { ref } from 'vue'
  51. import passwordFrom from './components/passwordPage.vue'
  52. import phoneFrom from '@/components/VerificationCode'
  53. import qrCode from './components/qrCode.vue'
  54. import { userLocaleStore } from '@/store/user'
  55. import { useRouter } from 'vue-router'
  56. import Snackbar from '@/plugins/snackbar'
  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 handleLogin = async () => {
  73. const { valid } = tab.value === 1 ? await phoneRef.value.phoneForm.validate() : await passRef.value.passwordForm.validate()
  74. if (!valid) return
  75. loginLoading.value = true
  76. try {
  77. if (tab.value === 1) {
  78. await userStore.handleSmsLogin(phoneRef.value.loginData)
  79. } else {
  80. await userStore.handlePasswordLogin(passRef.value.loginData)
  81. }
  82. Snackbar.success('登录成功')
  83. router.push({ path: '/home' })
  84. }
  85. finally {
  86. loginLoading.value = false
  87. }
  88. }
  89. // 隐私、用户协议
  90. const handleToUserAgreement = () => {
  91. router.push({ path: '/userAgreement' })
  92. }
  93. const handlePrivacyPolicy = () => {
  94. router.push({ path: '/privacyPolicy' })
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .login-box {
  99. position: relative;
  100. width: 100%;
  101. height: 100%;
  102. background-image: url('https://www.menduner.com/images/userfiles/92d7e4a755e2428b94aab3636d5047f3/images/recruitment/adImages/2018/11/1920x940.jpg');
  103. background-size: cover;
  104. }
  105. .login-content {
  106. position: absolute;
  107. top: 50%;
  108. left: 50%;
  109. translate: -50% -50%;
  110. width: 450px;
  111. height: 430px;
  112. background-color: #fff;
  113. border-radius: 10px;
  114. }
  115. .login-header {
  116. display: flex;
  117. justify-content: space-between;
  118. align-items: center;
  119. height: 40px;
  120. }
  121. .login-content-box {
  122. padding: 0 50px;
  123. }
  124. .left {
  125. display: flex;
  126. }
  127. .left-qrCode {
  128. position: absolute;
  129. left: 8px;
  130. top: 8px;
  131. width: 40px;
  132. height: 40px;
  133. cursor: pointer;
  134. background: url('../../assets/login.png') 0 0/40px auto no-repeat;
  135. }
  136. .left-qrCode:hover {
  137. background-position: 0 -40px !important;
  138. }
  139. .left-qrCode.phone-switch {
  140. background-position: 0 -80px !important;
  141. }
  142. .left-qrCode.phone-switch:hover {
  143. background-position: 0 -120px !important;
  144. }
  145. .switch-tip {
  146. position: absolute;
  147. left: 60px;
  148. top: 4px;
  149. padding: 0 14px;
  150. border-radius: 4px;
  151. font-size: 12px;
  152. color: #666;
  153. line-height: 32px;
  154. text-align: center;
  155. background-color: #fff;
  156. box-shadow: 0 6px 13px 0 rgba(0,0,0,.1);
  157. white-space: nowrap;
  158. &::before {
  159. content: '';
  160. position: absolute;
  161. left: -5px;
  162. top: 50%;
  163. transform: translateY(-50%) rotate(45deg);
  164. width: 10px;
  165. height: 10px;
  166. background-color: #fff;
  167. box-shadow: 0 6px 13px 0 rgba(0,0,0,.1);
  168. }
  169. }
  170. .login-tips {
  171. width: 100%;
  172. font-size: 12px;
  173. text-align: center;
  174. }
  175. .color {
  176. color: var(--v-primary-base);
  177. }
  178. </style>