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

@@ -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) => {

View File

@@ -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">