等待后端更新接口
This commit is contained in:
@@ -91,7 +91,6 @@
|
||||
}
|
||||
|
||||
function renderNormalizedArticleList(items) {
|
||||
if (!items.length) return '<div class="api-empty">当前暂无资讯</div>';
|
||||
return items.map(function (item) {
|
||||
return '<a class="site-info-item" href="article-detail.html?articleId=' +
|
||||
encodeURIComponent(item.articleId) + '">' +
|
||||
@@ -131,9 +130,7 @@
|
||||
function renderArticleDetail(item) {
|
||||
var article = normalizeArticle(item);
|
||||
|
||||
return article
|
||||
? renderNormalizedArticleDetail(article)
|
||||
: '<div class="api-empty">资讯不存在或已下线</div>';
|
||||
return article ? renderNormalizedArticleDetail(article) : '';
|
||||
}
|
||||
|
||||
function readQueryValue(search, key) {
|
||||
@@ -178,6 +175,27 @@
|
||||
return match;
|
||||
}
|
||||
|
||||
function isForbidden(error) {
|
||||
return Number(error && (error.status || error.code)) === 403;
|
||||
}
|
||||
|
||||
function isMissingArticleError(error) {
|
||||
return error && error.message === '资讯不存在或已下线';
|
||||
}
|
||||
|
||||
function setSiteState(container, type, message) {
|
||||
if (!container) return;
|
||||
if (root.ProfileUI && root.ProfileUI.setApiState) {
|
||||
root.ProfileUI.setApiState(container, type, message);
|
||||
return;
|
||||
}
|
||||
container.textContent = message;
|
||||
}
|
||||
|
||||
function setSiteStatus(container, message) {
|
||||
if (container) container.textContent = message || '';
|
||||
}
|
||||
|
||||
async function init() {
|
||||
var document = root.document;
|
||||
var api = root.GenealogyApi && root.GenealogyApi.defaultClient;
|
||||
@@ -196,19 +214,24 @@
|
||||
requestedType = readQueryValue(search, 'articleType');
|
||||
if (!list) return;
|
||||
if (requestedType && !normalizeArticleType(requestedType)) {
|
||||
list.innerHTML = '<div class="api-empty">资讯分类无效</div>';
|
||||
if (status) status.textContent = '资讯分类无效';
|
||||
setSiteState(list, 'error', '资讯分类无效。');
|
||||
setSiteStatus(status, '资讯分类无效。');
|
||||
return;
|
||||
}
|
||||
setSiteState(list, 'loading', '正在读取资讯…');
|
||||
try {
|
||||
list.classList.add('is-loading');
|
||||
list.innerHTML = renderNormalizedArticleList(await loadArticles(api, requestedType));
|
||||
if (status) status.textContent = '';
|
||||
var items = await loadArticles(api, requestedType);
|
||||
|
||||
if (!items.length) setSiteState(list, 'empty', '当前暂无资讯。');
|
||||
else list.innerHTML = renderNormalizedArticleList(items);
|
||||
setSiteStatus(status, '');
|
||||
} catch (error) {
|
||||
list.innerHTML = '<div class="api-empty">资讯读取失败,请稍后重试</div>';
|
||||
if (status) status.textContent = error.message || '资讯读取失败';
|
||||
} finally {
|
||||
list.classList.remove('is-loading');
|
||||
setSiteState(
|
||||
list,
|
||||
isForbidden(error) ? 'forbidden' : 'error',
|
||||
isForbidden(error) ? '当前账号无权查看资讯。' : '资讯读取失败,请稍后重试。'
|
||||
);
|
||||
setSiteStatus(status, error.message || '资讯读取失败,请稍后重试。');
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -219,20 +242,23 @@
|
||||
articleId = readArticleId(search);
|
||||
if (!detail) return;
|
||||
if (!articleId) {
|
||||
detail.innerHTML = '<div class="api-empty">资讯编号无效</div>';
|
||||
if (status) status.textContent = '资讯编号无效';
|
||||
setSiteState(detail, 'error', '资讯编号无效。');
|
||||
setSiteStatus(status, '资讯编号无效。');
|
||||
return;
|
||||
}
|
||||
setSiteState(detail, 'loading', '正在读取资讯详情…');
|
||||
try {
|
||||
detail.classList.add('is-loading');
|
||||
detail.innerHTML = renderNormalizedArticleDetail(await loadArticleDetail(api, articleId));
|
||||
if (status) status.textContent = '';
|
||||
setSiteStatus(status, '');
|
||||
} catch (error) {
|
||||
detail.innerHTML = '<div class="api-empty">' +
|
||||
escapeHtml(error.message || '资讯读取失败,请稍后重试') + '</div>';
|
||||
if (status) status.textContent = error.message || '资讯读取失败';
|
||||
} finally {
|
||||
detail.classList.remove('is-loading');
|
||||
setSiteState(
|
||||
detail,
|
||||
isForbidden(error) ? 'forbidden' : (isMissingArticleError(error) ? 'empty' : 'error'),
|
||||
isForbidden(error)
|
||||
? '当前账号无权查看该资讯。'
|
||||
: (isMissingArticleError(error) ? '资讯不存在或已下线。' : '资讯详情读取失败,请稍后重试。')
|
||||
);
|
||||
setSiteStatus(status, error.message || '资讯详情读取失败,请稍后重试。');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,6 +273,9 @@
|
||||
renderArticleDetail: renderArticleDetail,
|
||||
loadArticles: loadArticles,
|
||||
loadArticleDetail: loadArticleDetail,
|
||||
isForbidden: isForbidden,
|
||||
isMissingArticleError: isMissingArticleError,
|
||||
setSiteState: setSiteState,
|
||||
init: init
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user