(function (root, factory) { // 家族圈动态模块同时支持浏览器页面和 Node 单元测试。 if (typeof module === 'object' && module.exports) { module.exports = factory(root); return; } root.FeedPages = factory(root); if (root.document) { root.document.addEventListener('DOMContentLoaded', function () { root.FeedPages.init(); }); } })(typeof globalThis !== 'undefined' ? globalThis : window, function (root) { 'use strict'; var documentRef = root.document; function normalizeList(data) { // 动态分页响应兼容 rows、records、list、data。 if (Array.isArray(data)) return data; if (!data || typeof data !== 'object') return []; if (Array.isArray(data.rows)) return data.rows; if (Array.isArray(data.records)) return data.records; if (Array.isArray(data.list)) return data.list; if (Array.isArray(data.data)) return data.data; return []; } function pick(item, keys, fallback) { var source = item || {}; var index; var value; for (index = 0; index < keys.length; index += 1) { value = source[keys[index]]; if (value !== undefined && value !== null && value !== '') return value; } return fallback || ''; } function escapeHtml(value) { // 动态内容进入 innerHTML 前转义,详情富文本不在这里处理。 return String(value === undefined || value === null ? '' : value) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } function getApi() { return root.GenealogyApi && root.GenealogyApi.defaultClient; } function query(selector, rootNode) { return (rootNode || documentRef).querySelector(selector); } function queryAll(selector, rootNode) { return Array.prototype.slice.call((rootNode || documentRef).querySelectorAll(selector)); } function showMessage(message) { if (root.layui && root.layui.layer) { root.layui.layer.msg(message); return; } root.alert(message); } function getQueryParam(search, name) { var params = new URLSearchParams(String(search || '').replace(/^\?/, '')); return params.get(name) || ''; } function getCurrentGenealogyId() { var search = root.location && root.location.search; var page = query('[data-feed-page], [data-feed-edit-page]'); return getQueryParam(search, 'genealogyId') || (page && page.getAttribute('data-genealogy-id')) || getQueryParam(search, 'id') || ''; } function getCurrentFeedId() { var search = root.location && root.location.search; return getQueryParam(search, 'feedId') || ''; } function trimOrUndefined(value) { var text = String(value === undefined || value === null ? '' : value).trim(); return text || undefined; } function toNumber(value) { var text = String(value === undefined || value === null ? '' : value).trim(); var number = Number(text); return text && Number.isFinite(number) ? number : undefined; } function buildFeedBody(values) { // FamilyFeedBody 来自 APP.openapi.json。 var source = values || {}; return { content: String(source.content || '').trim(), mediaOssIds: trimOrUndefined(source.mediaOssIds), visibility: String(source.visibility || '').trim() || '2', status: String(source.status || '').trim() || '0' }; } function buildCommentBody(values) { // FamilyFeedCommentBody 要求 content 必填。 var source = values || {}; return { parentCommentId: toNumber(source.parentCommentId), replyUserId: toNumber(source.replyUserId), content: String(source.content || '').trim() }; } function getFeedId(item) { return pick(item, ['feedId', 'id'], ''); } function buildFeedRow(item) { var feedId = getFeedId(item); var author = pick(item, ['authorName', 'nickName', 'memberName'], '家族成员'); var content = pick(item, ['content', 'feedContent'], '暂无内容'); var likeCount = pick(item, ['likeCount', 'likes'], '0'); var commentCount = pick(item, ['commentCount', 'comments'], '0'); var createTime = pick(item, ['createTime', 'publishTime', 'updateTime'], '未记录时间'); return '
' + escapeHtml(content) + '
' + escapeHtml(createTime) + ' · ' + escapeHtml(likeCount) + ' 赞 · ' + escapeHtml(commentCount) + ' 评论