重构:将聊天室所有原生弹窗替换为全局弹窗,公告增加发送者与时间
- 将设公告、公屏讲话、全员清屏按钮弹窗改为使用 window.chatDialog 全局弹窗 - 所有弹窗改用 .then() 回调注册事件,避免 async/await 行为不一致问题 - 公告内容末尾追加「——发送者 MM-dd HH:mm」,无需新增数据库字段 - 前端编辑公告时自动剥离末尾元信息,用户仅编辑纯内容 - 修复 red-packet-panel.blade.php 中 3 处原生 alert() 残留 - 修复 shop-panel.blade.php 中购买确认 confirm() 原生弹窗残留
This commit is contained in:
@@ -452,36 +452,43 @@
|
||||
|
||||
/** 购买商品 */
|
||||
window.buyItem = function(itemId, name, price) {
|
||||
if (!confirm(`确定花费 ${Number(price).toLocaleString()} 金币购买【${name}】吗?`)) return;
|
||||
fetch('{{ route('shop.buy') }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': _csrf()
|
||||
},
|
||||
body: JSON.stringify({
|
||||
item_id: itemId
|
||||
}),
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
showShopToast(data.message, data.status === 'success');
|
||||
if (data.status === 'success') {
|
||||
if (data.jjb !== undefined)
|
||||
document.getElementById('shop-jjb').textContent = Number(data.jjb)
|
||||
.toLocaleString();
|
||||
if (data.play_effect && window.EffectManager)
|
||||
window.EffectManager.play(data.play_effect);
|
||||
// 刷新商品状态
|
||||
shopLoaded = false;
|
||||
setTimeout(() => {
|
||||
fetchShopData();
|
||||
shopLoaded = true;
|
||||
}, 800);
|
||||
}
|
||||
})
|
||||
.catch(() => showShopToast('⚠ 网络异常,请重试', false));
|
||||
// 使用全局弹窗替代原生 confirm(),通过 .then() 注册回调确保事件正确触发
|
||||
window.chatDialog.confirm(
|
||||
`确定花费 ${Number(price).toLocaleString()} 金币购买【${name}】吗?`,
|
||||
'确认购买',
|
||||
'#336699'
|
||||
).then(ok => {
|
||||
if (!ok) return;
|
||||
fetch('{{ route('shop.buy') }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': _csrf()
|
||||
},
|
||||
body: JSON.stringify({
|
||||
item_id: itemId
|
||||
}),
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
showShopToast(data.message, data.status === 'success');
|
||||
if (data.status === 'success') {
|
||||
if (data.jjb !== undefined)
|
||||
document.getElementById('shop-jjb').textContent = Number(data.jjb)
|
||||
.toLocaleString();
|
||||
if (data.play_effect && window.EffectManager)
|
||||
window.EffectManager.play(data.play_effect);
|
||||
// 刷新商品状态
|
||||
shopLoaded = false;
|
||||
setTimeout(() => {
|
||||
fetchShopData();
|
||||
shopLoaded = true;
|
||||
}, 800);
|
||||
}
|
||||
})
|
||||
.catch(() => showShopToast('⚠ 网络异常,请重试', false));
|
||||
});
|
||||
};
|
||||
|
||||
/** Toast 通知 */
|
||||
|
||||
Reference in New Issue
Block a user