bi-sdk-react 0.0.56 → 0.0.57

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.56",
3
+ "version": "0.0.57",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/umd/js/bi-sdk.umd.min.js",
@@ -24,10 +24,12 @@ import {
24
24
 
25
25
  export type TableColumnModel = {
26
26
  title: string;
27
- dataIndex: string;
27
+ dataIndex: string | string[];
28
28
  width?: string;
29
29
  align?: "left" | "center" | "right";
30
30
  ellipsis?: boolean;
31
+ customRender?: string;
32
+ className?: string;
31
33
  };
32
34
  export type TableModel = {
33
35
  pageSize?: number;
@@ -70,10 +72,14 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
70
72
  const editingForm =
71
73
  editingIndex != null && model.columns[editingIndex]
72
74
  ? model.columns[editingIndex]
73
- : { title: "", dataIndex: "", width: "", align: "left", ellipsis: false };
75
+ : { title: "", dataIndex: "", width: "", align: "left", ellipsis: false, customRender: "", className: "" };
74
76
  const columns = [
75
77
  { title: "列名", dataIndex: "title" },
76
- { title: "数据索引", dataIndex: "dataIndex" },
78
+ {
79
+ title: "数据索引",
80
+ dataIndex: "dataIndex",
81
+ render: (v: string | string[]) => (typeof v === "string" ? v : v.join(".")),
82
+ },
77
83
  {
78
84
  title: "操作",
79
85
  width: 80,
@@ -98,7 +104,10 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
98
104
  return (
99
105
  <div>
100
106
  <Form labelCol={{ span: 12 }} wrapperCol={{ span: 12 }}>
101
- <Form.Item label="数据键" tooltip="数据键用于指定数据来源中的数据项,例如:'data.items'">
107
+ <Form.Item
108
+ label="数据键"
109
+ tooltip="数据键用于指定数据来源中的数据项,例如:'data.items'"
110
+ >
102
111
  <Input
103
112
  size="small"
104
113
  value={model.dataKey}
@@ -178,45 +187,37 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
178
187
  <Button size="small" onClick={addColumn} block>
179
188
  添加列
180
189
  </Button>
181
- <Divider style={{marginTop: 10}}>样式设置</Divider>
190
+ <Divider style={{ marginTop: 10 }}>样式设置</Divider>
182
191
  <Form.Item label="表头单元格类名" layout="vertical">
183
192
  <Select
184
193
  mode="tags"
185
194
  size="small"
186
- value={(model.headerCellClassNames || [])}
187
- onChange={(e) =>
188
- trigger("headerCellClassNames", e)
189
- }
195
+ value={model.headerCellClassNames || []}
196
+ onChange={(e) => trigger("headerCellClassNames", e)}
190
197
  />
191
198
  </Form.Item>
192
199
  <Form.Item label="表格单元格类名" layout="vertical">
193
200
  <Select
194
201
  mode="tags"
195
202
  size="small"
196
- value={(model.bodyCellClassNames || [])}
197
- onChange={(e) =>
198
- trigger("bodyCellClassNames", e)
199
- }
203
+ value={model.bodyCellClassNames || []}
204
+ onChange={(e) => trigger("bodyCellClassNames", e)}
200
205
  />
201
206
  </Form.Item>
202
207
  <Form.Item label="分页根类名" layout="vertical">
203
208
  <Select
204
209
  mode="tags"
205
210
  size="small"
206
- value={(model.paginationRootClassNames || [])}
207
- onChange={(e) =>
208
- trigger("paginationRootClassNames", e)
209
- }
211
+ value={model.paginationRootClassNames || []}
212
+ onChange={(e) => trigger("paginationRootClassNames", e)}
210
213
  />
211
214
  </Form.Item>
212
215
  <Form.Item label="分页项类名" layout="vertical">
213
216
  <Select
214
217
  mode="tags"
215
218
  size="small"
216
- value={(model.paginationItemClassNames || [])}
217
- onChange={(e) =>
218
- trigger("paginationItemClassNames", e)
219
- }
219
+ value={model.paginationItemClassNames || []}
220
+ onChange={(e) => trigger("paginationItemClassNames", e)}
220
221
  />
221
222
  </Form.Item>
222
223
  <Modal
@@ -226,11 +227,11 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
226
227
  width={400}
227
228
  onCancel={() => setEditVisible(false)}
228
229
  >
229
- <Form layout="vertical">
230
+ <Form layout="vertical" size="small">
230
231
  <div
231
232
  style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}
232
233
  >
233
- <Form.Item label="列名">
234
+ <Form.Item label="列名" style={{marginBottom: 10}}>
234
235
  <Input
235
236
  value={editingForm.title}
236
237
  onChange={(e) =>
@@ -238,15 +239,18 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
238
239
  }
239
240
  />
240
241
  </Form.Item>
241
- <Form.Item label="数据索引">
242
- <Input
243
- value={editingForm.dataIndex}
244
- onChange={(e) =>
245
- setColumn(editingIndex!, { dataIndex: e.target.value })
242
+ <Form.Item label="数据索引" style={{marginBottom: 10}}>
243
+ <Select
244
+ mode="tags"
245
+ value={
246
+ typeof editingForm.dataIndex === "string"
247
+ ? [editingForm.dataIndex]
248
+ : editingForm.dataIndex
246
249
  }
250
+ onChange={(e) => setColumn(editingIndex!, { dataIndex: e })}
247
251
  />
248
252
  </Form.Item>
249
- <Form.Item label="宽度">
253
+ <Form.Item label="宽度" style={{marginBottom: 10}}>
250
254
  <Input
251
255
  value={editingForm.width}
252
256
  onChange={(e) =>
@@ -254,7 +258,7 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
254
258
  }
255
259
  />
256
260
  </Form.Item>
257
- <Form.Item label="对齐">
261
+ <Form.Item label="对齐" style={{marginBottom: 10}}>
258
262
  <Radio.Group
259
263
  value={editingForm.align}
260
264
  onChange={(e) =>
@@ -272,12 +276,28 @@ export const TableProps: React.FC<PropEditorProps<TableModel>> = ({
272
276
  </Radio.Button>
273
277
  </Radio.Group>
274
278
  </Form.Item>
275
- <Form.Item label="省略">
279
+ <Form.Item label="省略" style={{marginBottom: 10}}>
276
280
  <Switch
277
281
  checked={!!editingForm.ellipsis}
278
282
  onChange={(v) => setColumn(editingIndex!, { ellipsis: v })}
279
283
  />
280
284
  </Form.Item>
285
+ <Form.Item label="自定义渲染" tooltip="支持自定义渲染,使用{{}}包裹表达式,例如:{{text}},{{record.变量名}},{{index}},{{$g.变量名}},{{$e.变量名}}" style={{gridColumn: "span 2 / span 2", marginBottom: 10}}>
286
+ <Input.TextArea
287
+ value={editingForm.customRender}
288
+ onChange={(e) =>
289
+ setColumn(editingIndex!, { customRender: e.target.value })
290
+ }
291
+ />
292
+ </Form.Item>
293
+ <Form.Item label="类名" style={{gridColumn: "span 2 / span 2", marginBottom: 10}}>
294
+ <Input
295
+ value={editingForm.className}
296
+ onChange={(e) =>
297
+ setColumn(editingIndex!, { className: e.target.value })
298
+ }
299
+ />
300
+ </Form.Item>
281
301
  </div>
282
302
  </Form>
283
303
  </Modal>
@@ -42,12 +42,40 @@ export const TableRender: React.FC<TableRenderProps> = ({
42
42
  paginationRootClassNames = [],
43
43
  paginationItemClassNames = [],
44
44
  }) => {
45
- const { initCallback } = useContext(PageContext);
45
+ const { initCallback, globalVars, env } = useContext(PageContext);
46
46
  const [page, setPage] = useState<{
47
47
  current: number;
48
48
  pageSize: number;
49
49
  }>({ current: 1, pageSize });
50
50
 
51
+ const func = (path: string) =>
52
+ new Function(
53
+ "console",
54
+ "Math",
55
+ "Date",
56
+ "Array",
57
+ "Object",
58
+ "String",
59
+ "Number",
60
+ "Boolean",
61
+ "$g",
62
+ "$e",
63
+ "text",
64
+ "record",
65
+ "index",
66
+ `
67
+ "use strict";
68
+ const window = undefined;
69
+ const document = undefined;
70
+ const global = undefined;
71
+ const process = undefined;
72
+ const require = undefined;
73
+ const module = undefined;
74
+ const exports = undefined;
75
+ return ${path};
76
+ `,
77
+ );
78
+
51
79
  const dataSource = useDatasource({ item, query: page });
52
80
  const realColumns = columns.map((item: any) => ({
53
81
  ...item,
@@ -56,43 +84,31 @@ export const TableRender: React.FC<TableRenderProps> = ({
56
84
  (typeof item.customRender === "string" && item.customRender.trim() === "")
57
85
  ? item.render
58
86
  : (text: any, record: any, index: number) => {
59
- const safeEval = new Function(
60
- "console",
61
- "Math",
62
- "Date",
63
- "Array",
64
- "Object",
65
- "String",
66
- "Number",
67
- "Boolean",
68
- "text",
69
- "record",
70
- "index",
71
- `
72
- "use strict";
73
- const window = undefined;
74
- const document = undefined;
75
- const global = undefined;
76
- const process = undefined;
77
- const require = undefined;
78
- const module = undefined;
79
- const exports = undefined;
80
- ${item.customRender}
81
- `,
82
- );
83
- return (safeEval as any)(
84
- console,
85
- Math,
86
- Date,
87
- Array,
88
- Object,
89
- String,
90
- Number,
91
- Boolean,
92
- text,
93
- record,
94
- index,
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
+ },
95
110
  );
111
+ return <div dangerouslySetInnerHTML={{ __html: html }}></div>;
96
112
  },
97
113
  }));
98
114
 
@@ -142,7 +158,16 @@ export const TableRender: React.FC<TableRenderProps> = ({
142
158
  setPage({ current, pageSize: size });
143
159
  },
144
160
  } as PaginationProps),
145
- [data, page, pageSize, size, showSizeChanger, showQuickJumper, hideOnSinglePage, showTotal],
161
+ [
162
+ data,
163
+ page,
164
+ pageSize,
165
+ size,
166
+ showSizeChanger,
167
+ showQuickJumper,
168
+ hideOnSinglePage,
169
+ showTotal,
170
+ ],
146
171
  );
147
172
 
148
173
  const callback = () => {