等待后端更新接口
This commit is contained in:
+104
-39
@@ -295,7 +295,7 @@
|
||||
function renderAlbumDetail(album) {
|
||||
var actions = '';
|
||||
|
||||
if (!album) return '<div class="api-empty">未找到该相册</div>';
|
||||
if (!album) return '';
|
||||
if (canEditContent) {
|
||||
actions = '<div class="bottom-actions"><a class="btn ghost" href="' +
|
||||
escapeHtml(buildEditUrl(album.genealogyId, album.albumId)) + '">编辑相册</a>' +
|
||||
@@ -327,8 +327,8 @@
|
||||
function renderPhotoList(data) {
|
||||
var photos = Array.isArray(data) ? data.map(normalizeAlbumPhoto) : [];
|
||||
|
||||
if (photos.some(function (photo) { return !photo; })) return '<div class="api-empty">照片响应字段不完整</div>';
|
||||
if (!photos.length) return '<div class="api-empty">暂无照片</div>';
|
||||
if (photos.some(function (photo) { return !photo; })) return '';
|
||||
if (!photos.length) return '';
|
||||
return photos.map(function (photo) {
|
||||
var action = canEditContent
|
||||
? '<button class="pill is-danger" type="button" data-album-photo-delete-id="' +
|
||||
@@ -369,10 +369,23 @@
|
||||
if (root.ProfileUI && root.ProfileUI.syncGenealogyContextLinks) root.ProfileUI.syncGenealogyContextLinks();
|
||||
}
|
||||
|
||||
function setStatus(selector, message) {
|
||||
function getApiStateType(error) {
|
||||
return isForbidden(error) ? 'forbidden' : 'error';
|
||||
}
|
||||
|
||||
function setStatus(selector, message, type) {
|
||||
var target = query(selector);
|
||||
|
||||
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 setEditorEnabled(enabled, message) {
|
||||
@@ -397,12 +410,12 @@
|
||||
function renderNoContext() {
|
||||
var message = '请先选择家谱,再查看或维护相册。';
|
||||
|
||||
if (query('[data-album-list]')) query('[data-album-list]').innerHTML = '<div class="api-empty">' + message + '</div>';
|
||||
if (query('[data-album-detail]')) query('[data-album-detail]').innerHTML = '<div class="api-empty">当前没有家谱上下文。</div>';
|
||||
if (query('[data-album-photo-list]')) query('[data-album-photo-list]').innerHTML = '<div class="api-empty">当前没有家谱上下文。</div>';
|
||||
setStatus('[data-album-list]', message, 'empty');
|
||||
setStatus('[data-album-detail]', '当前没有家谱上下文。', 'empty');
|
||||
setStatus('[data-album-photo-list]', '当前没有家谱上下文。', 'empty');
|
||||
setEditorEnabled(false, message);
|
||||
setStatus('[data-album-form-status]', message);
|
||||
setStatus('[data-album-photo-status]', message);
|
||||
setStatus('[data-album-form-status]', message, 'forbidden');
|
||||
setStatus('[data-album-photo-status]', message, 'forbidden');
|
||||
}
|
||||
|
||||
function requireGenealogyId() {
|
||||
@@ -412,10 +425,14 @@
|
||||
return genealogyId;
|
||||
}
|
||||
|
||||
function canEditAlbums(genealogy) {
|
||||
return Boolean(genealogy && (genealogy.canEditContent === true || genealogy.canManage === true));
|
||||
}
|
||||
|
||||
async function loadCapability(api, genealogyId) {
|
||||
var detail = await api.genealogyDetail(genealogyId);
|
||||
|
||||
canEditContent = Boolean(detail && (detail.canEditContent || detail.canManage));
|
||||
canEditContent = canEditAlbums(detail);
|
||||
queryAll('[data-album-create-link], [data-album-editor-action], [data-album-photo-editor]').forEach(function (element) {
|
||||
element.hidden = !canEditContent;
|
||||
});
|
||||
@@ -430,11 +447,11 @@
|
||||
albums.forEach(function (album) { albumsById[album.albumId] = album; });
|
||||
if (!container) return albums;
|
||||
if (!Array.isArray(data) || (data.length && !albums.length)) {
|
||||
container.innerHTML = '<div class="api-empty">相册响应缺少稳定 AlbumVo 字段,请联系后端核对。</div>';
|
||||
setStatus('[data-album-list]', '相册响应缺少稳定 AlbumVo 字段,请联系后端核对。', 'error');
|
||||
return [];
|
||||
}
|
||||
if (!albums.length) {
|
||||
container.innerHTML = '<div class="api-empty">暂无相册</div>';
|
||||
setStatus('[data-album-list]', '暂无相册', 'empty');
|
||||
return [];
|
||||
}
|
||||
container.innerHTML = albums.map(renderAlbumRow).join('');
|
||||
@@ -449,16 +466,17 @@
|
||||
genealogyId = requireGenealogyId();
|
||||
if (!genealogyId) return;
|
||||
syncLinks();
|
||||
setStatus('[data-album-list]', '正在加载相册…', 'loading');
|
||||
try {
|
||||
await loadCapability(api, genealogyId);
|
||||
renderAlbums(await api.albums(genealogyId));
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
if (query('[data-album-list]')) {
|
||||
query('[data-album-list]').innerHTML = '<div class="api-empty">' +
|
||||
(isForbidden(error) ? '当前账号无权查看该家谱的相册。' : '相册加载失败,请稍后重试。') +
|
||||
'</div>';
|
||||
}
|
||||
setStatus(
|
||||
'[data-album-list]',
|
||||
isForbidden(error) ? '当前账号无权查看该家谱的相册。' : '相册加载失败,请稍后重试。',
|
||||
getApiStateType(error)
|
||||
);
|
||||
showMessage(isForbidden(error) ? '当前账号无权查看该家谱的相册。' : (error.message || '相册加载失败'));
|
||||
}
|
||||
}
|
||||
@@ -498,6 +516,7 @@
|
||||
albumId = getCurrentAlbumId();
|
||||
syncLinks();
|
||||
setEditorEnabled(false, '正在加载相册编辑信息…');
|
||||
setStatus('[data-album-form-status]', '正在读取家谱权限…', 'loading');
|
||||
try {
|
||||
await loadCapability(api, genealogyId);
|
||||
if (!canEditContent) throw { status: 403, message: '当前账号无权维护该家谱的相册。' };
|
||||
@@ -509,25 +528,38 @@
|
||||
if (query('[data-album-editor-title]')) query('[data-album-editor-title]').textContent = '编辑相册';
|
||||
}
|
||||
setEditorEnabled(true);
|
||||
setStatus('[data-album-form-status]', '');
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
setEditorEnabled(false, isForbidden(error) ? '当前账号无权维护该家谱的相册。' : (error.message || '相册编辑信息加载失败'));
|
||||
setStatus('[data-album-form-status]', isForbidden(error) ? '当前账号无权维护该家谱的相册。' : (error.message || '相册编辑信息加载失败'));
|
||||
setStatus(
|
||||
'[data-album-form-status]',
|
||||
isForbidden(error) ? '当前账号无权维护该家谱的相册。' : (error.message || '相册编辑信息加载失败'),
|
||||
getApiStateType(error)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPhotos(api, genealogyId, albumId) {
|
||||
var data = await api.albumPhotos(genealogyId, albumId);
|
||||
var photos = normalizeAlbumPhotos(data);
|
||||
var data;
|
||||
var photos;
|
||||
var container = query('[data-album-photo-list]');
|
||||
|
||||
setStatus('[data-album-photo-list]', '正在加载照片…', 'loading');
|
||||
data = await api.albumPhotos(genealogyId, albumId);
|
||||
photos = normalizeAlbumPhotos(data);
|
||||
photosById = Object.create(null);
|
||||
photos.forEach(function (photo) { photosById[photo.photoId] = photo; });
|
||||
if (container) {
|
||||
container.innerHTML = !Array.isArray(data) || (data.length && !photos.length)
|
||||
? '<div class="api-empty">照片响应缺少稳定 AlbumPhotoVo 字段,请联系后端核对。</div>'
|
||||
: renderPhotoList(photos);
|
||||
if (!container) return photos;
|
||||
if (!Array.isArray(data) || (data.length && !photos.length)) {
|
||||
setStatus('[data-album-photo-list]', '照片响应缺少稳定 AlbumPhotoVo 字段,请联系后端核对。', 'error');
|
||||
return [];
|
||||
}
|
||||
if (!photos.length) {
|
||||
setStatus('[data-album-photo-list]', '暂无照片', 'empty');
|
||||
return [];
|
||||
}
|
||||
container.innerHTML = renderPhotoList(photos);
|
||||
return photos;
|
||||
}
|
||||
|
||||
@@ -541,10 +573,15 @@
|
||||
genealogyId = requireGenealogyId();
|
||||
albumId = getCurrentAlbumId();
|
||||
if (!genealogyId || !albumId) {
|
||||
if (genealogyId && query('[data-album-detail]')) query('[data-album-detail]').innerHTML = '<div class="api-empty">缺少有效相册编号。</div>';
|
||||
if (genealogyId) {
|
||||
setStatus('[data-album-detail]', '缺少有效相册编号。', 'error');
|
||||
setStatus('[data-album-photo-list]', '缺少有效相册编号。', 'empty');
|
||||
}
|
||||
return;
|
||||
}
|
||||
syncLinks();
|
||||
setStatus('[data-album-detail]', '正在加载相册信息…', 'loading');
|
||||
setStatus('[data-album-photo-list]', '正在加载照片…', 'loading');
|
||||
try {
|
||||
await loadCapability(api, genealogyId);
|
||||
albums = await api.albums(genealogyId);
|
||||
@@ -552,12 +589,31 @@
|
||||
if (!currentAlbum) throw new Error('相册列表未返回当前相册');
|
||||
if (query('[data-album-detail]')) query('[data-album-detail]').innerHTML = renderAlbumDetail(currentAlbum);
|
||||
if (query('[data-album-detail-title]')) query('[data-album-detail-title]').textContent = currentAlbum.albumName;
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
setStatus(
|
||||
'[data-album-detail]',
|
||||
isForbidden(error) ? '当前账号无权查看该相册。' : (error.message || '相册详情加载失败'),
|
||||
getApiStateType(error)
|
||||
);
|
||||
setStatus(
|
||||
'[data-album-photo-list]',
|
||||
isForbidden(error) ? '当前账号无权查看该相册。' : '照片加载失败,请稍后重试。',
|
||||
getApiStateType(error)
|
||||
);
|
||||
showMessage(isForbidden(error) ? '当前账号无权查看该相册。' : (error.message || '相册详情加载失败'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await loadPhotos(api, genealogyId, albumId);
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
if (query('[data-album-detail]')) query('[data-album-detail]').innerHTML = '<div class="api-empty">' +
|
||||
(isForbidden(error) ? '当前账号无权查看该相册。' : escapeHtml(error.message || '相册详情加载失败')) + '</div>';
|
||||
showMessage(isForbidden(error) ? '当前账号无权查看该相册。' : (error.message || '相册详情加载失败'));
|
||||
setStatus(
|
||||
'[data-album-photo-list]',
|
||||
isForbidden(error) ? '当前账号无权查看该相册照片。' : (error.message || '照片加载失败'),
|
||||
getApiStateType(error)
|
||||
);
|
||||
showMessage(isForbidden(error) ? '当前账号无权查看该相册照片。' : (error.message || '照片加载失败'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,17 +628,17 @@
|
||||
var savedId;
|
||||
var verified;
|
||||
|
||||
if (writePending || !genealogyId || redirectUnauthorized(api)) return;
|
||||
if (writePending || !canEditContent || !genealogyId || redirectUnauthorized(api)) return;
|
||||
body = buildAlbumBody(getFormValues(form));
|
||||
validation = validateAlbumBody(body);
|
||||
if (validation) {
|
||||
setStatus('[data-album-form-status]', validation);
|
||||
setStatus('[data-album-form-status]', validation, 'error');
|
||||
return;
|
||||
}
|
||||
delete body.invalidCoverOssId;
|
||||
delete body.invalidSortOrder;
|
||||
setWritePending(true);
|
||||
setStatus('[data-album-form-status]', '正在保存相册…');
|
||||
setStatus('[data-album-form-status]', '正在保存相册…', 'loading');
|
||||
try {
|
||||
result = albumId
|
||||
? await api.updateAlbum(genealogyId, albumId, body)
|
||||
@@ -595,7 +651,11 @@
|
||||
if (root.location) root.location.href = buildDetailUrl(genealogyId, savedId);
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
setStatus('[data-album-form-status]', isForbidden(error) ? '当前账号无权保存该相册。' : (error.message || '相册保存失败'));
|
||||
setStatus(
|
||||
'[data-album-form-status]',
|
||||
isForbidden(error) ? '当前账号无权保存该相册。' : (error.message || '相册保存失败'),
|
||||
getApiStateType(error)
|
||||
);
|
||||
} finally {
|
||||
setWritePending(false);
|
||||
}
|
||||
@@ -609,17 +669,17 @@
|
||||
var validation;
|
||||
var saved;
|
||||
|
||||
if (writePending || !genealogyId || !albumId || redirectUnauthorized(api)) return;
|
||||
if (writePending || !canEditContent || !genealogyId || !albumId || redirectUnauthorized(api)) return;
|
||||
body = buildAlbumPhotoBody(getFormValues(form));
|
||||
validation = validateAlbumPhotoBody(body);
|
||||
if (validation) {
|
||||
setStatus('[data-album-photo-status]', validation);
|
||||
setStatus('[data-album-photo-status]', validation, 'error');
|
||||
return;
|
||||
}
|
||||
delete body.invalidOssId;
|
||||
delete body.invalidSortOrder;
|
||||
setWritePending(true);
|
||||
setStatus('[data-album-photo-status]', '正在添加照片…');
|
||||
setStatus('[data-album-photo-status]', '正在添加照片…', 'loading');
|
||||
try {
|
||||
saved = normalizeAlbumPhoto(await api.createAlbumPhoto(genealogyId, albumId, body));
|
||||
if (!saved || saved.albumId !== albumId) throw new Error('添加照片响应缺少稳定 photoId');
|
||||
@@ -630,7 +690,11 @@
|
||||
setStatus('[data-album-photo-status]', '照片已添加');
|
||||
} catch (error) {
|
||||
if (redirectUnauthorized(api, error)) return;
|
||||
setStatus('[data-album-photo-status]', isForbidden(error) ? '当前账号无权添加照片。' : (error.message || '照片添加失败'));
|
||||
setStatus(
|
||||
'[data-album-photo-status]',
|
||||
isForbidden(error) ? '当前账号无权添加照片。' : (error.message || '照片添加失败'),
|
||||
getApiStateType(error)
|
||||
);
|
||||
} finally {
|
||||
setWritePending(false);
|
||||
}
|
||||
@@ -641,7 +705,7 @@
|
||||
var genealogyId = requireGenealogyId();
|
||||
var album = albumsById[albumId] || currentAlbum;
|
||||
|
||||
if (writePending || !genealogyId || !normalizeId(albumId) || redirectUnauthorized(api)) return;
|
||||
if (writePending || !canEditContent || !genealogyId || !normalizeId(albumId) || redirectUnauthorized(api)) return;
|
||||
if (root.confirm && !root.confirm('确认删除“' + (album ? album.albumName : '该相册') + '”及其中全部照片吗?删除后不可恢复。')) return;
|
||||
setWritePending(true);
|
||||
try {
|
||||
@@ -662,7 +726,7 @@
|
||||
var albumId = getCurrentAlbumId();
|
||||
var photo = photosById[photoId];
|
||||
|
||||
if (writePending || !genealogyId || !albumId || !normalizeId(photoId) || redirectUnauthorized(api)) return;
|
||||
if (writePending || !canEditContent || !genealogyId || !albumId || !normalizeId(photoId) || redirectUnauthorized(api)) return;
|
||||
if (root.confirm && !root.confirm('确认删除“' + (photo && photo.photoTitle || '该照片') + '”吗?删除后不可恢复。')) return;
|
||||
setWritePending(true);
|
||||
try {
|
||||
@@ -722,6 +786,7 @@
|
||||
validateAlbumBody: validateAlbumBody,
|
||||
buildAlbumPhotoBody: buildAlbumPhotoBody,
|
||||
validateAlbumPhotoBody: validateAlbumPhotoBody,
|
||||
canEditAlbums: canEditAlbums,
|
||||
normalizeAlbum: normalizeAlbum,
|
||||
normalizeAlbumPhoto: normalizeAlbumPhoto,
|
||||
normalizeAlbums: normalizeAlbums,
|
||||
|
||||
Reference in New Issue
Block a user