@rxdrag/website-lib-core 0.0.127 → 0.0.128
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/README.md +1 -1
- package/index.ts +1 -1
- package/package.json +4 -4
- package/src/astro/animation.ts +146 -146
- package/src/astro/background.ts +82 -86
- package/src/astro/base.ts +7 -0
- package/src/astro/business.ts +13 -0
- package/src/astro/grid/consts.ts +80 -80
- package/src/astro/grid/index.ts +2 -2
- package/src/astro/grid/types.ts +35 -35
- package/src/astro/image.ts +239 -239
- package/src/astro/index.ts +12 -10
- package/src/astro/link.ts +20 -21
- package/src/astro/media.ts +123 -123
- package/src/astro/nav.ts +13 -13
- package/src/astro/section/index.ts +7 -12
- package/src/component-logic/index.ts +1 -1
- package/src/component-logic/link-client.ts +32 -32
- package/src/component-logic/link.ts +61 -61
- package/src/design-tokens.ts +160 -160
- package/src/entify/Entify.ts +533 -530
- package/src/entify/IEntify.ts +151 -177
- package/src/entify/index.ts +4 -4
- package/src/entify/lib/collectCategoryIds.ts +20 -20
- package/src/entify/lib/fulltextSearch.ts +63 -62
- package/src/entify/lib/langFields.ts +14 -14
- package/src/entify/lib/listToTree.ts +23 -23
- package/src/entify/lib/newAvatarQueryOptions.ts +4 -4
- package/src/entify/lib/newOgImageQueryOptions.ts +5 -5
- package/src/entify/lib/newQueryPostOptions.ts +42 -45
- package/src/entify/lib/newQueryProductOptions.ts +96 -98
- package/src/entify/lib/newQueryProductsMediaOptions.ts +28 -28
- package/src/entify/lib/queryAllProducts.ts +40 -40
- package/src/entify/lib/queryBulletin.ts +28 -16
- package/src/entify/lib/queryEntityList.ts +41 -41
- package/src/entify/lib/queryFeaturedProducts.ts +69 -68
- package/src/entify/lib/queryLangs.ts +36 -60
- package/src/entify/lib/queryLatestPosts.ts +92 -91
- package/src/entify/lib/queryOneEntity.ts +63 -63
- package/src/entify/lib/queryOneMedia.ts +27 -27
- package/src/entify/lib/queryOnePostById.ts +21 -21
- package/src/entify/lib/queryOnePostBySlug.ts +40 -39
- package/src/entify/lib/queryOnePostCategoryBySlug.ts +35 -35
- package/src/entify/lib/queryOneProductById.ts +20 -20
- package/src/entify/lib/queryOneProductBySlug.ts +53 -52
- package/src/entify/lib/queryOneProductCategoryBySlug.ts +50 -49
- package/src/entify/lib/queryOneTheme.ts +54 -72
- package/src/entify/lib/queryOneUser.ts +38 -38
- package/src/entify/lib/queryPostCategories.ts +67 -67
- package/src/entify/lib/queryPostSlugs.ts +37 -37
- package/src/entify/lib/queryPosts.ts +175 -174
- package/src/entify/lib/queryProductCategories.ts +59 -59
- package/src/entify/lib/queryProducts.ts +145 -144
- package/src/entify/lib/queryProductsInMenu.ts +45 -45
- package/src/entify/lib/queryTagCategories.ts +58 -58
- package/src/entify/lib/queryTags.ts +57 -57
- package/src/entify/lib/queryUserIds.ts +24 -24
- package/src/entify/lib/queryUserPosts.ts +80 -79
- package/src/entify/lib/queryWebSiteSettings.ts +28 -28
- package/src/entify/lib/queryWebsite.ts +43 -43
- package/src/entify/lib/sendEmail.ts +7 -7
- package/src/entify/lib/toQueryOptions.ts +19 -19
- package/src/entify/lib/upsertEntity.ts +8 -8
- package/src/entify/types/index.ts +1 -1
- package/src/entify/types/utils.ts +11 -6
- package/src/entify/types/variables.ts +5 -6
- package/src/entify/view-model/funcs.ts +230 -230
- package/src/entify/view-model/index.ts +1 -1
- package/src/entify/view-model/models.ts +135 -135
- package/src/global.d.ts +7 -7
- package/src/index.ts +8 -8
- package/src/lib/formatDate.ts +15 -15
- package/src/lib/index.ts +3 -3
- package/src/lib/pagination.ts +114 -114
- package/src/lib/utils.ts +135 -135
- package/src/react/components/Analytics/eventHandlers.ts +173 -173
- package/src/react/components/Analytics/index.tsx +21 -21
- package/src/react/components/Analytics/singleton.ts +214 -214
- package/src/react/components/Analytics/tracking.ts +221 -221
- package/src/react/components/Analytics/types.ts +60 -60
- package/src/react/components/Analytics/utils.ts +95 -95
- package/src/react/components/AttachmentIcon/index.tsx +53 -53
- package/src/react/components/BackgroundHlsVideoPlayer.tsx +97 -97
- package/src/react/components/BackgroundVideoPlayer.tsx +32 -32
- package/src/react/components/Bulletin.tsx +30 -30
- package/src/react/components/ContactForm/ContactForm.tsx +289 -289
- package/src/react/components/ContactForm/Input.tsx +48 -48
- package/src/react/components/ContactForm/Input2.tsx +59 -59
- package/src/react/components/ContactForm/Submit.tsx +48 -48
- package/src/react/components/ContactForm/TelInput.tsx +215 -215
- package/src/react/components/ContactForm/Textarea.tsx +48 -48
- package/src/react/components/ContactForm/Textarea2.tsx +89 -89
- package/src/react/components/ContactForm/funcs.ts +64 -64
- package/src/react/components/ContactForm/index.ts +7 -7
- package/src/react/components/ContactForm/types.ts +68 -68
- package/src/react/components/GoogleConsent/CookieItemPanel.tsx +80 -80
- package/src/react/components/GoogleConsent/CumtomizedModal.tsx +148 -148
- package/src/react/components/GoogleConsent/GoogleConsent.tsx +100 -100
- package/src/react/components/GoogleConsent/gtags.ts +67 -67
- package/src/react/components/GoogleConsent/index.ts +2 -2
- package/src/react/components/GoogleConsent/types.ts +18 -18
- package/src/react/components/GoogleConsent//345/217/202/350/200/203.md +4 -4
- package/src/react/components/Icon/index.tsx +19 -19
- package/src/react/components/Medias/MainMedia.tsx +257 -257
- package/src/react/components/Medias/Thumbnail.tsx +62 -62
- package/src/react/components/Medias/VideoPlayer.tsx +114 -114
- package/src/react/components/Medias/index.tsx +271 -271
- package/src/react/components/ProductCard/ProductCard.tsx +24 -24
- package/src/react/components/ProductCard/ProductCta/index.tsx +28 -28
- package/src/react/components/ProductCard/ProductCta/style.css +3 -3
- package/src/react/components/ProductCard/ProductDescription/index.tsx +12 -12
- package/src/react/components/ProductCard/ProductDescription/style.css +5 -5
- package/src/react/components/ProductCard/ProductMedia/index.tsx +35 -35
- package/src/react/components/ProductCard/ProductMedia/style.css +5 -5
- package/src/react/components/ProductCard/ProductTitle/index.tsx +7 -7
- package/src/react/components/ProductCard/ProductTitle/style.css +3 -3
- package/src/react/components/ProductCard/ProductView.tsx +36 -36
- package/src/react/components/ProductCard/index.ts +4 -4
- package/src/react/components/ProductCard/useQueryProduct.ts +32 -32
- package/src/react/components/ReactModalTrigger.tsx +28 -28
- package/src/react/components/ReactVideoPlayer.tsx +29 -52
- package/src/react/components/RichTextOutline/index.tsx +75 -75
- package/src/react/components/RichTextOutline/useAnchorScroll.ts +23 -23
- package/src/react/components/Scroller.tsx +39 -39
- package/src/react/components/SearchInput.tsx +21 -21
- package/src/react/components/Share/index.tsx +86 -86
- package/src/react/components/Share/socials.tsx +79 -77
- package/src/react/components/Share//350/265/204/346/226/231.md +7 -7
- package/src/react/components/ToTop.tsx +72 -72
- package/src/react/components/VideoPlayIcon.tsx +43 -0
- package/src/react/components/all.ts +38 -38
- package/src/react/components/index.ts +16 -16
- package/src/robots.ts +4 -4
- package/src/entify/lib/newPageMetaOptions.ts +0 -18
- package/src/entify/lib/newQueryPageOptions.ts +0 -14
- package/src/entify/lib/queryOneIcon.ts +0 -27
- package/src/entify/lib/queryPageBySlug.ts +0 -43
- package/src/entify/lib/queryPageByType.ts +0 -44
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import { Media, PageMeta } from "@rxdrag/rxcms-models";
|
|
2
|
-
|
|
3
|
-
export type TMedia = Media & {
|
|
4
|
-
alt?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export type TProductCategory = {
|
|
8
|
-
id?: string | null;
|
|
9
|
-
slug?: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
children?: TProductCategory[];
|
|
12
|
-
media?: TMedia;
|
|
13
|
-
parent?: TProductCategory;
|
|
14
|
-
products?: TProduct[];
|
|
15
|
-
description?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type TProduct = {
|
|
19
|
-
id?: string | null;
|
|
20
|
-
slug?: string;
|
|
21
|
-
title?: string;
|
|
22
|
-
shortTitle?: string;
|
|
23
|
-
description?: string;
|
|
24
|
-
features?: string;
|
|
25
|
-
medias?: TMedia[];
|
|
26
|
-
//从头medias中获取第一个不是视频的图片
|
|
27
|
-
cover?: Media;
|
|
28
|
-
content?: string;
|
|
29
|
-
content2?: string;
|
|
30
|
-
content3?: string;
|
|
31
|
-
extends?: object;
|
|
32
|
-
publishedAt?: Date;
|
|
33
|
-
createdAt?: Date;
|
|
34
|
-
updatedAt?: Date;
|
|
35
|
-
category?: TProductCategory;
|
|
36
|
-
related?: TProduct[];
|
|
37
|
-
attachments?: Media[];
|
|
38
|
-
meta?: PageMeta;
|
|
39
|
-
//todo:目前只有富文本编辑器用
|
|
40
|
-
coverUrl?: string;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export type TPostCategory = {
|
|
44
|
-
id?: string | null;
|
|
45
|
-
slug?: string;
|
|
46
|
-
name?: string;
|
|
47
|
-
children?: TProductCategory[];
|
|
48
|
-
media?: Media;
|
|
49
|
-
parent?: TProductCategory;
|
|
50
|
-
posts?: TPost[];
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type TTagCategory = {
|
|
54
|
-
id?: string | null;
|
|
55
|
-
name?: string;
|
|
56
|
-
children?: TTagCategory[];
|
|
57
|
-
parent?: TTagCategory;
|
|
58
|
-
tags?: TTag[];
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export type TTag = {
|
|
62
|
-
id?: string | null;
|
|
63
|
-
name?: string;
|
|
64
|
-
color?: string;
|
|
65
|
-
category?: TTagCategory;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type TUser = {
|
|
69
|
-
id?: string | null;
|
|
70
|
-
name?: string;
|
|
71
|
-
avatar?: Media;
|
|
72
|
-
position?: string;
|
|
73
|
-
profile?: string;
|
|
74
|
-
email?: string;
|
|
75
|
-
tel?: string;
|
|
76
|
-
mobile?: string;
|
|
77
|
-
linkedin?: string;
|
|
78
|
-
facebook?: string;
|
|
79
|
-
twitter?: string;
|
|
80
|
-
instagram?: string;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type TPost = {
|
|
84
|
-
id?: string | null;
|
|
85
|
-
slug?: string;
|
|
86
|
-
title?: string;
|
|
87
|
-
description?: string;
|
|
88
|
-
cover?: Media;
|
|
89
|
-
content?: string;
|
|
90
|
-
extends?: object;
|
|
91
|
-
publishedAt?: Date;
|
|
92
|
-
createdAt?: Date;
|
|
93
|
-
updatedAt?: Date;
|
|
94
|
-
category?: TPostCategory;
|
|
95
|
-
author?: TUser;
|
|
96
|
-
meta?: PageMeta;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export type TWebsiteSettings = {
|
|
100
|
-
id?: string | null;
|
|
101
|
-
contact?: string;
|
|
102
|
-
contactAvatar?: Media;
|
|
103
|
-
address?: string;
|
|
104
|
-
email?: string;
|
|
105
|
-
tel?: string;
|
|
106
|
-
mobile?: string;
|
|
107
|
-
//以下字段 暂时用不上,预留
|
|
108
|
-
linkedin?: string;
|
|
109
|
-
facebook?: string;
|
|
110
|
-
twitter?: string;
|
|
111
|
-
instagram?: string;
|
|
112
|
-
websiteName?: string;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export type TBreadcrumbItem = {
|
|
116
|
-
title: string;
|
|
117
|
-
href?: string;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export type TPagination = {
|
|
121
|
-
urlPrefix?: string;
|
|
122
|
-
current?: number;
|
|
123
|
-
total?: number;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export const entityMaps: Record<string, string> = {
|
|
127
|
-
ProductCategory: "TProductCategory",
|
|
128
|
-
Product: "TProduct",
|
|
129
|
-
Post: "TPost",
|
|
130
|
-
PostCategory: "TPostCategory",
|
|
131
|
-
TagCategory: "TTagCategory",
|
|
132
|
-
Tag: "TTag",
|
|
133
|
-
User: "TUser",
|
|
134
|
-
WebsiteSettings: "TWebsiteSettings",
|
|
135
|
-
};
|
|
1
|
+
import { Media, PageMeta } from "@rxdrag/rxcms-models";
|
|
2
|
+
|
|
3
|
+
export type TMedia = Media & {
|
|
4
|
+
alt?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type TProductCategory = {
|
|
8
|
+
id?: string | null;
|
|
9
|
+
slug?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
children?: TProductCategory[];
|
|
12
|
+
media?: TMedia;
|
|
13
|
+
parent?: TProductCategory;
|
|
14
|
+
products?: TProduct[];
|
|
15
|
+
description?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type TProduct = {
|
|
19
|
+
id?: string | null;
|
|
20
|
+
slug?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
shortTitle?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
features?: string;
|
|
25
|
+
medias?: TMedia[];
|
|
26
|
+
//从头medias中获取第一个不是视频的图片
|
|
27
|
+
cover?: Media;
|
|
28
|
+
content?: string;
|
|
29
|
+
content2?: string;
|
|
30
|
+
content3?: string;
|
|
31
|
+
extends?: object;
|
|
32
|
+
publishedAt?: Date;
|
|
33
|
+
createdAt?: Date;
|
|
34
|
+
updatedAt?: Date;
|
|
35
|
+
category?: TProductCategory;
|
|
36
|
+
related?: TProduct[];
|
|
37
|
+
attachments?: Media[];
|
|
38
|
+
meta?: PageMeta;
|
|
39
|
+
//todo:目前只有富文本编辑器用
|
|
40
|
+
coverUrl?: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type TPostCategory = {
|
|
44
|
+
id?: string | null;
|
|
45
|
+
slug?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
children?: TProductCategory[];
|
|
48
|
+
media?: Media;
|
|
49
|
+
parent?: TProductCategory;
|
|
50
|
+
posts?: TPost[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type TTagCategory = {
|
|
54
|
+
id?: string | null;
|
|
55
|
+
name?: string;
|
|
56
|
+
children?: TTagCategory[];
|
|
57
|
+
parent?: TTagCategory;
|
|
58
|
+
tags?: TTag[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type TTag = {
|
|
62
|
+
id?: string | null;
|
|
63
|
+
name?: string;
|
|
64
|
+
color?: string;
|
|
65
|
+
category?: TTagCategory;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type TUser = {
|
|
69
|
+
id?: string | null;
|
|
70
|
+
name?: string;
|
|
71
|
+
avatar?: Media;
|
|
72
|
+
position?: string;
|
|
73
|
+
profile?: string;
|
|
74
|
+
email?: string;
|
|
75
|
+
tel?: string;
|
|
76
|
+
mobile?: string;
|
|
77
|
+
linkedin?: string;
|
|
78
|
+
facebook?: string;
|
|
79
|
+
twitter?: string;
|
|
80
|
+
instagram?: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type TPost = {
|
|
84
|
+
id?: string | null;
|
|
85
|
+
slug?: string;
|
|
86
|
+
title?: string;
|
|
87
|
+
description?: string;
|
|
88
|
+
cover?: Media;
|
|
89
|
+
content?: string;
|
|
90
|
+
extends?: object;
|
|
91
|
+
publishedAt?: Date;
|
|
92
|
+
createdAt?: Date;
|
|
93
|
+
updatedAt?: Date;
|
|
94
|
+
category?: TPostCategory;
|
|
95
|
+
author?: TUser;
|
|
96
|
+
meta?: PageMeta;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type TWebsiteSettings = {
|
|
100
|
+
id?: string | null;
|
|
101
|
+
contact?: string;
|
|
102
|
+
contactAvatar?: Media;
|
|
103
|
+
address?: string;
|
|
104
|
+
email?: string;
|
|
105
|
+
tel?: string;
|
|
106
|
+
mobile?: string;
|
|
107
|
+
//以下字段 暂时用不上,预留
|
|
108
|
+
linkedin?: string;
|
|
109
|
+
facebook?: string;
|
|
110
|
+
twitter?: string;
|
|
111
|
+
instagram?: string;
|
|
112
|
+
websiteName?: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export type TBreadcrumbItem = {
|
|
116
|
+
title: string;
|
|
117
|
+
href?: string;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type TPagination = {
|
|
121
|
+
urlPrefix?: string;
|
|
122
|
+
current?: number;
|
|
123
|
+
total?: number;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const entityMaps: Record<string, string> = {
|
|
127
|
+
ProductCategory: "TProductCategory",
|
|
128
|
+
Product: "TProduct",
|
|
129
|
+
Post: "TPost",
|
|
130
|
+
PostCategory: "TPostCategory",
|
|
131
|
+
TagCategory: "TTagCategory",
|
|
132
|
+
Tag: "TTag",
|
|
133
|
+
User: "TUser",
|
|
134
|
+
WebsiteSettings: "TWebsiteSettings",
|
|
135
|
+
};
|
package/src/global.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
lastCta?: string;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
lastCta?: string;
|
|
6
|
+
}
|
|
7
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./astro";
|
|
2
|
-
export * from "./component-logic";
|
|
3
|
-
export * from "./entify";
|
|
4
|
-
export * from "./react";
|
|
5
|
-
export * from "./robots";
|
|
6
|
-
export * from "./lib";
|
|
7
|
-
export * from "./design-tokens";
|
|
8
|
-
|
|
1
|
+
export * from "./astro";
|
|
2
|
+
export * from "./component-logic";
|
|
3
|
+
export * from "./entify";
|
|
4
|
+
export * from "./react";
|
|
5
|
+
export * from "./robots";
|
|
6
|
+
export * from "./lib";
|
|
7
|
+
export * from "./design-tokens";
|
|
8
|
+
|
package/src/lib/formatDate.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 格式化日期为可读字符串
|
|
3
|
-
* @param date 日期对象或日期字符串
|
|
4
|
-
* @returns 格式化后的日期字符串,例如:2023年1月1日
|
|
5
|
-
*/
|
|
6
|
-
export function formatDate(date: Date | string | number): string {
|
|
7
|
-
const d = new Date(date);
|
|
8
|
-
|
|
9
|
-
// 使用 Intl.DateTimeFormat 进行本地化日期格式化
|
|
10
|
-
return new Intl.DateTimeFormat('zh-CN', {
|
|
11
|
-
year: 'numeric',
|
|
12
|
-
month: 'long',
|
|
13
|
-
day: 'numeric'
|
|
14
|
-
}).format(d);
|
|
15
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 格式化日期为可读字符串
|
|
3
|
+
* @param date 日期对象或日期字符串
|
|
4
|
+
* @returns 格式化后的日期字符串,例如:2023年1月1日
|
|
5
|
+
*/
|
|
6
|
+
export function formatDate(date: Date | string | number): string {
|
|
7
|
+
const d = new Date(date);
|
|
8
|
+
|
|
9
|
+
// 使用 Intl.DateTimeFormat 进行本地化日期格式化
|
|
10
|
+
return new Intl.DateTimeFormat('zh-CN', {
|
|
11
|
+
year: 'numeric',
|
|
12
|
+
month: 'long',
|
|
13
|
+
day: 'numeric'
|
|
14
|
+
}).format(d);
|
|
15
|
+
}
|
package/src/lib/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./pagination";
|
|
2
|
-
export * from "./formatDate";
|
|
3
|
-
export * from "./utils";
|
|
1
|
+
export * from "./pagination";
|
|
2
|
+
export * from "./formatDate";
|
|
3
|
+
export * from "./utils";
|
package/src/lib/pagination.ts
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
export type PageItem = number | "ellipsis";
|
|
2
|
-
|
|
3
|
-
export interface PaginationProps {
|
|
4
|
-
currentPage: number;
|
|
5
|
-
totalPages: number;
|
|
6
|
-
baseUrl: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface PaginationData {
|
|
10
|
-
pages: PageItem[];
|
|
11
|
-
hasPreviousPage: boolean;
|
|
12
|
-
hasNextPage: boolean;
|
|
13
|
-
previousPageUrl: string;
|
|
14
|
-
nextPageUrl: string;
|
|
15
|
-
pageUrls: Record<number, string>;
|
|
16
|
-
currentPage: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function generatePagination(current: number, total: number) {
|
|
20
|
-
const result: PageItem[] = [];
|
|
21
|
-
const edgePageCount = 1; // 边缘页数
|
|
22
|
-
const middlePagesSiblingCount = 2; // 中间页数的兄弟数量
|
|
23
|
-
const totalVisiblePages = edgePageCount * 2 + middlePagesSiblingCount * 2 + 1;
|
|
24
|
-
|
|
25
|
-
// 如果总页数较少,直接显示所有页码
|
|
26
|
-
if (total <= totalVisiblePages) {
|
|
27
|
-
for (let i = 1; i <= total; i++) {
|
|
28
|
-
result.push(i);
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// 始终显示第一页
|
|
34
|
-
result.push(1);
|
|
35
|
-
|
|
36
|
-
// 计算中间区域的起始和结束
|
|
37
|
-
let leftIndex = Math.max(
|
|
38
|
-
edgePageCount + 1,
|
|
39
|
-
current - middlePagesSiblingCount
|
|
40
|
-
);
|
|
41
|
-
let rightIndex = Math.min(
|
|
42
|
-
total - edgePageCount,
|
|
43
|
-
current + middlePagesSiblingCount
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// 调整以保持固定数量的页码
|
|
47
|
-
if (leftIndex <= edgePageCount + 1) {
|
|
48
|
-
rightIndex = Math.min(
|
|
49
|
-
total - edgePageCount,
|
|
50
|
-
totalVisiblePages - edgePageCount - 1
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (rightIndex >= total - edgePageCount) {
|
|
54
|
-
leftIndex = Math.max(
|
|
55
|
-
edgePageCount + 1,
|
|
56
|
-
total - totalVisiblePages + edgePageCount + 1
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 添加左省略号
|
|
61
|
-
if (leftIndex > edgePageCount + 1) {
|
|
62
|
-
result.push("ellipsis");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 添加中间页码
|
|
66
|
-
for (let i = leftIndex; i <= rightIndex; i++) {
|
|
67
|
-
result.push(i);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 添加右省略号
|
|
71
|
-
if (rightIndex < total - edgePageCount) {
|
|
72
|
-
result.push("ellipsis");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 始终显示最后一页
|
|
76
|
-
if (total > 1) {
|
|
77
|
-
result.push(total);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function paginate(props: PaginationProps): PaginationData {
|
|
84
|
-
const { currentPage, totalPages, baseUrl } = props;
|
|
85
|
-
|
|
86
|
-
// 生成页码数组
|
|
87
|
-
const pages = generatePagination(currentPage, totalPages);
|
|
88
|
-
|
|
89
|
-
// 判断是否有上一页和下一页
|
|
90
|
-
const hasPreviousPage = currentPage > 1;
|
|
91
|
-
const hasNextPage = currentPage < totalPages;
|
|
92
|
-
|
|
93
|
-
// 生成上一页和下一页的URL
|
|
94
|
-
const previousPageUrl = `${baseUrl}${currentPage - 1}`;
|
|
95
|
-
const nextPageUrl = `${baseUrl}${currentPage + 1}`;
|
|
96
|
-
|
|
97
|
-
// 生成每个页码对应的URL
|
|
98
|
-
const pageUrls: Record<number, string> = {};
|
|
99
|
-
pages.forEach((page) => {
|
|
100
|
-
if (typeof page === "number") {
|
|
101
|
-
pageUrls[page] = `${baseUrl}${page}`;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
pages,
|
|
107
|
-
hasPreviousPage,
|
|
108
|
-
hasNextPage,
|
|
109
|
-
previousPageUrl,
|
|
110
|
-
nextPageUrl,
|
|
111
|
-
pageUrls,
|
|
112
|
-
currentPage,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
1
|
+
export type PageItem = number | "ellipsis";
|
|
2
|
+
|
|
3
|
+
export interface PaginationProps {
|
|
4
|
+
currentPage: number;
|
|
5
|
+
totalPages: number;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PaginationData {
|
|
10
|
+
pages: PageItem[];
|
|
11
|
+
hasPreviousPage: boolean;
|
|
12
|
+
hasNextPage: boolean;
|
|
13
|
+
previousPageUrl: string;
|
|
14
|
+
nextPageUrl: string;
|
|
15
|
+
pageUrls: Record<number, string>;
|
|
16
|
+
currentPage: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function generatePagination(current: number, total: number) {
|
|
20
|
+
const result: PageItem[] = [];
|
|
21
|
+
const edgePageCount = 1; // 边缘页数
|
|
22
|
+
const middlePagesSiblingCount = 2; // 中间页数的兄弟数量
|
|
23
|
+
const totalVisiblePages = edgePageCount * 2 + middlePagesSiblingCount * 2 + 1;
|
|
24
|
+
|
|
25
|
+
// 如果总页数较少,直接显示所有页码
|
|
26
|
+
if (total <= totalVisiblePages) {
|
|
27
|
+
for (let i = 1; i <= total; i++) {
|
|
28
|
+
result.push(i);
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 始终显示第一页
|
|
34
|
+
result.push(1);
|
|
35
|
+
|
|
36
|
+
// 计算中间区域的起始和结束
|
|
37
|
+
let leftIndex = Math.max(
|
|
38
|
+
edgePageCount + 1,
|
|
39
|
+
current - middlePagesSiblingCount
|
|
40
|
+
);
|
|
41
|
+
let rightIndex = Math.min(
|
|
42
|
+
total - edgePageCount,
|
|
43
|
+
current + middlePagesSiblingCount
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// 调整以保持固定数量的页码
|
|
47
|
+
if (leftIndex <= edgePageCount + 1) {
|
|
48
|
+
rightIndex = Math.min(
|
|
49
|
+
total - edgePageCount,
|
|
50
|
+
totalVisiblePages - edgePageCount - 1
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (rightIndex >= total - edgePageCount) {
|
|
54
|
+
leftIndex = Math.max(
|
|
55
|
+
edgePageCount + 1,
|
|
56
|
+
total - totalVisiblePages + edgePageCount + 1
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 添加左省略号
|
|
61
|
+
if (leftIndex > edgePageCount + 1) {
|
|
62
|
+
result.push("ellipsis");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 添加中间页码
|
|
66
|
+
for (let i = leftIndex; i <= rightIndex; i++) {
|
|
67
|
+
result.push(i);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 添加右省略号
|
|
71
|
+
if (rightIndex < total - edgePageCount) {
|
|
72
|
+
result.push("ellipsis");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 始终显示最后一页
|
|
76
|
+
if (total > 1) {
|
|
77
|
+
result.push(total);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function paginate(props: PaginationProps): PaginationData {
|
|
84
|
+
const { currentPage, totalPages, baseUrl } = props;
|
|
85
|
+
|
|
86
|
+
// 生成页码数组
|
|
87
|
+
const pages = generatePagination(currentPage, totalPages);
|
|
88
|
+
|
|
89
|
+
// 判断是否有上一页和下一页
|
|
90
|
+
const hasPreviousPage = currentPage > 1;
|
|
91
|
+
const hasNextPage = currentPage < totalPages;
|
|
92
|
+
|
|
93
|
+
// 生成上一页和下一页的URL
|
|
94
|
+
const previousPageUrl = `${baseUrl}${currentPage - 1}`;
|
|
95
|
+
const nextPageUrl = `${baseUrl}${currentPage + 1}`;
|
|
96
|
+
|
|
97
|
+
// 生成每个页码对应的URL
|
|
98
|
+
const pageUrls: Record<number, string> = {};
|
|
99
|
+
pages.forEach((page) => {
|
|
100
|
+
if (typeof page === "number") {
|
|
101
|
+
pageUrls[page] = `${baseUrl}${page}`;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
pages,
|
|
107
|
+
hasPreviousPage,
|
|
108
|
+
hasNextPage,
|
|
109
|
+
previousPageUrl,
|
|
110
|
+
nextPageUrl,
|
|
111
|
+
pageUrls,
|
|
112
|
+
currentPage,
|
|
113
|
+
};
|
|
114
|
+
}
|