bi-sdk-react 0.0.70 → 0.0.72
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 +58 -58
- package/dist/index.html +1 -0
- package/dist/static/css/index.0c6f4f43.css +1 -0
- package/dist/static/js/index.08767759.js +1443 -0
- package/dist/static/js/vendor.7e15421f.js +477 -0
- package/dist/static/js/vendor.7e15421f.js.LICENSE.txt +208 -0
- package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +1 -1
- package/dist/umd/js/bi-sdk.umd.min.js +32 -32
- package/package.json +1 -1
- package/src/components/hooks/event.ts +36 -37
- package/src/components/layout/PageItem.tsx +23 -1
- package/src/components/plugins/@antd/index.ts +4 -0
- package/src/components/plugins/@antd/item-props/TableProps.tsx +77 -24
- package/src/components/plugins/@antd/items/TableRender.tsx +55 -31
package/package.json
CHANGED
|
@@ -14,22 +14,22 @@ export const useEvent = (item: SchemaItemType) => {
|
|
|
14
14
|
|
|
15
15
|
const handleEvent = (eventName: string, arg?: any) => {
|
|
16
16
|
const script = events[eventName];
|
|
17
|
+
|
|
17
18
|
if (script) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`
|
|
19
|
+
try {
|
|
20
|
+
const safeEval = new Function(
|
|
21
|
+
"console",
|
|
22
|
+
"Math",
|
|
23
|
+
"Date",
|
|
24
|
+
"Array",
|
|
25
|
+
"Object",
|
|
26
|
+
"String",
|
|
27
|
+
"Number",
|
|
28
|
+
"Boolean",
|
|
29
|
+
"callMethod",
|
|
30
|
+
"updateEnv",
|
|
31
|
+
"param",
|
|
32
|
+
`
|
|
33
33
|
"use strict";
|
|
34
34
|
const window = undefined;
|
|
35
35
|
const document = undefined;
|
|
@@ -43,28 +43,27 @@ export const useEvent = (item: SchemaItemType) => {
|
|
|
43
43
|
const sessionStorage = undefined;
|
|
44
44
|
${script}
|
|
45
45
|
`,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
46
|
+
);
|
|
47
|
+
return (safeEval as any)(
|
|
48
|
+
console,
|
|
49
|
+
Math,
|
|
50
|
+
Date,
|
|
51
|
+
Array,
|
|
52
|
+
Object,
|
|
53
|
+
String,
|
|
54
|
+
Number,
|
|
55
|
+
Boolean,
|
|
56
|
+
callMethod,
|
|
57
|
+
updateEnv,
|
|
58
|
+
{
|
|
59
|
+
item,
|
|
60
|
+
sourceId: item.id,
|
|
61
|
+
arg,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
} catch (evalError) {
|
|
65
|
+
console.error("点击事件脚本执行失败:", evalError);
|
|
66
|
+
return null;
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
};
|
|
@@ -107,6 +107,24 @@ const Toolbar: React.FC<{
|
|
|
107
107
|
margin: "0 -24px",
|
|
108
108
|
},
|
|
109
109
|
}}
|
|
110
|
+
modalRender={(node) => (
|
|
111
|
+
<div
|
|
112
|
+
onClick={(e) => {
|
|
113
|
+
e.stopPropagation();
|
|
114
|
+
}}
|
|
115
|
+
onMouseDown={(e) => {
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
}}
|
|
118
|
+
onMouseUp={(e) => {
|
|
119
|
+
e.stopPropagation();
|
|
120
|
+
}}
|
|
121
|
+
onPointerDown={(e) => {
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
{node}
|
|
126
|
+
</div>
|
|
127
|
+
)}
|
|
110
128
|
footer={
|
|
111
129
|
<Space>
|
|
112
130
|
<Button
|
|
@@ -158,7 +176,11 @@ const Toolbar: React.FC<{
|
|
|
158
176
|
}}
|
|
159
177
|
/>
|
|
160
178
|
</Modal>
|
|
161
|
-
<ToolbarWrap
|
|
179
|
+
<ToolbarWrap
|
|
180
|
+
onClick={(e) => {
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
162
184
|
{!!ancestors?.length ? (
|
|
163
185
|
<Dropdown
|
|
164
186
|
placement="topLeft"
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
1
|
import {
|
|
2
|
+
AlignCenterOutlined,
|
|
3
|
+
AlignLeftOutlined,
|
|
4
|
+
AlignRightOutlined,
|
|
5
|
+
DeleteOutlined,
|
|
6
|
+
EditOutlined,
|
|
7
|
+
ThunderboltOutlined
|
|
8
|
+
} from "@ant-design/icons";
|
|
9
|
+
import {
|
|
10
|
+
Button,
|
|
11
|
+
Descriptions,
|
|
12
|
+
Divider,
|
|
3
13
|
Form,
|
|
14
|
+
Input,
|
|
15
|
+
InputNumber,
|
|
16
|
+
Modal,
|
|
4
17
|
Radio,
|
|
18
|
+
Select,
|
|
19
|
+
Space,
|
|
5
20
|
Switch,
|
|
6
|
-
InputNumber,
|
|
7
|
-
Divider,
|
|
8
21
|
Table,
|
|
9
|
-
Space,
|
|
10
|
-
Button,
|
|
11
|
-
Modal,
|
|
12
|
-
Input,
|
|
13
22
|
type TableProps as AntTableProps,
|
|
14
|
-
Select,
|
|
15
23
|
} from "antd";
|
|
24
|
+
import React, { useState } from "react";
|
|
16
25
|
import type { PropEditorProps } from "./types";
|
|
17
|
-
import {
|
|
18
|
-
AlignCenterOutlined,
|
|
19
|
-
AlignLeftOutlined,
|
|
20
|
-
AlignRightOutlined,
|
|
21
|
-
DeleteOutlined,
|
|
22
|
-
EditOutlined,
|
|
23
|
-
} from "@ant-design/icons";
|
|
24
26
|
|
|
25
27
|
export type TableColumnModel = {
|
|
26
28
|
title: string;
|
|
@@ -72,13 +74,22 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
72
74
|
const editingForm =
|
|
73
75
|
editingIndex != null && model.columns[editingIndex]
|
|
74
76
|
? model.columns[editingIndex]
|
|
75
|
-
: {
|
|
77
|
+
: {
|
|
78
|
+
title: "",
|
|
79
|
+
dataIndex: "",
|
|
80
|
+
width: "",
|
|
81
|
+
align: "left",
|
|
82
|
+
ellipsis: false,
|
|
83
|
+
customRender: "",
|
|
84
|
+
className: "",
|
|
85
|
+
};
|
|
76
86
|
const columns = [
|
|
77
87
|
{ title: "列名", dataIndex: "title" },
|
|
78
88
|
{
|
|
79
89
|
title: "数据索引",
|
|
80
90
|
dataIndex: "dataIndex",
|
|
81
|
-
render: (v: string | string[]) =>
|
|
91
|
+
render: (v: string | string[]) =>
|
|
92
|
+
typeof v === "string" ? v : v.join("."),
|
|
82
93
|
},
|
|
83
94
|
{
|
|
84
95
|
title: "操作",
|
|
@@ -220,6 +231,41 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
220
231
|
onChange={(e) => trigger("paginationItemClassNames", e)}
|
|
221
232
|
/>
|
|
222
233
|
</Form.Item>
|
|
234
|
+
<Divider>组件事件</Divider>
|
|
235
|
+
<Descriptions
|
|
236
|
+
size="small"
|
|
237
|
+
layout="vertical"
|
|
238
|
+
column={1}
|
|
239
|
+
colon={false}
|
|
240
|
+
items={[
|
|
241
|
+
{
|
|
242
|
+
key: "onPageChange",
|
|
243
|
+
label: <><ThunderboltOutlined /> onPageChange:分页切换/分页大小变化</>,
|
|
244
|
+
children: (
|
|
245
|
+
<div>
|
|
246
|
+
<label>事件参数取值:</label>
|
|
247
|
+
<div>const {`{sourceId, item, arg}`} = param;</div>
|
|
248
|
+
<div>const {`{current, size}`} = arg;</div>
|
|
249
|
+
</div>
|
|
250
|
+
),
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: "columnClick",
|
|
254
|
+
label: <><ThunderboltOutlined /> columnClick:点击单元格</>,
|
|
255
|
+
children: (
|
|
256
|
+
<div>
|
|
257
|
+
事件参数取值:
|
|
258
|
+
<div>const {`{sourceId, item, arg}`} = param;</div>
|
|
259
|
+
<div>const {`{column, rowData}`} = arg;</div>
|
|
260
|
+
</div>
|
|
261
|
+
),
|
|
262
|
+
},
|
|
263
|
+
]}
|
|
264
|
+
styles={{
|
|
265
|
+
label: { color: "var(--ant-color-text)", alignItems: "center" },
|
|
266
|
+
content: { color: "var(--ant-color-text-label)" },
|
|
267
|
+
}}
|
|
268
|
+
/>
|
|
223
269
|
<Modal
|
|
224
270
|
title="编辑列"
|
|
225
271
|
open={editVisible}
|
|
@@ -231,7 +277,7 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
231
277
|
<div
|
|
232
278
|
style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}
|
|
233
279
|
>
|
|
234
|
-
<Form.Item label="列名" style={{marginBottom: 10}}>
|
|
280
|
+
<Form.Item label="列名" style={{ marginBottom: 10 }}>
|
|
235
281
|
<Input
|
|
236
282
|
value={editingForm.title}
|
|
237
283
|
onChange={(e) =>
|
|
@@ -239,7 +285,7 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
239
285
|
}
|
|
240
286
|
/>
|
|
241
287
|
</Form.Item>
|
|
242
|
-
<Form.Item label="数据索引" style={{marginBottom: 10}}>
|
|
288
|
+
<Form.Item label="数据索引" style={{ marginBottom: 10 }}>
|
|
243
289
|
<Select
|
|
244
290
|
mode="tags"
|
|
245
291
|
value={
|
|
@@ -250,7 +296,7 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
250
296
|
onChange={(e) => setColumn(editingIndex!, { dataIndex: e })}
|
|
251
297
|
/>
|
|
252
298
|
</Form.Item>
|
|
253
|
-
<Form.Item label="宽度" style={{marginBottom: 10}}>
|
|
299
|
+
<Form.Item label="宽度" style={{ marginBottom: 10 }}>
|
|
254
300
|
<Input
|
|
255
301
|
value={editingForm.width}
|
|
256
302
|
onChange={(e) =>
|
|
@@ -258,7 +304,7 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
258
304
|
}
|
|
259
305
|
/>
|
|
260
306
|
</Form.Item>
|
|
261
|
-
<Form.Item label="对齐" style={{marginBottom: 10}}>
|
|
307
|
+
<Form.Item label="对齐" style={{ marginBottom: 10 }}>
|
|
262
308
|
<Radio.Group
|
|
263
309
|
value={editingForm.align}
|
|
264
310
|
onChange={(e) =>
|
|
@@ -276,13 +322,17 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
276
322
|
</Radio.Button>
|
|
277
323
|
</Radio.Group>
|
|
278
324
|
</Form.Item>
|
|
279
|
-
<Form.Item label="省略" style={{marginBottom: 10}}>
|
|
325
|
+
<Form.Item label="省略" style={{ marginBottom: 10 }}>
|
|
280
326
|
<Switch
|
|
281
327
|
checked={!!editingForm.ellipsis}
|
|
282
328
|
onChange={(v) => setColumn(editingIndex!, { ellipsis: v })}
|
|
283
329
|
/>
|
|
284
330
|
</Form.Item>
|
|
285
|
-
<Form.Item
|
|
331
|
+
<Form.Item
|
|
332
|
+
label="自定义渲染"
|
|
333
|
+
tooltip="支持自定义渲染,使用{{}}包裹表达式,例如:{{text}},{{record.变量名}},{{index}},{{$g.变量名}},{{$e.变量名}}"
|
|
334
|
+
style={{ gridColumn: "span 2 / span 2", marginBottom: 10 }}
|
|
335
|
+
>
|
|
286
336
|
<Input.TextArea
|
|
287
337
|
value={editingForm.customRender}
|
|
288
338
|
onChange={(e) =>
|
|
@@ -290,7 +340,10 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
|
|
|
290
340
|
}
|
|
291
341
|
/>
|
|
292
342
|
</Form.Item>
|
|
293
|
-
<Form.Item
|
|
343
|
+
<Form.Item
|
|
344
|
+
label="类名"
|
|
345
|
+
style={{ gridColumn: "span 2 / span 2", marginBottom: 10 }}
|
|
346
|
+
>
|
|
294
347
|
<Input
|
|
295
348
|
value={editingForm.className}
|
|
296
349
|
onChange={(e) =>
|
|
@@ -3,6 +3,7 @@ import React, { useContext, useEffect, useMemo, useState } from "react";
|
|
|
3
3
|
import { PageContext } from "../../../context/PageContext";
|
|
4
4
|
import { HtmlBaseProps } from "../../../typing";
|
|
5
5
|
import { useDatasource } from "../../../hooks/datasource";
|
|
6
|
+
import { useEvent } from "../../../hooks/event";
|
|
6
7
|
|
|
7
8
|
export type TableRenderProps = {
|
|
8
9
|
columns?: any[];
|
|
@@ -43,6 +44,7 @@ export const TableRender: React.FC<TableRenderProps> = ({
|
|
|
43
44
|
paginationItemClassNames = [],
|
|
44
45
|
}) => {
|
|
45
46
|
const { initCallback, globalVars, env } = useContext(PageContext);
|
|
47
|
+
const { handleEvent } = useEvent(item);
|
|
46
48
|
const [page, setPage] = useState<{
|
|
47
49
|
current: number;
|
|
48
50
|
pageSize: number;
|
|
@@ -79,40 +81,60 @@ export const TableRender: React.FC<TableRenderProps> = ({
|
|
|
79
81
|
const dataSource = useDatasource({ item, query: page });
|
|
80
82
|
const realColumns = columns.map((item: any) => ({
|
|
81
83
|
...item,
|
|
82
|
-
render:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
84
|
+
render: (text: any, record: any, index: number) => {
|
|
85
|
+
if (
|
|
86
|
+
!item.customRender ||
|
|
87
|
+
(typeof item.customRender === "string" &&
|
|
88
|
+
item.customRender.trim() === "")
|
|
89
|
+
) {
|
|
90
|
+
return item.dataIndex?.length ? (
|
|
91
|
+
<div
|
|
92
|
+
onClick={() =>
|
|
93
|
+
handleEvent("columnClick", { column: item, rowData: record })
|
|
94
|
+
}
|
|
95
|
+
>
|
|
96
|
+
{text}
|
|
97
|
+
</div>
|
|
98
|
+
) : (
|
|
99
|
+
<></>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const html = (item.customRender || "").replace(
|
|
103
|
+
/{\s*{\s*([^}]+)\s*}\s*}/g,
|
|
104
|
+
(_match: any, p1: string) => {
|
|
105
|
+
try {
|
|
106
|
+
return (func(p1) as any)(
|
|
107
|
+
console,
|
|
108
|
+
Math,
|
|
109
|
+
Date,
|
|
110
|
+
Array,
|
|
111
|
+
Object,
|
|
112
|
+
String,
|
|
113
|
+
Number,
|
|
114
|
+
Boolean,
|
|
115
|
+
globalVars,
|
|
116
|
+
env.global,
|
|
117
|
+
text,
|
|
118
|
+
record,
|
|
119
|
+
index,
|
|
110
120
|
);
|
|
111
|
-
|
|
112
|
-
|
|
121
|
+
} catch {
|
|
122
|
+
return "";
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
return (
|
|
127
|
+
<div
|
|
128
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
129
|
+
onClick={() =>
|
|
130
|
+
handleEvent("columnClick", { column: item, rowData: record })
|
|
131
|
+
}
|
|
132
|
+
></div>
|
|
133
|
+
);
|
|
134
|
+
},
|
|
113
135
|
}));
|
|
114
136
|
|
|
115
|
-
const data: {total: number
|
|
137
|
+
const data: { total: number; records: any[] } = useMemo(() => {
|
|
116
138
|
let ds;
|
|
117
139
|
if (!dataKey || dataKey.trim() === "") {
|
|
118
140
|
ds = dataSource || [];
|
|
@@ -189,9 +211,11 @@ export const TableRender: React.FC<TableRenderProps> = ({
|
|
|
189
211
|
},
|
|
190
212
|
onChange: (page: number, pageSize: number) => {
|
|
191
213
|
setPage({ current: page, pageSize });
|
|
214
|
+
handleEvent("onPageChange", { current: page, size: pageSize });
|
|
192
215
|
},
|
|
193
216
|
onShowSizeChange: (current: number, size: number) => {
|
|
194
217
|
setPage({ current, pageSize: size });
|
|
218
|
+
handleEvent("onPageChange", { current, size });
|
|
195
219
|
},
|
|
196
220
|
} as PaginationProps),
|
|
197
221
|
[
|