修复:去掉多余的 @section 导致的 section 嵌套报错

将 inlinePatch script 块迁移回 @section('content') 内部,
彻底移除 @push/@endpush/@section('scripts') 等无效指令。

根本原因:admin layout 无 @yield('scripts'),在 @endsection 后
再开 @push 或 @section 会触发 'Cannot end a section' 异常。
This commit is contained in:
2026-03-01 11:30:23 +08:00
parent 89d93c92ed
commit 57f515e2eb
+41 -51
View File
@@ -402,61 +402,51 @@
</div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script>
/**
* inlinePatch - 职务列表内联编辑 Alpine 工厂函数
* 失焦或回车时自动 PATCH 保存单个字段到后端
*
* @param {number} positionId - 职务 ID
* @param {string} field - 要更新的字段名
* @param {number|null} initial - 初始值(null = 不限)
*/
function inlinePatch(positionId, field, initial) {
return {
val: initial, // null = 显示为空(placeholder "不限"
saving: false,
saved: false,
error: '',
{{-- 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=不限)
body[field] = this.val === '' || this.val === null ? null : Number(this.val);
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 ||
'{{ csrf_token() }}',
'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 || '保存失败';
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);
}
} catch {
this.error = '网络异常';
setTimeout(() => this.error = '', 3000);
this.saving = false;
}
this.saving = false;
}
};
}
</script>
};
}
</script>
</div>
@endsection