feat: 为DIY标签页组件添加滚动容器和样式

This commit is contained in:
2026-02-06 17:55:44 +08:00
parent 6897fc631b
commit 069b3c2c07

View File

@@ -1,14 +1,14 @@
<template> <template>
<!-- DIY 标签页组件 - 支持多种样式和位置的标签页切换 --> <!-- DIY 标签页组件 - 支持多种样式和位置的标签页切换 -->
<view data-component-name="diy-tab" class="tab-diy-component-preview-container" :class="[containerClass, styleClass]" :style="containerStyle"> <view data-component-name="diy-tab" class="tab-diy-component-preview-container"
:class="[containerClass, styleClass]" :style="containerStyle">
<!-- 顶部标签位置:标签导航 + 指示器 + 内容区域 --> <!-- 顶部标签位置:标签导航 + 指示器 + 内容区域 -->
<template v-if="mergedValue.tabPosition === 'top'"> <template v-if="mergedValue.tabPosition === 'top'">
<!-- 标签导航 --> <!-- 标签导航 -->
<view class="tab-nav" :style="tabNavStyle"> <view class="tab-nav" :style="tabNavStyle">
<view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item" <view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" :style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" @tap="switchTab(idx)">
@tap="switchTab(idx)">
<text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]"> <text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]">
{{ getTabTitle(tab.title) }} {{ getTabTitle(tab.title) }}
</text> </text>
@@ -16,8 +16,7 @@
</view> </view>
<!-- 指示器 --> <!-- 指示器 -->
<view v-if="mergedValue.showIndicator" class="tab-indicator" <view v-if="mergedValue.showIndicator" class="tab-indicator" :style="{
:style="{
...indicatorStyle, ...indicatorStyle,
top: indicatorVars.top, top: indicatorVars.top,
left: indicatorVars.left, left: indicatorVars.left,
@@ -32,11 +31,13 @@
<view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel" <view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]"> :style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]">
<view v-if="tab.components && tab.components.length > 0" class="tab-components">
<!-- 渲染每个标签下的组件 --> <!-- 渲染每个标签下的组件 -->
<diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }" <diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }"
:scrollTop="tab.scrollTop || 0" /> :scrollTop="tab.scrollTop || 0" />
</view> </view>
</view> </view>
</view>
</template> </template>
<!-- 底部标签位置:内容区域 + 指示器 + 标签导航 --> <!-- 底部标签位置:内容区域 + 指示器 + 标签导航 -->
@@ -46,15 +47,15 @@
<view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel" <view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]"> :style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]">
<view v-if="tab.components && tab.components.length > 0" class="tab-components">
<!-- 渲染每个标签下的组件 --> <!-- 渲染每个标签下的组件 -->
<diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }" <diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }"
:scrollTop="tab.scrollTop || 0" /> :scrollTop="tab.scrollTop || 0" />
</view> </view>
</view> </view>
</view>
<!-- 指示器 --> <!-- 指示器 -->
<view v-if="mergedValue.showIndicator" class="tab-indicator" <view v-if="mergedValue.showIndicator" class="tab-indicator" :style="{
:style="{
...indicatorStyle, ...indicatorStyle,
top: indicatorVars.top, top: indicatorVars.top,
left: indicatorVars.left, left: indicatorVars.left,
@@ -68,8 +69,7 @@
<view class="tab-nav" :style="tabNavStyle"> <view class="tab-nav" :style="tabNavStyle">
<view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item" <view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" :style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" @tap="switchTab(idx)">
@tap="switchTab(idx)">
<text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]"> <text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]">
{{ getTabTitle(tab.title) }} {{ getTabTitle(tab.title) }}
</text> </text>
@@ -84,8 +84,7 @@
<view class="tab-nav tab-nav-vertical" :style="tabNavStyle"> <view class="tab-nav tab-nav-vertical" :style="tabNavStyle">
<view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item tab-item-vertical" <view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item tab-item-vertical"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" :style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" @tap="switchTab(idx)">
@tap="switchTab(idx)">
<text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]"> <text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]">
{{ getTabTitle(tab.title) }} {{ getTabTitle(tab.title) }}
</text> </text>
@@ -93,8 +92,7 @@
</view> </view>
<!-- 左侧指示器 --> <!-- 左侧指示器 -->
<view v-if="mergedValue.showIndicator" class="tab-indicator tab-indicator-vertical" <view v-if="mergedValue.showIndicator" class="tab-indicator tab-indicator-vertical" :style="{
:style="{
...indicatorStyle, ...indicatorStyle,
top: indicatorVars.top, top: indicatorVars.top,
left: indicatorVars.left, left: indicatorVars.left,
@@ -109,12 +107,14 @@
<view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel" <view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]"> :style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]">
<view v-if="tab.components && tab.components.length > 0" class="tab-components">
<!-- 渲染每个标签下的组件 --> <!-- 渲染每个标签下的组件 -->
<diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }" <diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }"
:scrollTop="tab.scrollTop || 0" /> :scrollTop="tab.scrollTop || 0" />
</view> </view>
</view> </view>
</view> </view>
</view>
</template> </template>
<!-- 右侧标签位置:内容区域 + 指示器 + 标签导航 (水平布局) --> <!-- 右侧标签位置:内容区域 + 指示器 + 标签导航 (水平布局) -->
@@ -125,15 +125,16 @@
<view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel" <view v-for="(tab, idx) in mergedValue.tabs" :key="'panel' + idx" class="tab-panel"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]"> :style="[panelStyle, activeTab === idx ? panelActiveStyle : {}]">
<view v-if="tab.components && tab.components.length > 0" class="tab-components">
<!-- 渲染每个标签下的组件 --> <!-- 渲染每个标签下的组件 -->
<diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }" <diy-group v-if="tab.components" :diyData="{ value: tab.components, global: diyGlobal }"
:scrollTop="tab.scrollTop || 0" /> :scrollTop="tab.scrollTop || 0" />
</view> </view>
</view> </view>
</view>
<!-- 右侧指示器 --> <!-- 右侧指示器 -->
<view v-if="mergedValue.showIndicator" class="tab-indicator tab-indicator-vertical" <view v-if="mergedValue.showIndicator" class="tab-indicator tab-indicator-vertical" :style="{
:style="{
...indicatorStyle, ...indicatorStyle,
top: indicatorVars.top, top: indicatorVars.top,
left: indicatorVars.left, left: indicatorVars.left,
@@ -147,8 +148,7 @@
<view class="tab-nav tab-nav-vertical" :style="tabNavStyle"> <view class="tab-nav tab-nav-vertical" :style="tabNavStyle">
<view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item tab-item-vertical" <view v-for="(tab, idx) in mergedValue.tabs" :key="tab.id || idx" class="tab-item tab-item-vertical"
:class="{ active: activeTab === idx }" :class="{ active: activeTab === idx }"
:style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" :style="[tabItemStyle, activeTab === idx ? tabItemActiveStyle : {}]" @tap="switchTab(idx)">
@tap="switchTab(idx)">
<text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]"> <text class="tab-text" :style="[tabTextStyle, activeTab === idx ? tabTextActiveStyle : {}]">
{{ getTabTitle(tab.title) }} {{ getTabTitle(tab.title) }}
</text> </text>
@@ -1073,6 +1073,28 @@ export default {
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
transition: none; transition: none;
} }
.tab-components {
width: 100%;
height: 100%;
overflow-y: auto;
box-sizing: border-box;
padding-right: 8px;
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.05);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(0, 0, 0, 0.3);
}
}
} }
// ===== 默认样式 ===== // ===== 默认样式 =====