头部搜索对接开源软件列表

This commit is contained in:
付民康
2025-03-20 20:51:16 +08:00
parent 2e46635146
commit 61b7acc34c
6 changed files with 188 additions and 51 deletions

View File

@@ -18,8 +18,8 @@
</li>
<template #menu>
<ul class="list-menu">
<li class="menu-item" v-for="option in industryOptions" @click="onCategoryChange(option)">
{{ option }}
<li class="menu-item" v-for="option in industryList" @click="onCategoryChange(option)">
{{ option.name }}
</li>
</ul>
</template>
@@ -46,30 +46,32 @@ const globalInfo = useGlobalInfoStore();
const route = useRoute();
const router = useRouter();
const softwareName = ref(globalInfo.headerSearch.softwareName);
const searchType = ref(globalInfo.headerSearch.searchType);
const softwareName = ref('');
const searchType = ref('软件');
const position = ref(['right-start', 'right-end']);
const industryOptions = ref(['通信', '军工', '金融', '能源']);
// const industryOptions = ref(['通信', '军工', '金融', '能源']);
const placeholder = ref('「开搜」一搜即达开发者的AI搜索');
const industryList = globalInfo.industryList;
const onCategoryChange = (event) => {
searchType.value = event;
globalInfo.updateHeaderSearch({ softwareName: softwareName.value, searchType: searchType.value });
searchType.value = event?.name || '软件';
globalInfo.updateHeaderSearch({ softwareName: softwareName.value, searchType: event.value });
}
const search = () => {
window.open(`${import.meta.env.VITE_BASE_URL}repoList?softwareName=${softwareName.value ? softwareName.value : ''}&searchType=${searchType.value}`, '_blank')
window.open(`${import.meta.env.VITE_BASE_URL}repoList?softwareName=${softwareName.value ? softwareName.value : ''}&searchType=${getIndustryValue(searchType.value)}`, '_blank')
};
const handleClear = () => {
globalInfo.updateHeaderSearch({ softwareName: ''.value, searchType: searchType.value });
};
watch(() => route.query?.val, (newVal) => {
microApp.setData('micoro-app-homeweb-app', { type: 'search', data: newVal || '' });
});
const getIndustryValue = (name) => {
const industry = industryList.find(item => item.name === name);
return industry ? industry.value : ''; // 如果找不到,返回默认值
};
const handleDataChange = ({ name, type, data }) => {
if (name === 'micoro-app-homeweb-app') {
@@ -84,8 +86,8 @@ const handleDataChange = ({ name, type, data }) => {
onMounted(() => {
globalInfo.updateHeaderSearch({ softwareName: route.query.softwareName ? route.query.softwareName : '', searchType: route.query.searchType || '软件' });
softwareName.value = route.query.softwareName;
searchType.value = route.query.searchType || '软件';
// softwareName.value = route.query.softwareName;
// searchType.value = route.query.searchType || '软件';
});
onUnmounted(() => {