Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
laravelzh
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
冯超鹏
laravelzh
Commits
3082cb42
Commit
3082cb42
authored
Jul 01, 2020
by
冯超鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交长连接设备监测模块
parent
606f7980
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
33 deletions
+110
-33
swoole.php
app/Console/Commands/swoole.php
+1
-31
SwooleCommandController.php
app/Http/Controllers/Auth/SwooleCommandController.php
+31
-0
Controller.php
app/Http/Controllers/Controller.php
+0
-1
configurl.js
resources/js/api/configurl.js
+4
-0
chemicals.vue
resources/js/views/monitor/chemicals.vue
+37
-0
fire.vue
resources/js/views/monitor/fire.vue
+37
-0
userStatistics.vue
resources/js/views/user/userStatistics.vue
+0
-1
No files found.
app/Console/Commands/swoole.php
View file @
3082cb42
...
...
@@ -67,13 +67,6 @@ class swoole extends Command
));
$this
->
ws
->
on
(
'open'
,
function
(
$ws
,
$request
)
{
// //链接成功
// $data = [
// 'code' => 200,
// 'token' => md5($this->token),
// 'time' => date("Y-m-d H:i:s", time()),
// 'msg' => '连接成功'
// ];
// $this->ws->push(1, json_encode($data), 1);
$userdata
=
new
SwooleCommandController
();
$this
->
ws
->
push
(
$request
->
fd
,
$userdata
->
userslist
(),
1
);
swoole_timer_tick
(
6000
,
function
(
$timerId
)
use
(
$ws
,
$request
)
{
...
...
@@ -85,32 +78,9 @@ class swoole extends Command
//监听WebSocket消息事件
$this
->
ws
->
on
(
'message'
,
function
(
$ws
,
$frame
)
{
// $data = json_decode($frame->data, true);
// //监测是否是有效链接
// if($this->ws->isEstablished($frame->fd)){
// $ws->bind($frame->fd, $data['id']);
// $userdata = new SwooleCommandController();
// $this->ws->push($frame->fd,$userdata->userslist(),1);
// }else{
// Log::channel('single')->info('不是有效连接'. ','.'id=>'. $frame->fd);
// $this->ws->push($frame->fd, '不是有效连接', 1);
// $this->ws->disconnect($frame->fd, 105, '已断开连接,不是有效连接');
// }
//// $token = (string)$data['token'];
//// if ($token != md5($this->token)) {
//// Log::channel('single')->info('token错误'. ',' .'token=>'. $token . ',' . 'id=>' . $frame->fd);
//// $this->ws->push($frame->fd, 'token错误', 1);
//// $this->ws->disconnect($frame->fd, 105, '已断开连接,token错误');
//// } else {
//////
//// }
});
$this
->
ws
->
on
(
'request'
,
function
(
$request
,
$response
)
{
if
(
$request
->
post
[
'token'
]
==
"123"
)
{
echo
"123213"
;
$clients
=
$this
->
ws
->
getClientList
();
}
$this
->
ws
->
on
(
'request'
,
function
(
$request
,
$response
,
$from_id
,
$fd
)
{
});
//监听WebSocket连接关闭事件
$this
->
ws
->
on
(
'close'
,
function
(
$ws
,
$fd
)
{
...
...
app/Http/Controllers/Auth/SwooleCommandController.php
View file @
3082cb42
...
...
@@ -24,5 +24,36 @@ class SwooleCommandController extends Controller
$countdata
=
[
'usercount'
=>
$usercount
,
'userdata'
=>
$count
];
return
$this
->
jsonSuccessData
(
$countdata
);
}
public
function
chemicals
(){
$databadevice
=
DB
::
table
(
'device'
);
$devicelist
=
$databadevice
->
whereIn
(
'dtype'
,
[
1
,
5
,
10
])
->
leftjoin
(
'device_type as dy'
,
"device.dtype"
,
'='
,
'dy.tid'
)
->
leftjoin
(
'gas as g'
,
"device.status"
,
'='
,
'g.id'
)
->
leftjoin
(
'status as p'
,
"device.devicepolice"
,
'='
,
'p.id'
)
->
select
(
'dy.tname'
,
'g.gas'
,
'device.*'
,
'p.status_name'
)
->
orderBy
(
'device.id'
,
'desc'
)
->
get
()
->
toArray
();
$count
=
$databadevice
->
whereIn
(
'dtype'
,
[
1
,
5
,
10
])
->
count
();
return
$this
->
jsonSuccessData
([
'devicelist'
=>
$devicelist
,
'count'
=>
$count
]);
}
public
function
fire
(){
$databadevice
=
DB
::
table
(
'device'
);
$devicelist
=
$databadevice
->
whereIn
(
'dtype'
,
[
2
,
4
,
6
,
7
,
8
,
9
,
11
])
->
leftjoin
(
'device_type as dy'
,
"device.dtype"
,
'='
,
'dy.tid'
)
->
leftjoin
(
'gas as g'
,
"device.status"
,
'='
,
'g.id'
)
->
leftjoin
(
'status as p'
,
"device.devicepolice"
,
'='
,
'p.id'
)
->
select
(
'dy.tname'
,
'g.gas'
,
'device.*'
,
'p.status_name'
)
->
orderBy
(
'device.id'
,
'desc'
)
->
get
()
->
toArray
();
$count
=
$databadevice
->
whereIn
(
'dtype'
,
[
2
,
4
,
6
,
7
,
8
,
9
,
11
])
->
count
();
return
$this
->
jsonSuccessData
([
'devicelist'
=>
$devicelist
,
'count'
=>
$count
]);
}
}
\ No newline at end of file
app/Http/Controllers/Controller.php
View file @
3082cb42
...
...
@@ -68,7 +68,6 @@ class Controller extends BaseController
],
];
}
/*
* 验证当前登入用户
* */
...
...
resources/js/api/configurl.js
View file @
3082cb42
const
baseURL
=
'ws://127.0.0.1:9502'
;
const
chemicalsUrl
=
'ws://127.0.0.1:9507'
;
const
fireUrl
=
'ws://127.0.0.1:9508'
;
const
mapkey
=
'2719fe261fee06a08dcb4980990879da'
;
const
mapurl
=
'https://webapi.amap.com/maps?v=1.4.15&key='
;
export
default
{
baseURL
,
mapkey
,
mapurl
,
chemicalsUrl
,
fireUrl
,
};
resources/js/views/monitor/chemicals.vue
View file @
3082cb42
...
...
@@ -72,6 +72,7 @@
<
script
>
import
{
control
}
from
'@/api/device'
;
import
Pagination
from
'@/components/Pagination'
;
// 分页
import
websocketurl
from
'@/api/configurl'
;
import
clip
from
'@/utils/clipboard'
;
export
default
{
name
:
'Devicetype'
,
...
...
@@ -90,6 +91,7 @@ export default {
}
,
created
()
{
this
.
devicelist
();
// 设备状态
this
.
initWebSocket
();
}
,
methods
:
{
...
...
@@ -111,6 +113,41 @@ export default {
console
.
log
(
err
);
}
);
}
,
initWebSocket
(){
// 初始化weosocket
const
wsuri
=
websocketurl
.
chemicalsUrl
;
this
.
websock
=
new
WebSocket
(
wsuri
);
this
.
websock
.
onmessage
=
this
.
websocketonmessage
;
this
.
websock
.
onopen
=
this
.
websocketonopen
;
this
.
websock
.
onerror
=
this
.
websocketonerror
;
this
.
websock
.
onclose
=
this
.
websocketclose
;
}
,
websocketonopen
(){
// 连接建立之后执行send方法发送数据
console
.
log
(
'连接成功'
);
}
,
websocketonerror
(){
// 连接建立失败重连
this
.
$notify
({
title
:
'警告'
,
message
:
'建立链接失败,正在重连'
,
type
:
'warning'
,
}
);
this
.
initWebSocket
();
}
,
websocketonmessage
(
e
){
// 数据接收
const
redata
=
JSON
.
parse
(
e
.
data
);
this
.
device
=
redata
.
data
.
devicelist
;
this
.
total
=
redata
.
data
.
count
;
}
,
websocketsend
(){
// 数据发送
this
.
websock
.
send
(
JSON
.
stringify
(
this
.
type
));
}
,
websocketclose
(
e
){
// 关闭
console
.
log
(
'断开连接'
,
e
);
this
.
$notify
({
title
:
'警告'
,
message
:
'长连接已断开'
,
type
:
'warning'
,
}
);
}
,
handleClick
(
tab
)
{
this
.
type
=
tab
.
$attrs
.
tid
;
this
.
devicelist
();
...
...
resources/js/views/monitor/fire.vue
View file @
3082cb42
...
...
@@ -72,6 +72,7 @@
<
script
>
import
{
control
}
from
'@/api/device'
;
import
Pagination
from
'@/components/Pagination'
;
// 分页
import
websocketurl
from
'@/api/configurl'
;
import
clip
from
'@/utils/clipboard'
;
export
default
{
name
:
'Devicetype'
,
...
...
@@ -90,6 +91,7 @@ export default {
}
,
created
()
{
this
.
devicelist
();
// 设备状态
this
.
initWebSocket
();
}
,
methods
:
{
...
...
@@ -111,6 +113,41 @@ export default {
console
.
log
(
err
);
}
);
}
,
initWebSocket
(){
// 初始化weosocket
const
wsuri
=
websocketurl
.
fireUrl
;
this
.
websock
=
new
WebSocket
(
wsuri
);
this
.
websock
.
onmessage
=
this
.
websocketonmessage
;
this
.
websock
.
onopen
=
this
.
websocketonopen
;
this
.
websock
.
onerror
=
this
.
websocketonerror
;
this
.
websock
.
onclose
=
this
.
websocketclose
;
}
,
websocketonopen
(){
// 连接建立之后执行send方法发送数据
console
.
log
(
'连接成功'
);
}
,
websocketonerror
(){
// 连接建立失败重连
this
.
$notify
({
title
:
'警告'
,
message
:
'建立链接失败,正在重连'
,
type
:
'warning'
,
}
);
this
.
initWebSocket
();
}
,
websocketonmessage
(
e
){
// 数据接收
const
redata
=
JSON
.
parse
(
e
.
data
);
this
.
device
=
redata
.
data
.
devicelist
;
this
.
total
=
redata
.
data
.
count
;
}
,
websocketsend
(){
// 数据发送
this
.
websock
.
send
(
JSON
.
stringify
(
this
.
type
));
}
,
websocketclose
(
e
){
// 关闭
console
.
log
(
'断开连接'
,
e
);
this
.
$notify
({
title
:
'警告'
,
message
:
'长连接已断开'
,
type
:
'warning'
,
}
);
}
,
handleClick
(
tab
)
{
this
.
type
=
tab
.
$attrs
.
tid
;
this
.
devicelist
();
...
...
resources/js/views/user/userStatistics.vue
View file @
3082cb42
...
...
@@ -136,7 +136,6 @@ export default {
},
websocketonmessage
(
e
){
// 数据接收
const
redata
=
JSON
.
parse
(
e
.
data
);
this
.
type
.
token
=
redata
.
token
;
this
.
countdata
=
redata
.
data
.
userdata
;
this
.
devicenum
=
redata
.
data
.
usercount
;
},
...
...
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