Skip to content

Commit 7dc951a

Browse files
committed
✨ feat: 添加自动分类规则配置
1 parent eeb29a8 commit 7dc951a

File tree

1 file changed

+113
-1
lines changed

1 file changed

+113
-1
lines changed

src/components/ConfigView.vue

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<script setup>
2-
import { computed } from 'vue'
2+
import { computed, ref } from 'vue'
33
import { message } from 'ant-design-vue'
44
import { useSettingsStore } from '../stores/settings'
55
66
const settingsStore = useSettingsStore();
77
8+
const showRulesManager = ref(false);
9+
const showEditRule = ref(false);
10+
const editingRuleType = ref('');
11+
const ruleForm = ref({
12+
startsWith: [],
13+
contains: [],
14+
endsWith: []
15+
});
16+
817
// 计算属性绑定到 Pinia store
918
const isKill = computed({
1019
get: () => settingsStore.isKill,
@@ -39,6 +48,45 @@ const saveData = () => {
3948
logs();
4049
}
4150
51+
// 打开分类规则管理
52+
const openRulesManager = () => {
53+
showRulesManager.value = true;
54+
}
55+
56+
// 编辑分类规则
57+
const editRule = (type) => {
58+
editingRuleType.value = type;
59+
const rules = settingsStore.classifyRules[type];
60+
ruleForm.value = {
61+
startsWith: [...(rules.startsWith || [])],
62+
contains: [...(rules.contains || [])],
63+
endsWith: [...(rules.endsWith || [])]
64+
};
65+
showEditRule.value = true;
66+
}
67+
68+
// 保存分类规则
69+
const saveRule = () => {
70+
if (editingRuleType.value) {
71+
const newRules = { ...settingsStore.classifyRules };
72+
newRules[editingRuleType.value] = {
73+
startsWith: ruleForm.value.startsWith.filter(k => k.trim()),
74+
contains: ruleForm.value.contains.filter(k => k.trim()),
75+
endsWith: ruleForm.value.endsWith.filter(k => k.trim())
76+
};
77+
settingsStore.setClassifyRules(newRules);
78+
message.success('规则已更新');
79+
showEditRule.value = false;
80+
editingRuleType.value = '';
81+
}
82+
}
83+
84+
// 重置单个类型的规则
85+
const resetRule = (type) => {
86+
settingsStore.resetClassifyRules();
87+
message.success('已重置为默认规则');
88+
}
89+
4290
</script>
4391

4492
<template>
@@ -58,13 +106,77 @@ const saveData = () => {
58106
<a-typography-text v-if="autoClassify">开启自动分类🤖</a-typography-text>
59107
<a-typography-text class="forbidden-item" v-else>手动选择提交类型</a-typography-text>
60108
</div>
109+
<div class="config-row">
110+
<a-button type="default" @click="openRulesManager">
111+
🔧 管理自动分类规则
112+
</a-button>
113+
</div>
61114
<div class="config-row">
62115
<a-button type="primary" @click="saveData">保存</a-button>
63116
<a-popconfirm title="确定吗?" ok-text="Yes" cancel-text="我再想想" @confirm="resetConfig">
64117
<a-button type="dashed" danger>重置</a-button>
65118
</a-popconfirm>
66119
</div>
67120
</div>
121+
122+
<!-- 分类规则管理弹窗 -->
123+
<a-modal v-model:open="showRulesManager" title="自动分类规则管理" width="70vw" @ok="showRulesManager = false">
124+
<a-tabs>
125+
<a-tab-pane v-for="(rules, type) in settingsStore.classifyRules" :key="type" :tab="type">
126+
<div style="margin-bottom: 15px;">
127+
<a-button type="primary" size="small" @click="editRule(type)">编辑规则</a-button>
128+
<a-button type="default" size="small" style="margin-left: 10px;"
129+
@click="resetRule(type)">重置此类型</a-button>
130+
</div>
131+
<a-descriptions bordered :column="1" size="small">
132+
<a-descriptions-item label="以...开头">
133+
<a-tag v-for="keyword in rules.startsWith" :key="keyword" color="blue">{{ keyword }}</a-tag>
134+
<span v-if="!rules.startsWith || rules.startsWith.length === 0" style="color: #999;">无</span>
135+
</a-descriptions-item>
136+
<a-descriptions-item label="包含...">
137+
<a-tag v-for="keyword in rules.contains" :key="keyword" color="green">{{ keyword }}</a-tag>
138+
<span v-if="!rules.contains || rules.contains.length === 0" style="color: #999;">无</span>
139+
</a-descriptions-item>
140+
<a-descriptions-item label="以...结尾">
141+
<a-tag v-for="keyword in rules.endsWith" :key="keyword" color="orange">{{ keyword }}</a-tag>
142+
<span v-if="!rules.endsWith || rules.endsWith.length === 0" style="color: #999;">无</span>
143+
</a-descriptions-item>
144+
</a-descriptions>
145+
</a-tab-pane>
146+
</a-tabs>
147+
</a-modal>
148+
149+
<!-- 编辑规则弹窗 -->
150+
<a-modal v-model:open="showEditRule" :title="`编辑 ${editingRuleType} 的分类规则`" width="500px" @ok="saveRule"
151+
@cancel="showEditRule = false; editingRuleType = ''">>
152+
<a-form layout="vertical">
153+
<a-form-item label="以...开头(多个关键词用逗号分隔)">
154+
<a-input v-model:value="ruleForm.startsWith" placeholder="例如:修复,fix,修正"
155+
@change="ruleForm.startsWith = $event.target.value.split(',').map(k => k.trim())" />
156+
<div style="margin-top: 5px;">
157+
<a-tag v-for="keyword in ruleForm.startsWith.filter(k => k)" :key="keyword" closable
158+
@close="ruleForm.startsWith = ruleForm.startsWith.filter(k => k !== keyword)">{{ keyword
159+
}}</a-tag>
160+
</div>
161+
</a-form-item>
162+
<a-form-item label="包含...(多个关键词用逗号分隔)">
163+
<a-input v-model:value="ruleForm.contains" placeholder="例如:bug,错误,问题"
164+
@change="ruleForm.contains = $event.target.value.split(',').map(k => k.trim())" />
165+
<div style="margin-top: 5px;">
166+
<a-tag v-for="keyword in ruleForm.contains.filter(k => k)" :key="keyword" closable
167+
@close="ruleForm.contains = ruleForm.contains.filter(k => k !== keyword)">{{ keyword }}</a-tag>
168+
</div>
169+
</a-form-item>
170+
<a-form-item label="以...结尾(多个关键词用逗号分隔)">
171+
<a-input v-model:value="ruleForm.endsWith" placeholder="留空表示不使用"
172+
@change="ruleForm.endsWith = $event.target.value.split(',').map(k => k.trim())" />
173+
<div style="margin-top: 5px;">
174+
<a-tag v-for="keyword in ruleForm.endsWith.filter(k => k)" :key="keyword" closable
175+
@close="ruleForm.endsWith = ruleForm.endsWith.filter(k => k !== keyword)">{{ keyword }}</a-tag>
176+
</div>
177+
</a-form-item>
178+
</a-form>
179+
</a-modal>
68180
</template>
69181

70182
<style scoped>

0 commit comments

Comments
 (0)