Browse Source

feat: 优化首页UI - 搜索框+Tab分类设计

- 顶部改为渐变紫色搜索框
- Tab分类使用简洁文字+下划线指示器
- 移除图标emoji,使用现代简洁风格
- 修复Tab显示不完整问题
MyFramework User 5 months ago
parent
commit
e2d1c2af47
1 changed files with 75 additions and 99 deletions
  1. 75 99
      my-uniapp-vue3/src/pages/index/index.vue

+ 75 - 99
my-uniapp-vue3/src/pages/index/index.vue

@@ -1,38 +1,27 @@
 <template>
   <view class="page">
-    <!-- 顶部导航栏 -->
-    <view class="nav-bar">
-      <view class="nav-content">
-        <text class="logo">AI有声书</text>
-        <view class="nav-right">
-          <view class="search-icon" @click="goToSearch">
-            <text>🔍</text>
-          </view>
-          <view @click="handleUserClick">
-            <image v-if="userStore.userInfo?.avatar" :src="userStore.userInfo.avatar" class="avatar" mode="aspectFill" :lazy-load="true" />
-            <view v-else class="avatar-placeholder">
-              <text class="avatar-text">登</text>
-            </view>
-          </view>
-        </view>
-      </view>
+    <!-- 搜索栏 -->
+    <view class="search-bar" @click="goToSearch">
+      <text class="search-icon">🔍</text>
+      <text class="search-placeholder">搜索有声书...</text>
     </view>
 
     <!-- 分类标签栏 -->
-    <scroll-view scroll-x class="category-bar">
-      <view class="category-list">
-        <view
-          v-for="cat in categories"
-          :key="cat.id"
-          class="category-item"
-          :class="{ active: selectedCategory === cat.id }"
-          @click="selectCategory(cat.id)"
-        >
-          <text>{{ cat.icon }}</text>
-          <text class="category-name">{{ cat.name }}</text>
+    <view class="category-bar">
+      <scroll-view class="category-scroll" scroll-x="true" :show-scrollbar="false">
+        <view class="category-list">
+          <view
+            v-for="cat in categories"
+            :key="cat.id"
+            class="category-item"
+            :class="{ active: selectedCategory === cat.id }"
+            @click="selectCategory(cat.id)"
+          >
+            <text class="category-name">{{ cat.name }}</text>
+          </view>
         </view>
-      </view>
-    </scroll-view>
+      </scroll-view>
+    </view>
 
     <!-- 骨架屏加载状态 -->
     <scroll-view scroll-y class="audio-list" @scrolltolower="loadMore" v-if="loading && audioList.length === 0">
@@ -132,15 +121,14 @@ const hasMore = ref(true);
 interface Category {
   id: number;
   name: string;
-  icon: string;
 }
 const categories = ref<Category[]>([
-  { id: 1, name: '全部', icon: '🎵' },
-  { id: 2, name: '故事', icon: '📖' },
-  { id: 3, name: '小说', icon: '📚' },
-  { id: 4, name: '儿童', icon: '👶' },
-  { id: 5, name: '知识', icon: '💡' },
-  { id: 6, name: '娱乐', icon: '🎮' },
+  { id: 1, name: '推荐' },
+  { id: 2, name: '故事' },
+  { id: 3, name: '小说' },
+  { id: 4, name: '儿童' },
+  { id: 5, name: '知识' },
+  { id: 6, name: '娱乐' },
 ]);
 const selectedCategory = ref(1);
 
@@ -254,106 +242,94 @@ onShow(() => {
   padding-bottom: 180rpx;
 }
 
-.nav-bar {
+.search-bar {
   position: fixed;
   top: 0;
   left: 0;
   right: 0;
-  height: 88rpx;
-  background: #ffffff;
+  height: 100rpx;
+  padding-top: env(safe-area-inset-top);
+  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
+  display: flex;
+  align-items: center;
+  padding-left: 24rpx;
+  padding-right: 24rpx;
   z-index: 100;
-  padding-top: 44rpx;
-  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
 }
 
-.nav-content {
+.search-bar-inner {
+  flex: 1;
+  height: 64rpx;
+  background: rgba(255, 255, 255, 0.2);
+  border-radius: 32rpx;
   display: flex;
   align-items: center;
-  justify-content: space-between;
-  padding: 0 32rpx;
-  height: 88rpx;
-}
-
-.logo {
-  font-size: 36rpx;
-  font-weight: 600;
-  color: #4f46e5;
+  padding: 0 24rpx;
 }
 
-.nav-right {
-  display: flex;
-  align-items: center;
-  gap: 24rpx;
+.search-bar .search-icon {
+  font-size: 28rpx;
+  margin-right: 12rpx;
 }
 
-.search-icon {
-  width: 56rpx;
-  height: 56rpx;
-  display: flex;
-  align-items: center;
-  justify-content: center;
+.search-bar .search-placeholder {
+  font-size: 26rpx;
+  color: rgba(255, 255, 255, 0.8);
 }
 
 .category-bar {
-  position: sticky;
-  top: 88rpx;
+  position: fixed;
+  top: 100rpx;
+  left: 0;
+  right: 0;
   background: #ffffff;
-  padding: 16rpx 0;
-  white-space: nowrap;
   z-index: 99;
+  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
+}
+
+.category-scroll {
+  width: 100%;
+  white-space: nowrap;
 }
 
 .category-list {
-  display: flex;
+  display: inline-flex;
   gap: 16rpx;
-  padding: 0 24rpx;
+  padding: 16rpx 24rpx;
 }
 
 .category-item {
-  display: flex;
-  align-items: center;
-  gap: 6rpx;
-  padding: 12rpx 24rpx;
-  background: #f5f5f5;
-  border-radius: 32rpx;
-  font-size: 26rpx;
-  color: #6b7280;
+  padding: 12rpx 32rpx;
+  font-size: 28rpx;
+  color: #666;
   flex-shrink: 0;
+  position: relative;
 }
 
 .category-item.active {
-  background: #4f46e5;
-  color: #ffffff;
+  color: #4f46e5;
+  font-weight: 600;
 }
 
-.category-name {
-  font-size: 26rpx;
+.category-item.active::after {
+  content: '';
+  position: absolute;
+  bottom: 0;
+  left: 50%;
+  transform: translateX(-50%);
+  width: 40rpx;
+  height: 6rpx;
+  background: #4f46e5;
+  border-radius: 3rpx;
 }
 
-.avatar {
-  width: 56rpx;
-  height: 56rpx;
-  border-radius: 50%;
-}
 
-.avatar-placeholder {
-  width: 56rpx;
-  height: 56rpx;
-  border-radius: 50%;
-  background: linear-gradient(135deg, #4f46e5 0%, #818cf8 100%);
-  display: flex;
-  align-items: center;
-  justify-content: center;
-}
 
-.avatar-text {
-  font-size: 24rpx;
-  color: #ffffff;
-}
+
 
 .audio-list {
-  padding-top: 132rpx;
-  height: calc(100vh - 140rpx);
+  padding-top: 160rpx;
+  height: calc(100vh - 160rpx);
 }
 
 .empty {