Skip to content

Commit 0d7d978

Browse files
committed
add buttons
1 parent e449538 commit 0d7d978

File tree

26 files changed

+482
-58
lines changed

26 files changed

+482
-58
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from "react";
2+
import {registerComponent} from "@/framework/ComponentBus";
3+
4+
const MyItem = (props: { title: string, onChange: (value: string) => void }) => {
5+
return <input value={props.title} onChange={(e) => {
6+
props.onChange(e.target.value)
7+
}}/>
8+
}
9+
10+
registerComponent('myItem', MyItem);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from "react";
2+
3+
const componentBus = new Map<string, React.ComponentType<any>>();
4+
5+
6+
// 注册表操作方法
7+
export const registerComponent = (name: string, component: React.ComponentType<any>) => {
8+
componentBus.set(name, component);
9+
};
10+
11+
// 获取组件
12+
export const getComponent = (name: string): React.ComponentType<any> | undefined => {
13+
return componentBus.get(name);
14+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class GlobalEvent {
2+
private static instance: GlobalEvent;
3+
private events: Map<string, Function[]>;
4+
5+
private constructor() {
6+
this.events = new Map();
7+
}
8+
9+
public static getInstance(): GlobalEvent {
10+
if (!this.instance) {
11+
this.instance = new GlobalEvent();
12+
}
13+
return this.instance;
14+
}
15+
16+
public on(eventName: string, callback: Function): void {
17+
const callbacks = this.events.get(eventName) || [];
18+
callbacks.push(callback);
19+
this.events.set(eventName, callbacks);
20+
}
21+
22+
public emit(eventName: string, ...args: any[]): void {
23+
const callbacks = this.events.get(eventName);
24+
if (callbacks) {
25+
callbacks.forEach((callback) => {
26+
try {
27+
callback(...args);
28+
} catch (err) {
29+
console.error(
30+
`Error executing callback for event: ${eventName}`,
31+
err
32+
);
33+
}
34+
});
35+
}
36+
}
37+
38+
public off(eventName: string, callback?: Function): void {
39+
if (callback) {
40+
const callbacks = this.events.get(eventName);
41+
if (callbacks) {
42+
const callbackIndex = callbacks.indexOf(callback);
43+
if (callbackIndex > -1) {
44+
callbacks.splice(callbackIndex, 1);
45+
if (callbacks.length === 0) {
46+
this.events.delete(eventName);
47+
} else {
48+
this.events.set(eventName, callbacks);
49+
}
50+
}
51+
}
52+
} else {
53+
this.events.delete(eventName);
54+
}
55+
}
56+
}
57+
58+
export const events = GlobalEvent.getInstance();

admin-ui/src/layout/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import "./index.scss";
1010
import {useSelector} from "react-redux";
1111
import {RootState} from "@/store/Redux";
1212
import NotFound from "@/layout/pages/NotFound";
13+
import "@/config/register.component";
1314

1415
const welcomePath = config.welcomePath;
1516
const loginPath = config.loginPath;

example/example-application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.14</version>
8+
<version>3.3.15</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.14</version>
8+
<version>3.3.15</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.14</version>
8+
<version>3.3.15</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.14</version>
8+
<version>3.3.15</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.14</version>
8+
<version>3.3.15</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.14</version>
20+
<version>3.3.15</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

0 commit comments

Comments
 (0)