406 lines
12 KiB
Vue
406 lines
12 KiB
Vue
<template>
|
|
<view class="family-page" :class="`feed-state--${feedState}`">
|
|
<ModulePageBackground module="family" />
|
|
<view class="family-page__header"
|
|
><PageHeader
|
|
root
|
|
title="家族动态"
|
|
:action="hasValidContext ? '发布' : ''"
|
|
@action="toPublish"
|
|
/></view>
|
|
<view class="feed-content">
|
|
<view class="feed-heading"
|
|
><text>家族圈</text><text>家宴、通知与共同记忆</text></view
|
|
>
|
|
<view v-if="hasValidContext" class="feed-shortcuts"
|
|
><button
|
|
v-for="item in shortcuts"
|
|
:key="item.key"
|
|
class="feed-shortcut"
|
|
:aria-label="`打开${item.label}`"
|
|
@click="openSection(item.key)"
|
|
><text>{{ item.label }}</text></button
|
|
></view
|
|
>
|
|
<AppLoading
|
|
v-if="feedState === 'loading'"
|
|
text="正在读取家族动态"
|
|
description="请稍候,正在整理家族近况。"
|
|
/>
|
|
<view v-else-if="feedState === 'list'" class="feed-list">
|
|
<view
|
|
v-for="item in feeds"
|
|
:key="item.id"
|
|
class="feed-card"
|
|
@click="openFeed(item)"
|
|
>
|
|
<text class="feed-card__publisher">{{ item.publisher }}</text>
|
|
<text class="feed-card__content">{{ feedPreview(item.content) }}</text>
|
|
<FamilyFeedMedia :files="item.mediaFiles" />
|
|
<text class="feed-card__meta">{{ feedTypeLabel(item.type) }} · {{ formatMinuteTimestamp(item.time) }}</text>
|
|
<text v-if="item.recommendationReason" class="feed-card__reason">{{ item.recommendationReason }}</text>
|
|
</view>
|
|
<button
|
|
v-if="hasMoreFeeds || loadMoreState === 'loading' || loadMoreState === 'error'"
|
|
class="feed-more"
|
|
:disabled="loadMoreState === 'loading'"
|
|
@click="loadMoreFeeds"
|
|
>{{ loadMoreLabel }}</button>
|
|
</view>
|
|
<view v-else class="feed-state-card"
|
|
><view class="feed-state-card__copy"
|
|
><text>{{ stateCopy.title }}</text
|
|
><text>{{ stateCopy.copy }}</text></view
|
|
></view
|
|
>
|
|
<view class="feed-action" @click="handlePrimaryAction"
|
|
><text>{{ stateCopy.action }}</text></view
|
|
>
|
|
</view>
|
|
<AppTabbar active="family" />
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, ref } from "vue";
|
|
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
|
|
import AppLoading from "@/components/AppLoading.vue";
|
|
import AppTabbar from "@/components/AppTabbar.vue";
|
|
import FamilyFeedMedia from "@/components/family/FeedMedia.vue";
|
|
import ModulePageBackground from "@/components/ModulePageBackground.vue";
|
|
import PageHeader from "@/components/PageHeader.vue";
|
|
import {
|
|
createRequestController,
|
|
isRequestCancelled
|
|
} from "@/services/api/request-controller.js";
|
|
import { familyFeedApi } from "@/services/api/family-feed-service.js";
|
|
import { formatMinuteTimestamp } from "@/utils/display-time.js";
|
|
import { genealogyContext } from "@/utils/genealogy/context.js";
|
|
import { goRoot, openPage } from "@/utils/navigation/gateway.js";
|
|
|
|
const genealogyId = ref("");
|
|
const hasValidContext = ref(false);
|
|
const feedState = ref("loading");
|
|
const feeds = ref([]);
|
|
const FEED_PAGE_SIZE = 20;
|
|
const totalFeedCount = ref(0);
|
|
const currentFeedPage = ref(1);
|
|
const loadMoreState = ref("idle");
|
|
const hasMoreFeeds = computed(
|
|
() => feedState.value === "list" && feeds.value.length < totalFeedCount.value,
|
|
);
|
|
const loadMoreLabel = computed(() => {
|
|
if (loadMoreState.value === "loading") return "正在加载";
|
|
if (loadMoreState.value === "error") return "加载失败,重新加载";
|
|
return "继续加载";
|
|
});
|
|
let active = true;
|
|
let skipInitialShowRefresh = true;
|
|
const feedListRequestController = createRequestController();
|
|
const recommendationRequestController = createRequestController();
|
|
const feedTypeLabel = (type) =>
|
|
String(type || "")
|
|
.trim()
|
|
.toLowerCase() === "text"
|
|
? "文字动态"
|
|
: "家族动态";
|
|
const feedPreview = (content) => {
|
|
const text = String(content || "").trim();
|
|
return text.length > 96 ? `${text.slice(0, 96).trimEnd()}…` : text;
|
|
};
|
|
const shortcuts = [
|
|
{ key: "articles", label: "谱文" },
|
|
{ key: "albums", label: "相册" },
|
|
{ key: "rituals", label: "礼仪" },
|
|
{ key: "memos", label: "备忘" },
|
|
{ key: "people", label: "人物录" },
|
|
{ key: "gifts", label: "贺礼簿" },
|
|
{ key: "merits", label: "功德录" },
|
|
{ key: "videos", label: "家族视频" },
|
|
];
|
|
const stateCopy = computed(() =>
|
|
!hasValidContext.value
|
|
? {
|
|
title: "请先选择有效家谱",
|
|
copy: "家族动态必须归属明确家谱。",
|
|
action: "返回我的家谱",
|
|
}
|
|
: feedState.value === "empty"
|
|
? {
|
|
title: "还没有家族动态",
|
|
copy: "发布第一条动态,记录家族此刻。",
|
|
action: "发布家族动态",
|
|
}
|
|
: feedState.value === "error"
|
|
? {
|
|
title: "动态暂时无法读取",
|
|
copy: "请稍后重新读取。",
|
|
action: "重新读取",
|
|
}
|
|
: { title: "", copy: "", action: "发布家族动态" },
|
|
);
|
|
const loadFeeds = async () => {
|
|
if (!hasValidContext.value) return;
|
|
feedState.value = "loading";
|
|
loadMoreState.value = "idle";
|
|
currentFeedPage.value = 1;
|
|
feedListRequestController.abort();
|
|
recommendationRequestController.abort();
|
|
try {
|
|
const [pageResult, recommendationResult] = await Promise.allSettled([
|
|
familyFeedApi.getFeedPage(
|
|
genealogyId.value,
|
|
{ pageNum: 1, pageSize: FEED_PAGE_SIZE },
|
|
{ requestController: feedListRequestController },
|
|
),
|
|
familyFeedApi.getFeedRecommendations(genealogyId.value, {
|
|
requestController: recommendationRequestController,
|
|
}),
|
|
]);
|
|
if (pageResult.status === "rejected") throw pageResult.reason;
|
|
if (!active) return;
|
|
const recommendations =
|
|
recommendationResult.status === "fulfilled"
|
|
? recommendationResult.value
|
|
: [];
|
|
const reasons = new Map(
|
|
recommendations.map((item) => [String(item.id), item.recommendationReason]),
|
|
);
|
|
feeds.value = pageResult.value.rows.map((item) => ({
|
|
...item,
|
|
recommendationReason: reasons.get(String(item.id)) || "",
|
|
}));
|
|
totalFeedCount.value = pageResult.value.total;
|
|
loadMoreState.value =
|
|
feeds.value.length < totalFeedCount.value ? "idle" : "done";
|
|
feedState.value = feeds.value.length ? "list" : "empty";
|
|
} catch (error) {
|
|
if (!active || isRequestCancelled(error)) return;
|
|
feedState.value = "error";
|
|
}
|
|
};
|
|
const loadMoreFeeds = async () => {
|
|
if (!hasMoreFeeds.value || loadMoreState.value === "loading") return;
|
|
loadMoreState.value = "loading";
|
|
try {
|
|
const nextPage = currentFeedPage.value + 1;
|
|
const page = await familyFeedApi.getFeedPage(
|
|
genealogyId.value,
|
|
{ pageNum: nextPage, pageSize: FEED_PAGE_SIZE },
|
|
{ requestController: feedListRequestController },
|
|
);
|
|
if (!active) return;
|
|
const knownIds = new Set(feeds.value.map((item) => String(item.id)));
|
|
feeds.value = feeds.value.concat(
|
|
page.rows.filter((item) => !knownIds.has(String(item.id))),
|
|
);
|
|
currentFeedPage.value = nextPage;
|
|
totalFeedCount.value = page.total;
|
|
loadMoreState.value =
|
|
feeds.value.length < totalFeedCount.value ? "idle" : "done";
|
|
} catch (error) {
|
|
if (!active || isRequestCancelled(error)) return;
|
|
loadMoreState.value = "error";
|
|
}
|
|
};
|
|
onLoad((query) => {
|
|
const supplied = Object.prototype.hasOwnProperty.call(
|
|
query || {},
|
|
"genealogyId",
|
|
);
|
|
genealogyId.value = supplied
|
|
? String(query.genealogyId || "")
|
|
: String(genealogyContext.getCurrentGenealogyId() || "");
|
|
hasValidContext.value = /^[1-9]\d*$/.test(genealogyId.value);
|
|
if (hasValidContext.value) void loadFeeds();
|
|
else feedState.value = "error";
|
|
});
|
|
onShow(() => {
|
|
if (skipInitialShowRefresh) {
|
|
skipInitialShowRefresh = false;
|
|
return;
|
|
}
|
|
if (hasValidContext.value) void loadFeeds();
|
|
});
|
|
onUnload(() => {
|
|
active = false;
|
|
feedListRequestController.abort();
|
|
recommendationRequestController.abort();
|
|
});
|
|
const toPublish = () =>
|
|
hasValidContext.value
|
|
? openPage("F02", { genealogyId: genealogyId.value, mode: "create" }, "F01")
|
|
: goRoot("G01");
|
|
const openFeed = (item) =>
|
|
openPage("F03", { genealogyId: genealogyId.value, feedId: item.id }, "F01");
|
|
const openSection = (key) => {
|
|
const routes = {
|
|
articles: "F04",
|
|
albums: "F07",
|
|
rituals: "R05",
|
|
memos: "R10",
|
|
people: "R01",
|
|
gifts: "R03",
|
|
merits: "R11",
|
|
videos: "F10",
|
|
};
|
|
return openPage(routes[key], { genealogyId: genealogyId.value }, "F01");
|
|
};
|
|
const handlePrimaryAction = () =>
|
|
feedState.value === "error" ? loadFeeds() : toPublish();
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
@import "../../styles/adaptive-frame-profiles.scss";
|
|
.family-page {
|
|
display: flex;
|
|
min-height: 100vh;
|
|
flex-direction: column;
|
|
background: $paper;
|
|
}
|
|
.family-page__header,
|
|
.feed-content {
|
|
z-index: 1;
|
|
}
|
|
.feed-content {
|
|
flex: 1;
|
|
padding: 24rpx 24rpx 190rpx;
|
|
}
|
|
.feed-heading text {
|
|
display: block;
|
|
}
|
|
.feed-heading text:first-child {
|
|
color: $ink;
|
|
font-family: STKaiti, KaiTi, serif;
|
|
font-size: clamp(17px, 31rpx, 22px);
|
|
font-weight: 700;
|
|
}
|
|
.feed-heading text:last-child {
|
|
margin-top: 6rpx;
|
|
color: $ink-muted;
|
|
font-size: clamp(14px, 23rpx, 17px);
|
|
}
|
|
.feed-shortcuts {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
gap: 8rpx;
|
|
margin-top: 15rpx;
|
|
}
|
|
.feed-shortcut {
|
|
box-sizing: border-box;
|
|
min-height: 48px;
|
|
margin: 0;
|
|
padding: 0;
|
|
border: 1rpx solid rgba(181, 137, 63, 0.45);
|
|
border-radius: 8rpx;
|
|
background: rgba(255, 252, 244, 0.58);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.feed-shortcut text {
|
|
color: $ink;
|
|
font-size: clamp(14px, 22rpx, 17px);
|
|
font-weight: 700;
|
|
}
|
|
.feed-list {
|
|
margin-top: 22rpx;
|
|
}
|
|
.feed-card,
|
|
.feed-state-card {
|
|
@include adaptive-family-letter;
|
|
box-sizing: border-box;
|
|
margin-top: 16rpx;
|
|
padding: 30rpx;
|
|
}
|
|
.feed-card text,
|
|
.feed-state-card text {
|
|
display: block;
|
|
}
|
|
.feed-card__publisher {
|
|
color: $brand-red;
|
|
font-size: clamp(14px, 22rpx, 17px);
|
|
}
|
|
.feed-card__content {
|
|
display: -webkit-box;
|
|
margin-top: 12rpx;
|
|
overflow: hidden;
|
|
color: $ink;
|
|
font-size: clamp(16px, 28rpx, 20px);
|
|
line-height: 1.55;
|
|
overflow-wrap: anywhere;
|
|
-webkit-box-orient: vertical;
|
|
-webkit-line-clamp: 3;
|
|
}
|
|
.feed-card__meta {
|
|
margin-top: 12rpx;
|
|
color: $ink-muted;
|
|
font-size: clamp(13px, 21rpx, 16px);
|
|
}
|
|
.feed-shortcut::after {
|
|
border: 0;
|
|
}
|
|
.feed-shortcut:active {
|
|
background: rgba(181, 137, 63, 0.1);
|
|
}
|
|
.feed-card__reason {
|
|
margin-top: 8rpx;
|
|
color: #9a6555;
|
|
font-size: clamp(12px, 20rpx, 15px);
|
|
}
|
|
.feed-more {
|
|
@include adaptive-scroll-button(secondary);
|
|
display: block;
|
|
width: 420rpx;
|
|
max-width: 100%;
|
|
min-height: 76rpx;
|
|
margin: 22rpx auto 0;
|
|
padding: 0 24rpx;
|
|
border: 0;
|
|
color: $ink;
|
|
font-size: clamp(14px, 22rpx, 17px);
|
|
font-weight: 700;
|
|
line-height: 76rpx;
|
|
}
|
|
.feed-more::after {
|
|
border: 0;
|
|
}
|
|
.feed-more[disabled] {
|
|
opacity: 0.62;
|
|
}
|
|
.feed-state-card {
|
|
min-height: 230rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
text-align: center;
|
|
}
|
|
.feed-state-card text:first-child {
|
|
color: $ink;
|
|
font-size: clamp(17px, 31rpx, 22px);
|
|
font-weight: 700;
|
|
}
|
|
.feed-state-card text:last-child {
|
|
margin-top: 13rpx;
|
|
color: $ink-muted;
|
|
font-size: clamp(14px, 23rpx, 17px);
|
|
line-height: 1.45;
|
|
}
|
|
.feed-action {
|
|
@include adaptive-scroll-button(primary);
|
|
width: 514rpx;
|
|
max-width: 100%;
|
|
min-height: 76rpx;
|
|
margin: 19rpx auto;
|
|
}
|
|
.feed-action text {
|
|
display: flex;
|
|
min-height: 76rpx;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: #fff9ed;
|
|
font-size: clamp(15px, 24rpx, 18px);
|
|
font-weight: 700;
|
|
}
|
|
</style>
|