fix: 收藏夹弹窗优化 — 已收藏标识 + 移除确认 + 点击可靠性
- 收藏夹选项中已收藏项显示黄色'已收藏'徽章,一目了然
- 点击判断改用 classList.contains('active') 替代 JS 变量,防 currentFolderId 为空
- addToFolder 兜底处理'已在此收藏夹中'错误,不弹 alert
- 取消收藏确认文案优化为'确定移出该收藏夹吗?'
This commit is contained in:
@ -927,6 +927,17 @@
|
||||
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 {
|
||||
font-size: 12px;
|
||||
color: #9ca3af;
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
var isActive = currentFolderId === 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>'
|
||||
+ (isActive ? '<span class="fav-active-tag">已收藏</span>' : '')
|
||||
+ '<span class="fav-folder-opt-count">' + (f.item_count || 0) + ' 篇</span>'
|
||||
+ '</div>';
|
||||
});
|
||||
@ -110,6 +111,11 @@
|
||||
updateBtn(true);
|
||||
if (favCountEl) favCountEl.textContent = (parseInt(favCountEl.textContent) || 0) + 1;
|
||||
hideModal();
|
||||
} else if (d.message && d.message.indexOf('已在此收藏夹中') !== -1) {
|
||||
// 后端返回已收藏,直接关闭弹窗(兜底)
|
||||
currentFolderId = folderId;
|
||||
updateBtn(true);
|
||||
hideModal();
|
||||
} else {
|
||||
alert(d.message || '操作失败');
|
||||
}
|
||||
@ -119,7 +125,7 @@
|
||||
|
||||
function removeFromFolder(folderId) {
|
||||
if (loading) return;
|
||||
showConfirm('确认', '确定取消收藏吗?').then(function(ok) {
|
||||
showConfirm('确认取消收藏', '确定移出该收藏夹吗?').then(function(ok) {
|
||||
if (!ok) return;
|
||||
loading = true;
|
||||
api('DELETE', '/api/folders/' + folderId + '/posts/' + postId)
|
||||
@ -194,7 +200,7 @@
|
||||
if (!option) return;
|
||||
var folderId = parseInt(option.getAttribute('data-id'));
|
||||
if (isNaN(folderId)) return;
|
||||
if (currentFolderId === folderId) {
|
||||
if (option.classList.contains('active')) {
|
||||
removeFromFolder(folderId);
|
||||
} else {
|
||||
addToFolder(folderId);
|
||||
|
||||
Reference in New Issue
Block a user