bi-sdk-react 0.0.72 → 0.0.74

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bi-sdk-react",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/umd/js/bi-sdk.umd.min.js",
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { createFromIconfontCN } from "@ant-design/icons";
3
3
 
4
4
  const IconFontCN = createFromIconfontCN({
5
- scriptUrl: "https://at.alicdn.com/t/c/font_5072483_qyp3hlby2nr.js",
5
+ scriptUrl: "https://at.alicdn.com/t/c/font_5072483_dbprhooq0b9.js",
6
6
  });
7
7
 
8
8
  export type IconFontProps = {
@@ -1,9 +1,28 @@
1
1
  import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
2
- import React, { useContext, useEffect, useMemo, useRef } from "react";
2
+ import {
3
+ Card,
4
+ CheckboxOptionType,
5
+ Empty,
6
+ Flex,
7
+ Image,
8
+ Input,
9
+ Modal,
10
+ Pagination,
11
+ Radio,
12
+ Space,
13
+ Typography,
14
+ } from "antd";
15
+ import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
3
16
  import styled from "styled-components";
4
17
  import { PageContext } from "../context/PageContext";
5
18
  import { IconFont } from "../icon/IconFont";
6
- import { PluginType } from "../typing";
19
+ import {
20
+ ExampleItemType,
21
+ FetchType,
22
+ PluginType,
23
+ SchemaItemType,
24
+ TemplateItemType,
25
+ } from "../typing";
7
26
  import { uuid } from "../utils";
8
27
  import { PaneHeader } from "./PaneHeader";
9
28
 
@@ -51,6 +70,237 @@ const Root = styled.div`
51
70
  }
52
71
  `;
53
72
 
73
+ const EmptyImage = () => (
74
+ <svg
75
+ height="132"
76
+ version="1.1"
77
+ viewBox="0 0 148 132"
78
+ width="148"
79
+ xmlns="http://www.w3.org/2000/svg"
80
+ style={{
81
+ height: 80,
82
+ background: "#f5f5f5",
83
+ }}
84
+ >
85
+ <g node-id="23">
86
+ <path
87
+ d="M 116.04 26.83 L 95.88 26.83 L 95.88 19.15 C 95.88 18.62 95.45 18.19 94.92 18.19 L 88.20 18.19 C 87.67 18.19 87.24 18.62 87.24 19.15 L 87.24 26.83 L 56.52 26.83 L 56.52 19.15 C 56.52 18.62 56.09 18.19 55.56 18.19 L 48.84 18.19 C 48.31 18.19 47.88 18.62 47.88 19.15 L 47.88 26.83 L 27.72 26.83 C 26.70 26.83 25.72 27.24 25.00 27.96 C 24.28 28.68 23.88 29.65 23.88 30.67 L 23.88 110.35 C 23.88 111.37 24.28 112.35 25.00 113.07 C 25.72 113.79 26.70 114.19 27.72 114.19 L 116.04 114.19 C 117.06 114.20 118.04 113.79 118.76 113.07 C 119.48 112.35 119.88 111.37 119.88 110.36 L 119.88 30.67 C 119.88 29.65 119.48 28.67 118.76 27.95 C 118.04 27.23 117.06 26.83 116.04 26.83 Z"
88
+ fill="#e2e5f1"
89
+ fill-opacity="0.8"
90
+ fill-rule="nonzero"
91
+ group-id="1"
92
+ id="路径_2309"
93
+ node-id="3"
94
+ stroke="none"
95
+ target-height="96.005135"
96
+ target-width="96.00427"
97
+ target-x="23.878815"
98
+ target-y="18.189949"
99
+ />
100
+ </g>
101
+ <g node-id="24">
102
+ <path
103
+ d="M 29.95 122.53 L 27.74 118.71 L 46.79 107.71 L 49.00 111.53 Z M 54.50 99.05 L 16.39 121.05 L -0.00 92.66 L 38.10 70.66 L 54.49 99.05 Z M 21.46 95.65 L 17.57 110.02 C 17.54 110.12 17.55 110.23 17.61 110.31 C 17.66 110.40 17.74 110.47 17.84 110.50 L 20.30 111.15 C 20.40 111.18 20.51 111.16 20.60 111.11 C 20.69 111.06 20.76 110.98 20.79 110.88 L 23.91 99.34 L 31.57 101.37 C 31.68 101.40 31.78 101.39 31.87 101.33 C 31.96 101.28 32.03 101.19 32.05 101.10 L 37.43 81.25 C 37.46 81.15 37.45 81.04 37.39 80.95 C 37.34 80.86 37.25 80.80 37.15 80.77 L 34.69 80.13 C 34.48 80.07 34.27 80.20 34.21 80.40 L 29.60 97.41 L 21.94 95.38 C 21.84 95.36 21.73 95.37 21.65 95.43 C 21.55 95.47 21.49 95.56 21.46 95.66 Z"
104
+ fill="#417aff"
105
+ fill-opacity="0.8"
106
+ fill-rule="nonzero"
107
+ group-id="2"
108
+ id="联合_14"
109
+ node-id="4"
110
+ stroke="none"
111
+ target-height="51.876953"
112
+ target-width="54.5"
113
+ target-x="-0.00390625"
114
+ target-y="70.657715"
115
+ />
116
+ </g>
117
+ <g node-id="25">
118
+ <path
119
+ d="M 88.93 34.73 C 88.93 34.73 117.73 48.02 115.10 55.87 C 112.47 63.72 103.24 56.85 107.78 52.26 C 112.31 47.68 124.85 52.02 124.81 67.98 C 124.77 83.93 115.74 105.47 74.82 116.65"
120
+ fill="none"
121
+ group-id="3"
122
+ id="路径_2313"
123
+ node-id="5"
124
+ stroke="#c2c8d8"
125
+ stroke-dasharray="2 2"
126
+ stroke-linecap="butt"
127
+ stroke-opacity="0.8"
128
+ stroke-width="1"
129
+ target-height="81.921974"
130
+ target-width="50.02726"
131
+ target-x="74.82369"
132
+ target-y="34.732864"
133
+ />
134
+ </g>
135
+ <g node-id="26">
136
+ <g node-id="36">
137
+ <g node-id="38">
138
+ <path
139
+ d="M 142.32 93.93 C 139.32 93.93 136.89 91.50 136.89 88.49 C 136.89 85.49 139.32 83.06 142.32 83.06 C 145.33 83.06 147.76 85.49 147.76 88.49 C 147.74 91.49 145.32 93.91 142.32 93.93 Z M 142.32 84.92 C 140.35 84.92 138.76 86.52 138.76 88.49 C 138.76 90.46 140.35 92.06 142.32 92.06 C 144.29 92.06 145.89 90.46 145.89 88.49 C 145.88 86.53 144.29 84.94 142.32 84.92 Z"
140
+ fill="#a4bfff"
141
+ fill-opacity="0.8"
142
+ fill-rule="nonzero"
143
+ group-id="4,14,16"
144
+ id="路径_2292"
145
+ node-id="8"
146
+ stroke="none"
147
+ target-height="10.873993"
148
+ target-width="10.873993"
149
+ target-x="136.8869"
150
+ target-y="83.056"
151
+ />
152
+ </g>
153
+ </g>
154
+ </g>
155
+ <g node-id="27">
156
+ <g node-id="37">
157
+ <g node-id="39">
158
+ <path
159
+ d="M 24.03 49.65 L 15.77 41.38 L 24.03 33.12 L 32.30 41.38 Z M 18.66 41.38 L 24.11 46.84 L 29.57 41.38 L 24.11 35.92 Z"
160
+ fill="#c2c8d8"
161
+ fill-opacity="0.8"
162
+ fill-rule="nonzero"
163
+ group-id="5,15,17"
164
+ id="路径_2294"
165
+ node-id="11"
166
+ stroke="none"
167
+ target-height="16.531982"
168
+ target-width="16.531982"
169
+ target-x="15.768982"
170
+ target-y="33.115997"
171
+ />
172
+ </g>
173
+ </g>
174
+ </g>
175
+ <g node-id="28">
176
+ <path
177
+ d="M 60.87 132.43 C 60.31 132.43 59.87 131.98 59.87 131.43 L 59.87 127.81 L 56.25 127.81 C 55.70 127.81 55.25 127.36 55.25 126.81 L 55.25 125.72 C 55.25 125.17 55.70 124.72 56.25 124.72 L 59.87 124.72 L 59.87 121.11 C 59.87 120.55 60.31 120.11 60.87 120.11 L 61.95 120.11 C 62.50 120.11 62.95 120.55 62.95 121.11 L 62.95 124.72 L 66.57 124.72 C 67.12 124.72 67.57 125.17 67.57 125.72 L 67.57 126.81 C 67.57 127.36 67.12 127.81 66.57 127.81 L 62.95 127.81 L 62.95 131.43 C 62.95 131.98 62.50 132.43 61.95 132.43 Z"
178
+ fill="#c2c8d8"
179
+ fill-opacity="0.8"
180
+ fill-rule="nonzero"
181
+ group-id="6"
182
+ id="联合_16"
183
+ node-id="12"
184
+ stroke="none"
185
+ target-height="12.322006"
186
+ target-width="12.319"
187
+ target-x="55.247986"
188
+ target-y="120.106995"
189
+ />
190
+ </g>
191
+ <g node-id="29">
192
+ <path
193
+ d="M 9.55 20.92 C 9.00 20.92 8.55 20.47 8.55 19.92 L 8.55 17.36 L 6.00 17.36 C 5.44 17.36 5.00 16.92 5.00 16.36 L 5.00 15.99 C 5.00 15.44 5.44 14.99 6.00 14.99 L 8.55 14.99 L 8.55 12.44 C 8.55 11.88 9.00 11.44 9.55 11.44 L 9.92 11.44 C 10.48 11.44 10.92 11.88 10.92 12.44 L 10.92 14.99 L 13.48 14.99 C 14.03 14.99 14.48 15.44 14.48 15.99 L 14.48 16.36 C 14.48 16.91 14.03 17.36 13.48 17.36 L 10.92 17.36 L 10.92 19.92 C 10.92 20.47 10.48 20.92 9.92 20.92 Z"
194
+ fill="#417aff"
195
+ fill-opacity="0"
196
+ fill-rule="nonzero"
197
+ group-id="7"
198
+ id="联合_17"
199
+ node-id="13"
200
+ stroke="none"
201
+ target-height="9.483"
202
+ target-width="9.483"
203
+ target-x="4.9959717"
204
+ target-y="11.435974"
205
+ />
206
+ </g>
207
+ <g node-id="30">
208
+ <path
209
+ d="M 94.70 28.55 C 91.61 31.22 88.07 33.31 84.23 34.72 C 81.19 35.89 77.81 37.03 74.50 36.67 C 72.71 36.48 70.99 35.89 69.46 34.94 C 67.45 33.45 65.68 31.67 64.19 29.66 C 63.27 28.56 62.28 28.70 61.16 29.47 C 60.46 29.95 60.14 31.27 59.52 31.64 C 58.72 32.12 58.08 31.82 58.36 30.67 C 58.75 29.08 61.51 27.88 62.94 27.74 C 62.89 25.08 65.70 21.30 67.79 19.89 C 75.73 14.53 85.75 18.26 91.90 24.45 C 92.18 24.72 95.36 27.95 94.70 28.55 Z"
210
+ fill="#697391"
211
+ fill-opacity="0.8"
212
+ fill-rule="nonzero"
213
+ group-id="8"
214
+ id="路径_2314"
215
+ node-id="14"
216
+ stroke="none"
217
+ target-height="22.502167"
218
+ target-width="37.280975"
219
+ target-x="58.082336"
220
+ target-y="14.527588"
221
+ />
222
+ </g>
223
+ <g node-id="31">
224
+ <path
225
+ d="M 126.97 51.55 C 125.23 50.94 123.61 50.03 122.19 48.85 C 120.95 47.97 119.94 46.82 119.23 45.48 C 118.90 44.74 118.74 43.93 118.77 43.12 C 118.90 42.00 119.19 40.90 119.64 39.87 C 119.86 39.26 119.59 38.90 119.03 38.63 C 118.69 38.47 118.09 38.64 117.81 38.48 C 117.45 38.28 117.42 37.97 117.93 37.81 C 118.64 37.60 119.73 38.42 120.11 38.94 C 121.46 38.42 122.96 38.47 124.28 39.07 C 128.17 40.96 128.97 45.72 127.94 49.52 C 127.90 49.69 127.35 51.67 126.97 51.55 Z"
226
+ fill="#697391"
227
+ fill-opacity="0.8"
228
+ fill-rule="nonzero"
229
+ group-id="9"
230
+ id="路径_2316"
231
+ node-id="15"
232
+ stroke="none"
233
+ target-height="14.066719"
234
+ target-width="11.554443"
235
+ target-x="117.418564"
236
+ target-y="37.602352"
237
+ />
238
+ </g>
239
+ <g node-id="32">
240
+ <path
241
+ d="M 88.52 10.94 C 87.19 10.59 85.93 10.00 84.81 9.21 C 83.88 8.67 83.11 7.90 82.56 6.97 C 82.32 6.46 82.22 5.91 82.26 5.35 C 82.40 4.55 82.67 3.78 83.05 3.07 C 83.25 2.64 83.03 2.40 82.60 2.24 C 82.33 2.13 81.86 2.27 81.64 2.17 C 81.36 2.04 81.34 1.82 81.75 1.70 C 82.32 1.53 83.17 2.06 83.45 2.42 C 84.51 2.02 85.68 2.01 86.75 2.38 C 89.78 3.58 90.28 6.85 89.35 9.51 C 89.31 9.63 88.82 11.02 88.52 10.94 Z"
242
+ fill="#697391"
243
+ fill-opacity="0"
244
+ fill-rule="nonzero"
245
+ group-id="10"
246
+ id="路径_2317"
247
+ node-id="16"
248
+ stroke="none"
249
+ target-height="9.480836"
250
+ target-width="8.940781"
251
+ target-x="81.3402"
252
+ target-y="1.5345681"
253
+ />
254
+ </g>
255
+ <g node-id="33">
256
+ <path
257
+ d="M 110.05 85.50 C 111.54 83.78 112.70 81.80 113.49 79.67 C 114.27 77.97 114.64 76.11 114.57 74.25 C 114.47 73.25 114.14 72.29 113.61 71.44 C 112.78 70.32 111.79 69.33 110.67 68.51 C 110.06 68.00 110.13 67.44 110.56 66.82 C 110.83 66.43 111.57 66.24 111.77 65.90 C 112.04 65.46 111.87 65.10 111.23 65.25 C 110.34 65.47 109.68 67.02 109.60 67.81 C 108.11 67.78 106.01 69.35 105.22 70.51 C 102.24 74.93 104.32 80.51 107.76 83.94 C 107.92 84.09 109.72 85.87 110.05 85.50 Z"
258
+ fill="#697391"
259
+ fill-opacity="0"
260
+ fill-rule="nonzero"
261
+ group-id="11"
262
+ id="路径_2318"
263
+ node-id="17"
264
+ stroke="none"
265
+ target-height="20.767654"
266
+ target-width="12.403198"
267
+ target-x="102.238434"
268
+ target-y="65.100204"
269
+ />
270
+ </g>
271
+ <g node-id="34">
272
+ <path
273
+ d="M 104.48 112.46 C 105.55 112.38 106.59 112.11 107.56 111.66 C 108.38 111.36 109.12 110.87 109.72 110.22 C 110.01 109.86 110.22 109.43 110.33 108.97 C 110.42 108.32 110.42 107.67 110.33 107.02 C 110.30 106.65 110.51 106.49 110.86 106.43 C 111.07 106.39 111.38 106.57 111.56 106.52 C 111.79 106.47 111.86 106.29 111.59 106.13 C 111.23 105.91 110.50 106.20 110.21 106.44 C 109.53 105.94 108.68 105.74 107.86 105.88 C 105.40 106.36 104.24 108.90 104.24 111.18 C 104.24 111.28 104.25 112.47 104.48 112.46 Z"
274
+ fill="#697391"
275
+ fill-opacity="0"
276
+ fill-rule="nonzero"
277
+ group-id="12"
278
+ id="路径_2319"
279
+ node-id="18"
280
+ stroke="none"
281
+ target-height="6.72332"
282
+ target-width="7.620468"
283
+ target-x="104.23713"
284
+ target-y="105.74457"
285
+ />
286
+ </g>
287
+ <path
288
+ d="M 80.35 75.78 L 88.84 67.29 L 93.08 71.53 L 84.59 80.02 Z M 51.88 71.04 L 56.12 66.80 L 64.61 75.28 L 60.36 79.52 Z M 69.48 73.29 L 69.48 61.29 L 75.48 61.29 L 75.48 73.29 Z"
289
+ fill="#ffffff"
290
+ fill-opacity="0.8"
291
+ fill-rule="nonzero"
292
+ group-id="13"
293
+ id="联合_21"
294
+ node-id="19"
295
+ stroke="none"
296
+ target-height="18.728516"
297
+ target-width="41.197266"
298
+ target-x="51.88086"
299
+ target-y="61.29297"
300
+ />
301
+ </svg>
302
+ );
303
+
54
304
  const PluginTile: React.FC<{ plugin: PluginType }> = ({ plugin }) => {
55
305
  const ref: React.RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
56
306
 
@@ -88,8 +338,266 @@ const PluginTile: React.FC<{ plugin: PluginType }> = ({ plugin }) => {
88
338
  );
89
339
  };
90
340
 
341
+ const cloneItem = (node: SchemaItemType): SchemaItemType => {
342
+ const newNode = { ...node, id: uuid() };
343
+
344
+ if (node.children) {
345
+ if (Array.isArray(node.children)) {
346
+ newNode.children = node.children.map(cloneItem);
347
+ } else {
348
+ const newChildren: Record<string, SchemaItemType[]> = {};
349
+ Object.keys(node.children).forEach((key) => {
350
+ newChildren[key] = (node.children as Record<string, SchemaItemType[]>)[
351
+ key
352
+ ].map(cloneItem);
353
+ });
354
+ newNode.children = newChildren;
355
+ }
356
+ }
357
+ return newNode;
358
+ };
359
+
360
+ const ExampleItem: React.FC<{
361
+ data: ExampleItemType;
362
+ fetch: FetchType;
363
+ }> = ({ data }) => {
364
+ const ref: React.RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
365
+
366
+ /**
367
+ * 注册拖拽源:仅在设计模式下启用
368
+ */
369
+ useEffect(() => {
370
+ if (!data) {
371
+ return;
372
+ }
373
+ const el = ref.current;
374
+ if (!el) return;
375
+ const cleanup = draggable({
376
+ element: el,
377
+ getInitialData: () => {
378
+ const e = cloneItem(JSON.parse(JSON.stringify(data.item || {})));
379
+ return {
380
+ id: e.id,
381
+ data: e,
382
+ };
383
+ },
384
+ canDrag: () => true,
385
+ onDragStart: () => {},
386
+ onDrop: () => {},
387
+ });
388
+ return () => cleanup();
389
+ }, [data]);
390
+
391
+ return (
392
+ <div className="drag-move" ref={ref}>
393
+ <Card
394
+ size="small"
395
+ key={data.id}
396
+ cover={
397
+ data.cover?.length ? (
398
+ <Image
399
+ src={data.cover}
400
+ style={{
401
+ height: 80,
402
+ background: "#f5f5f5",
403
+ }}
404
+ />
405
+ ) : (
406
+ <EmptyImage />
407
+ )
408
+ }
409
+ variant="outlined"
410
+ style={{ cursor: "move" }}
411
+ >
412
+ <Card.Meta
413
+ title={data.name}
414
+ description={
415
+ <Typography.Text
416
+ ellipsis={{ tooltip: data.description || "暂无描述" }}
417
+ style={{ color: "var(--ant-color-text-description)" }}
418
+ >
419
+ {data.description}
420
+ </Typography.Text>
421
+ }
422
+ />
423
+ </Card>
424
+ </div>
425
+ );
426
+ };
427
+
428
+ const ExampleList: React.FC<{ fetch: FetchType }> = ({ fetch }) => {
429
+ const [total, setTotal] = useState(-1);
430
+ const [page, setPage] = useState(1);
431
+ const [size, setSize] = useState(20);
432
+ const [keyword, setKeyword] = useState("");
433
+ const [list, setList] = useState<ExampleItemType[]>([]);
434
+
435
+ const fetchList = async () => {
436
+ const res = await fetch.exampleList?.(page, size, keyword);
437
+ if (Array.isArray(res)) {
438
+ setList(res);
439
+ setTotal(-1);
440
+ } else if (typeof res === "object") {
441
+ setList(res.list || []);
442
+ setTotal(res.total);
443
+ }
444
+ };
445
+
446
+ useEffect(() => {
447
+ fetchList();
448
+ }, [page, size, keyword]);
449
+
450
+ return (
451
+ <Flex vertical={true} gap={12} style={{ height: "100%" }}>
452
+ <Input.Search
453
+ size="small"
454
+ value={keyword}
455
+ placeholder="输入关键字检索"
456
+ onChange={(e) => setKeyword(e.target.value)}
457
+ />
458
+ <Space orientation="vertical" style={{ flex: "auto", overflow: "auto" }}>
459
+ {list.map((item) => (
460
+ <ExampleItem key={item.id} data={item} fetch={fetch} />
461
+ ))}
462
+ </Space>
463
+ {total >= 0 && (
464
+ <Pagination
465
+ align="center"
466
+ size="small"
467
+ current={page}
468
+ pageSize={size}
469
+ total={total}
470
+ hideOnSinglePage={true}
471
+ onChange={(page, pageSize) => {
472
+ setPage(page);
473
+ setSize(pageSize);
474
+ }}
475
+ />
476
+ )}
477
+ </Flex>
478
+ );
479
+ };
480
+
481
+ const TemplateItem: React.FC<{
482
+ data: Omit<TemplateItemType, "schema">;
483
+ fetch: FetchType;
484
+ }> = ({ data, fetch }) => {
485
+ const { schema, setSchema } = useContext(PageContext);
486
+
487
+
488
+ const handleClick = async () => {
489
+ const item = await fetch?.templateDetail?.(data.id);
490
+ if (!item?.schema) {
491
+ return;
492
+ }
493
+ const next = JSON.parse(JSON.stringify(item.schema));
494
+ if (schema.items.length === 0) {
495
+ setSchema(next);
496
+ } else {
497
+ Modal.confirm({
498
+ title: "提示",
499
+ content: "确认加载该模板页面,加载后会替换现有页面内容。",
500
+ okText: "确认",
501
+ cancelText: "取消",
502
+ onOk() {
503
+ setSchema(next);
504
+ },
505
+ });
506
+ }
507
+ };
508
+
509
+ return (
510
+ <Card
511
+ size="small"
512
+ key={data.id}
513
+ cover={
514
+ data.cover?.length ? (
515
+ <Image
516
+ src={data.cover}
517
+ style={{
518
+ height: 80,
519
+ background: "#f5f5f5",
520
+ }}
521
+ />
522
+ ) : (
523
+ <EmptyImage />
524
+ )
525
+ }
526
+ variant="outlined"
527
+ style={{ cursor: "pointer" }}
528
+ onClick={handleClick}
529
+ >
530
+ <Card.Meta
531
+ title={data.name}
532
+ description={
533
+ <Typography.Text
534
+ ellipsis={{ tooltip: data.description || "暂无描述" }}
535
+ style={{ color: "var(--ant-color-text-description)" }}
536
+ >
537
+ {data.description}
538
+ </Typography.Text>
539
+ }
540
+ />
541
+ </Card>
542
+ );
543
+ };
544
+
545
+ const TemplateList: React.FC<{ fetch: FetchType }> = ({ fetch }) => {
546
+ const [total, setTotal] = useState(-1);
547
+ const [page, setPage] = useState(1);
548
+ const [size, setSize] = useState(20);
549
+ const [keyword, setKeyword] = useState("");
550
+ const [list, setList] = useState<Omit<TemplateItemType, "schema">[]>([]);
551
+
552
+ const fetchList = async () => {
553
+ const res = await fetch.templateList?.(page, size, keyword);
554
+ if (Array.isArray(res)) {
555
+ setList(res);
556
+ setTotal(-1);
557
+ } else if (typeof res === "object") {
558
+ setList(res.list || []);
559
+ setTotal(res.total);
560
+ }
561
+ };
562
+
563
+ useEffect(() => {
564
+ fetchList();
565
+ }, [page, size, keyword]);
566
+
567
+ return (
568
+ <Flex vertical={true} gap={12} style={{ height: "100%" }}>
569
+ <Input.Search
570
+ size="small"
571
+ value={keyword}
572
+ placeholder="输入关键字检索"
573
+ onChange={(e) => setKeyword(e.target.value)}
574
+ />
575
+ <Space orientation="vertical" style={{ flex: "auto", overflow: "auto" }}>
576
+ {list.map((item) => (
577
+ <TemplateItem key={item.id} data={item} fetch={fetch} />
578
+ ))}
579
+ </Space>
580
+ {total >= 0 && (
581
+ <Pagination
582
+ align="center"
583
+ size="small"
584
+ current={page}
585
+ pageSize={size}
586
+ total={total}
587
+ hideOnSinglePage={true}
588
+ onChange={(page, pageSize) => {
589
+ setPage(page);
590
+ setSize(pageSize);
591
+ }}
592
+ />
593
+ )}
594
+ </Flex>
595
+ );
596
+ };
597
+
91
598
  export const ComponentPanel: React.FC = () => {
92
- const { plugins } = useContext(PageContext);
599
+ const { plugins, fetch } = useContext(PageContext);
600
+ const [tab, setTab] = useState("component");
93
601
  const grouped = useMemo(() => {
94
602
  const grouped: { group: string; items: PluginType[] }[] = [];
95
603
  plugins.forEach((item) => {
@@ -99,20 +607,63 @@ export const ComponentPanel: React.FC = () => {
99
607
  });
100
608
  return grouped;
101
609
  }, [plugins]);
610
+
611
+ const headerOptions: CheckboxOptionType<string>[] = useMemo(() => {
612
+ const options = [
613
+ {
614
+ label: "组件",
615
+ value: "component",
616
+ },
617
+ ];
618
+ if (fetch?.exampleList) {
619
+ options.push({
620
+ label: "片段",
621
+ value: "chunk",
622
+ });
623
+ }
624
+ if (fetch?.templateList && fetch?.templateDetail) {
625
+ options.push({
626
+ label: "模板",
627
+ value: "template",
628
+ });
629
+ }
630
+ return options;
631
+ }, [
632
+ fetch?.exampleList,
633
+ fetch?.templateList,
634
+ fetch?.templateDetail,
635
+ ]);
102
636
  return (
103
637
  <Root className="component-panel">
104
- <PaneHeader title="组件库" />
638
+ <PaneHeader
639
+ title={
640
+ headerOptions.length === 1 ? (
641
+ headerOptions[0].label
642
+ ) : (
643
+ <Radio.Group
644
+ size="small"
645
+ optionType="button"
646
+ value={tab}
647
+ options={headerOptions}
648
+ onChange={(e) => setTab(e.target.value)}
649
+ />
650
+ )
651
+ }
652
+ />
105
653
  <div className="body beautified_scrollbar">
106
- {grouped.map((group) => (
107
- <div className="plugin-group" key={group.group}>
108
- <div className="group-title">{group.group}</div>
109
- <div className="plugin-list">
110
- {group.items.map((item) => (
111
- <PluginTile key={item.key} plugin={item} />
112
- ))}
654
+ {tab === "component" &&
655
+ grouped.map((group) => (
656
+ <div className="plugin-group" key={group.group}>
657
+ <div className="group-title">{group.group}</div>
658
+ <div className="plugin-list">
659
+ {group.items.map((item) => (
660
+ <PluginTile key={item.key} plugin={item} />
661
+ ))}
662
+ </div>
113
663
  </div>
114
- </div>
115
- ))}
664
+ ))}
665
+ {tab === "chunk" && fetch && <ExampleList fetch={fetch} />}
666
+ {tab === "template" && fetch && <TemplateList fetch={fetch} />}
116
667
  </div>
117
668
  </Root>
118
669
  );
@@ -1,11 +1,11 @@
1
- import React from 'react'
2
- import styled from 'styled-components'
1
+ import React from "react";
2
+ import styled from "styled-components";
3
3
 
4
4
  export type PaneHeaderProps = {
5
- title?: string
6
- extra?: React.ReactNode
7
- style?: React.CSSProperties
8
- }
5
+ title?: React.ReactNode;
6
+ extra?: React.ReactNode;
7
+ style?: React.CSSProperties;
8
+ };
9
9
 
10
10
  const Header = styled.div`
11
11
  width: 100%;
@@ -23,13 +23,17 @@ const Header = styled.div`
23
23
  .extra {
24
24
  line-height: 32px;
25
25
  }
26
- `
26
+ `;
27
27
 
28
- export const PaneHeader: React.FC<PaneHeaderProps> = ({ title = '', extra, style = {} }) => {
28
+ export const PaneHeader: React.FC<PaneHeaderProps> = ({
29
+ title = "",
30
+ extra,
31
+ style = {},
32
+ }) => {
29
33
  return (
30
34
  <Header className="pane-header" style={style}>
31
35
  <span className="title">{title}</span>
32
36
  <div className="extra">{extra}</div>
33
37
  </Header>
34
- )
35
- }
38
+ );
39
+ };