diff --git a/js/admin.js b/js/admin.js index a552c16..dd637d1 100644 --- a/js/admin.js +++ b/js/admin.js @@ -55,7 +55,7 @@ function renderAdminReports() { } API.updateReport(id, status, note).then(() => { renderAdminReports(); - }).catch(err => alert('操作失败:' + err.message)); + }).catch(err => showToast('操作失败:' + err.message, 'error')); }); }); }).catch(() => { @@ -218,7 +218,7 @@ function renderAdminUsers(page = 1, search = '') { if (!ok) return; API.updateUserRole(userId, role).then(() => { renderAdminUsers(currentUsersPage, usersSearchKeyword); - }).catch(err => alert('操作失败:' + err.message)); + }).catch(err => showToast('操作失败:' + err.message, 'error')); }); }); @@ -404,7 +404,7 @@ function renderAdminLinks() { if (!ok) return; API.deleteLink(this.dataset.linkid).then(() => { loadLinks(); - }).catch(err => alert('删除失败:' + err.message)); + }).catch(err => showToast('删除失败:' + err.message, 'error')); }); }); }).catch(() => {}); @@ -413,12 +413,12 @@ function renderAdminLinks() { document.getElementById('addLinkBtn').addEventListener('click', function() { const title = document.getElementById('newLinkTitle').value.trim(); const url = document.getElementById('newLinkUrl').value.trim(); - if (!title || !url) { alert('请填写完整信息'); return; } + if (!title || !url) { showToast('请填写完整信息', 'warning'); return; } API.addLink(title, url).then(() => { document.getElementById('newLinkTitle').value = ''; document.getElementById('newLinkUrl').value = ''; loadLinks(); - }).catch(err => alert('添加失败:' + err.message)); + }).catch(err => showToast('添加失败:' + err.message, 'error')); }); } @@ -445,7 +445,7 @@ function renderAdminSettings() { document.getElementById('settingsForumSave').addEventListener('click', async () => { const name = document.getElementById('settingsForumName').value.trim(); - if (!name) { alert('请输入论坛名称'); return; } + if (!name) { showToast('请输入论坛名称', 'warning'); return; } try { await API.updateSettings(name); document.getElementById('settingsResult').innerHTML = `${getIcon('success')} 保存成功!`; @@ -669,7 +669,7 @@ function loadCustomPageList() { API.deleteCustomPage(this.dataset.id).then(() => { loadCustomPageList(); loadCustomPagesNav(); - }).catch(err => alert('删除失败:' + err.message)); + }).catch(err => showToast('删除失败:' + err.message, 'error')); }); }); }).catch(err => { @@ -728,11 +728,11 @@ function openCustomPageEditor(page) { const content = document.getElementById('editorContent').value.trim(); const enabled = document.getElementById('editorEnabled').value === 'true'; - if (!name) { alert('请输入页面名称'); return; } - if (!title) { alert('请输入导航栏显示名称'); return; } - if (!content) { alert('请输入页面内容'); return; } + if (!name) { showToast('请输入页面名称', 'warning'); return; } + if (!title) { showToast('请输入导航栏显示名称', 'warning'); return; } + if (!content) { showToast('请输入页面内容', 'warning'); return; } if (!/^[a-zA-Z0-9\-_]+$/.test(name)) { - alert('页面名称只允许字母、数字、短横线和下划线'); + showToast('页面名称只允许字母、数字、短横线和下划线', 'warning'); return; } @@ -746,7 +746,7 @@ function openCustomPageEditor(page) { loadCustomPageList(); loadCustomPagesNav(); } catch (err) { - alert('保存失败:' + err.message); + showToast('保存失败:' + err.message, 'error'); } }); } diff --git a/js/app.js b/js/app.js index f3243eb..33e6a23 100644 --- a/js/app.js +++ b/js/app.js @@ -474,7 +474,7 @@ async function sendMessage() { renderMessageList(); } } catch (err) { - alert('发送失败:' + err.message); + showToast('发送失败:' + err.message, 'error'); } } @@ -497,7 +497,7 @@ async function openPrivateChat(otherUserId, otherUsername) { } }, 3000); } catch (err) { - alert('打开私信失败:' + err.message); + showToast('打开私信失败:' + err.message, 'error'); } } @@ -520,15 +520,15 @@ function handleImageFiles(files) { for (const file of files) { if (selectedImageFiles.length >= 6) { - alert('每篇帖子最多上传 6 张图片'); + showToast('每篇帖子最多上传 6 张图片', 'warning'); break; } if (!['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(file.type)) { - alert('图片 ' + file.name + ' 格式不支持'); + showToast('图片 ' + file.name + ' 格式不支持', 'error'); continue; } if (file.size > 5 * 1024 * 1024) { - alert('图片 ' + file.name + ' 超过 5MB,请压缩后上传'); + showToast('图片 ' + file.name + ' 超过 5MB,请压缩后上传', 'warning'); continue; } @@ -911,17 +911,17 @@ async function renderSettingsPage(tab = 'profile') { const username = document.getElementById('settingsUsername').value.trim(); const bio = document.getElementById('settingsBio').value.trim(); const signature = document.getElementById('settingsSignature').value.trim(); - if (!username) { alert('用户名不能为空'); return; } + if (!username) { showToast('用户名不能为空', 'error'); return; } try { await API.updateProfile(user.id, username, bio, signature); currentUser.username = username; currentUser.bio = bio; currentUser.signature = signature; - alert('保存成功!'); + showToast('保存成功!', 'success'); renderNav(); renderSettingsPage('profile'); } catch (err) { - alert('保存失败:' + err.message); + showToast('保存失败:' + err.message, 'error'); } }); } @@ -1045,7 +1045,7 @@ async function renderSettingsPage(tab = 'profile') { const countData = await API.getRecoveryCodesCount(); if (recoveryStatus) recoveryStatus.textContent = '剩余 ' + (countData.count || 0) + ' 个可用恢复码'; } catch (err) { - alert('获取恢复码失败:' + err.message); + showToast('获取恢复码失败:' + err.message, 'error'); } }); } @@ -1064,7 +1064,7 @@ async function renderSettingsPage(tab = 'profile') { const countData = await API.getRecoveryCodesCount(); if (recoveryStatus) recoveryStatus.textContent = '剩余 ' + (countData.count || 0) + ' 个可用恢复码'; } catch (err) { - alert('重新生成失败:' + err.message); + showToast('重新生成失败:' + err.message, 'error'); } }); } @@ -1118,7 +1118,7 @@ function openEditModal(postId, currentTitle, currentContent) { modal.querySelector('#editPostSaveBtn').addEventListener('click', async function() { const title = document.getElementById('editPostTitle').value.trim() || '无标题'; const content = document.getElementById('editPostContent').value.trim(); - if (!content) { alert('请填写内容'); return; } + if (!content) { showToast('请填写内容', 'warning'); return; } try { await API.updatePost(postId, title, content); @@ -1128,9 +1128,9 @@ function openEditModal(postId, currentTitle, currentContent) { } else { renderFeed(); } - alert('编辑成功!'); + showToast('编辑成功!', 'success'); } catch (err) { - alert('编辑失败:' + err.message); + showToast('编辑失败:' + err.message, 'error'); } }); } @@ -1335,7 +1335,7 @@ async function init() { e.preventDefault(); const page = this.dataset.page; if (page === 'admin' && currentUser?.role !== 'admin') { - alert('无权限访问'); + showToast('无权限访问', 'error'); return; } closeDropdown(document.getElementById('dropdownMenu')); @@ -1398,13 +1398,13 @@ async function init() { // ===== 发帖 ===== document.getElementById('fab').addEventListener('click', () => { - if (!currentUser) { alert('请先登录'); return; } + if (!currentUser) { showToast('请先登录', 'warning'); return; } switchPage('new'); }); document.getElementById('postSubmit').addEventListener('click', async () => { if (!currentUser || !currentUser.id) { - alert('请先登录'); + showToast('请先登录', 'warning'); switchPage('feed'); return; } @@ -1412,8 +1412,8 @@ async function init() { const content = document.getElementById('postContent').value.trim(); const captchaInput = document.getElementById('postCaptchaInput').value.trim(); const captchaAnswer = parseInt(document.getElementById('postCaptchaInput').dataset.answer); - if (!content) { alert('请填写内容'); return; } - if (parseInt(captchaInput) !== captchaAnswer) { alert('验证码错误,请重新计算'); refreshCaptcha('post'); return; } + if (!content) { showToast('请填写内容', 'warning'); return; } + if (parseInt(captchaInput) !== captchaAnswer) { showToast('验证码错误,请重新计算', 'error'); refreshCaptcha('post'); return; } const submitButton = document.getElementById('postSubmit'); submitButton.disabled = true; submitButton.textContent = selectedImageFiles.length ? '上传图片中...' : '发布中...'; @@ -1425,13 +1425,13 @@ async function init() { } await API.createPost(title, content, images); - alert('发布成功!'); + showToast('发布成功!', 'success'); clearSelectedImages(); switchPage('feed'); renderFeed(); renderStats(); } catch (err) { - alert('发布失败:' + err.message); + showToast('发布失败:' + err.message, 'error'); } finally { submitButton.disabled = false; submitButton.textContent = '发布帖子'; @@ -1489,10 +1489,10 @@ async function init() { try { await API.createReport(reportTargetPostId, reason); closeModal(document.getElementById('reportModal')); - alert('举报已提交,管理员将尽快处理'); + showToast('举报已提交,管理员将尽快处理', 'success'); reportTargetPostId = null; } catch (err) { - alert('举报失败:' + err.message); + showToast('举报失败:' + err.message, 'error'); } }); @@ -1533,7 +1533,7 @@ async function init() { messageBtn.parentNode.replaceChild(newBtn, messageBtn); newBtn.addEventListener('click', function(e) { e.stopPropagation(); - if (!currentUser) { alert('请先登录'); return; } + if (!currentUser) { showToast('请先登录', 'warning'); return; } openMessageList(); }); } diff --git a/js/auth.js b/js/auth.js index a317d91..71fd3b4 100644 --- a/js/auth.js +++ b/js/auth.js @@ -10,7 +10,7 @@ document.getElementById('loginBtn').addEventListener('click', () => { document.getElementById('loginSubmit').addEventListener('click', async () => { const email = document.getElementById('loginEmail').value.trim(); const password = document.getElementById('loginPassword').value; - if (!email || !password) { alert('请填写完整信息'); return; } + if (!email || !password) { showToast('请填写完整信息', 'warning'); return; } try { const result = await API.login(email, password); closeModal(document.getElementById('loginModal')); @@ -27,7 +27,7 @@ document.getElementById('loginSubmit').addEventListener('click', async () => { } } } catch (err) { - alert('登录失败:' + err.message); + showToast('登录失败:' + err.message, 'error'); } }); @@ -66,13 +66,13 @@ document.getElementById('registerSubmit').addEventListener('click', async () => : ''; const captchaInput = document.getElementById('regCaptchaInput').value.trim(); const captchaAnswer = parseInt(document.getElementById('regCaptchaInput').dataset.answer); - if (!username || !email || !password) { alert('请填写完整信息'); return; } - if (password.length < 6) { alert('密码至少6位'); return; } - if (parseInt(captchaInput) !== captchaAnswer) { alert('验证码错误,请重新计算'); refreshCaptcha('reg'); return; } + if (!username || !email || !password) { showToast('请填写完整信息', 'warning'); return; } + if (password.length < 6) { showToast('密码至少6位', 'warning'); return; } + if (parseInt(captchaInput) !== captchaAnswer) { showToast('验证码错误,请重新计算', 'error'); refreshCaptcha('reg'); return; } try { await API.register(email, password, username, bootstrapToken); } catch (err) { - alert('注册失败:' + err.message); + showToast('注册失败:' + err.message, 'error'); return; } @@ -95,7 +95,7 @@ document.getElementById('registerSubmit').addEventListener('click', async () => renderStats(); } } catch (err) { - alert('注册成功,但自动登录失败,请手动登录:' + err.message); + showToast('注册成功,但自动登录失败,请手动登录:' + err.message, 'error'); return; } @@ -106,7 +106,7 @@ document.getElementById('registerSubmit').addEventListener('click', async () => } } catch (err) { console.warn('恢复码生成失败:', err); - alert('注册并登录成功,但恢复码生成失败。请稍后在设置中重新生成。'); + showToast('注册并登录成功,但恢复码生成失败。请稍后在设置中重新生成。', 'error'); } }); diff --git a/js/feed.js b/js/feed.js index 06171b7..260db33 100644 --- a/js/feed.js +++ b/js/feed.js @@ -187,7 +187,7 @@ function renderFeed() { container.querySelectorAll('.action-report').forEach(btn => { btn.addEventListener('click', function(e) { e.stopPropagation(); - if (!currentUser) { alert('请先登录'); return; } + if (!currentUser) { showToast('请先登录', 'warning'); return; } reportTargetPostId = this.dataset.postid; document.getElementById('reportModal').classList.add('active'); }); @@ -202,7 +202,7 @@ function renderFeed() { API.deletePost(this.dataset.postid).then(() => { renderFeed(); renderStats(); - }).catch(err => alert('删除失败:' + err.message)); + }).catch(err => showToast('删除失败:' + err.message, 'error')); }); }); }).catch(err => { diff --git a/js/post.js b/js/post.js index 920369b..43e73a3 100644 --- a/js/post.js +++ b/js/post.js @@ -159,7 +159,7 @@ async function renderPostDetail(postId) { API.togglePinPost(postId).then(() => { renderPostDetail(postId); renderFeed(); - }).catch(err => alert('操作失败:' + err.message)); + }).catch(err => showToast('操作失败:' + err.message, 'error')); }); } @@ -182,11 +182,11 @@ async function renderPostDetail(postId) { }); if (!ok) return; API.deletePost(postId).then(() => { - alert('删除成功'); + showToast('删除成功', 'success'); switchPage('feed'); renderFeed(); renderStats(); - }).catch(err => alert('删除失败:' + err.message)); + }).catch(err => showToast('删除失败:' + err.message, 'error')); }); } @@ -200,7 +200,7 @@ async function renderPostDetail(postId) { if (!ok) return; API.deleteReply(replyId).then(() => { renderPostDetail(postId); - }).catch(err => alert('删除失败:' + err.message)); + }).catch(err => showToast('删除失败:' + err.message, 'error')); }); }); @@ -229,12 +229,12 @@ async function renderPostDetail(postId) { } async function handleReplySubmit(postId) { - if (!currentUser) { alert('请先登录'); return; } + if (!currentUser) { showToast('请先登录', 'warning'); return; } const content = document.getElementById('replyContent').value.trim(); const captchaInput = document.getElementById('replyCaptchaInput').value.trim(); const captchaAnswer = parseInt(document.getElementById('replyCaptchaInput').dataset.answer); - if (!content) { alert('请填写回复内容'); return; } - if (parseInt(captchaInput) !== captchaAnswer) { alert('验证码错误,请重新计算'); refreshCaptcha('reply'); return; } + if (!content) { showToast('请填写回复内容', 'warning'); return; } + if (parseInt(captchaInput) !== captchaAnswer) { showToast('验证码错误,请重新计算', 'error'); refreshCaptcha('reply'); return; } try { await API.createReply(postId, content); @@ -244,6 +244,6 @@ async function handleReplySubmit(postId) { } renderStats(); } catch (err) { - alert('回复失败:' + err.message); + showToast('回复失败:' + err.message, 'error'); } } diff --git a/style.css b/style.css index e32efb0..84a1b55 100644 --- a/style.css +++ b/style.css @@ -2960,3 +2960,99 @@ a.btn-secondary { width: 100%; } } + +/* ============================================================ + ⌨️ 输入框统一凹陷效果 + ------------------------------------------------------------ + 输入框样式此前散落在至少 8 组选择器里(.modal-content / + #pageSettings / #pageNew / #replyArea / #chatInput 等),各写一套 + 背景色,亮色下多为半透明白叠在白底上,几乎看不出输入区边界。 + 这里统一收口,给所有输入控件加上内凹阴影,靠「凹陷」而非描边 + 来表明可输入区域。 + + 实现要点: + - 用 inset box-shadow 制造整体内凹(上深下浅,模拟受光方向) + - 亮色用白底 + 深色内阴影;暗色用深底 + 更深内阴影 + - 聚焦时凹陷消失并换成品牌色光晕,形成明确的「浮起可编辑」反馈 + - !important 用于压过各处既有的散装 background/border 声明 + ============================================================ */ + +:root { + /* 凹陷:上方投影较重、下方较浅,模拟向内受光 */ + --inset-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.12), + inset 0 1px 2px rgba(0, 0, 0, 0.08); + --inset-border: rgba(0, 0, 0, 0.18); + /* 输入区底色需与白色弹窗/卡片明显区分,取值偏灰以保证一眼可辨 */ + --inset-bg: #eef1f6; + /* 聚焦时的实心底色:亮色取白,暗色取深色(下方按主题覆盖) */ + --input-focus-bg: #ffffff; +} + +[data-theme="dark"] { + --inset-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55), + inset 0 1px 2px rgba(0, 0, 0, 0.4); + --inset-border: rgba(255, 255, 255, 0.14); + /* 比弹窗底色更深,形成下沉感 */ + --inset-bg: rgba(0, 0, 0, 0.32); + --input-focus-bg: rgba(0, 0, 0, 0.42); +} + +/* 覆盖所有文本输入控件。排除 checkbox/radio/file/range/color 等 + 非文本控件,它们用凹陷阴影会显得突兀。 */ +input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]), +textarea, +select { + background: var(--inset-bg) !important; + border: 1px solid var(--inset-border) !important; + box-shadow: var(--inset-shadow) !important; + border-radius: var(--radius-sm) !important; + transition: box-shadow var(--dur-base, 0.26s) ease, + border-color var(--dur-base, 0.26s) ease, + background var(--dur-base, 0.26s) ease !important; +} + +/* 聚焦:内凹消失,换成品牌色外发光,明确当前编辑目标 */ +input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):focus, +textarea:focus, +select:focus { + outline: none !important; + background: var(--input-focus-bg) !important; + border-color: var(--primary) !important; + box-shadow: 0 0 0 3px var(--primary-glow), 0 1px 2px rgba(0, 0, 0, 0.05) !important; +} + +[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):focus, +[data-theme="dark"] textarea:focus, +[data-theme="dark"] select:focus { + background: var(--input-focus-bg) !important; +} + +/* 悬停时轻微加深边框,提示可交互 */ +input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):hover:not(:focus), +textarea:hover:not(:focus), +select:hover:not(:focus) { + border-color: rgba(0, 0, 0, 0.24) !important; +} + +[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]):hover:not(:focus), +[data-theme="dark"] textarea:hover:not(:focus), +[data-theme="dark"] select:hover:not(:focus) { + border-color: rgba(255, 255, 255, 0.2) !important; +} + +/* 占位符与被禁用状态 */ +input::placeholder, +textarea::placeholder { + color: var(--glass-text-light) !important; + opacity: 0.75; +} + +input:disabled, +textarea:disabled, +select:disabled { + opacity: 0.55; + cursor: not-allowed; + box-shadow: none !important; +} + +/* 搜索框、验证码等内嵌小输入框同样适用,无需单独处理 */