Command 命令调度
用于命令调度场景的 MoriUI 组件。
导入
import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut } from 'moriui'
示例
概览
可搜索的命令面板。
无结果
建议
日历⌘C
搜索邮件⌘E
计算器⌘K
设置
个人资料⌘P
账单⌘B
API⌘A
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut
} from 'moriui'
</script>
<template>
<Command class="rounded-lg border shadow-md">
<CommandInput placeholder="输入命令搜索…" />
<CommandList>
<CommandEmpty>无结果</CommandEmpty>
<CommandGroup heading="建议">
<CommandItem>日历<CommandShortcut>⌘C</CommandShortcut></CommandItem>
<CommandItem>搜索邮件<CommandShortcut>⌘E</CommandShortcut></CommandItem>
<CommandItem>计算器<CommandShortcut>⌘K</CommandShortcut></CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="设置">
<CommandItem>个人资料<CommandShortcut>⌘P</CommandShortcut></CommandItem>
<CommandItem>账单<CommandShortcut>⌘B</CommandShortcut></CommandItem>
<CommandItem disabled>
API<CommandShortcut>⌘A</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</template>
基础
最小化的命令列表。
无匹配操作
常用操作
新建文件
打开项目
保存当前
撤销操作
重做操作
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList
} from 'moriui'
const actions = ['新建文件', '打开项目', '保存当前', '撤销操作', '重做操作']
</script>
<template>
<Command class="rounded-lg border shadow-sm w-full max-w-sm">
<CommandInput placeholder="搜索操作…" />
<CommandList>
<CommandEmpty>无匹配操作</CommandEmpty>
<CommandGroup heading="常用操作">
<CommandItem v-for="item in actions" :key="item" :value="item">
{{ item }}
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</template>
对话框
CommandDialog 将命令面板置于模态内。
<script setup lang="ts">
import { shallowRef } from 'vue'
import {
Button,
Command,
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList
} from 'moriui'
const open = shallowRef(false)
</script>
<template>
<Button size="sm" variant="outline" @click="open = true">
打开命令面板
</Button>
<CommandDialog v-model:open="open">
<Command class="rounded-lg border shadow-md">
<CommandInput placeholder="输入命令搜索…" />
<CommandList>
<CommandEmpty>无结果</CommandEmpty>
<CommandGroup heading="快捷操作">
<CommandItem>新建项目</CommandItem>
<CommandItem>切换主题</CommandItem>
<CommandItem>查看设置</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</CommandDialog>
</template>
分组
Group 与 Separator 组织命令类别。
无匹配结果
页面
仪表盘
项目列表
任务看板
工具
搜索文件
全局替换
代码片段
账户
个人设置
团队管理
退出登录
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator
} from 'moriui'
const groups = [
{
heading: '页面',
items: ['仪表盘', '项目列表', '任务看板']
},
{
heading: '工具',
items: ['搜索文件', '全局替换', '代码片段']
},
{
heading: '账户',
items: ['个人设置', '团队管理', '退出登录']
}
]
</script>
<template>
<Command class="rounded-lg border shadow-sm w-full max-w-sm">
<CommandInput placeholder="搜索命令…" />
<CommandList>
<CommandEmpty>无匹配结果</CommandEmpty>
<template v-for="(group, index) in groups" :key="group.heading">
<CommandGroup :heading="group.heading">
<CommandItem v-for="item in group.items" :key="item" :value="item">
{{ item }}
</CommandItem>
</CommandGroup>
<CommandSeparator v-if="index < groups.length - 1" />
</template>
</CommandList>
</Command>
</template>
可滚动
长列表在 CommandList 中滚动。
无匹配结果
全部命令
命令 1
命令 2
命令 3
命令 4
命令 5
命令 6
命令 7
命令 8
命令 9
命令 10
命令 11
命令 12
命令 13
命令 14
命令 15
命令 16
命令 17
命令 18
命令 19
命令 20
命令 21
命令 22
命令 23
命令 24
命令 25
命令 26
命令 27
命令 28
命令 29
命令 30
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList
} from 'moriui'
const items = Array.from({ length: 30 }, (_, i) => `命令 ${i + 1}`)
</script>
<template>
<Command class="rounded-lg border shadow-sm w-full max-w-sm">
<CommandInput placeholder="搜索命令…" />
<CommandList class="max-h-60">
<CommandEmpty>无匹配结果</CommandEmpty>
<CommandGroup heading="全部命令">
<CommandItem v-for="item in items" :key="item" :value="item">
{{ item }}
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</template>
快捷键
CommandShortcut 显示键位提示。
无匹配结果
快捷键
保存当前⌘S
打印文档⌘P
查找替换⌘H
全屏模式⌃⌘F
开发者工具⌘⇧I
快速打开⌘K
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandShortcut
} from 'moriui'
const items = [
{ label: '保存当前', shortcut: '⌘S' },
{ label: '打印文档', shortcut: '⌘P' },
{ label: '查找替换', shortcut: '⌘H' },
{ label: '全屏模式', shortcut: '⌃⌘F' },
{ label: '开发者工具', shortcut: '⌘⇧I' },
{ label: '快速打开', shortcut: '⌘K' }
]
</script>
<template>
<Command class="rounded-lg border shadow-sm w-full max-w-sm">
<CommandInput placeholder="搜索快捷键…" />
<CommandList>
<CommandEmpty>无匹配结果</CommandEmpty>
<CommandGroup heading="快捷键">
<CommandItem v-for="item in items" :key="item.label" :value="item.label">
{{ item.label }}<CommandShortcut>{{ item.shortcut }}</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</template>
RTL
命令面板在 RTL 页面中工作。
لا توجد نتائج
الإجراءات
فتح
حفظ
طباعة
بحث
<script setup lang="ts">
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
DirectionProvider
} from 'moriui'
const actions = ['فتح', 'حفظ', 'طباعة', 'بحث']
</script>
<template>
<DirectionProvider direction="rtl">
<Command class="rounded-lg border shadow-sm w-full max-w-sm" dir="rtl">
<CommandInput placeholder="ابحث عن أمر…" />
<CommandList>
<CommandEmpty>لا توجد نتائج</CommandEmpty>
<CommandGroup heading="الإجراءات">
<CommandItem v-for="item in actions" :key="item" :value="item">
{{ item }}
</CommandItem>
</CommandGroup>
</CommandList>
</Command>
</DirectionProvider>
</template>
使用说明
组合方式
Command 基于 Reka Combobox 构建,使用 Input、List、Group、Item、Empty 与 Separator 组合快速命令面板。
对话框模式
CommandDialog 将命令面板包裹在模态 Dialog 中,适合全局快捷键唤醒的搜索场景。
分组
CommandGroup 通过 heading 属性提供标题,CommandSeparator 在组间建立视觉边界。
RTL
搜索输入与项目列表沿 dir 排列。
变体
Command 没有公开视觉变体;打开、高亮与选中状态由 Reka Combobox 属性驱动。
可访问性
Command 复用 Reka Combobox 的 combobox/listbox ARIA、方向键导航、Enter 选择与筛选。CommandDialog 额外使用 Dialog 的焦点管理。
API 参考
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Command v-model | AcceptableValue | AcceptableValue[] | undefined | 单选或多选值。 |
Command multiple / disabled | boolean | false | 多选模式与整体禁用。 |
Command ignoreFilter | boolean | false | 关闭内置筛选,由调用方控制。 |
CommandInput v-model | string | '' | 搜索输入值。 |
CommandInput placeholder | string | '输入命令或搜索…' | 输入占位提示。 |
CommandDialog v-model:open | boolean | undefined | 对话框的受控打开状态。 |
CommandDialog title | string | '命令面板' | 对话框标题。 |
CommandDialog description | string | '搜索并执行命令。' | 对话框辅助说明。 |
CommandGroup heading | string | undefined | 分组标题。 |
CommandItem value | AcceptableValue | — | 必填的项目值。 |