75 lines
3.0 KiB
JavaScript
75 lines
3.0 KiB
JavaScript
(function (root, factory) {
|
|
if (typeof module === 'object' && module.exports) {
|
|
module.exports = factory(root);
|
|
return;
|
|
}
|
|
root.ProfileReminderPages = factory(root);
|
|
if (root.document) root.document.addEventListener('DOMContentLoaded', root.ProfileReminderPages.init);
|
|
})(typeof globalThis !== 'undefined' ? globalThis : window, function (root) {
|
|
'use strict';
|
|
|
|
function escapeHtml(value) {
|
|
return String(value === undefined || value === null ? '' : value)
|
|
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
.replace(/"/g, '"').replace(/'/g, ''');
|
|
}
|
|
|
|
function normalizeId(value) {
|
|
var text = String(value === undefined || value === null ? '' : value).trim();
|
|
return /^[1-9][0-9]*$/.test(text) ? text : '';
|
|
}
|
|
|
|
function normalizeReminder(item) {
|
|
var source = item || {};
|
|
var personId = normalizeId(source.personId);
|
|
var displayName = String(source.displayName || '').trim();
|
|
var label = String(source.missingFieldLabel || source.missingField || '').trim();
|
|
|
|
if (!personId || !displayName || !label) return null;
|
|
return {
|
|
personId: personId,
|
|
displayName: displayName,
|
|
label: label,
|
|
handlingStatus: String(source.handlingStatus || '').trim(),
|
|
updatedAt: String(source.updatedAt || '').trim()
|
|
};
|
|
}
|
|
|
|
function renderReminders(data, genealogyId) {
|
|
var items = Array.isArray(data) ? data.map(normalizeReminder).filter(Boolean) : [];
|
|
var target = 'profile-tree.html?genealogyId=' + encodeURIComponent(genealogyId || '');
|
|
|
|
if (!items.length) return '<div class="api-empty">当前家谱没有待完善的成员资料</div>';
|
|
return items.map(function (item) {
|
|
return '<a class="module-row" href="' + target + '"><div><h3>' + escapeHtml(item.displayName) +
|
|
'</h3><p>待完善:' + escapeHtml(item.label) +
|
|
(item.updatedAt ? ' · 最近更新 ' + escapeHtml(item.updatedAt) : '') +
|
|
'</p></div><span class="pill">去完善</span></a>';
|
|
}).join('');
|
|
}
|
|
|
|
async function init() {
|
|
var page = root.document && root.document.querySelector('[data-profile-reminder-page]');
|
|
var list = page && page.querySelector('[data-profile-reminder-list]');
|
|
var api = root.GenealogyApi && root.GenealogyApi.defaultClient;
|
|
var genealogyId = root.ProfileUI && root.ProfileUI.getGenealogyId ? root.ProfileUI.getGenealogyId() : '';
|
|
|
|
if (!page) return;
|
|
if (!api || !api.getToken || !api.getToken()) {
|
|
root.NavigationUtil.open('login.html');
|
|
return;
|
|
}
|
|
if (!genealogyId) {
|
|
root.ProfileUI.setApiState(list, 'error', '缺少家谱上下文,请从“我的家谱”重新进入。');
|
|
return;
|
|
}
|
|
try {
|
|
list.innerHTML = renderReminders(await api.genealogyProfileReminders(genealogyId), genealogyId);
|
|
} catch (error) {
|
|
root.ProfileUI.setApiState(list, 'error', error.message || '资料提醒读取失败,请稍后重试。');
|
|
}
|
|
}
|
|
|
|
return { normalizeReminder: normalizeReminder, renderReminders: renderReminders, init: init };
|
|
});
|