fix: recommend list

This commit is contained in:
zzc
2026-01-28 15:44:30 +08:00
parent b22bbb8f7c
commit e3edccbd65
2 changed files with 116 additions and 61 deletions

View File

@@ -45,3 +45,10 @@ export const viewRecord = async (data) => {
data, data,
}); });
}; };
export const getRecommendList = async (page = 1) => {
return request({
url: `/api/blessing/recommend/list?page=${page}`,
method: "get",
});
};

View File

@@ -69,40 +69,45 @@
</view> </view>
<view class="use-grid"> <view class="use-grid">
<view <view
v-for="(card, i) in popularCards" v-for="(card, i) in recommendList"
:key="i" :key="i"
class="use-card" class="use-card"
@tap="previewCard(card)" @tap="onCardClick(card)"
> >
<view class="card-cover-wrap"> <view class="card-cover-wrap">
<image :src="card.cover" class="card-cover" mode="aspectFill" /> <image :src="card.imageUrl" class="card-cover" mode="aspectFill" />
<view <view v-if="card.tag" class="card-tag" :class="`tag--${card.tag}`">
v-if="card.tag" {{ getTagText(card.tag) }}
class="card-tag"
:class="`tag--${card.tagType || 'default'}`"
>
{{ card.tag }}
</view> </view>
</view> </view>
<view class="card-info"> <view class="card-info">
<view class="card-title">{{ card.title }}</view> <view class="card-title">{{ card.title }}</view>
<view class="card-desc">{{ card.desc }}</view> <view class="card-desc">{{ card.content }}</view>
<view class="card-footer"> <view class="card-footer">
<view class="cta-btn" @tap.stop="onCta(card)"> <view class="cta-btn" @tap.stop="onCardClick(card)">
{{ card.cta }} {{ getCtaText(card.type) }}
</view> </view>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
<view v-if="loading" class="loading-text">加载中...</view>
<view v-if="!hasMore && recommendList.length > 0" class="no-more-text"
>没有更多了</view
>
</view> </view>
</view> </view>
</template> </template>
<script setup> <script setup>
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { onPullDownRefresh, onShareAppMessage } from "@dcloudio/uni-app"; import {
onPullDownRefresh,
onShareAppMessage,
onReachBottom,
} from "@dcloudio/uni-app";
import { getBavBarHeight } from "@/utils/system"; import { getBavBarHeight } from "@/utils/system";
import { getRecommendList } from "@/api/system";
const countdownText = ref(""); const countdownText = ref("");
@@ -188,6 +193,8 @@ onMounted(() => {
const index = dayOfYear % inspirationList.length; const index = dayOfYear % inspirationList.length;
dailyGreeting.value = inspirationList[index]; dailyGreeting.value = inspirationList[index];
fetchRecommendList();
}); });
const features = ref([ const features = ref([
@@ -217,45 +224,81 @@ const features = ref([
}, },
]); ]);
const popularCards = ref([ const recommendList = ref([]);
{ const page = ref(1);
title: "招财进宝金框", const hasMore = ref(true);
tag: "热门", const loading = ref(false);
tagType: "hot",
desc: "2026马年限定汉字金框金光闪烁财运亨通。适合送亲友的新春祝福。", const fetchRecommendList = async (isRefresh = false) => {
cta: "立即制作", if (loading.value || (!hasMore.value && !isRefresh)) return;
cover: loading.value = true;
"https://file.lihailezzc.com/9a929a32-439f-453b-b603-fda7b04cbe08.png", if (isRefresh) {
}, page.value = 1;
{ hasMore.value = true;
title: "大吉大利卡片", }
tag: "精选", try {
tagType: "featured", const res = await getRecommendList(page.value);
desc: "经典红色大拜年卡片,适合送长辈、老师、同学,传递满满的新春喜气。", const list = res?.list || [];
cta: "去写祝福", if (isRefresh) {
cover: recommendList.value = list;
"https://file.lihailezzc.com/b5fe8ffb-5901-48d2-94fb-48191e36cbf5.png", } else {
}, recommendList.value = [...recommendList.value, ...list];
{ }
title: "合家团圆模板",
tag: "爆款", if (res.hasNext !== undefined) {
tagType: "hot2", hasMore.value = res.hasNext;
desc: "一键生成合家福贺图,支持换装、特效装饰、朋友圈海报等。", } else {
cta: "开始创作", // Fallback if API doesn't return hasNext
cover: if (list.length < 10) hasMore.value = false;
"https://file.lihailezzc.com/91cd1611-bb87-442b-a338-24e9d79e4ee9.png", }
type: "video",
}, if (list.length > 0) {
{ page.value++;
title: "福气满满", } else {
tag: "新款", hasMore.value = false;
tagType: "new", }
desc: "福字当头,好运连连。送给最爱的人。", } catch (e) {
cta: "立即制作", console.error(e);
cover: } finally {
"https://file.lihailezzc.com/resource/b48c41054c2633c478463ac1b1f1ca23.png", loading.value = false;
}, }
]); };
const getTagText = (tag) => {
const map = {
hot: "热门",
new: "新款",
featured: "精选",
hot2: "爆款",
};
return map[tag] || tag;
};
const getCtaText = (type) => {
const map = {
frame: "去制作",
decor: "去装饰",
avatar: "去查看",
card: "去写祝福",
fortune: "去抽取",
};
return map[type] || "立即查看";
};
const onCardClick = (card) => {
if (card.scene === "avatar_download") {
uni.navigateTo({ url: "/pages/avatar/index" });
return;
}
// Default fallback based on type
if (card.type === "card") {
uni.switchTab({ url: "/pages/make/index" });
} else if (card.type === "fortune") {
uni.navigateTo({ url: "/pages/fortune/index" });
} else {
uni.navigateTo({ url: "/pages/avatar/index" });
}
};
const onFeatureTap = (item) => { const onFeatureTap = (item) => {
if (item.type === "fortune") { if (item.type === "fortune") {
@@ -277,20 +320,16 @@ const onFeatureTap = (item) => {
uni.showToast({ title: `进入:${item.title}`, icon: "none" }); uni.showToast({ title: `进入:${item.title}`, icon: "none" });
}; };
const previewCard = (card) => { onReachBottom(() => {
uni.previewImage({ urls: [card.cover] }); fetchRecommendList();
}; });
const onMore = () => { const onMore = () => {
uni.showToast({ title: "更多模板即将上线~", icon: "none" }); uni.showToast({ title: "更多模板即将上线~", icon: "none" });
}; };
const onCta = (card) => { onPullDownRefresh(async () => {
// uni.showToast({ title: `${card.cta} · ${card.title}`, icon: "none" }); await fetchRecommendList(true);
uni.switchTab({ url: "/pages/make/index" });
};
onPullDownRefresh(() => {
setTimeout(() => { setTimeout(() => {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
uni.showToast({ title: "已为你更新内容", icon: "success" }); uni.showToast({ title: "已为你更新内容", icon: "success" });
@@ -647,4 +686,13 @@ onShareAppMessage(() => {
border-radius: 999rpx; border-radius: 999rpx;
font-weight: 500; font-weight: 500;
} }
.loading-text,
.no-more-text {
text-align: center;
font-size: 24rpx;
color: #999;
padding: 20rpx 0;
width: 100%;
}
</style> </style>