navBar.vue 9.1 KB

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