323 lines
7.4 KiB
Vue
323 lines
7.4 KiB
Vue
<template>
|
|
<view class="home-page">
|
|
<z-paging ref="paging" :auto="false" v-model="contList" @query="queryList" empty-view-text="暂无数据!">
|
|
<template #top>
|
|
<uni-nav-bar leftText=" " :fixed="true" :border="false" leftIcon="back" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" title="我的收藏"></uni-nav-bar>
|
|
<view class="search">
|
|
<view class="search-input-wrapper">
|
|
<view class="search-input-box">
|
|
<view v-if="searchTag" class="search-tag">
|
|
<text>{{searchTag}}</text>
|
|
<uni-icons type="closeempty" size="14" color="#666" @click="removeSearchTag"></uni-icons>
|
|
</view>
|
|
<input
|
|
class="search-input"
|
|
:placeholder="searchTag ? '' : '请输入搜索内容'"
|
|
v-model="searchKeyword"
|
|
@confirm="handleSearch"
|
|
@input="handleSearchInput"
|
|
/>
|
|
<uni-icons type="search" size="18" color="#909399" @click="handleSearch"></uni-icons>
|
|
</view>
|
|
</view>
|
|
<view class="sort-options">
|
|
<view
|
|
class="sort-item"
|
|
:class="{active: sortField === 'browse'}"
|
|
@click="toggleSort('browse')"
|
|
>
|
|
<text>观看量</text>
|
|
<view class="">
|
|
<u-icon name="arrow-up-fill" size="8" :color="sortField === 'browse'&&sortOrder === 'asc' ? '#206ff4' : '#666'"></u-icon>
|
|
<u-icon name="arrow-down-fill" size="8" :color="sortField === 'browse'&&sortOrder === 'desc' ? '#206ff4' : '#666'" ></u-icon>
|
|
</view>
|
|
</view>
|
|
<view
|
|
class="sort-item"
|
|
:class="{active: sortField === 'favorite'}"
|
|
@click="toggleSort('favorite')"
|
|
>
|
|
<text>收藏量</text>
|
|
<view class="">
|
|
<u-icon name="arrow-up-fill" size="8" :color="sortField === 'favorite'&&sortOrder === 'asc' ? '#206ff4' : '#666'"></u-icon>
|
|
<u-icon name="arrow-down-fill" size="8" :color="sortField === 'favorite'&&sortOrder === 'desc' ? '#206ff4' : '#666'" ></u-icon>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
<!-- 内容网格 -->
|
|
<view class="content-grid">
|
|
<square-post-card
|
|
class="grid-item"
|
|
v-for="sitem in contList"
|
|
:key="sitem.id"
|
|
:item="sitem.post"
|
|
:isshow="false"
|
|
@view="navToList"
|
|
@comment="viewPost"
|
|
@like="viewPost" />
|
|
</view>
|
|
</z-paging>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { request,showToast } from '@/api/apiT.js'
|
|
import SquarePostCard from '@/components/SquarePostCard.vue'
|
|
export default {
|
|
components: {
|
|
SquarePostCard
|
|
},
|
|
data() {
|
|
return {
|
|
contList:[],
|
|
searchKeyword: '',
|
|
searchTag: '', // 搜索标签(如 #包豪斯)
|
|
sortField: '', // 排序字段:''(时间) 或 'browse'(观看量) 或 'favorite'(收藏量)
|
|
sortOrder: 'desc', // 排序方向:'asc' 升序 或 'desc' 降序
|
|
}
|
|
},
|
|
onLoad() {
|
|
|
|
},
|
|
onShow(){
|
|
this.$refs.paging.reload()
|
|
},
|
|
methods: {
|
|
leftClick(){
|
|
uni.reLaunch({
|
|
url: '/pages/index/mine',// 替换为你要跳转的页面路径
|
|
});
|
|
// uni.navigateBack({})
|
|
},
|
|
// 点击商品项
|
|
navToList(item) {
|
|
uni.navigateTo({
|
|
url: '/pages/square/detiles?id='+item.id
|
|
});
|
|
},
|
|
queryList(pageNo, pageSize) {
|
|
this.loading = true;
|
|
var that = this;
|
|
const params = {
|
|
current:pageNo,
|
|
size:10
|
|
};
|
|
// 添加搜索参数
|
|
if(this.searchTag){
|
|
params.keyword = this.searchTag.replace('#', '');
|
|
} else if(this.searchKeyword){
|
|
params.keyword = this.searchKeyword;
|
|
}
|
|
// 添加排序参数(如果后端支持)
|
|
if(this.sortField){
|
|
params.sort_by = this.sortField;
|
|
params.order = this.sortOrder;
|
|
} else {
|
|
// 默认按时间排序
|
|
params.sort_by = '';
|
|
params.order = 'desc';
|
|
}
|
|
request({
|
|
url:'common/post/favorite/self',
|
|
method:'get',
|
|
data: params
|
|
}).then(res => {
|
|
|
|
if(res.data.code ==200){
|
|
var datas = res.data.data.records;
|
|
this.$refs.paging.complete(datas);
|
|
}else{
|
|
// this.$refs.paging.complete(null);
|
|
// that.listlength=0
|
|
}
|
|
uni.stopPullDownRefresh();
|
|
//
|
|
})
|
|
},
|
|
// 处理搜索输入
|
|
handleSearchInput(e) {
|
|
const value = e.detail.value;
|
|
// 检测是否输入了标签格式(#开头)
|
|
if(value.startsWith('#')){
|
|
this.searchTag = value;
|
|
this.searchKeyword = '';
|
|
} else {
|
|
this.searchKeyword = value;
|
|
if(this.searchTag){
|
|
this.searchTag = '';
|
|
}
|
|
}
|
|
},
|
|
// 处理搜索
|
|
handleSearch() {
|
|
if(this.searchKeyword && this.searchKeyword.startsWith('#')){
|
|
this.searchTag = this.searchKeyword;
|
|
this.searchKeyword = '';
|
|
}
|
|
// 重新加载数据
|
|
this.$refs.paging && this.$refs.paging.reload();
|
|
},
|
|
// 移除搜索标签
|
|
removeSearchTag() {
|
|
this.searchTag = '';
|
|
this.searchKeyword = '';
|
|
// 重新加载数据
|
|
this.$refs.paging && this.$refs.paging.reload();
|
|
},
|
|
// 切换排序
|
|
toggleSort(field) {
|
|
if(this.sortField === field){
|
|
// 如果点击的是当前排序字段,切换排序方向
|
|
this.sortOrder = this.sortOrder === 'asc' ? 'desc' : 'asc';
|
|
} else {
|
|
// 如果点击的是新字段,设置为降序
|
|
this.sortField = field;
|
|
this.sortOrder = 'desc';
|
|
}
|
|
// 重新加载数据
|
|
this.$refs.paging && this.$refs.paging.reload();
|
|
}
|
|
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.home-page{
|
|
min-height: 100vh;
|
|
background: #F5F6FA;
|
|
box-sizing: border-box;
|
|
padding-bottom: 120rpx;
|
|
}
|
|
.search{
|
|
padding: 20rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 20rpx;
|
|
background: #fff;
|
|
}
|
|
.search-input-wrapper{
|
|
flex: 1;
|
|
}
|
|
.search-input-box{
|
|
display: flex;
|
|
align-items: center;
|
|
background: #F5F6FA;
|
|
border-radius: 10rpx;
|
|
padding: 15rpx 24rpx;
|
|
gap: 12rpx;
|
|
}
|
|
.search-tag{
|
|
display: flex;
|
|
align-items: center;
|
|
background: #fff;
|
|
border-radius: 20rpx;
|
|
padding: 4rpx 12rpx;
|
|
gap: 8rpx;
|
|
font-size: 24rpx;
|
|
color: #333;
|
|
margin-right: 8rpx;
|
|
flex-shrink: 0;
|
|
}
|
|
.search-tag text{
|
|
font-size: 24rpx;
|
|
color: #333;
|
|
}
|
|
.search-input{
|
|
flex: 1;
|
|
font-size: 28rpx;
|
|
color: #333;
|
|
background: transparent;
|
|
border: none;
|
|
}
|
|
.sort-options{
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 24rpx;
|
|
flex-shrink: 0;
|
|
}
|
|
.sort-item{
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6rpx;
|
|
font-size: 26rpx;
|
|
color: #666;
|
|
cursor: pointer;
|
|
transition: color 0.3s;
|
|
}
|
|
.sort-item.active{
|
|
color: #206ff4;
|
|
font-weight: 500;
|
|
}
|
|
.sort-item text{
|
|
font-size: 26rpx;
|
|
}
|
|
.content-grid{
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
padding: 20rpx;
|
|
justify-content: space-between;
|
|
background: #fff;
|
|
}
|
|
.grid-item{
|
|
width: 48%;
|
|
overflow: hidden;
|
|
margin-bottom: 20rpx;
|
|
}
|
|
.grid-image{
|
|
width: 100%;
|
|
height: 320rpx;
|
|
background: #E5E5E5;
|
|
border-radius: 10rpx;
|
|
}
|
|
.grid-footer{
|
|
padding: 20rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
.grid-avatar{
|
|
width: 48rpx;
|
|
height: 48rpx;
|
|
border-radius: 50%;
|
|
margin-right: 12rpx;
|
|
flex-shrink: 0;
|
|
object-fit: cover;
|
|
display: block;
|
|
}
|
|
.grid-info{
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: 87%;
|
|
}
|
|
.grid-tag{
|
|
font-size: 24rpx;
|
|
color: #3F435B;
|
|
margin-bottom: 4rpx;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
width: 95%;
|
|
}
|
|
.grid-name{
|
|
font-size: 22rpx;
|
|
color: #8A8D97;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
width: 88%;
|
|
}
|
|
.iconview{
|
|
margin-right: 10px;
|
|
display: inline-block;
|
|
font-size: 22rpx;
|
|
}
|
|
.icons {
|
|
width: 16px;
|
|
height: 16px;
|
|
margin-right: 5px;
|
|
}
|
|
</style>
|