index.vue 3.6 KB
<!--
  NutUI Tabs 自定义标签栏测试页面

  @description 测试 NutUI Tabs 组件的自定义标签栏功能
  @page pages/test-tabs
  @created 2026-01-31
-->
<template>
  <view class="test-tabs-page">
    <view class="tabs-container">
      <nut-tabs v-model="activeTab">
        <!-- 自定义标签栏 - 参考 FilterTabs 样式 -->
        <template #titles>
          <view class="filter-tabs-wrapper">
            <view
              v-for="item in tabList"
              :key="item.paneKey"
              :class="[
                'filter-tab-item',
                activeTab === item.paneKey ? 'filter-tab-active' : 'filter-tab-inactive'
              ]"
              @tap="handleTabClick(item.paneKey)"
            >
              <text class="filter-tab-text">{{ item.title }}</text>
            </view>
          </view>
        </template>

        <!-- Tab 内容 -->
        <nut-tab-pane v-for="item in tabList" :key="item.paneKey" :pane-key="item.paneKey">
          <view class="tab-content">
            <text class="content-text">{{ item.content }}</text>
            <view class="content-list">
              <view v-for="i in 3" :key="i" class="list-item">
                <text>{{ item.title }} - 列表项 {{ i }}</text>
              </view>
            </view>
          </view>
        </nut-tab-pane>
      </nut-tabs>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

// 当前激活的 Tab
const activeTab = ref('c1')

// Tab 列表数据
const tabList = ref([
  {
    title: 'Tab 1',
    paneKey: 'c1',
    content: '这是 Tab 1 的内容区域'
  },
  {
    title: 'Tab 2',
    paneKey: 'c2',
    content: '这是 Tab 2 的内容区域'
  },
  {
    title: 'Tab 3',
    paneKey: 'c3',
    content: '这是 Tab 3 的内容区域'
  },
  {
    title: 'Tab 4',
    paneKey: 'c4',
    content: '这是 Tab 4 的内容区域'
  },
  {
    title: 'Tab 5',
    paneKey: 'c5',
    content: '这是 Tab 5 的内容区域'
  },
  {
    title: 'Tab 6',
    paneKey: 'c6',
    content: '这是 Tab 6 的内容区域'
  }
])

/**
 * 处理 Tab 点击事件
 * @param {string} paneKey - Tab 的 paneKey
 */
const handleTabClick = (paneKey) => {
  activeTab.value = paneKey
}
</script>

<style lang="less">
.test-tabs-page {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.page-header {
  padding: 40px 30px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
}

.page-title {
  font-size: 32px;
  font-weight: bold;
  color: #333;
}

.tabs-container {
  background-color: #fff;
  margin-top: 20px;
}

// FilterTabs 风格的标签栏
.filter-tabs-wrapper {
  display: flex;
  overflow-x: auto;
  padding: 24px 30px;
  gap: 24rpx;
  transition: all 0.3s ease;

  // 隐藏滚动条
  &::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  -ms-overflow-style: none;
  scrollbar-width: none;
}

.filter-tab-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16rpx 32rpx;
  border-radius: 9999rpx;
  white-space: nowrap;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.filter-tab-active {
  background-color: #2563EB; // 蓝色背景
  color: #fff;
}

.filter-tab-inactive {
  background-color: #F3F4F6; // 灰色背景
  color: #6B7280;
}

.filter-tab-text {
  font-size: 28rpx;
  font-weight: 500;
}

// Tab 内容区域
.tab-content {
  padding: 30px;
  min-height: 400px;
}

.content-text {
  font-size: 28px;
  color: #333;
  margin-bottom: 30px;
  display: block;
}

.content-list {
  margin-top: 30px;
}

.list-item {
  padding: 24px;
  background-color: #f9f9f9;
  border-radius: 12px;
  margin-bottom: 20px;
  font-size: 26px;
  color: #666;
}
</style>