update: 头部搜索功能补全

This commit is contained in:
@user8949
2025-03-19 19:38:32 +08:00
parent 6ed811968d
commit fc486e9488
5 changed files with 76 additions and 26 deletions

View File

@@ -1,9 +1,9 @@
<template>
<d-input
:key="$route.path + $route.query?.val" id="golbalSearch" class="g-header-search"
v-model.trim="searchStr" placeholder="输入搜索内容..." @keyup.enter="search" @clear="handleClear" clearable >
v-model.trim="searchStr" placeholder="输入搜索内容..." @clear="handleClear" clearable >
<template #prepend>
<d-dropdown @toggle="onCateToggle($event)">
<d-dropdown>
<div class="flex items-center gap-1 cursor-pointer">
{{ searchType }}
<d-icon :rotate="cateRotate" name="icon-chevron-down-2"></d-icon>
@@ -37,12 +37,18 @@
<script setup>
import { ref, onMounted, watch, onUnmounted, reactive } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useGlobalInfoStore } from '@/stores/Global';
import microApp from '@micro-zoe/micro-app';
const emit = defineEmits('updateSearch');
const globalInfo = useGlobalInfoStore();
const route = useRoute();
const router = useRouter();
const searchStr = ref(route?.query?.val || '');
const searchType = ref('软件');
const searchStr = ref(globalInfo.headerSearch.searchWord);
const searchType = ref(globalInfo.headerSearch.searchType);
const position = ref(['right-start', 'right-end']);
const industryOptions = ref(['通信', '军工', '金融', '能源']);
@@ -53,14 +59,11 @@ const onCategoryChange = (event) => {
}
const search = () => {
if (!searchStr.value) {
document.querySelector('#golbalSearch').blur();
return;
}
router.push({ name: 'Search', query: { searchWord: searchStr.value || '', type: route?.query?.type || 'software' }});
globalInfo.updateHeaderSearch({ searchWord: searchStr.value, searchType: searchType.value });
};
const handleClear = () => {
router.push({ name: 'home' });
globalInfo.updateHeaderSearch({ searchWord: ''.value, searchType: searchType.value });
};
watch(() => route.query?.val, (newVal) => {