navBar.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div>
  3. <v-toolbar class="banner font-size-14 pl-0" density="compact" style="height: 50px;">
  4. <div class="innerBox d-flex justify-space-between">
  5. <div class="nav-logo" style="cursor: pointer;" @click="handleLogoClick">
  6. <v-img src="../../assets/logo.png" aspect-ratio="16/9" contain :width="97" style="height: 40px"></v-img>
  7. </div>
  8. <div class="d-flex user-nav align-center">
  9. <!-- 企业logo、企业名称 -->
  10. <div class="d-flex align-center cursor-pointer">
  11. <v-img @click="enterpriseClick(2)" rounded contain width="40" height="40" :src="baseInfo?.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" ></v-img>
  12. <span @click="enterpriseClick(1)" class="ml-3 commonHover">{{ formatName(baseInfo?.enterpriseAnotherName || baseInfo?.enterpriseName) }}</span>
  13. </div>
  14. <div class="enterprise-septal-line"></div>
  15. <div class="cursor-pointer mx-3 commonHover" @click="handleLogout(false)">我要求职</div>
  16. <div class="enterprise-septal-line"></div>
  17. <div class="d-flex align-center mx-3 cursor-pointer commonHover" @click="router.push('/recruit/enterprise/membershipPackage/index?key=1')">
  18. <div>剩余M豆:{{ enterpriseUserAccount?.balance ? enterpriseUserAccount?.balance / 100 : 0 }}个</div>
  19. </div>
  20. <!-- 企业会员标识 -->
  21. <div v-if="baseInfo?.vipFlag && Date.now() < baseInfo?.vipExpireDate" >
  22. <div class="enterprise-septal-line"></div>
  23. <svg-icon name="vip" size="30" class="ml-3"></svg-icon>
  24. </div>
  25. <!-- 头像用户名 -->
  26. <div class="d-flex align-center" v-if="showBall">
  27. <v-menu open-on-hover>
  28. <template v-slot:activator="{ props }">
  29. <div class="d-flex ml-3 pl-2 align-center cursor-pointer" v-bind="props">
  30. <v-avatar>
  31. <v-img alt="" :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)"></v-img>
  32. </v-avatar>
  33. <div class="ml-2 commonHover">{{ formatName(baseInfo?.name ?? baseInfo?.phone) }}</div>
  34. </div>
  35. </template>
  36. <v-list>
  37. <v-list-item v-for="(item, index) in items" :key="index" @click="item.change">
  38. <template v-slot:prepend>
  39. <v-icon :icon="item.icon"></v-icon>
  40. </template>
  41. <v-list-item-title>{{ item.title }}</v-list-item-title>
  42. </v-list-item>
  43. </v-list>
  44. </v-menu>
  45. </div>
  46. <!-- 语言切换 -->
  47. <!-- <v-menu>
  48. <template v-slot:activator="{ props }">
  49. <v-btn
  50. class="ml-3"
  51. color="primary"
  52. size="small"
  53. icon="mdi-translate"
  54. v-bind="props"
  55. >
  56. </v-btn>
  57. </template>
  58. <v-list density="compact">
  59. <v-list-item
  60. v-for="item in localeStore.localeMap"
  61. :key="item.name"
  62. :value="item.lang"
  63. :active="localeStore.currentLocale.lang === item.lang"
  64. @click="handleChangeLocale(item)"
  65. >
  66. <v-list-item-title>{{ item.name }}</v-list-item-title>
  67. </v-list-item>
  68. </v-list>
  69. </v-menu> -->
  70. <!-- 消息通知 -->
  71. <MessageNotification class="commonHover2" path="/recruit/enterprise/invite/chatTools"></MessageNotification>
  72. </div>
  73. </div>
  74. </v-toolbar>
  75. </div>
  76. </template>
  77. <script setup>
  78. defineOptions({ name: 'personal-navbar' })
  79. import { ref, onMounted, computed } from 'vue'
  80. import { getToken } from '@/utils/auth'
  81. import { useUserStore } from '@/store/user'; const userStore = useUserStore()
  82. // import { useLocaleStore } from '@/store/locale'; const localeStore = useLocaleStore()
  83. import { useRouter } from 'vue-router'; const router = useRouter()
  84. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  85. import MessageNotification from '../message.vue'
  86. import { getUserAvatar } from '@/utils/avatar'
  87. import { formatName } from '@/utils/getText'
  88. defineProps({
  89. sticky: {
  90. type: Boolean,
  91. default: true
  92. }
  93. })
  94. const showBall = ref(false)
  95. const handleLogoClick = () => { window.open('/recruitHome') } // 点击logo
  96. const enterpriseClick = (tabKey = 1) => {
  97. const path = '/recruit/enterprise/systemManagement/entInfoSetting'
  98. router.push({ path, query: { tabKey } })
  99. }
  100. // 退出登录、切换求职者
  101. const handleLogout = async (exit = true) => {
  102. if (exit) await userStore.userLogout(2)
  103. router.push({ path: '/recruitHome' })
  104. }
  105. const menuList = ref([
  106. { title: t('setting.editPassword'), icon: 'mdi-shield-lock-open-outline', key: 'editPassword', change: () => router.push({ path: '/recruit/enterprise/systemManagement/staffChangePassword' }) },
  107. { title: t('setting.logOut'), icon: 'mdi-logout', change: handleLogout }
  108. ])
  109. const items = computed(() => {
  110. return menuList.value.filter(item => !item.hidden)
  111. })
  112. /**
  113. * @param {Array} routes
  114. * @returns {Array}
  115. * 路由扁平化 抽离children字段
  116. */
  117. function routeFlattening (routes) {
  118. return routes.reduce((prev, cur) => {
  119. prev.push(cur.path)
  120. if (cur.children && cur.children.length) {
  121. prev.push(...routeFlattening(cur.children))
  122. }
  123. return prev
  124. }, [])
  125. }
  126. const hasRoute = (path) => {
  127. const routes = router.getRoutes()
  128. return routeFlattening(routes).some(_path => {
  129. if (_path.includes(':')) {
  130. const change = path.split('/')
  131. const _change = _path.split('/')
  132. if (change.length !== _change.length) {
  133. return false
  134. }
  135. const res = _change.reduce((e, v, i) => {
  136. if (v.includes(':')) {
  137. e.push(true)
  138. return e
  139. }
  140. e.push(change[i] === v)
  141. return e
  142. }, [])
  143. return res.every(e => e)
  144. }
  145. return _path === path
  146. })
  147. }
  148. // 没有权限访问时,隐藏菜单
  149. if (!hasRoute('/recruit/enterprise/systemManagement/staffChangePassword')) {
  150. menuList.value.find(e => e.key === 'editPassword').hidden = true
  151. }
  152. onMounted(() => {
  153. if (getToken(1)) {
  154. showBall.value = true
  155. localStorage.setItem('showEditPassword', hasRoute('/recruit/enterprise/systemManagement/staffChangePassword'))
  156. }
  157. })
  158. // 企业logo、用户基本信息
  159. let baseInfo = ref(JSON.parse(localStorage.getItem('entBaseInfo')) || {})
  160. let enterpriseUserAccount = ref(JSON.parse(localStorage.getItem('enterpriseUserAccount')) || {}) // 账户信息
  161. userStore.$subscribe((mutation, state) => {
  162. if (Object.keys(state.entBaseInfo).length) baseInfo.value = state.entBaseInfo
  163. if (Object.keys(state.enterpriseUserAccount).length) enterpriseUserAccount.value = state.enterpriseUserAccount
  164. })
  165. // 语言切换
  166. // const handleChangeLocale = (item) => {
  167. // localeStore.setCurrentLocale(item)
  168. // location.reload()
  169. // }
  170. </script>
  171. <style lang="scss" scoped>
  172. .banner {
  173. width: 100%;
  174. height: 50px;
  175. z-index: var(--zIndex-nav) !important;
  176. color: #fff;
  177. background-color: var(--color-d5e6e8);
  178. padding-left: 0px;
  179. height: 50px;
  180. font-size: 15px;
  181. }
  182. .hover:hover {
  183. cursor: pointer;
  184. background: rgba(0, 0, 0, 0.03);
  185. }
  186. .innerBox {
  187. position: relative;
  188. width: 100%;
  189. align-items: center;
  190. padding: 0 30px;
  191. }
  192. .nav-logo {
  193. float: left;
  194. }
  195. .nav {
  196. font-size: 0;
  197. float: left;
  198. margin-left: 50px;
  199. height: 49px;
  200. line-height: 49px;
  201. }
  202. .user-nav {
  203. color: var(--color-333);
  204. font-size: 15px;
  205. }
  206. .enterprise-septal-line {
  207. width: 1px;
  208. display: inline-block;
  209. height: 20px;
  210. vertical-align: middle;
  211. background-color: #fff;
  212. margin: 0 10px;
  213. }
  214. </style>