修复:去掉多余的 @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:
@@ -402,61 +402,51 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
@endsection
|
|
||||||
|
|
||||||
@push('scripts')
|
{{-- inlinePatch:职务列表内联编辑 Alpine 工厂函数(失焦/回车自动 PATCH 保存) --}}
|
||||||
<script>
|
<script>
|
||||||
/**
|
function inlinePatch(positionId, field, initial) {
|
||||||
* inlinePatch - 职务列表内联编辑 Alpine 工厂函数
|
return {
|
||||||
* 失焦或回车时自动 PATCH 保存单个字段到后端
|
val: initial, // null = 显示为空(placeholder "不限")
|
||||||
*
|
saving: false,
|
||||||
* @param {number} positionId - 职务 ID
|
saved: false,
|
||||||
* @param {string} field - 要更新的字段名
|
error: '',
|
||||||
* @param {number|null} initial - 初始值(null = 不限)
|
|
||||||
*/
|
|
||||||
function inlinePatch(positionId, field, initial) {
|
|
||||||
return {
|
|
||||||
val: initial, // null = 显示为空(placeholder "不限")
|
|
||||||
saving: false,
|
|
||||||
saved: false,
|
|
||||||
error: '',
|
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
if (this.saving) return;
|
if (this.saving) return;
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
this.saved = false;
|
this.saved = false;
|
||||||
this.error = '';
|
this.error = '';
|
||||||
try {
|
try {
|
||||||
const body = {};
|
const body = {};
|
||||||
// 空字符串清空时发 null(=不限)
|
// 空字符串/null → 发 null(=不限)
|
||||||
body[field] = this.val === '' || this.val === null ? null : Number(this.val);
|
body[field] = (this.val === '' || this.val === null) ? null : Number(this.val);
|
||||||
|
|
||||||
const res = await fetch(`/admin/positions/${positionId}/patch`, {
|
const res = await fetch(`/admin/positions/${positionId}/patch`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]')?.content ||
|
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]')?.content || '',
|
||||||
'{{ csrf_token() }}',
|
'Accept': 'application/json',
|
||||||
'Accept': 'application/json',
|
},
|
||||||
},
|
body: JSON.stringify(body),
|
||||||
body: JSON.stringify(body),
|
});
|
||||||
});
|
if (res.ok) {
|
||||||
if (res.ok) {
|
this.saved = true;
|
||||||
this.saved = true;
|
setTimeout(() => this.saved = false, 2000);
|
||||||
setTimeout(() => this.saved = false, 2000);
|
} else {
|
||||||
} else {
|
const d = await res.json().catch(() => ({}));
|
||||||
const d = await res.json().catch(() => ({}));
|
this.error = d.message || '保存失败';
|
||||||
this.error = d.message || '保存失败';
|
setTimeout(() => this.error = '', 3000);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
this.error = '网络异常';
|
||||||
setTimeout(() => this.error = '', 3000);
|
setTimeout(() => this.error = '', 3000);
|
||||||
}
|
}
|
||||||
} catch {
|
this.saving = false;
|
||||||
this.error = '网络异常';
|
|
||||||
setTimeout(() => this.error = '', 3000);
|
|
||||||
}
|
}
|
||||||
this.saving = false;
|
};
|
||||||
}
|
}
|
||||||
};
|
</script>
|
||||||
}
|
</div>
|
||||||
</script>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
Reference in New Issue
Block a user