(function (root, factory) { // 消息模块同时支持浏览器页面和 Node 单元测试。 if (typeof module === 'object' && module.exports) { module.exports = factory(root); return; } root.NotificationPages = factory(root); if (root.document) { root.document.addEventListener('DOMContentLoaded', function () { root.NotificationPages.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 isRead(item) { var readStatus = pick(item, ['readStatus', 'status'], ''); var readFlag = pick(item, ['readFlag', 'isRead', 'read'], ''); if (readFlag === true || readFlag === 'true' || readFlag === 1 || readFlag === '1') return true; return readStatus === '1' || readStatus === 1 || readStatus === '已读'; } function formatNotificationStatus(item) { return isRead(item) ? '已读' : '未读'; } function buildNotificationRow(item) { // 通知字段名按接口常见命名做兼容,页面只关心标题、内容、时间和已读状态。 var id = pick(item, ['notificationId', 'id'], ''); var title = pick(item, ['title', 'noticeTitle', 'messageTitle'], '系统通知'); var content = pick(item, ['content', 'message', 'noticeContent', 'summary'], '暂无通知内容'); var time = pick(item, ['createTime', 'createdAt', 'time'], ''); var status = formatNotificationStatus(item); var className = isRead(item) ? 'module-row notification-row' : 'module-row notification-row is-unread'; var action = isRead(item) ? '已读' : ''; return '
' + escapeHtml(time) + ' · ' + escapeHtml(content) + '