@@ -20,9 +20,9 @@ const isSticky = ref(false);
20
20
const showSearchInput = ref (false );
21
21
const showBackToTop = ref (false );
22
22
const productList = ref ([]);
23
- const randomPlaceholder = ref (' ' );
23
+ const randomPlaceholder = ref (" " );
24
24
const placeholderTimer = ref (null );
25
- const lastPlaceholder = ref (' ' );
25
+ const lastPlaceholder = ref (" " );
26
26
27
27
const nameMapping = {
28
28
soc: " SoC型号" ,
@@ -63,7 +63,8 @@ const searchSuggestions = computed(() => {
63
63
.filter (
64
64
item =>
65
65
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 ()))
67
68
)
68
69
.slice (0 , 5 );
69
70
});
@@ -104,7 +105,8 @@ const filteredProductList = computed(() => {
104
105
filtered = filtered .filter (
105
106
product =>
106
107
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))
108
110
);
109
111
}
110
112
@@ -191,7 +193,15 @@ const handleInputBlur = () => {
191
193
};
192
194
193
195
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
+ }
195
205
showSuggestions .value = false ;
196
206
};
197
207
@@ -238,7 +248,7 @@ const viewportWidth = ref(0);
238
248
const isdummy = ref (false );
239
249
const changeViewportWidth = () => {
240
250
viewportWidth .value = document .body .scrollWidth ;
241
- changeIsDummy (viewportWidth .value )
251
+ changeIsDummy (viewportWidth .value );
242
252
};
243
253
244
254
onUnmounted (() => {
@@ -249,13 +259,13 @@ onUnmounted(() => {
249
259
});
250
260
watch (viewportWidth, newValue => {
251
261
console .log (newValue, " viewportWidth变化了" );
252
- changeIsDummy (newValue)
262
+ changeIsDummy (newValue);
263
+ });
264
+ watch (filteredProductList, newValue => {
265
+ console .log (newValue .length , " 我是筛选数目" );
266
+ changeIsDummy (viewportWidth .value );
253
267
});
254
- watch (filteredProductList,newValue => {
255
- console .log (newValue .length ,' 我是筛选数目' )
256
- changeIsDummy (viewportWidth .value )
257
- })
258
- const changeIsDummy = (value )=> {
268
+ const changeIsDummy = value => {
259
269
if (Math .floor ((value + 16 ) / 256 ) > filteredProductList .value .length ) {
260
270
isdummy .value = false ;
261
271
let elements = document .querySelectorAll (" .dummy-wrapper" );
@@ -271,29 +281,31 @@ const changeIsDummy=(value)=>{
271
281
element .style .display = " block" ;
272
282
});
273
283
}
274
- }
275
- const fetchProductList = async () => {
284
+ };
285
+ const fetchProductList = async () => {
276
286
try {
277
287
const response = await getProductList ();
278
288
productList .value = response .data ;
279
289
await nextTick ();
280
290
} catch (error) {
281
291
console .error (" 获取产品列表失败:" , error);
282
292
}
283
-
284
- }
293
+ };
285
294
286
295
const getRandomProduct = () => {
287
296
if (! productList .value || productList .value .length === 0 ) {
288
- return ' ' ;
297
+ return " " ;
289
298
}
290
-
299
+
291
300
let newPlaceholder;
292
301
do {
293
302
const randomIndex = Math .floor (Math .random () * productList .value .length );
294
303
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
+
297
309
lastPlaceholder .value = newPlaceholder;
298
310
return newPlaceholder;
299
311
};
@@ -389,7 +401,7 @@ onMounted(async () => {
389
401
src= " @/assets/icons/home/Group 2.png"
390
402
alt= " "
391
403
/ >
392
- < button v- else class = " search-text" type= " button" > 搜 索< / button>
404
+ < button v- else class = " search-text" type= " button" > 搜 索< / button>
393
405
< / div>
394
406
395
407
< div
@@ -403,7 +415,15 @@ onMounted(async () => {
403
415
@click= " handleSuggestionClick(item)"
404
416
>
405
417
< 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>
407
427
< / div>
408
428
< / div>
409
429
< / div>
@@ -442,7 +462,9 @@ onMounted(async () => {
442
462
@click= " handleOptionSelect(item.id, option, $event)"
443
463
>
444
464
< 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>
446
468
< / li>
447
469
< / div>
448
470
< / ul>
0 commit comments