@widget-js/core 0.1.6 → 0.1.12
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/LICENSE +21 -21
- package/dist/cjs/api/ApiConstants.js +8 -8
- package/dist/cjs/api/AppApi.js +31 -31
- package/dist/cjs/api/BroadcastApi.js +20 -20
- package/dist/cjs/api/BrowserWindowApi.js +58 -24
- package/dist/cjs/api/Channel.js +12 -11
- package/dist/cjs/api/DialogApi.js +16 -0
- package/dist/cjs/api/ElectronApi.js +13 -13
- package/dist/cjs/api/NotificationApi.js +83 -83
- package/dist/cjs/api/WidgetApi.js +58 -49
- package/dist/cjs/index.js +36 -34
- package/dist/cjs/model/HostedMode.js +14 -0
- package/dist/cjs/model/Notification.js +15 -15
- package/dist/cjs/model/SocialInfo.js +10 -10
- package/dist/cjs/model/Widget.js +79 -79
- package/dist/cjs/model/WidgetData.js +16 -16
- package/dist/cjs/model/WidgetPackage.js +21 -6
- package/dist/cjs/model/WidgetParams.js +139 -144
- package/dist/cjs/model/event/BroadcastEvent.js +14 -14
- package/dist/cjs/model/event/WebSocketEvent.js +14 -14
- package/dist/cjs/model/interface/IHostedWidget.js +2 -0
- package/dist/cjs/repository/WidgetDataRepository.js +71 -71
- package/dist/cjs/router/encoding.js +144 -144
- package/dist/cjs/router/query.js +84 -84
- package/dist/cjs/utils/ElectronUtils.js +24 -24
- package/dist/esm/api/ApiConstants.js +4 -4
- package/dist/esm/api/AppApi.js +27 -27
- package/dist/esm/api/BroadcastApi.js +16 -16
- package/dist/esm/api/BrowserWindowApi.js +54 -20
- package/dist/esm/api/Channel.js +9 -8
- package/dist/esm/api/DialogApi.js +12 -0
- package/dist/esm/api/ElectronApi.js +9 -9
- package/dist/esm/api/NotificationApi.js +79 -79
- package/dist/esm/api/WidgetApi.js +54 -45
- package/dist/esm/index.js +20 -18
- package/dist/esm/model/HostedMode.js +11 -0
- package/dist/esm/model/Notification.js +11 -11
- package/dist/esm/model/SocialInfo.js +6 -6
- package/dist/esm/model/Widget.js +75 -75
- package/dist/esm/model/WidgetData.js +12 -12
- package/dist/esm/model/WidgetPackage.js +17 -2
- package/dist/esm/model/WidgetParams.js +135 -140
- package/dist/esm/model/event/BroadcastEvent.js +10 -10
- package/dist/esm/model/event/WebSocketEvent.js +10 -10
- package/dist/esm/model/interface/IHostedWidget.js +1 -0
- package/dist/esm/repository/WidgetDataRepository.js +64 -64
- package/dist/esm/router/encoding.js +135 -135
- package/dist/esm/router/query.js +79 -79
- package/dist/esm/utils/ElectronUtils.js +20 -20
- package/dist/types/api/ApiConstants.d.ts +4 -4
- package/dist/types/api/AppApi.d.ts +10 -10
- package/dist/types/api/BroadcastApi.d.ts +6 -6
- package/dist/types/api/BrowserWindowApi.d.ts +37 -10
- package/dist/types/api/Channel.d.ts +8 -7
- package/dist/types/api/DialogApi.d.ts +8 -0
- package/dist/types/api/ElectronApi.d.ts +4 -4
- package/dist/types/api/NotificationApi.d.ts +14 -14
- package/dist/types/api/WidgetApi.d.ts +30 -24
- package/dist/types/index.d.ts +20 -18
- package/dist/types/model/HostedMode.d.ts +10 -0
- package/dist/types/model/Notification.d.ts +16 -16
- package/dist/types/model/SocialInfo.d.ts +6 -6
- package/dist/types/model/Widget.d.ts +96 -85
- package/dist/types/model/WidgetData.d.ts +35 -35
- package/dist/types/model/WidgetPackage.d.ts +43 -41
- package/dist/types/model/WidgetParams.d.ts +60 -63
- package/dist/types/model/event/BroadcastEvent.d.ts +12 -12
- package/dist/types/model/event/WebSocketEvent.d.ts +8 -8
- package/dist/types/model/interface/IHostedWidget.d.ts +13 -0
- package/dist/types/repository/WidgetDataRepository.d.ts +26 -26
- package/dist/types/router/encoding.d.ts +62 -62
- package/dist/types/router/query.d.ts +53 -53
- package/dist/types/utils/ElectronUtils.d.ts +8 -8
- package/dist/umd/index.js +1 -1
- package/package.json +15 -16
|
@@ -1,140 +1,135 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件参数,如宽,高,id,语言等环境参数
|
|
3
|
-
*/
|
|
4
|
-
import { parseQuery } from "../router/query";
|
|
5
|
-
import { snakeCase } from "change-case";
|
|
6
|
-
export class WidgetParams {
|
|
7
|
-
/**
|
|
8
|
-
* 将组件参数转为url参数
|
|
9
|
-
* @param object
|
|
10
|
-
* @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
|
|
11
|
-
*/
|
|
12
|
-
toUrlParams() {
|
|
13
|
-
const urlParams = new URLSearchParams();
|
|
14
|
-
const ownPropertyNames = Object.getOwnPropertyNames(this);
|
|
15
|
-
for (let ownPropertyName of ownPropertyNames) {
|
|
16
|
-
const key = ownPropertyName;
|
|
17
|
-
const value = this[key];
|
|
18
|
-
if (value) {
|
|
19
|
-
urlParams.append(WidgetParams.PARAM_PREFIX + snakeCase(ownPropertyName), value.toString());
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return urlParams;
|
|
23
|
-
}
|
|
24
|
-
getPersistKey() {
|
|
25
|
-
return `${this.name}-${this.id}`;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 从当前地址解析组件参数:
|
|
29
|
-
* http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
|
|
30
|
-
* =>
|
|
31
|
-
* {width:2,height:2,id:21,width_px:156,height_px:156}
|
|
32
|
-
*/
|
|
33
|
-
static fromCurrentLocation() {
|
|
34
|
-
const href = window.location.href;
|
|
35
|
-
let queryString = href.split("?")[1];
|
|
36
|
-
return this.fromObject(parseQuery(queryString));
|
|
37
|
-
}
|
|
38
|
-
static setValue(widgetEnv, key, value) {
|
|
39
|
-
const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
|
|
40
|
-
if (keyWithoutPrefix == WidgetParams.PARAM_ID) {
|
|
41
|
-
widgetEnv.id = value;
|
|
42
|
-
}
|
|
43
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_X) {
|
|
44
|
-
widgetEnv.x = parseInt(value);
|
|
45
|
-
}
|
|
46
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_Y) {
|
|
47
|
-
widgetEnv.y = parseInt(value);
|
|
48
|
-
}
|
|
49
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT) {
|
|
50
|
-
widgetEnv.height = parseInt(value);
|
|
51
|
-
}
|
|
52
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH) {
|
|
53
|
-
widgetEnv.width = parseInt(value);
|
|
54
|
-
}
|
|
55
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_LANG) {
|
|
56
|
-
widgetEnv.lang = value;
|
|
57
|
-
}
|
|
58
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_THEME) {
|
|
59
|
-
widgetEnv.theme = value;
|
|
60
|
-
}
|
|
61
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_MODE) {
|
|
62
|
-
widgetEnv.mode = parseInt(value);
|
|
63
|
-
}
|
|
64
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_RADIUS) {
|
|
65
|
-
widgetEnv.radius = parseInt(value);
|
|
66
|
-
}
|
|
67
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH_PX) {
|
|
68
|
-
widgetEnv.widthPx = parseInt(value);
|
|
69
|
-
}
|
|
70
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT_PX) {
|
|
71
|
-
widgetEnv.heightPx = parseInt(value);
|
|
72
|
-
}
|
|
73
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_NAME) {
|
|
74
|
-
widgetEnv.name = value;
|
|
75
|
-
}
|
|
76
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_TITLE) {
|
|
77
|
-
widgetEnv.title = value;
|
|
78
|
-
}
|
|
79
|
-
else if (keyWithoutPrefix == WidgetParams.PARAM_PREVIEW) {
|
|
80
|
-
widgetEnv.preview = (value === 'true');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* 从对象键值对中初始化组件参数
|
|
85
|
-
* {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
|
|
86
|
-
* {width:2,height:2,id:21,width_px:156,height_px:156}
|
|
87
|
-
* @param object
|
|
88
|
-
*/
|
|
89
|
-
static fromObject(object) {
|
|
90
|
-
const widgetEnv = new WidgetParams();
|
|
91
|
-
const ownPropertyNames = Object.getOwnPropertyNames(object);
|
|
92
|
-
for (let ownPropertyName of ownPropertyNames) {
|
|
93
|
-
const key = ownPropertyName;
|
|
94
|
-
const value = object[key];
|
|
95
|
-
this.setValue(widgetEnv, key, value);
|
|
96
|
-
}
|
|
97
|
-
return widgetEnv;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
WidgetParams.PARAM_PREFIX = "w_";
|
|
101
|
-
WidgetParams.PARAM_ID = "id";
|
|
102
|
-
WidgetParams.PARAM_WIDTH = "width";
|
|
103
|
-
WidgetParams.PARAM_HEIGHT = "height";
|
|
104
|
-
WidgetParams.PARAM_WIDTH_PX = "width_px";
|
|
105
|
-
WidgetParams.PARAM_HEIGHT_PX = "height_px";
|
|
106
|
-
WidgetParams.PARAM_X = "x";
|
|
107
|
-
WidgetParams.PARAM_Y = "y";
|
|
108
|
-
WidgetParams.PARAM_LANG = "lang";
|
|
109
|
-
WidgetParams.PARAM_THEME = "theme";
|
|
110
|
-
WidgetParams.PARAM_MODE = "mode";
|
|
111
|
-
WidgetParams.PARAM_RADIUS = "radius";
|
|
112
|
-
WidgetParams.PARAM_NAME = "name";
|
|
113
|
-
WidgetParams.PARAM_TITLE = "title";
|
|
114
|
-
WidgetParams.PARAM_PREVIEW = "preview";
|
|
115
|
-
WidgetParams.PARAMS = [
|
|
116
|
-
WidgetParams.PARAM_ID,
|
|
117
|
-
WidgetParams.PARAM_WIDTH,
|
|
118
|
-
WidgetParams.PARAM_HEIGHT,
|
|
119
|
-
WidgetParams.PARAM_X,
|
|
120
|
-
WidgetParams.PARAM_Y,
|
|
121
|
-
WidgetParams.PARAM_LANG,
|
|
122
|
-
WidgetParams.PARAM_THEME,
|
|
123
|
-
WidgetParams.PARAM_MODE,
|
|
124
|
-
WidgetParams.PARAM_WIDTH_PX,
|
|
125
|
-
WidgetParams.PARAM_HEIGHT_PX,
|
|
126
|
-
WidgetParams.PARAM_NAME,
|
|
127
|
-
WidgetParams.PARAM_TITLE,
|
|
128
|
-
WidgetParams.PARAM_PREVIEW,
|
|
129
|
-
];
|
|
130
|
-
export var ThemeMode;
|
|
131
|
-
(function (ThemeMode) {
|
|
132
|
-
ThemeMode["AUTO"] = "auto";
|
|
133
|
-
ThemeMode["LIGHT"] = "LIGHT";
|
|
134
|
-
ThemeMode["DARK"] = "DARK";
|
|
135
|
-
})(ThemeMode || (ThemeMode = {}));
|
|
136
|
-
export var WidgetHostMode;
|
|
137
|
-
(function (WidgetHostMode) {
|
|
138
|
-
WidgetHostMode[WidgetHostMode["DEFAULT"] = 0] = "DEFAULT";
|
|
139
|
-
WidgetHostMode[WidgetHostMode["OVERLAP"] = 1] = "OVERLAP";
|
|
140
|
-
})(WidgetHostMode || (WidgetHostMode = {}));
|
|
1
|
+
/**
|
|
2
|
+
* 组件参数,如宽,高,id,语言等环境参数
|
|
3
|
+
*/
|
|
4
|
+
import { parseQuery } from "../router/query";
|
|
5
|
+
import { snakeCase } from "change-case";
|
|
6
|
+
export class WidgetParams {
|
|
7
|
+
/**
|
|
8
|
+
* 将组件参数转为url参数
|
|
9
|
+
* @param object
|
|
10
|
+
* @return URLSearchParams w_w=2&w_h=2&w_id=21&w_width=156&w_height=156
|
|
11
|
+
*/
|
|
12
|
+
toUrlParams() {
|
|
13
|
+
const urlParams = new URLSearchParams();
|
|
14
|
+
const ownPropertyNames = Object.getOwnPropertyNames(this);
|
|
15
|
+
for (let ownPropertyName of ownPropertyNames) {
|
|
16
|
+
const key = ownPropertyName;
|
|
17
|
+
const value = this[key];
|
|
18
|
+
if (value) {
|
|
19
|
+
urlParams.append(WidgetParams.PARAM_PREFIX + snakeCase(ownPropertyName), value.toString());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return urlParams;
|
|
23
|
+
}
|
|
24
|
+
getPersistKey() {
|
|
25
|
+
return `${this.name}-${this.id}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 从当前地址解析组件参数:
|
|
29
|
+
* http://localhost:8080/#/widget/config/labor_progress?w_w=2&w_h=2&w_width=156&w_height=156
|
|
30
|
+
* =>
|
|
31
|
+
* {width:2,height:2,id:21,width_px:156,height_px:156}
|
|
32
|
+
*/
|
|
33
|
+
static fromCurrentLocation() {
|
|
34
|
+
const href = window.location.href;
|
|
35
|
+
let queryString = href.split("?")[1];
|
|
36
|
+
return this.fromObject(parseQuery(queryString));
|
|
37
|
+
}
|
|
38
|
+
static setValue(widgetEnv, key, value) {
|
|
39
|
+
const keyWithoutPrefix = key.replace(this.PARAM_PREFIX, "");
|
|
40
|
+
if (keyWithoutPrefix == WidgetParams.PARAM_ID) {
|
|
41
|
+
widgetEnv.id = value;
|
|
42
|
+
}
|
|
43
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_X) {
|
|
44
|
+
widgetEnv.x = parseInt(value);
|
|
45
|
+
}
|
|
46
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_Y) {
|
|
47
|
+
widgetEnv.y = parseInt(value);
|
|
48
|
+
}
|
|
49
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT) {
|
|
50
|
+
widgetEnv.height = parseInt(value);
|
|
51
|
+
}
|
|
52
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH) {
|
|
53
|
+
widgetEnv.width = parseInt(value);
|
|
54
|
+
}
|
|
55
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_LANG) {
|
|
56
|
+
widgetEnv.lang = value;
|
|
57
|
+
}
|
|
58
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_THEME) {
|
|
59
|
+
widgetEnv.theme = value;
|
|
60
|
+
}
|
|
61
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_MODE) {
|
|
62
|
+
widgetEnv.mode = parseInt(value);
|
|
63
|
+
}
|
|
64
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_RADIUS) {
|
|
65
|
+
widgetEnv.radius = parseInt(value);
|
|
66
|
+
}
|
|
67
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_WIDTH_PX) {
|
|
68
|
+
widgetEnv.widthPx = parseInt(value);
|
|
69
|
+
}
|
|
70
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_HEIGHT_PX) {
|
|
71
|
+
widgetEnv.heightPx = parseInt(value);
|
|
72
|
+
}
|
|
73
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_NAME) {
|
|
74
|
+
widgetEnv.name = value;
|
|
75
|
+
}
|
|
76
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_TITLE) {
|
|
77
|
+
widgetEnv.title = value;
|
|
78
|
+
}
|
|
79
|
+
else if (keyWithoutPrefix == WidgetParams.PARAM_PREVIEW) {
|
|
80
|
+
widgetEnv.preview = (value === 'true');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 从对象键值对中初始化组件参数
|
|
85
|
+
* {w_width:2,w_height:2,w_id:21,w_width_px:156,w_height_px:156}=>
|
|
86
|
+
* {width:2,height:2,id:21,width_px:156,height_px:156}
|
|
87
|
+
* @param object
|
|
88
|
+
*/
|
|
89
|
+
static fromObject(object) {
|
|
90
|
+
const widgetEnv = new WidgetParams();
|
|
91
|
+
const ownPropertyNames = Object.getOwnPropertyNames(object);
|
|
92
|
+
for (let ownPropertyName of ownPropertyNames) {
|
|
93
|
+
const key = ownPropertyName;
|
|
94
|
+
const value = object[key];
|
|
95
|
+
this.setValue(widgetEnv, key, value);
|
|
96
|
+
}
|
|
97
|
+
return widgetEnv;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
WidgetParams.PARAM_PREFIX = "w_";
|
|
101
|
+
WidgetParams.PARAM_ID = "id";
|
|
102
|
+
WidgetParams.PARAM_WIDTH = "width";
|
|
103
|
+
WidgetParams.PARAM_HEIGHT = "height";
|
|
104
|
+
WidgetParams.PARAM_WIDTH_PX = "width_px";
|
|
105
|
+
WidgetParams.PARAM_HEIGHT_PX = "height_px";
|
|
106
|
+
WidgetParams.PARAM_X = "x";
|
|
107
|
+
WidgetParams.PARAM_Y = "y";
|
|
108
|
+
WidgetParams.PARAM_LANG = "lang";
|
|
109
|
+
WidgetParams.PARAM_THEME = "theme";
|
|
110
|
+
WidgetParams.PARAM_MODE = "mode";
|
|
111
|
+
WidgetParams.PARAM_RADIUS = "radius";
|
|
112
|
+
WidgetParams.PARAM_NAME = "name";
|
|
113
|
+
WidgetParams.PARAM_TITLE = "title";
|
|
114
|
+
WidgetParams.PARAM_PREVIEW = "preview";
|
|
115
|
+
WidgetParams.PARAMS = [
|
|
116
|
+
WidgetParams.PARAM_ID,
|
|
117
|
+
WidgetParams.PARAM_WIDTH,
|
|
118
|
+
WidgetParams.PARAM_HEIGHT,
|
|
119
|
+
WidgetParams.PARAM_X,
|
|
120
|
+
WidgetParams.PARAM_Y,
|
|
121
|
+
WidgetParams.PARAM_LANG,
|
|
122
|
+
WidgetParams.PARAM_THEME,
|
|
123
|
+
WidgetParams.PARAM_MODE,
|
|
124
|
+
WidgetParams.PARAM_WIDTH_PX,
|
|
125
|
+
WidgetParams.PARAM_HEIGHT_PX,
|
|
126
|
+
WidgetParams.PARAM_NAME,
|
|
127
|
+
WidgetParams.PARAM_TITLE,
|
|
128
|
+
WidgetParams.PARAM_PREVIEW,
|
|
129
|
+
];
|
|
130
|
+
export var ThemeMode;
|
|
131
|
+
(function (ThemeMode) {
|
|
132
|
+
ThemeMode["AUTO"] = "auto";
|
|
133
|
+
ThemeMode["LIGHT"] = "LIGHT";
|
|
134
|
+
ThemeMode["DARK"] = "DARK";
|
|
135
|
+
})(ThemeMode || (ThemeMode = {}));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export class BroadcastEvent {
|
|
2
|
-
constructor(type, from, payload) {
|
|
3
|
-
this.type = type;
|
|
4
|
-
this.from = from;
|
|
5
|
-
this.payload = payload;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
BroadcastEvent.TYPE_WIDGET_UPDATED = "broadcast::cn.widgetjs.core.widget_updated";
|
|
9
|
-
BroadcastEvent.TYPE_APP_CONFIG_UPDATED = "broadcast::cn.widgetjs.core.app_config_updated";
|
|
10
|
-
BroadcastEvent.TYPE_THEME_CHANGED = "broadcast::cn.widgetjs.core.theme_changed";
|
|
1
|
+
export class BroadcastEvent {
|
|
2
|
+
constructor(type, from, payload) {
|
|
3
|
+
this.type = type;
|
|
4
|
+
this.from = from;
|
|
5
|
+
this.payload = payload;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
BroadcastEvent.TYPE_WIDGET_UPDATED = "broadcast::cn.widgetjs.core.widget_updated";
|
|
9
|
+
BroadcastEvent.TYPE_APP_CONFIG_UPDATED = "broadcast::cn.widgetjs.core.app_config_updated";
|
|
10
|
+
BroadcastEvent.TYPE_THEME_CHANGED = "broadcast::cn.widgetjs.core.theme_changed";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export var WebSocketEventType;
|
|
2
|
-
(function (WebSocketEventType) {
|
|
3
|
-
WebSocketEventType["RESISTER_WIDGETS"] = "ws::cn.widgetjs.core.resister_widgets";
|
|
4
|
-
})(WebSocketEventType || (WebSocketEventType = {}));
|
|
5
|
-
export class WebSocketEvent {
|
|
6
|
-
constructor(type, payload) {
|
|
7
|
-
this.type = type;
|
|
8
|
-
this.payload = payload;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export var WebSocketEventType;
|
|
2
|
+
(function (WebSocketEventType) {
|
|
3
|
+
WebSocketEventType["RESISTER_WIDGETS"] = "ws::cn.widgetjs.core.resister_widgets";
|
|
4
|
+
})(WebSocketEventType || (WebSocketEventType = {}));
|
|
5
|
+
export class WebSocketEvent {
|
|
6
|
+
constructor(type, payload) {
|
|
7
|
+
this.type = type;
|
|
8
|
+
this.payload = payload;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import localforage from "localforage";
|
|
2
|
-
import { BroadcastEvent } from "../model/event/BroadcastEvent";
|
|
3
|
-
import { BroadcastApi } from "../api/BroadcastApi";
|
|
4
|
-
export class WidgetDataRepository {
|
|
5
|
-
/**
|
|
6
|
-
* 保存组件数据
|
|
7
|
-
* @param data
|
|
8
|
-
*/
|
|
9
|
-
static async save(data) {
|
|
10
|
-
let store = this.getStore(data.name);
|
|
11
|
-
const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
|
|
12
|
-
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
|
|
13
|
-
await BroadcastApi.sendBroadcastEvent(broadcastEvent);
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* 获取组件 LocalForage 存储实例
|
|
18
|
-
* @param name
|
|
19
|
-
*/
|
|
20
|
-
static getStore(name) {
|
|
21
|
-
if (this.stores.has(name)) {
|
|
22
|
-
return this.stores.get(name);
|
|
23
|
-
}
|
|
24
|
-
const store = localforage.createInstance({ name: name });
|
|
25
|
-
this.stores.set(name, store);
|
|
26
|
-
return store;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
30
|
-
* @param data
|
|
31
|
-
*/
|
|
32
|
-
static async saveByName(data) {
|
|
33
|
-
const store = this.getStore(data.name);
|
|
34
|
-
const json = JSON.stringify(data);
|
|
35
|
-
const result = await store.setItem(data.name, json);
|
|
36
|
-
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
|
|
37
|
-
await BroadcastApi.sendBroadcastEvent(broadcastEvent);
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
static async findByName(name, type) {
|
|
41
|
-
let store = this.getStore(name);
|
|
42
|
-
let result = await store.getItem(name);
|
|
43
|
-
if (result) {
|
|
44
|
-
const widgetData = new type(name);
|
|
45
|
-
widgetData.parseJSON(JSON.parse(result));
|
|
46
|
-
return widgetData;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
static async find(name, id, type) {
|
|
51
|
-
let store = this.getStore(name);
|
|
52
|
-
let result = await store.getItem(this.getKey(name, id));
|
|
53
|
-
if (result) {
|
|
54
|
-
const widgetData = new type(name, id);
|
|
55
|
-
widgetData.parseJSON(JSON.parse(result));
|
|
56
|
-
return widgetData;
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
static getKey(name, id) {
|
|
61
|
-
return `${name}@${id}`;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
WidgetDataRepository.stores = new Map();
|
|
1
|
+
import localforage from "localforage";
|
|
2
|
+
import { BroadcastEvent } from "../model/event/BroadcastEvent";
|
|
3
|
+
import { BroadcastApi } from "../api/BroadcastApi";
|
|
4
|
+
export class WidgetDataRepository {
|
|
5
|
+
/**
|
|
6
|
+
* 保存组件数据
|
|
7
|
+
* @param data
|
|
8
|
+
*/
|
|
9
|
+
static async save(data) {
|
|
10
|
+
let store = this.getStore(data.name);
|
|
11
|
+
const result = await store.setItem(this.getKey(data.name, data.id), JSON.stringify(data));
|
|
12
|
+
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", data);
|
|
13
|
+
await BroadcastApi.sendBroadcastEvent(broadcastEvent);
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 获取组件 LocalForage 存储实例
|
|
18
|
+
* @param name
|
|
19
|
+
*/
|
|
20
|
+
static getStore(name) {
|
|
21
|
+
if (this.stores.has(name)) {
|
|
22
|
+
return this.stores.get(name);
|
|
23
|
+
}
|
|
24
|
+
const store = localforage.createInstance({ name: name });
|
|
25
|
+
this.stores.set(name, store);
|
|
26
|
+
return store;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
|
|
30
|
+
* @param data
|
|
31
|
+
*/
|
|
32
|
+
static async saveByName(data) {
|
|
33
|
+
const store = this.getStore(data.name);
|
|
34
|
+
const json = JSON.stringify(data);
|
|
35
|
+
const result = await store.setItem(data.name, json);
|
|
36
|
+
const broadcastEvent = new BroadcastEvent(BroadcastEvent.TYPE_WIDGET_UPDATED, "", { name: data.name, json });
|
|
37
|
+
await BroadcastApi.sendBroadcastEvent(broadcastEvent);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
static async findByName(name, type) {
|
|
41
|
+
let store = this.getStore(name);
|
|
42
|
+
let result = await store.getItem(name);
|
|
43
|
+
if (result) {
|
|
44
|
+
const widgetData = new type(name);
|
|
45
|
+
widgetData.parseJSON(JSON.parse(result));
|
|
46
|
+
return widgetData;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
static async find(name, id, type) {
|
|
51
|
+
let store = this.getStore(name);
|
|
52
|
+
let result = await store.getItem(this.getKey(name, id));
|
|
53
|
+
if (result) {
|
|
54
|
+
const widgetData = new type(name, id);
|
|
55
|
+
widgetData.parseJSON(JSON.parse(result));
|
|
56
|
+
return widgetData;
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
static getKey(name, id) {
|
|
61
|
+
return `${name}@${id}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
WidgetDataRepository.stores = new Map();
|