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.
Files changed (146) hide show
  1. package/dist/es/css/bi-sdk.css +1 -0
  2. package/dist/es/js/bi-sdk.es.js +795 -0
  3. package/dist/es/js/bi-sdk.es.js.LICENSE.txt +9 -0
  4. package/dist/types/components/PageDesigner.d.ts +10 -0
  5. package/dist/types/components/context/DesignerContext.d.ts +15 -0
  6. package/dist/types/components/context/EnvContext.d.ts +15 -0
  7. package/dist/types/components/dnd/DropContainer.d.ts +21 -0
  8. package/dist/types/components/example.d.ts +225 -0
  9. package/dist/types/components/hooks/datasource.d.ts +1 -0
  10. package/dist/types/components/hooks/useDeepCompareEffect.d.ts +1 -0
  11. package/dist/types/components/icon/IconFont.d.ts +6 -0
  12. package/dist/types/components/index.d.ts +10 -0
  13. package/dist/types/components/layout/PageCanvas.d.ts +6 -0
  14. package/dist/types/components/layout/PageItem.d.ts +27 -0
  15. package/dist/types/components/panel/AiPanel.d.ts +8 -0
  16. package/dist/types/components/panel/CascadePanel.d.ts +2 -0
  17. package/dist/types/components/panel/ChatInput.d.ts +28 -0
  18. package/dist/types/components/panel/CodePanel.d.ts +2 -0
  19. package/dist/types/components/panel/ComponentPanel.d.ts +2 -0
  20. package/dist/types/components/panel/DatasourcePanel.d.ts +2 -0
  21. package/dist/types/components/panel/LayerPanel.d.ts +2 -0
  22. package/dist/types/components/panel/PaneHeader.d.ts +6 -0
  23. package/dist/types/components/panel/PropertiesPanel.d.ts +2 -0
  24. package/dist/types/components/panel/ScriptPanel.d.ts +2 -0
  25. package/dist/types/components/panel/VariablesPanel.d.ts +2 -0
  26. package/dist/types/components/panel/index.d.ts +9 -0
  27. package/dist/types/components/plugins/@antd/index.d.ts +22 -0
  28. package/dist/types/components/plugins/@antd/item-props/ButtonProps.d.ts +8 -0
  29. package/dist/types/components/plugins/@antd/item-props/CapsuleProps.d.ts +13 -0
  30. package/dist/types/components/plugins/@antd/item-props/CardProps.d.ts +8 -0
  31. package/dist/types/components/plugins/@antd/item-props/CheckboxProps.d.ts +13 -0
  32. package/dist/types/components/plugins/@antd/item-props/ColProps.d.ts +12 -0
  33. package/dist/types/components/plugins/@antd/item-props/DatePickerProps.d.ts +8 -0
  34. package/dist/types/components/plugins/@antd/item-props/EchartsProps.d.ts +6 -0
  35. package/dist/types/components/plugins/@antd/item-props/HtmlProps.d.ts +6 -0
  36. package/dist/types/components/plugins/@antd/item-props/ImageProps.d.ts +10 -0
  37. package/dist/types/components/plugins/@antd/item-props/InputNumberProps.d.ts +9 -0
  38. package/dist/types/components/plugins/@antd/item-props/InputProps.d.ts +10 -0
  39. package/dist/types/components/plugins/@antd/item-props/ListProps.d.ts +10 -0
  40. package/dist/types/components/plugins/@antd/item-props/PageHeaderProps.d.ts +7 -0
  41. package/dist/types/components/plugins/@antd/item-props/RowProps.d.ts +6 -0
  42. package/dist/types/components/plugins/@antd/item-props/SelectProps.d.ts +16 -0
  43. package/dist/types/components/plugins/@antd/item-props/SpaceProps.d.ts +7 -0
  44. package/dist/types/components/plugins/@antd/item-props/SwitchProps.d.ts +6 -0
  45. package/dist/types/components/plugins/@antd/item-props/TableProps.d.ts +15 -0
  46. package/dist/types/components/plugins/@antd/item-props/TextProps.d.ts +6 -0
  47. package/dist/types/components/plugins/@antd/item-props/index.d.ts +19 -0
  48. package/dist/types/components/plugins/@antd/item-props/types.d.ts +5 -0
  49. package/dist/types/components/plugins/@antd/items/ButtonRender.d.ts +14 -0
  50. package/dist/types/components/plugins/@antd/items/CapsuleRender.d.ts +14 -0
  51. package/dist/types/components/plugins/@antd/items/CardRender.d.ts +12 -0
  52. package/dist/types/components/plugins/@antd/items/CheckboxRender.d.ts +14 -0
  53. package/dist/types/components/plugins/@antd/items/ColRender.d.ts +13 -0
  54. package/dist/types/components/plugins/@antd/items/DatePickerRender.d.ts +14 -0
  55. package/dist/types/components/plugins/@antd/items/EchartsRender.d.ts +10 -0
  56. package/dist/types/components/plugins/@antd/items/HtmlRender.d.ts +20 -0
  57. package/dist/types/components/plugins/@antd/items/ImageRender.d.ts +10 -0
  58. package/dist/types/components/plugins/@antd/items/InputNumberRender.d.ts +17 -0
  59. package/dist/types/components/plugins/@antd/items/InputRender.d.ts +17 -0
  60. package/dist/types/components/plugins/@antd/items/ListRender.d.ts +11 -0
  61. package/dist/types/components/plugins/@antd/items/PageHeaderRender.d.ts +8 -0
  62. package/dist/types/components/plugins/@antd/items/RowRender.d.ts +13 -0
  63. package/dist/types/components/plugins/@antd/items/SelectRender.d.ts +18 -0
  64. package/dist/types/components/plugins/@antd/items/SpaceRender.d.ts +10 -0
  65. package/dist/types/components/plugins/@antd/items/SwitchRender.d.ts +14 -0
  66. package/dist/types/components/plugins/@antd/items/TableRender.d.ts +12 -0
  67. package/dist/types/components/plugins/@antd/items/TextRender.d.ts +9 -0
  68. package/dist/types/components/plugins/@antd/items/index.d.ts +19 -0
  69. package/dist/types/components/typing.d.ts +80 -0
  70. package/dist/types/components/utils.d.ts +9 -0
  71. package/dist/types/example.d.ts +2 -0
  72. package/dist/types/index.d.ts +1 -0
  73. package/dist/umd/css/bi-sdk.css +1 -0
  74. package/dist/umd/js/bi-sdk.umd.min.js +795 -0
  75. package/dist/umd/js/bi-sdk.umd.min.js.LICENSE.txt +9 -0
  76. package/package.json +52 -0
  77. package/src/components/PageDesigner.tsx +509 -0
  78. package/src/components/context/DesignerContext.tsx +71 -0
  79. package/src/components/context/EnvContext.tsx +42 -0
  80. package/src/components/dnd/DropContainer.tsx +474 -0
  81. package/src/components/example.ts +577 -0
  82. package/src/components/hooks/datasource.ts +23 -0
  83. package/src/components/hooks/useDeepCompareEffect.ts +12 -0
  84. package/src/components/icon/IconFont.tsx +16 -0
  85. package/src/components/index.ts +29 -0
  86. package/src/components/layout/PageCanvas.tsx +145 -0
  87. package/src/components/layout/PageItem.tsx +182 -0
  88. package/src/components/panel/AiPanel.tsx +116 -0
  89. package/src/components/panel/CascadePanel.tsx +163 -0
  90. package/src/components/panel/ChatInput.tsx +550 -0
  91. package/src/components/panel/CodePanel.tsx +48 -0
  92. package/src/components/panel/ComponentPanel.tsx +119 -0
  93. package/src/components/panel/DatasourcePanel.tsx +419 -0
  94. package/src/components/panel/LayerPanel.tsx +238 -0
  95. package/src/components/panel/PaneHeader.tsx +34 -0
  96. package/src/components/panel/PropertiesPanel.tsx +394 -0
  97. package/src/components/panel/ScriptPanel.tsx +175 -0
  98. package/src/components/panel/VariablesPanel.tsx +153 -0
  99. package/src/components/panel/index.ts +9 -0
  100. package/src/components/plugins/@antd/index.ts +445 -0
  101. package/src/components/plugins/@antd/item-props/ButtonProps.tsx +91 -0
  102. package/src/components/plugins/@antd/item-props/CapsuleProps.tsx +102 -0
  103. package/src/components/plugins/@antd/item-props/CardProps.tsx +58 -0
  104. package/src/components/plugins/@antd/item-props/CheckboxProps.tsx +75 -0
  105. package/src/components/plugins/@antd/item-props/ColProps.tsx +43 -0
  106. package/src/components/plugins/@antd/item-props/DatePickerProps.tsx +72 -0
  107. package/src/components/plugins/@antd/item-props/EchartsProps.tsx +35 -0
  108. package/src/components/plugins/@antd/item-props/HtmlProps.tsx +61 -0
  109. package/src/components/plugins/@antd/item-props/ImageProps.tsx +43 -0
  110. package/src/components/plugins/@antd/item-props/InputNumberProps.tsx +18 -0
  111. package/src/components/plugins/@antd/item-props/InputProps.tsx +89 -0
  112. package/src/components/plugins/@antd/item-props/ListProps.tsx +69 -0
  113. package/src/components/plugins/@antd/item-props/PageHeaderProps.tsx +20 -0
  114. package/src/components/plugins/@antd/item-props/RowProps.tsx +21 -0
  115. package/src/components/plugins/@antd/item-props/SelectProps.tsx +136 -0
  116. package/src/components/plugins/@antd/item-props/SpaceProps.tsx +52 -0
  117. package/src/components/plugins/@antd/item-props/SwitchProps.tsx +17 -0
  118. package/src/components/plugins/@antd/item-props/TableProps.tsx +200 -0
  119. package/src/components/plugins/@antd/item-props/TextProps.tsx +41 -0
  120. package/src/components/plugins/@antd/item-props/index.ts +20 -0
  121. package/src/components/plugins/@antd/item-props/types.ts +6 -0
  122. package/src/components/plugins/@antd/items/ButtonRender.tsx +63 -0
  123. package/src/components/plugins/@antd/items/CapsuleRender.tsx +49 -0
  124. package/src/components/plugins/@antd/items/CardRender.tsx +119 -0
  125. package/src/components/plugins/@antd/items/CheckboxRender.tsx +56 -0
  126. package/src/components/plugins/@antd/items/ColRender.tsx +78 -0
  127. package/src/components/plugins/@antd/items/DatePickerRender.tsx +117 -0
  128. package/src/components/plugins/@antd/items/EchartsRender.tsx +98 -0
  129. package/src/components/plugins/@antd/items/HtmlRender.tsx +74 -0
  130. package/src/components/plugins/@antd/items/ImageRender.tsx +37 -0
  131. package/src/components/plugins/@antd/items/InputNumberRender.tsx +57 -0
  132. package/src/components/plugins/@antd/items/InputRender.tsx +75 -0
  133. package/src/components/plugins/@antd/items/ListRender.tsx +227 -0
  134. package/src/components/plugins/@antd/items/PageHeaderRender.tsx +74 -0
  135. package/src/components/plugins/@antd/items/RowRender.tsx +47 -0
  136. package/src/components/plugins/@antd/items/SelectRender.tsx +53 -0
  137. package/src/components/plugins/@antd/items/SpaceRender.tsx +54 -0
  138. package/src/components/plugins/@antd/items/SwitchRender.tsx +52 -0
  139. package/src/components/plugins/@antd/items/TableRender.tsx +99 -0
  140. package/src/components/plugins/@antd/items/TextRender.tsx +25 -0
  141. package/src/components/plugins/@antd/items/index.ts +20 -0
  142. package/src/components/styles.css +12 -0
  143. package/src/components/typing.ts +80 -0
  144. package/src/components/utils.ts +37 -0
  145. package/src/example.tsx +136 -0
  146. package/src/index.tsx +17 -0
@@ -0,0 +1,119 @@
1
+ import { Card, CardProps } from "antd";
2
+ import React, { useContext, useMemo, useState } from "react";
3
+ import { DropContainer } from "../../../dnd/DropContainer";
4
+ import { HtmlBaseProps } from "../../../typing";
5
+ import { DesignerContext } from "../../../context/DesignerContext";
6
+
7
+ export type CardRenderProps = {
8
+ bordered?: boolean;
9
+ size?: CardProps["size"];
10
+ title?: string;
11
+ hoverable?: boolean;
12
+ shadow?: boolean;
13
+ item: any;
14
+ } & HtmlBaseProps;
15
+
16
+ export const CardRender: React.FC<CardRenderProps> = ({
17
+ id,
18
+ bordered = false,
19
+ size = "default",
20
+ title,
21
+ hoverable = false,
22
+ shadow = true,
23
+ item,
24
+ style,
25
+ className,
26
+ }) => {
27
+ const titleSlot = useMemo(() => {
28
+ if (!item.children || Array.isArray(item.children)) return null;
29
+ if (typeof item.children !== "object") return null;
30
+ return item.children.title || [];
31
+ }, [item]);
32
+ const [titleList, setTitleList] = useState(titleSlot || []);
33
+ const onTitleListChange = (list: any[]) => {
34
+ item.children.title = list;
35
+ setTitleList(list);
36
+ };
37
+
38
+ const extraSlot = useMemo(() => {
39
+ if (!item.children || Array.isArray(item.children)) return null;
40
+ if (typeof item.children !== "object") return null;
41
+ return item.children.extra || [];
42
+ }, [item]);
43
+ const [extraList, setExtraList] = useState(extraSlot || []);
44
+ const onExtraListChange = (list: any[]) => {
45
+ item.children.extra = list;
46
+ setExtraList(list);
47
+ };
48
+
49
+ const bodySlot = useMemo(() => {
50
+ if (!item.children) return null;
51
+ if (Array.isArray(item.children)) return item.children;
52
+ if (typeof item.children !== "object") return null;
53
+ return item.children.body || [];
54
+ }, [item]);
55
+ const [bodyList, setBodyList] = useState(bodySlot || []);
56
+ const onBodyListChange = (list: any[]) => {
57
+ if (Array.isArray(item.children)) {
58
+ item.children = list;
59
+ } else {
60
+ item.children.body = list;
61
+ }
62
+ setBodyList(list);
63
+ };
64
+
65
+ const actionsSlot = useMemo(() => {
66
+ if (!item.children || Array.isArray(item.children)) return null;
67
+ if (typeof item.children !== "object") return null;
68
+ return item.children.actions || [];
69
+ }, [item]);
70
+ const [actionsList, setActionsList] = useState(actionsSlot || []);
71
+ const onActionsListChange = (list: any[]) => {
72
+ item.children.actions = list;
73
+ setActionsList(list);
74
+ };
75
+
76
+ const headStyle = { borderBottom: "none" };
77
+
78
+ return (
79
+ <Card
80
+ id={id}
81
+ variant={bordered ? "outlined" : "borderless"}
82
+ size={size}
83
+ hoverable={hoverable}
84
+ className={[shadow ? "ant-card-shadow" : undefined, className]
85
+ .filter(Boolean)
86
+ .join(" ")}
87
+ title={
88
+ title?.length && !titleSlot?.length ? (
89
+ title
90
+ ) : titleSlot ? (
91
+ <DropContainer list={titleList} onListChange={onTitleListChange} />
92
+ ) : (
93
+ title
94
+ )
95
+ }
96
+ extra={
97
+ extraSlot && (
98
+ <DropContainer list={extraList} onListChange={onExtraListChange} />
99
+ )
100
+ }
101
+ actions={
102
+ actionsSlot && [
103
+ <DropContainer
104
+ list={actionsList}
105
+ onListChange={onActionsListChange}
106
+ />,
107
+ ]
108
+ }
109
+ styles={{
110
+ header: headStyle,
111
+ }}
112
+ style={style}
113
+ >
114
+ {bodySlot && (
115
+ <DropContainer list={bodyList} onListChange={onBodyListChange} />
116
+ )}
117
+ </Card>
118
+ );
119
+ };
@@ -0,0 +1,56 @@
1
+ import { Checkbox } from "antd";
2
+ import React, { useContext } from "react";
3
+ import { HtmlBaseProps, SchemaItemType } from "../../../typing";
4
+ import { EnvContext } from "../../../context/EnvContext";
5
+ import { handleCallback, setVar } from "../../../utils";
6
+
7
+ export type CheckboxRenderProps = {
8
+ var?: string;
9
+ layout?: "horizontal" | "vertical" | "grid";
10
+ lineNumber?: number;
11
+ options?: { label: string; value: any }[];
12
+ item?: SchemaItemType;
13
+ onChange?: (value: any[]) => void;
14
+ } & HtmlBaseProps;
15
+
16
+ export const CheckboxRender: React.FC<CheckboxRenderProps> = ({
17
+ id,
18
+ var: varName = "",
19
+ layout = "horizontal",
20
+ lineNumber = 3,
21
+ options = [],
22
+ item,
23
+ onChange,
24
+ style,
25
+ className,
26
+ }) => {
27
+ const { env, callbacks } = useContext(EnvContext);
28
+ const groupStyle: React.CSSProperties = {
29
+ ...style,
30
+ display: layout === "grid" ? "grid" : "flex",
31
+ gap: layout === "grid" ? undefined : "8px",
32
+ flexDirection: layout === "vertical" ? "column" : "row",
33
+ gridTemplateColumns:
34
+ layout === "grid" ? `repeat(${lineNumber}, 1fr)` : undefined,
35
+ };
36
+ const change = (v: any[]) => {
37
+ if (onChange) onChange(v);
38
+ if (env && item && varName) setVar(env, item, varName, v);
39
+ if (env && item && callbacks) handleCallback(env, item, callbacks);
40
+ };
41
+ return (
42
+ <span id={id}>
43
+ <Checkbox.Group
44
+ onChange={change as any}
45
+ style={groupStyle}
46
+ className={className}
47
+ >
48
+ {options.map((op) => (
49
+ <Checkbox key={op.value} value={op.value}>
50
+ {op.label}
51
+ </Checkbox>
52
+ ))}
53
+ </Checkbox.Group>
54
+ </span>
55
+ );
56
+ };
@@ -0,0 +1,78 @@
1
+ import { Col } from "antd";
2
+ import React, { useContext, useMemo, useState } from "react";
3
+ import { PageItem } from "../../../layout/PageItem";
4
+ import { DropContainer } from "../../../dnd/DropContainer";
5
+ import { HtmlBaseProps } from "../../../typing";
6
+ import { DesignerContext } from "../../../context/DesignerContext";
7
+ import { EnvContext } from "../../../context/EnvContext";
8
+
9
+ export type ColRenderProps = {
10
+ span?: number;
11
+ xs?: number;
12
+ sm?: number;
13
+ md?: number;
14
+ lg?: number;
15
+ xl?: number;
16
+ xxl?: number;
17
+ item: any;
18
+ } & HtmlBaseProps;
19
+
20
+ export const ColRender: React.FC<ColRenderProps> = ({
21
+ id,
22
+ span = 24,
23
+ xs,
24
+ sm,
25
+ md,
26
+ lg,
27
+ xl,
28
+ xxl,
29
+ item,
30
+ style = {},
31
+ className,
32
+ }) => {
33
+ const { designable } = useContext(DesignerContext);
34
+ const { deviceWidth } = useContext(EnvContext);
35
+ const [localChildren, setLocalChildren] = useState(item.children || []);
36
+
37
+ const onLocalChildrenChange = (list: any[]) => {
38
+ item.children = list;
39
+ setLocalChildren(list);
40
+ };
41
+ const computedSpan = useMemo(() => {
42
+ const dw = deviceWidth || 1600;
43
+ let w = null;
44
+ if (dw < 576 && xs) {
45
+ w = xs;
46
+ }
47
+ if (dw >= 576 && sm) {
48
+ w = sm;
49
+ }
50
+ if (dw >= 768 && md) {
51
+ w = md;
52
+ }
53
+ if (dw >= 992 && lg) {
54
+ w = lg;
55
+ }
56
+ if (dw >= 1200 && xl) {
57
+ w = xl;
58
+ }
59
+ if (dw >= 1600 && xxl) {
60
+ w = xxl;
61
+ }
62
+ return w || span;
63
+ }, [xs, sm, md, lg, xl, xxl, span, deviceWidth]);
64
+ return (
65
+ <DropContainer
66
+ rootComponent={Col}
67
+ rootData={{
68
+ id: id || item.id,
69
+ span: computedSpan,
70
+ style: { ...(item.style || {}), ...style },
71
+ className,
72
+ }}
73
+ list={localChildren}
74
+ item={item}
75
+ onListChange={onLocalChildrenChange}
76
+ />
77
+ );
78
+ };
@@ -0,0 +1,117 @@
1
+ import { DatePicker, type DatePickerProps, TimePicker } from "antd";
2
+ import dayjs, { Dayjs } from "dayjs";
3
+ import React, { useContext } from "react";
4
+ import { HtmlBaseProps } from "../../../typing";
5
+ import { EnvContext } from "../../../context/EnvContext";
6
+ import { handleCallback, setVar } from "../../../utils";
7
+
8
+ export type DatePickerRenderProps = {
9
+ var?: string;
10
+ size?: DatePickerProps['size']
11
+ allowClear?: boolean;
12
+ type?: "date" | "time" | "month" | "year" | "range";
13
+ showTime?: boolean;
14
+ value?: string | [string, string];
15
+ item?: any;
16
+ onChange?: (value?: string | [string, string]) => void;
17
+ } & HtmlBaseProps;
18
+
19
+ export const DatePickerRender: React.FC<DatePickerRenderProps> = ({
20
+ id,
21
+ var: varName = "",
22
+ size,
23
+ allowClear = false,
24
+ type = "date",
25
+ showTime = false,
26
+ value,
27
+ item,
28
+ onChange,
29
+ style = {},
30
+ className,
31
+ }) => {
32
+ const { env, callbacks } = useContext(EnvContext);
33
+ const change = (val?: string | [string, string]) => {
34
+ if (onChange) onChange(val);
35
+ if (env && item && varName) setVar(env, item, varName, val as any);
36
+ if (env && item && callbacks) handleCallback(env, item, callbacks);
37
+ };
38
+ if (type === "time") {
39
+ const v =
40
+ typeof value === "string" && value ? dayjs(value, "HH:mm") : undefined;
41
+ return (
42
+ <TimePicker
43
+ id={id}
44
+ value={v as Dayjs | undefined}
45
+ format="HH:mm"
46
+ placeholder="请选择时间"
47
+ size={size}
48
+ allowClear={allowClear}
49
+ onChange={(d) => change(d ? d.format("HH:mm") : undefined)}
50
+ style={{ ...(item?.style || {}), ...style }}
51
+ className={className}
52
+ />
53
+ );
54
+ }
55
+ if (type === "month" || type === "year") {
56
+ const picker = type;
57
+ const fmt = type === "month" ? "YYYY-MM" : "YYYY";
58
+ const v =
59
+ typeof value === "string" && value ? dayjs(value, fmt) : undefined;
60
+ return (
61
+ <DatePicker
62
+ id={id}
63
+ picker={picker as any}
64
+ value={v as Dayjs | undefined}
65
+ format={fmt}
66
+ placeholder={type === "month" ? "请选择月份" : "请选择年份"}
67
+ size={size}
68
+ allowClear={allowClear}
69
+ onChange={(d) => change(d ? d.format(fmt) : undefined)}
70
+ onPanelChange={(d) => change(d ? (d as any).format(fmt) : undefined)}
71
+ style={{ ...(item?.style || {}), ...style }}
72
+ className={className}
73
+ />
74
+ );
75
+ }
76
+ if (type === "range") {
77
+ const fmt = showTime ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD";
78
+ const v0 =
79
+ Array.isArray(value) && value[0] ? dayjs(value[0], fmt) : undefined;
80
+ const v1 =
81
+ Array.isArray(value) && value[1] ? dayjs(value[1], fmt) : undefined;
82
+ return (
83
+ <DatePicker.RangePicker
84
+ id={id}
85
+ value={[v0 as any, v1 as any]}
86
+ format={fmt}
87
+ placeholder={["开始日期", "结束日期"]}
88
+ size={size}
89
+ allowClear={allowClear}
90
+ showTime={showTime}
91
+ onChange={(d) =>
92
+ change(
93
+ d && d[0] && d[1] ? [d[0].format(fmt), d[1].format(fmt)] : undefined
94
+ )
95
+ }
96
+ style={{ ...(item?.style || {}), ...style }}
97
+ className={className}
98
+ />
99
+ );
100
+ }
101
+ const fmt = showTime ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD";
102
+ const v = typeof value === "string" && value ? dayjs(value, fmt) : undefined;
103
+ return (
104
+ <DatePicker
105
+ id={id}
106
+ value={v as Dayjs | undefined}
107
+ format={fmt}
108
+ placeholder="请选择日期"
109
+ size={size}
110
+ allowClear={allowClear}
111
+ showTime={showTime}
112
+ style={{ ...(item?.style || {}), ...style }}
113
+ className={className}
114
+ onChange={(d) => change(d ? d.format(fmt) : undefined)}
115
+ />
116
+ );
117
+ };
@@ -0,0 +1,98 @@
1
+ import React, { useEffect, useRef, useState } from "react";
2
+ import * as echarts from "echarts";
3
+ import { HtmlBaseProps } from "../../../typing";
4
+ import { useDatasource } from "../../../hooks/datasource";
5
+
6
+ export type EchartsRenderProps = {
7
+ item: any;
8
+ title?: string;
9
+ script?: string;
10
+ height?: number;
11
+ style?: React.CSSProperties;
12
+ } & HtmlBaseProps;
13
+
14
+ export const EchartsRender: React.FC<EchartsRenderProps> = ({
15
+ id,
16
+ script = "",
17
+ item,
18
+ height = 400,
19
+ style,
20
+ className,
21
+ }) => {
22
+ const chartRef = useRef<HTMLDivElement | null>(null);
23
+ const [chart, setChart] = useState<echarts.ECharts | null>(null);
24
+ const datasource = useDatasource(id, item.datasource);
25
+ const parseConfig = (configStr: string): echarts.EChartsOption | null => {
26
+ try {
27
+ return JSON.parse(configStr);
28
+ } catch (jsonError) {
29
+ try {
30
+ const safeEval = new Function(
31
+ "echarts",
32
+ "console",
33
+ "Math",
34
+ "Date",
35
+ "Array",
36
+ "Object",
37
+ "String",
38
+ "Number",
39
+ "Boolean",
40
+ "data",
41
+ `
42
+ "use strict";
43
+ const window = undefined;
44
+ const document = undefined;
45
+ const global = undefined;
46
+ const process = undefined;
47
+ const require = undefined;
48
+ const module = undefined;
49
+ const exports = undefined;
50
+ ${configStr}
51
+ `
52
+ );
53
+ return (safeEval as any)(
54
+ echarts,
55
+ console,
56
+ Math,
57
+ Date,
58
+ Array,
59
+ Object,
60
+ String,
61
+ Number,
62
+ Boolean,
63
+ datasource
64
+ );
65
+ } catch (evalError) {
66
+ console.error("ECharts 配置解析失败:", evalError);
67
+ return null;
68
+ }
69
+ }
70
+ };
71
+ useEffect(() => {
72
+ if (!chartRef.current) return;
73
+ const next = echarts.init(chartRef.current);
74
+ setChart(next);
75
+ const onResize = () => next.resize();
76
+ window.addEventListener("resize", onResize);
77
+ return () => {
78
+ window.removeEventListener("resize", onResize);
79
+ next.dispose();
80
+ };
81
+ }, []);
82
+ useEffect(() => {
83
+ const opt = parseConfig(script);
84
+ if (chart && opt) {
85
+ chart.setOption(opt);
86
+ setTimeout(() => chart.resize(), 50);
87
+ }
88
+ }, [chart, script]);
89
+ return (
90
+ <div
91
+ id={id}
92
+ style={{ width: "100%", height, ...style }}
93
+ className={className}
94
+ >
95
+ <div ref={chartRef} style={{ width: "100%", height, ...style }}></div>
96
+ </div>
97
+ );
98
+ };
@@ -0,0 +1,74 @@
1
+ import React, { useMemo } from "react";
2
+ import { HtmlBaseProps } from "../../../typing";
3
+ import { useDatasource } from "../../../hooks/datasource";
4
+
5
+ export type HtmlRenderProps = {
6
+ dataSource?: Record<string, any>;
7
+ template?: string;
8
+ style?: React.CSSProperties;
9
+ item: any;
10
+ } & HtmlBaseProps;
11
+
12
+ /**
13
+ * HtmlRender 组件
14
+ * 用途:渲染自定义 HTML 模板,支持数据源变量插值
15
+ * 参数:
16
+ * - id:组件唯一标识
17
+ * - template:HTML 模板字符串,支持 {{ expr }} 插值
18
+ * - item:当前元素数据(含 datasource)
19
+ * - style:样式
20
+ * - className:类名
21
+ * - ref:转发到 div 的引用(HTMLDivElement)
22
+ */
23
+ export const HtmlRender: React.FC<HtmlRenderProps> = ({
24
+ id,
25
+ template = "",
26
+ item,
27
+ style,
28
+ className,
29
+ }) => {
30
+ const datasource = useDatasource(id, item.datasource);
31
+ const keys = useMemo(() => Object.keys(datasource || {}), [datasource]);
32
+ const func = (path: string) =>
33
+ new Function(
34
+ ...keys,
35
+ `
36
+ "use strict";
37
+ const window = undefined;
38
+ const document = undefined;
39
+ const global = undefined;
40
+ const process = undefined;
41
+ const require = undefined;
42
+ const module = undefined;
43
+ const exports = undefined;
44
+ return ${path};
45
+ `
46
+ );
47
+ const args = useMemo(
48
+ () => keys.map((k) => (datasource as any)?.[k]),
49
+ [keys, datasource]
50
+ );
51
+ const html = useMemo(
52
+ () =>
53
+ (template || "").replace(
54
+ /{{\s*([^}]+)\s*}}/g,
55
+ (_match: any, p1: string) => {
56
+ try {
57
+ return (func(p1) as any)(...args);
58
+ } catch {
59
+ return "";
60
+ }
61
+ }
62
+ ),
63
+ [template, args]
64
+ );
65
+
66
+ return (
67
+ <div
68
+ id={id}
69
+ style={style}
70
+ className={className}
71
+ dangerouslySetInnerHTML={{ __html: html }}
72
+ />
73
+ );
74
+ };
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { HtmlBaseProps } from "../../../typing";
3
+
4
+ export type ImageRenderProps = {
5
+ src: string;
6
+ alt?: string;
7
+ width?: number | string;
8
+ height?: number | string;
9
+ href?: string;
10
+ } & HtmlBaseProps;
11
+
12
+ export const ImageRender: React.FC<ImageRenderProps> = ({
13
+ id,
14
+ src,
15
+ alt,
16
+ width,
17
+ height,
18
+ href,
19
+ className,
20
+ }) => {
21
+ const img = (
22
+ <img
23
+ id={id}
24
+ src={src}
25
+ alt={alt}
26
+ style={{ width, height }}
27
+ className={className}
28
+ />
29
+ );
30
+ if (href && href.length)
31
+ return (
32
+ <a href={href} target="_blank" rel="noreferrer">
33
+ {img}
34
+ </a>
35
+ );
36
+ return <div>{img}</div>;
37
+ };
@@ -0,0 +1,57 @@
1
+ import { InputNumber, type InputNumberProps } from "antd";
2
+ import React, { useContext } from "react";
3
+ import { HtmlBaseProps, SchemaItemType } from "../../../typing";
4
+ import { EnvContext } from "../../../context/EnvContext";
5
+ import { handleCallback, setVar } from "../../../utils";
6
+
7
+ export type InputNumberRenderProps = {
8
+ var?: string;
9
+ value?: number;
10
+ size?: InputNumberProps["size"];
11
+ placeholder?: string;
12
+ allowClear?: boolean;
13
+ min?: number;
14
+ max?: number;
15
+ step?: number;
16
+ precision?: number;
17
+ item?: SchemaItemType;
18
+ onChange?: (v?: number) => void;
19
+ } & HtmlBaseProps;
20
+
21
+ export const InputNumberRender: React.FC<InputNumberRenderProps> = ({
22
+ id,
23
+ var: varName = "",
24
+ value,
25
+ size,
26
+ placeholder = "请输入",
27
+ min = 0,
28
+ max = Number.MAX_SAFE_INTEGER,
29
+ step = 1,
30
+ precision = 0,
31
+ item,
32
+ onChange,
33
+ style = {},
34
+ className,
35
+ }) => {
36
+ const { env, callbacks } = useContext(EnvContext);
37
+ const change = (v?: number) => {
38
+ if (onChange) onChange(v);
39
+ if (env && item && varName) setVar(env, item, varName, v);
40
+ if (env && item && callbacks) handleCallback(env, item, callbacks);
41
+ };
42
+ return (
43
+ <InputNumber
44
+ id={id}
45
+ value={value}
46
+ placeholder={placeholder}
47
+ size={size}
48
+ min={min}
49
+ max={max}
50
+ step={step}
51
+ precision={precision}
52
+ onChange={(v) => change(v ?? undefined)}
53
+ style={{ width: "100%", ...style }}
54
+ className={className}
55
+ />
56
+ );
57
+ };