等待后端更新接口
This commit is contained in:
+86
-25
@@ -304,11 +304,11 @@
|
||||
});
|
||||
if (!container) return;
|
||||
if (invalidCount) {
|
||||
container.innerHTML = '<div class="api-empty">人物响应缺少可安全使用的 personId 或 name,请联系后端补充 DTO。</div>';
|
||||
setLineageState('[data-lineage-list]', 'error', '人物响应缺少可安全使用的 personId 或 name,请联系后端补充 DTO。');
|
||||
return;
|
||||
}
|
||||
if (!people.length) {
|
||||
container.innerHTML = '<div class="api-empty">暂无世系人物</div>';
|
||||
setLineageState('[data-lineage-list]', 'empty', '暂无世系人物');
|
||||
return;
|
||||
}
|
||||
container.innerHTML = people.map(function (person) {
|
||||
@@ -344,16 +344,20 @@
|
||||
function renderLineageTreeHtml(data) {
|
||||
var nodes = normalizeList(data).map(function (item) { return renderTreeNode(item, {}); }).filter(Boolean);
|
||||
|
||||
if (!nodes.length) {
|
||||
return '<div class="api-empty">暂无世系树</div>';
|
||||
}
|
||||
if (!nodes.length) return '';
|
||||
return '<ul class="lineage-tree">' + nodes.join('') + '</ul>';
|
||||
}
|
||||
|
||||
function renderTree(data) {
|
||||
var container = query('[data-lineage-tree]');
|
||||
var html = renderLineageTreeHtml(data);
|
||||
|
||||
if (container) container.innerHTML = renderLineageTreeHtml(data);
|
||||
if (!container) return;
|
||||
if (!html) {
|
||||
setLineageState('[data-lineage-tree]', 'empty', '暂无世系树');
|
||||
return;
|
||||
}
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
function renderOptions(data) {
|
||||
@@ -397,9 +401,11 @@
|
||||
function updateBindingFields() {
|
||||
var bindingMode = query('[name="bindingMode"]');
|
||||
var memberSelect = query('[data-lineage-member-options]');
|
||||
var specifiedMember = query('[data-lineage-specified-member]');
|
||||
var specified = Boolean(bindingMode && bindingMode.value === 'SPECIFIED');
|
||||
|
||||
if (!memberSelect) return;
|
||||
if (specifiedMember) specifiedMember.hidden = !specified;
|
||||
memberSelect.hidden = !specified;
|
||||
memberSelect.required = specified;
|
||||
if (!specified) memberSelect.value = '';
|
||||
@@ -469,7 +475,7 @@
|
||||
|
||||
if (!container) return;
|
||||
if (!person) {
|
||||
container.innerHTML = '<div class="api-empty">人物详情缺少可安全使用的 personId 或 name,请联系后端补充 DTO。</div>';
|
||||
setLineageState('[data-lineage-detail]', 'error', '人物详情缺少可安全使用的 personId 或 name,请联系后端补充 DTO。');
|
||||
return;
|
||||
}
|
||||
selectedPersonId = person.personId;
|
||||
@@ -513,10 +519,61 @@
|
||||
return values;
|
||||
}
|
||||
|
||||
function setFormStatus(message) {
|
||||
function setLineageState(selector, type, message) {
|
||||
var target = query(selector);
|
||||
|
||||
if (!target) return;
|
||||
if (root.ProfileUI && root.ProfileUI.setApiState) {
|
||||
root.ProfileUI.setApiState(target, type, message);
|
||||
return;
|
||||
}
|
||||
target.innerHTML = '<div class="api-state api-state--' + escapeHtml(type) + '" data-api-state="' + escapeHtml(type) + '">' +
|
||||
escapeHtml(message) + '</div>';
|
||||
}
|
||||
|
||||
function setFormStatus(message, type) {
|
||||
var target = query('[data-lineage-form-status]');
|
||||
|
||||
if (target) target.textContent = message || '';
|
||||
if (!target) return;
|
||||
if (!message) {
|
||||
target.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
if (type && root.ProfileUI && root.ProfileUI.setApiState) {
|
||||
root.ProfileUI.setApiState(target, type, message);
|
||||
return;
|
||||
}
|
||||
target.textContent = message;
|
||||
}
|
||||
|
||||
function setActionStatus(message, type) {
|
||||
var target = query('[data-lineage-action-status]');
|
||||
|
||||
if (!target) return;
|
||||
if (!message) {
|
||||
target.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
if (type && root.ProfileUI && root.ProfileUI.setApiState) {
|
||||
root.ProfileUI.setApiState(target, type, message);
|
||||
return;
|
||||
}
|
||||
target.textContent = message;
|
||||
}
|
||||
|
||||
function setLineageSubmitPending(pending) {
|
||||
queryAll('[data-lineage-submit]').forEach(function (button) {
|
||||
if (!button.dataset.defaultLabel) button.dataset.defaultLabel = button.textContent;
|
||||
button.textContent = pending ? '正在保存…' : button.dataset.defaultLabel;
|
||||
button.setAttribute('aria-busy', pending ? 'true' : 'false');
|
||||
});
|
||||
}
|
||||
|
||||
function setLineageSubmitLabel(label) {
|
||||
queryAll('[data-lineage-submit]').forEach(function (button) {
|
||||
button.dataset.defaultLabel = label;
|
||||
if (!writePending) button.textContent = label;
|
||||
});
|
||||
}
|
||||
|
||||
function relationLabel(mode) {
|
||||
@@ -545,13 +602,12 @@
|
||||
|
||||
function renderNoContext() {
|
||||
['[data-lineage-tree]', '[data-lineage-list]', '[data-lineage-detail]'].forEach(function (selector) {
|
||||
var container = query(selector);
|
||||
|
||||
if (container) container.innerHTML = '<div class="api-empty">请从具体家谱进入世系管理</div>';
|
||||
setLineageState(selector, 'error', '请从具体家谱进入世系管理');
|
||||
});
|
||||
if (query('[data-lineage-list-summary]')) query('[data-lineage-list-summary]').textContent = '';
|
||||
currentPageTotal = null;
|
||||
setLineageEnabled(false);
|
||||
setActionStatus('请从具体家谱进入世系管理。', 'error');
|
||||
updatePaginationControls();
|
||||
}
|
||||
|
||||
@@ -588,18 +644,18 @@
|
||||
function setWritePending(pending) {
|
||||
writePending = Boolean(pending);
|
||||
refreshControls();
|
||||
setLineageSubmitPending(writePending);
|
||||
}
|
||||
|
||||
function renderForbiddenState() {
|
||||
['[data-lineage-tree]', '[data-lineage-list]', '[data-lineage-detail]'].forEach(function (selector) {
|
||||
var container = query(selector);
|
||||
|
||||
if (container) container.innerHTML = '<div class="api-empty">当前账号没有世系人物管理权限</div>';
|
||||
setLineageState(selector, 'forbidden', '当前账号没有世系人物管理权限');
|
||||
});
|
||||
if (query('[data-lineage-list-summary]')) query('[data-lineage-list-summary]').textContent = '';
|
||||
currentPageTotal = null;
|
||||
setLineageEnabled(false);
|
||||
setFormStatus('当前账号没有世系人物管理权限');
|
||||
setFormStatus('当前账号没有世系人物管理权限', 'forbidden');
|
||||
setActionStatus('当前账号没有世系人物管理权限', 'forbidden');
|
||||
}
|
||||
|
||||
function getCurrentKeyword() {
|
||||
@@ -648,6 +704,9 @@
|
||||
if (!genealogyId) return;
|
||||
currentPageNum = Number.isInteger(requestedPage) && requestedPage > 0 ? requestedPage : 1;
|
||||
syncGenealogyLinks(genealogyId);
|
||||
setLineageState('[data-lineage-tree]', 'loading', '正在加载世系树…');
|
||||
setLineageState('[data-lineage-list]', 'loading', '正在加载世系人物…');
|
||||
setActionStatus('');
|
||||
try {
|
||||
results = await Promise.all([
|
||||
api.genealogyDetail(genealogyId),
|
||||
@@ -681,9 +740,7 @@
|
||||
return;
|
||||
}
|
||||
['[data-lineage-tree]', '[data-lineage-list]'].forEach(function (selector) {
|
||||
var container = query(selector);
|
||||
|
||||
if (container) container.innerHTML = '<div class="api-empty">世系人物加载失败,请稍后重试</div>';
|
||||
setLineageState(selector, 'error', '世系人物加载失败,请稍后重试');
|
||||
});
|
||||
showMessage(error.message || '世系人物加载失败');
|
||||
}
|
||||
@@ -696,6 +753,7 @@
|
||||
if (redirectUnauthorized(api)) return;
|
||||
genealogyId = requireGenealogyId();
|
||||
if (!genealogyId || !personId) return;
|
||||
setLineageState('[data-lineage-detail]', 'loading', '正在加载成员详情…');
|
||||
try {
|
||||
renderDetail(await api.lineagePersonDetail(genealogyId, personId));
|
||||
} catch (error) {
|
||||
@@ -704,6 +762,7 @@
|
||||
renderForbiddenState();
|
||||
return;
|
||||
}
|
||||
setLineageState('[data-lineage-detail]', 'error', '人物详情加载失败,请稍后重试。');
|
||||
showMessage(error.message || '人物详情加载失败');
|
||||
}
|
||||
}
|
||||
@@ -720,7 +779,7 @@
|
||||
relationMode = mode;
|
||||
editingPersonId = '';
|
||||
setRelationFieldVisibility(mode === 'spouses');
|
||||
if (submitButton) submitButton.textContent = '新增' + relationLabel(mode);
|
||||
if (submitButton) setLineageSubmitLabel('新增' + relationLabel(mode));
|
||||
setFormStatus('当前将为“' + person.name + '”新增' + relationLabel(mode));
|
||||
}
|
||||
|
||||
@@ -777,7 +836,7 @@
|
||||
editingPersonId = person.personId;
|
||||
setRelationFieldVisibility(false);
|
||||
submitButton = query('[data-lineage-form] button[type="submit"]');
|
||||
if (submitButton) submitButton.textContent = '保存修改';
|
||||
if (submitButton) setLineageSubmitLabel('保存修改');
|
||||
setFormStatus('正在编辑“' + person.name + '”');
|
||||
}
|
||||
|
||||
@@ -787,7 +846,7 @@
|
||||
relationMode = '';
|
||||
editingPersonId = '';
|
||||
setRelationFieldVisibility(false);
|
||||
if (submitButton) submitButton.textContent = '保存成员';
|
||||
if (submitButton) setLineageSubmitLabel('保存成员');
|
||||
setFormStatus('');
|
||||
if (root.setTimeout) root.setTimeout(updateBindingFields, 0);
|
||||
}
|
||||
@@ -803,11 +862,11 @@
|
||||
genealogyId = requireGenealogyId();
|
||||
if (!genealogyId) return;
|
||||
if (validation) {
|
||||
setFormStatus(validation);
|
||||
setFormStatus(validation, 'error');
|
||||
return;
|
||||
}
|
||||
setWritePending(true);
|
||||
setFormStatus('正在保存成员...');
|
||||
setFormStatus('正在保存成员…', 'loading');
|
||||
try {
|
||||
if (editingPersonId) {
|
||||
result = await api.updateLineagePerson(genealogyId, editingPersonId, body);
|
||||
@@ -833,7 +892,7 @@
|
||||
renderForbiddenState();
|
||||
return;
|
||||
}
|
||||
setFormStatus(error.message || '成员保存失败');
|
||||
setFormStatus(error.message || '成员保存失败', 'error');
|
||||
} finally {
|
||||
setWritePending(false);
|
||||
}
|
||||
@@ -849,6 +908,7 @@
|
||||
if (!genealogyId || !personId) return;
|
||||
if (root.confirm && !root.confirm('确认停用“' + (person ? person.name : '该成员') + '”吗?有正常子女时后端会拒绝停用。')) return;
|
||||
setWritePending(true);
|
||||
setActionStatus('正在停用成员…', 'loading');
|
||||
try {
|
||||
await api.disableLineagePerson(genealogyId, personId);
|
||||
selectedPersonId = '';
|
||||
@@ -861,6 +921,7 @@
|
||||
renderForbiddenState();
|
||||
return;
|
||||
}
|
||||
setActionStatus(error.message || '成员停用失败', 'error');
|
||||
showMessage(error.message || '成员停用失败');
|
||||
} finally {
|
||||
setWritePending(false);
|
||||
|
||||
Reference in New Issue
Block a user