sanmu
authored
about a year ago
1
<template>
2
<div class="tw-m-auto tw-pb-[64px]" style="padding-bottom: 0px">
sanmu
authored
about a year ago
3
4
<CategoryList v-if="categoryStore.categoryVisible && !isMobile()" />
<MobileCategoryList v-if="categoryStore.categoryVisible && isMobile()" />
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<v-tabs
class="tabs"
v-model="tabRecom"
style="margin-top: 25px"
color="white"
bg-color="#eeeeee"
slider-color="blue-lighten-1"
selected-class="active"
v-if="recommendImages[0] !== null && !isMobile()"
>
<v-tab :value="1">Best Sellers</v-tab>
<!-- <v-tab :value="3">商品百科</v-tab> -->
</v-tabs>
<div id="image-container" v-if="recommendImages[0] !== null && !isMobile()">
<div class="recommend-left-box">
<v-img
src="https://m-canrd.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2024/09/14/76c987e13a334be481a346c19c2284f3qy4tjnxps7.png"
alt="往左移"
class="recommend-img-left"
@click="toggleRowLeft"
/>
</div>
<div class="image-row" id="row1">
<!-- <img
29
30
31
32
33
34
v-for="(imageObj, index) in recommendImages.slice(0, 5)"
:key="'row1-' + index"
:src="imageObj[0]?.url"
:alt="'Image ' + (index + 1)"
style="margin: 0 5px; width: 200px; height: 200px"
/> -->
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<div
v-for="(imageObj, index) in recommendImages"
:key="'row1-' + index"
class="imageTotal"
>
<a v-if="imageObj" :href="imageObj[0]?.productUrl" target="_blank">
<img
:src="imageObj[0]?.url"
:alt="'Image ' + (index + 1)"
class="item-imgHot"
/>
<span class="image-name">
{{ imageObj[0]?.name }}
</span>
</a>
<div v-else style="width: 200px; height: 200px"></div>
51
52
</div>
</div>
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<div class="recommend-right-box">
<v-img
src="https://m-canrd.oss-cn-shenzhen.aliyuncs.com/crmebimage/public/maintain/2024/09/14/b5daa0a8f2f140f5b406e984c730a453iznzlekysg.png"
alt="往右移"
class="recommend-img-right"
@click="toggleRowRight"
/>
</div>
</div>
<v-container class="">
<div class="tw-text-center tw-mt-[32px]" v-if="loading">
<v-progress-circular
color="blue-lighten-2"
indeterminate
size="64"
class="tw-m-auto"
></v-progress-circular>
</div>
<v-item-group multiple>
<v-row v-if="!loading">
<v-col
v-for="(item, i) in productStore.list"
:key="i"
cols="6"
lg="3"
md="4"
sm="6"
>
<v-hover v-slot="{ isHovering, props }" open-delay="200">
<v-card
:elevation="isHovering ? 16 : 2"
:class="{ 'on-hover': isHovering }"
class="mx-auto"
v-bind="props"
:to="`/products/detail/${item.id}`"
>
<v-img :src="item.imgList[0].url" :alt="item.name">
<!-- <v-expand-transition>
<div
v-if="isHovering"
class="d-flex transition-fast-in-fast-out bg-orange-darken-2 v-card--reveal tw-p-[12px] tw-text-justify"
style="height: 100%"
>
产品描述描述描述描述描述描述描述描述
</div>
</v-expand-transition> -->
</v-img>
<v-card-text class="tw-text-left font-weight-medium title">
<h3 style="color: red" v-if="item.price">
${{ item.price }}
</h3>
<h4>{{ item.name }}</h4>
</v-card-text>
</v-card>
</v-hover>
</v-col>
</v-row>
<div
v-if="!productStore.total && !loading"
class="text-medium-emphasis text-body-1 tw-text-center tw-m-[64px]"
>
no data
</div>
</v-item-group>
<v-row>
<v-col>
<v-pagination
:size="isMobile() ? 'small' : 'default'"
v-if="productStore.total"
v-model="productStore.pageNo"
@update:modelValue="productStore.updatePageNo"
:length="length"
rounded="0"
class="tw-float-right tw-mt-[32px]"
total-visible="5"
></v-pagination></v-col
></v-row>
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<v-tabs
class="tabs2"
ref="tabs2"
v-model="tabRecom"
style="margin-top: 25px; margin-bottom: 20px"
color="white"
bg-color="#eeeeee"
slider-color="blue-lighten-1"
selected-class="active"
v-if="isMobile()"
>
<v-tab :value="1">Best Sellers</v-tab>
<!-- <v-tab :value="3">商品百科</v-tab> -->
</v-tabs>
<div class="tw-text-center" v-if="hotLoading && isMobile()">
<v-progress-circular
color="blue-lighten-2"
indeterminate
size="64"
class="tw-m-auto"
></v-progress-circular>
</div>
<v-item-group multiple v-if="isMobile()">
<v-row v-if="!hotLoading">
<v-col
v-for="(item, i) in recommendImages"
:key="i"
cols="6"
lg="3"
md="4"
sm="6"
>
<div v-if="item !== null">
<v-card :elevation="4" class="mx-auto" :href="item[0].productUrl">
<!-- 设置 eager 属性,确保图片直接加载 -->
<v-img
:src="item[0].url"
:alt="item[0].name"
eager
class="d-block"
/>
<v-card-text class="tw-text-left font-weight-medium title">
<h4>{{ item[0].name }}</h4>
</v-card-text>
</v-card>
</div>
</v-col>
</v-row>
<!-- <div
v-if="!hotTotal"
class="text-medium-emphasis text-body-1 tw-text-center tw-m-[64px]"
>
no data
</div> -->
</v-item-group>
<v-row v-if="isMobile()">
<v-col>
<v-pagination
:size="isMobile() ? 'small' : 'default'"
v-if="hotTotal"
v-model="currentIndex"
@update:modelValue="toggleRowMobile"
:length="hotLength"
rounded="0"
class="tw-float-right tw-mt-[32px]"
total-visible="5"
></v-pagination></v-col
></v-row>
sanmu
authored
about a year ago
198
199
200
201
202
</v-container>
</div>
</template>
<script setup lang="ts">
203
import type { ProductImage } from "~/type";
204
205
206
207
208
209
import { isMobile, isEqual } from "~/utils";
import { useProductListStore } from "~/stores/product_list";
import { useCategoryStore } from "~/stores/category";
import CategoryList from "~/components/CategoryList.vue";
import MobileCategoryList from "~/components/MobileCategoryList.vue";
import { watchEffect, computed, ref } from "vue";
sanmu
authored
about a year ago
210
211
212
213
const productStore = useProductListStore();
const categoryStore = useCategoryStore();
const loading = ref(false);
214
const hotLoading = ref(false);
215
const route = useRoute(); // 获取路由信息
216
217
const router = useRouter(); // 获取路由信息
const title = ref("");
218
const keywordTitle = ref("");
219
220
221
222
223
const maxPage = ref(1);
const tabRecom = ref();
const recommendList = ref();
const recommendImages = ref();
const currentIndex = ref(1);
224
const hotTotal = ref(10);
225
const isOrNotMobile = isMobile();
226
227
const loadHotProducts = async () => {
228
229
230
231
232
const pageSize = ref(5);
if (isOrNotMobile) {
pageSize.value = 4;
}
hotLoading.value = true;
233
234
235
236
237
238
239
let { data: hotProducts } = await useAsyncData(
"hotProducts",
() =>
$fetch("/shop/product/hotProducts", {
method: "GET",
params: {
pageNo: currentIndex.value,
240
pageSize: pageSize.value,
241
242
243
244
245
246
},
}),
{
server: true, // 仅在服务器端获取数据
}
);
247
hotTotal.value = hotProducts.value.data.total;
248
249
250
recommendList.value = hotProducts.value.data.records;
maxPage.value = hotProducts.value.data.pages;
// recommendImages.value = recommendList.value.slice(0, 10).map((item) => {
251
252
253
254
255
recommendImages.value = Array.from({ length: pageSize.value }).map(
(_, index) => {
const item = recommendList.value[index];
if (!item) {
return null;
256
}
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// 检查 productimageliststore 是否为字符串格式,如果是,则尝试解析
if (typeof item.productimageliststore === "string") {
try {
item.productimageliststore = JSON.parse(item.productimageliststore);
} catch (error) {
item.productimageliststore = []; // 解析失败时,设置为空数组
}
}
const ree = (item.productimageliststore = item?.productimageliststore.map(
(productItem: ProductImage) => ({
...productItem,
// url: `http://112.74.45.244:8100/api/show/image?fileKey=${item.fileKey}`,
url: `https://www.canrud.com/api/show/image?fileKey=${productItem.fileKey}&psize=p256`,
name: item.name,
productUrl: `https://www.canrud.com/products/detail/${item.id}`,
})
));
return ree;
275
}
276
277
);
hotLoading.value = false;
278
};
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
const toggleRowLeft = () => {
if (currentIndex.value !== 1) {
currentIndex.value--;
} else if (currentIndex.value == 1) {
currentIndex.value = maxPage.value;
}
};
const toggleRowRight = () => {
if (currentIndex.value < maxPage.value) {
currentIndex.value++;
} else if (currentIndex.value == maxPage.value) {
currentIndex.value = 1;
}
};
294
295
296
297
const toggleRowMobile = (value: number) => {
currentIndex.value = value;
};
298
299
300
301
302
303
watch(currentIndex, (newIndex) => {
loadHotProducts(); // Call loadHotProducts when currentIndex changes
});
// Initial load of hot products
await loadHotProducts(); // Load hot products the first time
304
305
306
307
watchEffect(() => {
// 遍历数组
if (router.currentRoute.value.query.categories) {
title.value = `${router.currentRoute.value.query.categories}`;
308
} else if (router.currentRoute.value.query.function) {
309
310
title.value += `,${router.currentRoute.value.query.function}`;
}
311
312
313
if (router.currentRoute.value.query.keyword) {
keywordTitle.value = `${router.currentRoute.value.query.keyword}`;
}
314
});
315
316
useHead({
317
title: title.value || keywordTitle.value,
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
meta: [
{
name: "title",
content:
"科路得,助您科研之路势在必得。Canrd aims to be the world's leading one-stop service provider in new energy research. With a dedication to excellence, we offer Material Reagents, Lab Devices, Customized Batteries, Testing, and Advanced Packaging for energy materials and storage systems. We master advanced technologies to provide high-quality solutions. Our team's quick responses ensure tailored and professional services to meet your unique needs. Contact us at contact@canrd.com or call +86 19867737979 to explore our innovative offerings. Together, let's shape a greener, brighter world!",
},
{
name: "keywords",
content:
"科路得,canrd,canrud,Energy Storage Research,Lithium Batteries Research,Material Reagents,Lab Device,Customized Battery,Testing,Pack",
},
{
name: "description",
content:
"科路得,助您科研之路势在必得。We offer a wide range of research materials and related equipment, technical services, and battery material performance evaluation in areas such as pouch cells, lithium-ion batteries, supercapacitors, lithium-sulfur batteries, fuel cells, lithium-air batteries, and sodium-ion batteries.",
},
],
});
336
const firstIndex = ref(0);
337
const loadProducts = async () => {
sanmu
authored
about a year ago
338
339
let params: any = {
pageNo: productStore.pageNo,
340
341
pageSize: 20,
};
sanmu
authored
about a year ago
342
343
loading.value = true;
sanmu
authored
about a year ago
344
if (productStore.keyword && !isEqual(productStore.params, params)) {
345
346
347
348
349
params.keyword = productStore.keyword;
productStore.updateParams(params);
await productStore.getList(params);
loading.value = false;
return;
sanmu
authored
about a year ago
350
}
351
352
353
354
355
356
const categories = ref();
const mainCategory = ref();
if (router.currentRoute.value.query.categories) {
categories.value = router.currentRoute.value.query.categories.split(",");
mainCategory.value = categories.value[0].trim(); // 取第一个值
}
sanmu
authored
about a year ago
357
358
params.productCategoryId = categoryStore.selectedSubCategory;
sanmu
authored
about a year ago
359
360
// productCategoryId: '78b86c6e917841cf9a292234f2805e24',
if (categoryStore.selectedFuncCategory) {
361
params.productFunctionId = categoryStore.selectedFuncCategory;
362
363
364
365
366
367
368
if (firstIndex.value == 1) {
params.productFunctionId = selectedFuncCategoryBak.value;
firstIndex.value += 1;
if (
params.productFunctionId == "" &&
selectedFuncCategoryBak.value == ""
) {
369
categoryStore.selectedFuncCategory = selectedFuncCategoryBak.value;
370
params.productFunctionId = categoryStore.selectedFuncCategory;
371
// categoryStore.selectedFuncCategory = selectedFuncCategoryBak.value;
372
373
374
375
376
377
378
379
380
381
382
383
}
console.log(
params.productFunctionId,
selectedFuncCategoryBak.value,
categoryStore.selectedFuncCategory
);
}
// const savedSubCategory = localStorage.getItem("selectedFuncCategory2");
// console.log(savedSubCategory, "5656savedSubCategory");
// localStorage.setItem("selectedFuncCategory3", "2");
} else if (mainCategory.value == "Energy materials") {
params.productCategoryId = categoryStore.selectedSubCategory;
sanmu
authored
about a year ago
384
385
}
386
387
388
389
390
391
392
393
console.log(
// params,
// productStore?.params,
// categoryStore.selectedSubCategory,
// categoryStore.selectedFuncCategory,
window.selectedSubCategory,
window.selectedFuncCategory
);
394
395
396
397
if (
categoryStore.selectedSubCategory &&
!isEqual(productStore.params, params)
) {
398
// console.log(route, "5656route");
399
productStore.updateParams(params);
400
401
402
const categories = ref("Laboratory consumables,Others");
const mainCategory = categories.value[0].trim(); // 取第一个值
// console.log(categoryStore.selectedSubCategory, "5656mobi");
sanmu
authored
about a year ago
403
404
await productStore.getList(params);
sanmu
authored
about a year ago
405
}
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
// if (
// categoryStore.selectedFuncCategory &&
// !isEqual(productStore.params, params)
// ) {
// console.log(
// categoryStore.selectedFuncCategory,
// "5656categoryStore.selectedFuncCategoryss"
// );
// productStore.updateParams(params);
// await productStore.getList(params);
// }
if (firstIndex.value === 0 && categoryStore.selectedFuncCategory) {
// console.log(route, "5656route");
productStore.updateParams(params);
// const categories = ref("Laboratory consumables,Others");
// const mainCategory = categories.value[0].trim(); // 取第一个值
// console.log(categoryStore.selectedFuncCategory, "5656mobi");
await productStore.getList(params);
firstIndex.value = 1;
}
426
427
loading.value = false;
};
428
429
430
const isWindowAssigned = ref(false);
const selectedSubCategoryBak = ref();
const selectedFuncCategoryBak = ref();
431
watchEffect(async () => {
432
433
if (route.query.keyword !== undefined) {
productStore.keyword = route.query.keyword;
434
}
435
436
437
438
439
440
441
442
// console.log(categoryStore.selectedSubCategory, "5656index-categoryStore");
if (typeof window !== "undefined" && !isWindowAssigned.value) {
window.selectedSubCategory = categoryStore.selectedSubCategory;
window.selectedFuncCategory = categoryStore.selectedFuncCategory;
selectedSubCategoryBak.value = categoryStore.selectedSubCategory;
selectedFuncCategoryBak.value = categoryStore.selectedFuncCategory;
isWindowAssigned.value = true;
}
443
loadProducts();
444
// console.log(categoryStore.selectedSubCategory, "5656index-categoryStore");
445
});
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// onMounted(() => {
// // window.selectedSubCategory = categoryStore.selectedSubCategory;
// // window.selectedFuncCategory = categoryStore.selectedFuncCategory;
// if (route.query.function) {
// const functionName = route.query.function.trim();
// const funcCategoryList = computed(() => {
// if (categoryStore.selectedCategory) {
// const tmp = categoryStore.list.filter(
// (item) => item.categoryDisplayName === categoryStore.selectedCategory
// );
// return tmp?.[0]?.productFunctions || [];
// }
// return [];
// });
// const foundFuncCategory = funcCategoryList.value.find(
// (func) => func.name === functionName
// );
// if (foundFuncCategory) {
// const funcCategoryId = foundFuncCategory.id;
// if (typeof localStorage !== "undefined") {
// localStorage.setItem("selectedFuncCategory2", funcCategoryId);
// localStorage.setItem("selectedFuncCategory3", "1");
// }
// // 你可以在这里使用找到的 funcCategoryId
// }
// // // 6. 查找对应的功能分类 ID
// // const foundFuncCategory = funcCategories.find(
// // (func) => func.name === functionName
// // );
// // if (foundFuncCategory) {
// // const funcCategoryId = foundFuncCategory.id;
// // // 使用找到的 funcCategoryId
// // categoryStore.updateFuncCategory(funcCategoryId);
// // }
// }
// });
sanmu
authored
about a year ago
484
485
486
const length = computed(() =>
productStore.total ? Math.ceil(productStore.total / productStore.pageSize) : 0
487
);
488
489
490
const hotLength = computed(() =>
hotTotal.value ? Math.ceil(hotTotal.value / 4) : 0
);
sanmu
authored
about a year ago
491
492
493
494
495
496
497
498
499
500
501
</script>
<style scoped>
.title {
height: 60px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
502
503
504
505
506
@media screen and (min-width: 1537px) {
.tabs {
border-bottom: 2px solid #1f88e5;
margin: 10px auto 20px;
507
width: 93%;
508
509
510
511
512
513
}
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
.tabs {
border-bottom: 2px solid #1f88e5;
margin: 10px auto 40px;
514
width: 78%;
515
516
517
518
519
520
}
}
@media screen and (max-width: 1280px) {
.tabs {
border-bottom: 2px solid #1f88e5;
margin: 10px auto 40px;
521
width: 92%;
522
}
523
}
524
525
526
/* .tabs {
border-bottom: 2px solid #1f88e5;
} */
527
528
529
530
531
532
533
534
535
536
537
.active {
background-color: #1086e8;
}
@media screen and (min-width: 1537px) {
#image-container {
display: flex;
align-items: center;
justify-content: center;
height: 320px;
538
margin: 10px auto 50px;
539
540
541
542
543
544
545
546
width: 80%;
}
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
#image-container {
display: flex;
align-items: center;
justify-content: center;
547
548
height: 260px;
margin: 10px auto 0px;
549
550
551
552
width: 80%;
padding: 0;
}
}
553
554
555
556
557
@media screen and (max-width: 1280px) {
#image-container {
display: flex;
align-items: center;
justify-content: center;
558
559
height: 260px;
margin: 10px auto 0px;
560
561
562
563
width: 80%;
padding: 0;
}
}
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
.image-row {
display: flex;
height: 245px;
}
@media screen and (min-width: 1537px) {
.imageTotal {
display: inline-block;
margin: 0 5px;
text-align: center;
width: 300px;
}
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
.imageTotal {
display: inline-block;
margin: 0 5px;
text-align: center;
width: 200px;
}
}
584
585
586
587
588
@media screen and (max-width: 1280px) {
.imageTotal {
display: inline-block;
margin: 0 5px;
text-align: center;
589
width: 200px;
590
591
}
}
592
593
594
595
596
597
598
599
600
601
602
603
@media screen and (min-width: 1537px) {
.image-row img {
width: 240px;
height: 240px;
}
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
.image-row img {
width: 140px;
height: 140px;
}
}
604
605
@media screen and (max-width: 1280px) {
.image-row img {
606
607
width: 120px;
height: 120px;
608
609
}
}
610
611
@media screen and (min-width: 1537px) {
.image-name {
612
613
614
615
616
display: -webkit-box; /* Enables multi-line text handling */
-webkit-box-orient: vertical; /* Defines the vertical orientation of the box */
-webkit-line-clamp: 3; /* Limits the text to 3 lines */
overflow: hidden; /* Hides the overflowed text */
text-overflow: ellipsis; /* Adds an ellipsis when the text overflows */
617
618
619
620
margin-top: 5px;
font-size: 16px;
width: 180px;
color: #555;
621
text-align: center; /* Centers the text horizontally */
622
623
624
625
626
margin-left: 50px;
}
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
.image-name {
627
628
629
630
631
display: -webkit-box; /* Enables multi-line text handling */
-webkit-box-orient: vertical; /* Defines the vertical orientation of the box */
-webkit-line-clamp: 3; /* Limits the text to 3 lines */
overflow: hidden; /* Hides the overflowed text */
text-overflow: ellipsis; /* Adds an ellipsis when the text overflows */
632
633
634
635
margin-top: 5px;
font-size: 16px;
width: 180px;
color: #555;
636
text-align: center; /* Centers the text horizontally */
637
638
639
margin-left: 10px;
}
}
640
641
@media screen and (max-width: 1280px) {
.image-name {
642
643
644
645
646
display: -webkit-box; /* Enables multi-line text handling */
-webkit-box-orient: vertical; /* Defines the vertical orientation of the box */
-webkit-line-clamp: 3; /* Limits the text to 3 lines */
overflow: hidden; /* Hides the overflowed text */
text-overflow: ellipsis; /* Adds an ellipsis when the text overflows */
647
648
649
650
margin-top: 5px;
font-size: 16px;
width: 180px;
color: #555;
651
text-align: center; /* Centers the text horizontally */
652
653
654
margin-left: 10px;
}
}
655
656
657
658
659
660
661
662
663
button .recommendButton {
margin: 0 0px;
cursor: pointer;
}
.recommend-left-box {
}
664
665
666
667
668
669
670
@media screen and (max-width: 1280px) {
.recommend-img-left {
width: 26px;
height: 27px;
margin-bottom: 60px;
}
}
671
672
673
674
.recommend-img-left {
width: 26px;
height: 27px;
margin-right: 30px;
675
margin-bottom: 60px;
676
677
678
679
680
681
682
683
684
685
686
687
}
.recommend-img-left:hover {
cursor: pointer;
}
.recommend-right-box {
}
.recommend-img-right {
width: 26px;
height: 27px;
margin-left: 30px;
688
margin-bottom: 60px;
689
690
691
692
693
}
.recommend-img-right:hover {
cursor: pointer;
}
694
695
696
697
.v-card {
transition: all 0.3s ease-in-out;
}
sanmu
authored
about a year ago
698
</style>