feat(ui): 用 showToast 替代全部原生 alert,输入框统一加凹陷效果
一、替换 53 处原生 alert() 原生 alert() 样式无法定制、只有单一「确定」按钮、且会阻塞页面渲染, 与站点风格割裂。全部改为 showToast(),按语义区分类型: - 失败/错误提示 -> error(36 处) - 表单校验与操作提示 -> warning(21 处) - 成功提示 -> success(9 处) 覆盖 admin.js(12)、app.js(23)、auth.js(8)、feed.js(2)、post.js(8)。 替换用一个括号配平的小脚本完成,避免正则误伤字符串里含括号的文案; 替换后逐文件做了语法检查。 二、输入框统一凹陷效果 输入框样式此前散落在至少 8 组选择器里(.modal-content / #pageSettings / #pageNew / #replyArea / #chatInput 等),各写一套背景色。亮色下多为 半透明白叠在白底上,几乎看不出输入区边界,用户难以分辨哪里可输入。 改为新增一层统一样式(文件末尾),用 inset box-shadow 制造内凹, 靠「凹陷」而非描边表明可输入区域: - 新增 --inset-bg / --inset-border / --inset-shadow / --input-focus-bg 四个变量,亮暗主题各一套 - 亮色:浅灰底 #eef1f6 + 深色内阴影;暗色:更深底色 + 更强内阴影 - 聚焦时内凹消失,换成品牌色外发光,形成明确的「浮起可编辑」反馈 - 悬停时加深边框,提示可交互 - 排除 checkbox / radio / file / range / color 等非文本控件 - 添加 disabled 与 placeholder 状态处理 三、顺带修正 移除此前误加的一份重复暗色输入框规则(项目下方本就有 「暗色模式下的特殊修复」区块处理同一批选择器),并为其补上 border-color,因为亮色边框已改为深色,暗色下需换回浅色。 已用 Puppeteer 实测:亮暗两主题下输入框背景、边框、内凹阴影与聚焦 光晕均符合预期;三种 toast 类型均正常弹出;中文字体渲染正常。
This commit is contained in:
1 parent
51032c44d0
commit
75cc78d5f8
6 files changed
+149
-53
No files matched your search
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user