|
|
@@ -22,31 +22,45 @@ const panels = shallowReactive([
|
|
|
].filter(item => !unref(item.hide)));
|
|
|
|
|
|
const activePanel = ref(panels[0].id);
|
|
|
-const panelRef = ref<any[]>([]);
|
|
|
-
|
|
|
-function handleChange(activeKey: any) {
|
|
|
- let newVal = activeKey.target.value;
|
|
|
- const activeComponent = panels.findIndex(panel => {
|
|
|
- return panel.id === newVal;
|
|
|
- });
|
|
|
- panelRef.value[activeComponent]?.send();
|
|
|
+const currentComponent = ref<any>(null);
|
|
|
+
|
|
|
+// 获取当前激活的组件
|
|
|
+const getCurrentComponent = () => {
|
|
|
+ return panels.find(panel => panel.id === activePanel.value);
|
|
|
+};
|
|
|
+
|
|
|
+// 切换面板
|
|
|
+function handleChange(panelId: string) {
|
|
|
+ activePanel.value = panelId;
|
|
|
+ // 延迟执行,确保新组件已经渲染完成
|
|
|
+ setTimeout(() => {
|
|
|
+ if (currentComponent.value && typeof currentComponent.value.send === 'function') {
|
|
|
+ currentComponent.value?.send();
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div class="p-6">
|
|
|
- <a-tabs class="panel-wrapper" v-model:activeKey="activePanel" >
|
|
|
- <a-tab-pane v-for="panel in panels" :key="panel.id">
|
|
|
- <component :is="panel.component" :title="panel.title" ref="panelRef"></component>
|
|
|
- </a-tab-pane>
|
|
|
- <template #renderTabBar>
|
|
|
- <a-radio-group v-model:value="activePanel" @change="handleChange">
|
|
|
- <a-radio-button v-for="panel in panels" :key="panel.id" :value="panel.id">
|
|
|
- {{ panel.title }}
|
|
|
- </a-radio-button>
|
|
|
- </a-radio-group>
|
|
|
- </template>
|
|
|
- </a-tabs>
|
|
|
+ <!-- 标签栏 -->
|
|
|
+ <div class="mb-4">
|
|
|
+ <a-radio-group v-model:value="activePanel" @change="(e) => handleChange(e.target.value)">
|
|
|
+ <a-radio-button v-for="panel in panels" :key="panel.id" :value="panel.id">
|
|
|
+ {{ panel.title }}
|
|
|
+ </a-radio-button>
|
|
|
+ </a-radio-group>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 内容区域 -->
|
|
|
+ <div class="content-wrapper">
|
|
|
+ <component
|
|
|
+ :is="getCurrentComponent()?.component"
|
|
|
+ :title="getCurrentComponent()?.title"
|
|
|
+ ref="currentComponent"
|
|
|
+ :key="activePanel"
|
|
|
+ ></component>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -124,15 +138,9 @@ section {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-.panel-wrapper {
|
|
|
- :deep(.ant-tabs-content-holder) {
|
|
|
- padding-top: 12px;
|
|
|
- height: calc(100vh - 60px - 24px - 32px);
|
|
|
-
|
|
|
- .ant-tabs-content {
|
|
|
- height: 100%;
|
|
|
- }
|
|
|
- }
|
|
|
+.content-wrapper {
|
|
|
+ height: calc(100vh - 60px - 24px - 32px - 60px); // 减去标签栏高度
|
|
|
+ overflow: auto;
|
|
|
}
|
|
|
|
|
|
.trend-up {
|