Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

aHeader.vue 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <a-row>
  3. <a-col :span="4" style="display: flex;align-items: center;">
  4. <menu-unfold-outlined v-if="collapsed" class="trigger" @click="onCollapsed" />
  5. <menu-fold-outlined v-else class="trigger" @click="onCollapsed" />
  6. <a-input-search v-model:value="routerValue" placeholder="请输入想进入的管理页面" @keyup.enter="onSearch"
  7. @search="onSearch" style="margin-left: 10px;" />
  8. </a-col>
  9. <a-col :span="20">
  10. <a-row type="flex" justify="end" :gutter="20">
  11. <a-col flex="200px">
  12. <div>{{time}}</div>
  13. </a-col>
  14. <a-col flex="50px">
  15. <a-avatar src="@/static/images/logo_1.jpg"></a-avatar>
  16. </a-col>
  17. <a-col flex="50px">
  18. <div>admin</div>
  19. </a-col>
  20. <a-col flex="16px">
  21. <LogoutOutlined @click="loginOut" />
  22. </a-col>
  23. </a-row>
  24. </a-col>
  25. </a-row>
  26. </template>
  27. <script lang="ts" setup>
  28. import { ref, onMounted, computed } from 'vue';
  29. import { store } from '@/store';
  30. import { router } from '@/router';
  31. import { MenuUnfoldOutlined, MenuFoldOutlined, LogoutOutlined } from '@ant-design/icons-vue';
  32. import { getTime } from '@/utils/timeHelper';
  33. import { useComputed } from '@/hooks/useComputed';
  34. import { useMenu } from '@/hooks/useMenu';
  35. let { menuList, onMenu, message } = useMenu();
  36. let routerValue : string = ref('');
  37. const time : string = ref('');
  38. const currentTime = () => {
  39. setInterval(() => {
  40. time.value = getTime().nowTime + " " + getTime().nowDate + " " + getTime().nowWeek;
  41. }, 500);
  42. };
  43. const collapsed = computed(() => {
  44. return store.state.collapsed
  45. })
  46. const onCollapsed = () => {
  47. store.commit('getCollapsed');
  48. }
  49. onMounted(() => {
  50. currentTime();
  51. });
  52. const loginOut = () => {
  53. sessionStorage.clear();
  54. window.location.reload();
  55. router.replace('/login');
  56. }
  57. const onSearch = (val) => {
  58. const result = menuList.value.some(item => deepCompareAndMarkChecked(item, val));
  59. if(result.result == 1) {
  60. onMenu(result.path)
  61. } else {
  62. message.warning('无此页面')
  63. }
  64. }
  65. const deepCompareAndMarkChecked = (item : Object, str : String) => {
  66. let data = {
  67. result: 0,
  68. path: ''
  69. };
  70. if (item.meta.title === str) {
  71. return data = {
  72. result: 1,
  73. path: item.path
  74. };
  75. }
  76. if (item.children && Array.isArray(item.children)) {
  77. for (const child of item.children) {
  78. const result = deepCompareAndMarkChecked(child, str);
  79. if (result === 1) {
  80. return data = {
  81. result: 1,
  82. path: obj.path
  83. };
  84. }
  85. }
  86. }
  87. return data = {
  88. result: 0,
  89. path: ''
  90. };
  91. }
  92. </script>
  93. <style>
  94. </style>