Navbar.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="navbar">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <hamburger id="hamburger-container" :is-active="appStore.sidebar.opened" class="hamburger-container" @toggle-click="toggleSideBar" />
  5. <!-- <breadcrumb v-if="!settingsStore.topNav" id="breadcrumb-container" class="breadcrumb-container" />-->
  6. <top-nav v-if="settingsStore.topNav" id="topmenu-container" class="topmenu-container" />
  7. <div class="right-menu flex align-center">
  8. <template v-if="appStore.device !== 'mobile'">
  9. <!-- <el-select-->
  10. <!-- v-if="userId === 1 && tenantEnabled"-->
  11. <!-- v-model="companyName"-->
  12. <!-- class="min-w-244px"-->
  13. <!-- clearable-->
  14. <!-- filterable-->
  15. <!-- reserve-keyword-->
  16. <!-- :placeholder="$t('navbar.selectTenant')"-->
  17. <!-- @change="dynamicTenantEvent"-->
  18. <!-- @clear="dynamicClearEvent"-->
  19. <!-- >-->
  20. <!-- <el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName" :value="item.tenantId"> </el-option>-->
  21. <!-- <template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>-->
  22. <!-- </el-select>-->
  23. <!-- <header-search id="header-search" class="right-menu-item" /> -->
  24. <search-menu ref="searchMenuRef" />
  25. <el-tooltip content="搜索" effect="dark" placement="bottom">
  26. <div class="right-menu-item hover-effect" @click="openSearchMenu">
  27. <div class="search-icon" />
  28. </div>
  29. </el-tooltip>
  30. <!-- 消息 -->
  31. <el-tooltip :content="$t('navbar.message')" effect="dark" placement="bottom">
  32. <div style="margin: 12px">
  33. <el-popover placement="bottom" trigger="click" transition="el-zoom-in-top" :width="300" :persistent="false">
  34. <template #reference>
  35. <el-badge :value="newNotice > 0 ? newNotice : ''" :max="99">
  36. <div class="message" />
  37. </el-badge>
  38. </template>
  39. <template #default>
  40. <notice></notice>
  41. </template>
  42. </el-popover>
  43. </div>
  44. </el-tooltip>
  45. <!-- <el-tooltip :content="$t('navbar.full')" effect="dark" placement="bottom">-->
  46. <!-- <screenfull id="screenfull" class="right-menu-item hover-effect" />-->
  47. <!-- </el-tooltip>-->
  48. <!-- <el-tooltip :content="$t('navbar.language')" effect="dark" placement="bottom">-->
  49. <!-- <lang-select id="lang-select" class="right-menu-item hover-effect" />-->
  50. <!-- </el-tooltip>-->
  51. <!-- <el-tooltip :content="$t('navbar.layoutSize')" effect="dark" placement="bottom">-->
  52. <!-- <size-select id="size-select" class="right-menu-item hover-effect" />-->
  53. <!-- </el-tooltip>-->
  54. </template>
  55. <div class="avatar-container">
  56. <el-dropdown class="right-menu-item hover-effect" trigger="click" @command="handleCommand">
  57. <div class="avatar-wrapper">
  58. <img :src="userStore.avatar" class="user-avatar" />
  59. <span>{{ nickName }}</span>
  60. <el-icon><caret-bottom /></el-icon>
  61. </div>
  62. <template #dropdown>
  63. <el-dropdown-menu>
  64. <router-link v-if="!dynamic" to="/user/profile">
  65. <el-dropdown-item>{{ $t('navbar.personalCenter') }}</el-dropdown-item>
  66. </router-link>
  67. <!-- <el-dropdown-item v-if="settingsStore.showSettings" command="setLayout">-->
  68. <!-- <span>{{ $t('navbar.layoutSetting') }}</span>-->
  69. <!-- </el-dropdown-item>-->
  70. <el-dropdown-item divided command="logout">
  71. <span>{{ $t('navbar.logout') }}</span>
  72. </el-dropdown-item>
  73. </el-dropdown-menu>
  74. </template>
  75. </el-dropdown>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script setup lang="ts">
  81. import Logo from './Sidebar/Logo.vue';
  82. import SearchMenu from './TopBar/search.vue';
  83. import useAppStore from '@/store/modules/app';
  84. import useUserStore from '@/store/modules/user';
  85. import useSettingsStore from '@/store/modules/settings';
  86. import useNoticeStore from '@/store/modules/notice';
  87. // import { getTenantList } from '@/api/login';
  88. import { dynamicClear, dynamicTenant } from '@/api/system/tenant';
  89. import { TenantVO } from '@/api/types';
  90. import notice from './notice/index.vue';
  91. const appStore = useAppStore();
  92. const userStore = useUserStore();
  93. const settingsStore = useSettingsStore();
  94. const noticeStore = storeToRefs(useNoticeStore());
  95. const newNotice = ref(<number>0);
  96. const showLogo = computed(() => settingsStore.sidebarLogo);
  97. const isCollapse = computed(() => !appStore.sidebar.opened);
  98. const nickName = computed(() => userStore.nickname);
  99. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  100. const userId = ref(userStore.userId);
  101. const companyName = ref(undefined);
  102. const tenantList = ref<TenantVO[]>([]);
  103. // 是否切换了租户
  104. const dynamic = ref(false);
  105. // 租户开关
  106. const tenantEnabled = ref(true);
  107. // 搜索菜单
  108. const searchMenuRef = ref<InstanceType<typeof SearchMenu>>();
  109. const openSearchMenu = () => {
  110. searchMenuRef.value?.openSearch();
  111. };
  112. // 动态切换
  113. const dynamicTenantEvent = async (tenantId: string) => {
  114. if (companyName.value != null && companyName.value !== '') {
  115. await dynamicTenant(tenantId);
  116. dynamic.value = true;
  117. proxy?.$tab.closeAllPage();
  118. proxy?.$router.push('/');
  119. }
  120. };
  121. const dynamicClearEvent = async () => {
  122. await dynamicClear();
  123. dynamic.value = false;
  124. proxy?.$tab.closeAllPage();
  125. proxy?.$router.push('/');
  126. };
  127. /** 租户列表 */
  128. const initTenantList = async () => {
  129. // const { data } = await getTenantList();
  130. // tenantEnabled.value = data.tenantEnabled === undefined ? true : data.tenantEnabled;
  131. // if (tenantEnabled.value) {
  132. // tenantList.value = data.voList;
  133. // }
  134. };
  135. defineExpose({
  136. initTenantList
  137. });
  138. const toggleSideBar = () => {
  139. appStore.toggleSideBar(false);
  140. };
  141. const logout = async () => {
  142. await ElMessageBox.confirm('确定注销并退出系统吗?', '提示', {
  143. confirmButtonText: '确定',
  144. cancelButtonText: '取消',
  145. type: 'warning'
  146. });
  147. await userStore.logout();
  148. location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
  149. };
  150. const emits = defineEmits(['setLayout']);
  151. const setLayout = () => {
  152. emits('setLayout');
  153. };
  154. // 定义Command方法对象 通过key直接调用方法
  155. const commandMap: { [key: string]: any } = {
  156. setLayout,
  157. logout
  158. };
  159. const handleCommand = (command: string) => {
  160. // 判断是否存在该方法
  161. if (commandMap[command]) {
  162. commandMap[command]();
  163. }
  164. };
  165. //用深度监听 消息
  166. watch(
  167. () => noticeStore.state.value.notices,
  168. (newVal) => {
  169. newNotice.value = newVal.filter((item: any) => !item.read).length;
  170. },
  171. { deep: true }
  172. );
  173. </script>
  174. <style lang="scss" scoped>
  175. :deep(.el-select .el-input__wrapper) {
  176. height: 30px;
  177. }
  178. :deep(.el-badge__content.is-fixed) {
  179. top: 12px;
  180. }
  181. .flex {
  182. display: flex;
  183. }
  184. .align-center {
  185. align-items: center;
  186. }
  187. .navbar {
  188. height: 50px;
  189. overflow: hidden;
  190. position: relative;
  191. //background: url('@/assets/images/header.png') no-repeat;
  192. //background-size: 100% 100%;
  193. background-image: linear-gradient(to bottom #e6e6e6 0%, #e0e3e7 100%);
  194. box-shadow: 0 1px 6px rgba(0, 21, 41, 0.12);
  195. position: relative;
  196. &::before {
  197. content: '';
  198. width: 163px;
  199. height: 34px;
  200. background: url('@/assets/images/city.png') no-repeat;
  201. background-size: 100% 100%;
  202. position: absolute;
  203. bottom: 0;
  204. left: 0;
  205. }
  206. &::after {
  207. content: '';
  208. width: 163px;
  209. height: 34px;
  210. background: url('@/assets/images/city.png') no-repeat;
  211. background-size: 100% 100%;
  212. position: absolute;
  213. bottom: 0;
  214. right: 0;
  215. }
  216. .hamburger-container {
  217. line-height: 50px;
  218. height: 100%;
  219. float: left;
  220. cursor: pointer;
  221. transition: background 0.3s;
  222. -webkit-tap-highlight-color: transparent;
  223. &:hover {
  224. background: rgba(0, 0, 0, 0.025);
  225. }
  226. }
  227. .breadcrumb-container {
  228. float: left;
  229. }
  230. .topmenu-container {
  231. position: absolute;
  232. left: 50px;
  233. }
  234. .errLog-container {
  235. display: inline-block;
  236. vertical-align: top;
  237. }
  238. .right-menu {
  239. float: right;
  240. height: 100%;
  241. display: flex;
  242. &:focus {
  243. outline: none;
  244. }
  245. .right-menu-item {
  246. display: inline-block;
  247. padding: 0 12px;
  248. //height: 100%;
  249. font-size: 18px;
  250. color: #5a5e66;
  251. vertical-align: text-bottom;
  252. &.hover-effect {
  253. cursor: pointer;
  254. transition: background 0.3s;
  255. &:hover {
  256. background: rgba(0, 0, 0, 0.025);
  257. }
  258. }
  259. }
  260. .avatar-container {
  261. margin-right: 30px;
  262. .avatar-wrapper {
  263. margin-top: 5px;
  264. position: relative;
  265. display: flex;
  266. align-items: center;
  267. font-size: 14px;
  268. height: 100%;
  269. .user-avatar {
  270. cursor: pointer;
  271. width: 24px;
  272. height: 24px;
  273. border-radius: 50%;
  274. margin: 12px;
  275. }
  276. i {
  277. cursor: pointer;
  278. //position: absolute;
  279. //right: -20px;
  280. //top: 25px;
  281. font-size: 12px;
  282. }
  283. }
  284. }
  285. }
  286. }
  287. .search-icon {
  288. width: 17px;
  289. height: 16px;
  290. background: url('@/assets/images/search.png') no-repeat;
  291. background-size: 100% 100%;
  292. }
  293. .message {
  294. width: 17px;
  295. height: 16px;
  296. background: url('@/assets/images/message.png') no-repeat;
  297. background-size: 100% 100%;
  298. }
  299. </style>