feat(frontend): replace standalone search page with global command palette
Reworks search from a siloed /platform/knowledge-search page into a universal ⌘K palette plus natural, in-context entry points. Why the old page felt out of place: - "Search" was an action pinned next to entity routes (knowledge base, agent, organization), mixing noun- and verb-level navigation items. - Its two tabs (knowledge vs. chat messages) forced users to pick a mental model before they knew what they wanted. - It was also the only way to search at all — no global shortcut, no context-aware entry. What this replaces it with: - A new ⌘K/Ctrl+K command palette (GlobalCommandPalette.vue) mounted once in views/platform/index.vue. Results are grouped by type (files, messages, knowledge bases, agents, chat titles, commands) so users never need to pre-filter. Debounced, identity-keyed selection survives async arrivals (slow KB results no longer yank the highlight off the user's current row). ⌘1-9 jump shortcuts are rendered inline on each row for discoverability. - Sidebar gets a visible "Search" entry at the top — clicking it opens the palette (no route change), with a platform-aware kbd hint (⌘K on Mac, Ctrl K elsewhere). - KB detail page: opening ⌘K there auto-scopes the search to the current KB via a removable chip (Backspace in empty input also clears it); no separate embedded search bar needed. - The legacy route /platform/knowledge-search now redirects to the KB list with ?cmdk= set, so existing bookmarks still work. - KnowledgeBase.vue now handles both route-query changes and a window event (weknora:open-knowledge) for intra-KB navigation, fixing the silent-no-op when the palette jumps to a chunk in the already-open KB. Dropped: - frontend/src/views/knowledge/KnowledgeSearch.vue (1163 lines). - The exploratory SessionSearchBar mode-switching widget in the chat submenu; ⌘K covers its use cases without a two-mode UI. i18n: zh-CN / en-US / ko-KR / ru-RU updated together — new commandPalette.*, kb.*, and menu.search keys; obsolete session.search.* and menu.knowledgeSearch removed.
This commit is contained in:
@@ -10,21 +10,27 @@
|
||||
</div>
|
||||
<!-- 全局设置模态框,供所有 platform 子路由使用 -->
|
||||
<Settings />
|
||||
<!-- 全局命令面板 (⌘K),随 platform 路由存活 -->
|
||||
<GlobalCommandPalette />
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import Menu from '@/components/menu.vue'
|
||||
import { ref, onMounted, onUnmounted, nextTick, provide } from 'vue';
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ref, onMounted, onUnmounted, nextTick, provide, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase'
|
||||
import UploadMask from '@/components/upload-mask.vue'
|
||||
import Settings from '@/views/settings/Settings.vue'
|
||||
import GlobalCommandPalette from '@/components/GlobalCommandPalette.vue'
|
||||
import { useCommandPaletteStore } from '@/stores/commandPalette'
|
||||
import { getKnowledgeBaseById } from '@/api/knowledge-base/index'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
let { requestMethod } = useKnowledgeBase()
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const commandPaletteStore = useCommandPaletteStore();
|
||||
let ismask = ref(false)
|
||||
let uploadInput = ref();
|
||||
const { t } = useI18n();
|
||||
@@ -186,8 +192,26 @@ onMounted(() => {
|
||||
reloadApp()
|
||||
})
|
||||
}
|
||||
// 支持通过 URL 查询参数打开全局命令面板,例如旧路径
|
||||
// /platform/knowledge-search?q=foo 重定向后携带 ?cmdk=foo
|
||||
maybeOpenCmdkFromRoute()
|
||||
});
|
||||
|
||||
// 监听路由变化,兼容 SPA 内部跳转时的 ?cmdk= 参数
|
||||
watch(() => route.query.cmdk, () => {
|
||||
maybeOpenCmdkFromRoute()
|
||||
})
|
||||
|
||||
function maybeOpenCmdkFromRoute() {
|
||||
if (!('cmdk' in route.query)) return
|
||||
const q = String(route.query.cmdk ?? '')
|
||||
commandPaletteStore.openPalette(q)
|
||||
// 清除 query,避免回退/刷新时反复触发
|
||||
const newQuery = { ...route.query }
|
||||
delete (newQuery as any).cmdk
|
||||
router.replace({ path: route.path, query: newQuery, hash: route.hash })
|
||||
}
|
||||
|
||||
// 组件卸载时移除全局事件监听器
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('dragenter', handleGlobalDragEnter, true);
|
||||
|
||||
Reference in New Issue
Block a user