bi-sdk-react 0.0.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/dist/es/css/bi-sdk.css +1 -0
- package/dist/es/js/bi-sdk.es.js +795 -0
- package/dist/es/js/bi-sdk.es.js.LICENSE.txt +9 -0
- package/dist/types/components/PageDesigner.d.ts +10 -0
- package/dist/types/components/context/DesignerContext.d.ts +15 -0
- package/dist/types/components/context/EnvContext.d.ts +15 -0
- package/dist/types/components/dnd/DropContainer.d.ts +21 -0
- package/dist/types/components/example.d.ts +225 -0
- package/dist/types/components/hooks/datasource.d.ts +1 -0
- package/dist/types/components/hooks/useDeepCompareEffect.d.ts +1 -0
- package/dist/types/components/icon/IconFont.d.ts +6 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/components/layout/PageCanvas.d.ts +6 -0
- package/dist/types/components/layout/PageItem.d.ts +27 -0
- package/dist/types/components/panel/AiPanel.d.ts +8 -0
- package/dist/types/components/panel/CascadePanel.d.ts +2 -0
- package/dist/types/components/panel/ChatInput.d.ts +28 -0
- package/dist/types/components/panel/CodePanel.d.ts +2 -0
- package/dist/types/components/panel/ComponentPanel.d.ts +2 -0
- package/dist/types/components/panel/DatasourcePanel.d.ts +2 -0
- package/dist/types/components/panel/LayerPanel.d.ts +2 -0
- package/dist/types/components/panel/PaneHeader.d.ts +6 -0
- package/dist/types/components/panel/PropertiesPanel.d.ts +2 -0
- package/dist/types/components/panel/ScriptPanel.d.ts +2 -0
- package/dist/types/components/panel/VariablesPanel.d.ts +2 -0
- package/dist/types/components/panel/index.d.ts +9 -0
- package/dist/types/components/plugins/@antd/index.d.ts +22 -0
- package/dist/types/components/plugins/@antd/item-props/ButtonProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/CapsuleProps.d.ts +13 -0
- package/dist/types/components/plugins/@antd/item-props/CardProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/CheckboxProps.d.ts +13 -0
- package/dist/types/components/plugins/@antd/item-props/ColProps.d.ts +12 -0
- package/dist/types/components/plugins/@antd/item-props/DatePickerProps.d.ts +8 -0
- package/dist/types/components/plugins/@antd/item-props/EchartsProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/ImageProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/InputNumberProps.d.ts +9 -0
- package/dist/types/components/plugins/@antd/item-props/InputProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/ListProps.d.ts +10 -0
- package/dist/types/components/plugins/@antd/item-props/PageHeaderProps.d.ts +7 -0
- package/dist/types/components/plugins/@antd/item-props/RowProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/SelectProps.d.ts +16 -0
- package/dist/types/components/plugins/@antd/item-props/SpaceProps.d.ts +7 -0
- package/dist/types/components/plugins/@antd/item-props/SwitchProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +15 -0
- package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +6 -0
- package/dist/types/components/plugins/@antd/item-props/index.d.ts +19 -0
- package/dist/types/components/plugins/@antd/item-props/types.d.ts +5 -0
- package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/CardRender.d.ts +12 -0
- package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/ColRender.d.ts +13 -0
- package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/EchartsRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +20 -0
- package/dist/types/components/plugins/@antd/items/ImageRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/InputRender.d.ts +17 -0
- package/dist/types/components/plugins/@antd/items/ListRender.d.ts +11 -0
- package/dist/types/components/plugins/@antd/items/PageHeaderRender.d.ts +8 -0
- package/dist/types/components/plugins/@antd/items/RowRender.d.ts +13 -0
- package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +18 -0
- package/dist/types/components/plugins/@antd/items/SpaceRender.d.ts +10 -0
- package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +14 -0
- package/dist/types/components/plugins/@antd/items/TableRender.d.ts +12 -0
- package/dist/types/components/plugins/@antd/items/TextRender.d.ts +9 -0
- package/dist/types/components/plugins/@antd/items/index.d.ts +19 -0
- package/dist/types/components/typing.d.ts +80 -0
- package/dist/types/components/utils.d.ts +9 -0
- package/dist/types/example.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/umd/css/bi-sdk.css +1 -0
- package/dist/umd/js/bi-sdk.umd.min.js +795 -0
- package/dist/umd/js/bi-sdk.umd.min.js.LICENSE.txt +9 -0
- package/package.json +52 -0
- package/src/components/PageDesigner.tsx +509 -0
- package/src/components/context/DesignerContext.tsx +71 -0
- package/src/components/context/EnvContext.tsx +42 -0
- package/src/components/dnd/DropContainer.tsx +474 -0
- package/src/components/example.ts +577 -0
- package/src/components/hooks/datasource.ts +23 -0
- package/src/components/hooks/useDeepCompareEffect.ts +12 -0
- package/src/components/icon/IconFont.tsx +16 -0
- package/src/components/index.ts +29 -0
- package/src/components/layout/PageCanvas.tsx +145 -0
- package/src/components/layout/PageItem.tsx +182 -0
- package/src/components/panel/AiPanel.tsx +116 -0
- package/src/components/panel/CascadePanel.tsx +163 -0
- package/src/components/panel/ChatInput.tsx +550 -0
- package/src/components/panel/CodePanel.tsx +48 -0
- package/src/components/panel/ComponentPanel.tsx +119 -0
- package/src/components/panel/DatasourcePanel.tsx +419 -0
- package/src/components/panel/LayerPanel.tsx +238 -0
- package/src/components/panel/PaneHeader.tsx +34 -0
- package/src/components/panel/PropertiesPanel.tsx +394 -0
- package/src/components/panel/ScriptPanel.tsx +175 -0
- package/src/components/panel/VariablesPanel.tsx +153 -0
- package/src/components/panel/index.ts +9 -0
- package/src/components/plugins/@antd/index.ts +445 -0
- package/src/components/plugins/@antd/item-props/ButtonProps.tsx +91 -0
- package/src/components/plugins/@antd/item-props/CapsuleProps.tsx +102 -0
- package/src/components/plugins/@antd/item-props/CardProps.tsx +58 -0
- package/src/components/plugins/@antd/item-props/CheckboxProps.tsx +75 -0
- package/src/components/plugins/@antd/item-props/ColProps.tsx +43 -0
- package/src/components/plugins/@antd/item-props/DatePickerProps.tsx +72 -0
- package/src/components/plugins/@antd/item-props/EchartsProps.tsx +35 -0
- package/src/components/plugins/@antd/item-props/HtmlProps.tsx +61 -0
- package/src/components/plugins/@antd/item-props/ImageProps.tsx +43 -0
- package/src/components/plugins/@antd/item-props/InputNumberProps.tsx +18 -0
- package/src/components/plugins/@antd/item-props/InputProps.tsx +89 -0
- package/src/components/plugins/@antd/item-props/ListProps.tsx +69 -0
- package/src/components/plugins/@antd/item-props/PageHeaderProps.tsx +20 -0
- package/src/components/plugins/@antd/item-props/RowProps.tsx +21 -0
- package/src/components/plugins/@antd/item-props/SelectProps.tsx +136 -0
- package/src/components/plugins/@antd/item-props/SpaceProps.tsx +52 -0
- package/src/components/plugins/@antd/item-props/SwitchProps.tsx +17 -0
- package/src/components/plugins/@antd/item-props/TableProps.tsx +200 -0
- package/src/components/plugins/@antd/item-props/TextProps.tsx +41 -0
- package/src/components/plugins/@antd/item-props/index.ts +20 -0
- package/src/components/plugins/@antd/item-props/types.ts +6 -0
- package/src/components/plugins/@antd/items/ButtonRender.tsx +63 -0
- package/src/components/plugins/@antd/items/CapsuleRender.tsx +49 -0
- package/src/components/plugins/@antd/items/CardRender.tsx +119 -0
- package/src/components/plugins/@antd/items/CheckboxRender.tsx +56 -0
- package/src/components/plugins/@antd/items/ColRender.tsx +78 -0
- package/src/components/plugins/@antd/items/DatePickerRender.tsx +117 -0
- package/src/components/plugins/@antd/items/EchartsRender.tsx +98 -0
- package/src/components/plugins/@antd/items/HtmlRender.tsx +74 -0
- package/src/components/plugins/@antd/items/ImageRender.tsx +37 -0
- package/src/components/plugins/@antd/items/InputNumberRender.tsx +57 -0
- package/src/components/plugins/@antd/items/InputRender.tsx +75 -0
- package/src/components/plugins/@antd/items/ListRender.tsx +227 -0
- package/src/components/plugins/@antd/items/PageHeaderRender.tsx +74 -0
- package/src/components/plugins/@antd/items/RowRender.tsx +47 -0
- package/src/components/plugins/@antd/items/SelectRender.tsx +53 -0
- package/src/components/plugins/@antd/items/SpaceRender.tsx +54 -0
- package/src/components/plugins/@antd/items/SwitchRender.tsx +52 -0
- package/src/components/plugins/@antd/items/TableRender.tsx +99 -0
- package/src/components/plugins/@antd/items/TextRender.tsx +25 -0
- package/src/components/plugins/@antd/items/index.ts +20 -0
- package/src/components/styles.css +12 -0
- package/src/components/typing.ts +80 -0
- package/src/components/utils.ts +37 -0
- package/src/example.tsx +136 -0
- package/src/index.tsx +17 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import React, { useContext, useMemo, useRef, useState } from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
import { PaneHeader } from "./PaneHeader";
|
|
4
|
+
import { Radio, Divider, Form, Input, Upload, Button, Select } from "antd";
|
|
5
|
+
import Editor from "@monaco-editor/react";
|
|
6
|
+
import { InboxOutlined, DeleteOutlined } from "@ant-design/icons";
|
|
7
|
+
import { IconFont } from "../icon/IconFont";
|
|
8
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
9
|
+
|
|
10
|
+
const Root = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
height: 100%;
|
|
14
|
+
.body {
|
|
15
|
+
flex: 1 1 auto;
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: 12px;
|
|
19
|
+
padding: 12px;
|
|
20
|
+
overflow: auto;
|
|
21
|
+
|
|
22
|
+
.ant-form-item-label {
|
|
23
|
+
text-align: left;
|
|
24
|
+
|
|
25
|
+
label {
|
|
26
|
+
display: inline;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ant-form-item-control-input,
|
|
31
|
+
.ant-form-item-control-input-content {
|
|
32
|
+
text-align: end;
|
|
33
|
+
justify-content: flex-end;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const computeItems = (rootItems: any[] = []) => {
|
|
39
|
+
const items: any[] = [];
|
|
40
|
+
const walk = (list: any[]) => {
|
|
41
|
+
if (!Array.isArray(list)) return;
|
|
42
|
+
list.forEach((item) => {
|
|
43
|
+
items.push(item);
|
|
44
|
+
if (Array.isArray(item.children)) walk(item.children);
|
|
45
|
+
else if (typeof item.children === "object" && item.children) {
|
|
46
|
+
Object.keys(item.children).forEach((key) => walk(item.children[key]));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
walk(rootItems || []);
|
|
51
|
+
return items;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const PropertiesPanel: React.FC = () => {
|
|
55
|
+
const { plugins, selectedItem, updateSelectedItem: onUpdateSelectedItem, schema, setSchema } = useContext(DesignerContext);
|
|
56
|
+
const refCustomDatasource = useRef<any>(null);
|
|
57
|
+
const [selectedTab, setSelectedTab] = useState<"1" | "2">("1");
|
|
58
|
+
const items = useMemo(() => computeItems(schema?.items || []), [schema]);
|
|
59
|
+
const selectedItemInCanvas = useMemo(
|
|
60
|
+
() => selectedItem && items.find((i: any) => i.id === selectedItem.id),
|
|
61
|
+
[items, selectedItem]
|
|
62
|
+
);
|
|
63
|
+
const activeTab = selectedItemInCanvas ? selectedTab : "1";
|
|
64
|
+
const plugin = useMemo(
|
|
65
|
+
() => plugins.find((p: any) => p.key === selectedItem?.type),
|
|
66
|
+
[plugins, selectedItem]
|
|
67
|
+
);
|
|
68
|
+
const FormComp = plugin?.formComponent as
|
|
69
|
+
| React.ComponentType<any>
|
|
70
|
+
| undefined;
|
|
71
|
+
const model = selectedItem?.props || {};
|
|
72
|
+
const customStyle = selectedItem?.style || {};
|
|
73
|
+
const onChange = (next: any) => {
|
|
74
|
+
if (!selectedItem) return;
|
|
75
|
+
onUpdateSelectedItem &&
|
|
76
|
+
onUpdateSelectedItem({ ...selectedItem, props: next });
|
|
77
|
+
};
|
|
78
|
+
const [reportForm, setReportForm] = useState<any>(schema?.info || {});
|
|
79
|
+
const [datasource, setDatasource] = useState<any>(
|
|
80
|
+
selectedItem?.datasource || {}
|
|
81
|
+
);
|
|
82
|
+
const onUpdateReportProps = (next: any) => {
|
|
83
|
+
setSchema({ ...schema, info: next });
|
|
84
|
+
};
|
|
85
|
+
const uploadHeaders = {
|
|
86
|
+
Authorization: `Bearer ${localStorage.getItem("ASKDATA_TOKEN") || ""}`,
|
|
87
|
+
};
|
|
88
|
+
const beforeUpload = (file: File) => {
|
|
89
|
+
const isImage = file.type.startsWith("image/");
|
|
90
|
+
return isImage;
|
|
91
|
+
};
|
|
92
|
+
const handleUpload = (info: any) => {
|
|
93
|
+
if (info.file.status === "done") {
|
|
94
|
+
const cover = { url: info.file.response?.data, name: info.file.name };
|
|
95
|
+
const next = { ...reportForm, cover };
|
|
96
|
+
setReportForm(next);
|
|
97
|
+
onUpdateReportProps && onUpdateReportProps(next);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const removeCover = () => {
|
|
101
|
+
const next = { ...reportForm, cover: null };
|
|
102
|
+
setReportForm(next);
|
|
103
|
+
onUpdateReportProps && onUpdateReportProps(next);
|
|
104
|
+
};
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
setSelectedTab(selectedItem ? "2" : "1");
|
|
107
|
+
setDatasource(selectedItem?.datasource || {});
|
|
108
|
+
}, [selectedItem]);
|
|
109
|
+
return (
|
|
110
|
+
<Root className="properties-panel">
|
|
111
|
+
<PaneHeader
|
|
112
|
+
title="属性"
|
|
113
|
+
extra={
|
|
114
|
+
<Radio.Group
|
|
115
|
+
value={activeTab}
|
|
116
|
+
size="small"
|
|
117
|
+
buttonStyle="outline"
|
|
118
|
+
onChange={(e) => setSelectedTab(e.target.value)}
|
|
119
|
+
>
|
|
120
|
+
<Radio.Button value="1">页面</Radio.Button>
|
|
121
|
+
{selectedItemInCanvas && (
|
|
122
|
+
<Radio.Button value="2">组件</Radio.Button>
|
|
123
|
+
)}
|
|
124
|
+
</Radio.Group>
|
|
125
|
+
}
|
|
126
|
+
/>
|
|
127
|
+
<div className="body">
|
|
128
|
+
{activeTab === "1" && (
|
|
129
|
+
<Form labelCol={{ span: 24 }} wrapperCol={{ span: 24 }}>
|
|
130
|
+
<Form.Item label="页面名称">
|
|
131
|
+
<Input
|
|
132
|
+
size="small"
|
|
133
|
+
value={reportForm?.name}
|
|
134
|
+
placeholder="请输入页面名称"
|
|
135
|
+
onChange={(e) => {
|
|
136
|
+
const next = { ...reportForm, name: e.target.value };
|
|
137
|
+
setReportForm(next);
|
|
138
|
+
onUpdateReportProps && onUpdateReportProps(next);
|
|
139
|
+
}}
|
|
140
|
+
/>
|
|
141
|
+
</Form.Item>
|
|
142
|
+
<Form.Item label="页面描述">
|
|
143
|
+
<Input.TextArea
|
|
144
|
+
size="small"
|
|
145
|
+
value={reportForm?.description}
|
|
146
|
+
placeholder="请输入页面描述"
|
|
147
|
+
onChange={(e) => {
|
|
148
|
+
const next = { ...reportForm, description: e.target.value };
|
|
149
|
+
setReportForm(next);
|
|
150
|
+
onUpdateReportProps && onUpdateReportProps(next);
|
|
151
|
+
}}
|
|
152
|
+
/>
|
|
153
|
+
</Form.Item>
|
|
154
|
+
<Form.Item label="封面">
|
|
155
|
+
<Upload.Dragger
|
|
156
|
+
name="file"
|
|
157
|
+
multiple={false}
|
|
158
|
+
accept=".png,.jpg,.jpeg"
|
|
159
|
+
headers={uploadHeaders}
|
|
160
|
+
action="/api/datareport/upload"
|
|
161
|
+
showUploadList={false}
|
|
162
|
+
beforeUpload={beforeUpload}
|
|
163
|
+
onChange={handleUpload}
|
|
164
|
+
>
|
|
165
|
+
<p className="ant-upload-drag-icon">
|
|
166
|
+
<InboxOutlined />
|
|
167
|
+
</p>
|
|
168
|
+
<p className="ant-upload-text">
|
|
169
|
+
点击或将文件拖拽到此区域进行上传
|
|
170
|
+
</p>
|
|
171
|
+
<p className="ant-upload-hint">
|
|
172
|
+
严禁上传公司数据或其他被禁止的文件。
|
|
173
|
+
</p>
|
|
174
|
+
</Upload.Dragger>
|
|
175
|
+
{reportForm?.cover?.url && (
|
|
176
|
+
<div style={{ marginTop: 10, textAlign: "left" }}>
|
|
177
|
+
<div
|
|
178
|
+
style={{ display: "flex", justifyContent: "space-between" }}
|
|
179
|
+
>
|
|
180
|
+
<label>封面预览</label>
|
|
181
|
+
<a onClick={removeCover}>
|
|
182
|
+
<DeleteOutlined />
|
|
183
|
+
</a>
|
|
184
|
+
</div>
|
|
185
|
+
<img
|
|
186
|
+
src={reportForm.cover.url}
|
|
187
|
+
style={{ width: "100%", maxHeight: 200 }}
|
|
188
|
+
/>
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
</Form.Item>
|
|
192
|
+
</Form>
|
|
193
|
+
)}
|
|
194
|
+
{activeTab === "2" && (
|
|
195
|
+
<>
|
|
196
|
+
<Divider>基础属性</Divider>
|
|
197
|
+
<Form labelCol={{ span: 24 }} wrapperCol={{ span: 24 }}>
|
|
198
|
+
<Form.Item
|
|
199
|
+
label="组件标识"
|
|
200
|
+
labelCol={{ span: 12 }}
|
|
201
|
+
wrapperCol={{ span: 12 }}
|
|
202
|
+
>
|
|
203
|
+
{selectedItem?.id || ""}
|
|
204
|
+
</Form.Item>
|
|
205
|
+
<Form.Item label="组件名称">
|
|
206
|
+
<Input
|
|
207
|
+
size="small"
|
|
208
|
+
value={selectedItem?.name}
|
|
209
|
+
onChange={(e) =>
|
|
210
|
+
onUpdateSelectedItem &&
|
|
211
|
+
onUpdateSelectedItem({
|
|
212
|
+
...selectedItem,
|
|
213
|
+
name: e.target.value,
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
/>
|
|
217
|
+
</Form.Item>
|
|
218
|
+
<Form.Item label="组件描述">
|
|
219
|
+
<Input.TextArea
|
|
220
|
+
size="small"
|
|
221
|
+
value={selectedItem?.description}
|
|
222
|
+
onChange={(e) =>
|
|
223
|
+
onUpdateSelectedItem &&
|
|
224
|
+
onUpdateSelectedItem({
|
|
225
|
+
...selectedItem,
|
|
226
|
+
description: e.target.value,
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
/>
|
|
230
|
+
</Form.Item>
|
|
231
|
+
</Form>
|
|
232
|
+
{selectedItem?.datasource && <Divider>数据源</Divider>}
|
|
233
|
+
{selectedItem?.datasource && (
|
|
234
|
+
<Form labelCol={{ span: 24 }} wrapperCol={{ span: 24 }}>
|
|
235
|
+
<Form.Item
|
|
236
|
+
label={
|
|
237
|
+
<div
|
|
238
|
+
style={{
|
|
239
|
+
display: "flex",
|
|
240
|
+
alignItems: "center",
|
|
241
|
+
justifyContent: "space-between",
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
数据来源
|
|
245
|
+
<Radio.Group
|
|
246
|
+
size="small"
|
|
247
|
+
value={datasource?.source}
|
|
248
|
+
onChange={(e) => {
|
|
249
|
+
const next = {
|
|
250
|
+
...(datasource || {}),
|
|
251
|
+
source: e.target.value,
|
|
252
|
+
};
|
|
253
|
+
setDatasource(next);
|
|
254
|
+
onUpdateSelectedItem &&
|
|
255
|
+
onUpdateSelectedItem({
|
|
256
|
+
...selectedItem,
|
|
257
|
+
datasource: next,
|
|
258
|
+
});
|
|
259
|
+
}}
|
|
260
|
+
>
|
|
261
|
+
<Radio.Button value="define">已定义数据源</Radio.Button>
|
|
262
|
+
<Radio.Button value="custom">自定义</Radio.Button>
|
|
263
|
+
</Radio.Group>
|
|
264
|
+
</div>
|
|
265
|
+
}
|
|
266
|
+
>
|
|
267
|
+
{datasource?.source === "define" && (
|
|
268
|
+
<>
|
|
269
|
+
<Form.Item label="数据源" labelCol={{ span: 24 }} wrapperCol={{ span: 24 }}>
|
|
270
|
+
<Select
|
|
271
|
+
size="small"
|
|
272
|
+
value={datasource?.datasourceId}
|
|
273
|
+
onChange={(v) => {
|
|
274
|
+
const next = {
|
|
275
|
+
...(datasource || {}),
|
|
276
|
+
datasourceId: v,
|
|
277
|
+
};
|
|
278
|
+
setDatasource(next);
|
|
279
|
+
onUpdateSelectedItem &&
|
|
280
|
+
onUpdateSelectedItem({
|
|
281
|
+
...selectedItem,
|
|
282
|
+
datasource: next,
|
|
283
|
+
});
|
|
284
|
+
}}
|
|
285
|
+
>
|
|
286
|
+
{(schema?.datasources || []).map((item: any) => (
|
|
287
|
+
<Select.Option key={item.id} value={item.id}>
|
|
288
|
+
{item.name}
|
|
289
|
+
</Select.Option>
|
|
290
|
+
))}
|
|
291
|
+
</Select>
|
|
292
|
+
</Form.Item>
|
|
293
|
+
<Form.Item label="数据处理脚本" labelCol={{ span: 24 }} wrapperCol={{ span: 24 }}>
|
|
294
|
+
<Select
|
|
295
|
+
size="small"
|
|
296
|
+
value={datasource?.scriptId}
|
|
297
|
+
onChange={(v) => {
|
|
298
|
+
const next = { ...(datasource || {}), scriptId: v };
|
|
299
|
+
setDatasource(next);
|
|
300
|
+
onUpdateSelectedItem &&
|
|
301
|
+
onUpdateSelectedItem({
|
|
302
|
+
...selectedItem,
|
|
303
|
+
datasource: next,
|
|
304
|
+
});
|
|
305
|
+
}}
|
|
306
|
+
>
|
|
307
|
+
{(schema?.scripts || []).map((item: any) => (
|
|
308
|
+
<Select.Option key={item.id} value={item.id}>
|
|
309
|
+
{item.name}
|
|
310
|
+
</Select.Option>
|
|
311
|
+
))}
|
|
312
|
+
</Select>
|
|
313
|
+
</Form.Item>
|
|
314
|
+
</>
|
|
315
|
+
)}
|
|
316
|
+
{datasource?.source === "custom" && (
|
|
317
|
+
<>
|
|
318
|
+
<Form.Item
|
|
319
|
+
label={
|
|
320
|
+
<div
|
|
321
|
+
style={{
|
|
322
|
+
display: "flex",
|
|
323
|
+
alignItems: "center",
|
|
324
|
+
justifyContent: "space-between",
|
|
325
|
+
}}
|
|
326
|
+
>
|
|
327
|
+
自定义
|
|
328
|
+
<a
|
|
329
|
+
onClick={() => {
|
|
330
|
+
/* formatting via Monaco action not exposed here */
|
|
331
|
+
const editor = (refCustomDatasource.current as any)?.editor;
|
|
332
|
+
editor?.getAction("editor.action.formatDocument")?.run();
|
|
333
|
+
}}
|
|
334
|
+
>
|
|
335
|
+
<IconFont type="icon-formate" /> 格式化
|
|
336
|
+
</a>
|
|
337
|
+
</div>
|
|
338
|
+
}
|
|
339
|
+
labelCol={{ span: 24 }}
|
|
340
|
+
wrapperCol={{ span: 24 }}
|
|
341
|
+
>
|
|
342
|
+
<div
|
|
343
|
+
style={{
|
|
344
|
+
border: `1px solid var(--ant-color-border)`,
|
|
345
|
+
borderRadius: "var(--ant-border-radius)",
|
|
346
|
+
padding: 1,
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
<Editor
|
|
350
|
+
height="200px"
|
|
351
|
+
onMount={(editor) => {
|
|
352
|
+
(refCustomDatasource.current as any) = { editor };
|
|
353
|
+
}}
|
|
354
|
+
defaultLanguage="json"
|
|
355
|
+
value={datasource?.custom}
|
|
356
|
+
onChange={(v) => {
|
|
357
|
+
const next = {
|
|
358
|
+
...(datasource || {}),
|
|
359
|
+
custom: v || "",
|
|
360
|
+
};
|
|
361
|
+
setDatasource(next);
|
|
362
|
+
onUpdateSelectedItem &&
|
|
363
|
+
onUpdateSelectedItem({
|
|
364
|
+
...selectedItem,
|
|
365
|
+
datasource: next,
|
|
366
|
+
});
|
|
367
|
+
}}
|
|
368
|
+
options={{
|
|
369
|
+
minimap: { enabled: false },
|
|
370
|
+
scrollBeyondLastLine: false,
|
|
371
|
+
tabSize: 2,
|
|
372
|
+
}}
|
|
373
|
+
/>
|
|
374
|
+
</div>
|
|
375
|
+
</Form.Item>
|
|
376
|
+
</>
|
|
377
|
+
)}
|
|
378
|
+
</Form.Item>
|
|
379
|
+
</Form>
|
|
380
|
+
)}
|
|
381
|
+
{FormComp && <Divider>特有属性</Divider>}
|
|
382
|
+
{FormComp && (
|
|
383
|
+
<FormComp
|
|
384
|
+
model={model}
|
|
385
|
+
customStyle={customStyle}
|
|
386
|
+
onChange={onChange}
|
|
387
|
+
/>
|
|
388
|
+
)}
|
|
389
|
+
</>
|
|
390
|
+
)}
|
|
391
|
+
</div>
|
|
392
|
+
</Root>
|
|
393
|
+
);
|
|
394
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import React, { useContext, useMemo } from "react";
|
|
2
|
+
import Editor from "@monaco-editor/react";
|
|
3
|
+
import { Button, Space, Modal, Form, Input } from "antd";
|
|
4
|
+
import { PaneHeader } from "./PaneHeader";
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import { IconFont } from "../icon/IconFont";
|
|
7
|
+
import { DeleteOutlined, EditOutlined } from "@ant-design/icons";
|
|
8
|
+
import { DesignerContext } from "../context/DesignerContext";
|
|
9
|
+
import { ScriptItem } from "../typing";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const Root = styled.div`
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
height: 100%;
|
|
16
|
+
.body {
|
|
17
|
+
flex: 1 1 auto;
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
gap: 12px;
|
|
21
|
+
padding: 12px;
|
|
22
|
+
overflow: auto;
|
|
23
|
+
}
|
|
24
|
+
ul,
|
|
25
|
+
li {
|
|
26
|
+
list-style: none;
|
|
27
|
+
padding: 0;
|
|
28
|
+
margin: 0;
|
|
29
|
+
}
|
|
30
|
+
li {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
padding: 8px;
|
|
35
|
+
border-bottom: 1px dotted #d9d9d9;
|
|
36
|
+
}
|
|
37
|
+
li > div:first-child {
|
|
38
|
+
flex: 1 1 auto;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
text-overflow: ellipsis;
|
|
42
|
+
}
|
|
43
|
+
li:last-child {
|
|
44
|
+
border-bottom: none;
|
|
45
|
+
}
|
|
46
|
+
.function-wrapper {
|
|
47
|
+
color: #0000ff;
|
|
48
|
+
font-size: 14px;
|
|
49
|
+
padding: 0 50px;
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
export const ScriptPanel: React.FC = () => {
|
|
54
|
+
const {schema, setSchema} = useContext(DesignerContext);
|
|
55
|
+
const [visible, setVisible] = React.useState(false);
|
|
56
|
+
const [editIndex, setEditIndex] = React.useState(-1);
|
|
57
|
+
const [form] = Form.useForm<ScriptItem>();
|
|
58
|
+
const list = useMemo(() => schema.scripts || [], [schema]);
|
|
59
|
+
const onUpdateScripts = (scripts: ScriptItem[]) => {
|
|
60
|
+
setSchema({ ...schema, scripts });
|
|
61
|
+
};
|
|
62
|
+
const handleAdd = () => {
|
|
63
|
+
setEditIndex(-1);
|
|
64
|
+
form.setFieldsValue({ name: "", script: "return {};" });
|
|
65
|
+
setVisible(true);
|
|
66
|
+
};
|
|
67
|
+
const handleOk = async () => {
|
|
68
|
+
const vals = await form.validateFields().catch(() => null);
|
|
69
|
+
if (!vals) return;
|
|
70
|
+
const next = [...list];
|
|
71
|
+
if (editIndex === -1)
|
|
72
|
+
next.push({ id: Math.random().toString(36).slice(2, 10), ...vals });
|
|
73
|
+
else next[editIndex] = { ...next[editIndex], ...vals };
|
|
74
|
+
onUpdateScripts && onUpdateScripts(next);
|
|
75
|
+
setVisible(false);
|
|
76
|
+
setEditIndex(-1);
|
|
77
|
+
form.resetFields();
|
|
78
|
+
};
|
|
79
|
+
return (
|
|
80
|
+
<Root className="script-panel">
|
|
81
|
+
<PaneHeader
|
|
82
|
+
title="脚本"
|
|
83
|
+
extra={
|
|
84
|
+
<Space>
|
|
85
|
+
<a className="toolbar" onClick={handleAdd}>
|
|
86
|
+
+
|
|
87
|
+
</a>
|
|
88
|
+
</Space>
|
|
89
|
+
}
|
|
90
|
+
/>
|
|
91
|
+
<div className="body">
|
|
92
|
+
<ul>
|
|
93
|
+
{list.map((item, index) => (
|
|
94
|
+
<li key={item.id || index}>
|
|
95
|
+
<div title={item.name}>
|
|
96
|
+
<IconFont type="icon-drag" /> {item.name}
|
|
97
|
+
</div>
|
|
98
|
+
<Space>
|
|
99
|
+
<a
|
|
100
|
+
onClick={() => {
|
|
101
|
+
setEditIndex(index);
|
|
102
|
+
form.setFieldsValue({
|
|
103
|
+
name: item.name,
|
|
104
|
+
script: item.script,
|
|
105
|
+
});
|
|
106
|
+
setVisible(true);
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
<EditOutlined />
|
|
110
|
+
</a>
|
|
111
|
+
<a
|
|
112
|
+
onClick={() => {
|
|
113
|
+
const next = [...list];
|
|
114
|
+
next.splice(index, 1);
|
|
115
|
+
onUpdateScripts && onUpdateScripts(next);
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<DeleteOutlined />
|
|
119
|
+
</a>
|
|
120
|
+
</Space>
|
|
121
|
+
</li>
|
|
122
|
+
))}
|
|
123
|
+
</ul>
|
|
124
|
+
</div>
|
|
125
|
+
<Modal
|
|
126
|
+
title="添加脚本"
|
|
127
|
+
open={visible}
|
|
128
|
+
width={600}
|
|
129
|
+
styles={{
|
|
130
|
+
body: { maxHeight: "calc(100vh - 250px)", overflow: "auto" }
|
|
131
|
+
}}
|
|
132
|
+
onCancel={() => setVisible(false)}
|
|
133
|
+
footer={
|
|
134
|
+
<Space>
|
|
135
|
+
<Button type="primary" onClick={handleOk}>
|
|
136
|
+
确定
|
|
137
|
+
</Button>
|
|
138
|
+
<Button onClick={() => setVisible(false)}>取消</Button>
|
|
139
|
+
</Space>
|
|
140
|
+
}
|
|
141
|
+
>
|
|
142
|
+
<Form form={form} layout="vertical">
|
|
143
|
+
<Form.Item
|
|
144
|
+
label="脚本名称"
|
|
145
|
+
name="name"
|
|
146
|
+
rules={[{ required: true, message: "请输入脚本名称" }]}
|
|
147
|
+
>
|
|
148
|
+
<Input />
|
|
149
|
+
</Form.Item>
|
|
150
|
+
<Form.Item
|
|
151
|
+
label="脚本语句"
|
|
152
|
+
name="script"
|
|
153
|
+
rules={[{ required: true, message: "请输入脚本语句" }]}
|
|
154
|
+
>
|
|
155
|
+
<div style={{ border: "1px solid #d9d9d9", padding: "0 10px" }}>
|
|
156
|
+
<div className="function-wrapper">function fixed(data) {"{"}</div>
|
|
157
|
+
<Editor
|
|
158
|
+
height="200px"
|
|
159
|
+
defaultLanguage="javascript"
|
|
160
|
+
value={form.getFieldValue("script")}
|
|
161
|
+
onChange={(v) => form.setFieldsValue({ script: v || "" })}
|
|
162
|
+
options={{
|
|
163
|
+
minimap: { enabled: false },
|
|
164
|
+
scrollBeyondLastLine: false,
|
|
165
|
+
tabSize: 2,
|
|
166
|
+
}}
|
|
167
|
+
/>
|
|
168
|
+
<div className="function-wrapper">{"}"}</div>
|
|
169
|
+
</div>
|
|
170
|
+
</Form.Item>
|
|
171
|
+
</Form>
|
|
172
|
+
</Modal>
|
|
173
|
+
</Root>
|
|
174
|
+
);
|
|
175
|
+
};
|