Skip to content

Commit f798108

Browse files
committed
主页 SoC下拉菜单 加入厂商名称
- 主页 SoC下拉菜单加入厂商名称 - 添加对soc name的检索,更新关键词的显示 Resolves #10 Signed-off-by: Mingle Tan <mingle.oerv@isrc.iscas.ac.cn>
1 parent 757bbb6 commit f798108

File tree

1 file changed

+45
-24
lines changed

1 file changed

+45
-24
lines changed

src/views/home/index.vue

+45-24
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const isSticky = ref(false);
2020
const showSearchInput = ref(false);
2121
const showBackToTop = ref(false);
2222
const productList = ref([]);
23-
const randomPlaceholder = ref('');
23+
const randomPlaceholder = ref("");
2424
const placeholderTimer = ref(null);
25-
const lastPlaceholder = ref('');
25+
const lastPlaceholder = ref("");
2626
2727
const nameMapping = {
2828
soc: "SoC型号",
@@ -63,7 +63,8 @@ const searchSuggestions = computed(() => {
6363
.filter(
6464
item =>
6565
item.name.toLowerCase().includes(searchKeyword.value.toLowerCase()) ||
66-
item.vendor.toLowerCase().includes(searchKeyword.value.toLowerCase())
66+
item.vendor.toLowerCase().includes(searchKeyword.value.toLowerCase()) ||
67+
(item.soc && item.soc.name && item.soc.name.toLowerCase().includes(searchKeyword.value.toLowerCase()))
6768
)
6869
.slice(0, 5);
6970
});
@@ -104,7 +105,8 @@ const filteredProductList = computed(() => {
104105
filtered = filtered.filter(
105106
product =>
106107
product.name.toLowerCase().includes(keyword) ||
107-
product.vendor.toLowerCase().includes(keyword)
108+
product.vendor.toLowerCase().includes(keyword) ||
109+
(product.soc && product.soc.name && product.soc.name.toLowerCase().includes(keyword))
108110
);
109111
}
110112
@@ -191,7 +193,15 @@ const handleInputBlur = () => {
191193
};
192194
193195
const handleSuggestionClick = item => {
194-
searchKeyword.value = item.name;
196+
if (
197+
item.soc &&
198+
item.soc.name &&
199+
item.soc.name.toLowerCase().includes(searchKeyword.value.toLowerCase())
200+
) {
201+
searchKeyword.value = item.soc.name;
202+
} else {
203+
searchKeyword.value = item.name;
204+
}
195205
showSuggestions.value = false;
196206
};
197207
@@ -238,7 +248,7 @@ const viewportWidth = ref(0);
238248
const isdummy = ref(false);
239249
const changeViewportWidth = () => {
240250
viewportWidth.value = document.body.scrollWidth;
241-
changeIsDummy(viewportWidth.value)
251+
changeIsDummy(viewportWidth.value);
242252
};
243253
244254
onUnmounted(() => {
@@ -249,13 +259,13 @@ onUnmounted(() => {
249259
});
250260
watch(viewportWidth, newValue => {
251261
console.log(newValue, "viewportWidth变化了");
252-
changeIsDummy(newValue)
262+
changeIsDummy(newValue);
263+
});
264+
watch(filteredProductList, newValue => {
265+
console.log(newValue.length, "我是筛选数目");
266+
changeIsDummy(viewportWidth.value);
253267
});
254-
watch(filteredProductList,newValue=>{
255-
console.log(newValue.length,'我是筛选数目')
256-
changeIsDummy(viewportWidth.value)
257-
})
258-
const changeIsDummy=(value)=>{
268+
const changeIsDummy = value => {
259269
if (Math.floor((value + 16) / 256) > filteredProductList.value.length) {
260270
isdummy.value = false;
261271
let elements = document.querySelectorAll(".dummy-wrapper");
@@ -271,29 +281,31 @@ const changeIsDummy=(value)=>{
271281
element.style.display = "block";
272282
});
273283
}
274-
}
275-
const fetchProductList=async()=>{
284+
};
285+
const fetchProductList = async () => {
276286
try {
277287
const response = await getProductList();
278288
productList.value = response.data;
279289
await nextTick();
280290
} catch (error) {
281291
console.error("获取产品列表失败:", error);
282292
}
283-
284-
}
293+
};
285294
286295
const getRandomProduct = () => {
287296
if (!productList.value || productList.value.length === 0) {
288-
return '';
297+
return "";
289298
}
290-
299+
291300
let newPlaceholder;
292301
do {
293302
const randomIndex = Math.floor(Math.random() * productList.value.length);
294303
newPlaceholder = productList.value[randomIndex].name;
295-
} while (newPlaceholder === lastPlaceholder.value && productList.value.length > 1);
296-
304+
} while (
305+
newPlaceholder === lastPlaceholder.value &&
306+
productList.value.length > 1
307+
);
308+
297309
lastPlaceholder.value = newPlaceholder;
298310
return newPlaceholder;
299311
};
@@ -389,7 +401,7 @@ onMounted(async () => {
389401
src="@/assets/icons/home/Group 2.png"
390402
alt=""
391403
/>
392-
<button v-else class="search-text" type="button" >搜 索</button>
404+
<button v-else class="search-text" type="button">搜 索</button>
393405
</div>
394406
395407
<div
@@ -403,7 +415,15 @@ onMounted(async () => {
403415
@click="handleSuggestionClick(item)"
404416
>
405417
<div class="suggestion-content">
406-
<div class="suggestion-name">{{ item.name }}</div>
418+
<div class="suggestion-name">
419+
{{
420+
item.soc &&
421+
item.soc.name &&
422+
item.soc.name.toLowerCase().includes(searchKeyword.toLowerCase())
423+
? item.soc.name
424+
: item.name
425+
}}
426+
</div>
407427
</div>
408428
</div>
409429
</div>
@@ -442,7 +462,9 @@ onMounted(async () => {
442462
@click="handleOptionSelect(item.id, option, $event)"
443463
>
444464
<span class="selector"></span>
445-
<span id="option-name">{{ option }}</span>
465+
<span id="option-name">{{
466+
option.vendor ? option.vendor + " " + option.name : option
467+
}}</span>
446468
</li>
447469
</div>
448470
</ul>
@@ -765,7 +787,6 @@ $border-color: #f1faff;
765787
.menu-text {
766788
max-width: 120px;
767789
white-space: nowrap;
768-
overflow: hidden;
769790
text-overflow: ellipsis;
770791
display: inline-block;
771792
}

0 commit comments

Comments
 (0)