迁移自动事件后台开关

This commit is contained in:
2026-04-25 13:14:20 +08:00
parent bb401b8940
commit ed7ff81321
3 changed files with 93 additions and 27 deletions
+2 -27
View File
@@ -98,7 +98,8 @@
{{ $event->jjb_change > 0 ? '+' : '' }}{{ $event->jjb_change }}
</td>
<td class="p-3">
<button onclick="toggleEvent({{ $event->id }}, this)"
<button type="button"
data-autoact-toggle-url="{{ route('admin.autoact.toggle', $event->id) }}"
class="text-xs px-2 py-1 rounded {{ $event->enabled ? 'bg-green-100 text-green-700' : 'bg-gray-200 text-gray-500' }} cursor-pointer">
{{ $event->enabled ? '启用' : '禁用' }}
</button>
@@ -124,30 +125,4 @@
</div>
</div>
<script>
/**
* 切换事件启用/禁用状态
*/
function toggleEvent(id, btn) {
fetch(`/admin/autoact/${id}/toggle`, {
method: 'POST',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Content-Type': 'application/json',
'Accept': 'application/json',
},
})
.then(r => r.json())
.then(data => {
if (data.status === 'success') {
btn.textContent = data.enabled ? '启用' : '禁用';
btn.className = data.enabled ?
'text-xs px-2 py-1 rounded bg-green-100 text-green-700 cursor-pointer' :
'text-xs px-2 py-1 rounded bg-gray-200 text-gray-500 cursor-pointer';
// 切换行透明度
btn.closest('tr').classList.toggle('opacity-40', !data.enabled);
}
});
}
</script>
@endsection