searchPage.vue
4.81 KB
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
<!--
* @Date: 2024-12-03 10:35:15
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-12-03 15:15:45
* @FilePath: /tswj/src/views/client/searchPage.vue
* @Description: 文件描述
-->
<template>
<div class="search-page">
<div style="background-color: #F7F7F7; height: auto; padding: 1rem;">
<div style="background-color: #FFF; border-radius: 1rem; padding: 0.5rem 1rem; display: flex; align-items: center; justify-content: space-between;">
<input type="text" v-model="performer_name" placeholder="请输入要搜索的表演者姓名" @blur="onSearch" style="border: 0; width: 100%;">
<van-icon name="search" />
</div>
</div>
<div class="book-video-list">
<!-- <van-list ref="listRef" v-model:loading="loading" :finished="finished" :finished-text="finishedTextStatus ? '没有更多了' : ''"
@load="onLoad" :immediate-check="immediateCheck"> -->
<template v-for="item in search_prod_list" :key="item">
<video-card :item="item">
<template #bookDetailSub>
<div style="color: #999999; padding: 0px 1rem 0.5rem;" @click="setComment(item)">
{{ item.kg_name }} | {{ item.localism_type }}
</div>
</template>
</video-card>
</template>
<!-- </van-list> -->
</div>
<div style="height: 2rem;" />
<van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无作品信息" />
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Cookies, $, _, axios, storeToRefs, mainStore, useTitle } from '@/utils/generatePackage.js'
//import { } from '@/utils/generateModules.js'
import { no_image } from '@/utils/generateIcons.js'
//import { } from '@/composables'
import { VideoCard } from '@/utils/generateModules'
import { prodListAPI } from '@/api/C/book'
import { killPages, store } from '@/hooks/useKeepAlive';
killPages()
const $route = useRoute();
const $router = useRouter();
console.warn($route.meta.title);
useTitle($route.meta.title);
const search_prod_list = ref([]);
const limit = ref(10)
const offset = ref(0)
// 处理书籍下作品列表
const loading = ref(false);
const finished = ref(false);
const immediateCheck = ref(false);
// 因为不能让空图标提前出来的写法
const finishedTextStatus = ref(false);
const emptyStatus = ref(false);
const book_id = $route.query.book_id;
const kg_id = $route.query.kg_id;
// 定义一个变量来表示是否滚动到底部
const isBottom = ref(false);
// 标记是否是第一次进入页面
const isFirstMount = ref(true);
// 滚动事件处理函数,这里添加了触发回调的逻辑
const handleScroll = () => {
const scrollTop = window.scrollY; // 当前滚动距离
const clientHeight = document.documentElement.clientHeight; // 视口高度
const scrollHeight = document.documentElement.scrollHeight; // 页面总高度
if (scrollTop + clientHeight >= scrollHeight) {
// 在这里触发你的回调逻辑
if (performer_name.value) {
onLoad()
}
}
};
// 在组件挂载时添加滚动事件监听,并将第一次进入页面的标记设为false
onMounted(() => {
window.addEventListener('scroll', handleScroll);
});
// 在组件卸载时移除滚动事件监听
onUnmounted(() => {
window.removeEventListener('scroll', handleScroll);
});
const performer_name = ref('');
/**
* 向下滚动查询数据
*/
const onLoad = async () => {
// 异步更新数据
const { data, code } = await prodListAPI({ book_id, kg_id, limit: limit.value, offset: offset.value, performer_name: performer_name.value })
if (code === 1) {
search_prod_list.value = _.concat(search_prod_list.value, data.prod_list);
search_prod_list.value = _.uniqBy(search_prod_list.value, 'id');
offset.value = search_prod_list.value.length;
loading.value = false;
// 数据全部加载完成
if (!data.prod_list.length) {
// 加载状态结束
finished.value = true;
}
// 空数据提示
if (!search_prod_list.value.length) {
finishedTextStatus.value = false;
}
emptyStatus.value = Object.is(search_prod_list.value.length, 0);
}
};
const onSearch = async() => {
offset.value = 0
search_prod_list.value = []
loading.value = true;
finished.value = false;
onLoad()
}
</script>
<style lang="less" scoped>
.bottom-btn {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: white;
box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.07);
z-index: 9999;
.text {
text-align: center;
padding: 0.7rem;
margin: 0.8rem;
font-size: 1rem;
font-weight: bold;
border-radius: 24px;
// border: 1px solid F7F7F7;
color: @base-font-color;
background-color: @base-color;
box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.06);
}
}
</style>