Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wisdom-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
wisdom-components
Commits
9a2c6e24
Commit
9a2c6e24
authored
Mar 12, 2025
by
李纪文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: mqttview推送数据非json容错处理
parent
4955a6f3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
17 deletions
+21
-17
index.js
packages/base-components/MqttView/src/index.js
+21
-17
No files found.
packages/base-components/MqttView/src/index.js
View file @
9a2c6e24
...
@@ -74,7 +74,7 @@ class MqttView {
...
@@ -74,7 +74,7 @@ class MqttView {
this
.
flag
=
true
;
this
.
flag
=
true
;
this
.
devices
.
forEach
((
item
)
=>
{
this
.
devices
.
forEach
((
item
)
=>
{
if
(
item
)
{
if
(
item
)
{
var
saveWaTopic
=
this
.
siteCode
+
'/'
+
item
.
replace
(
/
[
#+
]
/g
,
'@'
);
const
saveWaTopic
=
this
.
siteCode
+
'/'
+
item
.
replace
(
/
[
#+
]
/g
,
'@'
);
this
.
saveWaClient
.
subscribe
(
saveWaTopic
);
this
.
saveWaClient
.
subscribe
(
saveWaTopic
);
}
}
});
});
...
@@ -88,7 +88,7 @@ class MqttView {
...
@@ -88,7 +88,7 @@ class MqttView {
this
.
isAlarm
&&
this
.
isAlarm
&&
this
.
devices
.
forEach
((
item
)
=>
{
this
.
devices
.
forEach
((
item
)
=>
{
if
(
item
)
{
if
(
item
)
{
var
saveWaTopic
=
this
.
siteCode
+
'/'
+
item
.
replace
(
/
[
#+
]
/g
,
'@'
)
+
'/alarm'
+
'/#'
;
const
saveWaTopic
=
this
.
siteCode
+
'/'
+
item
.
replace
(
/
[
#+
]
/g
,
'@'
)
+
'/alarm'
+
'/#'
;
this
.
saveWaClient
.
subscribe
(
saveWaTopic
);
this
.
saveWaClient
.
subscribe
(
saveWaTopic
);
}
}
});
});
...
@@ -122,18 +122,22 @@ class MqttView {
...
@@ -122,18 +122,22 @@ class MqttView {
//消息接收(控制和订阅)
//消息接收(控制和订阅)
onMessageArrived
(
message
,
infoType
)
{
onMessageArrived
(
message
,
infoType
)
{
var
topic
=
message
.
topic
;
try
{
var
code
=
topic
.
split
(
'/'
)[
topic
.
split
(
'/'
).
length
-
1
];
const
topic
=
message
.
topic
;
if
(
topic
.
indexOf
(
'callback/control/'
+
this
.
siteCode
)
>
-
1
)
{
const
code
=
topic
.
split
(
'/'
)[
topic
.
split
(
'/'
).
length
-
1
];
this
.
controlback
(
message
.
payloadString
,
code
,
topic
);
if
(
!
message
?.
payloadString
)
return
false
;
return
false
;
const
payloadString
=
JSON
.
stringify
(
JSON
.
parse
(
message
.
payloadString
));
}
if
(
topic
.
indexOf
(
'callback/control/'
+
this
.
siteCode
)
>
-
1
)
{
if
(
topic
.
indexOf
(
'alarm'
)
>
-
1
)
{
this
.
controlback
(
payloadString
,
code
,
topic
);
var
alarmCode
=
topic
.
split
(
'/'
)[
1
];
return
false
;
this
.
alarmback
(
message
.
payloadString
,
alarmCode
,
topic
);
}
return
false
;
if
(
topic
.
indexOf
(
'alarm'
)
>
-
1
)
{
}
const
alarmCode
=
topic
.
split
(
'/'
)[
1
];
this
.
callback
(
message
.
payloadString
,
code
,
topic
);
this
.
alarmback
(
payloadString
,
alarmCode
,
topic
);
return
false
;
}
this
.
callback
(
payloadString
,
code
,
topic
);
}
catch
(
err
)
{}
}
}
//消息发送
//消息发送
...
@@ -147,7 +151,7 @@ class MqttView {
...
@@ -147,7 +151,7 @@ class MqttView {
val
,
val
,
controlMode
,
controlMode
,
)
{
)
{
var
info
=
{
const
info
=
{
userName
:
userName
,
userName
:
userName
,
password
:
password
,
password
:
password
,
callbackGuid
:
callbackGuid
,
callbackGuid
:
callbackGuid
,
...
@@ -159,7 +163,7 @@ class MqttView {
...
@@ -159,7 +163,7 @@ class MqttView {
controlMode
:
controlMode
?
controlMode
:
''
,
controlMode
:
controlMode
?
controlMode
:
''
,
tag
:
tag
,
tag
:
tag
,
};
};
var
message
=
new
MqttClient
.
Message
(
JSON
.
stringify
(
info
));
let
message
=
new
MqttClient
.
Message
(
JSON
.
stringify
(
info
));
message
.
destinationName
=
'setdata/'
+
this
.
siteCode
+
'/'
+
devicecode
;
message
.
destinationName
=
'setdata/'
+
this
.
siteCode
+
'/'
+
devicecode
;
this
.
saveWaClient
.
send
(
message
);
this
.
saveWaClient
.
send
(
message
);
}
}
...
@@ -168,7 +172,7 @@ class MqttView {
...
@@ -168,7 +172,7 @@ class MqttView {
createGuid
()
{
createGuid
()
{
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.
replace
(
/
[
xy
]
/g
,
function
(
c
)
{
.
replace
(
/
[
xy
]
/g
,
function
(
c
)
{
var
r
=
(
Math
.
random
()
*
16
)
|
0
,
const
r
=
(
Math
.
random
()
*
16
)
|
0
,
v
=
c
==
'x'
?
r
:
(
r
&
0x3
)
|
0x8
;
v
=
c
==
'x'
?
r
:
(
r
&
0x3
)
|
0x8
;
return
v
.
toString
(
16
);
return
v
.
toString
(
16
);
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment