feat(header): 搜索框改居中命令面板,应用列表数据与 loading 与 AppList 共享
- header.scss: 删旧 .search-box 与 fade1/search-animation/icon-animation 动画段,
新增 app-cmdk-* 面板样式。样式段必须放顶层——面板 Teleport 到 body,嵌进
.default-header 会生成后代选择器而匹配不到
- Header.vue: 搜索 li 收敛为单图标 + openSearch;模板末尾追加 <Teleport to="body">
命令面板,支持实时过滤 / ↑↓ 键盘导航 / Enter 打开 / Esc 关闭 / 空结果态;
删 watch(isSearching) 与空函数 showSeachBox;挂/卸 window keydown
- store/index.ts: 新增 appListLoading 字段与 setAppListLoading
- utils/bschLinkPage.ts: 抽出 openAppPage(app, ifameAppIdArr),与点击应用图标同一路径
- AppList.vue: reloadAppData 写 store(数据 + loading,try/finally);
linkPage(item) 委托 openAppPage
硬约束保持不动:watch(searchAppText) -> mittBus.emit("searchChange")(背景应用网格靠它过滤)、
isSearchIconShow(route.name === "apps")。
This commit is contained in:
+128
-22
@@ -8,17 +8,9 @@
|
||||
</div>
|
||||
</li>
|
||||
<li v-if="isSearchIconShow">
|
||||
<Transition name="fade1" :duration="{ enter: 1000, leave: 0 }">
|
||||
<div v-show="!isSearching" @click="isSearching = true" class="icon-box" v-wave>
|
||||
<SvgIcon name="header-1" color="#333333" />
|
||||
</div>
|
||||
</Transition>
|
||||
<Transition name="search" :duration="{ enter: 300, leave: 300 }">
|
||||
<div v-show="isSearching" class="search-box">
|
||||
<input ref="refSearchInput" v-model="searchAppText" type="text" placeholder="请输入应用名称搜索" />
|
||||
<SvgIcon @click="isSearching = false" class="icon" name="header-1" size="20" color="#c4c4c4" />
|
||||
</div>
|
||||
</Transition>
|
||||
<div class="icon-box" v-wave @click="openSearch">
|
||||
<SvgIcon name="header-1" color="#333333" />
|
||||
</div>
|
||||
</li>
|
||||
<!-- 人像图标 =唯一入口(2026-10-08整合):铃铛与齿轮两枚图标下线,
|
||||
消息中心仍走左侧菜单 /msg(LeftMenu 保留未读角标);
|
||||
@@ -180,13 +172,60 @@
|
||||
|
||||
<StatsBarModal ref="refStatsBarModal" />
|
||||
<TeacherCopilotModal ref="refTeacherCopilotModal" />
|
||||
|
||||
<!-- 搜索命令面板(2026-10-08 定稿 B 方案):必须 Teleport 到 body ——
|
||||
.default-header 有 position:relative + z-index:10,会创建层叠上下文,
|
||||
面板写在 Header 内部时无论 z-index 多高,对外只表现为 10,会被左侧菜单与内容区盖住 -->
|
||||
<Teleport to="body">
|
||||
<div class="app-cmdk-layer" :class="{ 'is-open': isSearching }">
|
||||
<div class="app-cmdk-mask" @click="closeSearch"></div>
|
||||
<div class="app-cmdk-panel">
|
||||
<div class="app-cmdk-hd">
|
||||
<SvgIcon name="header-1" size="19" color="#98a2b0" />
|
||||
<input
|
||||
ref="refSearchInput"
|
||||
v-model="searchAppText"
|
||||
type="text"
|
||||
placeholder="输入应用名以搜索"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<span class="app-cmdk-kbd">Esc</span>
|
||||
</div>
|
||||
<div class="app-cmdk-list" :class="{ 'is-instant': !cmdkStagger }" ref="refCmdkList">
|
||||
<div
|
||||
v-for="(item, i) in cmdkResult"
|
||||
:key="item.id ?? i"
|
||||
class="app-cmdk-item"
|
||||
:class="{ 'is-hl': i === cmdkIndex }"
|
||||
:style="{ '--i': i }"
|
||||
@click="pickApp(item)"
|
||||
>
|
||||
<AppIcon
|
||||
v-if="vectorIconOf(item)"
|
||||
:name="vectorIconOf(item)"
|
||||
scene="tile"
|
||||
:tint="item.iconColor"
|
||||
/>
|
||||
<img v-else :src="$utils.appIconPath(item.icon)" class="app-cmdk-img" alt="" />
|
||||
<span class="app-cmdk-name">{{ item.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="app-cmdk-empty" :class="{ 'is-show': !cmdkResult.length }">
|
||||
{{ store.appListLoading ? "正在加载应用…" : "未找到匹配的应用" }}
|
||||
</div>
|
||||
<div class="app-cmdk-ft">
|
||||
<span>↑↓ 选择</span><span>↵ 打开</span><span>Esc 关闭</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import useCurrentInstance from "@/utils/hook/useCurrentInstance";
|
||||
import SvgIcon from "@/components/SvgIcon.vue";
|
||||
import vuescroll from "vuescroll";
|
||||
import { ref, reactive, computed, onMounted, onUnmounted, inject, watch } from "vue";
|
||||
import { ref, reactive, computed, onMounted, onUnmounted, inject, watch, nextTick } from "vue";
|
||||
import { useDefaultStore } from "@/store";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { requireImg } from "@/utils/hook/useImg";
|
||||
@@ -202,6 +241,9 @@ import UserSettingApi from "@/api/UserSettingApi";
|
||||
import mittBus from "@/utils/mitt";
|
||||
import MenuBarApi from "@/api/MenuBarApi";
|
||||
import Utils from "@/utils";
|
||||
import AppIcon from "@/components/AppIcon.vue";
|
||||
import { appiconKeyOf } from "@/constants/appIconRules";
|
||||
import { openAppPage } from "@/utils/bschLinkPage";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -360,22 +402,88 @@ onMounted(async () => {
|
||||
isSearching.value = false;
|
||||
searchAppText.value = null;
|
||||
});
|
||||
window.addEventListener("keydown", onCmdkKeydown);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
mittBus.off("searchReset");
|
||||
window.removeEventListener("keydown", onCmdkKeydown);
|
||||
closeMsgWs();
|
||||
});
|
||||
watch(isSearching, val => {
|
||||
if (val) {
|
||||
setTimeout(() => refSearchInput.value?.focus(), 300);
|
||||
} else {
|
||||
// searchAppText.value = null;
|
||||
}
|
||||
});
|
||||
|
||||
watch(searchAppText, val => {
|
||||
cmdkStagger.value = false; // 输入过滤时不重播逐条入场
|
||||
mittBus.emit("searchChange", val);
|
||||
});
|
||||
// ===== 搜索命令面板(2026-10-08 定稿 B 方案)=====
|
||||
const refCmdkList = ref<any>();
|
||||
const cmdkIndex = ref(0);
|
||||
const cmdkStagger = ref(true); // 仅首次打开做逐条入场,输入过滤时不重播
|
||||
|
||||
/** 与 AppList.vue / index.vue / SearchPanel.vue 同口径的矢量渲染回退链 */
|
||||
function vectorIconOf(item: any): string {
|
||||
if (item?.iconKey) return item.iconKey;
|
||||
if (item?.icon) return "";
|
||||
return appiconKeyOf(item?.name || "");
|
||||
}
|
||||
|
||||
/** 结果取自 store(由 AppList.reloadAppData 写入),与背景应用网格同源同口径 */
|
||||
const cmdkResult = computed(() => {
|
||||
const all = store.getFlattenAppList;
|
||||
const q = (searchAppText.value || "").trim();
|
||||
if (!q) return all;
|
||||
return all.filter((x: any) => x.name.indexOf(q) !== -1);
|
||||
});
|
||||
|
||||
function openSearch() {
|
||||
cmdkStagger.value = true;
|
||||
cmdkIndex.value = 0;
|
||||
searchAppText.value = null;
|
||||
isSearching.value = true;
|
||||
nextTick(() => refSearchInput.value?.focus());
|
||||
}
|
||||
|
||||
function closeSearch() {
|
||||
isSearching.value = false;
|
||||
searchAppText.value = null;
|
||||
}
|
||||
|
||||
function moveHighlight(step: number) {
|
||||
const len = cmdkResult.value.length;
|
||||
if (!len) return;
|
||||
cmdkIndex.value = (cmdkIndex.value + step + len) % len;
|
||||
nextTick(() => {
|
||||
const el = refCmdkList.value?.children?.[cmdkIndex.value];
|
||||
el?.scrollIntoView({ block: "nearest" });
|
||||
});
|
||||
}
|
||||
|
||||
function pickApp(item: any) {
|
||||
closeSearch();
|
||||
openAppPage(item, $conf.ifameAppIdArr); // 与点击应用图标同一条路径
|
||||
}
|
||||
|
||||
function onCmdkKeydown(ev: KeyboardEvent) {
|
||||
if (!isSearching.value) return; // 面板未开:绝不拦截全局按键
|
||||
if (ev.key === "Escape") {
|
||||
closeSearch();
|
||||
return;
|
||||
}
|
||||
if (ev.key === "ArrowDown") {
|
||||
ev.preventDefault();
|
||||
moveHighlight(1);
|
||||
return;
|
||||
}
|
||||
if (ev.key === "ArrowUp") {
|
||||
ev.preventDefault();
|
||||
moveHighlight(-1);
|
||||
return;
|
||||
}
|
||||
if (ev.key === "Enter") {
|
||||
ev.preventDefault();
|
||||
const it = cmdkResult.value[cmdkIndex.value];
|
||||
if (it) pickApp(it);
|
||||
}
|
||||
}
|
||||
|
||||
function getIsCheckRoles(item: RoleInfo) {
|
||||
return isEqual(item, store.curRoleInfo);
|
||||
}
|
||||
@@ -487,8 +595,6 @@ async function linkLogoSetting() {
|
||||
isLogoShow.value = true;
|
||||
}
|
||||
|
||||
function showSeachBox() { }
|
||||
|
||||
/** 卡片菜单:个人信息 → 设置中心 profile pane(与通知端/用户中心同一地址)。
|
||||
* 注意:mittBus 的 showUserInfoModal 事件仍由 AppHeader/BschIframe 使用,此处不再触发 */
|
||||
function showUserInfo() {
|
||||
|
||||
Reference in New Issue
Block a user