navBar.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)"></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. import { getUserAvatar } from '@/utils/avatar'
  97. defineOptions({ name: 'personal-navbar' })
  98. defineProps({
  99. sticky: {
  100. type: Boolean,
  101. default: true
  102. }
  103. })
  104. const showBall = ref(false)
  105. onMounted(() => {
  106. if (getToken()) {
  107. showBall.value = true
  108. }
  109. })
  110. const handleLogoClick = () => { router.push({ path: '/recruit/enterprise'}) }
  111. const enterpriseClick = (tabKey = 1) => {
  112. const path = '/recruit/enterprise/informationManagement/informationSettings'
  113. router.push({ path, query: { tabKey } })
  114. }
  115. // 退出登录
  116. const handleLogout = async () => {
  117. await userStore.userLogout(2)
  118. router.push({ path: '/login' })
  119. }
  120. const enterpriseList = ref([])
  121. const menuList = ref([
  122. { title: t('enterprise.account.myAccount'), icon: 'mdi-account', change: () => router.push({ path: '/recruit/enterprise/memberCenter/myPoints' }) },
  123. { title: t('vipPackage.purchasePackage'), icon: 'mdi-gift-outline', change: () => window.open('/recruit/enterprise/purchasePackage') },
  124. { title: t('enterprise.personalInformationSettings'), icon: 'mdi-account-cog', change: () => router.push({ path: '/recruit/enterprise/informationSettings' }) },
  125. { title: t('setting.switchToOtherCompany'), icon: 'mdi-home-switch', hidden: enterpriseList.value?.length < 2, change: () => handleSwitchToAnotherEnterprise },
  126. { title: t('enterprise.registeringNewEnterprise'), icon: 'mdi-home-plus-outline', change: () => handleRegisteringNewEnterprise },
  127. // { title: t('setting.switchToJobSeeker'), icon: 'mdi-swap-horizontal', change: handleLogout },
  128. { title: t('setting.logOut'), icon: 'mdi-logout', change: handleLogout }
  129. ])
  130. const items = computed(() => {
  131. return menuList.value.filter(item => !item.hidden)
  132. })
  133. // 企业logo、用户基本信息
  134. let baseInfo = ref(JSON.parse(localStorage.getItem('baseInfo')) || {})
  135. let enterpriseUserAccount = ref(JSON.parse(localStorage.getItem('enterpriseUserAccount')) || {}) // 账户信息
  136. userStore.$subscribe((mutation, state) => {
  137. baseInfo.value = state.baseInfo
  138. enterpriseUserAccount.value = state.enterpriseUserAccount
  139. })
  140. // 语言切换
  141. // const handleChangeLocale = (item) => {
  142. // localeStore.setCurrentLocale(item)
  143. // location.reload()
  144. // }
  145. // 企业相关操作
  146. const show = ref(false)
  147. const radios = ref(null)
  148. // 注册新企业
  149. const handleRegisteringNewEnterprise = async () => {
  150. const data = await getUserRegisterEnterpriseApply()
  151. const bool = data && Object.keys(data).length // 已经有数据说明已经申请过了
  152. const path = bool ? '/recruit/enterprise/register/inReview' : '/recruit/enterprise/register'
  153. router.push({ path })
  154. }
  155. // 切换其他企业
  156. const handleSwitchToAnotherEnterprise = async () => {
  157. if (enterpriseList.value?.length) {
  158. if (enterpriseList.value.length > 1) {
  159. show.value = true
  160. radios.value = enterpriseList.value[0].enterpriseId
  161. } else {
  162. // 只有一个企业不能切换 只能再注册新的一个
  163. handleRegisteringNewEnterprise()
  164. }
  165. }
  166. }
  167. // 手动切换企业提交
  168. const handleToAnotherEnterpriseSubmit = async () => {
  169. // 获取企业账号令牌以及企业用户个人信息
  170. await userStore.changeRole(radios.value) // enterpriseId
  171. // router.push({ path: '/recruit/enterprise' })
  172. localStorage.setItem('loginType', 'enterprise')
  173. window.location.href = '/recruit/enterprise'
  174. }
  175. const test = ref(false)
  176. // 企业列表
  177. const getEnterpriseListData = async () => {
  178. if (!test.value) return
  179. const data = await getUserBindEnterpriseList() // 申请通过才有数据,否则空数组
  180. enterpriseList.value = data || []
  181. }
  182. getEnterpriseListData()
  183. </script>
  184. <style lang="scss" scoped>
  185. .banner {
  186. width: 100%;
  187. height: 50px;
  188. z-index: var(--zIndex-nav) !important;
  189. color: #fff;
  190. background-color: var(--color-d5e6e8);
  191. padding-left: 0px;
  192. height: 50px;
  193. font-size: 15px;
  194. .left {
  195. height: 100%;
  196. display: flex;
  197. align-items: center;
  198. font-size: 20px;
  199. cursor: pointer;
  200. }
  201. }
  202. .hover:hover {
  203. cursor: pointer;
  204. background: rgba(0, 0, 0, 0.03);
  205. }
  206. .innerBox {
  207. position: relative;
  208. width: 100%;
  209. align-items: center;
  210. padding: 0 30px;
  211. }
  212. .nav-logo {
  213. float: left;
  214. }
  215. .nav {
  216. font-size: 0;
  217. float: left;
  218. margin-left: 50px;
  219. height: 49px;
  220. line-height: 49px;
  221. }
  222. .user-nav {
  223. color: var(--v-primary-base);
  224. }
  225. .line {
  226. width: 1px;
  227. height: 20px;
  228. background-color: #fff;
  229. margin: 0 10px;
  230. margin: 8px 0 0 29px;
  231. }
  232. </style>