迁移职务内联保存脚本

This commit is contained in:
2026-04-25 13:38:00 +08:00
parent b7af9330c4
commit 35cbfedeb7
3 changed files with 81 additions and 45 deletions
@@ -505,50 +505,5 @@
</div>
</div>
{{-- inlinePatch:职务列表内联编辑 Alpine 工厂函数(失焦/回车自动 PATCH 保存) --}}
<script>
function inlinePatch(positionId, field, initial) {
return {
val: initial, // null = 显示为空(placeholder "不限"
saving: false,
saved: false,
error: '',
async save() {
if (this.saving) return;
this.saving = true;
this.saved = false;
this.error = '';
try {
const body = {};
// 空字符串/null → 发 null=不限)
body[field] = (this.val === '' || this.val === null) ? null : Number(this.val);
const res = await fetch(`/admin/positions/${positionId}/patch`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]')?.content || '',
'Accept': 'application/json',
},
body: JSON.stringify(body),
});
if (res.ok) {
this.saved = true;
setTimeout(() => this.saved = false, 2000);
} else {
const d = await res.json().catch(() => ({}));
this.error = d.message || '保存失败';
setTimeout(() => this.error = '', 3000);
}
} catch {
this.error = '网络异常';
setTimeout(() => this.error = '', 3000);
}
this.saving = false;
}
};
}
</script>
</div>
@endsection