瀏覽代碼

统一导航组件并完善传承页筛选统计与文章收藏

lzj 1 月之前
父節點
當前提交
0a4baace18
共有 46 個文件被更改,包括 656 次插入 和 572 次删除
  1. 2 2
      patches/weapp-svg-icon@1.0.0.patch
  2. 3 3
      pnpm-lock.yaml
  3. 0 25
      src/components/heritage-header/index.wxml
  4. 0 45
      src/components/heritage-header/index.wxss
  5. 0 0
      src/components/nav-bar/index.json
  6. 40 0
      src/components/nav-bar/index.ts
  7. 9 0
      src/components/nav-bar/index.wxml
  8. 35 0
      src/components/nav-bar/index.wxss
  9. 0 30
      src/components/news-header/index.ts
  10. 0 22
      src/components/news-header/index.wxml
  11. 0 35
      src/components/news-header/index.wxss
  12. 0 0
      src/components/tab-header/index.json
  13. 35 6
      src/components/heritage-header/index.ts
  14. 23 0
      src/components/tab-header/index.wxml
  15. 61 0
      src/components/tab-header/index.wxss
  16. 0 5
      src/components/travel-header/index.json
  17. 0 13
      src/components/travel-header/index.ts
  18. 0 5
      src/components/travel-header/index.wxml
  19. 0 12
      src/components/travel-header/index.wxss
  20. 38 7
      src/data/inherit-api.ts
  21. 37 0
      src/data/user-api.ts
  22. 1 1
      src/pages/inherit/inherit.json
  23. 88 61
      src/pages/inherit/inherit.ts
  24. 35 53
      src/pages/inherit/inherit.wxml
  25. 101 40
      src/pages/inherit/inherit.wxss
  26. 1 1
      src/pages/news/news.json
  27. 1 1
      src/pages/news/news.wxml
  28. 1 1
      src/pages/travel/travel.json
  29. 1 1
      src/pages/travel/travel.wxml
  30. 1 0
      src/subpackages/content/article-detail/article-detail.json
  31. 28 35
      src/subpackages/content/article-detail/article-detail.scss
  32. 56 13
      src/subpackages/content/article-detail/article-detail.ts
  33. 9 10
      src/subpackages/content/article-detail/article-detail.wxml
  34. 1 0
      src/subpackages/content/culture-list/culture-list.json
  35. 0 34
      src/subpackages/content/culture-list/culture-list.scss
  36. 0 17
      src/subpackages/content/culture-list/culture-list.ts
  37. 2 8
      src/subpackages/content/culture-list/culture-list.wxml
  38. 6 5
      src/subpackages/content/favorites/favorites.json
  39. 12 4
      src/subpackages/content/favorites/favorites.scss
  40. 5 3
      src/subpackages/content/favorites/favorites.ts
  41. 20 14
      src/subpackages/content/favorites/favorites.wxml
  42. 3 1
      src/subpackages/content/village-list/village-list.json
  43. 0 33
      src/subpackages/content/village-list/village-list.scss
  44. 0 15
      src/subpackages/content/village-list/village-list.ts
  45. 1 8
      src/subpackages/content/village-list/village-list.wxml
  46. 0 3
      src/utils/nav-bar.ts

File diff suppressed because it is too large
+ 2 - 2
patches/weapp-svg-icon@1.0.0.patch


+ 3 - 3
pnpm-lock.yaml

@@ -5,7 +5,7 @@ settings:
   excludeLinksFromLockfile: false
 
 patchedDependencies:
-  weapp-svg-icon@1.0.0: fcb3cb71a53c4894474110b4e4726da91f0d5ef652dfb3a611d4282e4b551dd5
+  weapp-svg-icon@1.0.0: bc7180b5ce89b9bbee281d9fc9ecacdeddbddeb07ca958d66e23ff6eda462b08
 
 importers:
 
@@ -16,7 +16,7 @@ importers:
         version: 1.11.7
       weapp-svg-icon:
         specifier: ^1.0.0
-        version: 1.0.0(patch_hash=fcb3cb71a53c4894474110b4e4726da91f0d5ef652dfb3a611d4282e4b551dd5)
+        version: 1.0.0(patch_hash=bc7180b5ce89b9bbee281d9fc9ecacdeddbddeb07ca958d66e23ff6eda462b08)
     devDependencies:
       '@icebreakers/eslint-config':
         specifier: ^7.1.0
@@ -11359,7 +11359,7 @@ snapshots:
       '@weapp-tailwindcss/shared': 2.0.3
       micromatch: 4.0.8
 
-  weapp-svg-icon@1.0.0(patch_hash=fcb3cb71a53c4894474110b4e4726da91f0d5ef652dfb3a611d4282e4b551dd5):
+  weapp-svg-icon@1.0.0(patch_hash=bc7180b5ce89b9bbee281d9fc9ecacdeddbddeb07ca958d66e23ff6eda462b08):
     dependencies:
       '@iconify-json/mdi-light': 1.2.2
 

+ 0 - 25
src/components/heritage-header/index.wxml

@@ -1,25 +0,0 @@
-<view class="heritage-header" style="padding-top: {{statusBarHeight}}px;">
-  <view class="heritage-header__inner">
-    <view class="flex items-center gap-2.5">
-      <view class="heritage-header__back" bindtap="onBack">
-        <svg-icon name="ph:caret-left-bold" size="17px" color="#ffffff" />
-      </view>
-      <text class="text-xl font-bold tracking-[.2em] text-white">传承</text>
-    </view>
-
-    <view class="mt-4 flex">
-      <view class="heritage-header__search">
-        <svg-icon name="ph:magnifying-glass" size="18px" color="#8a7566" />
-        <input
-          class="heritage-header__input"
-          value="{{value}}"
-          placeholder="搜非遗名称、传承人、技艺、区县"
-          placeholder-class="heritage-header__placeholder"
-          confirm-type="search"
-          bindinput="onInput"
-          bindconfirm="onConfirm"
-        />
-      </view>
-    </view>
-  </view>
-</view>

+ 0 - 45
src/components/heritage-header/index.wxss

@@ -1,45 +0,0 @@
-.heritage-header {
-  flex: none;
-  background-color: #9d3829;
-  background-image: linear-gradient(30deg, transparent 45%, rgb(247 217 159 / 20%) 46%, transparent 47%),
-    linear-gradient(150deg, transparent 45%, rgb(247 217 159 / 20%) 46%, transparent 47%);
-  background-size: 34px 34px;
-}
-
-.heritage-header__inner {
-  padding: 10px 16px 20px;
-}
-
-.heritage-header__back {
-  width: 32px;
-  height: 32px;
-  border-radius: 50%;
-  background-color: rgb(255 255 255 / 15%);
-  display: flex;
-  align-items: center;
-  justify-content: center;
-}
-
-.heritage-header__search {
-  flex: 1;
-  height: 40px;
-  background-color: #fffaf1;
-  border-radius: 12px;
-  padding: 0 12px;
-  display: flex;
-  align-items: center;
-  gap: 8px;
-  box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
-}
-
-.heritage-header__input {
-  min-width: 0;
-  flex: 1;
-  background: transparent;
-  font-size: 12px;
-  color: #51433e;
-}
-
-.heritage-header__placeholder {
-  color: #ab9b8d;
-}

src/components/heritage-header/index.json → src/components/nav-bar/index.json


+ 40 - 0
src/components/nav-bar/index.ts

@@ -0,0 +1,40 @@
+import { getNavBarLayout } from '../../utils/nav-bar'
+
+/** 二级页面通用的自定义导航栏;默认插槽用于放置搜索框、筛选等附加头部内容。 */
+Component({
+  properties: {
+    title: {
+      type: String,
+      value: '',
+    },
+    /** 没有上一页(如分享直达)时,返回按钮跳转的 tab 页。 */
+    fallbackUrl: {
+      type: String,
+      value: '/pages/home/home',
+    },
+  },
+
+  data: {
+    statusBarHeight: 20,
+    navHeight: 44,
+    navRightPadding: 100,
+  },
+
+  lifetimes: {
+    attached() {
+      const { statusBarHeight, navHeight, navRightPadding } = getNavBarLayout()
+      this.setData({ statusBarHeight, navHeight, navRightPadding })
+    },
+  },
+
+  methods: {
+    onBack() {
+      if (getCurrentPages().length > 1) {
+        wx.navigateBack()
+      }
+      else {
+        wx.switchTab({ url: this.data.fallbackUrl })
+      }
+    },
+  },
+})

+ 9 - 0
src/components/nav-bar/index.wxml

@@ -0,0 +1,9 @@
+<view class="nav-bar" style="padding-top: {{statusBarHeight}}px;">
+  <view class="nav-bar__row" style="height: {{navHeight}}px; padding-right: {{navRightPadding}}px;">
+    <view class="nav-bar__back" aria-role="button" aria-label="返回" bindtap="onBack">
+      <svg-icon name="ph:caret-left-bold" size="18px" color="#753c2b" />
+    </view>
+    <text class="nav-bar__title">{{title}}</text>
+  </view>
+  <slot />
+</view>

+ 35 - 0
src/components/nav-bar/index.wxss

@@ -0,0 +1,35 @@
+.nav-bar {
+  flex: none;
+  background: #f9f3e7;
+  border-bottom: 1px solid #eadcc5;
+}
+
+.nav-bar__row {
+  display: flex;
+  gap: 10px;
+  align-items: center;
+  padding-left: 16px;
+}
+
+.nav-bar__back {
+  display: flex;
+  flex: none;
+  align-items: center;
+  justify-content: center;
+  width: 36px;
+  height: 36px;
+  background: rgb(255 255 255 / 70%);
+  border: 1px solid #eadcc5;
+  border-radius: 50%;
+}
+
+.nav-bar__title {
+  flex: 1;
+  min-width: 0;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  font-size: 17px;
+  font-weight: 600;
+  color: #753c2b;
+  white-space: nowrap;
+}

+ 0 - 30
src/components/news-header/index.ts

@@ -1,30 +0,0 @@
-import { getNavBarLayout } from '../../utils/nav-bar'
-
-Component({
-  properties: {
-    showActions: {
-      type: Boolean,
-      value: true,
-    },
-    value: {
-      type: String,
-      value: '',
-    },
-  },
-
-  data: {
-    statusBarHeight: 20,
-  },
-
-  lifetimes: {
-    attached() {
-      this.setData({ statusBarHeight: getNavBarLayout().statusBarHeight })
-    },
-  },
-
-  methods: {
-    onInput(e: WechatMiniprogram.Input) {
-      this.triggerEvent('search', { keyword: e.detail.value })
-    },
-  },
-})

+ 0 - 22
src/components/news-header/index.wxml

@@ -1,22 +0,0 @@
-<view class="news-header" style="padding-top: {{statusBarHeight}}px;">
-  <view class="news-header__inner">
-    <view class="flex items-center justify-between">
-      <text class="text-2xl font-bold tracking-[.24em] text-white">资讯</text>
-    </view>
-
-    <view wx:if="{{showActions}}" class="mt-4 flex gap-2">
-      <view class="news-header__search">
-        <svg-icon name="ph:magnifying-glass" size="18px" color="#8a7566" />
-        <input
-          class="news-header__input"
-          value="{{value}}"
-          placeholder="试试“古厝日落”或“亲子研学”"
-          placeholder-class="news-header__placeholder"
-          confirm-type="search"
-          bindinput="onInput"
-        />
-        <svg-icon name="ph:lightbulb-duotone" size="18px" color="#d29b3d" />
-      </view>
-    </view>
-  </view>
-</view>

+ 0 - 35
src/components/news-header/index.wxss

@@ -1,35 +0,0 @@
-.news-header {
-  flex: none;
-  background-color: #9d3829;
-  background-image: linear-gradient(35deg, transparent 45%, rgb(246 214 154 / 20%) 46%, transparent 47%),
-    linear-gradient(145deg, transparent 45%, rgb(246 214 154 / 20%) 46%, transparent 47%);
-  background-size: 32px 32px;
-}
-
-.news-header__inner {
-  padding: 10px 16px 20px;
-}
-
-.news-header__search {
-  flex: 1;
-  height: 40px;
-  background-color: #fffaf1;
-  border-radius: 20px;
-  padding: 0 12px;
-  display: flex;
-  align-items: center;
-  gap: 8px;
-  box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
-}
-
-.news-header__input {
-  min-width: 0;
-  flex: 1;
-  background: transparent;
-  font-size: 12px;
-  color: #51433e;
-}
-
-.news-header__placeholder {
-  color: #aa9787;
-}

src/components/news-header/index.json → src/components/tab-header/index.json


+ 35 - 6
src/components/heritage-header/index.ts

@@ -1,15 +1,41 @@
 import { getNavBarLayout } from '../../utils/nav-bar'
+import { svgToDataUri } from '../../utils/svgIcon'
 
+// 窗棂菱格纹,平铺作为底纹。
+const LATTICE_SVG
+  = '<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">'
+    + '<path d="M16 1 31 16 16 31 1 16Z" fill="none" stroke="#f6d79a" stroke-opacity=".13"/>'
+    + '<circle cx="16" cy="16" r="1.6" fill="#f6d79a" fill-opacity=".2"/>'
+    + '</svg>'
+
+const SEARCH_DEBOUNCE = 300
+
+/** tab 页顶部头部:标题与可选搜索框,统一底色与纹样。 */
 Component({
   properties: {
+    title: {
+      type: String,
+      value: '',
+    },
+    showSearch: {
+      type: Boolean,
+      value: false,
+    },
     value: {
       type: String,
       value: '',
     },
+    placeholder: {
+      type: String,
+      value: '搜索',
+    },
   },
 
   data: {
     statusBarHeight: 20,
+    navHeight: 44,
+    navRightPadding: 100,
+    latticeUrl: '',
     searchTimer: null as ReturnType<typeof setTimeout> | null,
   },
 
@@ -21,7 +47,13 @@ Component({
 
   lifetimes: {
     attached() {
-      this.setData({ statusBarHeight: getNavBarLayout().statusBarHeight })
+      const { statusBarHeight, navHeight, navRightPadding } = getNavBarLayout()
+      this.setData({
+        statusBarHeight,
+        navHeight,
+        navRightPadding,
+        latticeUrl: svgToDataUri(LATTICE_SVG),
+      })
     },
     detached() {
       this.clearSearchTimer()
@@ -32,11 +64,11 @@ Component({
     onInput(e: WechatMiniprogram.Input) {
       this.clearSearchTimer()
       const keyword = e.detail.value
-      // 停止输入后再查询,避免连续输入时反复请求四个栏目。
+      // 停止输入后再查询,避免连续输入时反复请求。
       this.data.searchTimer = setTimeout(() => {
         this.data.searchTimer = null
         this.triggerEvent('search', { keyword })
-      }, 300)
+      }, SEARCH_DEBOUNCE)
     },
     onConfirm(e: WechatMiniprogram.InputConfirm) {
       this.clearSearchTimer()
@@ -48,8 +80,5 @@ Component({
         this.data.searchTimer = null
       }
     },
-    onBack() {
-      this.triggerEvent('back')
-    },
   },
 })

+ 23 - 0
src/components/tab-header/index.wxml

@@ -0,0 +1,23 @@
+<view class="tab-header" style="padding-top: {{statusBarHeight}}px;">
+  <view class="tab-header__lattice" style="background-image: {{latticeUrl}};"></view>
+
+  <view class="tab-header__inner">
+    <view class="tab-header__row" style="height: {{navHeight}}px; padding-right: {{navRightPadding}}px;">
+      <text class="tab-header__title">{{title}}</text>
+    </view>
+
+    <view wx:if="{{showSearch}}" class="tab-header__search">
+      <svg-icon name="ph:magnifying-glass" size="18px" color="#8a7566" />
+      <input
+        class="tab-header__input"
+        value="{{value}}"
+        placeholder="{{placeholder}}"
+        placeholder-class="tab-header__placeholder"
+        confirm-type="search"
+        bindinput="onInput"
+        bindconfirm="onConfirm"
+        aria-label="{{placeholder}}"
+      />
+    </view>
+  </view>
+</view>

+ 61 - 0
src/components/tab-header/index.wxss

@@ -0,0 +1,61 @@
+.tab-header {
+  position: relative;
+  flex: none;
+  overflow: hidden;
+  background-color: #9d3829;
+  background-image: radial-gradient(circle at 12% 0%, rgb(255 214 150 / 22%), transparent 55%),
+    linear-gradient(160deg, #b5452f 0%, #9d3829 52%, #7f2a20 100%);
+  box-shadow: 0 4px 12px rgb(127 42 32 / 18%);
+}
+
+.tab-header__lattice {
+  position: absolute;
+  inset: 0;
+  background-repeat: repeat;
+  background-size: 28px 28px;
+}
+
+.tab-header__inner {
+  position: relative;
+  padding: 0 16px 14px;
+}
+
+.tab-header__row {
+  display: flex;
+  align-items: center;
+}
+
+.tab-header__title {
+  overflow: hidden;
+  text-overflow: ellipsis;
+  font-size: 24px;
+  font-weight: 700;
+  line-height: 1.2;
+  color: #fff;
+  letter-spacing: 0.16em;
+  white-space: nowrap;
+}
+
+.tab-header__search {
+  display: flex;
+  gap: 8px;
+  align-items: center;
+  height: 40px;
+  padding: 0 14px;
+  margin-top: 6px;
+  background-color: #fffaf1;
+  border-radius: 20px;
+  box-shadow: 0 2px 6px rgb(0 0 0 / 12%);
+}
+
+.tab-header__input {
+  flex: 1;
+  min-width: 0;
+  font-size: 13px;
+  color: #51433e;
+  background: transparent;
+}
+
+.tab-header__placeholder {
+  color: #ab9b8d;
+}

+ 0 - 5
src/components/travel-header/index.json

@@ -1,5 +0,0 @@
-{
-  "component": true,
-  "styleIsolation": "apply-shared",
-  "usingComponents": {}
-}

+ 0 - 13
src/components/travel-header/index.ts

@@ -1,13 +0,0 @@
-import { getNavBarLayout } from '../../utils/nav-bar'
-
-Component({
-  data: {
-    statusBarHeight: 20,
-  },
-
-  lifetimes: {
-    attached() {
-      this.setData({ statusBarHeight: getNavBarLayout().statusBarHeight })
-    },
-  },
-})

+ 0 - 5
src/components/travel-header/index.wxml

@@ -1,5 +0,0 @@
-<view class="travel-header" style="padding-top: {{statusBarHeight}}px;">
-  <view class="travel-header__inner">
-    <text class="text-2xl font-bold tracking-[.18em] text-white">趣游漳州</text>
-  </view>
-</view>

+ 0 - 12
src/components/travel-header/index.wxss

@@ -1,12 +0,0 @@
-.travel-header {
-  flex: none;
-  background-color: #a73529;
-  background-image: linear-gradient(90deg, rgb(255 240 213 / 9%) 1px, transparent 1px),
-    linear-gradient(rgb(255 240 213 / 9%) 1px, transparent 1px);
-  background-size: 34px 15px;
-  box-shadow: 0 2px 6px rgb(0 0 0 / 12%);
-}
-
-.travel-header__inner {
-  padding: 10px 16px 16px;
-}

+ 38 - 7
src/data/inherit-api.ts

@@ -125,6 +125,8 @@ export interface ContentDetail {
   date_birth?: string | null
   prize?: string | null
   association?: Record<string, unknown> | null
+  /** 携带登录令牌请求时表示当前用户是否已收藏,1 为已收藏。 */
+  is_collect?: number | string | null
 }
 
 export type ContentRelatedCollection = Record<string, unknown>[] | Record<string, Record<string, unknown>> | null
@@ -195,7 +197,19 @@ export interface InheritLists {
 
 export interface InheritResult {
   lists: InheritLists
-  totals: Record<HeritageKey, number>
+}
+
+interface ApiLevelCount {
+  total?: number | string
+}
+
+interface WebStatisticsData {
+  /** 非遗项目按级别统计 */
+  ich_data?: ApiLevelCount[]
+  /** 传承人按级别统计 */
+  inheritor_data?: ApiLevelCount[]
+  protection_center_total?: number | string
+  ich_center_total?: number | string
 }
 
 export interface InheritFilters {
@@ -205,12 +219,13 @@ export interface InheritFilters {
   districtId: string
 }
 
-function get<T>(path: string, data: RequestData): Promise<T> {
-  return request<T>(path, { data: { main_body_id: MAIN_BODY_ID, ...data } })
+function get<T>(path: string, data: RequestData, token = ''): Promise<T> {
+  return request<T>(path, { data: { main_body_id: MAIN_BODY_ID, ...data }, token })
 }
 
-export async function getContentDetail(id: string): Promise<ContentDetail> {
-  const data = await get<Partial<Omit<ContentDetail, 'model_id'>> & { model_id?: string | number | null }>('content/content/getContentDetail', { id })
+/** 传入登录令牌时,详情会带上当前用户的收藏状态。 */
+export async function getContentDetail(id: string, token = ''): Promise<ContentDetail> {
+  const data = await get<Partial<Omit<ContentDetail, 'model_id'>> & { model_id?: string | number | null }>('content/content/getContentDetail', { id }, token)
   if (!data || Array.isArray(data)) {
     throw new Error('文章不存在或已下架')
   }
@@ -482,13 +497,29 @@ export async function getInheritList(key: HeritageKey, filters: InheritFilters,
   }
 }
 
-export async function getInheritLists(filters: InheritFilters = { keyword: '', categoryId: '', levelId: '', districtId: '' }): Promise<InheritResult> {
+const NO_FILTERS: InheritFilters = { keyword: '', categoryId: '', levelId: '', districtId: '' }
+
+export async function getInheritLists(filters: InheritFilters = NO_FILTERS): Promise<InheritResult> {
   const contents = await Promise.all(HERITAGE_COLUMNS.map(column => getColumn(column, filters)))
   return {
     lists: Object.fromEntries(HERITAGE_COLUMNS.map((column, index) => [
       column.key,
       contents[index].items.map(item => normalizeInheritItem(item, column)),
     ])) as unknown as InheritLists,
-    totals: Object.fromEntries(HERITAGE_COLUMNS.map((column, index) => [column.key, contents[index].total])) as Record<HeritageKey, number>,
+  }
+}
+
+function sumTotals(items: ApiLevelCount[] = []) {
+  return items.reduce((sum, item) => sum + (Number(item.total) || 0), 0)
+}
+
+/** 传承页顶部统计,来自首页统计接口,不受页面筛选影响。 */
+export async function getInheritStats(): Promise<Record<HeritageKey, number>> {
+  const data = await request<WebStatisticsData>('volunteer/statistics/webData', { method: 'POST', data: { main_body_id: MAIN_BODY_ID } })
+  return {
+    projects: sumTotals(data.ich_data),
+    inheritors: sumTotals(data.inheritor_data),
+    units: Number(data.protection_center_total) || 0,
+    centers: Number(data.ich_center_total) || 0,
   }
 }

+ 37 - 0
src/data/user-api.ts

@@ -1,6 +1,8 @@
 import type { ApiResponse, RequestData } from '../utils/request'
+import type { ContentDetail } from './inherit-api'
 import { normalizeMediaUrl } from '../utils/media'
 import { API_BASE_URL, LoginRequiredError, MAIN_BODY_ID, request, unwrapResponse } from '../utils/request'
+import { getContentDetail } from './inherit-api'
 
 export { LoginRequiredError } from '../utils/request'
 
@@ -226,3 +228,38 @@ export async function getUserFavorites(page = 1, pageSize = 20) {
     hasMore: page * pageSize < Number(data.total),
   }
 }
+
+export function isContentFavorited(detail: Pick<ContentDetail, 'is_collect'>): boolean {
+  return Number(detail.is_collect) === 1
+}
+
+/** 已登录时携带令牌读取详情以获得收藏状态;令牌失效则清除会话并按游客身份重新读取。 */
+export async function getContentDetailForUser(id: string): Promise<ContentDetail> {
+  const session = getUserSession()
+  if (session) {
+    try {
+      return await getContentDetail(id, session.token)
+    }
+    catch (error) {
+      if (!(error instanceof LoginRequiredError)) {
+        throw error
+      }
+      clearSessionIfCurrent(session.token)
+    }
+  }
+  return getContentDetail(id)
+}
+
+/** 收藏与取消收藏是后台的两个独立接口。 */
+export async function setContentFavorite(contentId: string, favorite: boolean) {
+  const session = getUserSession()
+  if (!session) {
+    throw new LoginRequiredError()
+  }
+  if (favorite) {
+    await post<null>('collect', { main_body_id: MAIN_BODY_ID, content_id: contentId }, session.token)
+  }
+  else {
+    await post<null>('content/main_body_user/uncollect', { main_body_id: MAIN_BODY_ID, content_ids: contentId }, session.token)
+  }
+}

+ 1 - 1
src/pages/inherit/inherit.json

@@ -1,7 +1,7 @@
 {
   "navigationStyle": "custom",
   "usingComponents": {
-    "heritage-header": "/components/heritage-header/index",
+    "tab-header": "/components/tab-header/index",
     "heritage-card": "/components/heritage-card/index",
     "svg-icon": "weapp-svg-icon/index"
   }

+ 88 - 61
src/pages/inherit/inherit.ts

@@ -1,26 +1,62 @@
-import type { CategoryOption, InheritItem, InheritLists } from '../../data/inherit-api'
+import type { CategoryOption, HeritageKey, InheritFilters, InheritItem, InheritLists } from '../../data/inherit-api'
 import { getCultureListUrl } from '../../data/culture-content'
-import { getInheritCategories, getInheritLists, HERITAGE_COLUMNS } from '../../data/inherit-api'
+import { getInheritCategories, getInheritLists, getInheritStats, HERITAGE_COLUMNS } from '../../data/inherit-api'
 import { runRefresh } from '../../utils/refresh'
 import { syncTabBar } from '../../utils/tab-bar'
 
-interface TagOption extends CategoryOption {
-  active: boolean
+const ALL_OPTION: CategoryOption = { id: '', name: '全部', pid: '' }
+
+const FILTERS = [
+  { key: 'category', label: '非遗门类' },
+  { key: 'level', label: '保护级别' },
+  { key: 'district', label: '漳州各区县' },
+] as const
+
+type FilterKey = typeof FILTERS[number]['key']
+type FilterOptions = Record<FilterKey, CategoryOption[]>
+type FilterValues = Record<FilterKey, string>
+
+function createFilterValues(): FilterValues {
+  return { category: '', level: '', district: '' }
 }
 
-const ALL_OPTION: CategoryOption = { id: '', name: '全部', pid: '' }
+function createFilterOptions(): FilterOptions {
+  return { category: [ALL_OPTION], level: [ALL_OPTION], district: [ALL_OPTION] }
+}
+
+// 筛选条由选项和当前选中 id 推导,picker 需要名称数组和下标。
+function buildFilterBar(options: FilterOptions, values: FilterValues) {
+  return FILTERS.map((filter) => {
+    const list = options[filter.key]
+    const index = Math.max(0, list.findIndex(option => option.id === values[filter.key]))
+    return { key: filter.key, label: filter.label, names: list.map(option => option.name), index, value: index ? list[index].name : '' }
+  })
+}
+
+function buildStats(stats?: Record<HeritageKey, number>) {
+  return HERITAGE_COLUMNS.map(column => ({
+    key: column.key,
+    label: column.label,
+    icon: column.icon,
+    unit: column.unit,
+    value: stats ? String(stats[column.key]) : '—',
+  }))
+}
+
+function toInheritFilters(keyword: string, values: FilterValues): InheritFilters {
+  return { keyword, categoryId: values.category, levelId: values.level, districtId: values.district }
+}
 
 Component({
   data: {
     refreshing: false,
     keyword: '',
-    stats: HERITAGE_COLUMNS.map(column => ({ label: column.label, value: '—', unit: column.unit })),
-    categories: [ALL_OPTION] as CategoryOption[],
-    selectedCategory: '',
-    levels: [{ ...ALL_OPTION, active: true }] as TagOption[],
-    districts: [ALL_OPTION] as CategoryOption[],
+    stats: buildStats(),
+    filterOptions: createFilterOptions(),
+    filterValues: createFilterValues(),
+    filterBar: buildFilterBar(createFilterOptions(), createFilterValues()),
+    hasFilter: false,
     optionsLoaded: false,
-    selectedDistrict: '',
     projects: [] as InheritItem[],
     inheritors: [] as InheritItem[],
     units: [] as InheritItem[],
@@ -34,6 +70,7 @@ Component({
   lifetimes: {
     attached() {
       this.loadData()
+      this.loadStats().catch(() => {})
     },
     detached() {
       this.data.requestVersion++
@@ -49,7 +86,7 @@ Component({
   methods: {
     async onPullRefresh() {
       this.setData({ refreshing: true })
-      await runRefresh([this.loadData(true)])
+      await runRefresh([this.loadData(true), this.loadStats()])
       this.setData({ refreshing: false })
     },
 
@@ -57,17 +94,17 @@ Component({
       return this.loadData()
     },
 
+    // 顶部统计不随筛选变化,只在进入页面和下拉刷新时请求;失败时保留原数字。
+    async loadStats() {
+      const stats = await getInheritStats()
+      this.setData({ stats: buildStats(stats) })
+    },
+
     // refresh 为下拉刷新:同时重新拉取筛选项,不切换到加载态,已有内容时失败保留原内容。
     async loadData(refresh = false) {
       const requestVersion = ++this.data.requestVersion
-      const { keyword, selectedCategory, selectedDistrict, levels, optionsLoaded } = this.data
-      const filters = {
-        keyword,
-        categoryId: selectedCategory,
-        levelId: levels.find(level => level.active)?.id || '',
-        districtId: selectedDistrict,
-      }
-      const unfiltered = !filters.keyword.trim() && !filters.categoryId && !filters.levelId && !filters.districtId
+      const { keyword, filterValues, optionsLoaded } = this.data
+      const filters = toInheritFilters(keyword, filterValues)
       if (!refresh) {
         this.setData({ loading: true, loadError: '' })
       }
@@ -81,22 +118,17 @@ Component({
           return
         }
         if (options) {
+          const filterOptions: FilterOptions = {
+            category: [ALL_OPTION, ...options.categories],
+            level: [ALL_OPTION, ...options.levels],
+            district: [ALL_OPTION, ...options.districts],
+          }
           this.setData({
-            categories: [ALL_OPTION, ...options.categories],
-            districts: [ALL_OPTION, ...options.districts],
-            levels: [
-              { ...ALL_OPTION, active: !filters.levelId },
-              ...options.levels.map(item => ({ ...item, active: filters.levelId === item.id })),
-            ],
+            filterOptions,
+            filterBar: buildFilterBar(filterOptions, this.data.filterValues),
             optionsLoaded: true,
           })
         }
-        // 顶部统计展示全部数据的总数,只用不带筛选条件的结果更新。
-        if (unfiltered) {
-          this.setData({
-            stats: HERITAGE_COLUMNS.map(column => ({ label: column.label, value: String(result.totals[column.key]), unit: column.unit })),
-          })
-        }
         this.setData({ loading: false, loadError: '' })
         this.refresh(result.lists)
       }
@@ -124,39 +156,40 @@ Component({
       return this.loadData()
     },
 
-    onSelectCategory(e: WechatMiniprogram.TouchEvent) {
-      const id = e.currentTarget.dataset.id as string
-      if (this.data.selectedCategory === id) {
-        return
-      }
-      this.setData({ selectedCategory: id })
-      return this.loadData()
+    setFilterValues(filterValues: FilterValues) {
+      this.setData({
+        filterValues,
+        filterBar: buildFilterBar(this.data.filterOptions, filterValues),
+        hasFilter: FILTERS.some(filter => filterValues[filter.key]),
+      })
     },
 
-    onSelectLevel(e: WechatMiniprogram.TouchEvent) {
-      const id = e.currentTarget.dataset.id as string
-      const option = this.data.levels.find(level => level.id === id)
-      if (!option || option.active) {
+    onFilterChange(e: WechatMiniprogram.PickerChange) {
+      const key = e.currentTarget.dataset.key as FilterKey
+      const option = this.data.filterOptions[key]?.[Number(e.detail.value)]
+      if (!option || this.data.filterValues[key] === option.id) {
         return
       }
-      const levels = this.data.levels.map(level => ({ ...level, active: level.id === id }))
-      this.setData({ levels })
+      this.setFilterValues({ ...this.data.filterValues, [key]: option.id })
       return this.loadData()
     },
 
-    onSelectDistrict(e: WechatMiniprogram.TouchEvent) {
-      this.setData({ selectedDistrict: e.currentTarget.dataset.id as string })
+    onResetFilters() {
+      this.setFilterValues(createFilterValues())
       return this.loadData()
     },
 
     onReset() {
-      this.setData({
-        keyword: '',
-        selectedCategory: '',
-        levels: this.data.levels.map(level => ({ ...level, active: !level.id })),
-        selectedDistrict: '',
-      })
-      return this.loadData()
+      this.setData({ keyword: '' })
+      return this.onResetFilters()
+    },
+
+    // 统计数字是全部数据的总数,进入列表时不带筛选,保证数量一致。
+    onStatTap(e: WechatMiniprogram.TouchEvent) {
+      const column = HERITAGE_COLUMNS.find(column => column.key === e.currentTarget.dataset.category)
+      if (column) {
+        wx.navigateTo({ url: getCultureListUrl(column.key) })
+      }
     },
 
     onMore(e: WechatMiniprogram.TouchEvent) {
@@ -164,14 +197,8 @@ Component({
       if (!column) {
         return
       }
-      const { keyword, selectedCategory, selectedDistrict, levels } = this.data
-      const filters = { keyword, categoryId: selectedCategory, levelId: levels.find(level => level.active)?.id || '', districtId: selectedDistrict }
       // 沿用当前筛选,让“更多”展示当前栏目对应的完整结果。
-      wx.navigateTo({ url: getCultureListUrl(column.key, filters) })
-    },
-
-    onBack() {
-      wx.switchTab({ url: '/pages/home/home' })
+      wx.navigateTo({ url: getCultureListUrl(column.key, toInheritFilters(this.data.keyword, this.data.filterValues)) })
     },
   },
 })

+ 35 - 53
src/pages/inherit/inherit.wxml

@@ -1,68 +1,50 @@
 <view class="h-screen flex flex-col bg-[#f8efe2]">
-  <heritage-header value="{{keyword}}" bind:search="onSearch" bind:back="onBack" />
+  <tab-header title="传承" show-search value="{{keyword}}" placeholder="搜非遗名称、传承人、技艺、区县" bind:search="onSearch" />
 
   <scroll-view class="flex-1 min-h-0" scroll-y refresher-enabled="{{true}}" refresher-triggered="{{refreshing}}" bindrefresherrefresh="onPullRefresh">
     <view class="inherit-stats">
-      <view wx:for="{{stats}}" wx:key="label" class="inherit-stat">
+      <view
+        wx:for="{{stats}}"
+        wx:key="key"
+        class="inherit-stat"
+        hover-class="inherit-stat--pressed"
+        data-category="{{item.key}}"
+        bindtap="onStatTap"
+        aria-role="button"
+        aria-label="{{item.label}}{{item.value}}{{item.unit}},查看全部"
+      >
+        <view class="inherit-stat__icon">
+          <svg-icon name="{{item.icon}}" size="44px" color="#c9a46e" />
+        </view>
         <view class="inherit-stat__amount">
           <text class="inherit-stat__value">{{item.value}}</text>
           <text class="inherit-stat__unit">{{item.unit}}</text>
         </view>
-        <text class="inherit-stat__label">{{item.label}}</text>
-      </view>
-    </view>
-
-    <view class="bg-[#fffaf1] border-b border-[#eadcc5] px-4 pt-3 pb-2">
-      <view class="flex items-center justify-between">
-        <text class="text-sm font-bold text-[#983726]">非遗门类</text>
-      </view>
-      <scroll-view class="hide-scroll mt-2" scroll-x>
-        <view class="inline-flex gap-2 whitespace-nowrap pb-1">
-          <view
-            wx:for="{{categories}}"
-            wx:key="id"
-            class="rounded-full border px-3 py-1.5 text-sm {{selectedCategory === item.id ? 'bg-[#a83f2d] border-[#a83f2d] text-white' : 'bg-white border-[#e6d4bd] text-[#806d5c]'}}"
-            data-id="{{item.id}}"
-            bindtap="onSelectCategory"
-          >
-            {{item.name}}
-          </view>
-        </view>
-      </scroll-view>
-    </view>
-
-    <view class="bg-[#fffaf1] border-b border-[#eadcc5] px-4 py-3">
-      <view class="flex items-center justify-between">
-        <text class="text-sm font-bold text-[#983726]">保护级别</text>
-      </view>
-      <view class="mt-2 flex flex-wrap gap-2 text-sm">
-        <view
-          wx:for="{{levels}}"
-          wx:key="id"
-          class="rounded-full border px-3 py-1.5 {{item.active ? 'bg-[#a83f2d] border-[#a83f2d] text-white' : 'bg-white border-[#e6d4bd] text-[#806d5c]'}}"
-          data-id="{{item.id}}"
-          bindtap="onSelectLevel"
-        >
-          {{item.name}}
+        <view class="inherit-stat__footer">
+          <text class="inherit-stat__label">{{item.label}}</text>
+          <svg-icon name="ph:caret-right-bold" size="12px" color="#b59577" />
         </view>
       </view>
+    </view>
 
-      <view class="mt-3 flex items-center justify-between">
-        <text class="text-sm font-bold text-[#6c5145]">漳州各区县</text>
-      </view>
-      <scroll-view class="hide-scroll mt-2" scroll-x>
-        <view class="inline-flex gap-2 whitespace-nowrap pb-1">
-          <view
-            wx:for="{{districts}}"
-            wx:key="id"
-            class="rounded-full border px-3 py-1.5 text-sm {{selectedDistrict === item.id ? 'bg-[#a83f2d] border-[#a83f2d] text-white' : 'bg-white border-[#e6d4bd] text-[#806d5c]'}}"
-            data-id="{{item.id}}"
-            bindtap="onSelectDistrict"
-          >
-            {{item.name}}
-          </view>
+    <view class="inherit-filter">
+      <picker
+        wx:for="{{filterBar}}"
+        wx:key="key"
+        class="inherit-filter__item"
+        mode="selector"
+        range="{{item.names}}"
+        value="{{item.index}}"
+        data-key="{{item.key}}"
+        bindchange="onFilterChange"
+        aria-label="{{item.label}}筛选,{{item.value || '全部'}}"
+      >
+        <view class="inherit-filter__trigger {{item.value ? 'inherit-filter__trigger--selected' : ''}}">
+          <text class="inherit-filter__label">{{item.value || item.label}}</text>
+          <view class="inherit-filter__arrow" />
         </view>
-      </scroll-view>
+      </picker>
+      <view wx:if="{{hasFilter}}" class="inherit-filter__reset" bindtap="onResetFilters" aria-role="button" aria-label="重置筛选">重置</view>
     </view>
 
     <view wx:if="{{loading}}" class="px-4 py-12 text-center text-sm text-[#806d5c]">正在加载非遗内容…</view>

+ 101 - 40
src/pages/inherit/inherit.wxss

@@ -1,74 +1,135 @@
 .inherit-stats {
-  display: flex;
-  flex-wrap: wrap;
-  row-gap: 28rpx;
-  padding: 32rpx 20rpx 24rpx;
-  background: #fffaf1;
-  border-bottom: 1rpx solid #eadcc5;
+  display: grid;
+  grid-template-columns: repeat(2, minmax(0, 1fr));
+  gap: 10px;
+  padding: 14px 16px;
 }
 
 .inherit-stat {
   position: relative;
-  box-sizing: border-box;
-  display: flex;
-  flex: 0 0 50%;
-  flex-direction: column;
-  align-items: center;
-  min-width: 0;
-  padding: 0 10rpx;
-  text-align: center;
+  overflow: hidden;
+  padding: 12px 14px 10px;
+  background: linear-gradient(150deg, #fffdf8 0%, #faefdc 100%);
+  border: 1px solid #ecdcc3;
+  border-radius: 12px;
+  box-shadow: 0 2px 6px rgb(152 55 38 / 6%);
 }
 
-.inherit-stat:nth-child(even)::before {
-  position: absolute;
-  top: 12rpx;
-  left: 0;
-  width: 1rpx;
-  height: 64rpx;
-  content: "";
-  background: #e8d8c2;
+.inherit-stat--pressed {
+  background: #f6e7d0;
 }
 
-.inherit-stat:nth-child(n + 3)::after {
+/* 栏目图标作为右上角的淡色水印,不占文字空间。 */
+.inherit-stat__icon {
   position: absolute;
-  top: -14rpx;
-  right: 0;
-  left: 0;
-  height: 1rpx;
-  content: "";
-  background: #e8d8c2;
+  top: 6px;
+  right: 6px;
+  opacity: 0.5;
 }
 
 .inherit-stat__amount {
+  position: relative;
   display: flex;
   align-items: baseline;
-  justify-content: center;
   white-space: nowrap;
 }
 
 .inherit-stat__value {
-  font-size: 46rpx;
-  font-weight: 600;
+  font-size: 30px;
+  font-weight: 700;
   font-variant-numeric: tabular-nums;
-  line-height: 1.1;
+  line-height: 1.15;
   color: #873324;
 }
 
 .inherit-stat__unit {
-  margin-left: 4rpx;
-  font-size: 20rpx;
+  margin-left: 3px;
+  font-size: 13px;
   color: #a18b78;
 }
 
+.inherit-stat__footer {
+  position: relative;
+  display: flex;
+  gap: 2px;
+  align-items: center;
+  margin-top: 6px;
+}
+
 .inherit-stat__label {
-  display: block;
-  margin-top: 12rpx;
-  font-size: 24rpx;
-  line-height: 32rpx;
-  color: #8d7768;
+  min-width: 0;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  font-size: 14px;
+  line-height: 20px;
+  color: #6c5145;
+  white-space: nowrap;
+}
+
+/* 三个筛选合并为单行下拉,滚动时吸顶。 */
+.inherit-filter {
+  position: sticky;
+  top: 0;
+  z-index: 5;
+  display: flex;
+  align-items: center;
+  height: 46px;
+  background: #fffaf1;
+  border-top: 1px solid #eadcc5;
+  border-bottom: 1px solid #eadcc5;
+  box-shadow: 0 2px 6px rgb(127 42 32 / 5%);
+}
+
+.inherit-filter__item {
+  flex: 1;
+  min-width: 0;
+}
+
+.inherit-filter__item + .inherit-filter__item {
+  border-left: 1px solid #eadcc5;
+}
+
+.inherit-filter__trigger {
+  display: flex;
+  gap: 8px;
+  align-items: center;
+  justify-content: center;
+  height: 28px;
+  padding: 0 10px;
+  font-size: 14px;
+  color: #6c5145;
+}
+
+.inherit-filter__trigger--selected {
+  font-weight: 600;
+  color: #a83f2d;
+}
+
+.inherit-filter__label {
+  overflow: hidden;
+  text-overflow: ellipsis;
   white-space: nowrap;
 }
 
+.inherit-filter__arrow {
+  flex: none;
+  width: 5px;
+  height: 5px;
+  margin-top: -3px;
+  border-right: 1.5px solid currentcolor;
+  border-bottom: 1.5px solid currentcolor;
+  transform: rotate(45deg);
+}
+
+.inherit-filter__reset {
+  flex: none;
+  padding: 0 14px;
+  font-size: 14px;
+  line-height: 28px;
+  color: #a83f2d;
+  border-left: 1px solid #eadcc5;
+}
+
 .hide-scroll {
   scrollbar-width: none;
 }

+ 1 - 1
src/pages/news/news.json

@@ -1,7 +1,7 @@
 {
   "navigationStyle": "custom",
   "usingComponents": {
-    "news-header": "/components/news-header/index",
+    "tab-header": "/components/tab-header/index",
     "svg-icon": "weapp-svg-icon/index"
   }
 }

+ 1 - 1
src/pages/news/news.wxml

@@ -1,5 +1,5 @@
 <view class="h-screen flex flex-col paper">
-  <news-header show-actions="{{showHeaderActions}}" value="{{keyword}}" bind:search="onSearch" />
+  <tab-header title="资讯" show-search="{{showHeaderActions}}" value="{{keyword}}" placeholder="试试“古厝日落”或“亲子研学”" bind:search="onSearch" />
 
   <scroll-view class="flex-1 min-h-0" scroll-y scroll-top="{{scrollTop}}" bindscroll="onListScroll" bindscrolltolower="loadMoreNews" show-scrollbar="{{false}}" refresher-enabled="{{true}}" refresher-triggered="{{refreshing}}" bindrefresherrefresh="onPullRefresh">
     <view class="news-content">

+ 1 - 1
src/pages/travel/travel.json

@@ -1,7 +1,7 @@
 {
   "navigationStyle": "custom",
   "usingComponents": {
-    "travel-header": "/components/travel-header/index",
+    "tab-header": "/components/tab-header/index",
     "recommend-card": "/components/recommend-card/index",
     "section-header": "/components/section-header/index",
     "van-toast": "@vant/weapp/toast/index"

+ 1 - 1
src/pages/travel/travel.wxml

@@ -1,5 +1,5 @@
 <view class="h-screen flex flex-col bg-[#f9f3e7]">
-  <travel-header />
+  <tab-header title="趣游漳州" />
 
   <scroll-view class="flex-1 min-h-0" scroll-y refresher-enabled="{{true}}" refresher-triggered="{{refreshing}}" bindrefresherrefresh="onPullRefresh">
     <view class="pb-5">

+ 1 - 0
src/subpackages/content/article-detail/article-detail.json

@@ -5,6 +5,7 @@
   "backgroundColor": "#f9f3e7",
   "disableScroll": true,
   "usingComponents": {
+    "nav-bar": "/components/nav-bar/index",
     "svg-icon": "weapp-svg-icon/index"
   }
 }

+ 28 - 35
src/subpackages/content/article-detail/article-detail.scss

@@ -3,39 +3,7 @@
   flex-direction: column;
   height: 100vh;
   color: #302a23;
-  background: #f7f3e8;
-}
-
-.article-header {
-  flex: none;
-  background: #f7f3e8;
-}
-
-.article-nav {
-  position: relative;
-  display: flex;
-  align-items: center;
-  padding: 0 16px;
-}
-
-.article-back {
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  width: 32px;
-  height: 36px;
-}
-
-.article-nav__title {
-  position: absolute;
-  left: 50%;
-  overflow: hidden;
-  text-overflow: ellipsis;
-  font-size: 17px;
-  font-weight: 500;
-  text-align: center;
-  white-space: nowrap;
-  transform: translateX(-50%);
+  background: #f9f3e7;
 }
 
 .article-scroll {
@@ -126,6 +94,31 @@
   color: #9c9286;
 }
 
+.article-favorite {
+  display: flex;
+  flex: none;
+  gap: 4px;
+  align-items: center;
+  height: 32px;
+  padding: 0 14px;
+  margin-left: auto;
+  font-size: 13px;
+  color: #753c2b;
+  background: #fffdf7;
+  border: 1px solid #eadcc5;
+  border-radius: 16px;
+}
+
+.article-favorite--active {
+  color: #d66546;
+  background: #fbe6de;
+  border-color: #f0c6b8;
+}
+
+.article-favorite--pressed {
+  opacity: 0.7;
+}
+
 .article-facts {
   margin-top: 26px;
 }
@@ -214,7 +207,7 @@
   z-index: 2;
   padding: 0;
   margin-top: 0;
-  background: #f7f3e8;
+  background: #f9f3e7;
 }
 
 .article-tabs {
@@ -307,7 +300,7 @@
 
 .article-audio {
   padding: 14px 10px;
-  background: #f7f3e8;
+  background: #f9f3e7;
   border-radius: 10px;
 }
 

+ 56 - 13
src/subpackages/content/article-detail/article-detail.ts

@@ -3,9 +3,8 @@ import type { ArticleProfile } from '../../../data/article-profile'
 import type { ContentDetail } from '../../../data/inherit-api'
 import { createArticlePresentation, prepareArticleContent } from '../../../data/article-content'
 import { createArticleProfile } from '../../../data/article-profile'
-import { getContentDetail } from '../../../data/inherit-api'
+import { getContentDetailForUser, getUserSession, isContentFavorited, LoginRequiredError, loginWithWeChat, setContentFavorite } from '../../../data/user-api'
 import { normalizeMediaUrl } from '../../../utils/media'
-import { getNavBarLayout } from '../../../utils/nav-bar'
 import { getArticleDetailUrl } from '../../../utils/routes'
 
 Page({
@@ -20,15 +19,13 @@ Page({
     pageTitle: '文章详情',
     loading: true,
     loadError: '',
-    statusBarHeight: 20,
-    navHeight: 44,
-    navTitleWidth: 160,
     requestVersion: 0,
+    favorited: false,
+    favoriteSaving: false,
   },
 
   onLoad(options) {
-    const { statusBarHeight, navHeight, navTitleWidth } = getNavBarLayout()
-    this.setData({ id: options.id || '', statusBarHeight, navHeight, navTitleWidth })
+    this.setData({ id: options.id || '' })
     return this.loadDetail()
   },
 
@@ -40,7 +37,7 @@ Page({
     const requestVersion = ++this.data.requestVersion
     this.setData({ loading: true, loadError: '', detail: null, presentation: null, profile: null, activeTab: '', activeRelatedGroup: null })
     try {
-      const detail = await getContentDetail(this.data.id)
+      const detail = await getContentDetailForUser(this.data.id)
       if (requestVersion !== this.data.requestVersion) {
         return
       }
@@ -55,6 +52,7 @@ Page({
         activeRelatedGroup: presentation.relatedGroups.find(group => group.key === activeTab) || null,
         tabScrollTarget: activeTab ? `detail-tab-${activeTab}` : '',
         pageTitle: presentation.pageTitle,
+        favorited: isContentFavorited(detail),
         detail: {
           ...detail,
           image: normalizeMediaUrl(detail.image),
@@ -144,12 +142,57 @@ Page({
     return this.loadDetail()
   },
 
-  onBack() {
-    if (getCurrentPages().length > 1) {
-      wx.navigateBack()
+  async onToggleFavorite() {
+    if (this.data.favoriteSaving || !this.data.detail) {
+      return
+    }
+    const id = this.data.id
+    this.setData({ favoriteSaving: true })
+    try {
+      if (!getUserSession()) {
+        if (!await this.confirmLogin()) {
+          return
+        }
+        // 游客身份加载的详情没有收藏状态,登录后先确认是否已收藏,避免重复收藏。
+        if (isContentFavorited(await getContentDetailForUser(id))) {
+          this.setData({ favorited: true })
+          wx.showToast({ title: '已在收藏中', icon: 'none' })
+          return
+        }
+      }
+      const favorite = !this.data.favorited
+      await setContentFavorite(id, favorite)
+      this.setData({ favorited: favorite })
+      wx.showToast({ title: favorite ? '收藏成功' : '已取消收藏', icon: favorite ? 'success' : 'none' })
+    }
+    catch (error) {
+      const message = error instanceof LoginRequiredError
+        ? '登录已失效,请重新登录'
+        : error instanceof Error ? error.message : '操作失败,请稍后重试'
+      wx.showToast({ title: message, icon: 'none' })
+    }
+    finally {
+      this.setData({ favoriteSaving: false })
+    }
+  },
+
+  async confirmLogin() {
+    const { confirm } = await wx.showModal({
+      title: '微信登录',
+      content: '登录后即可收藏文章,并在「我的收藏」中查看。是否使用微信账号登录?',
+      confirmText: '登录',
+      cancelText: '暂不登录',
+    })
+    if (!confirm) {
+      return false
+    }
+    wx.showLoading({ title: '登录中', mask: true })
+    try {
+      await loginWithWeChat()
+      return true
     }
-    else {
-      wx.switchTab({ url: '/pages/home/home' })
+    finally {
+      wx.hideLoading()
     }
   },
 })

+ 9 - 10
src/subpackages/content/article-detail/article-detail.wxml

@@ -1,12 +1,5 @@
 <view class="article-page">
-  <view class="article-header" style="padding-top: {{statusBarHeight}}px;">
-    <view class="article-nav" style="height: {{navHeight}}px;">
-      <view class="article-back" aria-role="button" aria-label="返回" bindtap="onBack">
-        <svg-icon name="ph:caret-left-bold" size="20px" color="#302a23" />
-      </view>
-      <text class="article-nav__title" style="width: {{navTitleWidth}}px;">{{detail.title || pageTitle}}</text>
-    </view>
-  </view>
+  <nav-bar title="{{detail.title || pageTitle}}" />
 
   <scroll-view class="article-scroll" scroll-y show-scrollbar="{{false}}">
     <view wx:if="{{loading}}" class="article-status">正在加载…</view>
@@ -22,14 +15,20 @@
         </view>
       </view>
 
-      <view wx:if="{{detail.title || detail.flag_text || detail.publish_at || profile.facts.length || presentation.otherLevels.length}}" class="article-summary">
+      <view class="article-summary">
         <view wx:if="{{detail.title || profile.levelBadge}}" class="article-title-row">
           <text wx:if="{{detail.title}}" class="article-title" user-select>{{detail.title}}</text>
           <text wx:if="{{profile.levelBadge}}" class="article-level-card__badge">{{profile.levelBadge}}</text>
         </view>
-        <view wx:if="{{detail.flag_text || detail.publish_at}}" class="article-meta">
+        <view class="article-meta">
           <text wx:if="{{detail.flag_text}}" class="article-tag">{{detail.flag_text}}</text>
           <text wx:if="{{detail.publish_at}}" class="article-date">{{detail.publish_at}}</text>
+          <view class="article-favorite {{favorited ? 'article-favorite--active' : ''}}" hover-class="article-favorite--pressed" bindtap="onToggleFavorite" aria-role="button" aria-label="{{favorited ? '已收藏,点击取消收藏' : '收藏'}}">
+            <!-- weapp-svg-icon 只在 attached 时解析 name,切换图标需重新挂载组件。 -->
+            <svg-icon wx:if="{{favorited}}" name="ph:heart-fill" size="16px" color="#d66546" />
+            <svg-icon wx:else name="ph:heart" size="16px" color="#753c2b" />
+            <text>{{favorited ? '已收藏' : '收藏'}}</text>
+          </view>
         </view>
         <view wx:if="{{profile.facts.length}}" class="article-facts">
           <view wx:for="{{profile.facts}}" wx:key="label" class="article-fact">

+ 1 - 0
src/subpackages/content/culture-list/culture-list.json

@@ -5,6 +5,7 @@
   "backgroundColor": "#f9f3e7",
   "disableScroll": true,
   "usingComponents": {
+    "nav-bar": "/components/nav-bar/index",
     "svg-icon": "weapp-svg-icon/index"
   }
 }

+ 0 - 34
src/subpackages/content/culture-list/culture-list.scss

@@ -6,40 +6,6 @@
   background: #f9f3e7;
 }
 
-.culture-header {
-  flex: none;
-  background: #f9f3e7;
-  border-bottom: 1px solid #eadcc5;
-}
-
-.culture-nav {
-  display: flex;
-  gap: 10px;
-  align-items: center;
-  padding-left: 16px;
-}
-
-.culture-back {
-  display: flex;
-  flex: none;
-  align-items: center;
-  justify-content: center;
-  width: 36px;
-  height: 36px;
-  background: rgb(255 255 255 / 70%);
-  border: 1px solid #eadcc5;
-  border-radius: 50%;
-}
-
-.culture-nav__title {
-  overflow: hidden;
-  text-overflow: ellipsis;
-  font-size: 15px;
-  font-weight: 600;
-  color: #753c2b;
-  white-space: nowrap;
-}
-
 .culture-search {
   display: flex;
   gap: 9px;

+ 0 - 17
src/subpackages/content/culture-list/culture-list.ts

@@ -1,7 +1,6 @@
 import type { CultureCategoryKey, CultureItem } from '../../../data/culture-content'
 import { createCultureFilterOptions, createCultureFilters, findCultureCategory, getCultureList } from '../../../data/culture-content'
 import { getInheritCategories } from '../../../data/inherit-api'
-import { getNavBarLayout } from '../../../utils/nav-bar'
 import { runRefresh } from '../../../utils/refresh'
 import { getArticleDetailUrl } from '../../../utils/routes'
 
@@ -20,9 +19,6 @@ Page({
     filters: createCultureFilters(),
     filterOptions: createCultureFilterOptions(),
     failedImages: {} as Record<string, boolean>,
-    statusBarHeight: 20,
-    navHeight: 44,
-    navRightPadding: 100,
     scrollTop: 0,
     remoteCategory: '' as CultureCategoryKey | '',
     optionsLoaded: false,
@@ -36,13 +32,9 @@ Page({
   },
 
   onLoad(options) {
-    const { statusBarHeight, navHeight, navRightPadding } = getNavBarLayout()
     const category = findCultureCategory(options.category)
     const remoteCategory = category.key
     this.setData({
-      statusBarHeight,
-      navHeight,
-      navRightPadding,
       activeCategory: category.key,
       title: category.title,
       categoryIcon: category.icon,
@@ -208,13 +200,4 @@ Page({
     // 保存实际滚动位置,搜索时设为 0 才能触发滚动复位。
     this.data.scrollTop = e.detail.scrollTop
   },
-
-  onBack() {
-    if (getCurrentPages().length > 1) {
-      wx.navigateBack()
-    }
-    else {
-      wx.switchTab({ url: '/pages/home/home' })
-    }
-  },
 })

+ 2 - 8
src/subpackages/content/culture-list/culture-list.wxml

@@ -1,11 +1,5 @@
 <view class="culture-page">
-  <view class="culture-header" style="padding-top: {{statusBarHeight}}px;">
-    <view class="culture-nav" style="height: {{navHeight}}px; padding-right: {{navRightPadding}}px;">
-      <view class="culture-back" aria-role="button" aria-label="返回首页" bindtap="onBack">
-        <svg-icon name="ph:caret-left-bold" size="18px" color="#753c2b" />
-      </view>
-      <text class="culture-nav__title">{{title}}</text>
-    </view>
+  <nav-bar title="{{title}}">
     <view class="culture-search">
       <svg-icon name="ph:magnifying-glass" size="18px" color="#9c8470" />
       <input
@@ -39,7 +33,7 @@
         </view>
       </picker>
     </view>
-  </view>
+  </nav-bar>
 
   <scroll-view class="culture-scroll" scroll-y scroll-top="{{scrollTop}}" bindscroll="onListScroll" bindscrolltolower="onLoadMore" show-scrollbar="{{false}}" refresher-enabled="{{true}}" refresher-triggered="{{refreshing}}" bindrefresherrefresh="onPullRefresh">
     <view class="culture-content">

+ 6 - 5
src/subpackages/content/favorites/favorites.json

@@ -1,9 +1,10 @@
 {
   "$schema": "https://vite.weapp.dev/page.json",
+  "navigationStyle": "custom",
   "navigationBarTitleText": "我的收藏",
-  "navigationBarBackgroundColor": "#faf3e5",
-  "backgroundColor": "#faf3e5",
-  "backgroundTextStyle": "dark",
-  "enablePullDownRefresh": true,
-  "usingComponents": {}
+  "backgroundColor": "#f9f3e7",
+  "disableScroll": true,
+  "usingComponents": {
+    "nav-bar": "/components/nav-bar/index"
+  }
 }

+ 12 - 4
src/subpackages/content/favorites/favorites.scss

@@ -1,9 +1,17 @@
-page {
-  background: #faf3e5;
+.favorites-page {
+  display: flex;
+  flex-direction: column;
+  height: 100vh;
+  background: #f9f3e7;
 }
 
-.favorites-page {
-  padding: 16px;
+.favorites-scroll {
+  flex: 1;
+  min-height: 0;
+}
+
+.favorites-content {
+  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
 }
 
 .favorite-card {

+ 5 - 3
src/subpackages/content/favorites/favorites.ts

@@ -5,6 +5,7 @@ import { getArticleDetailUrl } from '../../../utils/routes'
 
 Page({
   data: {
+    refreshing: false,
     items: [] as FavoriteItem[],
     page: 0,
     loading: false,
@@ -25,9 +26,10 @@ Page({
     this.data.requestVersion++
   },
 
-  async onPullDownRefresh() {
+  async onPullRefresh() {
+    this.setData({ refreshing: true })
     await runRefresh([this.loadFavorites(true)])
-    wx.stopPullDownRefresh()
+    this.setData({ refreshing: false })
   },
 
   // refresh 为下拉刷新:重新加载第一页并替换列表,已有内容时失败只提示不清空。
@@ -73,7 +75,7 @@ Page({
     }
   },
 
-  onReachBottom() {
+  onLoadMore() {
     if (!this.data.loadError) {
       return this.loadFavorites()
     }

+ 20 - 14
src/subpackages/content/favorites/favorites.wxml

@@ -1,17 +1,23 @@
 <view class="favorites-page">
-  <view wx:for="{{items}}" wx:key="id" class="favorite-card" data-id="{{item.id}}" bindtap="onItemTap" aria-role="button" aria-label="查看{{item.title}}详情">
-    <image wx:if="{{item.image && !failedImages[item.id]}}" class="favorite-card__image" src="{{item.image}}" mode="aspectFill" lazy-load data-id="{{item.id}}" binderror="onImageError" />
-    <view class="favorite-card__body">
-      <text class="favorite-card__title">{{item.title}}</text>
-      <text wx:if="{{item.category}}" class="favorite-card__category">{{item.category}}</text>
+  <nav-bar title="我的收藏" fallback-url="/pages/user/user" />
+
+  <scroll-view class="favorites-scroll" scroll-y bindscrolltolower="onLoadMore" refresher-enabled="{{true}}" refresher-triggered="{{refreshing}}" bindrefresherrefresh="onPullRefresh">
+    <view class="favorites-content">
+      <view wx:for="{{items}}" wx:key="id" class="favorite-card" data-id="{{item.id}}" bindtap="onItemTap" aria-role="button" aria-label="查看{{item.title}}详情">
+        <image wx:if="{{item.image && !failedImages[item.id]}}" class="favorite-card__image" src="{{item.image}}" mode="aspectFill" lazy-load data-id="{{item.id}}" binderror="onImageError" />
+        <view class="favorite-card__body">
+          <text class="favorite-card__title">{{item.title}}</text>
+          <text wx:if="{{item.category}}" class="favorite-card__category">{{item.category}}</text>
+        </view>
+      </view>
+      <view wx:if="{{loading}}" class="favorites-status">正在加载收藏…</view>
+      <view wx:elif="{{loadError}}" class="favorites-status">
+        <text>{{loadError}}</text>
+        <button wx:if="{{loginRequired}}" class="favorites-action" bindtap="onLogin">前往登录</button>
+        <button wx:else class="favorites-action" bindtap="onRetry">重试</button>
+      </view>
+      <view wx:elif="{{!items.length}}" class="favorites-status">暂无收藏</view>
+      <view wx:else class="favorites-status" bindtap="onRetry">{{hasMore ? '点击加载更多' : '已展示全部收藏'}}</view>
     </view>
-  </view>
-  <view wx:if="{{loading}}" class="favorites-status">正在加载收藏…</view>
-  <view wx:elif="{{loadError}}" class="favorites-status">
-    <text>{{loadError}}</text>
-    <button wx:if="{{loginRequired}}" class="favorites-action" bindtap="onLogin">前往登录</button>
-    <button wx:else class="favorites-action" bindtap="onRetry">重试</button>
-  </view>
-  <view wx:elif="{{!items.length}}" class="favorites-status">暂无收藏</view>
-  <view wx:else class="favorites-status" bindtap="onRetry">{{hasMore ? '点击加载更多' : '已展示全部收藏'}}</view>
+  </scroll-view>
 </view>

+ 3 - 1
src/subpackages/content/village-list/village-list.json

@@ -2,7 +2,9 @@
   "$schema": "https://vite.weapp.dev/page.json",
   "navigationStyle": "custom",
   "navigationBarTitleText": "特色村镇/街区",
+  "backgroundColor": "#f9f3e7",
+  "disableScroll": true,
   "usingComponents": {
-    "svg-icon": "weapp-svg-icon/index"
+    "nav-bar": "/components/nav-bar/index"
   }
 }

+ 0 - 33
src/subpackages/content/village-list/village-list.scss

@@ -6,39 +6,6 @@
   background: #f9f3e7;
 }
 
-.village-header {
-  flex: none;
-  border-bottom: 1rpx solid #eadcc5;
-}
-
-.village-nav {
-  display: flex;
-  gap: 20rpx;
-  align-items: center;
-  padding-left: 32rpx;
-}
-
-.village-back {
-  display: flex;
-  flex: none;
-  align-items: center;
-  justify-content: center;
-  width: 72rpx;
-  height: 72rpx;
-  background: rgb(255 255 255 / 70%);
-  border: 1rpx solid #eadcc5;
-  border-radius: 50%;
-}
-
-.village-nav-title {
-  overflow: hidden;
-  text-overflow: ellipsis;
-  font-size: 30rpx;
-  font-weight: 600;
-  color: #753c2b;
-  white-space: nowrap;
-}
-
 .village-scroll {
   flex: 1;
   min-height: 0;

+ 0 - 15
src/subpackages/content/village-list/village-list.ts

@@ -1,6 +1,5 @@
 import type { VillageItem } from '../../../data/inherit-api'
 import { getVillageList } from '../../../data/inherit-api'
-import { getNavBarLayout } from '../../../utils/nav-bar'
 import { runRefresh } from '../../../utils/refresh'
 
 Page({
@@ -11,14 +10,9 @@ Page({
     loadError: '',
     failedImages: {} as Record<string, boolean>,
     requestVersion: 0,
-    statusBarHeight: 20,
-    navHeight: 44,
-    navRightPadding: 100,
   },
 
   onLoad() {
-    const { statusBarHeight, navHeight, navRightPadding } = getNavBarLayout()
-    this.setData({ statusBarHeight, navHeight, navRightPadding })
     return this.loadItems()
   },
 
@@ -65,13 +59,4 @@ Page({
     const id = e.currentTarget.dataset.id as string
     this.setData({ [`failedImages.${id}`]: true })
   },
-
-  onBack() {
-    if (getCurrentPages().length > 1) {
-      wx.navigateBack()
-    }
-    else {
-      wx.switchTab({ url: '/pages/travel/travel' })
-    }
-  },
 })

+ 1 - 8
src/subpackages/content/village-list/village-list.wxml

@@ -1,12 +1,5 @@
 <view class="village-page">
-  <view class="village-header" style="padding-top: {{statusBarHeight}}px;">
-    <view class="village-nav" style="height: {{navHeight}}px; padding-right: {{navRightPadding}}px;">
-      <view class="village-back" aria-role="button" aria-label="返回" bindtap="onBack">
-        <svg-icon name="ph:caret-left-bold" size="18px" color="#843428" />
-      </view>
-      <text class="village-nav-title">特色村镇/街区</text>
-    </view>
-  </view>
+  <nav-bar title="特色村镇/街区" fallback-url="/pages/travel/travel" />
 
   <scroll-view class="village-scroll" scroll-y refresher-enabled="{{true}}" refresher-triggered="{{refreshing}}" bindrefresherrefresh="onPullRefresh">
     <view class="village-content">

+ 0 - 3
src/utils/nav-bar.ts

@@ -6,8 +6,6 @@ export interface NavBarLayout {
   capsuleWidth: number
   /** 导航栏右侧留白,避免内容与胶囊按钮重叠。 */
   navRightPadding: number
-  /** 屏幕居中标题的最大宽度,以右侧胶囊为边界。 */
-  navTitleWidth: number
 }
 
 /** 自定义导航栏布局,统一按状态栏和胶囊按钮位置计算。 */
@@ -27,6 +25,5 @@ export function getNavBarLayout(): NavBarLayout {
     navHeight: capsule && capsule.height > 0 ? (capsule.top - statusBarHeight) * 2 + capsule.height : 44,
     capsuleWidth,
     navRightPadding: capsuleWidth ? capsuleWidth + 12 : 100,
-    navTitleWidth: capsuleWidth ? Math.max(80, (info.windowWidth / 2 - capsuleWidth - 12) * 2) : 160,
   }
 }