@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { IQueryOptions, ListResult } from "@rxdrag/entify-hooks";
|
|
2
|
+
import { TSize } from "./types";
|
|
3
|
+
import { ListConditions } from "./lib";
|
|
4
|
+
import { TPost, TPostCategory, TProduct, TProductCategory, TUser } from "./view-model";
|
|
5
|
+
import { Lang, Theme } from "@rxdrag/rxcms-models";
|
|
6
|
+
|
|
7
|
+
export type PostsOptions = {
|
|
8
|
+
category?: string;
|
|
9
|
+
coverSize?: TSize | undefined;
|
|
10
|
+
page: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type PostPatinateOptions = {
|
|
15
|
+
pageSize: number;
|
|
16
|
+
category?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface IEntify {
|
|
20
|
+
queryEntityList<
|
|
21
|
+
T,
|
|
22
|
+
WhereExp = unknown,
|
|
23
|
+
OrderBy = unknown,
|
|
24
|
+
DistinctExp = unknown
|
|
25
|
+
>(
|
|
26
|
+
options: IQueryOptions<T, WhereExp, OrderBy, DistinctExp>,
|
|
27
|
+
//用于生成静态网站时使用,预览测试也可以用
|
|
28
|
+
staticKey?: string
|
|
29
|
+
): Promise<ListResult<unknown> | undefined>;
|
|
30
|
+
|
|
31
|
+
getTheme(): Promise<Theme | undefined>;
|
|
32
|
+
|
|
33
|
+
getLangs(): Promise<Lang[] | undefined>;
|
|
34
|
+
|
|
35
|
+
getFeaturedProducts(count?: number): Promise<TProduct[] | undefined>;
|
|
36
|
+
|
|
37
|
+
getLatestPosts(count?: number): Promise<TPost[] | undefined>;
|
|
38
|
+
|
|
39
|
+
getPosts(options: PostsOptions): Promise<TPost[] | undefined>;
|
|
40
|
+
|
|
41
|
+
getPostListPaths(options: PostPatinateOptions): Promise<unknown>;
|
|
42
|
+
|
|
43
|
+
getPostPaths(): Promise<unknown>;
|
|
44
|
+
|
|
45
|
+
getPostBySlug(slug: string, coverSize: TSize | undefined): Promise<unknown>;
|
|
46
|
+
|
|
47
|
+
getPostSlugs(): Promise<Array<string | undefined>>;
|
|
48
|
+
|
|
49
|
+
getPostCategories(): Promise<TPostCategory[] | undefined>;
|
|
50
|
+
|
|
51
|
+
getPostCategoryBySlug(slug: string): Promise<TPostCategory | undefined>;
|
|
52
|
+
|
|
53
|
+
getProducts(
|
|
54
|
+
conditions: ListConditions,
|
|
55
|
+
imageSize: TSize | undefined
|
|
56
|
+
): Promise<TProduct[] | undefined>;
|
|
57
|
+
|
|
58
|
+
getProductListPaths(options: {
|
|
59
|
+
category?: string;
|
|
60
|
+
pageSize: number;
|
|
61
|
+
}): Promise<unknown>;
|
|
62
|
+
|
|
63
|
+
getCategoredProductListPaths(): Promise<unknown>;
|
|
64
|
+
|
|
65
|
+
getCategoredPostListPaths(): Promise<unknown>;
|
|
66
|
+
|
|
67
|
+
getProductBySlug(
|
|
68
|
+
slug: string,
|
|
69
|
+
imageSize: TSize | undefined
|
|
70
|
+
): Promise<TProduct | undefined>;
|
|
71
|
+
|
|
72
|
+
getProductPaths(): Promise<unknown>;
|
|
73
|
+
|
|
74
|
+
getProductSlugs(): Promise<Array<string | undefined>>;
|
|
75
|
+
|
|
76
|
+
getProductIds(): Promise<Array<string | null | undefined>>;
|
|
77
|
+
|
|
78
|
+
getProductCategories(): Promise<TProductCategory[] | undefined>;
|
|
79
|
+
|
|
80
|
+
getProductCategoryBySlug(slug: string): Promise<TProductCategory | undefined>;
|
|
81
|
+
|
|
82
|
+
getOneUser(id: string): Promise<TUser | undefined>;
|
|
83
|
+
|
|
84
|
+
getUserPosts(userId: string): Promise<TPost[] | undefined>;
|
|
85
|
+
|
|
86
|
+
searchProducts(keyword: string): Promise<ListResult<TProduct> | undefined>;
|
|
87
|
+
|
|
88
|
+
getUserPaths(): Promise<unknown>;
|
|
89
|
+
|
|
90
|
+
createPagination(totalItems: number, pageSize: number): unknown;
|
|
91
|
+
}
|
package/src/entify/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
ProductRelatedPivotQueryOptions,
|
|
11
11
|
ProductCategoryFields,
|
|
12
12
|
} from "@rxdrag/rxcms-models";
|
|
13
|
-
import { OrderBy } from "@rxdrag/entify-hooks";
|
|
14
13
|
import { TSize } from "../types";
|
|
15
14
|
import { newPageMetaOptions } from "./newPageMetaOptions";
|
|
16
15
|
|
|
@@ -33,7 +32,7 @@ function creatProductMediaOptions(imagSize?: TSize) {
|
|
|
33
32
|
{
|
|
34
33
|
orderBy: [
|
|
35
34
|
{
|
|
36
|
-
[MediaOnProductFields.seqValue]:
|
|
35
|
+
[MediaOnProductFields.seqValue]: "asc",
|
|
37
36
|
},
|
|
38
37
|
],
|
|
39
38
|
}
|
|
@@ -60,7 +59,7 @@ export function newQueryProductOptions(imagSize?: TSize) {
|
|
|
60
59
|
new AttachmentOnProductQueryOptions(undefined, {
|
|
61
60
|
orderBy: [
|
|
62
61
|
{
|
|
63
|
-
[AttachmentOnProductFields.seqValue]:
|
|
62
|
+
[AttachmentOnProductFields.seqValue]: "asc",
|
|
64
63
|
},
|
|
65
64
|
],
|
|
66
65
|
}).attachment(
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
MediaOnProductQueryOptions,
|
|
3
|
+
MediaOnProductFields,
|
|
4
|
+
MediaQueryOptions,
|
|
5
|
+
} from "@rxdrag/rxcms-models";
|
|
3
6
|
import { TSize } from "../types";
|
|
4
7
|
|
|
5
|
-
export function newQueryProductsMediaOptions(imageSize?: TSize | undefined
|
|
8
|
+
export function newQueryProductsMediaOptions(imageSize?: TSize | undefined) {
|
|
6
9
|
return new MediaOnProductQueryOptions(
|
|
7
|
-
[
|
|
8
|
-
MediaOnProductFields.seqValue,
|
|
9
|
-
MediaOnProductFields.altText,
|
|
10
|
-
],
|
|
10
|
+
[MediaOnProductFields.seqValue, MediaOnProductFields.altText],
|
|
11
11
|
{
|
|
12
12
|
orderBy: [
|
|
13
13
|
{
|
|
14
|
-
[MediaOnProductFields.seqValue]:
|
|
15
|
-
}
|
|
16
|
-
]
|
|
14
|
+
[MediaOnProductFields.seqValue]: "asc",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
17
|
}
|
|
18
18
|
).media(
|
|
19
|
-
new MediaQueryOptions().file(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
new MediaQueryOptions().file([
|
|
20
|
+
"thumbnail(width:400, height:320)",
|
|
21
|
+
"url",
|
|
22
|
+
imageSize
|
|
23
|
+
? `resize(width:${imageSize.width}, height:${imageSize.height})`
|
|
24
|
+
: "resize(width:500, height:400)",
|
|
25
|
+
])
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Product,
|
|
3
|
+
ProductBoolExp,
|
|
4
|
+
ProductDistinctExp,
|
|
5
|
+
ProductFields,
|
|
6
|
+
ProductOrderBy,
|
|
7
|
+
ProductQueryOptions,
|
|
8
|
+
PublishableStatus,
|
|
9
|
+
} from "@rxdrag/rxcms-models";
|
|
2
10
|
import { EnvVariables } from "../types";
|
|
3
|
-
import { ListResult
|
|
11
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
4
12
|
import { TProduct } from "../view-model";
|
|
5
13
|
import { queryEntityList } from "./queryEntityList";
|
|
6
14
|
|
|
@@ -13,7 +21,7 @@ export async function queryAllProducts(envVariables: EnvVariables) {
|
|
|
13
21
|
_eq: PublishableStatus.published,
|
|
14
22
|
},
|
|
15
23
|
},
|
|
16
|
-
orderBy: [{ [ProductFields.seqValue]:
|
|
24
|
+
orderBy: [{ [ProductFields.seqValue]: "asc" }],
|
|
17
25
|
}
|
|
18
26
|
);
|
|
19
27
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { queryEntityList } from "./queryEntityList";
|
|
10
10
|
import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
11
11
|
import { EnvVariables } from "../types";
|
|
12
|
-
import { ListResult
|
|
12
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
13
13
|
import { TProduct } from "../view-model";
|
|
14
14
|
|
|
15
15
|
export async function queryFeaturedProducts(
|
|
@@ -38,10 +38,10 @@ export async function queryFeaturedProducts(
|
|
|
38
38
|
_eq: true,
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
|
-
orderBy: [{ [ProductFields.seqValue]:
|
|
41
|
+
orderBy: [{ [ProductFields.seqValue]: "asc" }],
|
|
42
42
|
}
|
|
43
43
|
).mediaPivots(newQueryProductsMediaOptions()),
|
|
44
44
|
envVariables
|
|
45
45
|
);
|
|
46
|
-
return result as ListResult<TProduct> | undefined;
|
|
46
|
+
return (result as ListResult<TProduct> | undefined)?.items;
|
|
47
47
|
}
|
|
@@ -38,7 +38,7 @@ export async function queryLatestPosts(
|
|
|
38
38
|
orderBy: [
|
|
39
39
|
{
|
|
40
40
|
//暂时按照更新时间排序
|
|
41
|
-
updatedAt:
|
|
41
|
+
updatedAt: "desc",
|
|
42
42
|
},
|
|
43
43
|
],
|
|
44
44
|
where: {
|
|
@@ -61,5 +61,5 @@ export async function queryLatestPosts(
|
|
|
61
61
|
),
|
|
62
62
|
envVariables
|
|
63
63
|
);
|
|
64
|
-
return result as ListResult<TPost> | undefined;
|
|
64
|
+
return (result as ListResult<TPost> | undefined)?.items;
|
|
65
65
|
}
|
|
@@ -66,7 +66,7 @@ export async function queryOneTheme(envVariables: EnvVariables) {
|
|
|
66
66
|
ThemeConfigFields.mobile,
|
|
67
67
|
ThemeConfigFields.tel,
|
|
68
68
|
ThemeConfigFields.wechat,
|
|
69
|
-
ThemeConfigFields.websiteName,
|
|
69
|
+
//ThemeConfigFields.websiteName,
|
|
70
70
|
]).contactAvatar(new MediaQueryOptions().file(["thumbnail"]))
|
|
71
71
|
)
|
|
72
72
|
.lang(langFields)
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
PostFields,
|
|
12
12
|
} from "@rxdrag/rxcms-models";
|
|
13
13
|
import { queryEntityList } from "./queryEntityList";
|
|
14
|
-
import { ListResult
|
|
14
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
15
15
|
import { EnvVariables } from "../types";
|
|
16
16
|
import { TPostCategory } from "../view-model";
|
|
17
17
|
|
|
@@ -30,7 +30,7 @@ export async function queryPostCategories(envVariables: EnvVariables) {
|
|
|
30
30
|
PostCategoryFields.description,
|
|
31
31
|
],
|
|
32
32
|
{
|
|
33
|
-
orderBy: [{ [PostCategoryFields.seqValue]:
|
|
33
|
+
orderBy: [{ [PostCategoryFields.seqValue]: "asc" }],
|
|
34
34
|
}
|
|
35
35
|
).posts(
|
|
36
36
|
new PostQueryOptions([PostFields.id, PostFields.title, PostFields.slug], {
|
|
@@ -39,7 +39,7 @@ export async function queryPostCategories(envVariables: EnvVariables) {
|
|
|
39
39
|
_eq: PublishableStatus.published,
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
|
-
orderBy: [{ [ProductFields.seqValue]:
|
|
42
|
+
orderBy: [{ [ProductFields.seqValue]: "asc" }],
|
|
43
43
|
})
|
|
44
44
|
),
|
|
45
45
|
envVariables
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
PublishableStatus,
|
|
9
9
|
} from "@rxdrag/rxcms-models";
|
|
10
10
|
import { EnvVariables } from "../types";
|
|
11
|
-
import {
|
|
11
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
12
12
|
import { TPost } from "../view-model";
|
|
13
13
|
import { queryEntityList } from "./queryEntityList";
|
|
14
14
|
|
|
@@ -19,7 +19,7 @@ export async function queryPostSlugs(envVariables: EnvVariables) {
|
|
|
19
19
|
_eq: PublishableStatus.published,
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
|
-
orderBy: [{ [PostFields.seqValue]:
|
|
22
|
+
orderBy: [{ [PostFields.seqValue]: "asc" }],
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
const result = await queryEntityList<
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import { Post, PostBoolExp, PostOrderBy, PostDistinctExp, PostFields, PublishableStatus, PostAssciations, PostQueryOptions, MediaQueryOptions, UserQueryOptions, UserFields } from "@rxdrag/rxcms-models";
|
|
2
|
-
import { queryEntityList } from "./queryEntityList";
|
|
3
|
-
import { ListResult
|
|
4
|
-
import { EnvVariables, TSize } from "../types";
|
|
5
|
-
import { TPost } from "../view-model";
|
|
6
|
-
|
|
7
|
-
export interface ListConditions {
|
|
8
|
-
category?: string;//category slug
|
|
9
|
-
page?: number;
|
|
10
|
-
pageSize: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function queryPosts(
|
|
14
|
-
conditions: ListConditions,
|
|
15
|
-
coverSize: TSize | undefined,
|
|
16
|
-
envVariables: EnvVariables,
|
|
17
|
-
selectFields?: (keyof Post)[]
|
|
18
|
-
) {
|
|
19
|
-
const { category: categorySlug, page = 1, pageSize } = conditions;
|
|
20
|
-
|
|
21
|
-
let where = {}
|
|
22
|
-
if (categorySlug) {
|
|
23
|
-
where = {
|
|
24
|
-
[PostAssciations.category]: {
|
|
25
|
-
slug: {
|
|
26
|
-
"_eq": categorySlug
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 默认查询字段
|
|
33
|
-
const defaultFields = [
|
|
34
|
-
PostFields.id,
|
|
35
|
-
PostFields.title,
|
|
36
|
-
PostFields.slug,
|
|
37
|
-
PostFields.description,
|
|
38
|
-
PostFields.status,
|
|
39
|
-
PostFields.updatedAt,
|
|
40
|
-
PostFields.createdAt,
|
|
41
|
-
PostFields.publishedAt,
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
// 使用指定的字段或默认字段
|
|
45
|
-
const fields = selectFields || defaultFields;
|
|
46
|
-
|
|
47
|
-
const queryOptions = new PostQueryOptions(
|
|
48
|
-
fields,
|
|
49
|
-
{
|
|
50
|
-
offset: (page - 1) * pageSize,
|
|
51
|
-
limit: pageSize,
|
|
52
|
-
where: {
|
|
53
|
-
[PostFields.status]: {
|
|
54
|
-
"_eq": PublishableStatus.published
|
|
55
|
-
},
|
|
56
|
-
...where,
|
|
57
|
-
},
|
|
58
|
-
orderBy: [
|
|
59
|
-
{
|
|
60
|
-
[PostFields.createdAt]:
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// 只有在需要查询封面图时才添加封面图查询
|
|
67
|
-
if (!selectFields || selectFields.includes('cover' as keyof Post)) {
|
|
68
|
-
queryOptions.cover(
|
|
69
|
-
new MediaQueryOptions().file(
|
|
70
|
-
[
|
|
71
|
-
"thumbnail",
|
|
72
|
-
coverSize ? `resize(width:${coverSize.width}, height:${coverSize.height})` : "resize(width:480, height:180)"
|
|
73
|
-
]
|
|
74
|
-
)
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 只有在需要查询作者时才添加作者查询
|
|
79
|
-
if (!selectFields || selectFields.includes('author' as keyof Post)) {
|
|
80
|
-
queryOptions.author(
|
|
81
|
-
new UserQueryOptions([UserFields.id, UserFields.name])
|
|
82
|
-
.avatar(new MediaQueryOptions().file(["thumbnail"]))
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const result = await queryEntityList<Post, PostBoolExp, PostOrderBy, PostDistinctExp>(
|
|
87
|
-
queryOptions,
|
|
88
|
-
envVariables
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
return result as ListResult<TPost> | undefined;
|
|
92
|
-
}
|
|
1
|
+
import { Post, PostBoolExp, PostOrderBy, PostDistinctExp, PostFields, PublishableStatus, PostAssciations, PostQueryOptions, MediaQueryOptions, UserQueryOptions, UserFields } from "@rxdrag/rxcms-models";
|
|
2
|
+
import { queryEntityList } from "./queryEntityList";
|
|
3
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
4
|
+
import { EnvVariables, TSize } from "../types";
|
|
5
|
+
import { TPost } from "../view-model";
|
|
6
|
+
|
|
7
|
+
export interface ListConditions {
|
|
8
|
+
category?: string;//category slug
|
|
9
|
+
page?: number;
|
|
10
|
+
pageSize: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function queryPosts(
|
|
14
|
+
conditions: ListConditions,
|
|
15
|
+
coverSize: TSize | undefined,
|
|
16
|
+
envVariables: EnvVariables,
|
|
17
|
+
selectFields?: (keyof Post)[]
|
|
18
|
+
) {
|
|
19
|
+
const { category: categorySlug, page = 1, pageSize } = conditions;
|
|
20
|
+
|
|
21
|
+
let where = {}
|
|
22
|
+
if (categorySlug) {
|
|
23
|
+
where = {
|
|
24
|
+
[PostAssciations.category]: {
|
|
25
|
+
slug: {
|
|
26
|
+
"_eq": categorySlug
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 默认查询字段
|
|
33
|
+
const defaultFields = [
|
|
34
|
+
PostFields.id,
|
|
35
|
+
PostFields.title,
|
|
36
|
+
PostFields.slug,
|
|
37
|
+
PostFields.description,
|
|
38
|
+
PostFields.status,
|
|
39
|
+
PostFields.updatedAt,
|
|
40
|
+
PostFields.createdAt,
|
|
41
|
+
PostFields.publishedAt,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// 使用指定的字段或默认字段
|
|
45
|
+
const fields = selectFields || defaultFields;
|
|
46
|
+
|
|
47
|
+
const queryOptions = new PostQueryOptions(
|
|
48
|
+
fields,
|
|
49
|
+
{
|
|
50
|
+
offset: (page - 1) * pageSize,
|
|
51
|
+
limit: pageSize,
|
|
52
|
+
where: {
|
|
53
|
+
[PostFields.status]: {
|
|
54
|
+
"_eq": PublishableStatus.published
|
|
55
|
+
},
|
|
56
|
+
...where,
|
|
57
|
+
},
|
|
58
|
+
orderBy: [
|
|
59
|
+
{
|
|
60
|
+
[PostFields.createdAt]: "desc"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// 只有在需要查询封面图时才添加封面图查询
|
|
67
|
+
if (!selectFields || selectFields.includes('cover' as keyof Post)) {
|
|
68
|
+
queryOptions.cover(
|
|
69
|
+
new MediaQueryOptions().file(
|
|
70
|
+
[
|
|
71
|
+
"thumbnail",
|
|
72
|
+
coverSize ? `resize(width:${coverSize.width}, height:${coverSize.height})` : "resize(width:480, height:180)"
|
|
73
|
+
]
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 只有在需要查询作者时才添加作者查询
|
|
79
|
+
if (!selectFields || selectFields.includes('author' as keyof Post)) {
|
|
80
|
+
queryOptions.author(
|
|
81
|
+
new UserQueryOptions([UserFields.id, UserFields.name])
|
|
82
|
+
.avatar(new MediaQueryOptions().file(["thumbnail"]))
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const result = await queryEntityList<Post, PostBoolExp, PostOrderBy, PostDistinctExp>(
|
|
87
|
+
queryOptions,
|
|
88
|
+
envVariables
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return result as ListResult<TPost> | undefined;
|
|
92
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProductCategory, ProductCategoryBoolExp, ProductCategoryOrderBy, ProductCategoryDistinctExp, ProductCategoryFields, ProductCategoryQueryOptions, ProductFields, ProductQueryOptions, PublishableStatus } from "@rxdrag/rxcms-models";
|
|
2
2
|
import { queryEntityList } from "./queryEntityList";
|
|
3
|
-
import { ListResult
|
|
3
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
4
4
|
import { EnvVariables } from "../types";
|
|
5
5
|
import { TProductCategory } from "../view-model";
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@ export async function queryProductCategories(envVariables: EnvVariables) {
|
|
|
16
16
|
],
|
|
17
17
|
{
|
|
18
18
|
orderBy: [
|
|
19
|
-
{ [ProductCategoryFields.seqValue]:
|
|
19
|
+
{ [ProductCategoryFields.seqValue]: "asc" }
|
|
20
20
|
]
|
|
21
21
|
}
|
|
22
22
|
)
|
|
@@ -33,7 +33,7 @@ export async function queryProductCategories(envVariables: EnvVariables) {
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
orderBy: [
|
|
36
|
-
{ [ProductFields.seqValue]:
|
|
36
|
+
{ [ProductFields.seqValue]: "asc" }
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
39
|
)
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { Product, ProductBoolExp, ProductOrderBy, ProductDistinctExp, ProductFields, ProductQueryOptions, PublishableStatus, ProductAssciations } from "@rxdrag/rxcms-models";
|
|
2
|
-
import { ListConditions } from "./queryPosts";
|
|
3
|
-
import { queryEntityList } from "./queryEntityList";
|
|
4
|
-
import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
5
|
-
import { ListResult
|
|
6
|
-
import { EnvVariables, TSize } from "../types";
|
|
7
|
-
import { TProduct } from "../view-model";
|
|
8
|
-
|
|
9
|
-
export async function queryProducts(
|
|
10
|
-
conditions: ListConditions,
|
|
11
|
-
imageSize: TSize | undefined,
|
|
12
|
-
envVariables: EnvVariables,
|
|
13
|
-
selectFields?: (keyof Product)[]
|
|
14
|
-
) {
|
|
15
|
-
const { category: categorySlug, page = 1, pageSize = 10 } = conditions;
|
|
16
|
-
|
|
17
|
-
let where = {}
|
|
18
|
-
if (categorySlug) {
|
|
19
|
-
where = {
|
|
20
|
-
[ProductAssciations.category]: {
|
|
21
|
-
slug: {
|
|
22
|
-
"_eq": categorySlug
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// 默认查询字段
|
|
29
|
-
const defaultFields = [
|
|
30
|
-
ProductFields.id,
|
|
31
|
-
ProductFields.slug,
|
|
32
|
-
ProductFields.title,
|
|
33
|
-
ProductFields.shortTitle,
|
|
34
|
-
ProductFields.description,
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
// 使用指定的字段或默认字段
|
|
38
|
-
const fields = selectFields || defaultFields;
|
|
39
|
-
|
|
40
|
-
const queryOptions = new ProductQueryOptions(
|
|
41
|
-
fields,
|
|
42
|
-
{
|
|
43
|
-
offset: (page - 1) * pageSize,
|
|
44
|
-
limit: pageSize,
|
|
45
|
-
where: {
|
|
46
|
-
[ProductFields.status]: {
|
|
47
|
-
"_eq": PublishableStatus.published
|
|
48
|
-
},
|
|
49
|
-
...where,
|
|
50
|
-
},
|
|
51
|
-
orderBy: [
|
|
52
|
-
{ [ProductFields.seqValue]:
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// 只有在不指定字段或需要查询媒体时才添加媒体查询
|
|
58
|
-
if (!selectFields || !selectFields.includes('slug' as keyof Product)) {
|
|
59
|
-
queryOptions.mediaPivots(
|
|
60
|
-
newQueryProductsMediaOptions(imageSize)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const result = await queryEntityList<Product, ProductBoolExp, ProductOrderBy, ProductDistinctExp>(
|
|
65
|
-
queryOptions,
|
|
66
|
-
envVariables
|
|
67
|
-
);
|
|
68
|
-
return result as ListResult<TProduct> | undefined;
|
|
69
|
-
}
|
|
1
|
+
import { Product, ProductBoolExp, ProductOrderBy, ProductDistinctExp, ProductFields, ProductQueryOptions, PublishableStatus, ProductAssciations } from "@rxdrag/rxcms-models";
|
|
2
|
+
import { ListConditions } from "./queryPosts";
|
|
3
|
+
import { queryEntityList } from "./queryEntityList";
|
|
4
|
+
import { newQueryProductsMediaOptions } from "./newQueryProductsMediaOptions";
|
|
5
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
6
|
+
import { EnvVariables, TSize } from "../types";
|
|
7
|
+
import { TProduct } from "../view-model";
|
|
8
|
+
|
|
9
|
+
export async function queryProducts(
|
|
10
|
+
conditions: ListConditions,
|
|
11
|
+
imageSize: TSize | undefined,
|
|
12
|
+
envVariables: EnvVariables,
|
|
13
|
+
selectFields?: (keyof Product)[]
|
|
14
|
+
) {
|
|
15
|
+
const { category: categorySlug, page = 1, pageSize = 10 } = conditions;
|
|
16
|
+
|
|
17
|
+
let where = {}
|
|
18
|
+
if (categorySlug) {
|
|
19
|
+
where = {
|
|
20
|
+
[ProductAssciations.category]: {
|
|
21
|
+
slug: {
|
|
22
|
+
"_eq": categorySlug
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 默认查询字段
|
|
29
|
+
const defaultFields = [
|
|
30
|
+
ProductFields.id,
|
|
31
|
+
ProductFields.slug,
|
|
32
|
+
ProductFields.title,
|
|
33
|
+
ProductFields.shortTitle,
|
|
34
|
+
ProductFields.description,
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
// 使用指定的字段或默认字段
|
|
38
|
+
const fields = selectFields || defaultFields;
|
|
39
|
+
|
|
40
|
+
const queryOptions = new ProductQueryOptions(
|
|
41
|
+
fields,
|
|
42
|
+
{
|
|
43
|
+
offset: (page - 1) * pageSize,
|
|
44
|
+
limit: pageSize,
|
|
45
|
+
where: {
|
|
46
|
+
[ProductFields.status]: {
|
|
47
|
+
"_eq": PublishableStatus.published
|
|
48
|
+
},
|
|
49
|
+
...where,
|
|
50
|
+
},
|
|
51
|
+
orderBy: [
|
|
52
|
+
{ [ProductFields.seqValue]: "asc" }
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// 只有在不指定字段或需要查询媒体时才添加媒体查询
|
|
58
|
+
if (!selectFields || !selectFields.includes('slug' as keyof Product)) {
|
|
59
|
+
queryOptions.mediaPivots(
|
|
60
|
+
newQueryProductsMediaOptions(imageSize)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = await queryEntityList<Product, ProductBoolExp, ProductOrderBy, ProductDistinctExp>(
|
|
65
|
+
queryOptions,
|
|
66
|
+
envVariables
|
|
67
|
+
);
|
|
68
|
+
return result as ListResult<TProduct> | undefined;
|
|
69
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ListResult
|
|
1
|
+
import { ListResult } from "@rxdrag/entify-hooks";
|
|
2
2
|
import {
|
|
3
3
|
PostBoolExp,
|
|
4
4
|
PostOrderBy,
|
|
@@ -46,7 +46,7 @@ export async function queryUserPosts(
|
|
|
46
46
|
orderBy: [
|
|
47
47
|
{
|
|
48
48
|
//暂时按照更新时间排序
|
|
49
|
-
updatedAt:
|
|
49
|
+
updatedAt: "desc",
|
|
50
50
|
},
|
|
51
51
|
],
|
|
52
52
|
where: {
|