规则编辑:建议列表全量展开,目标补齐候选,删除免确认

组合框展开先给全量、本次展开输入过才过滤——按当前值过滤的话,预填的
类型会把列表滤到只剩它自己,MATCH 这类排在后面的选项等于不存在。类型
因此可以默认留空,placeholder 当示例。

目标建议由页面传入:全局规则给内置两个加用户自建的组和自有线路;附加
规则多一项本路专属组——「这个载荷走本路代理」写的就是它,放在拦截规则
前面还能做豁免。生成的专属组不列,每路三个会把列表灌成一面墙。

原文/字段切换只拦真正整行编辑的类型(isRawOnlyRule):之前用
isStructuredEditable 拦,新增时的空原文永远过不了,卡死在原文模式。

删除规则和附加规则不再二次确认——删错了有撤回,确认框只是多一步;
toast 带上被删规则的原文。
This commit is contained in:
2026-08-12 13:16:58 +08:00
parent 955fa340af
commit 48e97bd91f
6 changed files with 80 additions and 55 deletions
+19 -20
View File
@@ -10,6 +10,7 @@
*/
import { computed, onMounted, ref, watch } from 'vue'
import { collectOutboundNames } from '@shared/inbounds.ts'
import { isGenerated } from '@shared/inbound-groups.ts'
import {
findRuleIssues,
firstMatchIndex,
@@ -76,6 +77,17 @@ const outboundNames = computed(() => [
...outbounds.value.ownProxies,
])
/**
* 目标的建议:日常用的两个内置出站、用户自己建的策略组和自有线路。
* 生成的专属组不列——每路入站三个,会把列表灌成一面墙,真要指定就手填。
*/
const targetOptions = computed(() => [
'DIRECT',
'REJECT',
...outbounds.value.groups.filter((name) => !isGenerated(name)),
...outbounds.value.ownProxies,
])
/** 第一条 MATCH 的下标。它之后的行标成不可达。 */
const matchAt = computed(() => firstMatchIndex(rules.value))
@@ -161,17 +173,11 @@ async function move(index: number, delta: -1 | 1) {
await commit(withRules(moveRule(rules.value, index, delta)), '顺序已保存')
}
/** 待确认删除的规则下标。非 null 时确认对话框打开着。 */
const removingRule = ref<number | null>(null)
async function removeRuleConfirmed() {
const index = removingRule.value
removingRule.value = null
if (index === null || saving.value) return
await commit(
withRules(rules.value.filter((_, i) => i !== index)),
'已删除这条规则',
)
// 删除不设二次确认:删错了有撤回,规则原文放进提示里让人看清删掉的是哪条
async function removeRule(index: number) {
const rule = rules.value[index]
if (rule === undefined || saving.value) return
await commit(withRules(rules.value.filter((_, i) => i !== index)), `已删除规则 [ ${rule} ]`)
}
async function applyLanPreset() {
@@ -429,7 +435,7 @@ async function updateNow(name: string) {
class="icon-btn danger"
title="删除"
:disabled="saving"
@click="removingRule = row.index"
@click="removeRule(row.index)"
>
<IconDelete />
</button>
@@ -493,6 +499,7 @@ async function updateNow(name: string) {
:open="ruleFormOpen"
:editing="ruleEditing === null ? null : { index: ruleEditing, raw: rules[ruleEditing]! }"
:provider-names="providerNames"
:target-options="targetOptions"
:saving="saving"
@close="ruleFormOpen = false"
@submit="submitRule"
@@ -515,14 +522,6 @@ async function updateNow(name: string) {
@submit="submitImport"
/>
<ConfirmDialog
:open="removingRule !== null"
:message="removingRule === null ? '' : `删除这条规则?${rules[removingRule]}`"
action="删除"
@close="removingRule = null"
@confirm="removeRuleConfirmed"
/>
<ConfirmDialog
:open="removingProvider !== null"
:message="removingProvider === null ? '' : `删除规则组「${removingProvider}」?`"