文件
fenleixinxi/uniapp/pages/favorite/index.vue
MiAn d508949921 feat: 规范化页面导航与交互体验,优化多端适配
- 统一定制顶部导航组件,支持沉浸式渐变主题与返回逻辑
- 适配 H5 环境的页面跳转逻辑,避免 reLaunch 导致的闪屏问题
- 重构会员、充值、发布等页面布局,改用 Grid 提升移动端适配
- 优化搜索、收藏、消息等页面交互细节,增加点击反馈
- 统一配置页面导航样式,替换原生导航为自定义组件
2026-10-20 13:56:05 +08:00

184 行
4.1 KiB
Vue

<template>
<view class="fav fc-page">
<!-- 规范化顶部导航 -->
<fc-navbar title="我的收藏" theme="gradient" :show-back="true" />
<view v-if="loading && !list.length" class="fav__loading">
<view v-for="i in 3" :key="i" class="fc-skeleton fav__skeleton"></view>
</view>
<fc-empty v-else-if="!list.length" icon="bar-fav" text="还没有收藏的信息" btn-text="去逛逛" @action="goHome" />
<view v-else class="fav__list">
<view v-for="p in list" :key="p.id" class="fav__item">
<fc-post-card :post="p" @click="goDetail(p)" />
<view class="fav__action-bar">
<view class="fav__btn fav__btn--ghost" @click.stop="remove(p)">
<text>取消收藏</text>
</view>
<view class="fav__btn fav__btn--primary" @click.stop="goDetail(p)">
<text>查看详情</text>
</view>
</view>
</view>
<view class="fav__more">
<text v-if="loading">加载中…</text>
<text v-else-if="!hasMore">— 没有更多了 —</text>
<text v-else @click="loadMore">加载更多</text>
</view>
</view>
</view>
</template>
<script>
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
import FcPostCard from '@/components/fc-post-card/fc-post-card.vue'
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
import favoriteApi from '@/common/api/favorite.js'
export default {
components: { FcNavbar, FcPostCard, FcEmpty },
data() {
return {
list: [],
page: 1,
size: 10,
hasMore: true,
loading: false,
}
},
onLoad() {
this.fetch(true)
},
onShow() {
// 详情页取消收藏 / 重新收藏后返回,需要看到最新列表
this.page = 1
this.fetch(true)
},
onReachBottom() {
this.loadMore()
},
methods: {
/**
* 拉取当前用户的收藏列表
* @param {boolean} reset 是否重置分页重新拉取
*/
async fetch(reset = false) {
this.loading = true
try {
const res = await favoriteApi.list({ page: this.page, size: this.size })
this.list = reset ? res.list : this.list.concat(res.list)
this.hasMore = !!res.hasMore
} catch (e) {
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
/**
* 触底加载下一页数据
*/
loadMore() {
if (!this.hasMore || this.loading) return
this.page += 1
this.fetch()
},
/**
* 跳转到帖子详情
* @param {Object} p 目标帖子对象
*/
goDetail(p) {
uni.navigateTo({ url: `/pages/detail/detail?id=${p.id}` })
},
/**
* 返回首页浏览
*/
goHome() {
// #ifdef H5
uni.redirectTo({
url: '/pages/index/index',
fail: () => uni.reLaunch({ url: '/pages/index/index' }),
})
// #endif
// #ifndef H5
uni.reLaunch({ url: '/pages/index/index' })
// #endif
},
/**
* 取消收藏当前信息
* @param {Object} p 帖子对象
*/
async remove(p) {
try {
await favoriteApi.toggle({ postId: p.id })
this.list = this.list.filter((x) => x.id !== p.id)
uni.showToast({ title: '已取消收藏', icon: 'none' })
} catch (e) {
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
}
},
},
}
</script>
<style lang="scss" scoped>
.fav {
padding-bottom: 60rpx;
min-height: 100vh;
background: #f8fafc;
}
.fav__loading {
padding: 24rpx;
}
.fav__skeleton {
height: 240rpx;
margin-bottom: 20rpx;
}
.fav__list {
padding-top: 20rpx;
}
.fav__item {
margin-bottom: 12rpx;
}
.fav__action-bar {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 0 32rpx 20rpx;
margin-top: -10rpx;
gap: 16rpx;
}
.fav__btn {
padding: 8rpx 24rpx;
border-radius: 999rpx;
font-size: 24rpx;
cursor: pointer;
transition: all 0.2s ease;
&--ghost {
color: $fc-text-placeholder;
border: 1rpx solid $fc-border;
background: #ffffff;
&:active {
background: #f1f5f9;
color: $fc-danger;
}
}
&--primary {
color: $fc-primary-text;
background: $fc-primary-lighter;
border: 1rpx solid rgba(4, 135, 74, 0.25);
font-weight: 600;
&:active {
background: rgba(4, 135, 74, 0.15);
}
}
}
.fav__more {
text-align: center;
padding: 24rpx 0 40rpx;
font-size: $fc-font-sm;
color: $fc-text-placeholder;
}
</style>