navBar.vue 11 KB

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