tj
2025-05-30 d9a780fa538cb7a83aefa04e75cb53185d690d7d
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<template>
  <view :class="['app', theme]">
    <up-sticky bgColor="#ffffff">
      <view class="header">
        <up-icon name="list" size="40rpx" color="#333333" @click="onSettingClick" />
        <view>
          <!-- <up-tabs :list="list1"> -->
          <up-tabs v-model:current="parentTabIndex" :list="userTabList" @click="onChangeTab">
            <!-- <template #left>
            <up-icon name="list" size="40rpx" color="#333333" />
          </template> -->
            <!-- <template #right>
            <up-icon name="search" size="48rpx" color="#333333" />
          </template> -->
          </up-tabs>
        </view>
        <up-icon name="search" size="48rpx" color="#333333" @click="toSearchPage()" />
      </view>
    </up-sticky>
 
    <view style="margin: 10px 10px 10px 10px; ">
      <up-tabs :list="tabList" :itemStyle="{ padding: '0 16rpx', textAlign: 'center', flex: '1' }">
        <template #right>
          <up-icon name="arrow-down" size="15" color="#333333" />
        </template>
      </up-tabs>
    </view>
    <view class="content-area">
      <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 style="height: 50px; width: 100%;"></view>
    <common-footer flg="0"></common-footer>
    <setting-popup v-model="settingShow" />
  </view>
</template>
<script setup lang="ts">
import SettingPopup from '@/components/setting/setting-popup.vue';
import { reactive, ref, onMounted } from 'vue';
import { FilmCategoryTree, FilmWorks } from '@/types/index'
import { onLoad, onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import { FilmTabCategory, FilmWorksCategory } from '@/enums/dict'
import { useGlobal } from '@/composables/useGlobal'
const { $http, $message, $store } = useGlobal()
import { getParentTabList, getTabList, getFilmWorksBase } from '@/sub-pages/utils/api'
import { FilmWorksQueryDTO } from '@/types/index'
 
import { useNavigator } from '@/composables/useNavigator'
const { navigateTo } = useNavigator()
 
// 控制设置弹窗显示
const settingShow = ref(false);
// 方法定义
function onSettingClick() {
  settingShow.value = true;
}
 
// 创建响应式数据  
// const list1 = reactive([
//   { name: '关注' },
//   { name: '发现' },
//   { name: '苏州' },
// ]);
const parentTabIndex = ref<number>(0)
const userTabList = ref<FilmCategoryTree[]>([])
const tabList = ref<FilmCategoryTree[]>([])
 
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 toSearchPage = () => {
  const url = `/sub-pages/community/search-page`
  navigateTo(url)
}
 
const onChangeTab = (item: FilmCategoryTree) => {
  getTabList(item.id, tabList)
}
 
const theme = ref('light')
onLoad(() => {
  const storedTheme = uni.getStorageSync('theme') || 'light'
  theme.value = storedTheme
})
 
 
onShow(() => {
  getDefaultTabList()
  // 获取电影
  getfilms()
});
 
onPullDownRefresh(async () => {
  console.log('用户下拉刷新了')
  filmPage.value = 1
  getfilms()
  uni.stopPullDownRefresh() // 停止下拉刷新动画
})
 
onReachBottom(() => {
  console.log('用户触底了')
  getfilms()
})
 
const getDefaultTabList = async () => {
  await getParentTabList(userTabList, false)
  const curItem = userTabList.value[parentTabIndex.value]
  getTabList(curItem.id, tabList)
}
 
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,
  };
  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>
.header {
  display: flex;
  justify-content: space-between;
}
 
.content-area {
  // padding: 20rpx;
  margin-bottom: 100px;
}
</style>