/** * 用户详细信息弹窗(配合 templates/macros/user_detail.html) */ (function (global) { 'use strict'; function defaultEscapeHtml(s) { if (s == null) return ''; var div = document.createElement('div'); div.textContent = String(s); return div.innerHTML; } function cfg() { return global.IAR_USER_DETAIL_CONFIG || { modalId: 'iarUserDetailModal', apiUrlTemplate: '/api/users/0/profile' }; } function apiUrl(userId) { var tpl = String((cfg().apiUrlTemplate || '/api/users/0/profile')); if (tpl.indexOf('/0') !== -1) return tpl.replace('/0', '/' + String(userId)); return tpl.replace(/\/$/, '') + '/' + String(userId); } function renderProfile(u, esc) { esc = esc || defaultEscapeHtml; var dash = '—'; return ( '
加载中…
'; bootstrap.Modal.getOrCreateInstance(modalEl).show(); fetch(apiUrl(uid), { credentials: 'same-origin' }) .then(function (res) { return res.json().then(function (data) { if (!res.ok || !data.success) throw new Error((data && data.message) || ('HTTP ' + res.status)); bodyEl.innerHTML = renderProfile(data.item || {}); }); }) .catch(function (err) { bodyEl.innerHTML = '' + defaultEscapeHtml(err.message || String(err)) + '
'; }); } function operatorLinkHtml(userId, label, esc) { esc = esc || defaultEscapeHtml; var uid = parseInt(userId, 10); if (!uid || Number.isNaN(uid)) return esc(label || '-'); var text = esc(label || '-'); return ( '' + text + '' ); } global.IARUserDetail = { show: show, operatorLinkHtml: operatorLinkHtml, renderProfile: renderProfile, }; })(typeof window !== 'undefined' ? window : this);