riku
2025-09-20 0796eebe3520fafb0ac5d36ee584af81506d7e9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
  <el-affix>
    <el-menu
      ref="menuRef"
      :default-active="menu.length > 0 ? menu[0].path : ''"
      ellipsis
      mode="horizontal"
    >
      <el-menu-item
        v-for="item in menu"
        :key="item.path"
        :index="item.path"
        @click="navPage"
        >{{ item.name }}</el-menu-item
      >
    </el-menu>
  </el-affix>
  <router-view v-slot="{ Component, route }" :style="{ height: height + 'px' }">
    <keep-alive>
      <component
        v-if="route.meta.keepAlive"
        :is="Component"
        :key="route.name"
      />
    </keep-alive>
    <component v-if="!route.meta.keepAlive" :is="Component" :key="route.name" />
  </router-view>
</template>
<script setup>
import { ref, onMounted, provide, inject, computed } from 'vue';
import { useRouter } from 'vue-router';
 
const contentMaxHeight = inject('contentMaxHeight');
 
const props = defineProps({
  menu: {
    type: Array,
    default: () => []
  }
})
 
const router = useRouter();
 
const menuRef = ref(null);
const height = ref(contentMaxHeight.value);
 
// const menu = ref([
//   {
//     name: '场景清单',
//     path: 'scene',
//     selected: true
//   },
//   {
//     name: '评估清单',
//     path: 'evaluate'
//   },
//   {
//     name: '整改清单',
//     path: 'inspection'
//   },
//   {
//     name: '监测数据',
//     path: 'monitorData'
//   }
// ]);
 
const navPage = (item) => {
  if (item.index) {
    router.push({
      path: item.index
    });
  }
};
 
function calcTableHeight() {
  const h = menuRef.value.$el.offsetHeight;
  return contentMaxHeight.value - h;
  // return `calc(100vh - ${h}px - 60px - var(--el-main-padding) * 2)`;
}
 
onMounted(() => {
  height.value = calcTableHeight();
});
 
// 提供给内部组件视图最大高度
provide(
  'viewHeight',
  computed(() => height.value)
);
</script>
<style scoped></style>