index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <div class="box" :style="{'background-image': 'url(' + logoBgUrl + ')'}">
  3. <div class="content">
  4. <div class="login-content">
  5. <v-card height="392px" class="carousel mr-3" style="width: 792px; border-radius: 8px;">
  6. <v-carousel show-arrows="hover" cycle :model-value="0">
  7. <v-carousel-item v-for="(item, i) in carouselList" :key="i" @click="handleClick(item)">
  8. <div style="height: 392px; overflow: hidden;" :class="{'cursor-pointer': item.link}">
  9. <v-img :src="item.img" :lazy-src="item.src" cover style="height: 100%; overflow: hidden;">
  10. <template v-slot:placeholder>
  11. <v-row align="center" class="fill-height ma-0" justify="center">
  12. <v-progress-circular color="grey-lighten-5" indeterminate></v-progress-circular>
  13. </v-row>
  14. </template>
  15. </v-img>
  16. </div>
  17. </v-carousel-item>
  18. </v-carousel>
  19. </v-card>
  20. <div class="login-card">
  21. <div class="login-change" @click="handleChangeLogin">{{ isEnterpriseLogin ? '切换个人登录' : '切换企业登录' }}</div>
  22. <!-- 企业邮箱登录 -->
  23. <div v-show="isEnterpriseLogin" class="login-tab">
  24. <v-tabs v-model="tab1" align-tabs="center" color="primary" class="mb-10">
  25. <v-tab :value="1">企业邮箱登录</v-tab>
  26. </v-tabs>
  27. <passwordFrom ref="entPassRef" placeholder="请输入企业邮箱" :isCounter="true" :validEmail="true" @handleEnter="handleLogin"></passwordFrom>
  28. </div>
  29. <!-- 个人登录 -->
  30. <div v-show="!isEnterpriseLogin" class="login-tab">
  31. <v-tabs v-model="tab" align-tabs="center" color="primary" :class="`mb-${tab === 3 ? 6 : 9}`" @update:modelValue="tabChange">
  32. <v-tab :value="2">账号</v-tab>
  33. <v-tab :value="1">验证码</v-tab>
  34. <v-tab :value="3">微信扫码</v-tab>
  35. </v-tabs>
  36. <v-window v-model="tab">
  37. <!-- 验证码登录 -->
  38. <v-window-item :value="1">
  39. <phoneFrom ref="phoneRef" openVerify @handleEnter="handleLogin"></phoneFrom>
  40. </v-window-item>
  41. <!-- 账号密码登录 -->
  42. <v-window-item :value="2">
  43. <passwordFrom ref="passRef" @handleEnter="handleLogin"></passwordFrom>
  44. </v-window-item>
  45. <v-window-item :value="3">
  46. <div v-if="showQrCode" class="d-flex align-center flex-column position-relative">
  47. <v-img :src="qrCodeUrl" width="200" height="200"></v-img>
  48. <span class="color-666 font-size-13 mt-3">请使用微信扫描二维码登录“门墩儿”</span>
  49. <span v-if="remainderZhShow" class="color-warning font-size-13 mt-1">请在{{ remainderZhShow }}内扫码授权登录</span>
  50. <div v-if="qrCodeDisabled" class="disabledBox">
  51. <div class="disabledContent">
  52. <div class="color-666">请重新刷新二维码</div>
  53. <v-btn color="primary" class="mt-5" elevation="0" @click="disabledClick">点击刷新</v-btn>
  54. </div>
  55. </div>
  56. </div>
  57. <div v-else style="height: 150px; line-height: 150px; text-align: center;">
  58. 加载中 . . .
  59. </div>
  60. </v-window-item>
  61. </v-window>
  62. </div>
  63. <div class="font-size-14">
  64. <span v-if="tab === 2" class="float-left tips color-666 cursor-pointer" @click="router.push(isEnterpriseLogin ? '/forgotPasswordEnt': '/forgotPassword')">忘记密码</span>
  65. <span v-if="tab !== 3" class="float-right color-error cursor-pointer border-bottom-error" @click="router.push('/register/selected')">还没有登录账户?去注册</span>
  66. </div>
  67. <v-btn v-if="tab !== 3" :loading="loginLoading" color="primary" class="white--text mt-5" min-width="350" @click.stop="handleLogin">
  68. {{ $t('login.login') }}
  69. </v-btn>
  70. <div class="login-tips mt-3" v-if="tab !== 3">
  71. <v-icon v-if="isAgree" size="25" color="primary" class="mr-1" @click="isAgree = !isAgree">mdi-check-circle</v-icon>
  72. <v-icon v-else size="25" color="grey" class="mr-1" @click="isAgree = !isAgree">mdi-circle-outline</v-icon>
  73. {{ $t('login.agreeLogin') }}
  74. <span class="color" style="cursor: pointer;" @click="windowOpen('/userAgreement')"> [{{ $t('login.userAgreement') }}] </span>和
  75. <span class="color" style="cursor: pointer;" @click="windowOpen('/privacyPolicy')">[{{ $t('login.privacyPolicy') }}]</span>
  76. </div>
  77. </div>
  78. </div>
  79. <div class="aboutBox">
  80. <about :showBanner="false"></about>
  81. </div>
  82. </div>
  83. <navBar v-if="!isMobile" :showLoginBtn="false" class="navBar"></navBar>
  84. </div>
  85. <Verify
  86. ref="verify"
  87. captchaType="blockPuzzle"
  88. :imgSize="{ width: '400px', height: '200px' }"
  89. mode="pop"
  90. @success="verifySuccess"
  91. />
  92. </template>
  93. <script setup>
  94. defineOptions({ name: 'login-index' })
  95. import { nextTick, ref, onMounted } from 'vue'
  96. import passwordFrom from './components/passwordPage.vue'
  97. import phoneFrom from '@/components/VerificationCode'
  98. import { useUserStore } from '@/store/user'
  99. import { useRouter } from 'vue-router'
  100. import { useI18n } from '@/hooks/web/useI18n'
  101. import {
  102. getEnterpriseRegisterApply,
  103. getWebContent
  104. // socialAuthRedirect,
  105. } from '@/api/common'
  106. import Snackbar from '@/plugins/snackbar'
  107. import Confirm from '@/plugins/confirm'
  108. import navBar from '@/layout/personal/navBar.vue'
  109. import about from '@/views/about/index.vue'
  110. import { useRoute } from 'vue-router'; const route = useRoute()
  111. import Verify from '@/components/Verifition'
  112. import { useMallStore } from '@/store/mall'
  113. import { generateUUID } from '@/utils/index'
  114. import { getWeXinLoginQrCode, checkWeXinLoginAuthorize } from '@/api/common/qrcodeLogin'
  115. const isMobile = ref(false)
  116. onMounted(async () => {
  117. await useMallStore().getMallDiyTemplate()
  118. const userAgent = navigator.userAgent
  119. isMobile.value = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(userAgent)
  120. })
  121. // 获取轮播图、背景图
  122. const logoBgUrl = ref('')
  123. const preferred = ref({})
  124. const carouselList = ref([])
  125. const getSystemWebContent = async () => {
  126. const data = await getWebContent()
  127. logoBgUrl.value = data.pcLoginBackground && data.pcLoginBackground.length ? data.pcLoginBackground[0].img : 'https://minio.menduner.com/dev/menduner/login-bgc.jpg'
  128. carouselList.value = data.pcLoginCarousel || []
  129. preferred.value = data.appPreferredGroup || {}
  130. }
  131. getSystemWebContent()
  132. const handleClick = (item) => {
  133. if (!item.link) return
  134. if (item.link.includes('http')) return window.open(item.link)
  135. // 优选集团
  136. if (preferred.value && Object.keys(preferred.value).length > 0 && preferred.value[item.link]) window.open(`/recruit/personal/advertisement/${item.link}`)
  137. else window.open(`/recruit/personal/company/details/${item.link}?key=briefIntroduction`)
  138. }
  139. const { t } = useI18n()
  140. const router = useRouter()
  141. const tab = ref(2) // 密码登录
  142. const tab1 = ref(1)
  143. const isAgree = ref(false)
  144. const isEnterpriseLogin = ref(route.query?.entLogin || false)
  145. const handleChangeLogin = () => {
  146. isEnterpriseLogin.value = !isEnterpriseLogin.value
  147. nextTick(() => {
  148. // tab.value = isEnterpriseLogin.value ? 2 : 1 // 为了验证邮箱validate,企业邮箱登录时需要tab
  149. tab.value = 2 // 为了验证邮箱validate,企业邮箱登录时需要tab=2
  150. })
  151. }
  152. // 验证码登录
  153. const phoneRef = ref()
  154. const passRef = ref()
  155. const entPassRef = ref()
  156. const loginLoading = ref(false)
  157. const userStore = useUserStore()
  158. const handleCheckEnterprise = async () => {
  159. const data = await getEnterpriseRegisterApply(entPassRef.value.loginData.phone)
  160. if (data && Object.keys(data).length) {
  161. // 查看申请状态
  162. localStorage.setItem('entRegisterData', JSON.stringify(data))
  163. localStorage.setItem('loginAccount', data.phone)
  164. router.push({ path: '/recruit/entRegister/inReview', query: { type: 'noLoginToRegister', noLogin: true } })
  165. }
  166. }
  167. const handleLogin = async () => {
  168. const { valid } = isEnterpriseLogin.value ? await entPassRef.value.passwordForm.validate() : tab.value === 1 ? await phoneRef.value.phoneForm.validate() : await passRef.value.passwordForm.validate()
  169. if (!valid) return
  170. if (!isAgree.value) return Snackbar.warning('请阅读并勾选底部协议')
  171. loginLoading.value = true
  172. try {
  173. let params, api = {}
  174. if (isEnterpriseLogin.value) { params = { ...entPassRef.value.loginData }; api = 'handlePasswordLogin'}
  175. else { params = tab.value === 1 ? { ...phoneRef.value.loginData } : { ...passRef.value.loginData }; api = tab.value === 1 ? 'handleSmsLogin' : 'handlePasswordLogin'}
  176. if (!params.captchaVerification && captchaStr.value) params.captchaVerification = captchaStr.value
  177. if (!params.captchaVerification) {
  178. getCode() // 验证码组件
  179. return
  180. }
  181. // 邮箱为企业招聘, 手机号为个人求职
  182. if (isEnterpriseLogin.value) {
  183. const pattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  184. const isEnterprise = pattern.test(params.phone)
  185. if (!isEnterprise) return // 选中企业登录但输入内容非邮箱
  186. params.isEnterprise = isEnterprise
  187. }
  188. await userStore[api](params)
  189. // 跳转
  190. if (params.isEnterprise) return // 企业邮箱登录
  191. else localStorage.setItem('simpleCompleteDialogHaveBeenShow', true) // 个人登录简易基本信息填写弹窗open-status
  192. Snackbar.success(t('login.loginSuccess'))
  193. router.push({ path: '/recruitHome' })
  194. } catch (err) {
  195. console.log(err)
  196. captchaStr.value = '' // 清空人机验证
  197. if (tab.value === 1) phoneRef.value.clearCaptcha() // 清空人机验证
  198. if (!err.code || (err?.message && err.message.includes('timeout'))) return
  199. if (err.code === 1100017022) {
  200. // 密码不安全
  201. router.push('/forgotPassword?forgot=1')
  202. return
  203. }
  204. if (err.code === 1100021016) {
  205. // 企业注册申请中
  206. handleCheckEnterprise()
  207. return
  208. }
  209. // 登录未注册过的账号跳转注册
  210. const text = err.code === 1100016002 ? '您的手机号还未注册过' : '您的邮箱还未注册过'
  211. Confirm('系统提示', `${text},去注册?`, {
  212. cancelCallback: true
  213. }).then(() => {
  214. localStorage.setItem('loginAccount', isEnterpriseLogin.value ? entPassRef.value.loginData.phone : tab.value === 1 ? phoneRef.value.loginData.phone : passRef.value.loginData.phone)
  215. router.push(err.code === 1100016002 ? '/register/person?type=noLoginToRegister' : '/register/company?type=noLoginToRegister')
  216. }).catch(() => {})
  217. } finally {
  218. loginLoading.value = false
  219. }
  220. }
  221. // 微信扫码-小程序授权登录
  222. const qrCodeUrl = ref(null)
  223. const showQrCode = ref(true)
  224. const qrCodeDisabled = ref(true )
  225. const query = ref({
  226. clientId: null
  227. })
  228. const remainder = ref(0)
  229. const remainderZhShow = ref('')
  230. const remainderTimer = ref(null)
  231. const abortController = ref(null)
  232. const formatDuration = (time) => {
  233. var seconds = Math.floor(time / 1000)
  234. var minutes = Math.floor(seconds / 60)
  235. var remainingSeconds = seconds % 60
  236. minutes = minutes.toString().padStart(2, '0')
  237. remainingSeconds = remainingSeconds.toString().padStart(2, '0')
  238. return `${minutes}分${remainingSeconds}秒`
  239. }
  240. const remainderCalc = () => {
  241. remainder.value -= 1000
  242. remainderZhShow.value = formatDuration(remainder.value)
  243. if (remainder.value <= 0) {
  244. qrCodeDisabled.value = true
  245. // 取消所有正在进行的请求
  246. if (abortController.value) {
  247. abortController.value.abort()
  248. abortController.value = null
  249. }
  250. handleAuthorize(true)
  251. }
  252. }
  253. // 初始化倒计时
  254. const countdownTime = 60000 * 5 // 倒计时五分钟
  255. const initIntervalFun = () => {
  256. remainder.value = countdownTime // 初始倒计时时间
  257. if (remainderTimer.value) clearInterval(remainderTimer.value); remainderTimer.value = null // 每一次点击都清除上一个轮询
  258. // 倒计时计算
  259. remainderCalc()
  260. remainderTimer.value = setInterval(() => { remainderCalc() }, 1000)
  261. }
  262. // 轮巡查询是否授权成功
  263. const handleAuthorize = async (stop) => {
  264. // 二维码失效停止请求
  265. if (stop) return
  266. try {
  267. abortController.value = new AbortController()
  268. const signal = abortController.value.signal
  269. const data = await checkWeXinLoginAuthorize(query.value, signal)
  270. if (!data) return
  271. query.value.clientId = data.clientId
  272. // 等待扫码授权中
  273. if (data.status === '0' || !data.appMdeAuthLoginRespVO || !Object.keys(data.appMdeAuthLoginRespVO).length) {
  274. handleAuthorize()
  275. return
  276. }
  277. // 授权成功,返回登录信息
  278. await userStore.handleWeXinQrCodeLogin(data.appMdeAuthLoginRespVO)
  279. router.push('/')
  280. } catch (error) {
  281. console.log(error, 'error')
  282. }
  283. }
  284. // 小程序二维码获取
  285. const getSocialAuthRedirect = async () => {
  286. showQrCode.value = false
  287. try {
  288. const data = await getWeXinLoginQrCode(query.value)
  289. qrCodeUrl.value = URL.createObjectURL(data)
  290. qrCodeDisabled.value = false
  291. showQrCode.value = true
  292. initIntervalFun()
  293. handleAuthorize()
  294. } catch {
  295. showQrCode.value = false
  296. }
  297. }
  298. // 二维码过期重新生成
  299. const disabledClick = () => {
  300. qrCodeDisabled.value = false
  301. query.value.clientId = generateUUID()
  302. getSocialAuthRedirect()
  303. }
  304. const tabChange = (val) => {
  305. if (val === 3) {
  306. if (abortController.value) {
  307. abortController.value.abort()
  308. abortController.value = null
  309. }
  310. query.value.clientId = generateUUID()
  311. getSocialAuthRedirect()
  312. }
  313. }
  314. // 获取验证码
  315. const verify = ref()
  316. const getCode = async () => {
  317. // 弹出验证码 // 已开启:则展示验证码;只有完成验证码的情况,才进行登录
  318. verify.value.show()
  319. }
  320. const captchaStr = ref('')
  321. const verifySuccess = (params) => {
  322. captchaStr.value = params.captchaVerification
  323. handleLogin()
  324. }
  325. const windowOpen = (url) => {
  326. if (url) window.open(url)
  327. }
  328. </script>
  329. <style lang="scss" scoped>
  330. .disabledBox {
  331. position: absolute;
  332. top: 0;
  333. left: 0;
  334. background: rgb(255 255 255 / 90%);
  335. height: 100%;
  336. width: 100%;
  337. }
  338. .disabledContent {
  339. height: 90%;
  340. width: 100%;
  341. display: flex;
  342. flex-direction: column;
  343. justify-content: center;
  344. align-items: center;
  345. }
  346. .box {
  347. position: relative;
  348. width: 100%;
  349. height: 100vh;
  350. background-size: cover;
  351. overflow: hidden;
  352. .navBar {
  353. position: absolute;
  354. top: 0;
  355. }
  356. }
  357. .content {
  358. width: 100%;
  359. height: 100%;
  360. overflow-y: auto;
  361. }
  362. .login-content {
  363. display: flex;
  364. align-items: center;
  365. justify-content: center;
  366. width: 100%;
  367. height: 78vh;
  368. // height: calc(100vh - 50px);
  369. margin-top: 50px;
  370. }
  371. .login-change {
  372. position: absolute;
  373. top: 0;
  374. right: 0;
  375. margin: 15px 44px;
  376. border-bottom: 1px solid orange;
  377. color: orange;
  378. cursor: pointer;
  379. font-weight: 400;
  380. &:hover {
  381. color: #fbb93e;
  382. }
  383. }
  384. .login-card {
  385. position: relative;
  386. width: 450px;
  387. background-color: #fff;
  388. border-radius: 8px;
  389. padding: 36px 50px;
  390. height: 392px;
  391. }
  392. .left {
  393. display: flex;
  394. }
  395. .login-tips {
  396. width: 100%;
  397. font-size: 12px;
  398. display: flex;
  399. justify-content: center;
  400. align-items: center;
  401. }
  402. .tips:hover {
  403. border-bottom: 1px solid #666;
  404. }
  405. .color {
  406. color: var(--v-primary-base);
  407. }
  408. .aboutBox {
  409. width: 100%;
  410. background-color: #fff;
  411. }
  412. .carousel {
  413. :deep(.v-window) {
  414. height: 392px !important;
  415. }
  416. }
  417. </style>