u
This commit is contained in:
1 parent
513a991b57
commit
8f8e8d03c8
22 files changed
+2212
-213
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { loadDataApi, saveDataApi, getUniqueIdApi } from "@/request/api";
|
||||
import { loadDataApi, loadDataPageApi, saveDataApi, getUniqueIdApi } from "@/request/api";
|
||||
|
||||
export type FeedType = "join" | "rename" | "bill" | "fav";
|
||||
export type FeedType = "family" | "finance" | "favorite";
|
||||
|
||||
export interface FeedRecord {
|
||||
id: number;
|
||||
@@ -12,25 +12,7 @@ export interface FeedRecord {
|
||||
create_time: string;
|
||||
}
|
||||
|
||||
/** 获取用户在家庭中的昵称(来自 b_family_member,非 b_user) */
|
||||
export async function getFamilyMemberNickname(
|
||||
familyId: number,
|
||||
userId: number,
|
||||
): Promise<string> {
|
||||
const res = await loadDataApi({
|
||||
view_name: "b_family_member",
|
||||
search_condition: "family_id = ? AND user_id = ?",
|
||||
search_columns: ["nickname"],
|
||||
order_by: "",
|
||||
args: [familyId, userId],
|
||||
});
|
||||
if (res.isSuccess && res.data?.length > 0) {
|
||||
return res.data[0].nickname || "成员";
|
||||
}
|
||||
return "成员";
|
||||
}
|
||||
|
||||
/** 写入一条动态 — content 直接包含所有展示信息,用 {nickname} 占位 */
|
||||
/** 写入一条动态 */
|
||||
export async function recordFeed(
|
||||
familyId: number,
|
||||
userId: number,
|
||||
@@ -60,7 +42,7 @@ export async function recordFeed(
|
||||
]);
|
||||
}
|
||||
|
||||
/** 加载家庭动态列表 — 自动替换 {nickname} 占位符 */
|
||||
/** 加载家庭动态列表 */
|
||||
export async function loadFeeds(familyId: number): Promise<FeedRecord[]> {
|
||||
const res = await loadDataApi({
|
||||
view_name: "b_family_feed",
|
||||
@@ -69,18 +51,49 @@ export async function loadFeeds(familyId: number): Promise<FeedRecord[]> {
|
||||
search_columns: ["id", "family_id", "user_id", "type", "content", "meta", "create_time"],
|
||||
args: [familyId],
|
||||
});
|
||||
const feeds = (res.data || []) as FeedRecord[];
|
||||
return (res.data || []) as FeedRecord[];
|
||||
}
|
||||
|
||||
// 批量加载昵称:收集唯一 user_id,逐个查 b_family_member
|
||||
const uniqueUserIds = [...new Set(feeds.map((f) => f.user_id))];
|
||||
const nickMap = new Map<number, string>();
|
||||
for (const uid of uniqueUserIds) {
|
||||
nickMap.set(uid, await getFamilyMemberNickname(familyId, uid));
|
||||
/** 分页加载家庭动态列表 */
|
||||
export async function loadFeedsPage(
|
||||
familyId: number,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
type?: string,
|
||||
dateFrom?: string,
|
||||
dateTo?: string,
|
||||
): Promise<{ rows: FeedRecord[]; total: number; page: number; page_size: number }> {
|
||||
const conditions: string[] = ["family_id = ?"];
|
||||
const args: any[] = [familyId];
|
||||
|
||||
if (type) {
|
||||
conditions.push("type = ?");
|
||||
args.push(type);
|
||||
}
|
||||
|
||||
// 替换 {nickname} 占位符,保证每次展示都是最新昵称
|
||||
return feeds.map((f) => ({
|
||||
...f,
|
||||
content: f.content.replace(/\{nickname\}/g, nickMap.get(f.user_id) || "成员"),
|
||||
}));
|
||||
if (dateFrom) {
|
||||
conditions.push("create_time >= ?");
|
||||
args.push(dateFrom);
|
||||
}
|
||||
|
||||
if (dateTo) {
|
||||
conditions.push("create_time <= ?");
|
||||
args.push(dateTo + " 23:59:59");
|
||||
}
|
||||
|
||||
const res = await loadDataPageApi({
|
||||
view_name: "b_family_feed",
|
||||
search_condition: conditions.join(" AND "),
|
||||
order_by: "create_time DESC",
|
||||
search_columns: ["id", "family_id", "user_id", "type", "content", "meta", "create_time"],
|
||||
args,
|
||||
page,
|
||||
page_size: pageSize,
|
||||
});
|
||||
|
||||
if (!res.isSuccess || !res.data) {
|
||||
return { rows: [], total: 0, page, page_size: pageSize };
|
||||
}
|
||||
|
||||
return { rows: res.data.rows as FeedRecord[], total: res.data.total, page: res.data.page, page_size: res.data.page_size };
|
||||
}
|
||||
Reference in new issue
Block a user