bi-sdk-react 0.0.26 → 0.0.27
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/dist/es/js/bi-sdk.es.js +34 -34
- package/dist/types/components/context/PageContext.d.ts +12 -2
- package/dist/types/components/hooks/datasource.d.ts +2 -1
- package/dist/types/components/index.d.ts +1 -3
- package/dist/types/components/layout/PageCanvas.d.ts +0 -2
- package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +1 -1
- package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +1 -1
- package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +1 -1
- package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +3 -3
- package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +1 -1
- package/dist/types/components/plugins/@antd/items/InputRender.d.ts +2 -2
- package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +2 -2
- package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +1 -1
- package/dist/types/components/plugins/@antd/items/TableRender.d.ts +1 -1
- package/dist/types/components/typing.d.ts +6 -2
- package/dist/types/components/utils.d.ts +0 -8
- package/dist/umd/js/bi-sdk.umd.min.js +34 -34
- package/package.json +1 -1
- package/src/components/PageDesigner.tsx +0 -1
- package/src/components/context/PageContext.tsx +106 -3
- package/src/components/hooks/datasource.ts +29 -10
- package/src/components/index.ts +4 -10
- package/src/components/layout/PageCanvas.tsx +13 -45
- package/src/components/panel/LayerPanel.tsx +0 -2
- package/src/components/panel/PropertiesPanel.tsx +11 -1
- package/src/components/plugins/@antd/items/ButtonRender.tsx +7 -6
- package/src/components/plugins/@antd/items/CapsuleRender.tsx +6 -6
- package/src/components/plugins/@antd/items/CheckboxRender.tsx +6 -6
- package/src/components/plugins/@antd/items/ColRender.tsx +2 -4
- package/src/components/plugins/@antd/items/DatePickerRender.tsx +8 -8
- package/src/components/plugins/@antd/items/EchartsRender.tsx +31 -16
- package/src/components/plugins/@antd/items/HtmlRender.tsx +22 -13
- package/src/components/plugins/@antd/items/InputNumberRender.tsx +5 -6
- package/src/components/plugins/@antd/items/InputRender.tsx +6 -7
- package/src/components/plugins/@antd/items/ListRender.tsx +19 -15
- package/src/components/plugins/@antd/items/SelectRender.tsx +6 -7
- package/src/components/plugins/@antd/items/SwitchRender.tsx +5 -6
- package/src/components/plugins/@antd/items/TableRender.tsx +4 -6
- package/src/components/typing.ts +7 -1
- package/src/components/utils.ts +0 -34
- package/src/example.tsx +1 -1
- package/src/components/context/EnvContext.tsx +0 -45
package/package.json
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import { createContext, useState } from "react";
|
|
2
|
-
import {
|
|
1
|
+
import { createContext, useEffect, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
CallbacksType,
|
|
4
|
+
CallbackType,
|
|
5
|
+
DatasetAddFunction,
|
|
6
|
+
DatasetSelectorFunction,
|
|
7
|
+
EnvType,
|
|
8
|
+
FetchType,
|
|
9
|
+
PageSchema,
|
|
10
|
+
PluginType,
|
|
11
|
+
SchemaItemType,
|
|
12
|
+
} from "../typing";
|
|
13
|
+
|
|
14
|
+
type InitCallbackParams = {
|
|
15
|
+
id: string;
|
|
16
|
+
callback: CallbackType;
|
|
17
|
+
};
|
|
3
18
|
|
|
4
19
|
type PageContextType = {
|
|
5
20
|
pageId: string;
|
|
@@ -17,6 +32,17 @@ type PageContextType = {
|
|
|
17
32
|
onAddAtItem?: (item: SchemaItemType) => void;
|
|
18
33
|
onRemoveAtItem?: (item: SchemaItemType, index?: number) => void;
|
|
19
34
|
fetch?: FetchType;
|
|
35
|
+
|
|
36
|
+
deviceWidth: number;
|
|
37
|
+
setDeviceWidth: (width: number) => void;
|
|
38
|
+
initCallback: ({ id, callback }: InitCallbackParams) => any;
|
|
39
|
+
handleCallback: (
|
|
40
|
+
item: SchemaItemType,
|
|
41
|
+
refresh?: boolean,
|
|
42
|
+
consume?: (item: Omit<SchemaItemType, "children">, data: any) => void,
|
|
43
|
+
) => void;
|
|
44
|
+
getVars: (id: string) => Record<string, any>;
|
|
45
|
+
setVar: (item: SchemaItemType, key: string, value: any) => void;
|
|
20
46
|
};
|
|
21
47
|
|
|
22
48
|
export const PageContext = createContext<PageContextType>({
|
|
@@ -41,12 +67,27 @@ export const PageContext = createContext<PageContextType>({
|
|
|
41
67
|
datasetSelector: undefined,
|
|
42
68
|
datasetAdd: undefined,
|
|
43
69
|
fetch: undefined,
|
|
70
|
+
|
|
71
|
+
deviceWidth: 0,
|
|
72
|
+
setDeviceWidth: () => {},
|
|
73
|
+
initCallback: () => {},
|
|
74
|
+
handleCallback: () => {},
|
|
75
|
+
getVars: () => ({}),
|
|
76
|
+
setVar: () => {},
|
|
44
77
|
});
|
|
45
78
|
|
|
46
79
|
type PageProviderProps = React.PropsWithChildren<
|
|
47
80
|
Omit<
|
|
48
81
|
Partial<PageContextType>,
|
|
49
|
-
|
|
82
|
+
| "updateSelectedItem"
|
|
83
|
+
| "schema"
|
|
84
|
+
| "forceUpdate"
|
|
85
|
+
| "deviceWidth"
|
|
86
|
+
| "setDeviceWidth"
|
|
87
|
+
| "initCallback"
|
|
88
|
+
| "handleCallback"
|
|
89
|
+
| "getVars"
|
|
90
|
+
| "setVar"
|
|
50
91
|
> &
|
|
51
92
|
Pick<PageContextType, "schema" | "pageId">
|
|
52
93
|
>;
|
|
@@ -64,6 +105,7 @@ export const PageProvider: React.FC<PageProviderProps> = ({
|
|
|
64
105
|
fetch,
|
|
65
106
|
children,
|
|
66
107
|
}) => {
|
|
108
|
+
const [deviceWidth, setDeviceWidth] = useState<number>(0);
|
|
67
109
|
const updateSelectedItem = (props?: Partial<SchemaItemType> | null) => {
|
|
68
110
|
setSelectedItem?.(Object.assign(selectedItem!, props || {}));
|
|
69
111
|
setSchema?.({ ...schema });
|
|
@@ -76,6 +118,60 @@ export const PageProvider: React.FC<PageProviderProps> = ({
|
|
|
76
118
|
const onRemoveAtItem = (item: SchemaItemType) => {
|
|
77
119
|
setAtItems(atItems!.filter((i) => i !== item));
|
|
78
120
|
};
|
|
121
|
+
|
|
122
|
+
const [env, setEnv] = useState<EnvType>({ global: {}, local: {} });
|
|
123
|
+
const [callbacks, setCallbacks] = useState<CallbacksType>({});
|
|
124
|
+
|
|
125
|
+
const initCallback = ({
|
|
126
|
+
id,
|
|
127
|
+
callback,
|
|
128
|
+
}: {
|
|
129
|
+
id: string;
|
|
130
|
+
callback: (v: any) => void;
|
|
131
|
+
}) => {
|
|
132
|
+
setCallbacks((c) => ({ ...c, [id]: callback }));
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleCallback = (
|
|
136
|
+
item: SchemaItemType,
|
|
137
|
+
refresh?: boolean,
|
|
138
|
+
consume?: (item: Omit<SchemaItemType, "children">, data: any) => void,
|
|
139
|
+
) => {
|
|
140
|
+
(item.cascadeIds || []).forEach((id) => {
|
|
141
|
+
const cb = callbacks[id];
|
|
142
|
+
if (typeof cb === "function") {
|
|
143
|
+
const vars = getVars(id);
|
|
144
|
+
const res = cb(refresh, vars);
|
|
145
|
+
if (res) {
|
|
146
|
+
const { target: cbItem, data: cbData } = res;
|
|
147
|
+
consume?.(cbItem, cbData);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const getVars = (id: string) => {
|
|
154
|
+
return {
|
|
155
|
+
...env.global,
|
|
156
|
+
...(env.local[id || ""] || {}),
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const setVar = (item: SchemaItemType, key: string, value: any) => {
|
|
161
|
+
const next = { ...env };
|
|
162
|
+
(item.cascadeIds || []).forEach((id) => {
|
|
163
|
+
next.local[id] = next.local[id] || {};
|
|
164
|
+
next.local[id][key] = value;
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
const nextGlobal: Record<string, any> = {};
|
|
170
|
+
(schema.variables || []).forEach((item) => {
|
|
171
|
+
nextGlobal[item.name] = item.value;
|
|
172
|
+
});
|
|
173
|
+
setEnv((e: EnvType) => ({ ...e, global: nextGlobal }));
|
|
174
|
+
}, [schema.variables]);
|
|
79
175
|
return (
|
|
80
176
|
<PageContext.Provider
|
|
81
177
|
value={{
|
|
@@ -96,6 +192,13 @@ export const PageProvider: React.FC<PageProviderProps> = ({
|
|
|
96
192
|
},
|
|
97
193
|
onAddAtItem,
|
|
98
194
|
onRemoveAtItem,
|
|
195
|
+
|
|
196
|
+
deviceWidth,
|
|
197
|
+
setDeviceWidth: setDeviceWidth || (() => {}),
|
|
198
|
+
initCallback,
|
|
199
|
+
handleCallback,
|
|
200
|
+
getVars,
|
|
201
|
+
setVar,
|
|
99
202
|
}}
|
|
100
203
|
>
|
|
101
204
|
{children}
|
|
@@ -1,24 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
|
+
import { PageContext } from "../context/PageContext";
|
|
2
3
|
import { SchemaItemType } from "../typing";
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export type Signal = string | number;
|
|
6
|
+
|
|
7
|
+
export const useDatasource = (item: SchemaItemType, signal?: Signal): any => {
|
|
8
|
+
const [datasource, setDatasource] = useState<any>(null);
|
|
9
|
+
const { fetch, getVars } = useContext(PageContext);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!item?.datasource) {
|
|
12
|
+
return setDatasource(null);
|
|
8
13
|
}
|
|
9
|
-
const source = datasource.source || "custom";
|
|
14
|
+
const source = item?.datasource.source || "custom";
|
|
10
15
|
switch (source) {
|
|
11
16
|
case "custom":
|
|
12
17
|
try {
|
|
13
|
-
return JSON.parse(datasource.custom || "[]");
|
|
18
|
+
return setDatasource(JSON.parse(item?.datasource.custom || "[]"));
|
|
14
19
|
} catch (e) {
|
|
15
|
-
return null;
|
|
20
|
+
return setDatasource(null);
|
|
21
|
+
}
|
|
22
|
+
case "dataset":
|
|
23
|
+
if (!item?.datasource.dataset || !fetch?.dataset) {
|
|
24
|
+
return setDatasource(null);
|
|
16
25
|
}
|
|
26
|
+
const vars = getVars(item.id || "");
|
|
27
|
+
fetch
|
|
28
|
+
.dataset(item?.datasource.dataset.id, vars)
|
|
29
|
+
.then((res) => setDatasource(res?.data || null))
|
|
30
|
+
.catch((err) => {
|
|
31
|
+
console.error(err);
|
|
32
|
+
setDatasource(null);
|
|
33
|
+
});
|
|
17
34
|
case "define":
|
|
18
35
|
break;
|
|
19
36
|
default:
|
|
20
37
|
break;
|
|
21
38
|
}
|
|
22
|
-
return null;
|
|
23
|
-
}, [
|
|
39
|
+
return setDatasource(null);
|
|
40
|
+
}, [item?.datasource, signal]);
|
|
41
|
+
|
|
42
|
+
return datasource;
|
|
24
43
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -9,22 +9,16 @@ import DropContainer from "./dnd/DropContainer";
|
|
|
9
9
|
|
|
10
10
|
import { PageContext, PageProvider } from "./context/PageContext";
|
|
11
11
|
|
|
12
|
-
import { EnvContext } from "./context/EnvContext";
|
|
13
|
-
|
|
14
|
-
import { handleCallback } from "./utils";
|
|
15
|
-
|
|
16
12
|
import { PluginType } from "./typing";
|
|
17
13
|
|
|
18
14
|
export {
|
|
19
|
-
PageCanvas,
|
|
20
|
-
PageDesigner,
|
|
21
|
-
PageSchema,
|
|
22
15
|
DropContainer,
|
|
16
|
+
PageCanvas,
|
|
23
17
|
PageContext,
|
|
18
|
+
PageDesigner,
|
|
24
19
|
PageProvider,
|
|
25
|
-
|
|
20
|
+
PageSchema,
|
|
26
21
|
plugins,
|
|
27
|
-
PropEditorProps,
|
|
28
22
|
PluginType,
|
|
29
|
-
|
|
23
|
+
PropEditorProps,
|
|
30
24
|
};
|
|
@@ -7,14 +7,11 @@ import React, {
|
|
|
7
7
|
useState,
|
|
8
8
|
} from "react";
|
|
9
9
|
import styled from "styled-components";
|
|
10
|
-
import { DropContainer } from "../dnd/DropContainer";
|
|
11
|
-
import { CallbacksType, EnvType, FetchType } from "../typing";
|
|
12
10
|
import { PageContext } from "../context/PageContext";
|
|
13
|
-
import {
|
|
11
|
+
import { DropContainer } from "../dnd/DropContainer";
|
|
14
12
|
|
|
15
13
|
export type PageCanvasProps = {
|
|
16
14
|
device?: "desktop" | "mobile" | "tablet";
|
|
17
|
-
fetch?: FetchType;
|
|
18
15
|
};
|
|
19
16
|
|
|
20
17
|
const Wrapper = styled.div`
|
|
@@ -53,12 +50,9 @@ const Wrapper = styled.div`
|
|
|
53
50
|
`;
|
|
54
51
|
|
|
55
52
|
export const PageCanvas = React.forwardRef<any, PageCanvasProps>(
|
|
56
|
-
({ device = "desktop"
|
|
57
|
-
const { schema, forceUpdate } = useContext(PageContext);
|
|
53
|
+
({ device = "desktop" }, ref) => {
|
|
54
|
+
const { schema, forceUpdate, setDeviceWidth } = useContext(PageContext);
|
|
58
55
|
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
59
|
-
const [canvasWidth, setCanvasWidth] = useState(0);
|
|
60
|
-
const [callbacks, setCallbacks] = useState<CallbacksType>({});
|
|
61
|
-
const [env, setEnv] = useState<EnvType>({ global: {}, local: {} });
|
|
62
56
|
|
|
63
57
|
const items = useMemo(() => schema.items || [], [schema.items]);
|
|
64
58
|
|
|
@@ -75,14 +69,6 @@ export const PageCanvas = React.forwardRef<any, PageCanvasProps>(
|
|
|
75
69
|
forceUpdate?.();
|
|
76
70
|
};
|
|
77
71
|
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
const nextGlobal: Record<string, any> = {};
|
|
80
|
-
(schema.variables || []).forEach((item) => {
|
|
81
|
-
nextGlobal[item.name] = item.value;
|
|
82
|
-
});
|
|
83
|
-
setEnv((e) => ({ ...e, global: nextGlobal }));
|
|
84
|
-
}, [schema.variables]);
|
|
85
|
-
|
|
86
72
|
const computeCanvasWidth = () => {
|
|
87
73
|
const parent = rootRef.current?.parentElement;
|
|
88
74
|
const rect = parent?.getBoundingClientRect();
|
|
@@ -91,17 +77,7 @@ export const PageCanvas = React.forwardRef<any, PageCanvasProps>(
|
|
|
91
77
|
setTimeout(computeCanvasWidth, 10);
|
|
92
78
|
return;
|
|
93
79
|
}
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const initCallback = ({
|
|
98
|
-
id,
|
|
99
|
-
callback,
|
|
100
|
-
}: {
|
|
101
|
-
id: string;
|
|
102
|
-
callback: (v: any) => void;
|
|
103
|
-
}) => {
|
|
104
|
-
setCallbacks((c) => ({ ...c, [id]: callback }));
|
|
80
|
+
setDeviceWidth(width ? width - 36 : 0);
|
|
105
81
|
};
|
|
106
82
|
|
|
107
83
|
useEffect(() => {
|
|
@@ -124,24 +100,16 @@ export const PageCanvas = React.forwardRef<any, PageCanvasProps>(
|
|
|
124
100
|
}));
|
|
125
101
|
|
|
126
102
|
return (
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
<DropContainer
|
|
136
|
-
ancestors={[]}
|
|
137
|
-
list={localList}
|
|
138
|
-
onListChange={onLocalListChange}
|
|
139
|
-
className="page-canvas"
|
|
140
|
-
/>
|
|
141
|
-
</Wrapper>
|
|
142
|
-
</EnvProvider>
|
|
103
|
+
<Wrapper ref={rootRef}>
|
|
104
|
+
<DropContainer
|
|
105
|
+
ancestors={[]}
|
|
106
|
+
list={localList}
|
|
107
|
+
onListChange={onLocalListChange}
|
|
108
|
+
className="page-canvas"
|
|
109
|
+
/>
|
|
110
|
+
</Wrapper>
|
|
143
111
|
);
|
|
144
|
-
}
|
|
112
|
+
},
|
|
145
113
|
);
|
|
146
114
|
|
|
147
115
|
export default PageCanvas;
|
|
@@ -137,7 +137,6 @@ export const LayerPanel: React.FC = () => {
|
|
|
137
137
|
if (!info.dropToGap) {
|
|
138
138
|
if (info.node.dataRef.type === "slot") {
|
|
139
139
|
const { slot, origin } = info.node.dataRef;
|
|
140
|
-
console.log(slot, JSON.stringify(origin));
|
|
141
140
|
origin[slot] = origin[slot] || [];
|
|
142
141
|
origin[slot].push(dragObj);
|
|
143
142
|
}
|
|
@@ -184,7 +183,6 @@ export const LayerPanel: React.FC = () => {
|
|
|
184
183
|
|
|
185
184
|
const treeData = useMemo(() => {
|
|
186
185
|
const computeTreeData = (list: any[] = []): any[] => {
|
|
187
|
-
console.log(list)
|
|
188
186
|
return list.map((item) => ({
|
|
189
187
|
key: item.key,
|
|
190
188
|
title: <>{item?.title || formatType(item.type, (item as any).slot)}</>,
|
|
@@ -531,7 +531,7 @@ export const PropertiesPanel: React.FC<{
|
|
|
531
531
|
)}
|
|
532
532
|
</div>
|
|
533
533
|
|
|
534
|
-
{!!datasetSelector && (
|
|
534
|
+
{!!datasetSelector && selectedItem && (
|
|
535
535
|
<Drawer
|
|
536
536
|
title="选择数据集"
|
|
537
537
|
size={800}
|
|
@@ -542,15 +542,25 @@ export const PropertiesPanel: React.FC<{
|
|
|
542
542
|
>
|
|
543
543
|
{datasetSelector((dataset) => {
|
|
544
544
|
datasource!.dataset = dataset;
|
|
545
|
+
onUpdateSelectedItem({
|
|
546
|
+
...selectedItem,
|
|
547
|
+
datasource: {...selectedItem.datasource, dataset},
|
|
548
|
+
});
|
|
545
549
|
setDatasetSelectorOpen(false);
|
|
546
550
|
})}
|
|
547
551
|
</Drawer>
|
|
548
552
|
)}
|
|
549
553
|
{!!datasetAdd &&
|
|
554
|
+
selectedItem &&
|
|
550
555
|
datasetAddOpen &&
|
|
551
556
|
datasetAdd(
|
|
557
|
+
selectedItem,
|
|
552
558
|
(dataset) => {
|
|
553
559
|
datasource!.dataset = dataset;
|
|
560
|
+
onUpdateSelectedItem({
|
|
561
|
+
...selectedItem,
|
|
562
|
+
datasource: {...selectedItem.datasource, dataset},
|
|
563
|
+
});
|
|
554
564
|
setDatasetAddOpen(false);
|
|
555
565
|
},
|
|
556
566
|
() => {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Button, type ButtonProps } from "antd";
|
|
2
2
|
import React, { MouseEventHandler, useContext } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { EnvContext } from "../../../context/EnvContext";
|
|
3
|
+
import { PageContext } from "../../../context/PageContext";
|
|
5
4
|
import { IconFont } from "../../../icon/IconFont";
|
|
6
|
-
import {
|
|
5
|
+
import { HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
7
6
|
|
|
8
7
|
export type ButtonRenderProps = {
|
|
9
8
|
text?: string;
|
|
@@ -13,7 +12,7 @@ export type ButtonRenderProps = {
|
|
|
13
12
|
block?: ButtonProps["block"];
|
|
14
13
|
shape?: ButtonProps["shape"];
|
|
15
14
|
ghost?: ButtonProps["ghost"];
|
|
16
|
-
item
|
|
15
|
+
item: SchemaItemType;
|
|
17
16
|
} & HtmlBaseProps;
|
|
18
17
|
|
|
19
18
|
export const ButtonRender: React.FC<ButtonRenderProps> = ({
|
|
@@ -29,11 +28,13 @@ export const ButtonRender: React.FC<ButtonRenderProps> = ({
|
|
|
29
28
|
style,
|
|
30
29
|
className,
|
|
31
30
|
}) => {
|
|
32
|
-
const {
|
|
31
|
+
const { handleCallback } = useContext(PageContext);
|
|
33
32
|
const danger = type === "danger";
|
|
34
33
|
const realType = danger ? "default" : type;
|
|
35
34
|
const click: MouseEventHandler = () => {
|
|
36
|
-
|
|
35
|
+
handleCallback(item, false, (target, data) => {
|
|
36
|
+
console.log("点击回调:", { target, data });
|
|
37
|
+
});
|
|
37
38
|
};
|
|
38
39
|
const iconNode =
|
|
39
40
|
typeof icon === "string" ? (
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Radio, type RadioGroupProps } from "antd";
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
|
+
import { PageContext } from "../../../context/PageContext";
|
|
3
4
|
import { HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
4
|
-
|
|
5
|
-
import { handleCallback, setVar } from "../../../utils";
|
|
5
|
+
|
|
6
6
|
|
|
7
7
|
export type CapsuleRenderProps = {
|
|
8
8
|
var?: string;
|
|
9
9
|
size?: RadioGroupProps['size']
|
|
10
10
|
options?: { label: string; value: any }[];
|
|
11
|
-
item
|
|
11
|
+
item: SchemaItemType;
|
|
12
12
|
onChange?: (v: any) => void;
|
|
13
13
|
} & HtmlBaseProps;
|
|
14
14
|
|
|
@@ -22,11 +22,11 @@ export const CapsuleRender: React.FC<CapsuleRenderProps> = ({
|
|
|
22
22
|
style,
|
|
23
23
|
className,
|
|
24
24
|
}) => {
|
|
25
|
-
const {
|
|
25
|
+
const { handleCallback, setVar } = useContext(PageContext);
|
|
26
26
|
const change = (v: any) => {
|
|
27
27
|
if (onChange) onChange(v);
|
|
28
|
-
if (
|
|
29
|
-
|
|
28
|
+
if (item && varName) setVar(item, varName, v);
|
|
29
|
+
handleCallback(item);
|
|
30
30
|
};
|
|
31
31
|
return (
|
|
32
32
|
<span id={id}>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Checkbox } from "antd";
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
|
+
import { PageContext } from "../../../context/PageContext";
|
|
3
4
|
import { HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
4
|
-
|
|
5
|
-
import { handleCallback, setVar } from "../../../utils";
|
|
5
|
+
|
|
6
6
|
|
|
7
7
|
export type CheckboxRenderProps = {
|
|
8
8
|
var?: string;
|
|
9
9
|
layout?: "horizontal" | "vertical" | "grid";
|
|
10
10
|
lineNumber?: number;
|
|
11
11
|
options?: { label: string; value: any }[];
|
|
12
|
-
item
|
|
12
|
+
item: SchemaItemType;
|
|
13
13
|
onChange?: (value: any[]) => void;
|
|
14
14
|
} & HtmlBaseProps;
|
|
15
15
|
|
|
@@ -24,7 +24,7 @@ export const CheckboxRender: React.FC<CheckboxRenderProps> = ({
|
|
|
24
24
|
style,
|
|
25
25
|
className,
|
|
26
26
|
}) => {
|
|
27
|
-
const {
|
|
27
|
+
const { handleCallback, setVar } = useContext(PageContext);
|
|
28
28
|
const groupStyle: React.CSSProperties = {
|
|
29
29
|
...style,
|
|
30
30
|
display: layout === "grid" ? "grid" : "flex",
|
|
@@ -35,8 +35,8 @@ export const CheckboxRender: React.FC<CheckboxRenderProps> = ({
|
|
|
35
35
|
};
|
|
36
36
|
const change = (v: any[]) => {
|
|
37
37
|
if (onChange) onChange(v);
|
|
38
|
-
if (
|
|
39
|
-
|
|
38
|
+
if (item && varName) setVar(item, varName, v);
|
|
39
|
+
handleCallback(item);
|
|
40
40
|
};
|
|
41
41
|
return (
|
|
42
42
|
<span id={id}>
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Col } from "antd";
|
|
2
2
|
import React, { useContext, useEffect, useMemo, useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { PageContext } from "../../../context/PageContext";
|
|
4
4
|
import { DropContainer } from "../../../dnd/DropContainer";
|
|
5
5
|
import { HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
6
|
-
import { PageContext } from "../../../context/PageContext";
|
|
7
|
-
import { EnvContext } from "../../../context/EnvContext";
|
|
8
6
|
|
|
9
7
|
export type ColRenderProps = {
|
|
10
8
|
span?: number;
|
|
@@ -32,7 +30,7 @@ export const ColRender: React.FC<ColRenderProps> = ({
|
|
|
32
30
|
style = {},
|
|
33
31
|
className,
|
|
34
32
|
}) => {
|
|
35
|
-
const { deviceWidth } = useContext(
|
|
33
|
+
const { deviceWidth } = useContext(PageContext);
|
|
36
34
|
const [localChildren, setLocalChildren] = useState(item.children || []);
|
|
37
35
|
|
|
38
36
|
const onLocalChildrenChange = (list: any[]) => {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { DatePicker, type DatePickerProps, TimePicker } from "antd";
|
|
2
2
|
import dayjs, { Dayjs } from "dayjs";
|
|
3
3
|
import React, { useContext } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { PageContext } from "../../../context/PageContext";
|
|
5
|
+
import { HtmlBaseProps, SchemaItemType } from "../../../typing";
|
|
6
|
+
|
|
7
7
|
|
|
8
8
|
export type DatePickerRenderProps = {
|
|
9
9
|
var?: string;
|
|
10
|
-
size?: DatePickerProps[
|
|
10
|
+
size?: DatePickerProps["size"];
|
|
11
11
|
allowClear?: boolean;
|
|
12
12
|
type?: "date" | "time" | "month" | "year" | "range";
|
|
13
13
|
showTime?: boolean;
|
|
14
14
|
value?: string | [string, string];
|
|
15
|
-
item
|
|
15
|
+
item: SchemaItemType;
|
|
16
16
|
onChange?: (value?: string | [string, string]) => void;
|
|
17
17
|
} & HtmlBaseProps;
|
|
18
18
|
|
|
@@ -29,11 +29,11 @@ export const DatePickerRender: React.FC<DatePickerRenderProps> = ({
|
|
|
29
29
|
style = {},
|
|
30
30
|
className,
|
|
31
31
|
}) => {
|
|
32
|
-
const {
|
|
32
|
+
const { handleCallback, setVar } = useContext(PageContext);
|
|
33
33
|
const change = (val?: string | [string, string]) => {
|
|
34
34
|
if (onChange) onChange(val);
|
|
35
|
-
if (
|
|
36
|
-
|
|
35
|
+
if (item && varName) setVar(item, varName, val as any);
|
|
36
|
+
handleCallback(item);
|
|
37
37
|
};
|
|
38
38
|
if (type === "time") {
|
|
39
39
|
const v =
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
2
1
|
import * as echarts from "echarts";
|
|
3
|
-
import {
|
|
2
|
+
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { PageContext } from "../../../context/PageContext";
|
|
4
4
|
import { useDatasource } from "../../../hooks/datasource";
|
|
5
|
-
import {
|
|
6
|
-
import { getVars } from "../../../utils";
|
|
5
|
+
import { CallbackType, HtmlBaseProps } from "../../../typing";
|
|
7
6
|
|
|
8
7
|
export type EchartsRenderProps = {
|
|
9
8
|
item: any;
|
|
@@ -21,10 +20,16 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
|
|
|
21
20
|
style,
|
|
22
21
|
className,
|
|
23
22
|
}) => {
|
|
24
|
-
const { initCallback
|
|
23
|
+
const { initCallback } = useContext(PageContext);
|
|
25
24
|
const chartRef = useRef<HTMLDivElement | null>(null);
|
|
26
25
|
const [chart, setChart] = useState<echarts.ECharts | null>(null);
|
|
27
|
-
const
|
|
26
|
+
const [signal, setSignal] = useState<number>(0);
|
|
27
|
+
const datasource = useDatasource(item, signal);
|
|
28
|
+
const datasourceRef = useRef(datasource);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
datasourceRef.current = datasource;
|
|
31
|
+
}, [datasource]);
|
|
32
|
+
|
|
28
33
|
const parseConfig = (configStr: string): echarts.EChartsOption | null => {
|
|
29
34
|
try {
|
|
30
35
|
return JSON.parse(configStr);
|
|
@@ -51,7 +56,7 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
|
|
|
51
56
|
const module = undefined;
|
|
52
57
|
const exports = undefined;
|
|
53
58
|
${configStr}
|
|
54
|
-
|
|
59
|
+
`,
|
|
55
60
|
);
|
|
56
61
|
return (safeEval as any)(
|
|
57
62
|
echarts,
|
|
@@ -63,7 +68,7 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
|
|
|
63
68
|
String,
|
|
64
69
|
Number,
|
|
65
70
|
Boolean,
|
|
66
|
-
datasource
|
|
71
|
+
datasource,
|
|
67
72
|
);
|
|
68
73
|
} catch (evalError) {
|
|
69
74
|
console.error("ECharts 配置解析失败:", evalError);
|
|
@@ -71,10 +76,22 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
|
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
};
|
|
74
|
-
const callback = () => {
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
const callback: CallbackType = (refresh = true, args?: any) => {
|
|
80
|
+
if (refresh) setSignal((s) => s + 1);
|
|
81
|
+
return {
|
|
82
|
+
target: item,
|
|
83
|
+
data: datasourceRef.current,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const initOption = () => {
|
|
88
|
+
const opt = parseConfig(script);
|
|
89
|
+
if (chart && opt) {
|
|
90
|
+
chart.setOption(opt);
|
|
91
|
+
setTimeout(() => chart.resize(), 50);
|
|
92
|
+
}
|
|
77
93
|
};
|
|
94
|
+
|
|
78
95
|
useEffect(() => {
|
|
79
96
|
if (!chartRef.current) return;
|
|
80
97
|
const next = echarts.init(chartRef.current);
|
|
@@ -87,13 +104,11 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
|
|
|
87
104
|
next.dispose();
|
|
88
105
|
};
|
|
89
106
|
}, []);
|
|
107
|
+
|
|
90
108
|
useEffect(() => {
|
|
91
|
-
|
|
92
|
-
if (chart && opt) {
|
|
93
|
-
chart.setOption(opt);
|
|
94
|
-
setTimeout(() => chart.resize(), 50);
|
|
95
|
-
}
|
|
109
|
+
initOption();
|
|
96
110
|
}, [chart, script, datasource]);
|
|
111
|
+
|
|
97
112
|
return (
|
|
98
113
|
<div
|
|
99
114
|
id={id}
|