feat(command): 添加系统插件指令过滤与冲突处理

This commit is contained in:
Ocetars
2025-12-03 19:41:27 +08:00
parent 7b7d9f1b8c
commit 7f0e011126
4 changed files with 60 additions and 4 deletions
+3
View File
@@ -38,6 +38,7 @@ class CommandDescriptor:
enabled: bool = True
is_group: bool = False
is_sub_command: bool = False
reserved: bool = False
config: CommandConfig | None = None
has_conflict: bool = False
sub_commands: list[CommandDescriptor] = field(default_factory=list)
@@ -301,6 +302,7 @@ def _build_descriptor(handler: StarHandlerMetadata) -> CommandDescriptor | None:
enabled=handler.enabled,
is_group=isinstance(filter_ref, CommandGroupFilter),
is_sub_command=is_sub_command,
reserved=plugin_meta.reserved if plugin_meta else False,
)
return descriptor
@@ -437,6 +439,7 @@ def _descriptor_to_dict(desc: CommandDescriptor) -> dict[str, Any]:
"enabled": desc.enabled,
"is_group": desc.is_group,
"has_conflict": desc.has_conflict,
"reserved": desc.reserved,
}
# 如果是指令组,包含子指令列表
if desc.is_group and desc.sub_commands:
@@ -84,6 +84,8 @@
"byPlugin": "Filter by plugin",
"byType": "Filter by type",
"byPermission": "Filter by permission",
"byStatus": "Filter by status"
"byStatus": "Filter by status",
"showSystemPlugins": "Show system plugins commands",
"systemPluginConflictHint": "System plugin conflicts detected. Resolve conflicts to hide."
}
}
@@ -84,6 +84,8 @@
"byPlugin": "按插件筛选",
"byType": "按类型筛选",
"byPermission": "按权限筛选",
"byStatus": "按状态筛选"
"byStatus": "按状态筛选",
"showSystemPlugins": "显示系统插件指令",
"systemPluginConflictHint": "存在涉及系统插件的冲突,需解决冲突后才能隐藏"
}
}
+51 -2
View File
@@ -21,6 +21,7 @@ interface CommandItem {
enabled: boolean;
is_group: boolean;
has_conflict: boolean;
reserved: boolean; // 是否是系统插件的指令
sub_commands: CommandItem[];
}
@@ -52,10 +53,21 @@ const pluginFilter = ref('all');
const permissionFilter = ref('all');
const statusFilter = ref('all');
const typeFilter = ref('all');
const showSystemPlugins = ref(false);
// Track expanded groups
const expandedGroups = ref<Set<string>>(new Set());
// 检查是否有涉及系统插件的冲突
const hasSystemPluginConflict = computed(() => {
return commands.value.some(cmd => cmd.has_conflict && cmd.reserved);
});
// 实际是否显示系统插件(如果有系统插件冲突则强制显示)
const effectiveShowSystemPlugins = computed(() => {
return showSystemPlugins.value || hasSystemPluginConflict.value;
});
// Rename dialog
const renameDialog = reactive({
show: false,
@@ -81,14 +93,23 @@ const commandHeaders = computed(() => [
{ title: tm('table.headers.actions'), key: 'actions', sortable: false, width: '140px' }
]);
// Computed: unique plugins for filter
// Computed: unique plugins for filter (排除系统插件,除非显示系统插件)
const availablePlugins = computed(() => {
const plugins = new Set(commands.value.map(cmd => cmd.plugin));
const plugins = new Set(
commands.value
.filter(cmd => effectiveShowSystemPlugins.value || !cmd.reserved)
.map(cmd => cmd.plugin)
);
return Array.from(plugins).sort();
});
// Helper: check if a command matches filters
const matchesFilters = (cmd: CommandItem, query: string): boolean => {
// 系统插件过滤(除非显示系统插件)
if (!effectiveShowSystemPlugins.value && cmd.reserved) {
return false;
}
// Search filter
if (query) {
const matchesSearch =
@@ -426,6 +447,26 @@ onMounted(async () => {
<span class="text-body-2 text-medium-emphasis mr-1">{{ tm('summary.disabled') }}:</span>
<span class="text-body-1 font-weight-bold text-error">{{ summary.disabled }}</span>
</div>
<v-divider vertical class="mx-1" style="height: 20px;" />
<v-checkbox
:model-value="effectiveShowSystemPlugins"
@update:model-value="showSystemPlugins = !!$event"
:label="tm('filters.showSystemPlugins')"
density="compact"
hide-details
:disabled="hasSystemPluginConflict"
class="system-plugin-checkbox"
>
<template v-slot:label>
<span class="text-body-2">{{ tm('filters.showSystemPlugins') }}</span>
<v-tooltip v-if="hasSystemPluginConflict" location="top">
<template v-slot:activator="{ props }">
<v-icon v-bind="props" size="16" color="warning" class="ml-1">mdi-alert-circle</v-icon>
</template>
{{ tm('filters.systemPluginConflictHint') }}
</v-tooltip>
</template>
</v-checkbox>
</div>
</div>
@@ -718,6 +759,14 @@ code.sub-command-code {
background-color: rgba(var(--v-theme-secondary), 0.1);
color: rgb(var(--v-theme-secondary));
}
.system-plugin-checkbox {
flex: none;
}
.system-plugin-checkbox :deep(.v-selection-control) {
min-height: auto;
}
</style>
<style>