Skip to content

Commit 4ac6c58

Browse files
committed
feat: 延时自动保存配置文件
1 parent 16836bd commit 4ac6c58

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

MaiChartManager/Front/src/components/ModManager/ConfigEditor.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { computed, defineComponent, onMounted, ref, watch } from "vue";
2-
import { NButton, NCheckbox, NFlex, NModal, NSwitch, useDialog } from "naive-ui";
2+
import { NButton, NCheckbox, NFlex, NModal, NSwitch, useDialog, useMessage } from "naive-ui";
33
import api from "@/client/api";
44
import { globalCapture, modInfo, updateModInfo, updateMusicList, aquaMaiConfig as config } from "@/store/refs";
55
import AquaMaiConfigurator from "./AquaMaiConfigurator";
66
import { shouldShowUpdate } from "./shouldShowUpdateController";
77
import { useStorage } from "@vueuse/core";
8+
import _ from "lodash";
89

910
export default defineComponent({
1011
props: {
@@ -29,6 +30,7 @@ export default defineComponent({
2930
const installingAquaMai = ref(false)
3031
const showAquaMaiInstallDone = ref(false)
3132
const useNewSort = useStorage('useNewSort', true)
33+
const message = useMessage();
3234

3335
const updateAquaMaiConfig = async () => {
3436
try {
@@ -96,17 +98,26 @@ export default defineComponent({
9698
}
9799
}
98100

99-
watch(() => show.value, async (val) => {
101+
const saveImpl = async () => {
102+
if (!config.value) return;
103+
try {
104+
await api.SetAquaMaiConfig(config.value)
105+
await updateMusicList()
106+
message.success("保存配置文件成功")
107+
} catch (e) {
108+
globalCapture(e, "保存 AquaMai 配置失败")
109+
}
110+
}
111+
const save = _.debounce(saveImpl, 2000);
112+
113+
watch(() => config.value, async (val) => {
100114
if (configReadErr.value) return
101-
if (!val && config.value) {
102-
try {
103-
await api.SetAquaMaiConfig(config.value)
104-
await updateMusicList()
105-
} catch (e) {
106-
globalCapture(e, "保存 AquaMai 配置失败")
107-
}
115+
if (!show.value) return
116+
if (val) {
117+
console.log('配置变动')
118+
save()
108119
}
109-
})
120+
}, { deep: true })
110121

111122

112123
return () => <NModal

0 commit comments

Comments
 (0)