Commit 3e08f1f6a334bc82ca08f49c557a3c7f1e0d48b2

Authored by boyang
2 parents 14b1db9c d6a8ab2a

Merge branch 'by'

components/ProductDetail.vue
... ... @@ -46,30 +46,30 @@
46 46 <!-- <v-row class="bg-white mb-sm-10 text-h4 font-weight-medium">
47 47 <v-col>{{ info.name }}</v-col>
48 48 </v-row> -->
49   - <h1>{{ info.name }}</h1>
  49 + <h1 class="tw-m-[12px] tw-mb-[36px]">{{ info.name }}</h1>
50 50 <div class="tw-flex tw-flex-wrap">
51   - <div class="tw-w-1/2">
52   - <span class="tw-leading-[10px] tw-m-[16px]">
  51 + <div class="tw-w-1/2 tw-mb-[12px]">
  52 + <span class="tw-leading-[10px] tw-m-[12px]">
53 53 Brand:{{ info.brandName }}
54 54 </span>
55 55 </div>
56 56 <div class="tw-w-1/2 tw-mb-[12px]">
57   - <span class="tw-leading-[10px] tw-m-[16px]"
  57 + <span class="tw-leading-[10px] tw-m-[12px]"
58 58 >Product Model:{{ info.model }}</span
59 59 >
60 60 </div>
61 61 <div class="tw-w-1/2 tw-mb-[12px]" v-if="info.basename1">
62   - <span class="tw-leading-[10px] tw-m-[16px]"
  62 + <span class="tw-leading-[10px] tw-m-[12px]"
63 63 >{{ info.basename1 }}:{{ info.basecore1 }}</span
64 64 >
65 65 </div>
66 66 <div class="tw-w-1/2 tw-mb-[12px]" v-if="info.basename2">
67   - <span class="tw-leading-[10px] tw-m-[16px]"
  67 + <span class="tw-leading-[10px] tw-m-[12px]"
68 68 >{{ info.basename2 }}:{{ info.basecore2 }}</span
69 69 >
70 70 </div>
71 71 <div class="tw-w-1/2 tw-mb-[12px]" v-if="info.basename3">
72   - <span class="tw-leading-[10px] tw-m-[16px]"
  72 + <span class="tw-leading-[10px] tw-m-[12px]"
73 73 >{{ info.basename3 }}:{{ info.basecore3 }}</span
74 74 >
75 75 </div>
... ... @@ -85,7 +85,8 @@
85 85 :key="index"
86 86 class="tw-w-1/2 tw-mb-[12px]"
87 87 >
88   - <span class="tw-leading-[10px] tw-m-[16px]"
  88 + <span
  89 + class="tw-leading-normal tw-m-0 tw-block tw-max-w-full tw-break-words tw-ml-[12px]"
89 90 >{{ attribute.name }}:{{ attribute.value }}</span
90 91 >
91 92 </div>
... ... @@ -150,6 +151,123 @@
150 151 </v-dialog> -->
151 152 </v-col>
152 153 </v-row>
  154 +
  155 + <v-tabs
  156 + class="tabs"
  157 + v-model="tabRecom"
  158 + color="white"
  159 + bg-color="#eeeeee"
  160 + slider-color="blue-lighten-1"
  161 + selected-class="active"
  162 + v-if="recommendImages[0] !== null"
  163 + >
  164 + <v-tab :value="1">Product Recommendations</v-tab>
  165 + <!-- <v-tab :value="3">商品百科</v-tab> -->
  166 + </v-tabs>
  167 + <div id="image-container" v-if="recommendImages[0] !== null">
  168 + <div class="recommend-left-box">
  169 + <v-img
  170 + src="https://m-canrd.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2024/09/14/76c987e13a334be481a346c19c2284f3qy4tjnxps7.png"
  171 + alt="往左移"
  172 + class="recommend-img-left"
  173 + @click="toggleRow"
  174 + />
  175 + </div>
  176 + <div v-if="currentIndex === 0" class="image-row" id="row1">
  177 + <!-- <img
  178 + v-for="(imageObj, index) in recommendImages.slice(0, 5)"
  179 + :key="'row1-' + index"
  180 + :src="imageObj[0]?.url"
  181 + :alt="'Image ' + (index + 1)"
  182 + style="margin: 0 5px; width: 200px; height: 200px"
  183 + /> -->
  184 + <div
  185 + v-for="(imageObj, index) in recommendImages.slice(0, 5)"
  186 + :key="'row1-' + index"
  187 + style="
  188 + display: inline-block;
  189 + margin: 0 5px;
  190 + text-align: center;
  191 + width: 200px;
  192 + "
  193 + >
  194 + <a v-if="imageObj" :href="imageObj[0]?.productUrl" target="_blank">
  195 + <img
  196 + :src="imageObj[0]?.url"
  197 + :alt="'Image ' + (index + 1)"
  198 + style="width: 200px; height: 200px; margin-right: 10px"
  199 + />
  200 + <span
  201 + style="
  202 + display: block;
  203 + margin-top: 5px;
  204 + font-size: 16px;
  205 + width: 180px;
  206 + color: #555;
  207 + text-align: left;
  208 + margin-left: 10px;
  209 + "
  210 + >
  211 + {{ imageObj[0]?.name }}
  212 + </span>
  213 + </a>
  214 + <div v-else style="width: 200px; height: 200px"></div>
  215 + </div>
  216 + </div>
  217 + <div v-else class="image-row" id="row2">
  218 + <!-- <img
  219 + v-for="(imageObj, index) in recommendImages.slice(5, 10)"
  220 + :key="'row2-' + index"
  221 + :src="imageObj[0]?.url"
  222 + :alt="'Image ' + (index + 6)"
  223 + style="margin: 0 5px; width: 200px; height: 200px"
  224 + /> -->
  225 + <div
  226 + v-for="(imageObj, index) in recommendImages.slice(5, 10)"
  227 + :key="'row2-' + index"
  228 + style="
  229 + display: inline-block;
  230 + margin: 0 5px;
  231 + text-align: center;
  232 + width: 200px;
  233 + "
  234 + >
  235 + <a v-if="imageObj" :href="imageObj[0]?.productUrl" target="_blank">
  236 + <img
  237 + :src="imageObj[0]?.url"
  238 + :alt="'Image ' + (index + 6)"
  239 + style="width: 200px; height: 200px; margin-right: 10px"
  240 + />
  241 + <span
  242 + style="
  243 + display: block;
  244 + margin-top: 5px;
  245 + font-size: 16px;
  246 + color: #555;
  247 + text-align: left;
  248 + width: 180px;
  249 + margin-left: 10px;
  250 + "
  251 + >
  252 + {{ imageObj[0]?.name }}
  253 + </span>
  254 + </a>
  255 + <div
  256 + v-else
  257 + style="width: 200px; height: 200px; margin-right: 10px"
  258 + ></div>
  259 + </div>
  260 + </div>
  261 + <div class="recommend-right-box">
  262 + <v-img
  263 + src="https://m-canrd.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2024/09/14/b5daa0a8f2f140f5b406e984c730a453iznzlekysg.png"
  264 + alt="往右移"
  265 + class="recommend-img-right"
  266 + @click="toggleRow"
  267 + />
  268 + </div>
  269 + </div>
  270 +
153 271 <div class="tw-pb-[64px]">
154 272 <v-tabs
155 273 class="tabs"
... ... @@ -218,6 +336,12 @@ import { useDialogStore } from &quot;~/stores/dialog&quot;;
218 336 import { useRouter, useRoute } from "vue-router";
219 337 import { useRouteQuery } from "@/stores/route_query";
220 338  
  339 +const recommendList = ref();
  340 +const recommendImages = ref();
  341 +const selectedItem = ref();
  342 +const tabRecom = ref(0);
  343 +const tabRecommend = ref(0);
  344 +const tabPeriodical = ref(0);
221 345 const route = useRoute();
222 346 const router = useRouter();
223 347 const routeQuery = useRouteQuery();
... ... @@ -265,9 +389,23 @@ const props = defineProps&lt;{
265 389 info: Product;
266 390 }>();
267 391 const info = props.info;
  392 +let { data: resData } = await useAsyncData(
  393 + "detail",
  394 + () =>
  395 + $fetch("/shop/product/list", {
  396 + method: "GET",
  397 + params: {
  398 + pageNo: 1,
  399 + pageSize: 20,
  400 + ids: info.relatedProductIds,
  401 + },
  402 + }),
  403 + {
  404 + server: true, // 仅在服务器端获取数据
  405 + }
  406 +);
268 407 watchEffect(() => {
269 408 if (info?.productCrumbsVO?.category1 && productStore.keyword) {
270   - console.log(productStore.keyword, "5656keywordy");
271 409 items.value[1].title = info.productCrumbsVO.category1;
272 410 items.value[1].href =
273 411 href1.value + "?categories=" + info.productCrumbsVO.category1;
... ... @@ -320,7 +458,6 @@ watchEffect(() =&gt; {
320 458 // routeQuery.updateFunction(null);
321 459 }
322 460 } else if (info?.productCrumbsVO?.category1) {
323   - console.log(productStore.keyword, "5656keywordy");
324 461 items.value[1].title = info.productCrumbsVO.category1;
325 462 items.value[1].href =
326 463 href1.value + "?categories=" + info.productCrumbsVO.category1;
... ... @@ -341,10 +478,49 @@ watchEffect(() =&gt; {
341 478 href2.value + "&function=" + info.productCrumbsVO.function;
342 479 }
343 480 }
  481 + recommendList.value = resData.value.data.records;
  482 +
  483 + // recommendImages.value = recommendList.value.slice(0, 10).map((item) => {
  484 + recommendImages.value = Array.from({ length: 10 }).map((_, index) => {
  485 + const item = recommendList.value[index];
  486 + if (!item) {
  487 + return null;
  488 + }
  489 + // 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析
  490 + if (typeof item.productimageliststore === "string") {
  491 + try {
  492 + item.productimageliststore = JSON.parse(item.productimageliststore);
  493 + } catch (error) {
  494 + item.productimageliststore = []; // 解析失败时,设置为空数组
  495 + }
  496 + }
  497 + const ree = (item.productimageliststore = item?.productimageliststore.map(
  498 + (productItem: ProductImage) => ({
  499 + ...productItem,
  500 + // url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`,
  501 + url: `/api/show/image?fileKey=${productItem.fileKey}&psize=p512`,
  502 + name: item.name,
  503 + productUrl: `http://www.canrud.com/products/detail/${item.id}`,
  504 + })
  505 + ));
  506 + return ree;
  507 + });
344 508 });
345 509 // onMounted(() => {
346 510 // dialogStore.updateDialog(true)
347 511 // })
  512 +const currentIndex = ref(0);
  513 +const navigateToUrl = (url) => {
  514 + // window.open(url); // 在新标签页中打开链接
  515 +};
  516 +const toggleRow = () => {
  517 + currentIndex.value = currentIndex.value === 0 ? 1 : 0;
  518 +};
  519 +// onMounted(() => {
  520 +// recommendImages.value.forEach((imageArray, index) => {
  521 +// console.log(`5656Image Object ${index + 1}:`, imageArray[0]);
  522 +// });
  523 +// });
348 524  
349 525 const tab = ref(0);
350 526 const slide = ref(0);
... ... @@ -418,4 +594,53 @@ th {
418 594 .breadcrumb-active {
419 595 color: gray;
420 596 }
  597 +
  598 +#image-container {
  599 + display: flex;
  600 + align-items: center;
  601 + justify-content: center;
  602 + height: 320px;
  603 + margin-top: 10px;
  604 + margin-bottom: 10px;
  605 +}
  606 +
  607 +.image-row {
  608 + display: flex;
  609 + height: 245px;
  610 +}
  611 +
  612 +.image-row img {
  613 + width: 120px;
  614 + height: 120px;
  615 +}
  616 +
  617 +button .recommendButton {
  618 + margin: 0 0px;
  619 + cursor: pointer;
  620 +}
  621 +
  622 +.recommend-left-box {
  623 +}
  624 +
  625 +.recommend-img-left {
  626 + width: 26px;
  627 + height: 27px;
  628 + margin-right: 30px;
  629 +}
  630 +
  631 +.recommend-img-left:hover {
  632 + cursor: pointer;
  633 +}
  634 +.recommend-right-box {
  635 +}
  636 +
  637 +.recommend-img-right {
  638 + width: 26px;
  639 + height: 27px;
  640 + margin-left: 30px;
  641 +}
  642 +
  643 +.recommend-img-right:hover {
  644 + cursor: pointer;
  645 +}
421 646 </style>
... ...
pages/products/index.vue
... ... @@ -96,7 +96,6 @@ watchEffect(() =&gt; {
96 96 if (router.currentRoute.value.query.function) {
97 97 title.value += `,${router.currentRoute.value.query.function}`;
98 98 }
99   - // document.title = title.value;
100 99 });
101 100  
102 101 useHead({
... ...