等待后端更新接口
This commit is contained in:
+46
-12
@@ -40,6 +40,10 @@
|
||||
return !api || !api.getToken || !api.getToken() || Number(status) === 401;
|
||||
}
|
||||
|
||||
function isForbidden(error) {
|
||||
return Number(error && (error.status || error.code)) === 403;
|
||||
}
|
||||
|
||||
function redirectUnauthorized(api, error) {
|
||||
if (!shouldRedirectToLogin(api, error)) return false;
|
||||
if (api && api.clearToken) api.clearToken();
|
||||
@@ -171,7 +175,7 @@
|
||||
function renderInvitationDetail(invitation) {
|
||||
var mapLink = '';
|
||||
|
||||
if (!invitation) return '<div class="api-empty">请选择一条邀请查看详情</div>';
|
||||
if (!invitation) return '';
|
||||
if (invitation.longitude !== undefined && invitation.latitude !== undefined) {
|
||||
mapLink = ' <a class="pill" target="_blank" rel="noopener noreferrer" href="https://uri.amap.com/marker?position=' +
|
||||
encodeURIComponent(invitation.longitude + ',' + invitation.latitude) + '&name=' +
|
||||
@@ -194,7 +198,12 @@
|
||||
var container = query('[data-my-invitation-detail]');
|
||||
|
||||
selectedInvitationId = invitation ? invitation.invitationId : '';
|
||||
if (container) container.innerHTML = renderInvitationDetail(invitation);
|
||||
if (!container) return;
|
||||
if (!invitation) {
|
||||
setInvitationState('[data-my-invitation-detail]', 'empty', '请选择一条邀请查看详情');
|
||||
return;
|
||||
}
|
||||
container.innerHTML = renderInvitationDetail(invitation);
|
||||
}
|
||||
|
||||
function renderInvitations(data) {
|
||||
@@ -209,12 +218,12 @@
|
||||
});
|
||||
if (!container) return invitations;
|
||||
if (invalidCount) {
|
||||
container.innerHTML = '<div class="api-empty">邀请响应缺少稳定 ID 或合法状态,请联系后端核对 DTO。</div>';
|
||||
renderDetail(null);
|
||||
setInvitationState('[data-my-invitation-list]', 'error', '邀请响应缺少稳定 ID 或合法状态,请联系后端核对 DTO。');
|
||||
setInvitationState('[data-my-invitation-detail]', 'error', '邀请详情暂不可用,请联系后端核对 DTO。');
|
||||
return [];
|
||||
}
|
||||
if (!invitations.length) {
|
||||
container.innerHTML = '<div class="api-empty">暂无贺礼邀请</div>';
|
||||
setInvitationState('[data-my-invitation-list]', 'empty', '暂无贺礼邀请');
|
||||
renderDetail(null);
|
||||
return [];
|
||||
}
|
||||
@@ -234,23 +243,41 @@
|
||||
});
|
||||
}
|
||||
|
||||
function setListState(message) {
|
||||
var container = query('[data-my-invitation-list]');
|
||||
function setInvitationState(selector, type, message) {
|
||||
var container = query(selector);
|
||||
|
||||
if (container) container.innerHTML = '<div class="api-empty">' + escapeHtml(message) + '</div>';
|
||||
if (!container) return;
|
||||
if (!message) {
|
||||
container.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
if (type && root.ProfileUI && root.ProfileUI.setApiState) {
|
||||
root.ProfileUI.setApiState(container, type, message);
|
||||
return;
|
||||
}
|
||||
container.textContent = message;
|
||||
}
|
||||
|
||||
async function loadMyInvitations() {
|
||||
var api = getApi();
|
||||
|
||||
if (redirectUnauthorized(api)) return;
|
||||
setListState('正在加载我的邀请…');
|
||||
setInvitationState('[data-my-invitation-list]', 'loading', '正在加载我的邀请…');
|
||||
setInvitationState('[data-my-invitation-detail]', 'loading', '正在加载邀请详情…');
|
||||
try {
|
||||
renderInvitations(await api.myCeremonyInvitations());
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
setListState(Number(error && (error.status || error.code)) === 403 ? '当前账号无权查看邀请' : (error.message || '邀请加载失败'));
|
||||
renderDetail(null);
|
||||
setInvitationState(
|
||||
'[data-my-invitation-list]',
|
||||
isForbidden(error) ? 'forbidden' : 'error',
|
||||
isForbidden(error) ? '当前账号无权查看邀请。' : (error.message || '邀请加载失败')
|
||||
);
|
||||
setInvitationState(
|
||||
'[data-my-invitation-detail]',
|
||||
isForbidden(error) ? 'forbidden' : 'error',
|
||||
isForbidden(error) ? '当前账号无权查看邀请。' : '邀请详情加载失败,请稍后重试。'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,13 +290,19 @@
|
||||
if (writePending || redirectUnauthorized(api) || !invitation || !canRespondToInvitation(invitation)) return;
|
||||
if (validation) return;
|
||||
setWritePending(true);
|
||||
setInvitationState('[data-my-invitation-status]', 'loading', '正在更新邀请状态…');
|
||||
try {
|
||||
await api.respondCeremonyInvitation(invitation.genealogyId, invitation.ceremonyId, body);
|
||||
selectedInvitationId = invitation.invitationId;
|
||||
await loadMyInvitations();
|
||||
setInvitationState('[data-my-invitation-status]', '', '邀请状态已更新。');
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
setListState(Number(error && (error.status || error.code)) === 403 ? '当前账号无权响应该邀请' : (error.message || '邀请响应失败'));
|
||||
setInvitationState(
|
||||
'[data-my-invitation-status]',
|
||||
isForbidden(error) ? 'forbidden' : 'error',
|
||||
isForbidden(error) ? '当前账号无权响应该邀请。' : (error.message || '邀请响应失败')
|
||||
);
|
||||
} finally {
|
||||
setWritePending(false);
|
||||
}
|
||||
@@ -310,6 +343,7 @@
|
||||
renderInvitationRow: renderInvitationRow,
|
||||
renderInvitationDetail: renderInvitationDetail,
|
||||
shouldRedirectToLogin: shouldRedirectToLogin,
|
||||
isForbidden: isForbidden,
|
||||
loadMyInvitations: loadMyInvitations,
|
||||
init: init
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user