index.vue 16 KB

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