收口后台表单确认事件
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// 后台通用表单确认事件代理,集中替代简单的 Blade 内联 onsubmit confirm。
|
||||
|
||||
let adminFormConfirmationsBound = false;
|
||||
|
||||
/**
|
||||
* 绑定后台通用提交确认。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindAdminFormConfirmations() {
|
||||
if (adminFormConfirmationsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
adminFormConfirmationsBound = true;
|
||||
|
||||
document.addEventListener("submit", (event) => {
|
||||
if (!(event.target instanceof HTMLFormElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 删除、撤销、取消等不可逆操作统一由 Blade 提供确认文案。
|
||||
const confirmMessage = event.target.getAttribute("data-admin-confirm");
|
||||
if (confirmMessage && !window.confirm(confirmMessage)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import './bootstrap';
|
||||
import { bindAdminAutoactControls } from './admin/autoact.js';
|
||||
import { bindAdminFishingEventsControls } from './admin/fishing-events.js';
|
||||
import { bindAdminFormConfirmations } from './admin/form-confirmations.js';
|
||||
import { bindAdminGameConfigControls } from './admin/game-configs.js';
|
||||
import { bindAdminHolidayEventsControls } from './admin/holiday-events.js';
|
||||
import { bindAdminOpsControls } from './admin/ops.js';
|
||||
@@ -10,6 +11,7 @@ import { bindAdminSignInRulesControls } from './admin/sign-in-rules.js';
|
||||
// 后台共用入口只注册轻量事件代理,具体页面通过 data-* 属性决定是否响应。
|
||||
bindAdminAutoactControls();
|
||||
bindAdminFishingEventsControls();
|
||||
bindAdminFormConfirmations();
|
||||
bindAdminGameConfigControls();
|
||||
bindAdminHolidayEventsControls();
|
||||
bindAdminOpsControls();
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
</a>
|
||||
<form action="{{ route('admin.appointments.revoke', $up->id) }}" method="POST"
|
||||
class="inline"
|
||||
onsubmit="return confirm('确定撤销【{{ $up->user->username }}】的【{{ $up->position->name }}】职务?撤销后其等级将归 1。')">
|
||||
data-admin-confirm="确定撤销【{{ $up->user->username }}】的【{{ $up->position->name }}】职务?撤销后其等级将归 1。">
|
||||
@csrf @method('DELETE')
|
||||
<button type="submit"
|
||||
class="text-xs bg-red-50 text-red-600 font-bold px-2 py-1 rounded hover:bg-red-600 hover:text-white transition">
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
编辑
|
||||
</a>
|
||||
<form action="{{ route('admin.changelogs.destroy', $log->id) }}" method="POST"
|
||||
onsubmit="return confirm('确定要删除这条日志吗?');">
|
||||
data-admin-confirm="确定要删除这条日志吗?">
|
||||
@csrf @method('DELETE')
|
||||
<button type="submit"
|
||||
class="text-red-600 hover:text-red-800 font-semibold text-xs px-2 py-1 rounded hover:bg-red-50 transition">
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
</button>
|
||||
@if (Auth::id() === 1)
|
||||
<form action="{{ route('admin.departments.destroy', $dept->id) }}" method="POST"
|
||||
onsubmit="return confirm('确定删除部门【{{ $dept->name }}】?该操作会同时删除该部门所有职务(有在职人员时拒绝删除)。')">
|
||||
data-admin-confirm="确定删除部门【{{ $dept->name }}】?该操作会同时删除该部门所有职务(有在职人员时拒绝删除)。">
|
||||
@csrf @method('DELETE')
|
||||
<button type="submit"
|
||||
class="text-xs bg-red-50 text-red-600 font-bold px-3 py-1.5 rounded hover:bg-red-600 hover:text-white transition">
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
</div>
|
||||
@elseif ($m->status === 'pending')
|
||||
<form action="{{ route('admin.marriages.cancel-proposal', $m->id) }}" method="POST"
|
||||
onsubmit="return confirm('确定取消该求婚吗?')">
|
||||
data-admin-confirm="确定取消该求婚吗?">
|
||||
@csrf
|
||||
<button type="submit"
|
||||
class="text-xs bg-amber-50 text-amber-600 font-bold px-3 py-1.5 rounded hover:bg-amber-600 hover:text-white transition">
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<td class="px-4 py-3 text-center">
|
||||
@if ($p->status === 'pending')
|
||||
<form action="{{ route('admin.marriages.cancel-proposal', $p->id) }}" method="POST"
|
||||
onsubmit="return confirm('确定取消该求婚吗?')">
|
||||
data-admin-confirm="确定取消该求婚吗?">
|
||||
@csrf
|
||||
<button type="submit"
|
||||
class="text-xs bg-amber-50 text-amber-600 font-bold px-3 py-1.5 rounded hover:bg-amber-600 hover:text-white transition">
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
</button>
|
||||
@if ($isSuperAdmin)
|
||||
<form method="POST" action="{{ route('admin.shop.destroy', $item) }}"
|
||||
onsubmit="return confirm('确定要删除「{{ $item->name }}」吗?此操作不可撤销!')">
|
||||
data-admin-confirm="确定要删除「{{ $item->name }}」吗?此操作不可撤销!">
|
||||
@csrf @method('DELETE')
|
||||
<button type="submit"
|
||||
class="text-red-500 hover:text-red-700 text-xs font-semibold px-2 py-1 rounded hover:bg-red-50 transition">
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
|
||||
<form action="{{ route('admin.users.destroy', $user->id) }}" method="POST"
|
||||
class="inline"
|
||||
onsubmit="return confirm('危险:确定彻底物理清除用户 [{{ $user->username }}] 吗?数据不可恢复!')">
|
||||
data-admin-confirm="危险:确定彻底物理清除用户 [{{ $user->username }}] 吗?数据不可恢复!">
|
||||
@csrf @method('DELETE')
|
||||
<button type="submit"
|
||||
class="text-xs bg-red-50 text-red-600 font-bold px-3 py-1.5 rounded hover:bg-red-600 hover:text-white transition cursor-pointer">
|
||||
|
||||
@@ -171,7 +171,7 @@
|
||||
编辑
|
||||
</button>
|
||||
<form action="{{ route('admin.vip.destroy', $level->id) }}" method="POST"
|
||||
onsubmit="return confirm('确定删除等级 [{{ $level->name }}] 吗?关联用户会变为普通用户。')">
|
||||
data-admin-confirm="确定删除等级 [{{ $level->name }}] 吗?关联用户会变为普通用户。">
|
||||
@csrf @method('DELETE')
|
||||
<button type="submit"
|
||||
class="text-xs bg-red-50 text-red-600 font-bold px-3 py-1.5 rounded hover:bg-red-600 hover:text-white transition">
|
||||
|
||||
Reference in New Issue
Block a user