update: 头部搜索功能补全
This commit is contained in:
@@ -37,6 +37,18 @@
|
||||
</d-form-item>
|
||||
</d-col>
|
||||
</d-row>
|
||||
<d-row :gutter="16">
|
||||
<d-col :span="8">
|
||||
<d-form-item field="interestTag" label="兴趣标签">
|
||||
<d-input v-model="formData.interestTag"/>
|
||||
</d-form-item>
|
||||
</d-col>
|
||||
<d-col :span="8">
|
||||
<d-form-item field="industry" label="行业">
|
||||
<d-input v-model="formData.industry"/>
|
||||
</d-form-item>
|
||||
</d-col>
|
||||
</d-row>
|
||||
<slot name="operation">
|
||||
<gc-form-operation style="display: flex; justify-content: center; gap: 8px;">
|
||||
<d-button style="width: 96px; height: 32px;" variant="solid" @click="submitForm">搜索</d-button>
|
||||
@@ -63,6 +75,8 @@ const props = defineProps({
|
||||
softwareVersion: '',
|
||||
dependentSoftware: '',
|
||||
programmingLanguage: '',
|
||||
interestTag: '',
|
||||
industry: '',
|
||||
dateRange: ['', '']
|
||||
})
|
||||
}
|
||||
@@ -95,6 +109,8 @@ const cancel = () => {
|
||||
softwareVersion: '',
|
||||
dependentSoftware: '',
|
||||
programmingLanguage: '',
|
||||
interestTag: '',
|
||||
industry: '',
|
||||
dateRange: ['', '']
|
||||
}
|
||||
emit('cancel');
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -14,6 +14,10 @@ export const useGlobalInfoStore = defineStore('globalInfo', () => {
|
||||
const showTools = ref(true); // 是否展示工具栏
|
||||
const namespaceType = ref(-1); // 0 - 用户 1 - 组织
|
||||
const globalTheme = ref('light'); // 网站主题
|
||||
const headerSearch = ref({
|
||||
searchType: '软件',
|
||||
searchWord: ''
|
||||
})
|
||||
|
||||
const menuInfo = computed(() => {
|
||||
// 当前菜单
|
||||
@@ -63,6 +67,11 @@ export const useGlobalInfoStore = defineStore('globalInfo', () => {
|
||||
}
|
||||
};
|
||||
|
||||
const updateHeaderSearch = (data: any) => {
|
||||
headerSearch.value = { ...data };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置菜单标题旁的数字(如:mr数量,成员数量)
|
||||
* @param id 菜单id
|
||||
@@ -107,6 +116,7 @@ export const useGlobalInfoStore = defineStore('globalInfo', () => {
|
||||
showTools,
|
||||
namespaceType,
|
||||
globalTheme,
|
||||
headerSearch,
|
||||
setMenuType,
|
||||
updateMenuNum,
|
||||
setMenuInfo,
|
||||
@@ -114,6 +124,7 @@ export const useGlobalInfoStore = defineStore('globalInfo', () => {
|
||||
setIsNotFound,
|
||||
setShowTools,
|
||||
setNamespaceType,
|
||||
setGlobalTheme
|
||||
setGlobalTheme,
|
||||
updateHeaderSearch
|
||||
};
|
||||
});
|
||||
|
||||
@@ -113,7 +113,9 @@ import AdvanceSearch from '@/components/AdvanceSearch/index.vue';
|
||||
import { getHomeNoticeList } from '@/api/jyh';
|
||||
import EarlyWarningDetail from '@/views/Jyh/PersonalCenter/Detail/EarlyWarningDetail.vue';
|
||||
import { useDiscussGetUserInfo } from '@/api/discussion/hook';
|
||||
import { useGlobalInfoStore } from '@/stores/Global';
|
||||
|
||||
const { updateHeaderSearch } = useGlobalInfoStore();
|
||||
// 获取当前用户信息 & 是否登录
|
||||
const { isLogin = false, userInfo = {}} = useDiscussGetUserInfo();
|
||||
const route = useRoute();
|
||||
@@ -193,7 +195,8 @@ const updateDropdownWidth = () => {
|
||||
};
|
||||
|
||||
const search = () => {
|
||||
router.push({ name: 'Search', query: { searchWord: searchStr.value, searchType: selectedCate.value } });
|
||||
updateHeaderSearch({ searchWord: searchStr.value, searchType: selectedCate.value })
|
||||
router.push({ name: 'Search' });
|
||||
};
|
||||
|
||||
const onCategoryChange = (cate) => {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</AdvanceSearch>
|
||||
<div class="jyh-form-operation">
|
||||
<d-button @click="getReleaseList" class="mr-2" variant="solid">搜索</d-button>
|
||||
<d-button variant="solid" color="secondary">清空</d-button>
|
||||
<d-button variant="solid" color="secondary" @click="clear">清空</d-button>
|
||||
</div>
|
||||
<div class="left-btn">
|
||||
<d-button v-if="isLogin" class="output-btn" icon="icon-share" variant="text">导出</d-button>
|
||||
@@ -124,6 +124,7 @@ import { useAccountStore } from '@/stores/user';
|
||||
const { formatTime } = useTimeFormat();
|
||||
import { releasePage } from '@/api/jyh';
|
||||
import { useTimeFormat } from '@/utils/hooks/useTimeFormat';
|
||||
import { useGlobalInfoStore } from '@/stores/Global';
|
||||
const { namespace } = getOrgInfo();
|
||||
const userInfo = useAccountStore();
|
||||
const { isLogin } = storeToRefs(userInfo);
|
||||
@@ -138,16 +139,26 @@ const typeOptions = reactive(['主软件', '依赖软件']);
|
||||
const riskOptions = reactive(['低', '中', '高']);
|
||||
const useTypeOptions = reactive(['软件', '文档', '文档+软件']);
|
||||
const isUseOptions = reactive(['是', '否']);
|
||||
const globalInfo = useGlobalInfoStore();
|
||||
const headerSearch = ref(globalInfo.headerSearch)
|
||||
const newFormData = ref({
|
||||
licenseName: '',
|
||||
searchType: 'software',
|
||||
searchType: headerSearch.value.searchType ? headerSearch.value.searchType : 'software',
|
||||
searchWord: '',
|
||||
softwareVersion: '',
|
||||
dependentSoftware: '',
|
||||
programmingLanguage: '',
|
||||
interestTag: '',
|
||||
industry: '',
|
||||
dateRange: ['', '']
|
||||
})
|
||||
|
||||
watch(() => globalInfo.headerSearch, (newVal: any) => {
|
||||
headerSearch.value = newVal;
|
||||
newFormData.value.searchType = newVal.searchType;
|
||||
getReleaseList();
|
||||
}, { deep: true })
|
||||
|
||||
const pager = ref({
|
||||
total: 10,
|
||||
pageIndex: 1,
|
||||
@@ -195,6 +206,22 @@ const showColumnList = ref(false);
|
||||
const countryModalRef = ref(null);
|
||||
const orgModalRef = ref(null);
|
||||
|
||||
// 清空高级搜索
|
||||
const clear = () => {
|
||||
newFormData.value = {
|
||||
licenseName: '',
|
||||
searchType: headerSearch.value.searchType ? headerSearch.value.searchType : 'software',
|
||||
searchWord: '',
|
||||
softwareVersion: '',
|
||||
dependentSoftware: '',
|
||||
programmingLanguage: '',
|
||||
interestTag: '',
|
||||
industry: '',
|
||||
dateRange: ['', '']
|
||||
}
|
||||
getReleaseList();
|
||||
}
|
||||
|
||||
// 打开模态框的方法
|
||||
const openCountryModal = () => {
|
||||
if (countryModalRef.value) {
|
||||
@@ -294,8 +321,10 @@ const signCla = (row: any) => {
|
||||
};
|
||||
|
||||
const getReleaseList = async() => {
|
||||
console.log(newFormData.value.searchWord, headerSearch.value.searchWord)
|
||||
const { data, error } = await releasePage({
|
||||
...newFormData.value,
|
||||
searchWord: newFormData.value.searchWord ? newFormData.value.searchWord : headerSearch.value.searchWord,
|
||||
releaseDateStart: newFormData.value.dateRange&&newFormData.value.dateRange.length>0?newFormData.value.dateRange[0]:'',
|
||||
releaseDateEnd: newFormData.value.dateRange&&newFormData.value.dateRange.length>0?newFormData.value.dateRange[1]:'',
|
||||
current: pager.value.pageIndex,
|
||||
@@ -317,18 +346,6 @@ onMounted(() => {
|
||||
...query
|
||||
};
|
||||
});
|
||||
|
||||
// 监听路由变化,更新 searchWord
|
||||
watch(
|
||||
() => route.query.searchWord, // 监听路由的 searchWord 参数
|
||||
(newSearchWord) => {
|
||||
if (newSearchWord) {
|
||||
newFormData.value.searchWord = newSearchWord; // 更新组件的 searchWord
|
||||
getReleaseList(); // 重新调用接口
|
||||
}
|
||||
},
|
||||
{ immediate: true } // 立即执行一次
|
||||
);
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user