navBar.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div>
  3. <v-toolbar
  4. class="banner"
  5. density="compact"
  6. style="padding-left: 0px;height: 50px;font-size: 14px;"
  7. >
  8. <div class="innerBox d-flex justify-space-between">
  9. <div>
  10. <div class="nav-logo" style="cursor: pointer;" @click="handleLogoClick">
  11. <v-img src="../../assets/logo.png" aspect-ratio="16/9" cover :width="90" style="height: 40px"></v-img>
  12. </div>
  13. </div>
  14. <div class="d-flex user-nav align-center">
  15. <div class="d-flex align-center cursor-pointer">
  16. <v-img @click="enterpriseClick(2)" rounded width="40" height="40" :src="baseInfo?.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" ></v-img>
  17. <span @click="enterpriseClick(1)" class="ml-3">{{ baseInfo?.enterpriseAnotherName || baseInfo?.enterpriseName || '--' }}</span>
  18. </div>
  19. <div class="line"></div>
  20. <div class="ml-3 cursor-pointer" @click="handleLogout">我要求职</div>
  21. <div class="line"></div>
  22. <div class="d-flex align-center ml-6">
  23. <div class="cursor-pointer" @click="router.push({ path: '/recruit/enterprise/memberCenter/myPoints' })">{{ $t('enterprise.account.accountBalances') }}:{{ enterpriseUserAccount?.balance || 0 }}元</div>
  24. <div class="ml-5 cursor-pointer" @click="router.push({ path: '/recruit/enterprise/memberCenter/myPoints' })">{{ $t('enterprise.account.remainingPoints') }}:{{ enterpriseUserAccount?.point || 0 }}点</div>
  25. </div>
  26. <div class="line"></div>
  27. <!-- 头像用户名 -->
  28. <div class="d-flex align-center" v-if="showBall">
  29. <v-menu open-on-hover>
  30. <template v-slot:activator="{ props }">
  31. <div class="d-flex ml-5 pl-2 align-center cursor-pointer" v-bind="props">
  32. <v-avatar>
  33. <v-img alt="" :src="baseInfo?.avatar || 'https://minio.citupro.com/dev/menduner/7.png'"></v-img>
  34. </v-avatar>
  35. <div class="ml-2">{{ baseInfo?.name ?? $t('sys.tourist') }}</div>
  36. </div>
  37. </template>
  38. <v-list>
  39. <v-list-item v-for="(item, index) in items" :key="index" @click="item.change">
  40. <template v-slot:prepend>
  41. <v-icon :icon="item.icon"></v-icon>
  42. </template>
  43. <v-list-item-title>{{ item.title }}</v-list-item-title>
  44. </v-list-item>
  45. </v-list>
  46. </v-menu>
  47. </div>
  48. <!-- 语言切换 -->
  49. <!-- <v-menu>
  50. <template v-slot:activator="{ props }">
  51. <v-btn
  52. class="ml-3"
  53. color="primary"
  54. size="small"
  55. icon="mdi-translate"
  56. v-bind="props"
  57. >
  58. </v-btn>
  59. </template>
  60. <v-list density="compact">
  61. <v-list-item
  62. v-for="item in localeStore.localeMap"
  63. :key="item.name"
  64. :value="item.lang"
  65. :active="localeStore.currentLocale.lang === item.lang"
  66. @click="handleChangeLocale(item)"
  67. >
  68. <v-list-item-title>{{ item.name }}</v-list-item-title>
  69. </v-list-item>
  70. </v-list>
  71. </v-menu> -->
  72. <!-- <v-btn size="small" icon="mdi-bell-outline" @click="router.push('/recruit/enterprise/communication')"></v-btn> -->
  73. <MessageNotification path="/recruit/enterprise/communication"></MessageNotification>
  74. </div>
  75. </div>
  76. </v-toolbar>
  77. <CtDialog :visible="show" title="请选择要切换的公司账号" :footer="true" widthType="2" @close="show = false" @submit="handleToAnotherEnterpriseSubmit">
  78. <v-radio-group v-model="radios">
  79. <v-radio v-for="item in enterpriseList" :key="item.enterpriseId" color="primary" :label="item.enterpriseName" :value="item.enterpriseId"></v-radio>
  80. </v-radio-group>
  81. </CtDialog>
  82. </div>
  83. </template>
  84. <script setup>
  85. import {
  86. getUserBindEnterpriseList,
  87. getUserRegisterEnterpriseApply
  88. } from '@/api/personal/user'
  89. import { computed, ref, onMounted } from 'vue'
  90. import { getToken } from '@/utils/auth'
  91. import { useUserStore } from '@/store/user'; const userStore = useUserStore()
  92. // import { useLocaleStore } from '@/store/locale'; const localeStore = useLocaleStore()
  93. import { useRouter } from 'vue-router'; const router = useRouter()
  94. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  95. import MessageNotification from '../message.vue'
  96. defineOptions({ name: 'personal-navbar' })
  97. defineProps({
  98. sticky: {
  99. type: Boolean,
  100. default: true
  101. }
  102. })
  103. const showBall = ref(false)
  104. onMounted(() => {
  105. if (getToken()) {
  106. showBall.value = true
  107. }
  108. })
  109. const handleLogoClick = () => { router.push({ path: '/recruit/enterprise'}) }
  110. const enterpriseClick = (tabKey = 1) => {
  111. const path = '/recruit/enterprise/informationManagement/informationSettings'
  112. router.push({ path, query: { tabKey } })
  113. }
  114. // 退出登录
  115. const handleLogout = async () => {
  116. await userStore.userLogout(2)
  117. router.push({ path: '/login' })
  118. }
  119. const enterpriseList = ref([])
  120. const menuList = ref([
  121. { title: t('enterprise.account.myAccount'), icon: 'mdi-account', change: () => router.push({ path: '/recruit/enterprise/memberCenter/myPoints' }) },
  122. { title: t('vipPackage.purchasePackage'), icon: 'mdi-gift-outline', change: () => window.open('/recruit/enterprise/purchasePackage') },
  123. { title: t('enterprise.personalInformationSettings'), icon: 'mdi-account-cog', change: () => router.push({ path: '/recruit/enterprise/informationSettings' }) },
  124. { title: t('setting.switchToOtherCompany'), icon: 'mdi-home-switch', hidden: enterpriseList.value?.length < 2, change: () => handleSwitchToAnotherEnterprise },
  125. { title: t('enterprise.registeringNewEnterprise'), icon: 'mdi-home-plus-outline', change: () => handleRegisteringNewEnterprise },
  126. // { title: t('setting.switchToJobSeeker'), icon: 'mdi-swap-horizontal', change: handleLogout },
  127. { title: t('setting.logOut'), icon: 'mdi-logout', change: handleLogout }
  128. ])
  129. const items = computed(() => {
  130. return menuList.value.filter(item => !item.hidden)
  131. })
  132. // 企业logo、用户基本信息
  133. let baseInfo = ref(JSON.parse(localStorage.getItem('baseInfo')) || {})
  134. let enterpriseUserAccount = ref(JSON.parse(localStorage.getItem('enterpriseUserAccount')) || {}) // 账户信息
  135. userStore.$subscribe((mutation, state) => {
  136. baseInfo.value = state.baseInfo
  137. enterpriseUserAccount.value = state.enterpriseUserAccount
  138. })
  139. // 语言切换
  140. // const handleChangeLocale = (item) => {
  141. // localeStore.setCurrentLocale(item)
  142. // location.reload()
  143. // }
  144. // 企业相关操作
  145. const show = ref(false)
  146. const radios = ref(null)
  147. // 注册新企业
  148. const handleRegisteringNewEnterprise = async () => {
  149. const data = await getUserRegisterEnterpriseApply()
  150. const bool = data && Object.keys(data).length // 已经有数据说明已经申请过了
  151. const path = bool ? '/recruit/enterprise/register/inReview' : '/recruit/enterprise/register'
  152. router.push({ path })
  153. }
  154. // 切换其他企业
  155. const handleSwitchToAnotherEnterprise = async () => {
  156. if (enterpriseList.value?.length) {
  157. if (enterpriseList.value.length > 1) {
  158. show.value = true
  159. radios.value = enterpriseList.value[0].enterpriseId
  160. } else {
  161. // 只有一个企业不能切换 只能再注册新的一个
  162. handleRegisteringNewEnterprise()
  163. }
  164. }
  165. }
  166. // 手动切换企业提交
  167. const handleToAnotherEnterpriseSubmit = async () => {
  168. // 获取企业账号令牌以及企业用户个人信息
  169. await userStore.changeRole(radios.value) // enterpriseId
  170. router.push({ path: '/recruit/enterprise' })
  171. localStorage.setItem('loginType', 'enterprise')
  172. }
  173. const test = ref(false)
  174. // 企业列表
  175. const getEnterpriseListData = async () => {
  176. if (!test.value) return
  177. const data = await getUserBindEnterpriseList() // 申请通过才有数据,否则空数组
  178. enterpriseList.value = data || []
  179. }
  180. getEnterpriseListData()
  181. </script>
  182. <style lang="scss" scoped>
  183. .banner {
  184. width: 100%;
  185. height: 50px;
  186. z-index: var(--zIndex-nav) !important;
  187. color: #fff;
  188. background-color: var(--color-d5e6e8);
  189. padding-left: 0px;
  190. height: 50px;
  191. font-size: 15px;
  192. .left {
  193. height: 100%;
  194. display: flex;
  195. align-items: center;
  196. font-size: 20px;
  197. cursor: pointer;
  198. }
  199. }
  200. .hover:hover {
  201. cursor: pointer;
  202. background: rgba(0, 0, 0, 0.03);
  203. }
  204. .innerBox {
  205. position: relative;
  206. width: 100%;
  207. align-items: center;
  208. padding: 0 30px;
  209. }
  210. .nav-logo {
  211. float: left;
  212. }
  213. .nav {
  214. font-size: 0;
  215. float: left;
  216. margin-left: 50px;
  217. height: 49px;
  218. line-height: 49px;
  219. }
  220. .user-nav {
  221. color: var(--v-primary-base);
  222. }
  223. .line {
  224. width: 1px;
  225. height: 20px;
  226. background-color: #fff;
  227. margin: 0 10px;
  228. margin: 8px 0 0 29px;
  229. }
  230. </style>