From 06c01b1e26d7a5320251f22c46608d79bd5234cf Mon Sep 17 00:00:00 2001
From: boyang <1920788179@qq.com>
Date: Tue, 19 Nov 2024 15:28:40 +0800
Subject: [PATCH] fix: 解决面包屑导航搜索后的bug

---
 components/ProductDetail.vue         | 25 ++++++++++++++++++++++++-
 pages/products/detail/[id]/index.vue |  2 +-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/components/ProductDetail.vue b/components/ProductDetail.vue
index ab3bd6e..c7d58ec 100644
--- a/components/ProductDetail.vue
+++ b/components/ProductDetail.vue
@@ -224,6 +224,7 @@ const routeQuery = useRouteQuery();
 const dialogStore = useDialogStore();
 const href1 = ref("/products");
 const href2 = ref("/products");
+const productStore = useProductListStore();
 // 定义单个 item 的接口
 interface BreadcrumbItem {
   title: string; // 标题
@@ -265,7 +266,28 @@ const props = defineProps<{
 }>();
 const info = props.info;
 watchEffect(() => {
-  if (routeQuery.categories) {
+  if (info?.productCrumbsVO?.category1 && productStore.keyword) {
+    console.log(productStore.keyword, "5656keywordy");
+    items.value[1].title = info.productCrumbsVO.category1;
+    items.value[1].href =
+      href1.value + "?categories=" + info.productCrumbsVO.category1;
+    href1.value = href1.value + "?categories=" + info.productCrumbsVO.category1;
+    if (info?.productCrumbsVO?.category2) {
+      items.value[2].title = info.productCrumbsVO.category2;
+      href2.value = href1.value + "," + info.productCrumbsVO.category2;
+      items.value[2].href = href1.value + "," + info.productCrumbsVO.category2;
+    }
+    if (info?.productCrumbsVO?.function) {
+      // items.value.push({
+      //   title: info.productCrumbsVO.function,
+      //   disabled: false,
+      //   href: href2.value + "&function=" + info.productCrumbsVO.function,
+      // });
+      items.value[3].title = info.productCrumbsVO.function;
+      items.value[3].href =
+        href2.value + "&function=" + info.productCrumbsVO.function;
+    }
+  } else if (routeQuery.categories) {
     if (!routeQuery.categories.includes("Energy materials")) {
       routeQuery.updateFunction("Not specified");
     }
@@ -298,6 +320,7 @@ watchEffect(() => {
       // routeQuery.updateFunction(null);
     }
   } else if (info?.productCrumbsVO?.category1) {
+    console.log(productStore.keyword, "5656keywordy");
     items.value[1].title = info.productCrumbsVO.category1;
     items.value[1].href =
       href1.value + "?categories=" + info.productCrumbsVO.category1;
diff --git a/pages/products/detail/[id]/index.vue b/pages/products/detail/[id]/index.vue
index 1751e91..88290bd 100644
--- a/pages/products/detail/[id]/index.vue
+++ b/pages/products/detail/[id]/index.vue
@@ -59,7 +59,7 @@ newData.productimageliststore =
   typeof newData.productimageliststore === "string"
     ? JSON.parse(newData.productimageliststore) || []
     : (newData.productimageliststore as ProductImage[]);
-newData.productimageliststore = newData?.productimageliststore.map(
+newData.productimageliststore = newData?.productimageliststore?.map(
   (item: ProductImage) => ({
     ...item,
     // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`
--
libgit2 0.23.3