1
cloudroam
2025-06-09 9544981b868e010ebdac17446f4a8dc4dfc241a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
  <view :class="['app', theme]">
    <view style="padding-top: 10rpx;">
      <up-search height="70rpx" placeholder="搜索" search-icon-size="40rpx" margin="0rpx 30rpx" v-model="search"
        :show-action="true" @search="onSearch" @custom="onSearch" @click-icon="onSearch" />
    </view>
 
    <up-tabs :list="tabList" @click="click">
      <template #right>
        <view style="padding-left: 4px;" @tap="() => showToast('插槽被点击')">
          <up-icon name="list" size="40rpx" bold></up-icon>
        </view>
      </template>
    </up-tabs>
 
    <view class="list-view">
      <up-waterfall v-model="films">
        <template #left="{ leftList }">
          <FlowCard v-for="(item, index) in leftList" :key="index" :item="item" @click="handleDetailClick" />
        </template>
        <template #right="{ rightList }">
          <FlowCard v-for="(item, index) in rightList" :key="index" :item="item" @click="handleDetailClick" />
        </template>
      </up-waterfall>
      <up-loadmore :status="filmStatus" :line="true" />
    </view>
  </view>
</template>
 
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { onLoad, onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import { FilmCategoryTree,FilmWorks,FilmWorksQueryDTO } from '@/types/index'
import { useGlobal } from '@/composables/useGlobal'
const { $http, $message, $store } = useGlobal()
import { FilmTabCategory,FilmWorksCategory } from '@/enums/dict'
import { useNavigator } from '@/composables/useNavigator'
const { navigateTo } = useNavigator()
 
import { getTabList,getFilmWorksBase } from '@/sub-pages/utils/api'
 
const theme = ref('light')
const search = ref('')
const keywords = ref('') // 新增关键词状态
const tabList = ref<FilmCategoryTree[]>([])
const onSearch = (value: string) => {
  const searchValue = typeof value === 'string' ? value : search.value
  keywords.value = searchValue
  filmPage.value = 1
  films.value = []
  filmStatus.value = 'loadmore'
 getfilms()
 
}
 
const handleDetailClick = (item: FilmCategoryTree) => {
    const urlOfficicl=`/sub-pages/film-list/film-official-detail?id=${item.id}`;
    const url= `/sub-pages/film-list/film-detail?id=${item.id}` 
    navigateTo(url)
}
 
const showToast = (msg: string) => {
  uni.showToast({ title: msg, icon: 'none' })
}
 
onLoad(() => {
  const storedTheme = uni.getStorageSync('theme') || 'light'
  theme.value = storedTheme
})
 
 
onMounted(() => {
  
})
 
onShow(() => {
  // 获取分类
  getTabList(FilmTabCategory.FILM_TYPE,tabList)
 
  // 获取电影
  getfilms()
 
});
 
onPullDownRefresh(async () => {
  console.log('用户下拉刷新了')
  filmPage.value = 1
  getfilms()
  uni.stopPullDownRefresh() // 停止下拉刷新动画
})
 
onReachBottom(() => {
  console.log('用户触底了')
  getfilms()
})
 
const films = ref<FilmWorks[]>([])
const filmPage = ref(1)
const filmSize = 10
const filmStatus = ref('loading')
const getfilms = async () => {
  if (filmStatus.value === 'nomore') return
 
  filmStatus.value = 'loading'
 
  // TODO 暂时使用光影社区的类别
  const query: FilmWorksQueryDTO = {
    classify: '',
    type: '',
    current: filmPage.value,
    size: filmSize,
    keywords: keywords.value // 关键修改
  };
  const records = await getFilmWorksBase(query)
 
  if (records && records.length > 0) {
    // 使用 Set 进行去重
    const existingIds = new Set(films.value.map(item => item.id))
    const uniqueRecords = records.filter(item => !existingIds.has(item.id))
 
    films.value = [...films.value, ...uniqueRecords]
 
    // 如果返回的记录数少于请求的 size,说明没有更多数据
    if (records.length < filmSize) {
      filmStatus.value = 'noMore'
    }
 
    filmPage.value++
  } else {
    filmStatus.value = 'noMore'
  }
}
 
 
 
 
 
 
</script>
 
<style lang="scss" scoped></style>