@tbox.cn/app-card-assets 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +10 -2
- package/SOURCE.md +5 -0
- package/assets.json +239 -0
- package/components/Banner/index.module.less +13 -0
- package/components/Banner/index.tsx +36 -0
- package/components/BlockAnimal/LottiePlayer/index.module.less +11 -0
- package/components/BlockAnimal/LottiePlayer/index.tsx +24 -0
- package/components/BlockAnimal/LottiePlayer/utils.ts +72 -0
- package/components/BlockAnimal/index.module.less +80 -0
- package/components/BlockAnimal/index.tsx +120 -0
- package/components/BlockBarrage/index.module.less +104 -0
- package/components/BlockBarrage/index.tsx +98 -0
- package/components/BlockFanSwiper/index.module.less +93 -0
- package/components/BlockFanSwiper/index.tsx +56 -0
- package/components/BlockIntro/index.module.less +32 -0
- package/components/BlockIntro/index.tsx +21 -0
- package/components/BlockIntroCenter/index.module.less +31 -0
- package/components/BlockIntroCenter/index.tsx +22 -0
- package/components/BlockNowList/index.module.less +75 -0
- package/components/BlockNowList/index.tsx +54 -0
- package/components/BlockQuestionList/index.module.less +115 -0
- package/components/BlockQuestionList/index.tsx +107 -0
- package/components/BlockServiceIconList/index.module.less +68 -0
- package/components/BlockServiceIconList/index.tsx +83 -0
- package/components/BlockServiceList/index.module.less +92 -0
- package/components/BlockServiceList/index.tsx +88 -0
- package/components/BlockTravelCarousel/index.module.less +127 -0
- package/components/BlockTravelCarousel/index.tsx +101 -0
- package/components/BlockTravelCarousel/tags/Tags.module.less +20 -0
- package/components/BlockTravelCarousel/tags/Tags.tsx +20 -0
- package/components/OneCol/index.module.less +161 -0
- package/components/OneCol/index.tsx +83 -0
- package/components/TwoCol/index.module.less +199 -0
- package/components/TwoCol/index.tsx +82 -0
- package/docs/Banner.md +17 -0
- package/docs/BlockAnimal.md +17 -0
- package/docs/BlockBarrage.md +17 -0
- package/docs/BlockFanSwiper.md +17 -0
- package/docs/BlockIntro.md +17 -0
- package/docs/BlockIntroCenter.md +17 -0
- package/docs/BlockNowList.md +17 -0
- package/docs/BlockQuestionList.md +17 -0
- package/docs/BlockServiceIconList.md +17 -0
- package/docs/BlockServiceList.md +17 -0
- package/docs/BlockTravelCarousel.md +17 -0
- package/docs/OneCol.md +17 -0
- package/docs/TwoCol.md +17 -0
- package/examples/Banner.json +5 -0
- package/examples/BlockAnimal.json +22 -0
- package/examples/BlockBarrage.json +26 -0
- package/examples/BlockFanSwiper.json +23 -0
- package/examples/BlockIntro.json +4 -0
- package/examples/BlockIntroCenter.json +4 -0
- package/examples/BlockNowList.json +36 -0
- package/examples/BlockQuestionList.json +25 -0
- package/examples/BlockServiceIconList.json +36 -0
- package/examples/BlockServiceList.json +36 -0
- package/examples/BlockTravelCarousel.json +37 -0
- package/examples/OneCol.json +49 -0
- package/examples/TwoCol.json +49 -0
- package/package.json +39 -3
- package/shared/actions.ts +38 -0
- package/shared/home-integration.md +49 -0
- package/shared/types.ts +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tbox.cn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tbox.cn/app-card-assets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
卡片源码资源 npm 包,由 tbox-app 维护。首期包含 13 个首页组件;包名不限定后续卡片场景。
|
|
4
|
+
|
|
5
|
+
消费方为开发期 CLI:读取 assets.json 并按需复制 components/shared/docs/examples。生成应用不把本包作为运行时依赖,只安装选中卡片的 dependencies。每个组件用法在 docs/;来源记录见 SOURCE.md。复制后的源文件由应用自行维护,重复安装遇到修改默认报冲突。
|
|
6
|
+
|
|
7
|
+
包不导出全量 React registry;不包含平台模板 ID,不解释远程页面配置。源码保留 750 设计尺寸,面向 template-agent 的 Less + postcss-pxtorem(rootValue=100)链。
|
|
8
|
+
|
|
9
|
+
首页交互由 shared/actions.ts 适配:query 使用 home 槽 onSend,跳转使用应用 store 的 openLink 动作;接线示例见 shared/home-integration.md。
|
|
10
|
+
|
|
11
|
+
容器与内部列宽约定见 [容器宽度](shared/home-integration.md#容器宽度)。
|
package/SOURCE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Source provenance
|
|
2
|
+
|
|
3
|
+
Initial source: tbox-inc-agent-ui, commit `e25b78b82adbba2bbdac723ed06335e992b46702`, `src/ThousandFace/components/`.
|
|
4
|
+
|
|
5
|
+
The portable copy is maintained in this package. No automatic upstream synchronization. OneCol and TwoCol originate from Onecol and Twocol. Local adaptations include explicit bridge types, CSS Modules names, browser units and lifecycle repairs.
|
package/assets.json
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"assetVersion": "0.1.1",
|
|
4
|
+
"components": [
|
|
5
|
+
{
|
|
6
|
+
"name": "BlockIntro",
|
|
7
|
+
"scene": "home",
|
|
8
|
+
"entry": "components/BlockIntro/index.tsx",
|
|
9
|
+
"files": [
|
|
10
|
+
"components/BlockIntro/index.module.less",
|
|
11
|
+
"components/BlockIntro/index.tsx"
|
|
12
|
+
],
|
|
13
|
+
"sharedFiles": [
|
|
14
|
+
"shared/types.ts",
|
|
15
|
+
"shared/home-integration.md",
|
|
16
|
+
"shared/actions.ts"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {},
|
|
19
|
+
"usage": "docs/BlockIntro.md",
|
|
20
|
+
"example": "examples/BlockIntro.json"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "BlockIntroCenter",
|
|
24
|
+
"scene": "home",
|
|
25
|
+
"entry": "components/BlockIntroCenter/index.tsx",
|
|
26
|
+
"files": [
|
|
27
|
+
"components/BlockIntroCenter/index.module.less",
|
|
28
|
+
"components/BlockIntroCenter/index.tsx"
|
|
29
|
+
],
|
|
30
|
+
"sharedFiles": [
|
|
31
|
+
"shared/types.ts",
|
|
32
|
+
"shared/home-integration.md",
|
|
33
|
+
"shared/actions.ts"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {},
|
|
36
|
+
"usage": "docs/BlockIntroCenter.md",
|
|
37
|
+
"example": "examples/BlockIntroCenter.json"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "BlockServiceList",
|
|
41
|
+
"scene": "home",
|
|
42
|
+
"entry": "components/BlockServiceList/index.tsx",
|
|
43
|
+
"files": [
|
|
44
|
+
"components/BlockServiceList/index.module.less",
|
|
45
|
+
"components/BlockServiceList/index.tsx"
|
|
46
|
+
],
|
|
47
|
+
"sharedFiles": [
|
|
48
|
+
"shared/types.ts",
|
|
49
|
+
"shared/home-integration.md",
|
|
50
|
+
"shared/actions.ts"
|
|
51
|
+
],
|
|
52
|
+
"dependencies": {},
|
|
53
|
+
"usage": "docs/BlockServiceList.md",
|
|
54
|
+
"example": "examples/BlockServiceList.json"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "BlockServiceIconList",
|
|
58
|
+
"scene": "home",
|
|
59
|
+
"entry": "components/BlockServiceIconList/index.tsx",
|
|
60
|
+
"files": [
|
|
61
|
+
"components/BlockServiceIconList/index.module.less",
|
|
62
|
+
"components/BlockServiceIconList/index.tsx"
|
|
63
|
+
],
|
|
64
|
+
"sharedFiles": [
|
|
65
|
+
"shared/types.ts",
|
|
66
|
+
"shared/home-integration.md",
|
|
67
|
+
"shared/actions.ts"
|
|
68
|
+
],
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"antd-mobile-icons": "0.3.0"
|
|
71
|
+
},
|
|
72
|
+
"usage": "docs/BlockServiceIconList.md",
|
|
73
|
+
"example": "examples/BlockServiceIconList.json"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "BlockQuestionList",
|
|
77
|
+
"scene": "home",
|
|
78
|
+
"entry": "components/BlockQuestionList/index.tsx",
|
|
79
|
+
"files": [
|
|
80
|
+
"components/BlockQuestionList/index.module.less",
|
|
81
|
+
"components/BlockQuestionList/index.tsx"
|
|
82
|
+
],
|
|
83
|
+
"sharedFiles": [
|
|
84
|
+
"shared/types.ts",
|
|
85
|
+
"shared/home-integration.md",
|
|
86
|
+
"shared/actions.ts"
|
|
87
|
+
],
|
|
88
|
+
"dependencies": {},
|
|
89
|
+
"usage": "docs/BlockQuestionList.md",
|
|
90
|
+
"example": "examples/BlockQuestionList.json"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "Banner",
|
|
94
|
+
"scene": "home",
|
|
95
|
+
"entry": "components/Banner/index.tsx",
|
|
96
|
+
"files": [
|
|
97
|
+
"components/Banner/index.module.less",
|
|
98
|
+
"components/Banner/index.tsx"
|
|
99
|
+
],
|
|
100
|
+
"sharedFiles": [
|
|
101
|
+
"shared/types.ts",
|
|
102
|
+
"shared/home-integration.md",
|
|
103
|
+
"shared/actions.ts"
|
|
104
|
+
],
|
|
105
|
+
"dependencies": {},
|
|
106
|
+
"usage": "docs/Banner.md",
|
|
107
|
+
"example": "examples/Banner.json"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "BlockNowList",
|
|
111
|
+
"scene": "home",
|
|
112
|
+
"entry": "components/BlockNowList/index.tsx",
|
|
113
|
+
"files": [
|
|
114
|
+
"components/BlockNowList/index.module.less",
|
|
115
|
+
"components/BlockNowList/index.tsx"
|
|
116
|
+
],
|
|
117
|
+
"sharedFiles": [
|
|
118
|
+
"shared/types.ts",
|
|
119
|
+
"shared/home-integration.md",
|
|
120
|
+
"shared/actions.ts"
|
|
121
|
+
],
|
|
122
|
+
"dependencies": {},
|
|
123
|
+
"usage": "docs/BlockNowList.md",
|
|
124
|
+
"example": "examples/BlockNowList.json"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": "BlockBarrage",
|
|
128
|
+
"scene": "home",
|
|
129
|
+
"entry": "components/BlockBarrage/index.tsx",
|
|
130
|
+
"files": [
|
|
131
|
+
"components/BlockBarrage/index.module.less",
|
|
132
|
+
"components/BlockBarrage/index.tsx"
|
|
133
|
+
],
|
|
134
|
+
"sharedFiles": [
|
|
135
|
+
"shared/types.ts",
|
|
136
|
+
"shared/home-integration.md",
|
|
137
|
+
"shared/actions.ts"
|
|
138
|
+
],
|
|
139
|
+
"dependencies": {},
|
|
140
|
+
"usage": "docs/BlockBarrage.md",
|
|
141
|
+
"example": "examples/BlockBarrage.json"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "BlockTravelCarousel",
|
|
145
|
+
"scene": "home",
|
|
146
|
+
"entry": "components/BlockTravelCarousel/index.tsx",
|
|
147
|
+
"files": [
|
|
148
|
+
"components/BlockTravelCarousel/index.module.less",
|
|
149
|
+
"components/BlockTravelCarousel/index.tsx",
|
|
150
|
+
"components/BlockTravelCarousel/tags/Tags.module.less",
|
|
151
|
+
"components/BlockTravelCarousel/tags/Tags.tsx"
|
|
152
|
+
],
|
|
153
|
+
"sharedFiles": [
|
|
154
|
+
"shared/types.ts",
|
|
155
|
+
"shared/home-integration.md",
|
|
156
|
+
"shared/actions.ts"
|
|
157
|
+
],
|
|
158
|
+
"dependencies": {
|
|
159
|
+
"antd-mobile": "5.39.0"
|
|
160
|
+
},
|
|
161
|
+
"usage": "docs/BlockTravelCarousel.md",
|
|
162
|
+
"example": "examples/BlockTravelCarousel.json"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"name": "BlockFanSwiper",
|
|
166
|
+
"scene": "home",
|
|
167
|
+
"entry": "components/BlockFanSwiper/index.tsx",
|
|
168
|
+
"files": [
|
|
169
|
+
"components/BlockFanSwiper/index.module.less",
|
|
170
|
+
"components/BlockFanSwiper/index.tsx"
|
|
171
|
+
],
|
|
172
|
+
"sharedFiles": [
|
|
173
|
+
"shared/types.ts",
|
|
174
|
+
"shared/home-integration.md",
|
|
175
|
+
"shared/actions.ts"
|
|
176
|
+
],
|
|
177
|
+
"dependencies": {},
|
|
178
|
+
"usage": "docs/BlockFanSwiper.md",
|
|
179
|
+
"example": "examples/BlockFanSwiper.json"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"name": "BlockAnimal",
|
|
183
|
+
"scene": "home",
|
|
184
|
+
"entry": "components/BlockAnimal/index.tsx",
|
|
185
|
+
"files": [
|
|
186
|
+
"components/BlockAnimal/LottiePlayer/index.module.less",
|
|
187
|
+
"components/BlockAnimal/LottiePlayer/index.tsx",
|
|
188
|
+
"components/BlockAnimal/LottiePlayer/utils.ts",
|
|
189
|
+
"components/BlockAnimal/index.module.less",
|
|
190
|
+
"components/BlockAnimal/index.tsx"
|
|
191
|
+
],
|
|
192
|
+
"sharedFiles": [
|
|
193
|
+
"shared/types.ts",
|
|
194
|
+
"shared/home-integration.md",
|
|
195
|
+
"shared/actions.ts"
|
|
196
|
+
],
|
|
197
|
+
"dependencies": {
|
|
198
|
+
"lottie-web": "5.13.0",
|
|
199
|
+
"jszip": "3.10.1"
|
|
200
|
+
},
|
|
201
|
+
"usage": "docs/BlockAnimal.md",
|
|
202
|
+
"example": "examples/BlockAnimal.json"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "OneCol",
|
|
206
|
+
"scene": "home",
|
|
207
|
+
"entry": "components/OneCol/index.tsx",
|
|
208
|
+
"files": [
|
|
209
|
+
"components/OneCol/index.module.less",
|
|
210
|
+
"components/OneCol/index.tsx"
|
|
211
|
+
],
|
|
212
|
+
"sharedFiles": [
|
|
213
|
+
"shared/types.ts",
|
|
214
|
+
"shared/home-integration.md",
|
|
215
|
+
"shared/actions.ts"
|
|
216
|
+
],
|
|
217
|
+
"dependencies": {},
|
|
218
|
+
"usage": "docs/OneCol.md",
|
|
219
|
+
"example": "examples/OneCol.json"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"name": "TwoCol",
|
|
223
|
+
"scene": "home",
|
|
224
|
+
"entry": "components/TwoCol/index.tsx",
|
|
225
|
+
"files": [
|
|
226
|
+
"components/TwoCol/index.module.less",
|
|
227
|
+
"components/TwoCol/index.tsx"
|
|
228
|
+
],
|
|
229
|
+
"sharedFiles": [
|
|
230
|
+
"shared/types.ts",
|
|
231
|
+
"shared/home-integration.md",
|
|
232
|
+
"shared/actions.ts"
|
|
233
|
+
],
|
|
234
|
+
"dependencies": {},
|
|
235
|
+
"usage": "docs/TwoCol.md",
|
|
236
|
+
"example": "examples/TwoCol.json"
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { runCardClick } from '../../shared/actions';
|
|
2
|
+
import type { CardAssetProps as ICardProps } from '../../shared/types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import styles from './index.module.less';
|
|
5
|
+
|
|
6
|
+
interface BannerProps extends ICardProps {
|
|
7
|
+
cardData?: {
|
|
8
|
+
bannerImage?: string;
|
|
9
|
+
clickAction?: string;
|
|
10
|
+
bannerJumpUrl?: string;
|
|
11
|
+
screenHeight?: number | string;
|
|
12
|
+
query?: string;
|
|
13
|
+
} & ICardProps['cardData'];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const Banner: React.FC<BannerProps> = ({ cardData = {}, bridgeAPI }) => {
|
|
17
|
+
const { bannerImage, bannerJumpUrl, clickAction, query } = cardData;
|
|
18
|
+
|
|
19
|
+
const handleClick = () => runCardClick(bridgeAPI, {
|
|
20
|
+
clickAction,
|
|
21
|
+
query,
|
|
22
|
+
jumpUrl: bannerJumpUrl,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!bannerImage) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className={styles.bannerContainer}>
|
|
31
|
+
<img src={bannerImage} alt="banner" className={styles.bannerImage} onClick={handleClick} />
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default Banner;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import lottie, { type AnimationItem } from 'lottie-web';
|
|
3
|
+
import styles from './index.module.less';
|
|
4
|
+
import { LottieLoader } from './utils';
|
|
5
|
+
|
|
6
|
+
/** Loads local/remote animation data and destroys stale instances. */
|
|
7
|
+
export default function LottiePlayer({ cardData }: { cardData: { djangoId: string; placeholder: string; fileType?: string } }) {
|
|
8
|
+
const container = useRef<HTMLDivElement>(null);
|
|
9
|
+
const [failed, setFailed] = useState(false);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
let disposed = false;
|
|
12
|
+
let animation: AnimationItem | undefined;
|
|
13
|
+
setFailed(false);
|
|
14
|
+
void (cardData.fileType === 'zip' ? LottieLoader.loadZIP(cardData.djangoId) : LottieLoader.load(cardData.djangoId)).then((animationData) => {
|
|
15
|
+
if (disposed || !container.current) return;
|
|
16
|
+
animation = lottie.loadAnimation({ container: container.current, renderer: 'svg', loop: true, autoplay: true, animationData });
|
|
17
|
+
}).catch(() => { if (!disposed) setFailed(true); });
|
|
18
|
+
return () => { disposed = true; animation?.destroy(); };
|
|
19
|
+
}, [cardData.djangoId, cardData.fileType]);
|
|
20
|
+
return <div className={styles.playerContainer}>
|
|
21
|
+
{failed && <img style={{ width: '100%' }} src={cardData.placeholder} alt="animation unavailable" />}
|
|
22
|
+
<div className={styles.animationWrapper} style={{ display: failed ? 'none' : undefined }} ref={container} />
|
|
23
|
+
</div>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import JSZip from 'jszip';
|
|
2
|
+
|
|
3
|
+
/** Standalone loader: ZIP images are embedded so no original container file service is needed. */
|
|
4
|
+
export class LottieLoader {
|
|
5
|
+
static detectFileType(source: string | File): string {
|
|
6
|
+
if (typeof File !== 'undefined' && source instanceof File) return source.name.split('.').pop()?.toLowerCase() || 'unknown';
|
|
7
|
+
if (typeof source !== 'string') return 'unknown';
|
|
8
|
+
if (source.startsWith('data:application/json')) return 'json';
|
|
9
|
+
if (source.startsWith('data:application/zip')) return 'zip';
|
|
10
|
+
const hint = source.split('?')[1]?.split('#')[0];
|
|
11
|
+
const type = new URLSearchParams(hint).get('fileType');
|
|
12
|
+
if (type === 'json' || type === 'zip') return type;
|
|
13
|
+
const extension = source.split(/[?#]/)[0].split('.').pop()?.toLowerCase();
|
|
14
|
+
return extension === 'json' || extension === 'zip' ? extension : 'url';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static async loadJSON(source: string | object): Promise<any> {
|
|
18
|
+
if (typeof source === 'object' && source !== null) return source;
|
|
19
|
+
if (typeof source !== 'string') throw new Error('不支持的JSON数据源');
|
|
20
|
+
if (/^(https?:\/\/|data:application\/json)/.test(source)) {
|
|
21
|
+
const response = await fetch(source);
|
|
22
|
+
if (!response.ok) throw new Error(`动画加载失败: ${response.status}`);
|
|
23
|
+
return response.json();
|
|
24
|
+
}
|
|
25
|
+
return JSON.parse(source);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static async loadZIP(source: string | File): Promise<any> {
|
|
29
|
+
let data: ArrayBuffer;
|
|
30
|
+
if (typeof File !== 'undefined' && source instanceof File) data = await source.arrayBuffer();
|
|
31
|
+
else {
|
|
32
|
+
const response = await fetch(source as string);
|
|
33
|
+
if (!response.ok) throw new Error(`动画加载失败: ${response.status}`);
|
|
34
|
+
data = await response.arrayBuffer();
|
|
35
|
+
}
|
|
36
|
+
const zip = await JSZip.loadAsync(data);
|
|
37
|
+
const names = Object.keys(zip.files).filter((name) => name.endsWith('.json') && !zip.files[name].dir);
|
|
38
|
+
names.sort((a, b) => Number(!/(^|\/)data.json$/.test(a)) - Number(!/(^|\/)data.json$/.test(b)));
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
let animation: any;
|
|
41
|
+
try { animation = JSON.parse(await zip.files[name].async('string')); } catch { continue; }
|
|
42
|
+
if (!this.validateLottieData(animation)) continue;
|
|
43
|
+
const base = name.slice(0, name.lastIndexOf('/') + 1);
|
|
44
|
+
for (const asset of animation.assets || []) {
|
|
45
|
+
if (!asset.p || asset.e === 1 || /^(data:|https?:)/.test(asset.p)) continue;
|
|
46
|
+
const image = zip.file(base + (asset.u || '') + asset.p);
|
|
47
|
+
if (!image) throw new Error(`动画图片缺失: ${asset.p}`);
|
|
48
|
+
const extension = asset.p.split('.').pop()?.toLowerCase();
|
|
49
|
+
const mime = extension === 'jpg' || extension === 'jpeg' ? 'image/jpeg' : extension === 'svg' ? 'image/svg+xml' : `image/${extension}`;
|
|
50
|
+
asset.p = `data:${mime};base64,${await image.async('base64')}`;
|
|
51
|
+
asset.u = '';
|
|
52
|
+
asset.e = 1;
|
|
53
|
+
}
|
|
54
|
+
return animation;
|
|
55
|
+
}
|
|
56
|
+
throw new Error('ZIP文件中未找到有效的Lottie动画数据');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static async load(source: string | File | object): Promise<any> {
|
|
60
|
+
if (typeof source === 'object' && !(typeof File !== 'undefined' && source instanceof File)) return this.loadJSON(source);
|
|
61
|
+
const type = this.detectFileType(source as string | File);
|
|
62
|
+
if (type === 'zip') return this.loadZIP(source as string | File);
|
|
63
|
+
if (typeof File !== 'undefined' && source instanceof File) return JSON.parse(await source.text());
|
|
64
|
+
return this.loadJSON(source);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static validateLottieData(data: any): boolean {
|
|
68
|
+
return !!data && typeof data === 'object' && typeof data.v === 'string' &&
|
|
69
|
+
Number.isFinite(data.fr) && Number.isFinite(data.ip) && Number.isFinite(data.op) &&
|
|
70
|
+
Number.isFinite(data.w) && Number.isFinite(data.h) && Array.isArray(data.layers);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
.blockAnimal {
|
|
2
|
+
min-width: 0;
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
position: relative;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
margin-bottom: 32px;
|
|
8
|
+
.blockContent {
|
|
9
|
+
position: relative;
|
|
10
|
+
}
|
|
11
|
+
.blockMedia {
|
|
12
|
+
min-height: 300px;
|
|
13
|
+
}
|
|
14
|
+
.animalGif {
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
.animalMp4 {
|
|
18
|
+
width: 100%;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.welcomeWrapper {
|
|
22
|
+
margin-top: 24px;
|
|
23
|
+
border-radius: 8px 48px 48px 48px;
|
|
24
|
+
padding: 24px 32px;
|
|
25
|
+
background: #1f3b63;
|
|
26
|
+
background: rgba(255, 255, 255, 0.4);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.welcomeText {
|
|
30
|
+
font-size: 30px;
|
|
31
|
+
color: #1f3b63;
|
|
32
|
+
letter-spacing: 0;
|
|
33
|
+
line-height: 48px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.tipsContainer {
|
|
37
|
+
position: absolute;
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: 100%;
|
|
40
|
+
top: 0;
|
|
41
|
+
left: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.lottieTips {
|
|
45
|
+
font-size: 24px;
|
|
46
|
+
position: absolute;
|
|
47
|
+
padding: 12px 24px;
|
|
48
|
+
background-color: #fff;
|
|
49
|
+
flex-direction: row;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
align-items: center;
|
|
52
|
+
border-radius: 37px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.tips-icon {
|
|
56
|
+
height: 28px;
|
|
57
|
+
width: 28px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.tipsTitle {
|
|
61
|
+
color: #1f3b63;
|
|
62
|
+
font-size: 26px;
|
|
63
|
+
margin-left: 8px;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
.guessbox {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
align-items: flex-start;
|
|
70
|
+
}
|
|
71
|
+
.guessItem {
|
|
72
|
+
background: rgba(255, 255, 255, 0.8);
|
|
73
|
+
border-radius: 31px;
|
|
74
|
+
padding: 8px 32px;
|
|
75
|
+
margin-top: 16px;
|
|
76
|
+
font-size: 26px;
|
|
77
|
+
line-height: 1.5;
|
|
78
|
+
color: #1f3b63;
|
|
79
|
+
display: inline-block;
|
|
80
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { runCardClick } from '../../shared/actions';
|
|
2
|
+
import type { CardAssetProps as ICardProps } from '../../shared/types';
|
|
3
|
+
import React, { useEffect } from 'react';
|
|
4
|
+
import LottiePlayer from './LottiePlayer';
|
|
5
|
+
import styles from './index.module.less';
|
|
6
|
+
|
|
7
|
+
interface IProps extends ICardProps {
|
|
8
|
+
cardData?: {
|
|
9
|
+
djangoId?: string;
|
|
10
|
+
fileType?: string;
|
|
11
|
+
desc?: string;
|
|
12
|
+
button?: Array<{
|
|
13
|
+
title: string;
|
|
14
|
+
clickAction: 'query' | 'jump' | 'link';
|
|
15
|
+
jumpUrl?: string;
|
|
16
|
+
query?: string;
|
|
17
|
+
location: { top: string; left: string };
|
|
18
|
+
}>;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
guessQuestionList?: any[];
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
} & ICardProps['cardData'];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const BlockAnimal: React.FC<IProps> = ({ cardData = {}, bridgeAPI }) => {
|
|
27
|
+
const { desc, button = [], guessQuestionList = [] } = cardData;
|
|
28
|
+
const [djangoData, setDjangoData] = React.useState({
|
|
29
|
+
djangoId: cardData.djangoId,
|
|
30
|
+
placeholder: cardData.placeholder,
|
|
31
|
+
fileType: cardData.fileType,
|
|
32
|
+
});
|
|
33
|
+
const queryObj = new URLSearchParams(djangoData.djangoId?.split('?')?.[1] || '');
|
|
34
|
+
const fileType = djangoData.fileType || queryObj.get('fileType') || djangoData.djangoId?.split(/[?#]/)[0].split('.').pop()?.toLowerCase();
|
|
35
|
+
|
|
36
|
+
// 更新djangoData
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setDjangoData({
|
|
39
|
+
djangoId: cardData.djangoId,
|
|
40
|
+
placeholder: cardData.placeholder,
|
|
41
|
+
fileType: cardData.fileType,
|
|
42
|
+
});
|
|
43
|
+
}, [cardData.djangoId, cardData.placeholder, cardData.fileType]);
|
|
44
|
+
|
|
45
|
+
const handleItemClick = (item: any) => {
|
|
46
|
+
let params = item;
|
|
47
|
+
if (typeof item === 'string') {
|
|
48
|
+
try { params = JSON.parse(item); } catch { return; }
|
|
49
|
+
}
|
|
50
|
+
if (!params || typeof params !== 'object') return;
|
|
51
|
+
|
|
52
|
+
setDjangoData({
|
|
53
|
+
djangoId: params.djangoId || djangoData.djangoId,
|
|
54
|
+
placeholder: params.placeholder || djangoData.placeholder,
|
|
55
|
+
fileType: params.fileType || (params.djangoId ? undefined : djangoData.fileType),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
runCardClick(bridgeAPI, params);
|
|
59
|
+
};
|
|
60
|
+
const handleQuery = (query: string) => {
|
|
61
|
+
bridgeAPI.sendQuery({
|
|
62
|
+
question_content: query,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const renderMedia = () => {
|
|
67
|
+
if (fileType === 'zip' || fileType === 'json') {
|
|
68
|
+
return <LottiePlayer cardData={{ djangoId: djangoData.djangoId || '', placeholder: djangoData.placeholder || '', fileType }} />;
|
|
69
|
+
}
|
|
70
|
+
if (['gif', 'png', 'jpg', 'jpeg', 'webp'].includes(fileType || '')) {
|
|
71
|
+
return <img className={styles.animalGif} src={djangoData.djangoId} alt="" />;
|
|
72
|
+
}
|
|
73
|
+
if (fileType === 'mp4') {
|
|
74
|
+
return <video playsInline className={styles.animalMp4} src={djangoData.djangoId} autoPlay muted loop controls={false} />;
|
|
75
|
+
}
|
|
76
|
+
return <img className={styles.animalGif} src={djangoData.placeholder} alt="" />;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className={styles.blockAnimal}>
|
|
81
|
+
<div className={styles.blockContent}>
|
|
82
|
+
<div className={styles.blockMedia}>{renderMedia()}</div>
|
|
83
|
+
{button.length > 0 && (
|
|
84
|
+
<div className={styles.tipsContainer}>
|
|
85
|
+
{button.map(
|
|
86
|
+
(item) =>
|
|
87
|
+
item && (
|
|
88
|
+
<div
|
|
89
|
+
key={`button-${item.title}-${item.query}`}
|
|
90
|
+
className={styles.lottieTips}
|
|
91
|
+
style={item.location}
|
|
92
|
+
onClick={() => handleItemClick(item)}
|
|
93
|
+
>
|
|
94
|
+
<span className={styles.tipsTitle}>{item.title}</span>
|
|
95
|
+
</div>
|
|
96
|
+
),
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
{desc && (
|
|
103
|
+
<div className={styles.welcomeWrapper}>
|
|
104
|
+
<div className={styles.welcomeText}>{desc}</div>
|
|
105
|
+
</div>
|
|
106
|
+
)}
|
|
107
|
+
{guessQuestionList?.length > 0 && (
|
|
108
|
+
<div className={styles.guessbox}>
|
|
109
|
+
{guessQuestionList.map((item) => (
|
|
110
|
+
<div key={`guess-${String(item)}`} className={styles.guessItem} onClick={() => handleQuery(item)}>
|
|
111
|
+
{item}
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default BlockAnimal;
|