优化(系统设置): 实现未保存前前端内存暂存与草稿保留
This commit is contained in:
parent
3ee6a34cc1
commit
a5b7832d53
@ -64,6 +64,8 @@ export function useDashboard() {
|
|||||||
let dnsVerificationTimer;
|
let dnsVerificationTimer;
|
||||||
let dnsRequestVersion = 0;
|
let dnsRequestVersion = 0;
|
||||||
const settingsForm = ref(createEmptySettingsForm());
|
const settingsForm = ref(createEmptySettingsForm());
|
||||||
|
const settingsDraftDirty = ref(false);
|
||||||
|
const settingsDraftBaseline = ref(null);
|
||||||
const showCertificateImport = ref(false);
|
const showCertificateImport = ref(false);
|
||||||
const importDomain = ref(null);
|
const importDomain = ref(null);
|
||||||
const importSaving = ref(false);
|
const importSaving = ref(false);
|
||||||
@ -899,12 +901,18 @@ export function useDashboard() {
|
|||||||
settingsError.value = "只有超级管理员可以配置邮件通知和系统设置";
|
settingsError.value = "只有超级管理员可以配置邮件通知和系统设置";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settingsForm.value = normalizeSettings(settings.value);
|
if (!settingsDraftDirty.value) {
|
||||||
|
settingsForm.value = normalizeSettings(settings.value);
|
||||||
|
settingsDraftBaseline.value = JSON.stringify(settingsForm.value);
|
||||||
|
}
|
||||||
showSettings.value = true;
|
showSettings.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeSettings() {
|
function closeSettings() {
|
||||||
if (!settingsSaving.value) {
|
if (!settingsSaving.value) {
|
||||||
|
if (settingsDraftBaseline.value && JSON.stringify(settingsForm.value) !== settingsDraftBaseline.value) {
|
||||||
|
settingsDraftDirty.value = true;
|
||||||
|
}
|
||||||
handleDNSProviderChange();
|
handleDNSProviderChange();
|
||||||
showSettings.value = false;
|
showSettings.value = false;
|
||||||
}
|
}
|
||||||
@ -938,6 +946,9 @@ export function useDashboard() {
|
|||||||
const result = await response.json().catch(() => ({}));
|
const result = await response.json().catch(() => ({}));
|
||||||
if (!response.ok) throw new Error(result.error || "保存系统设置失败");
|
if (!response.ok) throw new Error(result.error || "保存系统设置失败");
|
||||||
settings.value = result.settings;
|
settings.value = result.settings;
|
||||||
|
settingsDraftDirty.value = false;
|
||||||
|
settingsDraftBaseline.value = null;
|
||||||
|
showSettings.value = false;
|
||||||
notice.value = result.message || "设置已保存";
|
notice.value = result.message || "设置已保存";
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -1142,6 +1153,8 @@ export function useDashboard() {
|
|||||||
error.value = "";
|
error.value = "";
|
||||||
currentUser.value = null;
|
currentUser.value = null;
|
||||||
settings.value = null;
|
settings.value = null;
|
||||||
|
settingsDraftDirty.value = false;
|
||||||
|
settingsDraftBaseline.value = null;
|
||||||
settingsForm.value = normalizeSettings(null);
|
settingsForm.value = normalizeSettings(null);
|
||||||
showSettings.value = false;
|
showSettings.value = false;
|
||||||
try {
|
try {
|
||||||
@ -1211,7 +1224,10 @@ export function useDashboard() {
|
|||||||
value: item.id,
|
value: item.id,
|
||||||
label: item.name,
|
label: item.name,
|
||||||
}));
|
}));
|
||||||
settingsForm.value = normalizeSettings(settings.value);
|
if (!settingsDraftDirty.value) {
|
||||||
|
settingsForm.value = normalizeSettings(settings.value);
|
||||||
|
settingsDraftBaseline.value = JSON.stringify(settingsForm.value);
|
||||||
|
}
|
||||||
const associations = await Promise.all(
|
const associations = await Promise.all(
|
||||||
domains.value.map(async (item) => {
|
domains.value.map(async (item) => {
|
||||||
const response = await fetchAdmin(
|
const response = await fetchAdmin(
|
||||||
@ -1228,6 +1244,8 @@ export function useDashboard() {
|
|||||||
if (version !== loadDataVersion) return;
|
if (version !== loadDataVersion) return;
|
||||||
currentUser.value = null;
|
currentUser.value = null;
|
||||||
settings.value = null;
|
settings.value = null;
|
||||||
|
settingsDraftDirty.value = false;
|
||||||
|
settingsDraftBaseline.value = null;
|
||||||
settingsForm.value = normalizeSettings(null);
|
settingsForm.value = normalizeSettings(null);
|
||||||
error.value = err.message || "无法连接核心服务,请先启动 scert serve";
|
error.value = err.message || "无法连接核心服务,请先启动 scert serve";
|
||||||
} finally {
|
} finally {
|
||||||
@ -1262,6 +1280,7 @@ export function useDashboard() {
|
|||||||
auditLogs,
|
auditLogs,
|
||||||
settings,
|
settings,
|
||||||
settingsForm,
|
settingsForm,
|
||||||
|
settingsDraftDirty,
|
||||||
dnsProviderCatalog,
|
dnsProviderCatalog,
|
||||||
selectedDNSProvider,
|
selectedDNSProvider,
|
||||||
dnsTesting,
|
dnsTesting,
|
||||||
|
|||||||
@ -1217,3 +1217,25 @@ test("workflowTasks.renderOnlySupportedActions", async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
test("系统设置未保存前在前端内存中暂存,关闭后再次打开保留编辑内容", async (t) => {
|
||||||
|
const { state } = await setup(t, () => verifiedResponse());
|
||||||
|
assert.equal(state.showSettings.value, true);
|
||||||
|
state.settingsForm.value.acme.renewal_threshold_days = 88;
|
||||||
|
state.settingsForm.value.notification.smtp_host = "smtp.draft-test.com";
|
||||||
|
state.settingsForm.value.notification.smtp_port = 465;
|
||||||
|
state.settingsForm.value.notification.smtp_username = "draft_user@test.com";
|
||||||
|
|
||||||
|
state.closeSettings();
|
||||||
|
assert.equal(state.showSettings.value, false);
|
||||||
|
assert.equal(state.settingsDraftDirty.value, true);
|
||||||
|
|
||||||
|
state.openSettings();
|
||||||
|
assert.equal(state.showSettings.value, true);
|
||||||
|
assert.equal(state.settingsForm.value.acme.renewal_threshold_days, 88);
|
||||||
|
assert.equal(state.settingsForm.value.notification.smtp_host, "smtp.draft-test.com");
|
||||||
|
assert.equal(state.settingsForm.value.notification.smtp_port, 465);
|
||||||
|
assert.equal(state.settingsForm.value.notification.smtp_username, "draft_user@test.com");
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user