@dobot-plus/template 1.0.7 → 1.1.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.
@@ -1,234 +0,0 @@
1
- import i18n from '../utils/i18n'
2
- import store from '../store'
3
- import { toolActions } from '../store/actions/toolActions'
4
- import { userMagamentActions } from '../store/actions/userMagamentActions'
5
- import { communicator } from './postMessageCenter'
6
-
7
- const url = `ws://localhost:8099`
8
-
9
- export class WebSocketHandler {
10
- private ws: null | WebSocket
11
- private promiseObj: any
12
- private id: number
13
- private timerId: any
14
- private timeoutObj: any
15
- private timeout: number
16
- private serverTimeoutObj: null
17
- private isConnect: boolean
18
- private tryTimes: number
19
-
20
- constructor() {
21
- this.ws = null
22
- this.promiseObj = {}
23
- this.id = 0
24
- this.timerId = null
25
- this.timeout = 30000 //30秒发一次心跳
26
- this.timeoutObj = null
27
- this.serverTimeoutObj = null
28
- this.isConnect = false
29
- this.contentWs()
30
- this.tryTimes = -1
31
- }
32
-
33
- private contentWs = () => {
34
- if (this.isConnect || this.tryTimes > 3) return
35
- this.tryTimes += 1
36
-
37
- this.ws = new WebSocket(url)
38
- this.ws.onopen = () => {
39
- this.reset().start()
40
- this.isConnect = true
41
- ;(this.ws as WebSocket).onmessage = (data) => this.onSocketMessage(JSON.parse(data.data))
42
- }
43
- this.ws.onerror = () => {
44
- this.isConnect = false
45
- this.contentWs()
46
- }
47
- this.ws.onclose = () => {
48
- this.isConnect = false
49
- this.contentWs()
50
- }
51
- }
52
-
53
- private send = (params: { method: string; data: any }) => {
54
- const { data, method } = params
55
- const sendData = JSON.stringify({
56
- jsonrpc: '2.0',
57
- method,
58
- id: this.id,
59
- data
60
- })
61
-
62
- if (this.ws) this.ws.send(sendData)
63
- return new Promise((resolve) => {
64
- this.promiseObj[this.id] = resolve
65
- this.id++
66
- })
67
- }
68
-
69
- private onSocketMessage = (data: { id: number; method: string; result?: any; data?: any }) => {
70
- this.reset().start()
71
- this.id = data.id
72
- if (this.promiseObj[data.id]) {
73
- this.promiseObj[data.id](data.result || data.data)
74
- delete this.promiseObj[data.id]
75
- }
76
- if (data.method === 'heart') return
77
- this.messageHandler(data)
78
- }
79
-
80
- private reset() {
81
- clearTimeout(this.timeoutObj)
82
- clearTimeout(this.serverTimeoutObj as any)
83
- return this
84
- }
85
- private start() {
86
- if (this.ws) {
87
- this.timeoutObj = setTimeout(() => {
88
- //这里发送一个心跳,后端收到后,返回一个心跳消息,
89
- //onmessage拿到返回的心跳就说明连接正常
90
- this.send({ data: 'ping', method: 'heart' })
91
- // this.serverTimeoutObj = setTimeout(function () {//如果超过一定时间还没重置,说明后端主动断开了
92
- // this.ws.close(); //如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
93
- // }, this.timeout)
94
- }, this.timeout)
95
- }
96
- }
97
-
98
- private messageHandler = (data: any) => {
99
- let method = data.method
100
- if (method) {
101
- // 将 highlight_blocks 更改为 highlightBlocks 这样的驼峰样式
102
- method = method.replace(/_(\w)/g, (_: any, match: string) => match.toUpperCase()) + 'Handler'
103
- if ((this as any)[method]) {
104
- ;(this as any)[method](data)
105
- } else {
106
- throw `没有对应的 ${method} 处理方法, 请进行定义`
107
- }
108
- } else {
109
- console.error('不是自定义 message' + data)
110
- }
111
- }
112
-
113
- // *******************以下是WebSocket的响应接口********************
114
-
115
- // 初始化, 根据WS的消息调起
116
- private initHandler = (data: any) => {
117
- const deviceInfo = data.data
118
- if (deviceInfo) {
119
- store.dispatch(toolActions.setPortIp(deviceInfo.portName))
120
- }
121
- }
122
- private syncJogInPausedHandler = (event: MessageEvent) => {
123
- const data = event.data
124
- communicator.registerSource(event.data.from || event.data.iframeName, event.source, event.origin)
125
- store.dispatch(toolActions.setJogInPaused(data))
126
- }
127
-
128
- private syncIPAddressHandler = (data: any) => {
129
- const { ip } = data.data
130
- if (ip) {
131
- store.dispatch(toolActions.setPortIp(ip))
132
- }
133
- }
134
-
135
- // 同步语言
136
- private changeLocaleHandler = (data: any) => {
137
- const locale = data.data
138
- i18n.changeLanguage(locale.substr(0, 2))
139
- }
140
- syncExchangeHandler = (event: MessageEvent) => {
141
- const deviceStateData = event.data
142
- store.dispatch(toolActions.setDeviceStateData(deviceStateData))
143
- }
144
-
145
- dobotPlusBlockDataHandler = (event: MessageEvent) => {
146
- console.log('websocket dobotPlusBlockDataHandler', event)
147
- communicator.registerSource(JSON.parse(event.data).from, event.source, event.origin)
148
- const { data, locale, portName } = JSON.parse(event.data)
149
- store.dispatch(toolActions.setPortIp(portName))
150
- setTimeout(() => {
151
- PubSub.publish('dobotPlusBlockData', data)
152
- }, 1000)
153
- i18n.changeLanguage(locale.substr(0, 2))
154
- }
155
-
156
- resetDobotPlusBlockData = (data: any) => {
157
- console.log(data)
158
- communicator.send({
159
- method: 'resetDobotPlusBlockData',
160
- data,
161
- iframeName: 'alsontech',
162
- to: 'blockly'
163
- })
164
- }
165
- syncUserPermissionHandler = (event: MessageEvent) => {
166
- console.log('websocket syncUserPermissionHandler', event)
167
- communicator.registerSource(event.data.from || event.data.iframeName, event.source, event.origin)
168
- const level = JSON.parse(event.data)
169
- store.dispatch(userMagamentActions.setCurrentLevel(level))
170
- }
171
- syncCreditCardInfoHandler = (event: MessageEvent) => {
172
- console.log('websocket syncCreditCardInfoHandler', event)
173
- communicator.registerSource(event.data.from || event.data.iframeName, event.source, event.origin)
174
- store.dispatch(userMagamentActions.setCurrentUserInfo(String(event.data)))
175
- }
176
- dobotPlusLogout = () => {
177
- this.send({
178
- method: 'dobotPlusLogout',
179
- data: ''
180
- })
181
- }
182
- changeExitLoginTime = (time: any) => {
183
- this.send({
184
- method: 'changeExitLoginTime',
185
- data: time
186
- })
187
- }
188
- sendSkinState = (status: boolean) => {
189
- this.send({
190
- method: 'sendSkinState',
191
- data: status
192
- })
193
- }
194
- // dobot+应用通讯
195
- dobotplusQuit = async () => {
196
- await this.send({
197
- method: 'dobotplusQuit',
198
- data: {
199
- iframeName: 'dobotplusApp'
200
- }
201
- })
202
- }
203
-
204
- dobotplusCreateProject = async (path: string, projectData: any) => {
205
- return this.send({
206
- method: 'dobotplusCreateProject',
207
- data: { path, projectData }
208
- })
209
- }
210
-
211
- dobotplusWriteProject = async (path: string, projectData: any) => {
212
- return this.send({
213
- method: 'dobotplusWriteProject',
214
- data: { path, projectData }
215
- })
216
- }
217
-
218
- dobotplusDeleteProject = async (path: string) => {
219
- return this.send({
220
- method: 'dobotplusDeleteProject',
221
- data: { path }
222
- })
223
- }
224
-
225
- syncDobotPlusHostHandler = (data: any) => {
226
- if (!data.data) return
227
- store.dispatch(toolActions.setDobotplusHost(data.data))
228
- }
229
-
230
- syncIoDataHandler = (event: MessageEvent) => {
231
- const ioData = JSON.parse(event.data)
232
- store.dispatch(toolActions.setIoData(ioData))
233
- }
234
- }
@@ -1,3 +0,0 @@
1
- declare global {
2
- var COMPONENT_PATH: string
3
- }
@@ -1,69 +0,0 @@
1
- import { DeviceState } from '@dobot/store/types'
2
-
3
- export const TOOL_ACTIONS_TYPE = {
4
- SET_PORT_IP: 'setPortIp',
5
- SET_TCP_STATUS: 'setTcpStatus',
6
- SET_TCP_INFO: 'setTcpInfo',
7
- SET_EXTEND_IO_INDEX: 'setExtendIOData',
8
- SET_PORT: 'setPort',
9
- SET_ONROBOT_TOOL: 'setOnRobotTool',
10
- SET_DEVICE_STATE_DATA: 'setDeviceStateData',
11
- SET_PLUGIN_PORT: 'setPluginPort',
12
- SET_DOBOTPLUS_HOST: 'setDobotplusHost',
13
- SET_IO_DATA: 'setIoData',
14
- SET_POINT_DATA: 'setPointData',
15
- SET_JOG_IN_PAUSED: 'setJogInPaused'
16
- }
17
-
18
- class ToolActions {
19
- setPortIp = (params: string) => ({
20
- type: TOOL_ACTIONS_TYPE.SET_PORT_IP,
21
- params
22
- })
23
- setTcpStatus = (params: any) => ({
24
- type: TOOL_ACTIONS_TYPE.SET_TCP_STATUS,
25
- params
26
- })
27
- setTcpInfo = (params: any) => ({
28
- type: TOOL_ACTIONS_TYPE.SET_TCP_INFO,
29
- params
30
- })
31
- setExtendIOData = (params: any) => ({
32
- type: TOOL_ACTIONS_TYPE.SET_EXTEND_IO_INDEX,
33
- params
34
- })
35
- setPort = (params: any) => ({
36
- type: TOOL_ACTIONS_TYPE.SET_PORT,
37
- params
38
- })
39
- setOnRobotTool = (params: string[]) => ({
40
- type: TOOL_ACTIONS_TYPE.SET_ONROBOT_TOOL,
41
- params
42
- })
43
- setDeviceStateData = (params: DeviceState) => ({
44
- type: TOOL_ACTIONS_TYPE.SET_DEVICE_STATE_DATA,
45
- params
46
- })
47
- setPluginPort = (params: DeviceState) => ({
48
- type: TOOL_ACTIONS_TYPE.SET_PLUGIN_PORT,
49
- params
50
- })
51
- setDobotplusHost = (params: string) => ({
52
- type: TOOL_ACTIONS_TYPE.SET_DOBOTPLUS_HOST,
53
- params
54
- })
55
- setIoData = (params: DeviceState) => ({
56
- type: TOOL_ACTIONS_TYPE.SET_IO_DATA,
57
- params
58
- })
59
- setPointData = (params: any[]) => ({
60
- type: TOOL_ACTIONS_TYPE.SET_POINT_DATA,
61
- params
62
- })
63
- setJogInPaused = (params: boolean) => ({
64
- type: TOOL_ACTIONS_TYPE.SET_JOG_IN_PAUSED,
65
- params
66
- })
67
- }
68
-
69
- export const toolActions = new ToolActions()
@@ -1,25 +0,0 @@
1
- export const userMagamentActionsType = {
2
- SETUSERMODALDATA: 'setUserModalData',
3
- SET_PERMISSIONLIST: 'setPermissionList',
4
- SET_CURRENT_LEVEL: 'setCurrentLevel',
5
- SET_CURRENT_USER_INFO: 'setCurrentUserInfo'
6
- }
7
- class UserMagamentActions {
8
- setUserModalData = (params: any) => ({
9
- type: userMagamentActionsType.SETUSERMODALDATA,
10
- params
11
- })
12
- setPermissionList = (params: any) => ({
13
- type: userMagamentActionsType.SET_PERMISSIONLIST,
14
- params
15
- })
16
- setCurrentLevel = (params: any) => ({
17
- type: userMagamentActionsType.SET_CURRENT_LEVEL,
18
- params
19
- })
20
- setCurrentUserInfo = (params: any) => ({
21
- type: userMagamentActionsType.SET_CURRENT_USER_INFO,
22
- params
23
- })
24
- }
25
- export const userMagamentActions = new UserMagamentActions()
@@ -1,7 +0,0 @@
1
- import { createStore } from 'redux'
2
-
3
- import reducers from './reducers'
4
-
5
- const store = createStore(reducers)
6
-
7
- export default store
@@ -1,8 +0,0 @@
1
- import { combineReducers } from 'redux'
2
- import toolReducer from './toolReducer'
3
- import userMagamentReducer from './userMagamentReducer'
4
-
5
- export default combineReducers({
6
- toolReducer,
7
- userMagamentReducer
8
- })
@@ -1,149 +0,0 @@
1
- import { TOOL_ACTIONS_TYPE } from '../actions/toolActions'
2
-
3
- const initialStore = {
4
- portData: {
5
- ip: '192.168.5.1',
6
- port: '22000',
7
- isSync: false
8
- },
9
- tcpStatus: false,
10
- tcpInfo: [],
11
- extendIoData: [],
12
- onRobotTool: [],
13
- pluginPort: undefined,
14
- dobotplusHost: 'http://localhost:9889',
15
- deviceStateData: {
16
- prjState: 'stopped'
17
- },
18
- ioData: {
19
- ioList: {
20
- input: [...Array(1)].map((item, index) => ({
21
- address: index + 1,
22
- init: `DI_${index + 1}`,
23
- name: `DI_${index + 1}`,
24
- editName: '',
25
- value: 1,
26
- isShow: true,
27
- diValue: 0,
28
- isDI: false,
29
- type: 'Common',
30
- configurationStr: '',
31
- safeIOKey: 0
32
- })),
33
- inputSimulation: [...Array(1)].map((item, index) => ({
34
- address: index + 1,
35
- init: `AD_${index + 1}`,
36
- name: `AD_${index + 1}`,
37
- editName: '',
38
- isShow: true,
39
- value: 3.3
40
- })),
41
- output: [...Array(1)].map((item, index) => ({
42
- address: index + 1,
43
- init: `DO_${index + 1}`,
44
- name: `DO_${index + 1}`,
45
- editName: '',
46
- value: 0,
47
- isShow: true,
48
- type: 'Common',
49
- configurationStr: '',
50
- safeIOKey: 0
51
- }))
52
- },
53
- endEffectorIo: {
54
- input: [...Array(1)].map((item, index) => ({
55
- address: index + 17,
56
- init: `DI_${index + 1}`,
57
- name: `DI_${index + 1}`,
58
- editName: '',
59
- value: 1,
60
- isShow: true,
61
- diValue: 0,
62
- isDI: false
63
- })),
64
- output: [...Array(1)].map((item, index) => ({
65
- address: index + 17,
66
- init: `DO_${index + 1}`,
67
- name: `DO_${index + 1}`,
68
- editName: '',
69
- value: 1,
70
- isShow: true
71
- }))
72
- },
73
- isShowInputAll: true,
74
- isShowOutputAll: true,
75
- ioAO: [0, 0],
76
- ioAI: [0, 0],
77
- ioAIUnit: { mode1: 0, mode2: 0 },
78
- ioAOUnit: { mode1: 0, mode2: 0 },
79
- endAIUnit: { mode1: 0, mode2: 0, mode3: 0, mode4: 0 },
80
- endAI: [0, 0, 0, 0],
81
- toolMode: { mode1: 1, mode2: 1 },
82
- ioData: {}
83
- },
84
- pointData: [],
85
- jogInPaused: false
86
- }
87
-
88
- const toolReducer = (state = initialStore, action: { type: string; params: any }) => {
89
- switch (action.type) {
90
- case TOOL_ACTIONS_TYPE.SET_PORT_IP: {
91
- return Object.assign({}, state, {
92
- portData: {
93
- ip: action.params,
94
- port: state.portData.port,
95
- isSync: true
96
- }
97
- })
98
- }
99
- case TOOL_ACTIONS_TYPE.SET_PORT: {
100
- return Object.assign({}, state, {
101
- portData: {
102
- ip: state.portData.ip,
103
- port: action.params,
104
- isSync: true
105
- }
106
- })
107
- }
108
- case TOOL_ACTIONS_TYPE.SET_TCP_STATUS: {
109
- return Object.assign({}, state, { tcpStatus: action.params })
110
- }
111
- case TOOL_ACTIONS_TYPE.SET_TCP_INFO: {
112
- return Object.assign({}, state, { tcpInfo: action.params })
113
- }
114
- case TOOL_ACTIONS_TYPE.SET_EXTEND_IO_INDEX: {
115
- const newData = action.params.map((item: any) => {
116
- return {
117
- name: item.name,
118
- DONumber: item.doNumber,
119
- DOStart: item.doStart,
120
- DINumber: item.diNumber,
121
- DIStart: item.diStart
122
- }
123
- })
124
- return Object.assign({}, state, { extendIoData: newData })
125
- }
126
- case TOOL_ACTIONS_TYPE.SET_ONROBOT_TOOL: {
127
- return Object.assign({}, state, { onRobotTool: action.params })
128
- }
129
- case TOOL_ACTIONS_TYPE.SET_DEVICE_STATE_DATA: {
130
- return Object.assign({}, state, { deviceStateData: action.params })
131
- }
132
- case TOOL_ACTIONS_TYPE.SET_PLUGIN_PORT: {
133
- return Object.assign({}, state, { pluginPort: action.params })
134
- }
135
- case TOOL_ACTIONS_TYPE.SET_DOBOTPLUS_HOST:
136
- return Object.assign({}, state, { dobotplusHost: action.params })
137
- case TOOL_ACTIONS_TYPE.SET_IO_DATA: {
138
- return Object.assign({}, state, { deviceStateData: action.params })
139
- }
140
- case TOOL_ACTIONS_TYPE.SET_POINT_DATA:
141
- return Object.assign({}, state, { pointData: action.params })
142
- case TOOL_ACTIONS_TYPE.SET_JOG_IN_PAUSED:
143
- return Object.assign({}, state, { jogInPaused: action.params })
144
- default:
145
- return state
146
- }
147
- }
148
-
149
- export default toolReducer
@@ -1,35 +0,0 @@
1
- import { userMagamentActionsType } from '../actions/userMagamentActions'
2
- import { userMagamentState } from '@dobot/store/types'
3
-
4
- const initialStore: userMagamentState = {
5
- userModalData: {
6
- show: false
7
- },
8
- permissionList: [
9
- [1, 'TR_LEVEL_1'],
10
- [2, 'TR_LEVEL_2'],
11
- [3, 'TR_LEVEL_3']
12
- ],
13
- currentLevel: 0,
14
- currentUserInfo: ''
15
- }
16
- const userMagamentReducer = (state = initialStore, action: { type: string; params: any }) => {
17
- switch (action.type) {
18
- case userMagamentActionsType.SETUSERMODALDATA: {
19
- return Object.assign({}, state, { userModalData: action.params })
20
- }
21
- case userMagamentActionsType.SET_PERMISSIONLIST: {
22
- return Object.assign({}, state, { permissionList: action.params })
23
- }
24
- case userMagamentActionsType.SET_CURRENT_LEVEL: {
25
- return Object.assign({}, state, { currentLevel: action.params })
26
- }
27
- case userMagamentActionsType.SET_CURRENT_USER_INFO: {
28
- return Object.assign({}, state, { currentUserInfo: action.params })
29
- }
30
- default:
31
- return state
32
- }
33
- }
34
-
35
- export default userMagamentReducer