Blame view

components/CategoryList.vue 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
<template>
  <v-container>
    <div class="tw-border tw-border-solid tw-border-[#1f88e5]">
      <v-row
        class="ma-0 pl-4 bg-grey-lighten-3 tw-border-0 tw-border-b tw-border-solid tw-border-[#1f88e5] md:tw-leading-[64px]"
      >
        <div
          class="tw-pr-0 tw-font-bold tw-w-[160px] tw-h-[36px] tw-leading-[64px] text-grey-darken-3"
        >
          CATEGORY:
        </div>
        <v-col class="flex pa-0" cols="12" sm="9">
          <span
柏杨 authored
14
15
            :class="
              'tw-leading-[50px] tw-inline-flex tw-cursor-pointer px-4 mb-1 mr-1 tw-font-medium rounded hover:tw-text-[#fff] hover:tw-bg-[#1e88e5] ' +
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
              (categoryStore.selectedCategory === item.categoryDisplayName &&
                'tw-text-[#fff] tw-bg-[#1e88e5]')
            "
            v-for="(item, index) in categoryStore.list"
            :key="index"
            @click="handleCategoryClick(item)"
          >
            <b class="tw-m-0 tw-inline">{{ item.categoryDisplayName }}</b>
          </span>
        </v-col>
      </v-row>
      <v-row class="pa-4 ma-0 bg-grey-lighten-4">
        <div
          class="tw-pr-0 tw-font-bold tw-w-[130px] tw-h-[36px] tw-leading-[36px] text-grey-darken-3"
        >
          DEVICE TYPE:
        </div>
        <v-col class="pa-0" cols="12" sm="9">
          <span
柏杨 authored
35
36
37
38
            :class="
              'px-4 py-1 mb-1 mr-1 tw-font-medium  rounded  tw-inline-flex tw-cursor-pointer hover:tw-text-[#fff] hover:tw-bg-[#1e88e5] ' +
              (categoryStore.selectedSubCategory === item.id &&
                'tw-text-[#fff] tw-bg-[#1e88e5]')
39
40
41
            "
            v-for="(item, index) in subCategoryList"
            :key="index"
柏杨 authored
42
            @click="handleSubCategoryClick(item)"
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
          >
            {{ item.name }}
          </span>
        </v-col>
      </v-row>
      <v-row
        v-if="funcCategoryList.length"
        class="pa-4 ma-0 bg-grey-lighten-4 tw-border-0 tw-border-t tw-border-dashed tw-border-[rgb(178, 178, 178)]"
      >
        <div
          class="tw-pr-0 tw-font-bold tw-w-[210px] tw-h-[36px] tw-leading-[36px] text-grey-darken-3"
        >
          MATERIAL FUNCTION:
        </div>
        <v-col class="pa-0" cols="12" sm="9">
          <span
柏杨 authored
59
60
61
62
            :class="
              'px-4 py-1 mb-1  mr-1  tw-font-medium rounded tw-inline-flex tw-cursor-pointer hover:tw-text-[#fff] hover:tw-bg-[#1e88e5] ' +
              (categoryStore.selectedFuncCategory === item.id &&
                'tw-text-[#fff] tw-bg-[#1e88e5]')
63
64
65
            "
            v-for="(item, index) in funcCategoryList"
            :key="index"
柏杨 authored
66
            @click="handleFuncCategoryClick(item)"
67
68
69
70
71
72
73
74
75
76
          >
            {{ item.name }}
          </span>
        </v-col>
      </v-row>
    </div>
  </v-container>
</template>

<script setup lang="ts">
柏杨 authored
77
78
79
80
81
import { useCategoryStore } from "@/stores/category";
import { useProductListStore } from "@/stores/product_list";
import type { CategoryRootType } from "@/type";
import { computed } from "vue";
import { useRouter, useRoute } from "vue-router";
柏杨 authored
82
import { useRouteQuery } from "@/stores/route_query";
柏杨 authored
83
柏杨 authored
84
const routeQuery = useRouteQuery();
柏杨 authored
85
86
87
88
89
90
const route = useRoute();
const router = useRouter();

const categoryStore = useCategoryStore();
const productStore = useProductListStore();
watchEffect(async () => {
91
  if (route.query.categories) {
柏杨 authored
92
    // 1. 提取 query.category 的内容
柏杨 authored
93
    productStore.updateKeyword("");
94
    const categories = route.query.categories.split(",");
柏杨 authored
95
    const mainCategory = categories[0].trim(); // 取第一个值
96
97
    const subCategoryName = ref("Not specified");
    subCategoryName.value = categories[1]
柏杨 authored
98
99
      ? categories[1].trim()
      : "Not specified"; // 取第二个值(如果存在)
柏杨 authored
100
101
102

    // 2. 更新选中的主分类
    categoryStore.updateCategory(mainCategory);
103
    routeQuery.updateCategories(mainCategory + "," + subCategoryName.value);
柏杨 authored
104
    // 3. 如果有子分类名称,查找其对应的 ID
105
    if (subCategoryName.value) {
柏杨 authored
106
107
108
109
110
111
112
113
114
115
      const subCategoryList = computed(() => {
        if (categoryStore.selectedCategory) {
          const tmp = categoryStore.list.filter(
            (item) =>
              item.categoryDisplayName === categoryStore.selectedCategory
          );
          return tmp?.[0]?.list || [];
        }
        return [];
      });
116
柏杨 authored
117
118
      // 4. 查找对应的子分类 ID
      const foundFuncCategory = subCategoryList.value.find(
119
        (func) => func.name === subCategoryName.value
柏杨 authored
120
      );
121
柏杨 authored
122
123
124
125
126
127
128
129
130
      if (foundFuncCategory) {
        const funcCategoryId = foundFuncCategory.id;
        // 你可以在这里使用找到的 funcCategoryId
        categoryStore.updateSubCategory(funcCategoryId);
      }
    }
    // 5. 判断 query 中是否存在 function,并查找对应的 ID
    if (route.query.function) {
      const functionName = route.query.function.trim();
柏杨 authored
131
      routeQuery.updateFunction(functionName);
柏杨 authored
132
133
134
135
136
137
138
139
140
141
142
143
144
      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
      );
145
柏杨 authored
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
      if (foundFuncCategory) {
        const funcCategoryId = foundFuncCategory.id;
        // 你可以在这里使用找到的 funcCategoryId
        categoryStore.updateFuncCategory(funcCategoryId);
      }
      // // 6. 查找对应的功能分类 ID
      // const foundFuncCategory = funcCategories.find(
      //   (func) => func.name === functionName
      // );

      // if (foundFuncCategory) {
      //   const funcCategoryId = foundFuncCategory.id;
      //   // 使用找到的 funcCategoryId
      //   categoryStore.updateFuncCategory(funcCategoryId);
      // }
柏杨 authored
161
    } else if (route.query.categories.includes("Energy materials")) {
162
163
      const defaultCategory = categoryStore.list[1];
      const defaultFuncCategory = defaultCategory.productFunctions[1];
柏杨 authored
164
165
166
167
168
169
170
171
172
      if (defaultFuncCategory) {
        categoryStore.updateFuncCategory(defaultFuncCategory.id);
      }
      router.push({
        query: {
          categories: route.query.categories,
          function: defaultFuncCategory.name,
        },
      });
柏杨 authored
173
    }
柏杨 authored
174
175
176
177
  } else if (
    Object.keys(route.query).length === 0 &&
    !route.path.includes("/products/detail")
  ) {
柏杨 authored
178
179
    // 检查是否有默认的分类
    const defaultCategory = categoryStore.list[0]; // 假设第一个分类是默认的
柏杨 authored
180
柏杨 authored
181
182
    if (defaultCategory) {
      const defaultCategoryName = defaultCategory.categoryDisplayName;
183
184
      const defaultSubCategory = defaultCategory.list[1]; // 假设第一个子分类为默认子分类
      const defaultFuncCategory = defaultCategory.productFunctions[1]; // 假设第一个功能分类为默认功能分类
柏杨 authored
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

      // 更新 store 和 URL
      categoryStore.updateCategory(defaultCategoryName);
      productStore.updatePageNo(1);

      if (defaultSubCategory) {
        categoryStore.updateSubCategory(defaultSubCategory.id);

        // 如果有之前的值则使用之前的值,拼接新的子分类名
        const updatedCategory =
          defaultCategoryName + "," + defaultSubCategory.name;

        // 拼接设备类型到 URL
        router.push({
          query: {
200
            categories: defaultCategoryName + "," + defaultSubCategory.name,
柏杨 authored
201
202
203
204
205
206
207
208
209
          },
        });
      }

      if (defaultFuncCategory) {
        categoryStore.updateFuncCategory(defaultFuncCategory.id);
        // 拼接功能类型到 URL
        router.push({
          query: {
210
            categories: defaultCategoryName + "," + defaultSubCategory.name,
柏杨 authored
211
212
213
214
215
216
217
            function: defaultFuncCategory.name,
          },
        });
      }
    }
  }
});
柏杨 authored
218
219
220
221
222
223
224
225
226
227
const seo = {
  "Energy materials":
    "Energy materials,Not specified,Battery accessories,Lithium-ion batteries,Capacitors,Sodium-ion batteries,Lithium-sulfur batteries,Potassium/magnesium/aluminum/zinc batteries,Air/fuel/solar,Analytical electrodes,Complete battery accessories",
  "Laboratory consumables":
    "Laboratory consumables,Not specified,Glass materials,Plastic materials,Metal materials,Ceramic materials,Paper film materials,Chemical materials,Tetrafluoro materials,Safety protection,Office supplies,Tools,Others",
  "Low-dimensional materials":
    ",Low-dimensional materialsNot specified,Zero-dimensional carbon materials,One-dimensional carbon materials,Two-dimensional carbon materials,Three-dimensional carbon materials,Inorganic nanomaterials,Organic nanomaterials,Metal nanomaterials,Others",
  Equipment:
    "Equipment,Not specified,Equipment,Accessories & fixtures,Fuel cell manufacturing and testing equipment",
};
228
229

const handleCategoryClick = (item: CategoryRootType) => {
柏杨 authored
230
231
232
233
  categoryStore.updateCategory(item.categoryDisplayName);
  categoryStore.updateSubCategory(item.list[0].id);
  productStore.updatePageNo(1);
  const defaultSubCategory = item.list[0]; // 假设第一个子分类为默认子分类
234
柏杨 authored
235
236
237
  if (item.categoryDisplayName === "Energy materials") {
    router.push({
      query: {
238
        categories: item.categoryDisplayName + "," + defaultSubCategory.name,
柏杨 authored
239
240
241
242
243
244
        function: item.productFunctions[0].name,
      },
    });
  } else {
    router.push({
      query: {
245
        categories: item.categoryDisplayName + "," + defaultSubCategory.name,
柏杨 authored
246
247
248
      },
    });
  }
249
250
251
252
253
254
255
256
257

  // const doc = document as any
  // const head = doc.getElementsByTagName('head')
  // const meta = doc.createElement('meta')
  // document.title = seo[item.categoryDisplayName as keyof typeof seo]
  // doc
  //   .querySelector('meta[name="keywords"]')
  //   .setAttribute('content', seo[item.categoryDisplayName as keyof typeof seo])
  // head[0].appendChild(meta)
柏杨 authored
258
259
260
261
262
263
264
265
};

const handleSubCategoryClick = (value: CategoryRootType) => {
  categoryStore.updateSubCategory(value.id);
  productStore.updatePageNo(1);

  // 获取当前的查询参数
  const currentQuery = router.currentRoute.value.query;
266
  const currentCategory = currentQuery.categories || "";
柏杨 authored
267
268
269
270
271
272
273
274

  // 如果有之前的值则使用之前的值,拼接新的子分类名
  const updatedCategory = currentCategory.split(",")[0] + "," + value.name;

  // 更新路由,保持 handleCategoryClick 的值不变
  // router.push({ query: { category: updatedCategory } });
  // 更新路由,保持 function 参数不变
  router.push({
275
    query: { categories: updatedCategory, function: currentQuery.function },
柏杨 authored
276
277
278
279
280
281
282
283
  });
};

const handleFuncCategoryClick = (value: CategoryRootType) => {
  categoryStore.updateFuncCategory(value.id);
  productStore.updatePageNo(1);
  // 获取当前的查询参数
  const currentQuery = router.currentRoute.value.query;
284
柏杨 authored
285
286
287
288
289
  // 将 value.name 作为新的查询参数加入到现有的 query 中
  const updatedQuery = {
    ...currentQuery, // 保持当前的查询参数
    function: value.name, // 将 value.name 添加为新的查询参数 funcCategory
  };
290
柏杨 authored
291
292
293
  // 更新路由
  router.push({ query: updatedQuery });
};
294
295
296
297
298

const subCategoryList = computed(() => {
  if (categoryStore.selectedCategory) {
    const tmp = categoryStore.list.filter(
      (item) => item.categoryDisplayName === categoryStore.selectedCategory
柏杨 authored
299
300
    );
    return tmp?.[0]?.list || [];
301
  }
柏杨 authored
302
303
  return [];
});
304
305
306
307
308

const funcCategoryList = computed(() => {
  if (categoryStore.selectedCategory) {
    const tmp = categoryStore.list.filter(
      (item) => item.categoryDisplayName === categoryStore.selectedCategory
柏杨 authored
309
310
    );
    return tmp?.[0]?.productFunctions || [];
311
  }
柏杨 authored
312
313
  return [];
});
314
315
316
317
318
319
320
321

import type { ProductImage } from "~/type";
import { isMobile, isEqual } from "~/utils";
import { watchEffect, ref } from "vue";

const title = ref("");
const { width } = useDisplay();
322
</script>
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<style scoped>
.title {
  height: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

@media screen and (min-width: 1537px) {
  .tabs {
    border-bottom: 2px solid #1f88e5;
    margin: 10px auto 20px;
    width: 100%;
  }
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
  .tabs {
    border-bottom: 2px solid #1f88e5;
    margin: 10px auto 40px;
    width: 100%;
  }
}
@media screen and (max-width: 1280px) {
  .tabs {
    border-bottom: 2px solid #1f88e5;
    margin: 10px auto 40px;
    width: 100%;
  }
}
/* .tabs {
  border-bottom: 2px solid #1f88e5;
} */

.active {
  background-color: #1086e8;
}

@media screen and (min-width: 1537px) {
  #image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 320px;
    margin: 10px auto 50px;
369
    width: 75%;
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
  }
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
  #image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 260px;
    margin: 10px auto 0px;
    width: 100%;
    padding: 0;
  }
}
@media screen and (max-width: 1280px) {
  #image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 260px;
    margin: 10px auto 0px;
    width: 100%;
    padding: 0;
  }
}
.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;
  }
}
@media screen and (max-width: 1280px) {
  .imageTotal {
    display: inline-block;
    margin: 0 5px;
    text-align: center;
    width: 200px;
  }
}
@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;
  }
}
@media screen and (max-width: 1280px) {
  .image-row img {
    width: 120px;
    height: 120px;
  }
}
@media screen and (min-width: 1537px) {
  .image-name {
    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 */
    margin-top: 5px;
    font-size: 16px;
    width: 180px;
    color: #555;
    text-align: center; /* Centers the text horizontally */
    margin-left: 50px;
  }
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
  .image-name {
    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 */
    margin-top: 5px;
    font-size: 16px;
    width: 180px;
    color: #555;
    text-align: center; /* Centers the text horizontally */
    margin-left: 10px;
  }
}
@media screen and (max-width: 1280px) {
  .image-name {
    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 */
    margin-top: 5px;
    font-size: 16px;
    width: 180px;
    color: #555;
    text-align: center; /* Centers the text horizontally */
    margin-left: 10px;
  }
}

button .recommendButton {
  margin: 0 0px;
  cursor: pointer;
}

.recommend-left-box {
}

@media screen and (max-width: 1280px) {
  .recommend-img-left {
    width: 26px;
    height: 27px;
    margin-bottom: 60px;
  }
}
.recommend-img-left {
  width: 26px;
  height: 27px;
  margin-right: 30px;
  margin-bottom: 60px;
}

.recommend-img-left:hover {
  cursor: pointer;
}
.recommend-right-box {
}

.recommend-img-right {
  width: 26px;
  height: 27px;
  margin-left: 30px;
  margin-bottom: 60px;
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
  .recommend-img-left {
    width: 26px;
    height: 27px;
    margin-right: 30px;
    margin-bottom: 60px;
  }
}
@media screen and (max-width: 1536px) and (min-width: 1281px) {
  .recommend-img-right {
    width: 26px;
    height: 27px;
    margin-left: 30px;
    margin-bottom: 60px;
  }
}
@media screen and (min-width: 1600px) {
  .recommend-img-left {
    width: 26px;
    height: 27px;
    margin-right: 70px;
    margin-bottom: 60px;
  }
}
@media screen and (min-width: 1600px) {
  .recommend-img-right {
    width: 26px;
    height: 27px;
    margin-left: 70px;
    margin-bottom: 60px;
  }
}

.recommend-img-right:hover {
  cursor: pointer;
}

.v-card {
  transition: all 0.3s ease-in-out;
}

.v-card-text {
  max-width: 100%; /* 确保文字宽度受限 */
}
.item-name {
  display: -webkit-box !important;
  -webkit-box-orient: vertical !important;
  -webkit-line-clamp: 3 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: normal !important;
  text-align: left;
  line-height: 1.5em;
  min-height: calc(3 * 1.5em); /* 强制未满三行时高度一致 */
}

#product-card .v-responsive.v-img {
  width: 274px !important; /* 设置宽度 */
  height: 274px !important; /* 设置高度 */
}

.clamp-text {
  display: -webkit-box; /* 使用弹性盒子 */
  -webkit-box-orient: vertical; /* 设置为垂直方向 */
  -webkit-line-clamp: 3; /* 限制最多显示3行 */
  overflow: hidden; /* 隐藏多余内容 */
  text-overflow: ellipsis; /* 添加省略号 */
  white-space: normal; /* 允许换行 */
  line-height: 1.5em; /* 设置每行的高度 */
  min-height: calc(3 * 1.5em); /* 确保最小高度为3行 */
}
</style>