Files
spring-festival-greetings/pages/mine/greeting.vue

564 lines
12 KiB
Vue
Raw Normal View History

2026-01-28 22:44:47 +08:00
<template>
2026-02-03 10:25:47 +08:00
<view class="greeting-page">
<NavBar title="我的新春祝福" background="transparent" />
2026-01-28 22:44:47 +08:00
<!-- Header Stats -->
<view class="header-stats">
<view class="stats-card">
<view class="stats-left">
<view class="icon-circle">
2026-02-03 10:25:47 +08:00
<text class="sparkle-emoji"></text>
2026-01-28 22:44:47 +08:00
</view>
<view class="stats-info">
<text class="label">已累计创作</text>
<view class="value-wrap">
<text class="value">{{ totalCount }}</text>
<text class="unit">份祝福</text>
</view>
</view>
</view>
<view class="divider"></view>
<view class="stats-right">
<text class="label">马年运势</text>
<text class="value red-text">一马当先</text>
</view>
</view>
</view>
<!-- List Section -->
<view class="list-section">
<view class="section-header">
2026-02-03 10:25:47 +08:00
<text class="section-title">祝福库</text>
2026-01-28 22:44:47 +08:00
</view>
2026-02-03 10:25:47 +08:00
<view class="list-grid">
2026-02-03 11:31:18 +08:00
<view
v-for="item in list"
:key="item.id"
class="card-item"
@tap="onPreview(item)"
>
2026-02-03 10:25:47 +08:00
<view class="card-image-wrap">
<image :src="item.imageUrl" mode="aspectFill" class="card-img" />
<view class="year-badge" v-if="item.year">{{ item.year }}</view>
<view class="draft-overlay" v-if="item.status === 'draft'">
<text class="lock-icon">🔒</text>
2026-01-28 22:54:40 +08:00
</view>
2026-02-03 10:25:47 +08:00
</view>
<view class="card-info">
2026-02-03 11:17:58 +08:00
<view class="card-title">{{ getTitle(item) }}</view>
2026-02-03 10:25:47 +08:00
<view class="card-date">{{ formatDate(item.updatedAt) }}</view>
<view class="card-footer">
<view class="tag" :class="getTagClass(item)">{{
getTagText(item)
}}</view>
<view class="actions">
2026-02-03 11:31:18 +08:00
<button
class="action-btn"
open-type="share"
:data-item="item"
@tap.stop
>
2026-02-03 10:25:47 +08:00
<text class="action-emoji">🔗</text>
2026-02-03 11:26:47 +08:00
</button>
2026-02-03 11:01:58 +08:00
<!-- <view class="action-btn" @tap.stop="onMore(item)">
2026-02-03 10:25:47 +08:00
<text class="action-emoji"></text>
2026-02-03 11:01:58 +08:00
</view> -->
2026-01-28 22:44:47 +08:00
</view>
2026-01-28 22:54:40 +08:00
</view>
</view>
2026-01-28 22:44:47 +08:00
</view>
2026-02-03 10:25:47 +08:00
</view>
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
<!-- Loading State -->
<view class="loading-state" v-if="loading">
<text>加载中...</text>
</view>
<view class="empty-state" v-if="!loading && list.length === 0">
<text>暂无祝福记录</text>
</view>
<view class="footer-note" v-if="!loading && list.length > 0">
<text>2026 丙午马年 · 祝福管理助手</text>
</view>
</view>
<!-- FAB -->
<view class="fab-btn" @tap="onMake">
<view class="fab-content">
<text class="fab-emoji"></text>
<text>新春制作</text>
2026-01-28 22:44:47 +08:00
</view>
</view>
</view>
</template>
<script setup>
import { ref, onMounted } from "vue";
2026-02-03 11:26:47 +08:00
import {
onPullDownRefresh,
onReachBottom,
onShareAppMessage,
} from "@dcloudio/uni-app";
2026-01-28 22:44:47 +08:00
import { getMyCard } from "@/api/mine.js";
2026-01-31 23:31:40 +08:00
import NavBar from "@/components/NavBar/NavBar.vue";
2026-02-03 11:26:47 +08:00
import { getShareToken } from "@/utils/common.js";
2026-01-28 22:44:47 +08:00
const list = ref([]);
const page = ref(1);
const loading = ref(false);
const hasMore = ref(true);
const totalCount = ref(0);
onMounted(() => {
fetchList(true);
});
onPullDownRefresh(() => {
2026-02-03 10:25:47 +08:00
fetchList(true);
2026-01-28 22:44:47 +08:00
});
onReachBottom(() => {
2026-02-03 10:25:47 +08:00
if (hasMore.value && !loading.value) {
fetchList();
}
2026-01-28 22:44:47 +08:00
});
2026-02-03 11:26:47 +08:00
onShareAppMessage(async (options) => {
if (options.from === "button") {
2026-02-05 23:43:51 +08:00
const shareToken = await getShareToken(
2026-02-03 11:26:47 +08:00
"card_generate",
options?.target?.dataset?.item?.id,
);
return {
title: "我刚做了一张祝福卡片,送给你",
2026-02-05 23:43:51 +08:00
path: "/pages/detail/index?shareToken=" + shareToken,
2026-02-03 11:26:47 +08:00
imageUrl:
2026-02-08 16:33:21 +08:00
"https://file.lihailezzc.com/resource/bf9faeddb7ff55a5cd3d435779d56556.png",
2026-02-03 11:26:47 +08:00
};
} else {
2026-02-05 23:43:51 +08:00
const shareToken = await getShareToken("greeting_page", "");
2026-02-03 11:26:47 +08:00
return {
title: "新春祝福",
2026-02-05 23:43:51 +08:00
path: `/pages/index/index?shareToken=${shareToken}`,
2026-02-03 11:26:47 +08:00
imageUrl:
2026-02-08 15:01:42 +08:00
"https://file.lihailezzc.com/resource/8dd026d76ef7a63d123b7fd698fb989b.png",
2026-02-03 11:26:47 +08:00
};
}
});
2026-01-28 22:44:47 +08:00
const fetchList = async (reset = false) => {
if (loading.value) return;
if (reset) {
page.value = 1;
hasMore.value = true;
}
if (!hasMore.value) return;
loading.value = true;
try {
const res = await getMyCard(page.value);
const dataList = res?.list || [];
totalCount.value = res?.totalCount || 0;
if (reset) {
list.value = dataList;
} else {
list.value = [...list.value, ...dataList];
}
hasMore.value = res.hasNext;
if (hasMore.value) {
page.value++;
}
} catch (e) {
console.error("Failed to fetch greeting list", e);
} finally {
loading.value = false;
uni.stopPullDownRefresh();
}
};
const formatDate = (dateStr) => {
if (!dateStr) return "";
const date = new Date(dateStr);
const y = date.getFullYear();
const m = String(date.getMonth() + 1).padStart(2, "0");
const d = String(date.getDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
};
2026-02-03 10:25:47 +08:00
const getTagText = (item) => {
2026-02-03 11:01:58 +08:00
// if (item.status === "draft") return "草稿";
return item?.title?.name || item.festival || "新春快乐";
};
const getTitle = (item) => {
2026-02-03 11:17:58 +08:00
const title =
(item?.blessingTo || "祝您") + (item?.content?.content || "新春快乐");
return title.length > 10 ? title.substring(0, 10) + "..." : title;
2026-02-03 10:25:47 +08:00
};
const getTagClass = (item) => {
if (item.status === "draft") return "tag-draft";
const tagMap = {
2026-02-03 11:01:58 +08:00
万事如意: "tag-spring",
新春快乐: "tag-gold",
新春大吉: "tag-horse",
钱包鼓鼓: "tag-ink",
福气旺旺: "tag-spring",
龙马精神: "tag-horse",
马年纳祥: "tag-horse",
福马迎春: "tag-horse",
2026-02-03 10:25:47 +08:00
};
2026-02-03 11:01:58 +08:00
return tagMap[item?.title?.name || item.festival] || "tag-gold";
2026-02-03 10:25:47 +08:00
};
2026-02-03 11:17:58 +08:00
const onPreview = (item) => {
if (!item.imageUrl) return;
uni.previewImage({
urls: [item.imageUrl],
current: item.imageUrl,
2026-02-03 10:25:47 +08:00
});
};
const onMake = () => {
uni.switchTab({
url: "/pages/make/index",
});
};
2026-02-03 11:26:47 +08:00
// const onShare = (item) => {
// uni.showToast({ title: "分享功能开发中", icon: "none" });
// };
2026-02-03 10:25:47 +08:00
const onMore = (item) => {
uni.showActionSheet({
itemList: ["编辑", "删除"],
success: (res) => {
if (res.tapIndex === 0) {
// Edit
} else if (res.tapIndex === 1) {
onDelete(item);
}
},
});
};
2026-01-28 22:54:40 +08:00
const onDelete = (item) => {
uni.showModal({
title: "提示",
content: "确定要删除这条祝福吗?",
success: (res) => {
if (res.confirm) {
list.value = list.value.filter((i) => i.id !== item.id);
totalCount.value = Math.max(0, totalCount.value - 1);
uni.showToast({ title: "删除成功", icon: "none" });
}
},
});
2026-01-28 22:44:47 +08:00
};
</script>
<style lang="scss" scoped>
.greeting-page {
min-height: 100vh;
2026-02-03 10:25:47 +08:00
background: #fbf9f2;
padding-bottom: 120rpx;
2026-01-28 22:44:47 +08:00
box-sizing: border-box;
}
.header-stats {
2026-02-03 10:25:47 +08:00
padding: 30rpx 40rpx;
margin-top: 20rpx;
2026-01-28 22:44:47 +08:00
.stats-card {
background: #fff;
2026-02-03 10:25:47 +08:00
border-radius: 40rpx;
padding: 40rpx;
2026-01-28 22:44:47 +08:00
display: flex;
align-items: center;
justify-content: space-between;
2026-02-03 10:25:47 +08:00
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.02);
2026-01-28 22:44:47 +08:00
.stats-left {
display: flex;
align-items: center;
.icon-circle {
2026-02-03 10:25:47 +08:00
width: 100rpx;
height: 100rpx;
2026-01-28 22:44:47 +08:00
border-radius: 50%;
2026-02-03 10:25:47 +08:00
background: #fff5f5;
2026-01-28 22:44:47 +08:00
display: flex;
align-items: center;
justify-content: center;
2026-02-03 10:25:47 +08:00
margin-right: 24rpx;
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
.sparkle-emoji {
font-size: 50rpx;
2026-01-28 22:44:47 +08:00
}
}
.stats-info {
display: flex;
flex-direction: column;
.label {
2026-02-03 10:25:47 +08:00
font-size: 24rpx;
2026-01-28 22:44:47 +08:00
color: #999;
2026-02-03 10:25:47 +08:00
margin-bottom: 8rpx;
2026-01-28 22:44:47 +08:00
}
.value-wrap {
display: flex;
align-items: baseline;
.value {
2026-02-03 10:25:47 +08:00
font-size: 40rpx;
2026-01-28 22:44:47 +08:00
font-weight: bold;
color: #333;
2026-02-03 10:25:47 +08:00
margin-right: 8rpx;
2026-01-28 22:44:47 +08:00
}
.unit {
2026-02-03 10:25:47 +08:00
font-size: 24rpx;
2026-01-28 22:44:47 +08:00
color: #666;
}
}
}
}
.divider {
2026-02-03 10:25:47 +08:00
width: 1rpx;
height: 80rpx;
background: #f0f0f0;
2026-01-28 22:44:47 +08:00
}
.stats-right {
display: flex;
flex-direction: column;
align-items: center;
2026-02-03 10:25:47 +08:00
padding-left: 20rpx;
2026-01-28 22:44:47 +08:00
.label {
2026-02-03 10:25:47 +08:00
font-size: 24rpx;
2026-01-28 22:44:47 +08:00
color: #999;
2026-02-03 10:25:47 +08:00
margin-bottom: 12rpx;
2026-01-28 22:44:47 +08:00
}
.value {
2026-02-03 10:25:47 +08:00
font-size: 32rpx;
font-weight: bold;
2026-01-28 22:44:47 +08:00
&.red-text {
2026-02-03 10:25:47 +08:00
color: #ff4d4f;
2026-01-28 22:44:47 +08:00
}
}
}
}
}
.list-section {
2026-02-03 10:25:47 +08:00
padding: 0 40rpx;
2026-01-28 22:44:47 +08:00
.section-header {
2026-02-03 10:25:47 +08:00
margin: 40rpx 0 24rpx;
2026-01-28 22:44:47 +08:00
.section-title {
2026-02-03 10:25:47 +08:00
font-size: 32rpx;
font-weight: bold;
color: #7c6d5d;
2026-01-28 22:44:47 +08:00
}
}
2026-02-03 10:25:47 +08:00
.list-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 30rpx;
2026-01-28 22:44:47 +08:00
}
}
2026-02-03 10:25:47 +08:00
.card-item {
background: #fff;
border-radius: 48rpx;
2026-01-28 22:44:47 +08:00
overflow: hidden;
2026-02-03 10:25:47 +08:00
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.03);
.card-image-wrap {
position: relative;
width: 100%;
padding-bottom: 133%; // 3:4 aspect ratio
background: #fdf3e7;
.card-img {
position: absolute;
top: 20rpx;
left: 20rpx;
right: 20rpx;
bottom: 20rpx;
width: auto;
height: auto;
border-radius: 12rpx;
}
2026-01-28 22:54:40 +08:00
2026-02-03 10:25:47 +08:00
.year-badge {
position: absolute;
top: 20rpx;
left: 20rpx;
background: #ff4d4f;
color: #fff;
font-size: 20rpx;
padding: 4rpx 12rpx;
border-radius: 8rpx;
font-weight: bold;
}
2026-01-28 22:54:40 +08:00
2026-02-03 10:25:47 +08:00
.draft-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.05);
display: flex;
align-items: center;
justify-content: center;
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
.icon {
font-size: 40rpx;
opacity: 0.3;
}
}
2026-01-28 22:44:47 +08:00
}
2026-02-03 10:25:47 +08:00
.card-info {
padding: 24rpx;
2026-01-28 22:44:47 +08:00
.card-title {
2026-02-03 10:25:47 +08:00
font-size: 28rpx;
font-weight: bold;
2026-01-28 22:44:47 +08:00
color: #333;
2026-02-03 10:25:47 +08:00
margin-bottom: 8rpx;
2026-01-28 22:44:47 +08:00
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
.card-date {
2026-02-03 10:25:47 +08:00
font-size: 22rpx;
2026-01-28 22:44:47 +08:00
color: #999;
2026-02-03 10:25:47 +08:00
margin-bottom: 20rpx;
2026-01-28 22:44:47 +08:00
}
2026-02-03 10:25:47 +08:00
.card-footer {
2026-01-28 22:44:47 +08:00
display: flex;
2026-02-03 10:25:47 +08:00
justify-content: space-between;
align-items: center;
2026-01-28 22:44:47 +08:00
.tag {
2026-02-03 10:25:47 +08:00
font-size: 20rpx;
padding: 4rpx 16rpx;
border-radius: 20rpx;
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
&.tag-gold {
background: #fff8e6;
color: #ffb800;
2026-01-28 22:44:47 +08:00
}
2026-02-03 10:25:47 +08:00
&.tag-horse {
background: #fff1f0;
color: #ff4d4f;
}
&.tag-ink {
background: #f0f5ff;
color: #2f54eb;
}
&.tag-draft {
background: #f5f5f5;
color: #bfbfbf;
2026-01-28 22:44:47 +08:00
}
2026-02-03 10:25:47 +08:00
&.tag-spring {
background: #fff1f0;
color: #ff4d4f;
}
}
.actions {
display: flex;
gap: 16rpx;
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
.action-btn {
2026-02-03 11:31:18 +08:00
background: transparent;
border: none;
padding: 0;
margin: 0;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
outline: none;
&::after {
border: none;
}
2026-02-03 10:25:47 +08:00
.action-emoji {
font-size: 32rpx;
opacity: 0.6;
}
2026-01-28 22:44:47 +08:00
}
}
}
}
2026-02-03 10:25:47 +08:00
}
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
.fab-btn {
position: fixed;
bottom: 60rpx;
left: 50%;
transform: translateX(-50%);
z-index: 100;
.fab-content {
background: #ff4d4f;
padding: 20rpx 48rpx;
border-radius: 100rpx;
2026-01-28 22:44:47 +08:00
display: flex;
2026-02-03 10:25:47 +08:00
align-items: center;
box-shadow: 0 10rpx 30rpx rgba(255, 77, 79, 0.3);
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
.fab-emoji {
font-size: 36rpx;
margin-right: 12rpx;
}
2026-01-28 22:44:47 +08:00
2026-02-03 10:25:47 +08:00
text {
color: #fff;
font-size: 32rpx;
font-weight: bold;
2026-01-28 22:44:47 +08:00
}
}
2026-02-03 10:25:47 +08:00
&:active {
opacity: 0.9;
transform: translateX(-50%) scale(0.95);
}
}
.footer-note {
text-align: center;
padding: 60rpx 0 40rpx;
font-size: 24rpx;
color: #ccc;
2026-01-28 22:44:47 +08:00
}
.loading-state,
2026-02-03 10:25:47 +08:00
.empty-state {
grid-column: span 2;
2026-01-28 22:44:47 +08:00
text-align: center;
2026-02-03 10:25:47 +08:00
padding: 100rpx 0;
2026-01-28 22:44:47 +08:00
color: #999;
2026-02-03 10:25:47 +08:00
font-size: 28rpx;
2026-01-28 22:44:47 +08:00
}
</style>