bi-sdk-react 0.0.69 → 0.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bi-sdk-react",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/umd/js/bi-sdk.umd.min.js",
@@ -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
- if (script) {
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
- `
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
- 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;
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
  };
@@ -160,6 +160,10 @@ export const TablePlugin: PluginType = {
160
160
  ],
161
161
  },
162
162
  },
163
+ events: [
164
+ { name: "分页切换/分页大小变化", handler: "onPageChange" },
165
+ { name: "点击单元格", handler: "columnClick" },
166
+ ],
163
167
  };
164
168
 
165
169
  export const ListPlugin: PluginType = {
@@ -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
- : { title: "", dataIndex: "", width: "", align: "left", ellipsis: false, customRender: "", className: "" };
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[]) => (typeof v === "string" ? v : v.join(".")),
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 label="自定义渲染" tooltip="支持自定义渲染,使用{{}}包裹表达式,例如:{{text}},{{record.变量名}},{{index}},{{$g.变量名}},{{$e.变量名}}" style={{gridColumn: "span 2 / span 2", marginBottom: 10}}>
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 label="类名" style={{gridColumn: "span 2 / span 2", marginBottom: 10}}>
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,45 +81,64 @@ 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
- !item.customRender ||
84
- (typeof item.customRender === "string" && item.customRender.trim() === "")
85
- ? item.render
86
- : (text: any, record: any, index: number) => {
87
- const html = (item.customRender || "").replace(
88
- /{\s*{\s*([^}]+)\s*}\s*}/g,
89
- (_match: any, p1: string) => {
90
- try {
91
- return (func(p1) as any)(
92
- console,
93
- Math,
94
- Date,
95
- Array,
96
- Object,
97
- String,
98
- Number,
99
- Boolean,
100
- globalVars,
101
- env.global,
102
- text,
103
- record,
104
- index,
105
- );
106
- } catch {
107
- return "";
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
- return <div dangerouslySetInnerHTML={{ __html: html }}></div>;
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, records: any[]} = useMemo(() => {
116
- if (!dataKey || dataKey.trim() === "") {
117
- return dataSource || [];
118
- }
137
+ const data: { total: number; records: any[] } = useMemo(() => {
119
138
  let ds;
120
- if (dataKey.startsWith("$g.")) {
139
+ if (!dataKey || dataKey.trim() === "") {
140
+ ds = dataSource || [];
141
+ } else if (dataKey.startsWith("$g.")) {
121
142
  try {
122
143
  ds = (func(dataKey) as any)(
123
144
  console,
@@ -190,9 +211,11 @@ export const TableRender: React.FC<TableRenderProps> = ({
190
211
  },
191
212
  onChange: (page: number, pageSize: number) => {
192
213
  setPage({ current: page, pageSize });
214
+ handleEvent("onPageChange", { current: page, size: pageSize });
193
215
  },
194
216
  onShowSizeChange: (current: number, size: number) => {
195
217
  setPage({ current, pageSize: size });
218
+ handleEvent("onPageChange", { current, size });
196
219
  },
197
220
  } as PaginationProps),
198
221
  [