navBar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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">
  9. <div>
  10. <div class="nav-logo mr-5 mt-1 cursor-pointer" @click="router.push('/')">
  11. <v-img src="../../assets/logo.png" aspect-ratio="16/9" cover :width="90" style="height: 40px"></v-img>
  12. </div>
  13. <!-- <div class="nav-city">
  14. <p class="nav-city-box">
  15. <v-icon color="primary">mdi-map-marker</v-icon>
  16. <span class="nav-city-selected">广州</span>
  17. <span class="switchover-city nav-city-selected">[{{ $t('sys.switchCities') }}]</span>
  18. </p>
  19. </div> -->
  20. <div class="menuList">
  21. <div v-for="val in navList" :key="val.name" class="mr-3">
  22. <template v-if="val.children">
  23. <defineListPage v-bind="$attrs" :title="val.title" :list="val.children" @emitClick="handleClick" :closeOnContentClick="true"></defineListPage>
  24. </template>
  25. <template v-else>
  26. <span class="cursor-pointer menuList-first-title" @click="handleClick(val, true)">{{ val.title }}</span>
  27. </template>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="d-flex user-nav">
  32. <div class="btns d-flex align-center" v-if="!getToken()">
  33. <v-btn class="half-button" border color="primary" size="small" @click="handleLogin">{{ $t('login.loginOrRegister') }}</v-btn>
  34. </div>
  35. <!-- 头像用户名 -->
  36. <div class="d-flex align-center color-333" v-if="getToken()">
  37. <span class="cursor-pointer mr-5 commonHover" @click="handleSwitch">我要招聘</span>
  38. <span class="cursor-pointer commonHover" :class="{'active-route': routeActive === 6}" @click="router.push({ path: paths[6] })">
  39. {{t('enterprise.account.accountBalances')}}:{{ userAccount?.balance && userAccount?.balance > 0 ? (userAccount?.balance / 100.0).toFixed(2) : 0 }}
  40. </span>
  41. <span class="mr-3 ml-3 cursor-pointer commonHover" :class="{'active-route': routeActive === 7}" @click="router.push({ path: paths[7] })">{{t('resume.goldCoins')}}:{{ userAccount?.point || 0 }}</span>
  42. <v-menu open-on-hover>
  43. <template v-slot:activator="{ props }">
  44. <div class="d-flex ml-3 align-center cursor-pointer" :class="{'active-route': routeActive === 5}" v-bind="props" @click="handleToPersonalCenter">
  45. <v-avatar>
  46. <v-img alt="John" :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)"></v-img>
  47. </v-avatar>
  48. <div class="ml-3 commonHover">
  49. {{ baseInfo?.name || userInfo.phone }}
  50. <v-icon :color="routeActive === 5 ? '#008979' : '#333'" size="30">mdi-menu-down</v-icon>
  51. </div>
  52. </div>
  53. </template>
  54. <v-list>
  55. <v-list-item v-for="(item, index) in items" :key="index" @click="item.change">
  56. <template v-slot:prepend>
  57. <v-icon :icon="item.icon"></v-icon>
  58. </template>
  59. <v-list-item-title>{{ item.title }}</v-list-item-title>
  60. </v-list-item>
  61. </v-list>
  62. </v-menu>
  63. </div>
  64. <!-- 语言切换 -->
  65. <!-- <v-menu>
  66. <template v-slot:activator="{ props }">
  67. <v-btn
  68. class="ml-3"
  69. color="primary"
  70. icon="mdi-translate"
  71. size="small"
  72. v-bind="props"
  73. >
  74. </v-btn>
  75. </template>
  76. <v-list density="compact" color="primary">
  77. <v-list-item
  78. v-for="item in localeStore.localeMap"
  79. :key="item.name"
  80. :value="item.lang"
  81. :active="localeStore.currentLocale.lang === item.lang"
  82. @click="handleChangeLocale(item)"
  83. >
  84. <v-list-item-title>{{ item.name }}</v-list-item-title>
  85. </v-list-item>
  86. </v-list>
  87. </v-menu> -->
  88. <div class="d-flex align-center" v-if="showBall">
  89. <message-notification v-if="showBall" :path="paths[3]" class="commonHover2" :class="{'active-route': routeActive === 3}"></message-notification>
  90. </div>
  91. </div>
  92. </div>
  93. </v-toolbar>
  94. <CtDialog :visible="show" title="请选择要切换的公司账号" :footer="true" widthType="2" @close="show = false" @submit="switchSubmit">
  95. <v-radio-group v-model="radios">
  96. <v-radio v-for="item in enterpriseList" :key="item.enterpriseId" color="primary" :label="item.enterpriseName" :value="item.enterpriseId"></v-radio>
  97. </v-radio-group>
  98. <v-btn :loading="loading1" class="mt-2 mb-3" style="width: 100%;" color="primary" variant="tonal" @click="newRegistering">{{ btnType ? '注册新企业' : '查看申请进度' }}</v-btn>
  99. </CtDialog>
  100. </div>
  101. </template>
  102. <script setup>
  103. import { computed, onMounted, ref } from 'vue'
  104. import { getToken } from '@/utils/auth'
  105. import { useUserStore } from '@/store/user'
  106. // import { useLocaleStore } from '@/store/locale'
  107. import { useI18n } from '@/hooks/web/useI18n'
  108. import CtDialog from '@/components/CtDialog'
  109. import { useRoute } from 'vue-router'; const route = useRoute()
  110. import { useRouter } from 'vue-router'; const router = useRouter()
  111. import { getUserBindEnterpriseList, getUserRegisterEnterpriseApply } from '@/api/personal/user'
  112. import MessageNotification from '../message.vue'
  113. import { getUserAvatar } from '@/utils/avatar'
  114. import defineListPage from '@/views/entrances/navBar/components/defineListPage'
  115. defineOptions({ name: 'personal-navbar' })
  116. defineProps({
  117. sticky: {
  118. type: Boolean,
  119. default: true
  120. }
  121. })
  122. const showBall = ref(false)
  123. onMounted(() => {
  124. if (getToken()) {
  125. showBall.value = true
  126. }
  127. })
  128. // const useIM = useIMStore()
  129. const { t } = useI18n()
  130. // const localeStore = useLocaleStore()
  131. const userStore = useUserStore()
  132. const paths = [ // 有选中样式-路由列表
  133. '/recruitHome', // 0
  134. '/recruit/personal/position', // 1
  135. '/recruit/personal/company', // 2
  136. '/recruit/personal/message', // 3
  137. '/recruit/personal/myWallet', // 4
  138. '/recruit/personal/personalCenter', // 5
  139. '/recruit/personal/myWallet/myBalance', // 6
  140. '/recruit/personal/myWallet/myIntegral', // 7
  141. ]
  142. const navList = [
  143. {
  144. title: '直聘',
  145. children: [
  146. {
  147. title: '门墩儿直聘',
  148. appList: [
  149. [{ title: '职位', path: paths[1] }, { title: '公司', path: paths[2] }]
  150. ]
  151. }
  152. ]
  153. },
  154. { title: '甄选', path: '/mall' },
  155. { title: '猎寻', path: '/headhunting' },
  156. { title: '数据' },
  157. { title: '火苗儿' },
  158. { title: '联合会' },
  159. { title: '了解门墩儿' },
  160. ]
  161. const handleClick = (e, status) => {
  162. if (!e.path) return
  163. if (status) window.open(e.path)
  164. else router.push(e.path)
  165. }
  166. const routeActive = computed(() => {
  167. const index = paths.findIndex(item => item === route.path)
  168. return index
  169. })
  170. const show = ref(false)
  171. const radios = ref(null)
  172. const enterpriseList = ref([])
  173. // 切换为招聘者
  174. const handleSwitch = async () => {
  175. await getApplyInfo() // 查询申请信息(注册进度)
  176. const data = await getUserBindEnterpriseList() // 申请通过才有数据,否则空数组
  177. enterpriseList.value = data || []
  178. if (data?.length) {
  179. radios.value = data[0].enterpriseId
  180. show.value = true
  181. } else {
  182. // router.push('recruit/enterprise/register')
  183. newRegistering() // 既没有存在的企业 又没有申请数据 》 进入注册页面
  184. }
  185. }
  186. // 切换提交
  187. const switchSubmit = async () => {
  188. // await logout() // 先退出个人登录
  189. localStorage.setItem('enterpriseId', radios.value)
  190. // 跳转企业路由 且验证是否已完善必填基本信息
  191. window.location.href = '/enterpriseVerification'
  192. // 获取企业账号令牌以及企业用户个人信息
  193. // await userStore.changeRole(radios.value)
  194. }
  195. const btnType = ref(0)
  196. // 查看用户是否有在申请中的数据
  197. const getApplyInfo = async () => {
  198. const data = await getUserRegisterEnterpriseApply()
  199. localStorage.setItem('userApplyInfo', JSON.stringify(data))
  200. const status = data?.status || null // 有数据说明有申请
  201. // 0: 有等待审核的数据或者审核不通过的数据 >查看申请进度
  202. // 1: 没有正在审核的数据 >注册新企业
  203. btnType.value = (status === '0' || status === '2') ? 0 : 1
  204. }
  205. // 注册/查看申请进度
  206. const loading1 = ref(false)
  207. const newRegistering = () => {
  208. loading1.value = true
  209. const path = btnType.value ? '/recruit/enterprise/register' : '/recruit/enterprise/register/inReview'
  210. router.replace({ path })
  211. }
  212. const handleToPersonalCenter = () => {
  213. router.push({ path: paths[5] })
  214. }
  215. // 退出登录
  216. const handleLogout = async () => {
  217. await userStore.userLogout(1)
  218. router.push({ path: '/recruitHome' })
  219. }
  220. const items = ref([
  221. { title: t('vipPackage.purchasePackage'), icon: 'mdi-gift-outline', change: () => router.push({ path: '/recruit/personal/purchasePackage' }) },
  222. { title: t('resume.onlineResume'), icon: 'mdi-list-box-outline', change: () => router.push({ path: '/recruit/personal/resume' }) },
  223. { title: t('setting.accountSettings'), icon: 'mdi-cog-outline', change: () => router.push({ path: '/recruit/personal/accountSettings/accountBinding' }) },
  224. // { title: t('setting.switchToRecruit'), icon: 'mdi-swap-horizontal', change: handleSwitch },
  225. { title: t('publicRecruitment.bountyRewards'), icon: 'mdi-google-circles-extended', change: () => router.push({ path: '/publicRecruitment' }) },
  226. { title: t('points.wallet'), icon: ' mdi-database-outline', change: () => router.push({ path: '/recruit/personal/myWallet' }) },
  227. { title: t('taskCenter.taskCenter'), icon: 'mdi-calendar-check-outline', change: () => router.push({ path: '/recruit/personal/TaskCenter' }) },
  228. { title: t('setting.logOut'), icon: 'mdi-logout', change: handleLogout }
  229. ])
  230. let baseInfo = ref(JSON.parse(localStorage.getItem('baseInfo')) || {}) // 人才信息
  231. let userInfo = ref(JSON.parse(localStorage.getItem('userInfo')) || {})
  232. let userAccount = ref(JSON.parse(localStorage.getItem('userAccount')) || {}) // 账户信息
  233. userStore.$subscribe((mutation, state) => {
  234. if (Object.keys(state.baseInfo).length) baseInfo.value = state.baseInfo
  235. if (Object.keys(state.userAccount).length) userAccount.value = state.userAccount
  236. })
  237. const handleLogin = () => {
  238. router.push({ path: '/login' })
  239. }
  240. // 语言切换
  241. // const handleChangeLocale = (item) => {
  242. // localeStore.setCurrentLocale(item)
  243. // location.reload()
  244. // }
  245. </script>
  246. <style lang="scss" scoped>
  247. @import '@/styles/personal/navBar.scss'
  248. </style>