@dobot-plus/template 1.0.0
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/.dobot/.sftprc +3 -0
- package/.dobot/components/DobotPlusApp.tsx +78 -0
- package/.dobot/http/api.json +11 -0
- package/.dobot/http/api.ts +26 -0
- package/.dobot/http/api.ts.txt +26 -0
- package/.dobot/http/axios.ts +52 -0
- package/.dobot/http/axios.ts.txt +52 -0
- package/.dobot/http/http.ts +22 -0
- package/.dobot/http/http.ts.txt +22 -0
- package/.dobot/index.ts +2 -0
- package/.dobot/index.txt +2 -0
- package/.dobot/protocol/keyBoard.ts +18 -0
- package/.dobot/protocol/keyBoard.ts.txt +18 -0
- package/.dobot/protocol/methodsHandler.ts +15 -0
- package/.dobot/protocol/methodsHandler.ts.txt +15 -0
- package/.dobot/protocol/postMessageCenter.ts +50 -0
- package/.dobot/protocol/postMessageCenter.ts.txt +38 -0
- package/.dobot/protocol/postMessageHandler.ts +289 -0
- package/.dobot/protocol/postMessageHandler.ts.txt +289 -0
- package/.dobot/protocol/websocketHandler.ts +234 -0
- package/.dobot/protocol/websocketHandler.ts.txt +234 -0
- package/.dobot/shim.d.ts +3 -0
- package/.dobot/shim.d.ts.txt +3 -0
- package/.dobot/store/actions/toolActions.ts +69 -0
- package/.dobot/store/actions/toolActions.ts.txt +69 -0
- package/.dobot/store/actions/userMagamentActions.ts +25 -0
- package/.dobot/store/actions/userMagamentActions.ts.txt +25 -0
- package/.dobot/store/index.ts +7 -0
- package/.dobot/store/index.ts.txt +7 -0
- package/.dobot/store/reducers/index.ts +8 -0
- package/.dobot/store/reducers/index.ts.txt +8 -0
- package/.dobot/store/reducers/toolReducer.ts +152 -0
- package/.dobot/store/reducers/toolReducer.ts.txt +149 -0
- package/.dobot/store/reducers/userMagamentReducer.ts +38 -0
- package/.dobot/store/reducers/userMagamentReducer.ts.txt +35 -0
- package/.dobot/store/types.ts +240 -0
- package/.dobot/store/types.ts.txt +237 -0
- package/.dobot/template/default.tsx.mustache +20 -0
- package/.dobot/template/entry.css +26 -0
- package/.dobot/template/entry.tsx +53 -0
- package/.dobot/template/index.html +23 -0
- package/.dobot/template/index.scss +5 -0
- package/.dobot/utils/i18n.ts +31 -0
- package/.dobot/utils/i18n.ts.txt +31 -0
- package/.dobot/utils/mqtt.ts +61 -0
- package/.dobot/utils/mqtt.ts.txt +61 -0
- package/.dobot/utils/rem.js +21 -0
- package/.dobot/utils/rem.js.txt +21 -0
- package/.dobot/utils/tool.ts +15 -0
- package/.dobot/utils/tool.ts.txt +15 -0
- package/.eslintrc.cjs +18 -0
- package/.luarc.json +17 -0
- package/.vscode/Api.schema.json +103 -0
- package/.vscode/Blocks.schema.json +94 -0
- package/.vscode/Main.schema.json +42 -0
- package/.vscode/Script.schema.json +22 -0
- package/.vscode/Toolbar.schema.json +19 -0
- package/.vscode/extensions.json +8 -0
- package/.vscode/settings.json +52 -0
- package/Resources/document/config.json +0 -0
- package/Resources/i18n/client/de.json +11 -0
- package/Resources/i18n/client/en.json +11 -0
- package/Resources/i18n/client/es.json +11 -0
- package/Resources/i18n/client/hk.json +11 -0
- package/Resources/i18n/client/ja.json +11 -0
- package/Resources/i18n/client/ko.json +11 -0
- package/Resources/i18n/client/ru.json +11 -0
- package/Resources/i18n/client/zh.json +11 -0
- package/Resources/i18n/plugin/de.json +3 -0
- package/Resources/i18n/plugin/en.json +3 -0
- package/Resources/i18n/plugin/es.json +3 -0
- package/Resources/i18n/plugin/hk.json +3 -0
- package/Resources/i18n/plugin/ja.json +3 -0
- package/Resources/i18n/plugin/ko.json +3 -0
- package/Resources/i18n/plugin/ru.json +3 -0
- package/Resources/i18n/plugin/zh.json +3 -0
- package/Resources/images/pallet.svg +1 -0
- package/configs/Blocks.json +21 -0
- package/configs/Main.json +5 -0
- package/configs/Scripts.json +7 -0
- package/configs/Toolbar.json +5 -0
- package/dpt.json +4 -0
- package/lua/control.lua +19 -0
- package/lua/daemon.lua +22 -0
- package/lua/httpAPI.lua +65 -0
- package/lua/userAPI.lua +51 -0
- package/lua/utils/await485.lua +55 -0
- package/lua/utils/mqtt.lua +17 -0
- package/lua/utils/num_convert.lua +41 -0
- package/lua/utils/tcp.lua +31 -0
- package/lua/utils/util.lua +31 -0
- package/lua/utils/variables.lua +0 -0
- package/package.json +51 -0
- package/project.json +3 -0
- package/tsconfig.json +27 -0
- package/ui/Blocks.tsx +5 -0
- package/ui/Main.tsx +31 -0
- package/ui/Toolbar.tsx +5 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
export interface IStoreState {
|
|
2
|
+
toolReducer: ToolState
|
|
3
|
+
userMagamentReducer: userMagamentState
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface ICapacityData {
|
|
7
|
+
totalPallet: number
|
|
8
|
+
totalBox: number
|
|
9
|
+
timeHour: number
|
|
10
|
+
timeMin: number
|
|
11
|
+
timeSec: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IPalletRunningData {
|
|
15
|
+
status: number
|
|
16
|
+
layer: number
|
|
17
|
+
box: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ParamsStyle {
|
|
21
|
+
x: number
|
|
22
|
+
y: number
|
|
23
|
+
// 0:默认;1:旋转90
|
|
24
|
+
rotate: number
|
|
25
|
+
connection: number // 0:单吸 1:双吸(长边对齐) 2:双吸(短边对齐)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ItemPreviewParams {
|
|
29
|
+
boxCount: number
|
|
30
|
+
pallet: {
|
|
31
|
+
length: number
|
|
32
|
+
width: number
|
|
33
|
+
height: number
|
|
34
|
+
}
|
|
35
|
+
box: {
|
|
36
|
+
length: number
|
|
37
|
+
width: number
|
|
38
|
+
height: number
|
|
39
|
+
weight: number
|
|
40
|
+
}
|
|
41
|
+
style:
|
|
42
|
+
| {
|
|
43
|
+
typeA: ParamsStyle[]
|
|
44
|
+
typeB: ParamsStyle[]
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
typeC: ParamsStyle[]
|
|
48
|
+
typeD: ParamsStyle[]
|
|
49
|
+
}
|
|
50
|
+
layer: {
|
|
51
|
+
count: number
|
|
52
|
+
order: number[]
|
|
53
|
+
partition: number
|
|
54
|
+
partitionHeight: number
|
|
55
|
+
}
|
|
56
|
+
coordinate: {
|
|
57
|
+
user: Array<number>
|
|
58
|
+
tool: number
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PreviewParamsData {
|
|
63
|
+
conveyer?: number
|
|
64
|
+
suction?: number
|
|
65
|
+
lift?: number
|
|
66
|
+
left?: ItemPreviewParams
|
|
67
|
+
right?: ItemPreviewParams
|
|
68
|
+
}
|
|
69
|
+
export interface PointType {
|
|
70
|
+
x: number
|
|
71
|
+
y: number
|
|
72
|
+
z: number
|
|
73
|
+
rx: number
|
|
74
|
+
ry: number
|
|
75
|
+
rz: number
|
|
76
|
+
}
|
|
77
|
+
export interface caliPointType {
|
|
78
|
+
imageX: number
|
|
79
|
+
imageY: number
|
|
80
|
+
physicalX: number
|
|
81
|
+
physicalY: number
|
|
82
|
+
angle: number
|
|
83
|
+
}
|
|
84
|
+
export interface ToolState {
|
|
85
|
+
portData: {
|
|
86
|
+
ip: string
|
|
87
|
+
port: string
|
|
88
|
+
isSync: boolean
|
|
89
|
+
}
|
|
90
|
+
tcpStatus: boolean
|
|
91
|
+
tcpInfo: any
|
|
92
|
+
extendIoData: any[]
|
|
93
|
+
onRobotTool: string[]
|
|
94
|
+
deviceStateData: DeviceState
|
|
95
|
+
ioData: any
|
|
96
|
+
pluginPort: string
|
|
97
|
+
dobotplusHost: string
|
|
98
|
+
ioList: {
|
|
99
|
+
input: {
|
|
100
|
+
address: number
|
|
101
|
+
diValue: number
|
|
102
|
+
editName: string
|
|
103
|
+
init: string
|
|
104
|
+
isShow: boolean
|
|
105
|
+
name: string
|
|
106
|
+
value: number
|
|
107
|
+
}[]
|
|
108
|
+
output: {
|
|
109
|
+
address: number
|
|
110
|
+
editName: string
|
|
111
|
+
init: string
|
|
112
|
+
isShow: boolean
|
|
113
|
+
name: string
|
|
114
|
+
value: number
|
|
115
|
+
}[]
|
|
116
|
+
}
|
|
117
|
+
pointData: any[]
|
|
118
|
+
jogInPaused: boolean
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type DeviceState = {
|
|
122
|
+
isTimeout?: boolean
|
|
123
|
+
stateL?: boolean
|
|
124
|
+
pose: {
|
|
125
|
+
joints: number[]
|
|
126
|
+
axes: number[]
|
|
127
|
+
auxJoint: number[]
|
|
128
|
+
l: number
|
|
129
|
+
rdnCoordinate?: number[]
|
|
130
|
+
}
|
|
131
|
+
alarm: number[]
|
|
132
|
+
alarmGo: number[]
|
|
133
|
+
hht: {
|
|
134
|
+
isEnabled: boolean
|
|
135
|
+
}
|
|
136
|
+
safeGuardMode?: 0 | 1 | 2
|
|
137
|
+
batteryVoltage?: number
|
|
138
|
+
batteryStatus?: 0 | 1
|
|
139
|
+
moveSpeed?: {
|
|
140
|
+
x: number
|
|
141
|
+
y: number
|
|
142
|
+
r: number
|
|
143
|
+
}
|
|
144
|
+
position?: {
|
|
145
|
+
x: number
|
|
146
|
+
y: number
|
|
147
|
+
yaw: number
|
|
148
|
+
}
|
|
149
|
+
joyState?: boolean
|
|
150
|
+
controlMode: number
|
|
151
|
+
isCollision?: boolean
|
|
152
|
+
skinCollison?: boolean
|
|
153
|
+
|
|
154
|
+
remoteControl?: remoteControlType
|
|
155
|
+
cameraModel?: {
|
|
156
|
+
arm: number
|
|
157
|
+
car: number
|
|
158
|
+
}
|
|
159
|
+
inputs?: number[]
|
|
160
|
+
outputs?: number[]
|
|
161
|
+
endDI?: number[]
|
|
162
|
+
endDO?: number[]
|
|
163
|
+
gpioAO?: number[]
|
|
164
|
+
extendDO?: number[][]
|
|
165
|
+
extendDI?: number[][]
|
|
166
|
+
ioAI?: number[]
|
|
167
|
+
endAI?: number[]
|
|
168
|
+
prjState?: PrjStateType
|
|
169
|
+
powerState?: boolean
|
|
170
|
+
detailsInfo?: {
|
|
171
|
+
controlParams: number[]
|
|
172
|
+
jointCurrent: number[]
|
|
173
|
+
jointVoltage: number[]
|
|
174
|
+
jointTemp: number[]
|
|
175
|
+
}
|
|
176
|
+
dragMode?: boolean // 拖拽状态
|
|
177
|
+
isSafeRun?: number
|
|
178
|
+
isSafeSuspend?: number
|
|
179
|
+
safeDO?: number[]
|
|
180
|
+
safeDI?: number[]
|
|
181
|
+
selectedControlBarCoordinate: {
|
|
182
|
+
user: number
|
|
183
|
+
tool: number
|
|
184
|
+
}
|
|
185
|
+
jogMode: JogMode
|
|
186
|
+
dragPlayback?: boolean // 复现状态
|
|
187
|
+
dragTrack?: boolean // 录制状态
|
|
188
|
+
autoManual?: 'auto' | 'manual'
|
|
189
|
+
emergencyStop?: boolean
|
|
190
|
+
warning?: number
|
|
191
|
+
speedRatio?: number
|
|
192
|
+
remoteRun?: boolean
|
|
193
|
+
jointBrake?: number[]
|
|
194
|
+
coordinate?: CoordinateType
|
|
195
|
+
pointSignal?: number
|
|
196
|
+
ledStatus?: number
|
|
197
|
+
skinValue?: number[]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export enum RemoteModeType {
|
|
201
|
+
Online = 'tp',
|
|
202
|
+
TCP = 'tcp'
|
|
203
|
+
}
|
|
204
|
+
export type remoteControlType = {
|
|
205
|
+
mode: RemoteModeType
|
|
206
|
+
name: string
|
|
207
|
+
}
|
|
208
|
+
export enum PrjStateType {
|
|
209
|
+
stopped = 'stopped',
|
|
210
|
+
suspended = 'suspended',
|
|
211
|
+
running = 'running'
|
|
212
|
+
}
|
|
213
|
+
export enum JogMode {
|
|
214
|
+
Jog = 'jog',
|
|
215
|
+
Step = 'step'
|
|
216
|
+
}
|
|
217
|
+
export enum CoordinateType {
|
|
218
|
+
Cartesian = 'cartesian',
|
|
219
|
+
Joint = 'joint',
|
|
220
|
+
Tool = 'tool'
|
|
221
|
+
}
|
|
222
|
+
export interface userMagamentState {
|
|
223
|
+
userModalData: {
|
|
224
|
+
show: boolean
|
|
225
|
+
edit?: boolean
|
|
226
|
+
user?: any
|
|
227
|
+
index?: number
|
|
228
|
+
}
|
|
229
|
+
permissionList: any[]
|
|
230
|
+
currentLevel: number
|
|
231
|
+
currentUserInfo: string
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export enum ModuleType {
|
|
235
|
+
Module = 'Module',
|
|
236
|
+
Template = 'Template'
|
|
237
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import './index.scss'
|
|
3
|
+
import { Provider } from 'react-redux'
|
|
4
|
+
import store from '../store'
|
|
5
|
+
import App from '$APP_PATH$'
|
|
6
|
+
import '@dobot/utils/rem'
|
|
7
|
+
import '@dobot/utils/i18n'
|
|
8
|
+
import '@dobot-plus/components/dist/style.css'
|
|
9
|
+
import { createRoot } from 'react-dom/client'
|
|
10
|
+
|
|
11
|
+
const root = document.getElementById('root')
|
|
12
|
+
if (root) {
|
|
13
|
+
createRoot(root).render(
|
|
14
|
+
<React.StrictMode>
|
|
15
|
+
<Provider store={store}>
|
|
16
|
+
<App />
|
|
17
|
+
</Provider>
|
|
18
|
+
</React.StrictMode>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
body,
|
|
2
|
+
html {
|
|
3
|
+
padding: 0;
|
|
4
|
+
margin: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.container {
|
|
8
|
+
padding: 12px 24px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.iframe-container {
|
|
12
|
+
position: relative;
|
|
13
|
+
width: 320px;
|
|
14
|
+
height: 180px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
iframe {
|
|
18
|
+
width: 1920px;
|
|
19
|
+
height: 1080px;
|
|
20
|
+
transform: scale(0.1667); /* 根据比例缩放,320/1920 = 0.1667 */
|
|
21
|
+
transform-origin: top left; /* 保持左上角为缩放原点 */
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 0;
|
|
24
|
+
left: 0;
|
|
25
|
+
border: 1px solid #F5F5F5;
|
|
26
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import './entry.css'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { Card, Space } from 'antd'
|
|
5
|
+
|
|
6
|
+
const root = document.getElementById('root')
|
|
7
|
+
if (root) {
|
|
8
|
+
createRoot(root).render(
|
|
9
|
+
<React.StrictMode>
|
|
10
|
+
<div className="container">
|
|
11
|
+
<h2>插件页面</h2>
|
|
12
|
+
<Space>
|
|
13
|
+
<Card
|
|
14
|
+
title={
|
|
15
|
+
<Space>
|
|
16
|
+
<span>导航栏</span>
|
|
17
|
+
<a href="/Toolbar/toolbar.html">预览|调试</a>
|
|
18
|
+
</Space>
|
|
19
|
+
}
|
|
20
|
+
>
|
|
21
|
+
<div className="iframe-container">
|
|
22
|
+
<iframe src="/Toolbar/toolbar.html"></iframe>
|
|
23
|
+
</div>
|
|
24
|
+
</Card>
|
|
25
|
+
<Card
|
|
26
|
+
title={
|
|
27
|
+
<Space>
|
|
28
|
+
<span>控制页面</span>
|
|
29
|
+
<a href="/Main">预览|调试</a>
|
|
30
|
+
</Space>
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
<div className="iframe-container">
|
|
34
|
+
<iframe src="/Main"></iframe>
|
|
35
|
+
</div>
|
|
36
|
+
</Card>
|
|
37
|
+
<Card
|
|
38
|
+
title={
|
|
39
|
+
<Space>
|
|
40
|
+
<span>积木弹窗</span>
|
|
41
|
+
<a href="/Blocks">预览|调试</a>
|
|
42
|
+
</Space>
|
|
43
|
+
}
|
|
44
|
+
>
|
|
45
|
+
<div className="iframe-container">
|
|
46
|
+
<iframe src="/Blocks"></iframe>
|
|
47
|
+
</div>
|
|
48
|
+
</Card>
|
|
49
|
+
</Space>
|
|
50
|
+
</div>
|
|
51
|
+
</React.StrictMode>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Document</title>
|
|
7
|
+
<style>
|
|
8
|
+
body,
|
|
9
|
+
html {
|
|
10
|
+
height: 100%;
|
|
11
|
+
}
|
|
12
|
+
body,
|
|
13
|
+
html {
|
|
14
|
+
margin: 0;
|
|
15
|
+
padding: 0;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
|
|
20
|
+
<body>
|
|
21
|
+
<div id="root"></div>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import zh from '../../Resources/i18n/plugin/zh.json'
|
|
2
|
+
import de from '../../Resources/i18n/plugin/de.json'
|
|
3
|
+
import ja from '../../Resources/i18n/plugin/ja.json'
|
|
4
|
+
import ko from '../../Resources/i18n/plugin/ko.json'
|
|
5
|
+
import en from '../../Resources/i18n/plugin/en.json'
|
|
6
|
+
import ru from '../../Resources/i18n/plugin/ru.json'
|
|
7
|
+
import es from '../../Resources/i18n/plugin/es.json'
|
|
8
|
+
import hk from '../../Resources/i18n/plugin/hk.json'
|
|
9
|
+
|
|
10
|
+
import i18n from 'i18next'
|
|
11
|
+
import { initReactI18next } from 'react-i18next'
|
|
12
|
+
|
|
13
|
+
i18n.use(initReactI18next).init({
|
|
14
|
+
resources: {
|
|
15
|
+
en: { translation: en },
|
|
16
|
+
zh: { translation: zh },
|
|
17
|
+
de: { translation: de },
|
|
18
|
+
ja: { translation: ja },
|
|
19
|
+
ko: { translation: ko },
|
|
20
|
+
ru: { translation: ru },
|
|
21
|
+
es: { translation: es },
|
|
22
|
+
hk: { translation: hk }
|
|
23
|
+
},
|
|
24
|
+
lng: 'zh',
|
|
25
|
+
interpolation: {
|
|
26
|
+
escapeValue: false
|
|
27
|
+
},
|
|
28
|
+
fallbackLng: 'en'
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export default i18n
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import zh from '../../Resources/i18n/plugin/zh.json'
|
|
2
|
+
import de from '../../Resources/i18n/plugin/de.json'
|
|
3
|
+
import ja from '../../Resources/i18n/plugin/ja.json'
|
|
4
|
+
import ko from '../../Resources/i18n/plugin/ko.json'
|
|
5
|
+
import en from '../../Resources/i18n/plugin/en.json'
|
|
6
|
+
import ru from '../../Resources/i18n/plugin/ru.json'
|
|
7
|
+
import es from '../../Resources/i18n/plugin/es.json'
|
|
8
|
+
import hk from '../../Resources/i18n/plugin/hk.json'
|
|
9
|
+
|
|
10
|
+
import i18n from 'i18next'
|
|
11
|
+
import { initReactI18next } from 'react-i18next'
|
|
12
|
+
|
|
13
|
+
i18n.use(initReactI18next).init({
|
|
14
|
+
resources: {
|
|
15
|
+
en: { translation: en },
|
|
16
|
+
zh: { translation: zh },
|
|
17
|
+
de: { translation: de },
|
|
18
|
+
ja: { translation: ja },
|
|
19
|
+
ko: { translation: ko },
|
|
20
|
+
ru: { translation: ru },
|
|
21
|
+
es: { translation: es },
|
|
22
|
+
hk: { translation: hk }
|
|
23
|
+
},
|
|
24
|
+
lng: 'zh',
|
|
25
|
+
interpolation: {
|
|
26
|
+
escapeValue: false
|
|
27
|
+
},
|
|
28
|
+
fallbackLng: 'en'
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export default i18n
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { connect, MqttClient, IClientOptions } from 'mqtt'
|
|
2
|
+
export class MqttWebSocketClient {
|
|
3
|
+
private client!: MqttClient
|
|
4
|
+
private receiveMessageHandle!: (topic: string, msg: Buffer) => void
|
|
5
|
+
private serverUrl: string
|
|
6
|
+
private clientId: string
|
|
7
|
+
private options: IClientOptions
|
|
8
|
+
public constructor(serverUrl: string, clientId: string, options?: IClientOptions) {
|
|
9
|
+
this.serverUrl = serverUrl
|
|
10
|
+
this.clientId = clientId
|
|
11
|
+
this.options = options || {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//连接
|
|
15
|
+
public connect(): void {
|
|
16
|
+
this.client = connect(this.serverUrl, {
|
|
17
|
+
clientId: this.clientId,
|
|
18
|
+
...this.options
|
|
19
|
+
})
|
|
20
|
+
this.client.on('connect', this.onConnect)
|
|
21
|
+
this.client.on('message', this.onMessage) //接收消息
|
|
22
|
+
this.client.on('error', this.onError)
|
|
23
|
+
}
|
|
24
|
+
//断开连接
|
|
25
|
+
public disconnect(): void {
|
|
26
|
+
if (this.client) {
|
|
27
|
+
this.client.end()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 订阅
|
|
32
|
+
public subscribe(topic: string, receiveMessageHandle?: (topic: string, msg: Buffer) => void): void {
|
|
33
|
+
if (this.client) {
|
|
34
|
+
this.client.subscribe(topic)
|
|
35
|
+
if (receiveMessageHandle) {
|
|
36
|
+
this.receiveMessageHandle = receiveMessageHandle
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//取消订阅
|
|
41
|
+
public unsubscribe(topic: string): void {
|
|
42
|
+
if (this.client) {
|
|
43
|
+
this.client.unsubscribe(topic)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// 发布消息
|
|
47
|
+
public publish(topic: string, message: string | Buffer): void {
|
|
48
|
+
if (this.client) {
|
|
49
|
+
this.client.publish(topic, message)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
private onConnect = (): void => {}
|
|
53
|
+
private onMessage = (topic: string, message: Buffer): void => {
|
|
54
|
+
if (this.receiveMessageHandle) {
|
|
55
|
+
this.receiveMessageHandle(topic, message)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
private onError = (error: Error): void => {
|
|
59
|
+
console.log('连接错误:', error)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { connect, MqttClient, IClientOptions } from 'mqtt'
|
|
2
|
+
export class MqttWebSocketClient {
|
|
3
|
+
private client!: MqttClient
|
|
4
|
+
private receiveMessageHandle!: (topic: string, msg: Buffer) => void
|
|
5
|
+
private serverUrl: string
|
|
6
|
+
private clientId: string
|
|
7
|
+
private options: IClientOptions
|
|
8
|
+
public constructor(serverUrl: string, clientId: string, options?: IClientOptions) {
|
|
9
|
+
this.serverUrl = serverUrl
|
|
10
|
+
this.clientId = clientId
|
|
11
|
+
this.options = options || {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//连接
|
|
15
|
+
public connect(): void {
|
|
16
|
+
this.client = connect(this.serverUrl, {
|
|
17
|
+
clientId: this.clientId,
|
|
18
|
+
...this.options
|
|
19
|
+
})
|
|
20
|
+
this.client.on('connect', this.onConnect)
|
|
21
|
+
this.client.on('message', this.onMessage) //接收消息
|
|
22
|
+
this.client.on('error', this.onError)
|
|
23
|
+
}
|
|
24
|
+
//断开连接
|
|
25
|
+
public disconnect(): void {
|
|
26
|
+
if (this.client) {
|
|
27
|
+
this.client.end()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 订阅
|
|
32
|
+
public subscribe(topic: string, receiveMessageHandle?: (topic: string, msg: Buffer) => void): void {
|
|
33
|
+
if (this.client) {
|
|
34
|
+
this.client.subscribe(topic)
|
|
35
|
+
if (receiveMessageHandle) {
|
|
36
|
+
this.receiveMessageHandle = receiveMessageHandle
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//取消订阅
|
|
41
|
+
public unsubscribe(topic: string): void {
|
|
42
|
+
if (this.client) {
|
|
43
|
+
this.client.unsubscribe(topic)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// 发布消息
|
|
47
|
+
public publish(topic: string, message: string | Buffer): void {
|
|
48
|
+
if (this.client) {
|
|
49
|
+
this.client.publish(topic, message)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
private onConnect = (): void => {}
|
|
53
|
+
private onMessage = (topic: string, message: Buffer): void => {
|
|
54
|
+
if (this.receiveMessageHandle) {
|
|
55
|
+
this.receiveMessageHandle(topic, message)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
private onError = (error: Error): void => {
|
|
59
|
+
console.log('连接错误:', error)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
;(function (doc, win) {
|
|
2
|
+
var docEl = doc.documentElement,
|
|
3
|
+
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
|
|
4
|
+
recalc = function () {
|
|
5
|
+
var clientWidth = docEl.clientWidth
|
|
6
|
+
var clientHeight = docEl.clientHeight
|
|
7
|
+
if (!clientWidth) return
|
|
8
|
+
if (clientWidth >= 596 && clientHeight >= 624) {
|
|
9
|
+
docEl.style.fontSize = '100px'
|
|
10
|
+
} else if (clientWidth < 596 && clientHeight >= 624) {
|
|
11
|
+
docEl.style.fontSize = 100 * (clientWidth / 596) + 'px'
|
|
12
|
+
} else if (clientWidth >= 596 && clientHeight < 624) {
|
|
13
|
+
docEl.style.fontSize = 100 * (clientHeight / 624) + 'px'
|
|
14
|
+
} else {
|
|
15
|
+
docEl.style.fontSize = 100 * (clientWidth / 624) + 'px'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!doc.addEventListener) return
|
|
19
|
+
win.addEventListener(resizeEvt, recalc, false)
|
|
20
|
+
doc.addEventListener('DOMContentLoaded', recalc, false)
|
|
21
|
+
})(document, window)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
; (function (doc, win) {
|
|
2
|
+
var docEl = doc.documentElement,
|
|
3
|
+
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
|
|
4
|
+
recalc = function () {
|
|
5
|
+
var clientWidth = docEl.clientWidth
|
|
6
|
+
var clientHeight = docEl.clientHeight
|
|
7
|
+
if (!clientWidth) return
|
|
8
|
+
if (clientWidth >= 596 && clientHeight >= 624) {
|
|
9
|
+
docEl.style.fontSize = '100px'
|
|
10
|
+
} else if (clientWidth < 596 && clientHeight >= 624) {
|
|
11
|
+
docEl.style.fontSize = 100 * (clientWidth / 596) + 'px'
|
|
12
|
+
} else if (clientWidth >= 596 && clientHeight < 624) {
|
|
13
|
+
docEl.style.fontSize = 100 * (clientHeight / 624) + 'px'
|
|
14
|
+
} else {
|
|
15
|
+
docEl.style.fontSize = 100 * (clientWidth / 624) + 'px'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (!doc.addEventListener) return
|
|
19
|
+
win.addEventListener(resizeEvt, recalc, false)
|
|
20
|
+
doc.addEventListener('DOMContentLoaded', recalc, false)
|
|
21
|
+
})(document, window)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const isInIframe = window.self !== window.top
|
|
2
|
+
|
|
3
|
+
export const jsonSafeParse = (data: string|object) => {
|
|
4
|
+
if (typeof data === 'string') {
|
|
5
|
+
try {
|
|
6
|
+
const obj = JSON.parse(data)
|
|
7
|
+
if (typeof obj === 'object' && obj) {
|
|
8
|
+
return obj
|
|
9
|
+
}
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return data
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return data
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const isInIframe = window.self !== window.top
|
|
2
|
+
|
|
3
|
+
export const jsonSafeParse = (data: string | object) => {
|
|
4
|
+
if (typeof data === 'string') {
|
|
5
|
+
try {
|
|
6
|
+
const obj = JSON.parse(data)
|
|
7
|
+
if (typeof obj === 'object' && obj) {
|
|
8
|
+
return obj
|
|
9
|
+
}
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return data
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return data
|
|
15
|
+
}
|
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: { browser: true, es2020: true },
|
|
4
|
+
extends: [
|
|
5
|
+
'eslint:recommended',
|
|
6
|
+
'plugin:@typescript-eslint/recommended',
|
|
7
|
+
'plugin:react-hooks/recommended',
|
|
8
|
+
],
|
|
9
|
+
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
|
10
|
+
parser: '@typescript-eslint/parser',
|
|
11
|
+
plugins: ['react-refresh'],
|
|
12
|
+
rules: {
|
|
13
|
+
'react-refresh/only-export-components': [
|
|
14
|
+
'warn',
|
|
15
|
+
{ allowConstantExport: true },
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
}
|
package/.luarc.json
ADDED