navBar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div>
  3. <v-toolbar
  4. class="banner"
  5. density="compact"
  6. >
  7. <div class="innerBox d-flex align-center">
  8. <div class="nav-logo" @click="router.push('/recruitHome')">
  9. <v-img src="../../assets/logo.png" aspect-ratio="16/9" contain width="90" height="35"></v-img>
  10. </div>
  11. <div class="menuList default-width">
  12. <div v-for="val in navList" :key="val.name" :class="{'active-route': menuActive(val)}">
  13. <template v-if="val.children">
  14. <defineListPage v-bind="$attrs" :title="val.title" :list="val.children" @emitClick="handleClick" :closeOnContentClick="true"></defineListPage>
  15. </template>
  16. <template v-else>
  17. <span
  18. class="cursor-pointer menuList-first-title"
  19. @click.stop="handleClick(val, val.title === '首页' ? false : true)">
  20. {{ val.title }}
  21. </span>
  22. </template>
  23. </div>
  24. </div>
  25. <div class="d-flex align-center position-absolute" style="right: 30px;">
  26. <div class="btns d-flex align-center" v-if="!isLogin && showLoginBtn">
  27. <v-btn color="primary" style="color: #fff !important; background-color: #00B760;" to="/login">{{ t('login.loginOrRegister') }}</v-btn>
  28. </div>
  29. <!-- 头像用户名 -->
  30. <div class="d-flex align-center color-333" v-if="isLogin">
  31. <v-menu open-on-hover>
  32. <template v-slot:activator="{ props }">
  33. <div class="d-flex align-center cursor-pointer px-4" :class="{'active-route': route.path.includes('/recruit/personal/personalCenter'), 'vipBox': vip}" v-bind="props" @click="handleToPersonalCenter">
  34. <div class="position-relative d-flex align-center">
  35. <v-avatar class="avatar">
  36. <v-img alt="" :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" ></v-img>
  37. </v-avatar>
  38. <div v-if="vip" style="position: absolute; right: -9px; bottom: -13px;" @click.stop="router.push('/recruit/personal/personalCenter/memberBenefits/membershipPackage')">
  39. <svg-icon name="huangguan1" size="25"></svg-icon>
  40. </div>
  41. </div>
  42. <div class="ml-3 font-size-15 userName">
  43. {{ baseInfo?.name || userInfo.phone }}
  44. </div>
  45. </div>
  46. </template>
  47. <v-list>
  48. <v-list-item v-for="(item, index) in items" :key="index" @click="item.change">
  49. <template v-slot:prepend>
  50. <v-icon :icon="item.icon"></v-icon>
  51. </template>
  52. <v-list-item-title>{{ item.title }}</v-list-item-title>
  53. </v-list-item>
  54. </v-list>
  55. </v-menu>
  56. <v-chip
  57. class="mx-4 cursor-pointer"
  58. color="#008bb7"
  59. label
  60. size="small"
  61. @click="router.push({ path: paths[6] })"
  62. >
  63. 积分
  64. <strong class="ml-3">{{ userAccount?.point || 0 }}</strong>
  65. </v-chip>
  66. <v-chip
  67. color="primary"
  68. class="cursor-pointer"
  69. label
  70. size="small"
  71. @click="router.push({ path: paths[6] })"
  72. >
  73. 现金
  74. <strong class="ml-3">{{ userAccount?.balance && userAccount?.balance > 0 ? (userAccount?.balance / 100.0).toFixed(2) : 0 }}</strong>
  75. </v-chip>
  76. </div>
  77. <!-- 语言切换 -->
  78. <!-- <v-menu>
  79. <template v-slot:activator="{ props }">
  80. <v-btn
  81. class="ml-3"
  82. color="primary"
  83. icon="mdi-translate"
  84. size="small"
  85. v-bind="props"
  86. >
  87. </v-btn>
  88. </template>
  89. <v-list density="compact" color="primary">
  90. <v-list-item
  91. v-for="item in localeStore.localeMap"
  92. :key="item.name"
  93. :value="item.lang"
  94. :active="localeStore.currentLocale.lang === item.lang"
  95. @click="handleChangeLocale(item)"
  96. >
  97. <v-list-item-title>{{ item.name }}</v-list-item-title>
  98. </v-list-item>
  99. </v-list>
  100. </v-menu> -->
  101. <div class="d-flex align-center ml-4" v-if="showBall">
  102. <message-notification v-if="showBall" :path="paths[3]"></message-notification>
  103. </div>
  104. <div v-if="isLogin" class="d-flex align-center ml-4 cursor-pointer">
  105. <v-chip v-if="showTeacherLogin" label size="small" color="primary" variant="flat" @click="handleSwitchTeacher">切换为老师</v-chip>
  106. <v-chip v-else label color="primary" size="small" variant="flat" @click="handleSwitchEnterprise">我要招聘</v-chip>
  107. </div>
  108. </div>
  109. </div>
  110. </v-toolbar>
  111. <CtDialog :visible="show" title="请选择要切换的公司账号" :footer="true" widthType="2" @close="show = false" @submit="switchSubmit">
  112. <v-radio-group v-model="radios" :hide-details="true">
  113. <v-radio v-for="item in enterpriseList" :key="item.enterpriseId" color="primary" :label="formatName(item.enterpriseName)" :value="item.enterpriseId"></v-radio>
  114. </v-radio-group>
  115. <div class="text-end pr-5 pt-5">
  116. <span class="color-error cursor-pointer border-bottom-error" @click="newRegistering">{{ btnType ? '都不是我要的?去注册新企业' : '查看申请进度' }}</span>
  117. </div>
  118. </CtDialog>
  119. </div>
  120. </template>
  121. <script setup>
  122. import { computed, onMounted, ref } from 'vue'
  123. import { getToken, getRefreshToken } from '@/utils/auth'
  124. import { useUserStore } from '@/store/user'
  125. // import { useLocaleStore } from '@/store/locale'
  126. import { useI18n } from '@/hooks/web/useI18n'
  127. import CtDialog from '@/components/CtDialog'
  128. import { useRoute } from 'vue-router'; const route = useRoute()
  129. import { useRouter } from 'vue-router'; const router = useRouter()
  130. import { getUserBindEnterpriseList, getUserRegisterEnterpriseApply } from '@/api/personal/user'
  131. import MessageNotification from '../message.vue'
  132. import { getUserAvatar } from '@/utils/avatar'
  133. import defineListPage from '@/views/entrances/navBar/components/defineListPage'
  134. import { formatName } from '@/utils/getText'
  135. import { getSchoolInformation } from '@/api/school'
  136. defineOptions({ name: 'personal-navbar' })
  137. defineProps({
  138. showLoginBtn: {
  139. type: Boolean,
  140. default: true
  141. },
  142. sticky: {
  143. type: Boolean,
  144. default: true
  145. }
  146. })
  147. const showBall = ref(false)
  148. const showTeacherLogin = ref(false)
  149. const isSchool = localStorage.getItem('isSchool') ? true : false
  150. // 获取老师注册信息
  151. const schoolInfo = ref({})
  152. const getSchoolInfo = async () => {
  153. const data = await getSchoolInformation()
  154. if (data && Object.keys(data).length > 0) {
  155. schoolInfo.value = data
  156. showTeacherLogin.value = isSchool ? false : true
  157. }
  158. }
  159. onMounted(async () => {
  160. if (getToken()) {
  161. showBall.value = true
  162. await getSchoolInfo()
  163. }
  164. })
  165. const { t } = useI18n()
  166. // const localeStore = useLocaleStore()
  167. const userStore = useUserStore()
  168. const paths = [ // 有选中样式-路由列表
  169. '/recruitHome', // 0
  170. '/recruit/personal/position', // 1
  171. '/recruit/personal/company', // 2
  172. '/recruit/personal/message', // 3
  173. '/recruit/personal/myWallet', // 4
  174. '/recruit/personal/personalCenter', // 5
  175. '/recruit/personal/personalCenter/wallet', // 6
  176. ]
  177. const navList = ref([
  178. { title: '首页', path: '/recruitHome' },
  179. { title: '门墩儿招聘', path: '/recruit/personal/recommend', dealActive: true },
  180. { title: '门墩儿猎头', path: '/headhunting' },
  181. { title: '门墩儿商城', path: '/pointsExchange', isEdit: true },
  182. { title: '火苗儿校企', path: '/flameLogin' },
  183. { title: '了解门墩儿', path: '/about' }
  184. ])
  185. const mode = import.meta.env.VITE_NODE_ENV
  186. console.log(import.meta.env.VITE_NODE_ENV, '当前环境变量===========')
  187. const mall = navList.value.find(item => item.isEdit)
  188. // 区分生产环境展示地址
  189. mall.path = mode === 'production' ? '/pointsExchange' : '/mall'
  190. const handleClick = (e, status) => {
  191. if (!e.path) return
  192. if (status) window.open(e.path)
  193. else router.push(e.path)
  194. }
  195. // 左侧菜单选中状态
  196. const position = [
  197. '/recruit/personal/recommend',
  198. '/recruit/personal/position',
  199. '/recruit/personal/company',
  200. '/recruit/personal/jobFair',
  201. '/recruit/personal/company/details',
  202. '/recruit/personal/position/details'
  203. ]
  204. const menuActive = (val) => {
  205. let path
  206. position.forEach(e => {
  207. if (route.path.indexOf(e) !== -1) path = e
  208. })
  209. return val.dealActive ? position.indexOf(path) !== -1 : (route.path === val.path || route.path.includes(val.path))
  210. }
  211. const vip = computed(() => {
  212. return new Date().getTime() < userStore.userInfo?.vipExpireDate
  213. })
  214. const show = ref(false)
  215. const radios = ref(null)
  216. const enterpriseList = ref([])
  217. // 切换为招聘者
  218. const handleSwitchEnterprise = async () => {
  219. await getApplyInfo() // 查询申请信息(注册进度)
  220. const data = await getUserBindEnterpriseList() // 申请通过才有数据,否则空数组
  221. enterpriseList.value = data || []
  222. if (data?.length) {
  223. radios.value = data[0].enterpriseId
  224. show.value = true
  225. } else {
  226. // router.push('recruit/enterpriseRegister')
  227. newRegistering() // 既没有存在的企业 又没有申请数据 》 进入注册页面
  228. }
  229. }
  230. // 切换提交
  231. const switchSubmit = async () => {
  232. localStorage.setItem('enterpriseId', radios.value)
  233. localStorage.setItem('emailLoginInfo', "false") // 先清空企业邮箱信息,避免求职切换招聘有邮箱登录信息遗留导致使用邮箱信息
  234. // 跳转企业路由 且验证是否已完善必填基本信息
  235. window.location.href = '/enterpriseVerification'
  236. }
  237. const btnType = ref(0)
  238. // 查看用户是否有在申请中的数据
  239. const getApplyInfo = async () => {
  240. const data = await getUserRegisterEnterpriseApply()
  241. localStorage.setItem('userApplyInfo', JSON.stringify(data))
  242. const status = data?.status || null // 有数据说明有申请
  243. // 0: 有等待审核的数据或者审核不通过的数据 >查看申请进度
  244. // 1: 没有正在审核的数据 >注册新企业
  245. btnType.value = (status === '0' || status === '2') ? 0 : 1
  246. }
  247. // 注册/查看申请进度
  248. const loading1 = ref(false)
  249. const newRegistering = () => {
  250. loading1.value = true
  251. const path = btnType.value ? '/recruit/entRegister' : '/recruit/entRegister/inReview'
  252. router.replace({ path })
  253. }
  254. // 跳转老师页面
  255. const statusList = [
  256. { status: '0', path: '/register/school/inReview', key: 'registerSchoolInfo' }, // 审核中
  257. { status: '1', path: '/recruit/teacher/studentList/index', key: 'schoolInfo' }, // 审核通过
  258. { status: '2', path: '/register/school/inReview', key: 'registerSchoolInfo' }, // 审核不通过
  259. ]
  260. const handleSwitchTeacher = () => {
  261. const obj = statusList.find(item => item.status === schoolInfo.value?.authStatus)
  262. if (!obj || !schoolInfo.value) return
  263. localStorage.setItem(obj.key, JSON.stringify(schoolInfo.value))
  264. router.push({ path: obj.path })
  265. }
  266. const handleToPersonalCenter = () => {
  267. router.push({ path: paths[5] })
  268. }
  269. // 退出登录
  270. const handleLogout = async () => {
  271. await userStore.userLogout(1)
  272. showBall.value = false
  273. if (route.path === '/recruitHome') location.reload()
  274. else router.push({ path: '/recruitHome' })
  275. }
  276. const items = ref([
  277. { title: t('setting.personalCenter'), icon: 'mdi-account-circle-outline', change: handleToPersonalCenter },
  278. { title: t('setting.editPassword'), icon: 'mdi-shield-lock-open-outline', change: () => router.push({ path: '/recruit/personal/personalCenter/accountSettings' }) },
  279. { title: t('setting.logOut'), icon: 'mdi-logout', change: handleLogout }
  280. ])
  281. let baseInfo = ref(JSON.parse(localStorage.getItem('baseInfo')) || {}) // 人才信息
  282. let userInfo = ref(JSON.parse(localStorage.getItem('userInfo')) || {})
  283. let userAccount = ref(JSON.parse(localStorage.getItem('userAccount')) || {}) // 账户信息
  284. const isLogin = ref(Boolean(getRefreshToken(2)))
  285. const updatePage = () => {
  286. baseInfo.value = JSON.parse(localStorage.getItem('baseInfo')) || {}
  287. userInfo.value = JSON.parse(localStorage.getItem('userInfo')) || {}
  288. userAccount.value = JSON.parse(localStorage.getItem('userAccount')) || {}
  289. isLogin.value = Boolean(getRefreshToken(2))
  290. }
  291. userStore.$subscribe((mutation, state) => {
  292. if (Object.keys(state.baseInfo).length) baseInfo.value = state.baseInfo
  293. if (state.userInfo && Object.keys(state.userInfo).length) userInfo.value = state?.userInfo
  294. if (Object.keys(state.userAccount).length) userAccount.value = state.userAccount
  295. if (state.token) showBall.value = true
  296. updatePage()
  297. })
  298. // 语言切换
  299. // const handleChangeLocale = (item) => {
  300. // localeStore.setCurrentLocale(item)
  301. // location.reload()
  302. // }
  303. </script>
  304. <style lang="scss" scoped>
  305. @import '@/styles/personal/navBar.scss'
  306. </style>