Files
spring-festival-greetings/pages/wallpaper/detail.vue

675 lines
15 KiB
Vue
Raw Normal View History

2026-01-28 21:13:27 +08:00
<template>
<view class="detail-page" :style="{ paddingTop: navHeight + 'px' }">
<!-- Navbar -->
<view
class="nav-bar"
:style="{ height: navHeight + 'px', paddingTop: statusBarHeight + 'px' }"
>
<view class="nav-content">
<view class="back" @tap="goBack">
<text class="back-icon"></text>
</view>
<text class="title">壁纸详情</text>
</view>
</view>
2026-01-28 21:37:37 +08:00
<view class="content-container">
<!-- Sharer Info -->
<view class="sharer-info" v-if="detailData.from">
<image
:src="detailData.from.avatar || '/static/default-avatar.png'"
class="avatar"
mode="aspectFill"
/>
<view class="info-text">
<view class="nickname">{{
detailData.from.nickname || "神秘好友"
}}</view>
<view class="action-text">给你分享了一张2026新春精美壁纸</view>
<view class="sub-text"> 2026 且马贺岁</view>
2026-01-28 21:13:27 +08:00
</view>
2026-01-28 21:37:37 +08:00
</view>
2026-01-28 21:13:27 +08:00
2026-01-28 21:37:37 +08:00
<!-- Wallpaper Preview -->
<view class="preview-card">
<view class="preview-badge">PREVIEW</view>
<image
2026-02-26 11:00:19 +08:00
:src="getThumbUrl(detailData.imageUrl)"
2026-01-28 21:37:37 +08:00
mode="widthFix"
class="main-image"
@tap="previewImage"
/>
</view>
2026-01-28 21:13:27 +08:00
2026-01-28 21:37:37 +08:00
<!-- Action Buttons -->
<view class="action-buttons">
2026-02-26 10:53:46 +08:00
<view class="points-display" v-if="isLoggedIn">
<text class="label">当前积分</text>
<text class="value">{{ userPoints }}</text>
</view>
2026-02-26 10:51:06 +08:00
<button class="btn primary-btn" @tap="downloadWallpaper">
2026-02-26 10:53:46 +08:00
<view class="btn-content">
<view class="btn-main">
<text class="btn-icon"></text>
<text>下载高清壁纸</text>
</view>
<text class="btn-sub">消耗 20 积分</text>
</view>
2026-01-28 21:37:37 +08:00
</button>
</view>
2026-01-28 21:13:27 +08:00
2026-01-28 21:37:37 +08:00
<!-- More Wallpapers -->
<view class="more-section">
<view class="section-header">
2026-02-26 10:51:06 +08:00
<text class="section-title">更多同款壁纸</text>
2026-01-28 21:37:37 +08:00
<view class="more-link" @tap="goToIndex">
<text>查看更多</text>
<text class="arrow"></text>
2026-01-28 21:13:27 +08:00
</view>
2026-01-28 21:37:37 +08:00
</view>
2026-01-28 21:54:23 +08:00
<scroll-view scroll-x class="more-scroll" :show-scrollbar="false">
<view class="scroll-inner">
<view
v-for="(item, index) in recommendList"
:key="index"
class="scroll-item"
@tap="onRecommendClick(item)"
>
<image
2026-02-10 00:05:08 +08:00
:src="getThumbUrl(item.imageUrl)"
2026-01-28 21:54:23 +08:00
mode="aspectFill"
class="scroll-img"
/>
<text class="item-title">{{ item.title || "新春壁纸" }}</text>
</view>
2026-01-28 21:13:27 +08:00
</view>
2026-01-28 21:54:23 +08:00
</scroll-view>
2026-01-28 21:37:37 +08:00
</view>
2026-01-28 21:13:27 +08:00
2026-01-28 21:37:37 +08:00
<!-- Footer -->
<view class="footer">
<view class="footer-divider">
<view class="line"></view>
<text class="footer-text">2026 HAPPY NEW YEAR</text>
<view class="line"></view>
2026-01-28 21:13:27 +08:00
</view>
2026-01-28 21:37:37 +08:00
<view class="footer-sub">新春祝福 · 传递温情</view>
2026-01-28 21:13:27 +08:00
</view>
2026-01-28 21:37:37 +08:00
</view>
2026-02-26 10:51:06 +08:00
<LoginPopup ref="loginPopupRef" @logind="handleLogind" />
<RewardAd ref="rewardAdRef" @onReward="handleAdReward" />
2026-01-28 21:13:27 +08:00
</view>
</template>
<script setup>
2026-02-26 10:51:06 +08:00
import { ref, computed } from "vue";
2026-02-08 18:57:45 +08:00
import { onLoad, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
2026-01-28 21:13:27 +08:00
import { getBavBarHeight } from "@/utils/system";
2026-02-28 23:22:35 +08:00
import { getPageDetail, getShareReward } from "@/api/system";
2026-02-26 14:35:42 +08:00
import { getWallpaperSameList } from "@/api/wallpaper";
2026-02-26 10:51:06 +08:00
import {
getShareToken,
saveViewRequest,
saveRemoteImageToLocal,
saveRecordRequest,
trackRecord,
} from "@/utils/common.js";
import { useUserStore } from "@/stores/user";
2026-03-04 12:35:59 +08:00
import { watchAdReward } from "@/api/system.js";
import { checkAbilityAndHandle } from "@/utils/ability.js";
2026-02-26 10:51:06 +08:00
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
import RewardAd from "@/components/RewardAd/RewardAd.vue";
const userStore = useUserStore();
const loginPopupRef = ref(null);
const rewardAdRef = ref(null);
const isLoggedIn = computed(() => !!userStore.userInfo.nickName);
2026-02-26 10:53:46 +08:00
const userPoints = computed(() => userStore.userInfo.points || 0);
2026-01-28 21:13:27 +08:00
const navHeight = getBavBarHeight();
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const detailData = ref({
imageUrl: "",
from: null,
});
const recommendList = ref([]);
const shareToken = ref("");
2026-02-26 14:58:04 +08:00
const categoryId = ref("");
2026-01-28 21:13:27 +08:00
onLoad(async (options) => {
if (options.shareToken) {
shareToken.value = options.shareToken;
await fetchDetail();
}
2026-02-26 10:51:06 +08:00
if (options.id) {
detailData.value.id = options.id;
}
if (options.imageUrl) {
detailData.value.imageUrl = decodeURIComponent(options.imageUrl);
}
2026-02-26 15:14:55 +08:00
if (options.categoryId) {
categoryId.value = options.categoryId;
}
2026-02-26 14:35:42 +08:00
fetchRecommend(options.id);
2026-01-28 21:13:27 +08:00
});
2026-02-09 22:31:01 +08:00
onShareAppMessage(async () => {
2026-02-12 00:42:36 +08:00
const token = await getShareToken("wallpaper_download", detailData.value?.id);
2026-02-28 23:22:35 +08:00
getShareReward({ scene: "wallpaper_download" });
2026-02-08 18:57:45 +08:00
return {
title: "快来看看我刚领到的新年精美壁纸 🖼",
2026-02-09 22:31:01 +08:00
path: `/pages/wallpaper/detail?shareToken=${token || ""}`,
2026-02-08 18:57:45 +08:00
imageUrl:
detailData.value?.imageUrl ||
"https://file.lihailezzc.com/resource/8dd026d76ef7a63d123b7fd698fb989b.png",
};
});
2026-02-09 22:31:01 +08:00
onShareTimeline(async () => {
2026-02-12 01:47:53 +08:00
const token = await getShareToken("wallpaper_download", detailData.value?.id);
2026-02-08 18:57:45 +08:00
return {
title: "快来看看我刚领到的新年精美壁纸 🖼",
2026-02-09 22:31:01 +08:00
query: `shareToken=${token}`,
2026-02-08 18:57:45 +08:00
imageUrl:
detailData.value?.imageUrl ||
"https://file.lihailezzc.com/resource/8dd026d76ef7a63d123b7fd698fb989b.png",
};
});
2026-02-10 00:05:08 +08:00
const getThumbUrl = (url) => {
return `${url}?imageView2/1/w/340/h/600/q/80`;
};
2026-01-28 21:13:27 +08:00
const fetchDetail = async () => {
try {
const res = await getPageDetail(shareToken.value);
2026-02-09 22:31:01 +08:00
saveViewRequest(shareToken.value, "wallpaper_detail", res.id);
2026-01-28 21:13:27 +08:00
if (res) {
detailData.value = res;
2026-02-26 14:35:42 +08:00
fetchRecommend(res.id);
2026-01-28 21:13:27 +08:00
}
} catch (e) {
console.error("Failed to fetch detail", e);
uni.showToast({
title: "获取详情失败",
icon: "none",
});
}
};
2026-02-26 14:35:42 +08:00
const fetchRecommend = async (id) => {
if (!id && !detailData.value.id) return;
2026-01-28 21:13:27 +08:00
try {
2026-02-26 14:35:42 +08:00
const res = await getWallpaperSameList(id || detailData.value.id);
2026-01-28 21:37:37 +08:00
recommendList.value = res;
2026-02-26 15:14:55 +08:00
// categoryId.value = res[0]?.categoryId || "";
2026-01-28 21:13:27 +08:00
} catch (e) {
console.error("Failed to fetch recommendations", e);
}
};
const goBack = () => {
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack();
} else {
uni.reLaunch({
url: "/pages/index/index",
});
}
};
const goToIndex = () => {
uni.navigateTo({
2026-02-26 14:58:04 +08:00
url: `/pages/wallpaper/index?categoryId=${categoryId.value}`,
2026-01-28 21:13:27 +08:00
});
};
const goToFortune = () => {
uni.navigateTo({
url: "/pages/fortune/index",
});
};
const previewImage = () => {
2026-02-26 11:00:19 +08:00
if (detailData.value.imageUrl) {
uni.previewImage({
urls: [detailData.value.imageUrl],
});
}
2026-01-28 21:13:27 +08:00
};
2026-02-26 14:35:42 +08:00
const onRecommendClick = (item) => {
// Update detailData with new item info
detailData.value = {
...detailData.value,
id: item.id,
imageUrl: item.imageUrl,
title: item.title,
};
// Refresh recommendations for the new item
fetchRecommend(item.id);
// Scroll to top or just update view
uni.pageScrollTo({
scrollTop: 0,
duration: 300,
});
2026-01-28 21:13:27 +08:00
};
2026-02-26 10:51:06 +08:00
const handleLogind = async () => {
// Logic after successful login if needed
};
const handleAdReward = async (token) => {
try {
const res = await watchAdReward(token);
if (res) {
uni.showToast({
title: "获得50积分",
icon: "success",
});
await userStore.fetchUserAssets();
}
} catch (e) {
console.error("Reward claim failed", e);
uni.showToast({ title: "奖励发放失败", icon: "none" });
}
};
const downloadWallpaper = async () => {
trackRecord({
eventName: "wallpaper_download_click",
eventType: `click`,
elementId: detailData.value?.id || "",
});
if (!isLoggedIn.value) {
loginPopupRef.value.open();
return;
}
2026-03-04 12:35:59 +08:00
const canProceed = await checkAbilityAndHandle(
"wallpaper_download",
rewardAdRef,
);
if (!canProceed) return;
2026-02-26 10:51:06 +08:00
uni.showLoading({ title: "下载中..." });
try {
// Parallelize save record and download
// Wait for saveRecordRequest to ensure backend deducts points
await Promise.all([
saveRecordRequest(
"",
detailData.value?.id,
"wallpaper_download",
detailData.value?.imageUrl,
),
saveRemoteImageToLocal(detailData.value?.imageUrl),
]);
// Refresh user assets to show updated points
await userStore.fetchUserAssets();
uni.hideLoading();
uni.showToast({ title: "保存成功 消耗 20 积分", icon: "success" });
} catch (e) {
uni.hideLoading();
console.error("Download failed", e);
uni.showToast({ title: "下载失败", icon: "none" });
}
};
2026-01-28 21:13:27 +08:00
</script>
<style lang="scss" scoped>
.detail-page {
min-height: 100vh;
background: #ffffff;
box-sizing: border-box;
}
.nav-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 100;
2026-01-28 21:37:37 +08:00
background-color: #ffffff;
2026-01-28 21:13:27 +08:00
.nav-content {
height: 44px; // Standard nav height
display: flex;
align-items: center;
2026-01-31 22:23:39 +08:00
padding: 0 24rpx;
2026-01-28 21:13:27 +08:00
.back {
display: flex;
align-items: center;
2026-01-31 22:23:39 +08:00
margin-right: 24rpx;
/* 增大点击区域 */
padding: 20rpx;
margin-left: -20rpx;
2026-01-28 21:13:27 +08:00
.back-icon {
2026-01-31 22:23:39 +08:00
font-size: 50rpx;
2026-01-28 21:13:27 +08:00
color: #333;
font-weight: 300;
2026-01-31 22:23:39 +08:00
line-height: 1;
2026-01-28 21:13:27 +08:00
}
}
.title {
2026-01-31 22:23:39 +08:00
font-size: 34rpx;
2026-01-28 21:13:27 +08:00
font-weight: 600;
color: #333;
2026-01-31 22:23:39 +08:00
flex: 1;
text-align: center;
margin-right: 50rpx; /* Balance back button */
2026-01-28 21:13:27 +08:00
}
}
}
.content-container {
padding: 20px;
padding-bottom: 40px;
}
.sharer-info {
display: flex;
align-items: center;
margin-bottom: 24px;
.avatar {
width: 48px;
height: 48px;
border-radius: 50%;
margin-right: 12px;
border: 2px solid #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.info-text {
.nickname {
font-size: 16px;
font-weight: 600;
color: #333;
margin-bottom: 4px;
}
.action-text {
font-size: 14px;
color: #666;
margin-bottom: 2px;
}
.sub-text {
font-size: 12px;
color: #ff3b30;
font-weight: 500;
}
}
}
.preview-card {
position: relative;
width: 100%;
background: #fff;
border-radius: 16px;
padding: 12px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.04);
border: 1px solid #f5f5f5;
margin-bottom: 24px;
.preview-badge {
position: absolute;
top: 24px;
right: 24px;
background: rgba(0, 0, 0, 0.2);
backdrop-filter: blur(4px);
color: #fff;
font-size: 10px;
padding: 4px 8px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.2);
z-index: 10;
}
.main-image {
2026-02-26 11:00:19 +08:00
width: 460rpx;
margin: 0 auto;
2026-01-28 21:13:27 +08:00
border-radius: 12px;
display: block;
background-color: #fafafa; // Placeholder color
2026-02-26 11:00:19 +08:00
box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.1);
2026-01-28 21:13:27 +08:00
}
}
.action-buttons {
display: flex;
flex-direction: column;
gap: 12px;
margin-bottom: 32px;
.btn {
width: 100%;
height: 52px;
border-radius: 26px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
font-weight: 600;
border: none;
margin: 0;
transition: all 0.2s;
.btn-icon {
margin-right: 8px;
font-size: 18px;
}
&.primary-btn {
background: linear-gradient(90deg, #ff3b30 0%, #ff6b6b 100%);
color: #fff;
box-shadow: 0 8px 20px rgba(255, 59, 48, 0.15);
2026-02-26 10:53:46 +08:00
height: 64px; /* Increased height for two lines */
2026-01-28 21:13:27 +08:00
}
&.secondary-btn {
background: #f9f9f9;
color: #333;
border: 1px solid #eee;
}
&:active {
transform: scale(0.98);
opacity: 0.9;
}
}
2026-02-26 10:53:46 +08:00
.points-display {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 8px;
font-size: 14px;
color: #666;
.value {
color: #ff5722;
font-weight: bold;
font-size: 16px;
margin-left: 4px;
}
}
.btn-content {
display: flex;
flex-direction: column;
align-items: center;
line-height: 1.2;
.btn-main {
display: flex;
align-items: center;
font-size: 18px;
font-weight: bold;
margin-bottom: 2px;
}
.btn-sub {
font-size: 12px;
opacity: 0.9;
font-weight: normal;
}
}
2026-01-28 21:13:27 +08:00
}
.more-section {
margin-bottom: 32px;
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
.section-title {
font-size: 18px;
font-weight: 600;
color: #333;
}
.more-link {
display: flex;
align-items: center;
font-size: 14px;
color: #ff3b30;
.arrow {
margin-left: 2px;
font-size: 16px;
}
}
}
2026-01-28 21:54:23 +08:00
.more-scroll {
width: 100%;
white-space: nowrap;
}
2026-01-28 21:13:27 +08:00
2026-01-28 21:54:23 +08:00
.scroll-inner {
display: flex;
padding-right: 20px;
}
2026-01-28 21:13:27 +08:00
2026-01-28 21:54:23 +08:00
.scroll-item {
display: inline-flex;
flex-direction: column;
width: 200rpx;
margin-right: 20rpx;
flex-shrink: 0;
.scroll-img {
width: 100%;
height: 355rpx;
border-radius: 12rpx;
margin-bottom: 12rpx;
background-color: #f5f5f5;
}
.item-title {
font-size: 24rpx;
color: #333;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
2026-01-28 21:13:27 +08:00
}
}
}
.fortune-banner-wrap {
margin-bottom: 40px;
}
.wallpaper-banner {
background: #fafafa;
border-radius: 24rpx;
padding: 30rpx;
display: flex;
align-items: center;
margin-bottom: 60rpx;
border: 1px solid #f5f5f5;
}
.banner-icon {
width: 80rpx;
height: 80rpx;
background: #fff;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 24rpx;
}
.banner-icon text {
font-size: 40rpx;
color: #ff3b30;
}
.banner-content {
flex: 1;
}
.banner-title {
font-size: 30rpx;
font-weight: bold;
color: #333;
display: block;
margin-bottom: 8rpx;
}
.banner-desc {
font-size: 22rpx;
color: #999;
}
.banner-arrow {
font-size: 36rpx;
color: #ccc;
}
.footer {
text-align: center;
padding-bottom: 20px;
.footer-divider {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 8px;
.line {
width: 40px;
height: 1px;
background: #e0e0e0;
}
.footer-text {
margin: 0 12px;
font-size: 12px;
color: #999;
letter-spacing: 1px;
font-weight: 600;
}
}
.footer-sub {
font-size: 10px;
color: #ccc;
}
}
</style>