Skip to content

Commit 7fb0d14

Browse files
authored
Merge pull request #780 from MoYingJi/pr/set
refactor(setting): 改了点设置 优化显示效果 更改字段名
2 parents 22589b4 + 598b209 commit 7fb0d14

14 files changed

Lines changed: 539 additions & 275 deletions

File tree

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ declare module 'vue' {
3737
DownloadModal: typeof import('./src/components/Modal/DownloadModal.vue')['default']
3838
DownloadPathButtons: typeof import('./src/components/Setting/components/DownloadPathButtons.vue')['default']
3939
Equalizer: typeof import('./src/components/Modal/Equalizer.vue')['default']
40+
ExcludeComment: typeof import('./src/components/Modal/Setting/ExcludeComment.vue')['default']
4041
ExcludeLyrics: typeof import('./src/components/Modal/Setting/ExcludeLyrics.vue')['default']
4142
FontManager: typeof import('./src/components/Modal/Setting/FontManager.vue')['default']
4243
FullPlayer: typeof import('./src/components/Player/FullPlayer.vue')['default']

src/components/Modal/CommentFilter.vue

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<template>
2+
<div class="exclude-comment-modal">
3+
<n-flex vertical size="large">
4+
<n-card class="switch-card" size="small">
5+
<n-flex align="center" justify="space-between">
6+
<n-text>启用评论排除</n-text>
7+
<n-switch v-model:value="enableExcludeComments" :round="false" />
8+
</n-flex>
9+
</n-card>
10+
11+
<n-tabs v-model:value="page" animated>
12+
<n-tab-pane name="keywords" tab="关键词">
13+
<n-scrollbar style="max-height: 50vh">
14+
<n-flex vertical :size="12">
15+
<n-text depth="3">关键词过滤(支持普通文本匹配)</n-text>
16+
<n-dynamic-tags v-model:value="filterKeywords" />
17+
<n-popconfirm @positive-click="clearKeywords">
18+
<template #trigger>
19+
<n-button type="error" secondary size="small">
20+
<template #icon>
21+
<SvgIcon name="DeleteSweep" />
22+
</template>
23+
清空关键词
24+
</n-button>
25+
</template>
26+
<n-text> 确定要清空所有关键词规则吗? </n-text>
27+
</n-popconfirm>
28+
</n-flex>
29+
</n-scrollbar>
30+
</n-tab-pane>
31+
32+
<n-tab-pane name="regexes" tab="正则表达式">
33+
<n-scrollbar style="max-height: 50vh">
34+
<n-flex vertical :size="12">
35+
<n-text depth="3">正则过滤(支持 JavaScript 正则表达式)</n-text>
36+
<n-dynamic-tags v-model:value="filterRegexes" />
37+
<n-popconfirm @positive-click="clearRegexes">
38+
<template #trigger>
39+
<n-button type="error" secondary size="small">
40+
<template #icon>
41+
<SvgIcon name="DeleteSweep" />
42+
</template>
43+
清空正则表达式
44+
</n-button>
45+
</template>
46+
<n-text> 确定要清空所有正则表达式规则吗? </n-text>
47+
</n-popconfirm>
48+
</n-flex>
49+
</n-scrollbar>
50+
</n-tab-pane>
51+
</n-tabs>
52+
53+
<n-divider style="margin: 6px 0" />
54+
55+
<n-flex justify="space-between">
56+
<n-flex>
57+
<n-popconfirm @positive-click="clearAll">
58+
<template #trigger>
59+
<n-button type="error" secondary>
60+
<template #icon>
61+
<SvgIcon name="DeleteSweep" />
62+
</template>
63+
清空全部
64+
</n-button>
65+
</template>
66+
<n-text> 确定要清空所有过滤规则(关键词和正则表达式)吗? </n-text>
67+
</n-popconfirm>
68+
<n-button secondary @click="importFilters"> 导入 </n-button>
69+
<n-button secondary @click="exportFilters"> 导出 </n-button>
70+
</n-flex>
71+
<n-flex>
72+
<n-button @click="handleClose">取消</n-button>
73+
<n-button type="primary" @click="saveFilter">保存</n-button>
74+
</n-flex>
75+
</n-flex>
76+
</n-flex>
77+
</div>
78+
</template>
79+
80+
<script setup lang="ts">
81+
import { useSettingStore } from "@/stores";
82+
83+
const emit = defineEmits(["close"]);
84+
85+
const settingStore = useSettingStore();
86+
87+
const enableExcludeComments = ref(settingStore.enableExcludeComments);
88+
const filterKeywords = ref<string[]>([]);
89+
const filterRegexes = ref<string[]>([]);
90+
const page = ref("keywords");
91+
92+
// 清空关键词
93+
const clearKeywords = () => {
94+
filterKeywords.value = [];
95+
};
96+
97+
// 清空正则表达式
98+
const clearRegexes = () => {
99+
filterRegexes.value = [];
100+
};
101+
102+
// 清空全部
103+
const clearAll = () => {
104+
filterKeywords.value = [];
105+
filterRegexes.value = [];
106+
};
107+
108+
// 导出规则
109+
const exportFilters = () => {
110+
const data = {
111+
keywords: settingStore.excludeCommentKeywords || [],
112+
regexes: settingStore.excludeCommentRegexes || [],
113+
};
114+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
115+
const url = URL.createObjectURL(blob);
116+
const a = document.createElement("a");
117+
a.href = url;
118+
a.download = "splayer-comment-filters.json";
119+
a.click();
120+
URL.revokeObjectURL(url);
121+
};
122+
123+
// 导入规则
124+
const importFilters = () => {
125+
const input = document.createElement("input");
126+
input.type = "file";
127+
input.accept = ".json";
128+
input.onchange = (e: any) => {
129+
const file = e.target.files[0];
130+
if (!file) return;
131+
const reader = new FileReader();
132+
reader.onload = (e) => {
133+
try {
134+
const data = JSON.parse(e.target?.result as string);
135+
if (data.keywords && Array.isArray(data.keywords)) {
136+
filterKeywords.value = data.keywords;
137+
}
138+
if (data.regexes && Array.isArray(data.regexes)) {
139+
filterRegexes.value = data.regexes;
140+
}
141+
window.$message.success("规则导入成功");
142+
} catch (error) {
143+
console.error("Import filters error:", error);
144+
window.$message.error("规则文件解析失败");
145+
}
146+
};
147+
reader.readAsText(file);
148+
};
149+
input.click();
150+
};
151+
152+
// 保存过滤
153+
const saveFilter = () => {
154+
settingStore.enableExcludeComments = enableExcludeComments.value;
155+
settingStore.excludeCommentKeywords = filterKeywords.value;
156+
settingStore.excludeCommentRegexes = filterRegexes.value;
157+
window.$message.success("设置已保存");
158+
handleClose();
159+
};
160+
161+
const handleClose = () => {
162+
emit("close");
163+
};
164+
165+
onMounted(() => {
166+
enableExcludeComments.value = settingStore.enableExcludeComments;
167+
filterKeywords.value = [...(settingStore.excludeCommentKeywords || [])];
168+
filterRegexes.value = [...(settingStore.excludeCommentRegexes || [])];
169+
});
170+
</script>
171+
172+
<style scoped lang="scss">
173+
.exclude-comment-modal {
174+
padding: 0;
175+
.switch-card {
176+
width: 100%;
177+
border-radius: 8px;
178+
.n-text {
179+
font-size: 16px;
180+
}
181+
}
182+
}
183+
</style>

0 commit comments

Comments
 (0)