修改功能
This commit is contained in:
@@ -352,14 +352,19 @@
|
||||
var api = root.GenealogyApi && root.GenealogyApi.defaultClient;
|
||||
var target = getTargetPage();
|
||||
var container = root.document && root.document.querySelector('[data-genealogy-list="mine"]');
|
||||
var sortSelect = root.document && root.document.querySelector('[data-genealogy-sort-select]');
|
||||
var sortUp = root.document && root.document.querySelector('[data-genealogy-sort-up]');
|
||||
var sortDown = root.document && root.document.querySelector('[data-genealogy-sort-down]');
|
||||
var sortSave = root.document && root.document.querySelector('[data-genealogy-sort-save]');
|
||||
var result;
|
||||
var sortPending = false;
|
||||
|
||||
if (!status) return;
|
||||
if (shouldRedirectToLogin(api)) {
|
||||
redirectToLogin(api);
|
||||
return;
|
||||
}
|
||||
if (!api || !api.genealogyQuota || !api.genealogiesMine) {
|
||||
if (!api || !api.genealogyQuota || !api.genealogiesMine || !api.saveGenealogyOrder) {
|
||||
setEntryStatus('家谱入口接口初始化失败,请刷新后重试。', 'error');
|
||||
setGenealogyListState(container, 'error', '家谱列表接口初始化失败,请刷新后重试。');
|
||||
return;
|
||||
@@ -369,6 +374,15 @@
|
||||
try {
|
||||
result = await api.genealogiesMine();
|
||||
renderGenealogies(container, result, target);
|
||||
if (sortSelect) {
|
||||
var sortItems = Array.isArray(result) ? result.map(normalizeGenealogy).filter(Boolean) : [];
|
||||
sortSelect.innerHTML = sortItems.map(function (item) {
|
||||
return '<option value="' + escapeHtml(item.genealogyId) + '">' + escapeHtml(item.genealogyName) + '</option>';
|
||||
}).join('');
|
||||
[sortSelect, sortUp, sortDown, sortSave].forEach(function (control) {
|
||||
if (control) control.disabled = sortItems.length < 2;
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (shouldRedirectToLogin(api, error)) {
|
||||
redirectToLogin(api);
|
||||
@@ -380,6 +394,41 @@
|
||||
getApiStateType(error) === 'forbidden' ? '当前账号无权查看我的家谱。' : '无法读取我的家谱,请稍后重试。'
|
||||
);
|
||||
}
|
||||
|
||||
function moveSelected(offset) {
|
||||
var index;
|
||||
var targetIndex;
|
||||
var option;
|
||||
|
||||
if (!sortSelect || sortPending) return;
|
||||
index = sortSelect.selectedIndex;
|
||||
targetIndex = index + offset;
|
||||
if (index < 0 || targetIndex < 0 || targetIndex >= sortSelect.options.length) return;
|
||||
option = sortSelect.options[index];
|
||||
if (offset < 0) sortSelect.insertBefore(option, sortSelect.options[targetIndex]);
|
||||
else sortSelect.insertBefore(sortSelect.options[targetIndex], option);
|
||||
sortSelect.selectedIndex = targetIndex;
|
||||
}
|
||||
|
||||
if (sortUp) sortUp.addEventListener('click', function () { moveSelected(-1); });
|
||||
if (sortDown) sortDown.addEventListener('click', function () { moveSelected(1); });
|
||||
if (sortSave) sortSave.addEventListener('click', async function () {
|
||||
if (sortPending || !sortSelect) return;
|
||||
sortPending = true;
|
||||
[sortSelect, sortUp, sortDown, sortSave].forEach(function (control) { if (control) control.disabled = true; });
|
||||
setEntryStatus('正在保存家谱顺序…', 'loading');
|
||||
try {
|
||||
await api.saveGenealogyOrder(Array.prototype.map.call(sortSelect.options, function (option) { return option.value; }));
|
||||
setEntryStatus('家谱顺序已保存');
|
||||
} catch (error) {
|
||||
setEntryStatus(error.message || '家谱顺序保存失败,请稍后重试。', getApiStateType(error));
|
||||
} finally {
|
||||
sortPending = false;
|
||||
[sortSelect, sortUp, sortDown, sortSave].forEach(function (control) {
|
||||
if (control) control.disabled = sortSelect.options.length < 2;
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
result = await api.genealogyQuota();
|
||||
setEntryStatus(buildStatus(result));
|
||||
|
||||
Reference in New Issue
Block a user