bi-sdk-react 0.0.54 → 0.0.56
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 +55 -41
- package/dist/types/components/context/GlobalDatasetContext.d.ts +7 -0
- package/dist/types/components/context/PageContext.d.ts +6 -3
- package/dist/types/components/example.d.ts +8 -4
- package/dist/types/components/hooks/datasource.d.ts +2 -1
- package/dist/types/components/hooks/method.d.ts +1 -0
- package/dist/types/components/panel/GlobalDatasetPanel.d.ts +2 -0
- package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +9 -0
- package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +1 -0
- package/dist/types/components/plugins/@antd/items/TableRender.d.ts +9 -1
- package/dist/types/components/plugins/@antd/items/TextRender.d.ts +3 -4
- package/dist/types/components/typing.d.ts +9 -1
- package/dist/umd/js/bi-sdk.umd.min.js +55 -41
- package/package.json +1 -1
- package/src/components/PageDesigner.tsx +8 -0
- package/src/components/context/GlobalDatasetContext.tsx +52 -0
- package/src/components/context/PageContext.tsx +31 -8
- package/src/components/example.ts +9 -10
- package/src/components/hooks/datasource.ts +5 -4
- package/src/components/hooks/event.ts +6 -1
- package/src/components/hooks/method.ts +2 -2
- package/src/components/icon/IconFont.tsx +1 -1
- package/src/components/panel/EventPanel.tsx +1 -0
- package/src/components/panel/GlobalDatasetPanel.tsx +165 -0
- package/src/components/panel/VariablesPanel.tsx +4 -1
- package/src/components/plugins/@antd/index.ts +15 -7
- package/src/components/plugins/@antd/item-props/EchartsProps.tsx +20 -2
- package/src/components/plugins/@antd/item-props/HtmlProps.tsx +19 -2
- package/src/components/plugins/@antd/item-props/TableProps.tsx +86 -0
- package/src/components/plugins/@antd/item-props/TextProps.tsx +12 -0
- package/src/components/plugins/@antd/items/DrawerRender.tsx +8 -0
- package/src/components/plugins/@antd/items/EchartsRender.tsx +6 -2
- package/src/components/plugins/@antd/items/HtmlRender.tsx +13 -4
- package/src/components/plugins/@antd/items/ModalRender.tsx +7 -0
- package/src/components/plugins/@antd/items/TableRender.tsx +95 -21
- package/src/components/plugins/@antd/items/TextRender.tsx +21 -6
- package/src/components/typing.ts +9 -1
- package/src/example.tsx +9 -0
package/package.json
CHANGED
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
} from "./typing";
|
|
46
46
|
import { uuid } from "./utils";
|
|
47
47
|
import { EventPanel } from "./panel/EventPanel";
|
|
48
|
+
import { GlobalDatasetPanel } from "./panel/GlobalDatasetPanel";
|
|
48
49
|
|
|
49
50
|
export type PageDesignerProps = {
|
|
50
51
|
pageId: string;
|
|
@@ -266,6 +267,7 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
|
|
|
266
267
|
| "env"
|
|
267
268
|
| "code"
|
|
268
269
|
| "dataset"
|
|
270
|
+
| "global-dataset"
|
|
269
271
|
>("component");
|
|
270
272
|
const [rightPanelActiveKey, setRightPanelActiveKey] = useState<
|
|
271
273
|
"ai" | "props" | "cascade" | "events"
|
|
@@ -635,6 +637,11 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
|
|
|
635
637
|
<IconFont type="icon-variable" />
|
|
636
638
|
</Radio.Button>
|
|
637
639
|
</Tooltip>
|
|
640
|
+
<Tooltip title="全局数据集" placement="right">
|
|
641
|
+
<Radio.Button value="global-dataset">
|
|
642
|
+
<IconFont type="icon-datasource-g" />
|
|
643
|
+
</Radio.Button>
|
|
644
|
+
</Tooltip>
|
|
638
645
|
<Tooltip title="源码" placement="right">
|
|
639
646
|
<Radio.Button value="code">
|
|
640
647
|
<IconFont type="icon-json" />
|
|
@@ -666,6 +673,7 @@ export const PageDesigner = React.forwardRef<any, PageDesignerProps>(
|
|
|
666
673
|
renderNode={datasetPanel}
|
|
667
674
|
/>
|
|
668
675
|
)}
|
|
676
|
+
{leftPanelActiveKey === "global-dataset" && <GlobalDatasetPanel />}
|
|
669
677
|
</div>
|
|
670
678
|
</div>
|
|
671
679
|
<div className="center" style={{ flex: "1 1 auto" }}>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useContext, useEffect, useMemo } from "react";
|
|
2
|
+
import { PageContext } from "./PageContext";
|
|
3
|
+
|
|
4
|
+
type GlobalDatasetContextType = {
|
|
5
|
+
datasetId: string;
|
|
6
|
+
var: string;
|
|
7
|
+
dependencies: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const GlobalDatasetContext: React.FC<GlobalDatasetContextType> = ({
|
|
11
|
+
datasetId,
|
|
12
|
+
var: varName,
|
|
13
|
+
dependencies,
|
|
14
|
+
}) => {
|
|
15
|
+
const { schema, getGlobalEnv, fetch, env, updateGlobalVar } = useContext(PageContext);
|
|
16
|
+
const dataset = schema?.datasets?.find((item) => item.id === datasetId);
|
|
17
|
+
if (!dataset || !fetch?.dataset) {
|
|
18
|
+
return <></>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const params = useMemo(() => {
|
|
22
|
+
return dependencies.reduce(
|
|
23
|
+
(prev, cur) => {
|
|
24
|
+
const value = env.global[cur];
|
|
25
|
+
return [...prev, value];
|
|
26
|
+
},
|
|
27
|
+
[] as any[],
|
|
28
|
+
);
|
|
29
|
+
}, [dependencies, env.global]);
|
|
30
|
+
|
|
31
|
+
const handleFetch = async () => {
|
|
32
|
+
const queryParams = dependencies.reduce(
|
|
33
|
+
(prev, cur) => {
|
|
34
|
+
const value = getGlobalEnv(cur);
|
|
35
|
+
return { ...prev, [cur]: value };
|
|
36
|
+
},
|
|
37
|
+
{} as Record<string, any>,
|
|
38
|
+
);
|
|
39
|
+
const { code, data } = await fetch?.dataset?.(datasetId, queryParams, dataset.aiPrompt);
|
|
40
|
+
if (code === "OK") {
|
|
41
|
+
updateGlobalVar(varName, data);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
handleFetch();
|
|
47
|
+
}, [datasetId, fetch, ...params]);
|
|
48
|
+
|
|
49
|
+
return <></>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default GlobalDatasetContext;
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
PluginType,
|
|
11
11
|
SchemaItemType,
|
|
12
12
|
} from "../typing";
|
|
13
|
+
import GlobalDatasetContext from "./GlobalDatasetContext";
|
|
13
14
|
|
|
14
15
|
type InitCallbackParams = {
|
|
15
16
|
id: string;
|
|
@@ -60,9 +61,12 @@ type PageContextType = {
|
|
|
60
61
|
) => any;
|
|
61
62
|
getVars: (id: string) => Record<string, any>;
|
|
62
63
|
setVar: (item: SchemaItemType, key: string, value: any) => void;
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
env: EnvType;
|
|
65
|
+
getGlobalEnv: (key: string) => string | undefined | null;
|
|
66
|
+
setGlobalEnv: (key: string, value: any) => void;
|
|
65
67
|
setItemData?: (id: string, data: any) => void;
|
|
68
|
+
globalVars: Record<string, any>;
|
|
69
|
+
updateGlobalVar: (key: string, value: any) => void;
|
|
66
70
|
};
|
|
67
71
|
|
|
68
72
|
export const PageContext = createContext<PageContextType>({
|
|
@@ -97,9 +101,12 @@ export const PageContext = createContext<PageContextType>({
|
|
|
97
101
|
handleMethod: () => {},
|
|
98
102
|
getVars: () => ({}),
|
|
99
103
|
setVar: () => {},
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
env: { global: {}, local: {} },
|
|
105
|
+
getGlobalEnv: () => undefined,
|
|
106
|
+
setGlobalEnv: () => {},
|
|
102
107
|
setItemData: () => {},
|
|
108
|
+
globalVars: {},
|
|
109
|
+
updateGlobalVar: () => {},
|
|
103
110
|
});
|
|
104
111
|
|
|
105
112
|
type PageProviderProps = React.PropsWithChildren<
|
|
@@ -133,6 +140,7 @@ export const PageProvider: React.FC<PageProviderProps> = ({
|
|
|
133
140
|
setItemData,
|
|
134
141
|
}) => {
|
|
135
142
|
const [deviceWidth, setDeviceWidth] = useState<number>(0);
|
|
143
|
+
const [globalVars, setGlobalVars] = useState<Record<string, any>>({});
|
|
136
144
|
const updateSelectedItem = (props?: Partial<SchemaItemType> | null) => {
|
|
137
145
|
setSelectedItem?.(Object.assign(selectedItem!, props || {}));
|
|
138
146
|
setSchema?.({ ...schema });
|
|
@@ -218,10 +226,14 @@ export const PageProvider: React.FC<PageProviderProps> = ({
|
|
|
218
226
|
next.local[id][key] = value;
|
|
219
227
|
});
|
|
220
228
|
};
|
|
221
|
-
const
|
|
222
|
-
const
|
|
229
|
+
const getGlobalEnv = (key: string) => env.global[key];
|
|
230
|
+
const setGlobalEnv = (key: string, value: any) => {
|
|
223
231
|
setEnv((e: EnvType) => ({ ...e, global: { ...e.global, [key]: value } }));
|
|
224
232
|
};
|
|
233
|
+
const updateGlobalVar = (key: string, value: any) => {
|
|
234
|
+
// console.log("updateGlobalVar", key, value);
|
|
235
|
+
setGlobalVars((c) => ({ ...c, [key]: value }));
|
|
236
|
+
};
|
|
225
237
|
|
|
226
238
|
useEffect(() => {
|
|
227
239
|
const nextGlobal: Record<string, any> = {};
|
|
@@ -260,12 +272,23 @@ export const PageProvider: React.FC<PageProviderProps> = ({
|
|
|
260
272
|
handleMethod,
|
|
261
273
|
getVars,
|
|
262
274
|
setVar,
|
|
263
|
-
|
|
264
|
-
|
|
275
|
+
env,
|
|
276
|
+
getGlobalEnv,
|
|
277
|
+
setGlobalEnv,
|
|
265
278
|
setItemData,
|
|
279
|
+
globalVars,
|
|
280
|
+
updateGlobalVar,
|
|
266
281
|
}}
|
|
267
282
|
>
|
|
268
283
|
{children}
|
|
284
|
+
{schema.datasets?.map((item, index) => (
|
|
285
|
+
<GlobalDatasetContext
|
|
286
|
+
key={index}
|
|
287
|
+
datasetId={item.id}
|
|
288
|
+
var={item.key!}
|
|
289
|
+
dependencies={item.dependencies || []}
|
|
290
|
+
/>
|
|
291
|
+
))}
|
|
269
292
|
</PageContext.Provider>
|
|
270
293
|
);
|
|
271
294
|
};
|
|
@@ -539,22 +539,21 @@ return {
|
|
|
539
539
|
{
|
|
540
540
|
type: "b-table",
|
|
541
541
|
name: "数据表格",
|
|
542
|
+
datasource: {
|
|
543
|
+
source: "custom",
|
|
544
|
+
custom:
|
|
545
|
+
'[\r\n {\r\n "name": "汉族",\r\n "count": 1204\r\n },\r\n {\r\n "name": "少数民族",\r\n "count": 80\r\n }\r\n]',
|
|
546
|
+
},
|
|
542
547
|
props: {
|
|
543
548
|
title: "民族分布",
|
|
544
549
|
size: "small",
|
|
545
550
|
bordered: true,
|
|
546
551
|
showHeader: true,
|
|
552
|
+
showSizeChanger: true,
|
|
553
|
+
showQuickJumper: true,
|
|
554
|
+
hideOnSinglePage: true,
|
|
555
|
+
showTotal: true,
|
|
547
556
|
pageSize: 10,
|
|
548
|
-
dataSource: [
|
|
549
|
-
{
|
|
550
|
-
name: "汉族",
|
|
551
|
-
count: 1204,
|
|
552
|
-
},
|
|
553
|
-
{
|
|
554
|
-
name: "少数民族",
|
|
555
|
-
count: 80,
|
|
556
|
-
},
|
|
557
|
-
],
|
|
558
557
|
columns: [
|
|
559
558
|
{
|
|
560
559
|
title: "民族",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext, useEffect,
|
|
1
|
+
import { useContext, useEffect, useState } from "react";
|
|
2
2
|
import { PageContext } from "../context/PageContext";
|
|
3
3
|
import { SchemaItemType } from "../typing";
|
|
4
4
|
|
|
@@ -7,9 +7,10 @@ export type Signal = string | number;
|
|
|
7
7
|
type Props = {
|
|
8
8
|
item: SchemaItemType;
|
|
9
9
|
signal?: Signal;
|
|
10
|
+
query?: Record<string, any>;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
export const useDatasource = ({ item, signal }: Props): any => {
|
|
13
|
+
export const useDatasource = ({ item, signal, query }: Props): any => {
|
|
13
14
|
const { fetch, getVars, setItemData } = useContext(PageContext);
|
|
14
15
|
const [datasource, setDatasource] = useState<any>(null);
|
|
15
16
|
useEffect(() => {
|
|
@@ -44,7 +45,7 @@ export const useDatasource = ({ item, signal }: Props): any => {
|
|
|
44
45
|
}
|
|
45
46
|
const vars = getVars(item.id || "");
|
|
46
47
|
fetch
|
|
47
|
-
.dataset(item?.datasource.dataset.id, vars)
|
|
48
|
+
.dataset(item?.datasource.dataset.id, { ...vars, ...query })
|
|
48
49
|
.then((res) => {
|
|
49
50
|
setDatasource(res || null);
|
|
50
51
|
setItemData?.(item.id || "", res || null);
|
|
@@ -60,7 +61,7 @@ export const useDatasource = ({ item, signal }: Props): any => {
|
|
|
60
61
|
setItemData?.(item.id || "", null);
|
|
61
62
|
break;
|
|
62
63
|
}
|
|
63
|
-
}, [item?.datasource, signal]);
|
|
64
|
+
}, [item?.datasource, signal, query]);
|
|
64
65
|
|
|
65
66
|
return datasource;
|
|
66
67
|
};
|
|
@@ -10,7 +10,7 @@ export const useEvent = (item: SchemaItemType) => {
|
|
|
10
10
|
{} as Record<string, string>,
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
-
const { callMethod } = useMethods(item);
|
|
13
|
+
const { callMethod, updateEnv } = useMethods(item);
|
|
14
14
|
|
|
15
15
|
const handleEvent = (eventName: string, arg?: any) => {
|
|
16
16
|
const script = events[eventName];
|
|
@@ -27,6 +27,7 @@ export const useEvent = (item: SchemaItemType) => {
|
|
|
27
27
|
"Number",
|
|
28
28
|
"Boolean",
|
|
29
29
|
"callMethod",
|
|
30
|
+
"updateEnv",
|
|
30
31
|
"param",
|
|
31
32
|
`
|
|
32
33
|
"use strict";
|
|
@@ -37,6 +38,9 @@ export const useEvent = (item: SchemaItemType) => {
|
|
|
37
38
|
const require = undefined;
|
|
38
39
|
const module = undefined;
|
|
39
40
|
const exports = undefined;
|
|
41
|
+
const cookie = undefined;
|
|
42
|
+
const localStorage = undefined;
|
|
43
|
+
const sessionStorage = undefined;
|
|
40
44
|
${script}
|
|
41
45
|
`,
|
|
42
46
|
);
|
|
@@ -50,6 +54,7 @@ export const useEvent = (item: SchemaItemType) => {
|
|
|
50
54
|
Number,
|
|
51
55
|
Boolean,
|
|
52
56
|
callMethod,
|
|
57
|
+
updateEnv,
|
|
53
58
|
{
|
|
54
59
|
item,
|
|
55
60
|
sourceId: item.id,
|
|
@@ -3,11 +3,11 @@ import { PageContext } from "../context/PageContext";
|
|
|
3
3
|
import { SchemaItemType } from "../typing";
|
|
4
4
|
|
|
5
5
|
export const useMethods = (item: SchemaItemType) => {
|
|
6
|
-
const { handleMethod } = useContext(PageContext);
|
|
6
|
+
const { handleMethod, setGlobalEnv: updateEnv } = useContext(PageContext);
|
|
7
7
|
|
|
8
8
|
const callMethod = (targetId: string, methodName: string, arg?: any) => {
|
|
9
9
|
return handleMethod(item, targetId, methodName, arg);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
return { callMethod };
|
|
12
|
+
return { callMethod, updateEnv };
|
|
13
13
|
};
|
|
@@ -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/
|
|
5
|
+
scriptUrl: "https://at.alicdn.com/t/c/font_5072483_30lly4gkmhf.js",
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
export type IconFontProps = {
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { DeleteOutlined } from "@ant-design/icons";
|
|
2
|
+
import { Card, Drawer, Form, Input, Popconfirm, Select, Space } from "antd";
|
|
3
|
+
import React, { useContext, useMemo, useState } from "react";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { PageContext } from "../context/PageContext";
|
|
6
|
+
import { PaneHeader } from "./PaneHeader";
|
|
7
|
+
|
|
8
|
+
const Root = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
height: 100%;
|
|
12
|
+
.body {
|
|
13
|
+
flex: 1 1 auto;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
gap: 12px;
|
|
17
|
+
padding: 12px;
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const GlobalDatasetPanel: React.FC = () => {
|
|
22
|
+
const [visible, setVisible] = useState(false);
|
|
23
|
+
const [form] = Form.useForm();
|
|
24
|
+
|
|
25
|
+
const { schema, datasetSelector, setSchema } = useContext(PageContext);
|
|
26
|
+
|
|
27
|
+
const datasets = useMemo(() => schema?.datasets || [], [schema]);
|
|
28
|
+
const variables = useMemo(() => schema.variables || [], [schema.variables]);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<Root>
|
|
32
|
+
<PaneHeader
|
|
33
|
+
title="全局数据集"
|
|
34
|
+
extra={
|
|
35
|
+
<Space>
|
|
36
|
+
<a
|
|
37
|
+
className="toolbar"
|
|
38
|
+
onClick={() => {
|
|
39
|
+
form.resetFields();
|
|
40
|
+
setVisible(true);
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
+
|
|
44
|
+
</a>
|
|
45
|
+
</Space>
|
|
46
|
+
}
|
|
47
|
+
/>
|
|
48
|
+
<div className="body beautified_scrollbar">
|
|
49
|
+
{datasets.map((dataset, index) => (
|
|
50
|
+
<Card
|
|
51
|
+
key={index}
|
|
52
|
+
title={dataset.name}
|
|
53
|
+
size="small"
|
|
54
|
+
variant="outlined"
|
|
55
|
+
extra={
|
|
56
|
+
<Popconfirm
|
|
57
|
+
title="确认删除吗?"
|
|
58
|
+
onConfirm={() => {
|
|
59
|
+
setSchema((schema) => ({
|
|
60
|
+
...schema,
|
|
61
|
+
datasets: datasets.filter((d) => d.id !== dataset.id),
|
|
62
|
+
}));
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<a className="toolbar">
|
|
66
|
+
<DeleteOutlined />
|
|
67
|
+
</a>
|
|
68
|
+
</Popconfirm>
|
|
69
|
+
}
|
|
70
|
+
styles={{
|
|
71
|
+
header: {minHeight: 0}
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<Form
|
|
75
|
+
layout="vertical"
|
|
76
|
+
size="small"
|
|
77
|
+
styles={{
|
|
78
|
+
label: { fontSize: 12, color: "var(--ant-color-text-label)" },
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<Form.Item label="变量名" style={{ marginBottom: 10 }}>
|
|
82
|
+
<Input
|
|
83
|
+
name="key"
|
|
84
|
+
size="small"
|
|
85
|
+
value={dataset.key}
|
|
86
|
+
placeholder="请输入变量名"
|
|
87
|
+
onChange={(e) => {
|
|
88
|
+
datasets[index].key = e.target.value;
|
|
89
|
+
setSchema((schema) => ({
|
|
90
|
+
...schema,
|
|
91
|
+
datasets: [...datasets],
|
|
92
|
+
}));
|
|
93
|
+
}}
|
|
94
|
+
style={{ width: "100%" }}
|
|
95
|
+
/>
|
|
96
|
+
</Form.Item>
|
|
97
|
+
<Form.Item label="依赖环境变量" style={{ marginBottom: 10 }}>
|
|
98
|
+
<Select
|
|
99
|
+
size="small"
|
|
100
|
+
mode="multiple"
|
|
101
|
+
options={variables.map((variable) => ({
|
|
102
|
+
label: variable.name,
|
|
103
|
+
value: variable.name,
|
|
104
|
+
}))}
|
|
105
|
+
placeholder="请选择依赖环境变量"
|
|
106
|
+
style={{ width: "100%" }}
|
|
107
|
+
value={dataset.dependencies}
|
|
108
|
+
notFoundContent={"暂无依赖环境变量"}
|
|
109
|
+
onChange={(values) => {
|
|
110
|
+
datasets[index].dependencies = values;
|
|
111
|
+
setSchema((schema) => ({
|
|
112
|
+
...schema,
|
|
113
|
+
datasets: [...datasets],
|
|
114
|
+
}));
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
</Form.Item>
|
|
118
|
+
<Form.Item label="AI解读提示词" tooltip="用于AI解读数据集,为空时不进行解读" style={{ marginBottom: 0 }}>
|
|
119
|
+
<Input.TextArea
|
|
120
|
+
size="small"
|
|
121
|
+
value={dataset.aiPrompt}
|
|
122
|
+
onChange={(e) => {
|
|
123
|
+
datasets[index].aiPrompt = e.target.value;
|
|
124
|
+
setSchema((schema) => ({
|
|
125
|
+
...schema,
|
|
126
|
+
datasets: [...datasets],
|
|
127
|
+
}));
|
|
128
|
+
}}
|
|
129
|
+
rows={4}
|
|
130
|
+
/>
|
|
131
|
+
</Form.Item>
|
|
132
|
+
</Form>
|
|
133
|
+
</Card>
|
|
134
|
+
))}
|
|
135
|
+
</div>
|
|
136
|
+
{!!datasetSelector && (
|
|
137
|
+
<Drawer
|
|
138
|
+
title="选择数据集"
|
|
139
|
+
size={800}
|
|
140
|
+
open={visible}
|
|
141
|
+
onClose={() => {
|
|
142
|
+
setVisible(false);
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{datasetSelector((dataset) => {
|
|
146
|
+
setVisible(false);
|
|
147
|
+
setSchema((schema) => ({
|
|
148
|
+
...schema,
|
|
149
|
+
datasets: [
|
|
150
|
+
...datasets,
|
|
151
|
+
{
|
|
152
|
+
id: dataset.id,
|
|
153
|
+
name: dataset.name,
|
|
154
|
+
key: dataset.id,
|
|
155
|
+
output: dataset.output,
|
|
156
|
+
dependencies: [],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
}));
|
|
160
|
+
})}
|
|
161
|
+
</Drawer>
|
|
162
|
+
)}
|
|
163
|
+
</Root>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
@@ -22,13 +22,16 @@ const Root = styled.div`
|
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
24
|
export const VariablesPanel: React.FC = () => {
|
|
25
|
-
const {schema, setSchema} = useContext(PageContext);
|
|
25
|
+
const {schema, setSchema, setGlobalEnv} = useContext(PageContext);
|
|
26
26
|
const [visible, setVisible] = React.useState(false);
|
|
27
27
|
const [editIndex, setEditIndex] = React.useState(-1);
|
|
28
28
|
const [form] = Form.useForm<VariableItem>();
|
|
29
29
|
const list = useMemo(() => schema.variables || [], [schema.variables]);
|
|
30
30
|
const onUpdateVariables = (data: VariableItem[]) => {
|
|
31
31
|
setSchema({ ...schema, variables: data });
|
|
32
|
+
data.forEach((item) => {
|
|
33
|
+
setGlobalEnv(item.name, item.value);
|
|
34
|
+
});
|
|
32
35
|
};
|
|
33
36
|
const columns = [
|
|
34
37
|
{
|
|
@@ -71,6 +71,7 @@ export const TextPlugin: PluginType = {
|
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
|
+
events: [{ name: "点击", handler: "click" }],
|
|
74
75
|
};
|
|
75
76
|
|
|
76
77
|
export const ImagePlugin: PluginType = {
|
|
@@ -139,19 +140,17 @@ export const TablePlugin: PluginType = {
|
|
|
139
140
|
source: "custom",
|
|
140
141
|
datasourceId: null,
|
|
141
142
|
scriptId: null,
|
|
142
|
-
custom:
|
|
143
|
+
custom: "[{\"name\":\"苹果\",\"count\":12},{\"name\":\"华为\",\"count\":803},{\"name\":\"OPPO\",\"count\":654},{\"name\":\"vivo\",\"count\":719}]",
|
|
143
144
|
},
|
|
144
145
|
props: {
|
|
145
146
|
size: "default",
|
|
146
147
|
bordered: true,
|
|
147
148
|
showHeader: true,
|
|
149
|
+
showSizeChanger: true,
|
|
150
|
+
showQuickJumper: true,
|
|
151
|
+
hideOnSinglePage: true,
|
|
152
|
+
showTotal: true,
|
|
148
153
|
pageSize: 10,
|
|
149
|
-
dataSource: [
|
|
150
|
-
{ name: "苹果", count: 12 },
|
|
151
|
-
{ name: "华为", count: 803 },
|
|
152
|
-
{ name: "OPPO", count: 654 },
|
|
153
|
-
{ name: "vivo", count: 719 },
|
|
154
|
-
],
|
|
155
154
|
columns: [
|
|
156
155
|
{ title: "品牌", dataIndex: "name" },
|
|
157
156
|
{ title: "日销量(件)", dataIndex: "count" },
|
|
@@ -197,6 +196,7 @@ export const HtmlPlugin: PluginType = {
|
|
|
197
196
|
template: `<div>{{name}}, welcome to the world of programming.</div>`,
|
|
198
197
|
},
|
|
199
198
|
},
|
|
199
|
+
events: [{ name: "点击", handler: "click" }],
|
|
200
200
|
};
|
|
201
201
|
|
|
202
202
|
export const EchartsPlugin: PluginType = {
|
|
@@ -459,6 +459,10 @@ export const ModalPlugin: PluginType = {
|
|
|
459
459
|
},
|
|
460
460
|
children: [],
|
|
461
461
|
},
|
|
462
|
+
events: [
|
|
463
|
+
{ name: "打开", handler: "open" },
|
|
464
|
+
{ name: "关闭", handler: "close" },
|
|
465
|
+
]
|
|
462
466
|
};
|
|
463
467
|
|
|
464
468
|
export const DrawerPlugin: PluginType = {
|
|
@@ -485,6 +489,10 @@ export const DrawerPlugin: PluginType = {
|
|
|
485
489
|
},
|
|
486
490
|
children: [],
|
|
487
491
|
},
|
|
492
|
+
events: [
|
|
493
|
+
{ name: "打开", handler: "open" },
|
|
494
|
+
{ name: "关闭", handler: "close" },
|
|
495
|
+
]
|
|
488
496
|
};
|
|
489
497
|
|
|
490
498
|
export const plugins: PluginType[] = [
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { useRef } from "react";
|
|
2
|
-
import { Form, InputNumber } from "antd";
|
|
2
|
+
import { Form, InputNumber, Space, Tooltip } from "antd";
|
|
3
3
|
import Editor from "@monaco-editor/react";
|
|
4
4
|
import type { PropEditorProps } from "./types";
|
|
5
5
|
import { IconFont } from "../../../icon/IconFont";
|
|
6
|
+
import { InfoCircleOutlined } from "@ant-design/icons";
|
|
6
7
|
|
|
7
8
|
export type EchartsModel = { script: string; height?: number };
|
|
8
9
|
|
|
@@ -40,7 +41,24 @@ export const EchartsProps: React.FC<PropEditorProps<EchartsModel>> = ({
|
|
|
40
41
|
layout="vertical"
|
|
41
42
|
label={
|
|
42
43
|
<>
|
|
43
|
-
|
|
44
|
+
<Space>
|
|
45
|
+
Echarts 渲染脚本{" "}
|
|
46
|
+
<Tooltip
|
|
47
|
+
title={
|
|
48
|
+
<>
|
|
49
|
+
模板语法参考
|
|
50
|
+
<ul style={{padding: 0, listStyle: "none"}}>
|
|
51
|
+
<li>变量调用:{ `{{变量名}}` }</li>
|
|
52
|
+
<li>环境变量:{ `{{$e.变量名}}` }</li>
|
|
53
|
+
<li>全局变量:{ `{{$g.变量名}}` }</li>
|
|
54
|
+
<li>函数参数:{ `{{data}}` }</li>
|
|
55
|
+
</ul>
|
|
56
|
+
</>
|
|
57
|
+
}
|
|
58
|
+
>
|
|
59
|
+
<InfoCircleOutlined />
|
|
60
|
+
</Tooltip>
|
|
61
|
+
</Space>
|
|
44
62
|
<a onClick={format}>
|
|
45
63
|
<IconFont type="icon-formate" /> 格式化
|
|
46
64
|
</a>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { useRef } from "react";
|
|
2
|
-
import { Form, Select } from "antd";
|
|
2
|
+
import { Form, Select, Space, Tooltip } from "antd";
|
|
3
3
|
import Editor from "@monaco-editor/react";
|
|
4
4
|
import type { PropEditorProps } from "./types";
|
|
5
5
|
import { IconFont } from "../../../icon/IconFont";
|
|
6
|
+
import { InfoCircleOutlined } from "@ant-design/icons";
|
|
6
7
|
|
|
7
8
|
export type HtmlModel = { template: string; classNames?: string[] };
|
|
8
9
|
|
|
@@ -31,7 +32,23 @@ export const HtmlProps: React.FC<PropEditorProps<HtmlModel>> = ({
|
|
|
31
32
|
<Form.Item
|
|
32
33
|
label={
|
|
33
34
|
<>
|
|
34
|
-
|
|
35
|
+
<Space>
|
|
36
|
+
模板
|
|
37
|
+
<Tooltip
|
|
38
|
+
title={
|
|
39
|
+
<>
|
|
40
|
+
模板语法参考
|
|
41
|
+
<ul style={{padding: 0, listStyle: "none"}}>
|
|
42
|
+
<li>变量调用:{ `{{变量名}}` }</li>
|
|
43
|
+
<li>环境变量:{ `{{$e.变量名}}` }</li>
|
|
44
|
+
<li>全局变量:{ `{{$g.变量名}}` }</li>
|
|
45
|
+
</ul>
|
|
46
|
+
</>
|
|
47
|
+
}
|
|
48
|
+
>
|
|
49
|
+
<InfoCircleOutlined />
|
|
50
|
+
</Tooltip>
|
|
51
|
+
</Space>
|
|
35
52
|
<a onClick={format}>
|
|
36
53
|
<IconFont type="icon-formate" /> 格式化
|
|
37
54
|
</a>
|