Navbar.vue 10.0 KB

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