@@ -302,7 +302,6 @@ const state = reactive({
302
302
303
303
const search = () => {
304
304
console .log (state.검색어)
305
- console .log (' 검색어' )
306
305
applyFilter1 ()
307
306
}
308
307
@@ -318,12 +317,10 @@ const toggleSlider = (filter) => {
318
317
};
319
318
320
319
const applyFilter1 = async () => {
321
-
322
320
const query1 = { buildingUse: ' 아파트' ,
323
321
fromArea: state.면적[0 ],
324
322
toArea: state.면적[1 ],
325
323
keyword: state.검색어 }
326
-
327
324
const queryString1 = new URLSearchParams (query1).toString ();
328
325
await fetchData (queryString1); // 데이터 로드
329
326
};
@@ -340,7 +337,6 @@ const navigateTo = (param) => {
340
337
router .push ({ name: ' map' , params: { param } }); // 이름과 params를 명확히 지정
341
338
};
342
339
343
-
344
340
// *상세 정보 불러오는 곳
345
341
const selectedHouse = ref (null ); // 반드시 ref로 선언
346
342
@@ -364,7 +360,7 @@ const selectHouse = (house) => {
364
360
365
361
const findDealsByAptseq = async (aptSeq ) => {
366
362
try {
367
- console .log (` Fetching deals for aptSeq: ${ aptSeq} ` );
363
+ // console.log(`Fetching deals for aptSeq: ${aptSeq}`);
368
364
await houseInfoStore .fetchHouseDeals (aptSeq); // Pinia 스토어 호출
369
365
370
366
} catch (error) {
@@ -410,7 +406,6 @@ class TrieNode {
410
406
}
411
407
return this ._collectWords (node, prefix);
412
408
}
413
-
414
409
_collectWords (node , prefix ) {
415
410
const results = [];
416
411
if (node .isEndOfWord ) {
@@ -435,53 +430,82 @@ onMounted(async () => {
435
430
houseNames .value = Array .isArray (houseInfoStore .houseNames ? .data )
436
431
? houseInfoStore .houseNames .data
437
432
: [];
438
-
439
- // 트라이에 이름 삽입
440
- console .log (" 트라이가 생성전" , trie);
441
- console .log (' houseNames.value의 타입:' , Array .isArray (houseNames .value ) ? ' 배열' : typeof houseNames .value );
442
- console .log (' houseNames.value의 타입:' , Array .isArray (houseNames .value ) ? ' 배열' : typeof houseNames .value );
443
433
for (const name of houseInfoStore .houseNames ) {
444
434
if (name? .aptNm ) { // aptNm이 존재하는지 확인
445
435
trie .insert (name .aptNm );
446
- console .log (` 삽입된 이름: ${ name .aptNm } ` );
447
436
} else {
448
437
console .warn (" aptNm이 없는 데이터:" , name);
449
438
}
450
439
}
451
-
452
- console .log (" 트라이가 생성되었습니다:" , trie);
453
440
});
454
441
455
442
// 검색 처리
443
+ // const updateSearchResults = () => {
444
+ // console.log('검색처리중')
445
+ // if (!searchQuery.value || searchQuery.value.trim() === "") {
446
+ // filteredNames.value = [];
447
+ // console.log("검색어가 비어 있습니다.");
448
+ // return;
449
+ // }
450
+ // filteredNames.value = trie.search(searchQuery.value.trim());
451
+ // };
456
452
const updateSearchResults = () => {
457
- console .log (' 검색처리중' )
458
- if (! searchQuery .value || searchQuery .value .trim () === " " ) {
453
+ if (! searchQuery .value .trim ()) {
459
454
filteredNames .value = [];
460
- console .log (" 검색어가 비어 있습니다." );
461
455
return ;
462
456
}
463
457
464
- filteredNames .value = trie .search (searchQuery .value .trim ());
465
- console .log (" 검색 결과:" , JSON .stringify (filteredNames .value )); // 일치하는 결과 콘솔 출력
458
+ const results = [];
459
+ let node = trie .root ;
460
+ const prefix = searchQuery .value .trim ();
461
+
462
+ for (const char of prefix) {
463
+ if (! node .children [char]) {
464
+ filteredNames .value = []; // 검색어에 맞는 결과가 없으면 초기화
465
+ return ;
466
+ }
467
+ node = node .children [char];
468
+ }
469
+
470
+ // 결과를 최대 5개까지만 수집
471
+ const collectWords = (currentNode , currentWord ) => {
472
+ if (results .length >= 5 ) return ; // 5개를 찾으면 종료
473
+ if (currentNode .isEndOfWord ) {
474
+ results .push (currentWord);
475
+ }
476
+ for (const [char , childNode ] of Object .entries (currentNode .children )) {
477
+ collectWords (childNode, currentWord + char);
478
+ }
479
+ };
480
+
481
+ collectWords (node, prefix);
482
+ filteredNames .value = results; // 결과 저장
466
483
};
484
+
485
+ const selectKeyword = (name ) => {
486
+ searchQuery .value = name
487
+ }
488
+
489
+
490
+
467
491
< / script>
468
492
< template>
469
493
< div class = " flex flex-row items-center w-full h-[100vh] overflow-hidden " >
470
494
<!-- 지도 및 필터 영역 -->
471
- < div class = " flex flex-col justify-start w-full h-full mt-40" >
495
+ < div class = " relative flex flex-col justify-start w-full h-full mt-40" >
472
496
<!-- 필터 전체 버튼 -->
473
- < div class = " flex flex-row items-center py-4 h-14 border-b border-gray-200 z-100" >
474
- <!-- 검색 창-->
475
- < div class = " relative w-[370px] ml-4 mr-2 " >
497
+ < div class = " flex flex-row items-center py-4 h-14 border-b border-gray-200 z-100 relative " >
498
+ <!-- 검색 창-->
499
+ < div class = " w-[370px] ml-4 mr-2 relative justify-center " >
476
500
< input
477
501
v- model= " searchQuery"
478
502
type= " text"
479
503
@input= " updateSearchResults"
480
504
placeholder= " 찾고자하는 아파트 이름을 입력하세요"
481
- class = " absolute w-full h-8 px-4 pr-10 text-sm text-gray-700 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 " / >
505
+ class = " w-full h-8 px-4 pr-10 text-sm text-gray-700 border border-gray-300 rounded-lg shadow-sm focus:outline-none " / >
482
506
< button
483
507
type= " button"
484
- class = " absolute inset-y-0 right-0 flex items-center px-3 text-gray-500 hover:text-gray-700"
508
+ class = " absolute flex justify-center right-0 top-2 px-3 text-gray-500 hover:text-gray-700"
485
509
@click= " search" >
486
510
< svg
487
511
class = " w-4 h-4"
@@ -498,19 +522,24 @@ const updateSearchResults = () => {
498
522
< / svg>
499
523
< / button>
500
524
<!-- 검색 결과 -->
501
- < div v- if = " filteredNames.length > 0" class = " absolute bg-yellow-400 z-100" >
502
- < p> 검색 결과: < / p>
525
+ < / div>
526
+ <!-- 검색 결과 -->
527
+ < div v- if = " filteredNames.length > 0" class = " absolute w-[360px] h-auto max-h-96 z-100 top-12 left-4 shadow-lg rounded-md border border-gray-300" >
528
+ <!-- 결과 없음 메시지 -->
529
+ < div class = " bg-white text-gray-700 px-4 py-2 font-semibold border-b border-gray-300" >
503
530
< ul>
504
- < li v- for = " (name, index) in filteredNames" : key = " index " >
505
- {{ name }}
506
- < / li >
507
- < / ul >
508
- < / div >
509
- < div v - else >
510
- < p > 일치하는 결과가 없습니다. < / p >
531
+ < li v- for = " (name, index) in filteredNames"
532
+ : key = " index "
533
+ class = " px-4 py-2 hover:bg-blue-100 cursor-pointer "
534
+ @click = " selectKeyword(name) " >
535
+ {{ name }}
536
+ < / li >
537
+ < / ul >
511
538
< / div>
539
+ <!-- 검색 결과 리스트 -->
512
540
< / div>
513
541
542
+
514
543
< div class = " relative inline-block text-left ml-2" >
515
544
<!-- 버튼 -->
516
545
< button
@@ -587,6 +616,7 @@ const updateSearchResults = () => {
587
616
< / button>
588
617
< / div>
589
618
< / div>
619
+
590
620
< / div>
591
621
<!-- 필요한 필터 수 만큼 반복 -->
592
622
< button type= " button" class = " relative inline-block text-left ml-2 h-8 px-2 py-2 bg-white border border-gray-300 shadow-sm focus:ring-indigo-500" >
@@ -596,22 +626,24 @@ const updateSearchResults = () => {
596
626
< / button>
597
627
< / div>
598
628
<!-- 리스트와 지도 영역 -->
599
- < div class = " flex flex-row h-full font-Pretendard text-gray-600 relaitvie" >
629
+
630
+
631
+ < div class = " flex h-full font-Pretendard text-gray-600 z-10" >
600
632
< div class = " flex flex-col h-full rounded-lg" >
601
- < div class = " flex flex-row p-2 text-s bg-blue-100" >
602
- < p class = " mr-1 ml-2 cursor-pointer font-bold" > 인기순< / p>
603
- < p class = " mr-1 cursor-pointer font-bold" > 가격순< / p>
604
- < p class = " mr-1 cursor-pointer font-bold" > 면적순< / p>
605
- < FilterButton>< / FilterButton>
606
- < / div>
607
633
<!-- 목록 영역 추가할 수 있습니다 -->
608
- < div class = " p-2 overflow-y-auto" >
609
- < div class = " text-center " >
634
+ < div class = " p-2 overflow-y-auto " >
635
+
636
+ < div class = " flex flex-row p-2 text-s h-[24px] fixed bg-white-800 z-20" >
637
+ < p class = " mr-1 ml-2 cursor-pointer font-bold" > 인기순< / p>
638
+ < p class = " mr-1 cursor-pointer font-bold" > 가격순< / p>
639
+ < p class = " mr-1 cursor-pointer font-bold" > 면적순< / p>
640
+ < / div>
641
+ < div class = " text-center" >
610
642
< div v- for = " name in houseNames" : key= " name.aptSeq" >
611
643
{{ name .aptNm }}
612
644
< / div>
613
- < / div>
614
- < div v- for = " house in houseInfos" : key= " house.id" >
645
+ < / div>
646
+ < div v- for = " house in houseInfos" : key= " house.id" class = " z-10 " >
615
647
< CardView
616
648
: jibun= " house.jibun"
617
649
: imgUrl= " house.imgUrl"
0 commit comments