navBar.vue 9.3 KB

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