index.vue 5.3 KB

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