feat(settings): 支持系统设置按模块独立保存负载
This commit is contained in:
parent
681ecfc735
commit
bfc36d3ad3
@ -820,20 +820,21 @@ export function useDashboard() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
async function saveSettings(section) {
|
||||
settingsError.value = "";
|
||||
if (!canManageSystemSettings.value) {
|
||||
settingsError.value = "只有超级管理员可以保存系统设置";
|
||||
return;
|
||||
}
|
||||
verificationClock.value = Date.now();
|
||||
if (!dnsReadyToSave.value) {
|
||||
// 只有在保存全部或保存 DNS 配置时才强依赖 DNS API 测试
|
||||
if ((!section || section === "dns") && !dnsReadyToSave.value) {
|
||||
settingsError.value = "DNS 服务商配置尚未通过在线测试,请先完成测试";
|
||||
return;
|
||||
}
|
||||
settingsSaving.value = true;
|
||||
try {
|
||||
const payload = settingsPayload(settingsForm.value);
|
||||
const payload = settingsPayload(settingsForm.value, section);
|
||||
const response = await fetchAdmin("/api/v1/settings", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@ -842,8 +843,7 @@ export function useDashboard() {
|
||||
const result = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(result.error || "保存系统设置失败");
|
||||
settings.value = result.settings;
|
||||
showSettings.value = false;
|
||||
notice.value = result.message || "系统设置已保存";
|
||||
notice.value = result.message || "设置已保存";
|
||||
await loadData();
|
||||
} catch (err) {
|
||||
settingsError.value = err.message || "保存系统设置失败";
|
||||
|
||||
@ -19,21 +19,24 @@ const requestFields = {
|
||||
],
|
||||
};
|
||||
|
||||
export function settingsPayload(current) {
|
||||
export function settingsPayload(current, targetSection) {
|
||||
const payload = {};
|
||||
for (const [section, fields] of Object.entries(requestFields)) {
|
||||
if (targetSection && targetSection !== section) continue;
|
||||
const source = current[section] || {};
|
||||
payload[section] = Object.fromEntries(
|
||||
fields.filter((field) => source[field] !== undefined)
|
||||
.map((field) => [field, source[field]]),
|
||||
);
|
||||
}
|
||||
const dns = current.dns || {};
|
||||
payload.dns = { provider: dns.provider };
|
||||
if (dns.credential_ref && dns.verification_token) {
|
||||
payload.dns.credential_ref = dns.credential_ref;
|
||||
payload.dns.verification_token = dns.verification_token;
|
||||
payload.dns.test_domain = dns.test_domain;
|
||||
if (!targetSection || targetSection === "dns") {
|
||||
const dns = current.dns || {};
|
||||
payload.dns = { provider: dns.provider };
|
||||
if (dns.credential_ref && dns.verification_token) {
|
||||
payload.dns.credential_ref = dns.credential_ref;
|
||||
payload.dns.verification_token = dns.verification_token;
|
||||
payload.dns.test_domain = dns.test_domain;
|
||||
}
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user