修复PHP改主校验流程:Java失败时PHP自动回退+前端不立即刷新
1. PHP handleUpdateLandOwner: 不再直接更新web_area_lands,写入pending队列,返回pending=true 2. PHP handleOwnerChangeCallback失败时:回退owner为旧值,记录日志 3. PHP admin.php adminTransferLand: 收到pending=true时不立即刷新列表,改为5秒后轮询 4. 按钮禁用防重复提交,等待回调后恢复
This commit is contained in:
@@ -2439,20 +2439,35 @@ async function adminTransferLand(name, currentOwner) {
|
||||
}
|
||||
if (!await glassConfirm('确定将领地 [' + name + '] 改主为 [' + trimmed + '] ?\n(将写入待验证队列,等Java端确认后生效)')) return;
|
||||
try {
|
||||
const btn = event.target;
|
||||
btn.disabled = true;
|
||||
btn.textContent = '验证中...';
|
||||
const res = await fetch('api/land_api.php?action=update_land_owner', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: 'name=' + encodeURIComponent(name) + '&owner=' + encodeURIComponent(trimmed) + '&admin_token=' + (admToken||'')
|
||||
});
|
||||
const d = await res.json();
|
||||
if (d.success) {
|
||||
if (d.success && d.pending) {
|
||||
glassAlert(d.message || '已提交改主请求,等待Java端验证');
|
||||
btn.textContent = '改主';
|
||||
btn.disabled = false;
|
||||
// 不立即刷新列表,改为5秒后轮询检查更新
|
||||
setTimeout(() => loadLands(document.getElementById('C')), 5000);
|
||||
} else if (d.success) {
|
||||
glassAlert(d.message || '改主成功');
|
||||
btn.textContent = '改主';
|
||||
btn.disabled = false;
|
||||
loadLands(document.getElementById('C'));
|
||||
} else {
|
||||
glassAlert('失败: ' + (d.error || ''));
|
||||
btn.textContent = '改主';
|
||||
btn.disabled = false;
|
||||
}
|
||||
} catch(e) {
|
||||
glassAlert('请求失败: ' + e.message);
|
||||
const btn = event.target;
|
||||
if (btn) { btn.textContent = '改主'; btn.disabled = false; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user