Commit d1d75b795aac74e9cd58ed7b9792e73cae1ff5c4
Merge remote-tracking branch 'origin/by'
# Conflicts: # nuxt.config.ts
Showing
2 changed files
with
174 additions
and
0 deletions
pages/productList.vue
0 → 100644
1 | +<template> | |
2 | + <div class="tw-m-auto tw-pb-[64px]" style="margin-bottom: 0px"> | |
3 | + <CategoryList v-if="categoryStore.categoryVisible && !isMobile()" /> | |
4 | + <MobileCategoryList v-if="categoryStore.categoryVisible && isMobile()" /> | |
5 | + <v-container> | |
6 | + <v-row align="center"> | |
7 | + <v-col> | |
8 | + <v-text-field | |
9 | + v-model="keyword" | |
10 | + style="max-width: 500px" | |
11 | + label="Keyword" | |
12 | + > | |
13 | + </v-text-field> | |
14 | + </v-col> | |
15 | + </v-row> | |
16 | + <v-row align="center"> | |
17 | + <v-col> | |
18 | + <v-text-field | |
19 | + v-model="secret" | |
20 | + style="max-width: 500px" | |
21 | + label="Secret" | |
22 | + ></v-text-field> | |
23 | + </v-col> | |
24 | + <v-col cols=""> | |
25 | + <v-btn @click="handleProduce">生成</v-btn> | |
26 | + </v-col> | |
27 | + </v-row> | |
28 | + </v-container> | |
29 | + </div> | |
30 | +</template> | |
31 | + | |
32 | +<script setup lang="ts"> | |
33 | +import { isMobile, isEqual } from "~/utils"; | |
34 | +import { useProductListStore } from "~/stores/product_list"; | |
35 | +import { useCategoryStore } from "~/stores/category"; | |
36 | +import CategoryList from "~/components/CategoryList.vue"; | |
37 | +import MobileCategoryList from "~/components/MobileCategoryList.vue"; | |
38 | +import { watchEffect, computed, ref } from "vue"; | |
39 | + | |
40 | +const productStore = useProductListStore(); | |
41 | +const categoryStore = useCategoryStore(); | |
42 | +const loading = ref(false); | |
43 | +const route = useRoute(); // 获取路由信息 | |
44 | +const keyword = ref(""); | |
45 | +const rootProductCategoryName = ref(""); | |
46 | +const productCategoryName = ref(""); | |
47 | +const productFunctionName = ref(""); | |
48 | +const secret = ref(""); | |
49 | + | |
50 | +useHead({ | |
51 | + title: "canrud", | |
52 | + meta: [ | |
53 | + { | |
54 | + name: "title", | |
55 | + content: | |
56 | + "科路得,助您科研之路势在必得。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!", | |
57 | + }, | |
58 | + { | |
59 | + name: "keywords", | |
60 | + content: | |
61 | + "科路得,canrd,canrud,Energy Storage Research,Lithium Batteries Research,Material Reagents,Lab Device,Customized Battery,Testing,Pack", | |
62 | + }, | |
63 | + { | |
64 | + name: "description", | |
65 | + content: | |
66 | + "科路得,助您科研之路势在必得。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.", | |
67 | + }, | |
68 | + ], | |
69 | +}); | |
70 | + | |
71 | +const loadProducts = async () => { | |
72 | + let params: any = { | |
73 | + pageNo: productStore.pageNo, | |
74 | + pageSize: 20, | |
75 | + }; | |
76 | + | |
77 | + loading.value = true; | |
78 | + if (productStore.keyword && !isEqual(productStore.params, params)) { | |
79 | + params.keyword = productStore.keyword; | |
80 | + productStore.updateParams(params); | |
81 | + await productStore.getList(params); | |
82 | + loading.value = false; | |
83 | + return; | |
84 | + } | |
85 | + | |
86 | + params.productCategoryId = categoryStore.selectedSubCategory; | |
87 | + // productCategoryId: '78b86c6e917841cf9a292234f2805e24', | |
88 | + | |
89 | + if (categoryStore.selectedFuncCategory) { | |
90 | + params.productFunctionId = categoryStore.selectedFuncCategory; | |
91 | + } | |
92 | + | |
93 | + if ( | |
94 | + categoryStore.selectedSubCategory && | |
95 | + !isEqual(productStore.params, params) | |
96 | + ) { | |
97 | + productStore.updateParams(params); | |
98 | + | |
99 | + await productStore.getList(params); | |
100 | + } | |
101 | + loading.value = false; | |
102 | +}; | |
103 | + | |
104 | +const handleProduce = async () => { | |
105 | + try { | |
106 | + let { data: resUrl } = await useAsyncData( | |
107 | + "detail", | |
108 | + () => | |
109 | + $fetch("/shop/product/generateList", { | |
110 | + method: "GET", | |
111 | + params: { | |
112 | + pageNo: 1, | |
113 | + pageSize: 20, | |
114 | + keyword: keyword.value, | |
115 | + rootProductCategoryName: rootProductCategoryName.value, | |
116 | + productCategoryName: productCategoryName.value, | |
117 | + productFunctionName: productFunctionName.value, | |
118 | + secret: secret.value, | |
119 | + }, | |
120 | + }), | |
121 | + { | |
122 | + server: true, // 仅在服务器端获取数据 | |
123 | + } | |
124 | + ); | |
125 | + const productId = resUrl.value.data; | |
126 | + if (productId) { | |
127 | + window.location.href = `https://www.canrud.com/products/${productId}`; | |
128 | + } else { | |
129 | + console.error("No product ID found in response."); | |
130 | + } | |
131 | + } catch (error) { | |
132 | + console.error("Error fetching data:", error); | |
133 | + } | |
134 | +}; | |
135 | + | |
136 | +watchEffect(async () => { | |
137 | + if (route.query.categories) { | |
138 | + const categories = route.query.categories.split(","); | |
139 | + rootProductCategoryName.value = categories[0].trim(); // 取第一个值 | |
140 | + productCategoryName.value = categories[1] ? categories[1].trim() : ""; // 取第二个值(如果存在) | |
141 | + } else { | |
142 | + rootProductCategoryName.value = ""; | |
143 | + productCategoryName.value = ""; | |
144 | + } | |
145 | + if (route.query.function) { | |
146 | + productFunctionName.value = route.query.function; | |
147 | + } else { | |
148 | + productFunctionName.value = ""; | |
149 | + } | |
150 | + // if (route.query.keyword !== undefined) { | |
151 | + // productStore.keyword = route.query.keyword; | |
152 | + // } | |
153 | + // loadProducts(); | |
154 | +}); | |
155 | + | |
156 | +const length = computed(() => | |
157 | + productStore.total ? Math.ceil(productStore.total / productStore.pageSize) : 0 | |
158 | +); | |
159 | +</script> | |
160 | + | |
161 | +<style scoped> | |
162 | +.title { | |
163 | + height: 60px; | |
164 | + overflow: hidden; | |
165 | + text-overflow: ellipsis; | |
166 | + display: -webkit-box; | |
167 | + -webkit-line-clamp: 2; | |
168 | + -webkit-box-orient: vertical; | |
169 | +} | |
170 | +</style> | ... | ... |
pages/products/index.vue
... | ... | @@ -41,6 +41,9 @@ |
41 | 41 | </v-expand-transition> --> |
42 | 42 | </v-img> |
43 | 43 | <v-card-text class="tw-text-left font-weight-medium title"> |
44 | + <h3 style="color: red" v-if="item.price"> | |
45 | + ${{ item.price }} | |
46 | + </h3> | |
44 | 47 | <h4>{{ item.name }}</h4> |
45 | 48 | </v-card-text> |
46 | 49 | </v-card> |
... | ... | @@ -106,6 +109,7 @@ useHead({ |
106 | 109 | }); |
107 | 110 | |
108 | 111 | const loadProducts = async () => { |
112 | + console.log(productStore, "5656productStore"); | |
109 | 113 | let params: any = { |
110 | 114 | pageNo: productStore.pageNo, |
111 | 115 | pageSize: 20, | ... | ... |