navBar.vue 10 KB

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