@rxdrag/website-lib-core 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +1 -1
- package/package.json +11 -7
- package/src/component-logic/gsap.d.ts +4 -0
- package/src/component-logic/index.ts +8 -0
- package/src/component-logic/link-client.ts +33 -0
- package/src/component-logic/link.ts +50 -0
- package/src/component-logic/modal.ts +36 -0
- package/src/component-logic/motion.ts +272 -0
- package/src/component-logic/number.ts +45 -0
- package/src/component-logic/popover.ts +51 -0
- package/src/component-logic/tabs.ts +10 -0
- package/src/controller/AnimateController.ts +138 -0
- package/src/controller/AosController.ts +240 -0
- package/src/controller/FlipController.ts +339 -0
- package/src/controller/ModalController.ts +127 -0
- package/src/controller/NumberController.ts +161 -0
- package/src/controller/PageLoader.ts +163 -0
- package/src/controller/PopoverController.ts +116 -0
- package/src/controller/TabsController.ts +271 -0
- package/src/controller/applyAnimation.ts +86 -0
- package/src/controller/applyInitialState.ts +79 -0
- package/src/{scripts → controller}/consts.ts +0 -2
- package/src/controller/index.ts +9 -0
- package/src/controller/popup.ts +346 -0
- package/src/controller/utils.ts +48 -0
- package/src/entify/Entify.ts +354 -365
- package/src/entify/IEntify.ts +91 -0
- package/src/entify/index.ts +3 -2
- package/src/entify/lib/newQueryProductOptions.ts +2 -3
- package/src/entify/lib/newQueryProductsMediaOptions.ts +19 -18
- package/src/entify/lib/queryAllProducts.ts +11 -3
- package/src/entify/lib/queryFeaturedProducts.ts +3 -3
- package/src/entify/lib/queryLatestPosts.ts +2 -2
- package/src/entify/lib/queryOneTheme.ts +1 -1
- package/src/entify/lib/queryPostCategories.ts +3 -3
- package/src/entify/lib/queryPostSlugs.ts +2 -2
- package/src/entify/lib/queryPosts.ts +92 -92
- package/src/entify/lib/queryProductCategories.ts +3 -3
- package/src/entify/lib/queryProducts.ts +69 -69
- package/src/entify/lib/queryUserPosts.ts +2 -2
- package/src/entify/lib/searchProducts.ts +2 -2
- package/src/index.ts +3 -1
- package/src/lib/formatDate.ts +15 -0
- package/src/lib/index.ts +3 -0
- package/src/lib/pagination.ts +114 -0
- package/src/lib/utils.ts +119 -0
- package/src/motion/consts.ts +428 -598
- package/src/motion/convertToGsapVars.ts +102 -0
- package/src/motion/index.ts +5 -1
- package/src/motion/normalizeAnimation.ts +28 -0
- package/src/motion/normalizeAosAnimation.ts +22 -0
- package/src/motion/normalizePopupAnimation.ts +24 -0
- package/src/motion/types.ts +133 -46
- package/src/react/components/AttachmentIcon/index.tsx +53 -0
- package/src/react/components/ContactForm/index.tsx +341 -0
- package/src/react/components/Icon/index.tsx +10 -0
- package/src/react/components/Medias/index.tsx +347 -347
- package/src/react/components/ProductCard/ProductCta/index.tsx +7 -5
- package/src/react/components/RichTextOutline/index.tsx +76 -76
- package/src/react/components/Scroller.tsx +5 -1
- package/src/react/components/SearchInput.tsx +36 -34
- package/src/react/components/ToTop.tsx +63 -28
- package/src/react/components/index.ts +3 -1
- package/src/react/hooks/useScroll.ts +16 -10
- package/src/react/components/EnquiryForm/index.tsx +0 -334
- package/src/scripts/actions.ts +0 -304
- package/src/scripts/events.ts +0 -33
- package/src/scripts/index.ts +0 -3
- /package/src/react/components/{EnquiryForm → ContactForm}/Input.tsx +0 -0
- /package/src/react/components/{EnquiryForm → ContactForm}/Submit.tsx +0 -0
- /package/src/react/components/{EnquiryForm → ContactForm}/Textarea.tsx +0 -0
package/src/entify/Entify.ts
CHANGED
|
@@ -1,365 +1,354 @@
|
|
|
1
|
-
import { EnvVariables, TSize } from "./types";
|
|
2
|
-
import { queryOneTheme } from "./lib/queryOneTheme";
|
|
3
|
-
import {
|
|
4
|
-
ListConditions,
|
|
5
|
-
queryEntityList,
|
|
6
|
-
queryFeaturedProducts,
|
|
7
|
-
queryLangs,
|
|
8
|
-
queryLatestPosts,
|
|
9
|
-
queryOnePostBySlug,
|
|
10
|
-
queryOnePostCategoryBySlug,
|
|
11
|
-
queryOneProductBySlug,
|
|
12
|
-
queryOneProductCategoryBySlug,
|
|
13
|
-
queryOneUser,
|
|
14
|
-
queryPostCategories,
|
|
15
|
-
queryPosts,
|
|
16
|
-
queryProductCategories,
|
|
17
|
-
queryProducts,
|
|
18
|
-
queryUserPosts,
|
|
19
|
-
searchProducts,
|
|
20
|
-
} from "./lib";
|
|
21
|
-
import { IQueryOptions } from "@rxdrag/entify-hooks";
|
|
22
|
-
import { queryAllProducts } from "./lib/queryAllProducts";
|
|
23
|
-
import { queryPostSlugs } from "./lib/queryPostSlugs";
|
|
24
|
-
import { queryUserIds } from "./lib/queryUserIds";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return await
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public async
|
|
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
|
-
public async
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
public async
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return (await
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
public async
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
currentPage,
|
|
356
|
-
totalPages,
|
|
357
|
-
pageSize,
|
|
358
|
-
totalItems,
|
|
359
|
-
},
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return paths;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
1
|
+
import { EnvVariables, TSize } from "./types";
|
|
2
|
+
import { queryOneTheme } from "./lib/queryOneTheme";
|
|
3
|
+
import {
|
|
4
|
+
ListConditions,
|
|
5
|
+
queryEntityList,
|
|
6
|
+
queryFeaturedProducts,
|
|
7
|
+
queryLangs,
|
|
8
|
+
queryLatestPosts,
|
|
9
|
+
queryOnePostBySlug,
|
|
10
|
+
queryOnePostCategoryBySlug,
|
|
11
|
+
queryOneProductBySlug,
|
|
12
|
+
queryOneProductCategoryBySlug,
|
|
13
|
+
queryOneUser,
|
|
14
|
+
queryPostCategories,
|
|
15
|
+
queryPosts,
|
|
16
|
+
queryProductCategories,
|
|
17
|
+
queryProducts,
|
|
18
|
+
queryUserPosts,
|
|
19
|
+
searchProducts,
|
|
20
|
+
} from "./lib";
|
|
21
|
+
import { IQueryOptions } from "@rxdrag/entify-hooks";
|
|
22
|
+
import { queryAllProducts } from "./lib/queryAllProducts";
|
|
23
|
+
import { queryPostSlugs } from "./lib/queryPostSlugs";
|
|
24
|
+
import { queryUserIds } from "./lib/queryUserIds";
|
|
25
|
+
import { IEntify, PostPatinateOptions, PostsOptions } from "./IEntify";
|
|
26
|
+
|
|
27
|
+
export class Entify implements IEntify {
|
|
28
|
+
private static instance: Entify | null = null;
|
|
29
|
+
|
|
30
|
+
private constructor(protected envVariables: EnvVariables) {}
|
|
31
|
+
|
|
32
|
+
public static getInstance(envVariables: EnvVariables): Entify {
|
|
33
|
+
if (!Entify.instance) {
|
|
34
|
+
Entify.instance = new Entify(envVariables);
|
|
35
|
+
}
|
|
36
|
+
return Entify.instance;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async queryEntityList<
|
|
40
|
+
T,
|
|
41
|
+
WhereExp = unknown,
|
|
42
|
+
OrderBy = unknown,
|
|
43
|
+
DistinctExp = unknown
|
|
44
|
+
>(options: IQueryOptions<T, WhereExp, OrderBy, DistinctExp>) {
|
|
45
|
+
return await queryEntityList<T, WhereExp, OrderBy, DistinctExp>(
|
|
46
|
+
options,
|
|
47
|
+
this.envVariables
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async getTheme() {
|
|
52
|
+
return await queryOneTheme(this.envVariables);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async getLangs() {
|
|
56
|
+
return (await queryLangs(this.envVariables))?.items;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public async getFeaturedProducts(count?: number) {
|
|
60
|
+
return await queryFeaturedProducts(count, this.envVariables);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async getLatestPosts(count?: number) {
|
|
64
|
+
return await queryLatestPosts(count, this.envVariables);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async getPosts(options: PostsOptions) {
|
|
68
|
+
const { category, coverSize, page, pageSize } = options;
|
|
69
|
+
const conditions: ListConditions = { category, page, pageSize };
|
|
70
|
+
const result = await queryPosts(conditions, coverSize, this.envVariables);
|
|
71
|
+
return result?.items;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public async getPostListPaths(options: PostPatinateOptions) {
|
|
75
|
+
const { category, pageSize } = options;
|
|
76
|
+
// 获取总文章数据,只需要获取总数
|
|
77
|
+
// TODO: 目前数据查询有点重复,后续要结合后端优化
|
|
78
|
+
const postsData = await queryPosts(
|
|
79
|
+
{ category, page: 1, pageSize: 10 },
|
|
80
|
+
undefined,
|
|
81
|
+
this.envVariables
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const totalItems = postsData?.total ?? 0;
|
|
85
|
+
|
|
86
|
+
return this.createPagination(totalItems, pageSize);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async getPostPaths() {
|
|
90
|
+
// 获取所有文章的 slug
|
|
91
|
+
const slugs = await this.getPostSlugs();
|
|
92
|
+
|
|
93
|
+
// 为每个 slug 创建路径
|
|
94
|
+
return slugs.map((slug) => ({
|
|
95
|
+
params: { slug },
|
|
96
|
+
props: { slug },
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public async getPostBySlug(slug: string, coverSize: TSize | undefined) {
|
|
101
|
+
return await queryOnePostBySlug(slug, coverSize, this.envVariables);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 获取所有文章的 slug,用于生成静态页面
|
|
106
|
+
* 对于大量文章,这个方法会进行优化,只获取 slug 字段
|
|
107
|
+
*/
|
|
108
|
+
public async getPostSlugs() {
|
|
109
|
+
// 只获取 slug 字段,减少数据传输量
|
|
110
|
+
const result = await queryPostSlugs(this.envVariables);
|
|
111
|
+
|
|
112
|
+
return result?.items?.map((post) => post.slug) || [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public async getPostCategories() {
|
|
116
|
+
return (await queryPostCategories(this.envVariables))?.items;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public async getPostCategoryBySlug(slug: string) {
|
|
120
|
+
return await queryOnePostCategoryBySlug(slug, this.envVariables);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public async getProducts(
|
|
124
|
+
conditions: ListConditions,
|
|
125
|
+
imageSize: TSize | undefined
|
|
126
|
+
) {
|
|
127
|
+
return (await queryProducts(conditions, imageSize, this.envVariables))
|
|
128
|
+
?.items;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public async getProductListPaths(options: {
|
|
132
|
+
category?: string;
|
|
133
|
+
pageSize: number;
|
|
134
|
+
}) {
|
|
135
|
+
const { category, pageSize } = options;
|
|
136
|
+
// 获取总产品数据,只需要获取总数
|
|
137
|
+
const productsData = await queryProducts(
|
|
138
|
+
{ category, page: 1, pageSize: 10 },
|
|
139
|
+
undefined,
|
|
140
|
+
this.envVariables
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const totalItems = productsData?.total ?? 0;
|
|
144
|
+
|
|
145
|
+
return this.createPagination(totalItems, pageSize);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public async getCategoredProductListPaths() {
|
|
149
|
+
// 获取所有产品分类
|
|
150
|
+
const categories = await this.getProductCategories();
|
|
151
|
+
|
|
152
|
+
// 为每个分类生成路径
|
|
153
|
+
const paths = [];
|
|
154
|
+
|
|
155
|
+
// 如果没有分类,至少创建一个默认路径
|
|
156
|
+
if (!categories || categories.length === 0) {
|
|
157
|
+
paths.push({
|
|
158
|
+
params: { slug: "default", page: "1" },
|
|
159
|
+
props: {
|
|
160
|
+
currentPage: 1,
|
|
161
|
+
totalPages: 1,
|
|
162
|
+
pageSize: 12,
|
|
163
|
+
totalItems: 0,
|
|
164
|
+
slug: "default",
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
return paths;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const category of categories) {
|
|
171
|
+
// 跳过没有 slug 的分类
|
|
172
|
+
if (!category.slug) continue;
|
|
173
|
+
|
|
174
|
+
// 获取该分类下的分页路径
|
|
175
|
+
const categoryPaths = await this.getProductListPaths({
|
|
176
|
+
pageSize: 12,
|
|
177
|
+
category: category.slug,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// 如果该分类没有产品,至少创建一个第一页
|
|
181
|
+
if (categoryPaths.length === 0) {
|
|
182
|
+
paths.push({
|
|
183
|
+
params: { slug: String(category.slug), page: "1" },
|
|
184
|
+
props: {
|
|
185
|
+
currentPage: 1,
|
|
186
|
+
totalPages: 1,
|
|
187
|
+
pageSize: 12,
|
|
188
|
+
totalItems: 0,
|
|
189
|
+
slug: String(category.slug),
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// 为每个分页路径添加分类 slug
|
|
196
|
+
for (const path of categoryPaths) {
|
|
197
|
+
paths.push({
|
|
198
|
+
params: { ...path.params, slug: String(category.slug) },
|
|
199
|
+
props: { ...path.props, slug: String(category.slug) },
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return paths;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* TODO:未调试
|
|
209
|
+
* 获取所有文章分类的分页路径
|
|
210
|
+
* 用于生成静态页面
|
|
211
|
+
* @returns 所有文章分类的分页路径
|
|
212
|
+
*/
|
|
213
|
+
public async getCategoredPostListPaths() {
|
|
214
|
+
// 获取所有文章分类
|
|
215
|
+
const categories = await this.getPostCategories();
|
|
216
|
+
|
|
217
|
+
// 为每个分类生成路径
|
|
218
|
+
const paths = [];
|
|
219
|
+
|
|
220
|
+
// 如果没有分类,至少创建一个默认路径
|
|
221
|
+
if (!categories || categories.length === 0) {
|
|
222
|
+
paths.push({
|
|
223
|
+
params: { slug: "default", page: "1" },
|
|
224
|
+
props: {
|
|
225
|
+
currentPage: 1,
|
|
226
|
+
totalPages: 1,
|
|
227
|
+
pageSize: 10,
|
|
228
|
+
totalItems: 0,
|
|
229
|
+
slug: "default",
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
return paths;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
for (const category of categories) {
|
|
236
|
+
// 跳过没有 slug 的分类
|
|
237
|
+
if (!category.slug) continue;
|
|
238
|
+
|
|
239
|
+
// 获取该分类下的分页路径
|
|
240
|
+
const categoryPaths = await this.getPostListPaths({
|
|
241
|
+
pageSize: 10,
|
|
242
|
+
category: category.slug,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// 如果该分类没有文章,至少创建一个第一页
|
|
246
|
+
if (categoryPaths.length === 0) {
|
|
247
|
+
paths.push({
|
|
248
|
+
params: { slug: String(category.slug), page: "1" },
|
|
249
|
+
props: {
|
|
250
|
+
currentPage: 1,
|
|
251
|
+
totalPages: 1,
|
|
252
|
+
pageSize: 10,
|
|
253
|
+
totalItems: 0,
|
|
254
|
+
slug: String(category.slug),
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 为每个分页路径添加分类 slug
|
|
261
|
+
for (const path of categoryPaths) {
|
|
262
|
+
paths.push({
|
|
263
|
+
params: { ...path.params, slug: String(category.slug) },
|
|
264
|
+
props: { ...path.props, slug: String(category.slug) },
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return paths;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public async getProductBySlug(slug: string, imageSize: TSize | undefined) {
|
|
273
|
+
return await queryOneProductBySlug(slug, imageSize, this.envVariables);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public async getProductPaths() {
|
|
277
|
+
// 获取所有产品的 slug
|
|
278
|
+
const slugs = await this.getProductSlugs();
|
|
279
|
+
|
|
280
|
+
// 为每个 slug 创建路径
|
|
281
|
+
return slugs.map((slug) => ({
|
|
282
|
+
params: { slug },
|
|
283
|
+
props: { slug },
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 获取所有产品的 slug,用于生成静态页面
|
|
289
|
+
* 对于大量产品,这个方法会进行优化,只获取 slug 字段
|
|
290
|
+
*/
|
|
291
|
+
public async getProductSlugs() {
|
|
292
|
+
// 只获取 slug 字段,减少数据传输量
|
|
293
|
+
const result = await queryAllProducts(this.envVariables);
|
|
294
|
+
return result?.items?.map((product) => product.slug) || [];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public async getProductIds() {
|
|
298
|
+
const result = await queryAllProducts(this.envVariables);
|
|
299
|
+
return result?.items?.map((product) => product.id) || [];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public async getProductCategories() {
|
|
303
|
+
return (await queryProductCategories(this.envVariables))?.items;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
public async getProductCategoryBySlug(slug: string) {
|
|
307
|
+
return await queryOneProductCategoryBySlug(slug, this.envVariables);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public async getOneUser(id: string) {
|
|
311
|
+
return await queryOneUser(id, this.envVariables);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public async getUserPosts(userId: string) {
|
|
315
|
+
return (await queryUserPosts({ userId }, this.envVariables))?.items;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
public async searchProducts(keyword: string) {
|
|
319
|
+
return await searchProducts(keyword, this.envVariables);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
public async getUserPaths() {
|
|
323
|
+
const result = await queryUserIds(this.envVariables);
|
|
324
|
+
return (
|
|
325
|
+
result?.items?.map((user) => ({
|
|
326
|
+
params: { id: user.id },
|
|
327
|
+
props: { id: user.id },
|
|
328
|
+
})) || []
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public createPagination(totalItems: number, pageSize: number) {
|
|
333
|
+
const totalPages = Math.max(1, Math.ceil(totalItems / pageSize));
|
|
334
|
+
|
|
335
|
+
// 为每个页面创建路径和获取对应的文章数据
|
|
336
|
+
const paths = [];
|
|
337
|
+
|
|
338
|
+
for (let i = 0; i < totalPages; i++) {
|
|
339
|
+
const currentPage = i + 1;
|
|
340
|
+
|
|
341
|
+
paths.push({
|
|
342
|
+
params: { page: String(currentPage) },
|
|
343
|
+
props: {
|
|
344
|
+
currentPage,
|
|
345
|
+
totalPages,
|
|
346
|
+
pageSize,
|
|
347
|
+
totalItems,
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return paths;
|
|
353
|
+
}
|
|
354
|
+
}
|