Skip to content

Commit 6522070

Browse files
authored
Merge pull request #625 from MoYingJi/feat
feat(setting): 添加清空歌词排除列表功能
2 parents 31fefa7 + 173a7ee commit 6522070

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

src/components/Modal/Setting/ExcludeLyrics.vue

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
</n-tab-pane>
1212

1313
<template #suffix>
14-
<n-button type="primary" strong secondary @click="reset">重置此页</n-button>
14+
<n-flex>
15+
<n-button type="primary" strong secondary @click="clear">清空此页</n-button>
16+
<n-button type="primary" strong secondary @click="reset">重置此页</n-button>
17+
</n-flex>
1518
</template>
1619
</n-tabs>
1720
</div>
@@ -25,16 +28,42 @@ const settingStore = useSettingStore();
2528
2629
const page = ref("keywords");
2730
28-
const reset = () => {
29-
switch (page.value) {
30-
case "keywords":
31-
settingStore.excludeKeywords = keywords;
32-
break;
33-
case "regexes":
34-
settingStore.excludeRegexes = regexes;
35-
break;
36-
}
31+
const pageConfig = {
32+
keywords: {
33+
name: "关键词",
34+
storeKey: "excludeKeywords",
35+
defaultValue: keywords,
36+
},
37+
regexes: {
38+
name: "正则表达式",
39+
storeKey: "excludeRegexes",
40+
defaultValue: regexes,
41+
},
42+
} as const;
43+
44+
const handleAction = (action: "clear" | "reset") => {
45+
const pageKey = page.value as keyof typeof pageConfig;
46+
const { name, storeKey, defaultValue } = pageConfig[pageKey];
47+
const isClear = action === "clear";
48+
49+
const actionText = isClear ? "清空" : "重置";
50+
const contentDetail = isClear ? "" : "为默认值";
51+
const successMessage = isClear ? "列表已清空" : "列表已重置为默认值";
52+
53+
window.$dialog.warning({
54+
title: `${actionText}确认`,
55+
content: `确认${actionText}${name}列表${contentDetail}?该操作不可撤销!`,
56+
positiveText: "确认",
57+
negativeText: "取消",
58+
onPositiveClick: () => {
59+
settingStore[storeKey] = isClear ? [] : defaultValue;
60+
window.$message.success(`${name}${successMessage}`);
61+
},
62+
});
3763
};
64+
65+
const clear = () => handleAction("clear");
66+
const reset = () => handleAction("reset");
3867
</script>
3968

4069
<style lang="scss" scoped>

0 commit comments

Comments
 (0)