index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="app-wrapper">
  3. <!-- 根据 permission.ts 的判断逻辑决定显示哪个header -->
  4. <template v-if="headerType == 'dataHeader'">
  5. <dataHeader :userInfo="userStore.userInfo" v-if="whiteList.indexOf(route.path) == -1" />
  6. </template>
  7. <template v-else-if="headerType == 'jdHeader'">
  8. <jdHeader v-if="whiteList.indexOf(route.path) == -1" />
  9. </template>
  10. <template v-else-if="headerType == 'default'">
  11. <Header v-if="meta.header != 'hide'" />
  12. <Search v-if="meta.search != 'hide' && whiteList.indexOf(route.path) == -1" :meta="meta" />
  13. </template>
  14. <Nav v-if="meta.nav" :meta="meta" />
  15. <Breadcrumb v-if="meta.breadcrumb" />
  16. <div class="pages-bos" :class="meta.workbench ? 'pages-bos1' : 'pages-bos2'" :style="{ minHeight: boxHeight }">
  17. <Workbench ref="WorkbenchRef" v-if="meta.workbench" />
  18. <router-view> </router-view>
  19. </div>
  20. <Foot />
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import { Header, Search, Nav, Breadcrumb, Foot, Workbench } from './components';
  25. import dataHeader from '@/views/home/datacomponents/JDHeader.vue';
  26. import jdHeader from '@/views/home/jdcomponents/JDHeader.vue';
  27. import { stationStore } from '@/store/modules/station';
  28. import { useUserStore } from '@/store/modules/user';
  29. const route = useRoute();
  30. const meta = ref<any>({});
  31. const WorkbenchRef = ref<any>(null);
  32. const boxHeight = ref<any>('0px');
  33. const station = stationStore();
  34. const userStore = useUserStore();
  35. const whiteList = [
  36. '/index',
  37. '/',
  38. '/indexDiy',
  39. '/indexMro',
  40. '/indexMroDiy',
  41. '/indexFuli',
  42. '/indexFuliDiy',
  43. '/indexData',
  44. '/indexDataDiy',
  45. '/indexEnterprise'
  46. ];
  47. // 根据 permission.ts 中的逻辑判断应该显示哪个 Header
  48. const headerType = computed(() => {
  49. if (station.stationData && Object.keys(station.stationData).length > 0) {
  50. const data = station.stationData.data || station.stationData;
  51. const isDiy = data?.isDiy;
  52. if (isDiy === 0 || isDiy === '0') {
  53. return 'dataHeader';
  54. } else if (isDiy !== undefined && isDiy !== null) {
  55. return 'dataHeader';
  56. }
  57. }
  58. // 2. 判断是否显示 jdHeader(userSonType 为 '3' 且允许 /indexEnterprise)
  59. if (userStore.userInfo?.user?.userSonType == '3') {
  60. return 'jdHeader';
  61. }
  62. // 3. 其他情况显示普通 Header
  63. return 'default';
  64. });
  65. const observeHeight = () => {
  66. if (!WorkbenchRef.value?.$el) return;
  67. const resizeObserver = new ResizeObserver((entries) => {
  68. for (const entry of entries) {
  69. boxHeight.value = entry.contentRect.height + 'px';
  70. }
  71. });
  72. resizeObserver.observe(WorkbenchRef.value.$el);
  73. // 组件卸载时清理
  74. onUnmounted(() => {
  75. resizeObserver.disconnect();
  76. });
  77. };
  78. onMounted(() => {
  79. nextTick(() => {
  80. if (route.meta.workbench) {
  81. observeHeight();
  82. }
  83. });
  84. });
  85. watch(
  86. () => route.meta.workbench,
  87. (newVal) => {
  88. if (newVal) {
  89. nextTick(() => observeHeight());
  90. }
  91. }
  92. );
  93. meta.value = route.meta;
  94. watch(route, () => {
  95. meta.value = route.meta;
  96. });
  97. </script>
  98. <style lang="scss" scoped>
  99. @use '@/assets/styles/mixin.scss';
  100. @use '@/assets/styles/variables.module.scss' as *;
  101. .app-wrapper {
  102. min-height: 100vh;
  103. width: 100%;
  104. min-width: 1200px;
  105. background: #f4f4f4;
  106. display: flex;
  107. flex-direction: column;
  108. .pages-bos {
  109. display: flex;
  110. flex: 1;
  111. position: relative;
  112. &.pages-bos1 {
  113. max-width: 1500px;
  114. min-width: 1200px;
  115. width: 100%;
  116. margin: 20px auto;
  117. gap: 0 15px;
  118. }
  119. &.pages-bos2 {
  120. width: 100%;
  121. }
  122. .page-container {
  123. flex: 1;
  124. background-color: #ffffff;
  125. padding: 15px;
  126. margin-bottom: 20px;
  127. }
  128. }
  129. }
  130. </style>