bi-sdk-react 0.0.51 → 0.0.52

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.
@@ -15,7 +15,6 @@ const Placeholder = styled.div`
15
15
  font-size: 12px;
16
16
  `;
17
17
 
18
-
19
18
  export type DrawerRenderProps = {
20
19
  item: any;
21
20
  title?: string;
@@ -46,8 +45,13 @@ export const DrawerRender: React.FC<DrawerRenderProps> = ({
46
45
  resizable = true,
47
46
  ...rest
48
47
  }) => {
49
- const { designable, selectedItem, setSelectedItem, initCallback } =
50
- useContext(PageContext);
48
+ const {
49
+ designable,
50
+ selectedItem,
51
+ setSelectedItem,
52
+ initCallback,
53
+ initMethod,
54
+ } = useContext(PageContext);
51
55
  const [open, setOpen] = useState(false);
52
56
  const [localChildren, setLocalChildren] = useState(item.children || []);
53
57
  const [size, setSize] = useState(rest.size || 400);
@@ -105,6 +109,13 @@ export const DrawerRender: React.FC<DrawerRenderProps> = ({
105
109
 
106
110
  useEffect(() => {
107
111
  initCallback({ id: item.id, callback });
112
+ initMethod({
113
+ id: item.id,
114
+ method: {
115
+ open: () => setOpen(true),
116
+ close: () => setOpen(false),
117
+ },
118
+ });
108
119
  }, []);
109
120
 
110
121
  const classes = [
@@ -145,9 +156,7 @@ export const DrawerRender: React.FC<DrawerRenderProps> = ({
145
156
  footer ? (
146
157
  <Space>
147
158
  <Button onClick={() => setOpen(false)}>{cancelText}</Button>
148
- <Button type={okType}>
149
- {okText}
150
- </Button>
159
+ <Button type={okType}>{okText}</Button>
151
160
  </Space>
152
161
  ) : null
153
162
  }
@@ -8,10 +8,11 @@ import React, { useContext, useEffect, useRef, useState } from "react";
8
8
  echarts.registerMap("china", chinaJson as any);
9
9
  import { PageContext } from "../../../context/PageContext";
10
10
  import { useDatasource } from "../../../hooks/datasource";
11
- import { CallbackType, HtmlBaseProps } from "../../../typing";
11
+ import { CallbackType, HtmlBaseProps, SchemaItemType } from "../../../typing";
12
+ import { useEvent } from "../../../hooks/event";
12
13
 
13
14
  export type EchartsRenderProps = {
14
- item: any;
15
+ item: SchemaItemType;
15
16
  title?: string;
16
17
  script?: string;
17
18
  height?: number;
@@ -36,6 +37,7 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
36
37
  const [chart, setChart] = useState<echarts.ECharts | null>(null);
37
38
  const [signal, setSignal] = useState<number>(0);
38
39
  const datasource = useDatasource({ item, signal });
40
+ const { handleEvent } = useEvent(item);
39
41
 
40
42
  /**
41
43
  * 解析配置脚本
@@ -96,6 +98,25 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
96
98
  };
97
99
  };
98
100
 
101
+ const initEvent = () => {
102
+ if (!chart) return;
103
+ const events = (item.events || []).reduce(
104
+ (acc, cur) => {
105
+ acc[cur.name] = cur.script;
106
+ return acc;
107
+ },
108
+ {} as Record<string, string>,
109
+ );
110
+ ["click", "dblclick", "selectchanged"].forEach((eventName) => {
111
+ chart.off(eventName);
112
+ if (events[eventName]?.length) {
113
+ chart.on(eventName, (params) => {
114
+ handleEvent(eventName, params);
115
+ });
116
+ }
117
+ });
118
+ };
119
+
99
120
  useEffect(() => {
100
121
  const opt = parseConfig(script);
101
122
  if (chart && opt) {
@@ -108,13 +129,19 @@ export const EchartsRender: React.FC<EchartsRenderProps> = ({
108
129
  }
109
130
  }, [chart, script, datasource]);
110
131
 
132
+ useEffect(() => {
133
+ if (!chart) return;
134
+ initEvent();
135
+ }, [chart, item.events]);
136
+
111
137
  useEffect(() => {
112
138
  if (!chartRef.current) return;
113
139
  const next = echarts.init(chartRef.current);
114
140
  setChart(next);
141
+
115
142
  const onResize = () => next.resize();
116
143
  window.addEventListener("resize", onResize);
117
- initCallback({ id: item.id, callback });
144
+ initCallback({ id: item.id!, callback });
118
145
  return () => {
119
146
  window.removeEventListener("resize", onResize);
120
147
  next.dispose();
@@ -39,8 +39,13 @@ export const ModalRender: React.FC<ModalRenderProps> = ({
39
39
  footer = true,
40
40
  ...rest
41
41
  }) => {
42
- const { designable, selectedItem, setSelectedItem, initCallback } =
43
- useContext(PageContext);
42
+ const {
43
+ designable,
44
+ selectedItem,
45
+ setSelectedItem,
46
+ initCallback,
47
+ initMethod,
48
+ } = useContext(PageContext);
44
49
  const [open, setOpen] = useState(false);
45
50
  const [localChildren, setLocalChildren] = useState(item.children || []);
46
51
 
@@ -93,6 +98,13 @@ export const ModalRender: React.FC<ModalRenderProps> = ({
93
98
 
94
99
  useEffect(() => {
95
100
  initCallback({ id: item.id, callback });
101
+ initMethod({
102
+ id: item.id,
103
+ method: {
104
+ open: () => setOpen(true),
105
+ close: () => setOpen(false),
106
+ },
107
+ });
96
108
  }, []);
97
109
 
98
110
  const classes = [
@@ -105,6 +105,10 @@ export type SchemaItemType = {
105
105
  custom?: string | null;
106
106
  dataset?: DataSetType;
107
107
  };
108
+ events?: {
109
+ name: string;
110
+ script: string;
111
+ }[]
108
112
  };
109
113
 
110
114
  export type PluginType = {
@@ -116,8 +120,16 @@ export type PluginType = {
116
120
  formComponent?: React.FC<any>;
117
121
  defaultOptions?: Pick<
118
122
  SchemaItemType,
119
- "props" | "children" | "cascadeIds" | "datasource" | "style"
123
+ "props" | "children" | "cascadeIds" | "datasource" | "events" | "style"
120
124
  >;
125
+ events?: {
126
+ name: string;
127
+ handler: string;
128
+ }[];
129
+ methods?: {
130
+ name: string;
131
+ handler: string;
132
+ }[];
121
133
  };
122
134
  type NameValue = { name?: string; value?: string };
123
135
  export type ScriptItem = { id?: string; name: string; script: string };