diff --git a/plugins/commands/client/commands.vue b/plugins/commands/client/commands.vue index 2b1df272..c1916e14 100644 --- a/plugins/commands/client/commands.vue +++ b/plugins/commands/client/commands.vue @@ -26,7 +26,7 @@ -import { clone, Dict, pick, Schema, send, store, valueMap } from '@koishijs/client' +import { clone, Dict, pick, Schema, send, store, useRpc, valueMap } from '@koishijs/client' import { useRoute, useRouter } from 'vue-router' import { computed, nextTick, onActivated, ref, watch } from 'vue' import { CommandData, CommandState } from '@koishijs/plugin-commands' import {} from '@koishijs/plugin-locales' import {} from '@koishijs/plugin-config' -import { commands, createSchema } from './utils' +import { createSchema } from './utils' const route = useRoute() const router = useRouter() +const data = useRpc() + const inputEl = ref() const title = ref('') const alias = ref('') @@ -134,6 +136,21 @@ const schema = ref<{ options: Dict }>() +function getCommands(data: CommandData[]) { + const result: CommandData[] = [] + for (const item of data) { + result.push(item) + if (!item.children) continue + result.push(...getCommands(item.children)) + } + return result +} + +const commands = computed>(() => { + if (!data.value) return {} + return Object.fromEntries(getCommands(data.value).map((item) => [item.name, item])) +}) + const aliases = computed(() => { return Object.values(commands.value).flatMap(command => command.override.aliases) }) diff --git a/plugins/commands/client/index.ts b/plugins/commands/client/index.ts index ca5ede32..1af3ae07 100644 --- a/plugins/commands/client/index.ts +++ b/plugins/commands/client/index.ts @@ -20,7 +20,6 @@ export default (ctx: Context) => { icon: 'activity:commands', order: 500, authority: 4, - fields: ['commands'], component: Commands, }) diff --git a/plugins/commands/client/locales.vue b/plugins/commands/client/locales.vue index fc7834f8..526b8249 100644 --- a/plugins/commands/client/locales.vue +++ b/plugins/commands/client/locales.vue @@ -1,5 +1,5 @@