fix: 收藏夹弹窗优化 — 已收藏标识 + 移除确认 + 点击可靠性
- 收藏夹选项中已收藏项显示黄色'已收藏'徽章,一目了然
- 点击判断改用 classList.contains('active') 替代 JS 变量,防 currentFolderId 为空
- addToFolder 兜底处理'已在此收藏夹中'错误,不弹 alert
- 取消收藏确认文案优化为'确定移出该收藏夹吗?'
This commit is contained in:
@ -927,6 +927,17 @@
|
|||||||
color: #9ca3af;
|
color: #9ca3af;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fav-active-tag {
|
||||||
|
font-size: 11px;
|
||||||
|
color: #f59e0b;
|
||||||
|
background: #fef3c7;
|
||||||
|
padding: 1px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-weight: 500;
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.fav-folder-opt-count {
|
.fav-folder-opt-count {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #9ca3af;
|
color: #9ca3af;
|
||||||
|
|||||||
@ -47,6 +47,7 @@
|
|||||||
var isActive = currentFolderId === f.id;
|
var isActive = currentFolderId === f.id;
|
||||||
html += '<div class="fav-folder-option' + (isActive ? ' active' : '') + '" data-id="' + f.id + '">'
|
html += '<div class="fav-folder-option' + (isActive ? ' active' : '') + '" data-id="' + f.id + '">'
|
||||||
+ '<span class="fav-folder-opt-name">' + escapeHtml(f.name) + (f.is_default ? ' <small>(默认)</small>' : '') + '</span>'
|
+ '<span class="fav-folder-opt-name">' + escapeHtml(f.name) + (f.is_default ? ' <small>(默认)</small>' : '') + '</span>'
|
||||||
|
+ (isActive ? '<span class="fav-active-tag">已收藏</span>' : '')
|
||||||
+ '<span class="fav-folder-opt-count">' + (f.item_count || 0) + ' 篇</span>'
|
+ '<span class="fav-folder-opt-count">' + (f.item_count || 0) + ' 篇</span>'
|
||||||
+ '</div>';
|
+ '</div>';
|
||||||
});
|
});
|
||||||
@ -110,6 +111,11 @@
|
|||||||
updateBtn(true);
|
updateBtn(true);
|
||||||
if (favCountEl) favCountEl.textContent = (parseInt(favCountEl.textContent) || 0) + 1;
|
if (favCountEl) favCountEl.textContent = (parseInt(favCountEl.textContent) || 0) + 1;
|
||||||
hideModal();
|
hideModal();
|
||||||
|
} else if (d.message && d.message.indexOf('已在此收藏夹中') !== -1) {
|
||||||
|
// 后端返回已收藏,直接关闭弹窗(兜底)
|
||||||
|
currentFolderId = folderId;
|
||||||
|
updateBtn(true);
|
||||||
|
hideModal();
|
||||||
} else {
|
} else {
|
||||||
alert(d.message || '操作失败');
|
alert(d.message || '操作失败');
|
||||||
}
|
}
|
||||||
@ -119,7 +125,7 @@
|
|||||||
|
|
||||||
function removeFromFolder(folderId) {
|
function removeFromFolder(folderId) {
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
showConfirm('确认', '确定取消收藏吗?').then(function(ok) {
|
showConfirm('确认取消收藏', '确定移出该收藏夹吗?').then(function(ok) {
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
loading = true;
|
loading = true;
|
||||||
api('DELETE', '/api/folders/' + folderId + '/posts/' + postId)
|
api('DELETE', '/api/folders/' + folderId + '/posts/' + postId)
|
||||||
@ -194,7 +200,7 @@
|
|||||||
if (!option) return;
|
if (!option) return;
|
||||||
var folderId = parseInt(option.getAttribute('data-id'));
|
var folderId = parseInt(option.getAttribute('data-id'));
|
||||||
if (isNaN(folderId)) return;
|
if (isNaN(folderId)) return;
|
||||||
if (currentFolderId === folderId) {
|
if (option.classList.contains('active')) {
|
||||||
removeFromFolder(folderId);
|
removeFromFolder(folderId);
|
||||||
} else {
|
} else {
|
||||||
addToFolder(folderId);
|
addToFolder(folderId);
|
||||||
|
|||||||
@ -127,7 +127,7 @@ function showConfirm(title, message) {
|
|||||||
var overlay = document.createElement('div');
|
var overlay = document.createElement('div');
|
||||||
setStyles(overlay, {
|
setStyles(overlay, {
|
||||||
position: 'fixed', inset: '0', background: 'rgba(0,0,0,0.4)',
|
position: 'fixed', inset: '0', background: 'rgba(0,0,0,0.4)',
|
||||||
zIndex: '9998', display: 'flex', alignItems: 'center', justifyContent: 'center'
|
zIndex: '10000', display: 'flex', alignItems: 'center', justifyContent: 'center'
|
||||||
});
|
});
|
||||||
|
|
||||||
// 弹窗容器
|
// 弹窗容器
|
||||||
@ -209,7 +209,7 @@ function showPrompt(message, defaultValue) {
|
|||||||
var overlay = document.createElement('div');
|
var overlay = document.createElement('div');
|
||||||
setStyles(overlay, {
|
setStyles(overlay, {
|
||||||
position: 'fixed', inset: '0', background: 'rgba(0,0,0,0.4)',
|
position: 'fixed', inset: '0', background: 'rgba(0,0,0,0.4)',
|
||||||
zIndex: '9998', display: 'flex', alignItems: 'center', justifyContent: 'center'
|
zIndex: '10000', display: 'flex', alignItems: 'center', justifyContent: 'center'
|
||||||
});
|
});
|
||||||
|
|
||||||
// 弹窗容器
|
// 弹窗容器
|
||||||
|
|||||||
Reference in New Issue
Block a user