(function (root, factory) {
// 成长记录模块同时支持浏览器页面和 Node 单元测试。
if (typeof module === 'object' && module.exports) {
module.exports = factory(root);
return;
}
root.GrowthPages = factory(root);
if (root.document) {
root.document.addEventListener('DOMContentLoaded', function () {
root.GrowthPages.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-growth-page], [data-growth-edit-page]');
return getQueryParam(search, 'genealogyId') ||
(page && page.getAttribute('data-genealogy-id')) ||
getQueryParam(search, 'id') ||
'';
}
function getCurrentRecordId() {
var search = root.location && root.location.search;
return getQueryParam(search, 'recordId') || '';
}
function trimOrUndefined(value) {
var text = String(value === undefined || value === null ? '' : value).trim();
return text || undefined;
}
function toNumber(value, fallback) {
var text = String(value === undefined || value === null ? '' : value).trim();
var number = Number(text);
return text && Number.isFinite(number) ? number : fallback;
}
function buildGrowthBody(values) {
var source = values || {};
return {
lineagePersonId: toNumber(source.lineagePersonId),
recordType: String(source.recordType || '').trim() || 'growth',
recordTitle: String(source.recordTitle || '').trim(),
recordContent: trimOrUndefined(source.recordContent),
recordDate: trimOrUndefined(source.recordDate),
remindTime: trimOrUndefined(source.remindTime),
mediaOssIds: trimOrUndefined(source.mediaOssIds),
sortOrder: toNumber(source.sortOrder, 1),
status: String(source.status || '').trim() || '0'
};
}
function getRecordId(item) {
return pick(item, ['recordId', 'id'], '');
}
function buildGrowthRow(item, genealogyId) {
var recordId = getRecordId(item);
var title = pick(item, ['recordTitle', 'title'], '未命名成长记录');
var type = pick(item, ['recordType', 'type'], 'growth');
var date = pick(item, ['recordDate', 'createTime'], '未记录日期');
return '' +
' ' + escapeHtml(type) + ' · ' + escapeHtml(date) + '' + escapeHtml(title) + '