Commit 7ed4003b authored by Administrator's avatar Administrator
parents aafdbced 38d9dacc
...@@ -68,16 +68,13 @@ class alarm extends Command ...@@ -68,16 +68,13 @@ class alarm extends Command
$this->ws->on('open', function ($ws, $request) { $this->ws->on('open', function ($ws, $request) {
// //链接成功 // //链接成功
$userdata = new SwooleCommandController(); $userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->alarm(),1); // $this->ws->push($request->fd,'11',1);
swoole_timer_tick(6000, function($timerId) use ($ws, $request) {
$userdata = new SwooleCommandController();
$this->ws->push($request->fd,$userdata->alarm(),1);
});
}); });
//监听WebSocket消息事件 //监听WebSocket消息事件
$this->ws->on('message', function ($ws, $frame) { $this->ws->on('message', function ($ws, $frame) {
$userdata = new SwooleCommandController();
$this->ws->push($frame->fd,$userdata->alarm($frame->data),1);
}); });
$this->ws->on('request', function ($request, $response,$from_id,$fd) { $this->ws->on('request', function ($request, $response,$from_id,$fd) {
......
...@@ -62,10 +62,10 @@ class SwooleCommandController extends Controller ...@@ -62,10 +62,10 @@ class SwooleCommandController extends Controller
//监测是否设备报警 //监测是否设备报警
public function alarm() public function alarm($id)
{ {
$isadmin = DB::table('config')->first(); $isadmin = DB::table('users')->where('id','=',$id)->value('isadmin');
if (is_null($isadmin)) { if ($isadmin == 1) {
$isalarm = DB::table('reportpolice') $isalarm = DB::table('reportpolice')
->where('status', '=', '1') ->where('status', '=', '1')
->where('police', '=', '1') ->where('police', '=', '1')
...@@ -73,21 +73,19 @@ class SwooleCommandController extends Controller ...@@ -73,21 +73,19 @@ class SwooleCommandController extends Controller
->select('devicenumber') ->select('devicenumber')
->get()->toArray(); ->get()->toArray();
} else { } else {
$uid = get_object_vars($isadmin)['uid'];
$isalarm = DB::table('reportpolice') $isalarm = DB::table('reportpolice')
->join('device as d','reportpolice.devicenumber','=','d.devicenum') ->join('device as d','reportpolice.devicenumber','=','d.devicenum')
->where('reportpolice.status', '=', '1') ->where('reportpolice.status', '=', '1')
->where('reportpolice.police', '=', '1') ->where('reportpolice.police', '=', '1')
->where('d.uid', '=', $uid) ->where('d.uid', '=', $isadmin)
->groupBy('reportpolice.id') ->groupBy('reportpolice.id')
->select('reportpolice.devicenumber') ->select('reportpolice.devicenumber')
->get()->toArray(); ->get()->toArray();
} }
if ($isalarm) { if ($isalarm) {
return $this->jsonSuccessData($isalarm); return $this->jsonSuccessData($isalarm);
} else { } else {
return $this->jsonErrorData(105, '当前无报警'); return $this->jsonErrorData(105, '当前无报警');
} }
} }
} }
\ No newline at end of file
...@@ -73,8 +73,7 @@ class AuthController extends Controller ...@@ -73,8 +73,7 @@ class AuthController extends Controller
} }
public function logout(Request $request) public function logout(Request $request)
{ {
$config = DB::table('config'); $delectuser = \Session::forget('loginuid');
$delectuser = $config->where('uid','=',Auth::id())->delete();
if($delectuser){ if($delectuser){
$request->user()->token()->revoke(); $request->user()->token()->revoke();
return response()->json((new JsonResponse())->success([]), Response::HTTP_OK); return response()->json((new JsonResponse())->success([]), Response::HTTP_OK);
......
...@@ -488,7 +488,34 @@ class DevicesController extends Controller ...@@ -488,7 +488,34 @@ class DevicesController extends Controller
->count(); ->count();
return $this->jsonSuccessData(['devicelist' => $devicelist, 'count' => $count]); return $this->jsonSuccessData(['devicelist' => $devicelist, 'count' => $count]);
} }
public function devicepolice(Request $request)
{
$devicenum = $request->input('devicenum');
if ($devicenum) {
$police = DB::table('reportpolice')->where('devicenumber','=',$devicenum)->update(['police'=>2]);
$this->jsonSuccessData($police);
}else{
return $this->jsonErrorData(105,'设备编号不能为空');
}
}
public function devicepoliceinfo(Request $request){
$devicenum = $request->input('devicenum');
if ($devicenum) {
$data = DB::table('device as d')
->join('device_type as t','d.dtype','=','t.tid')
->join('gas as g','d.status','=','g.id')
->join('status as s','d.devicepolice','=','s.id')
->join('danwei as w','d.devicemonad','=','w.id')
->join('users as u','d.uid','=','u.id')
->join('reportpolice as r','d.devicenum','=','r.devicenumber')
->where('d.devicenum','=',$devicenum)
->select('d.devicenum','d.username','d.nd','d.deviceremark','d.devicecoord','d.deviceaddtime','d.devicestatus','t.tname','g.gas','s.status_name','w.danwei','u.name','u.email','r.location','r.concentration','r.starttime')
->first();
return $this->jsonSuccessData($data);
}else{
return $this->jsonErrorData(105,'设备编号不能为空');
}
}
/** /**
* @param bool $isNew * @param bool $isNew
* @return array * @return array
......
...@@ -81,11 +81,8 @@ class HomepageController extends Controller ...@@ -81,11 +81,8 @@ class HomepageController extends Controller
//返回一年当前月份 //返回一年当前月份
public function userdevicemonthcount(Request $request) public function userdevicemonthcount(Request $request)
{ {
$config = DB::table('config'); \Session::put(['loginuid' => Auth::id()]);
$user = $config->where('uid','=',Auth::id())->first(); dd(\Session::get('loginuid'));
if(!$user){
$config ->insertGetId(['uid'=>Auth::id(),'userinfo'=>Auth::user(),'upde_time'=>time()]);
}
$year_start = strtotime(date("Y") . "-01-01"); // 获取当前的1月份的时间戳 $year_start = strtotime(date("Y") . "-01-01"); // 获取当前的1月份的时间戳
$endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y')); //获取当月的时间戳 $endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y')); //获取当月的时间戳
$devicedata = Device::where('uid','=',Auth::id())->whereBetween('deviceaddtime', [$year_start, $endThismonth]) $devicedata = Device::where('uid','=',Auth::id())->whereBetween('deviceaddtime', [$year_start, $endThismonth])
......
...@@ -151,3 +151,17 @@ export function updedata(data) { ...@@ -151,3 +151,17 @@ export function updedata(data) {
data, data,
}); });
} }
export function devicepolice(devicenum) {
return request({
url: '/devices/devicepolice?devicenum=' + devicenum,
method: 'get',
});
}
export function devicepoliceinfo(devicenum) {
return request({
url: '/devices/devicepoliceinfo?devicenum=' + devicenum,
method: 'get',
});
}
...@@ -80,6 +80,7 @@ export default { ...@@ -80,6 +80,7 @@ export default {
}, },
async logout() { async logout() {
await this.$store.dispatch('user/logout'); await this.$store.dispatch('user/logout');
localStorage.removeItem('userinfoid');
this.$notify.closeAll(); this.$notify.closeAll();
this.$router.go(0); this.$router.go(0);
this.$router.push(`/login?redirect=${this.$route.fullPath}`); this.$router.push(`/login?redirect=${this.$route.fullPath}`);
......
...@@ -31,6 +31,46 @@ ...@@ -31,6 +31,46 @@
{{ $t('tagsView.closeAll') }} {{ $t('tagsView.closeAll') }}
</li> </li>
</ul> </ul>
<el-dialog title="报警详情" :visible.sync="dialogTableVisible">
<el-form ref="form" label-width="80px">
<el-form-item label="设备编号">
<span>{{ gridData.devicenum }}</span>
</el-form-item>
<el-form-item label="设备名称">
<span>{{ gridData.username }}</span>
</el-form-item>
<el-form-item label="用户名称">
<span>{{ gridData.name }}</span>
</el-form-item>
<el-form-item label="用户邮箱">
<span>{{ gridData.email }}</span>
</el-form-item>
<el-form-item label="设备类型">
<span>{{ gridData.tname }}</span>
</el-form-item>
<el-form-item label="设备单位浓度" label-width="100px">
<span>{{ gridData.gas }}/{{ gridData.concentration }}{{ gridData.danwei }}</span>
</el-form-item>
<el-form-item label="设备报警开始时间" label-width="130px">
<span>{{ gridData.starttime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
</el-form-item>
<el-form-item label="报警位置">
<span>{{ gridData.location }}</span>
</el-form-item>
<el-form-item label="设备坐标">
<span>{{ gridData.devicecoord }}</span>
</el-form-item>
<el-form-item label="设备备注">
<span>{{ gridData.deviceremark }}</span>
</el-form-item>
<el-form-item label="添加时间">
<span>{{ gridData.deviceaddtime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
</el-form-item>
<el-form-item label="设备报警状态" label-width="100px">
<span>{{ gridData.status_name }}</span>
</el-form-item>
</el-form>
</el-dialog>
</div> </div>
</template> </template>
...@@ -39,14 +79,19 @@ import ScrollPane from './ScrollPane'; ...@@ -39,14 +79,19 @@ import ScrollPane from './ScrollPane';
import { generateTitle } from '@/utils/i18n'; import { generateTitle } from '@/utils/i18n';
import path from 'path'; import path from 'path';
import websocketurl from '@/api/configurl'; import websocketurl from '@/api/configurl';
import { devicepolice, devicepoliceinfo } from '@/api/device';
export default { export default {
components: { ScrollPane }, components: { ScrollPane },
data() { data() {
return { return {
visible: false, visible: false,
top: 0, top: 0,
tableKey: 0,
dialogTableVisible: false,
left: 0, left: 0,
timer: '',
selectedTag: {}, selectedTag: {},
gridData: [],
affixTags: [], affixTags: [],
}; };
}, },
...@@ -131,6 +176,9 @@ export default { ...@@ -131,6 +176,9 @@ export default {
}, },
websocketonopen(){ // 连接建立之后执行send方法发送数据 websocketonopen(){ // 连接建立之后执行send方法发送数据
console.log('连接成功'); console.log('连接成功');
this.timer = setInterval(() => {
this.websocketsend();
}, 5000);
}, },
websocketonerror(){ // 连接建立失败重连 websocketonerror(){ // 连接建立失败重连
this.$notify({ this.$notify({
...@@ -141,6 +189,7 @@ export default { ...@@ -141,6 +189,7 @@ export default {
this.initWebSocket(); this.initWebSocket();
}, },
websocketonmessage(e){ // 数据接收 websocketonmessage(e){ // 数据接收
const that = this;
const redata = JSON.parse(e.data); const redata = JSON.parse(e.data);
if (redata.code === 200) { if (redata.code === 200) {
if (localStorage.getItem('isalam') === null || localStorage.getItem('isalam') === undefined) { // 第一次没有的话 if (localStorage.getItem('isalam') === null || localStorage.getItem('isalam') === undefined) { // 第一次没有的话
...@@ -153,6 +202,23 @@ export default { ...@@ -153,6 +202,23 @@ export default {
duration: 0, duration: 0,
message: redata.data[i].devicenumber + '正在报警请尽快处理', message: redata.data[i].devicenumber + '正在报警请尽快处理',
onClose: function(){ onClose: function(){
devicepolice(redata.data[i].devicenumber)
.then(response => {
localStorage.removeItem('isalam');
})
.catch(err => {
console.log(err);
});
},
onClick: function(){
devicepoliceinfo(redata.data[i].devicenumber)
.then(response => {
that.gridData = response.data;
that.dialogTableVisible = true;
})
.catch(err => {
console.log(err);
});
}, },
}); });
}, 3); }, 3);
...@@ -167,7 +233,23 @@ export default { ...@@ -167,7 +233,23 @@ export default {
duration: 0, duration: 0,
message: redata.data[j].devicenumber + '正在报警请尽快处理', message: redata.data[j].devicenumber + '正在报警请尽快处理',
onClose: function(){ onClose: function(){
console.log(redata.data[j].devicenumber); devicepolice(redata.data[j].devicenumber)
.then(response => {
localStorage.removeItem('isalam');
})
.catch(err => {
console.log(err);
});
},
onClick: function(){
devicepoliceinfo(redata.data[j].devicenumber)
.then(response => {
that.gridData = response.data;
that.dialogTableVisible = true;
})
.catch(err => {
console.log(err);
});
}, },
}); });
}, 3); }, 3);
...@@ -180,8 +262,11 @@ export default { ...@@ -180,8 +262,11 @@ export default {
beforeun(e) { beforeun(e) {
localStorage.removeItem('isalam'); localStorage.removeItem('isalam');
}, },
closeAlls() {
this.$notify.closeAll();
},
websocketsend(){ // 数据发送 websocketsend(){ // 数据发送
this.websock.send(JSON.stringify(this.type)); this.websock.send(localStorage.getItem('userinfoid'));
}, },
websocketclose(e){ // 关闭 websocketclose(e){ // 关闭
console.log('断开连接', e); console.log('断开连接', e);
...@@ -190,6 +275,7 @@ export default { ...@@ -190,6 +275,7 @@ export default {
message: '监测报警长连接已断开', message: '监测报警长连接已断开',
type: 'warning', type: 'warning',
}); });
clearInterval(this.timer);
}, },
isarray(needle, arr) { // data长连接返回 adata本地储 isarray(needle, arr) { // data长连接返回 adata本地储
var has = false; var has = false;
......
...@@ -45,6 +45,7 @@ const actions = { ...@@ -45,6 +45,7 @@ const actions = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login({ email: email.trim(), password: password, userOrAdmin: userOrAdmin }) login({ email: email.trim(), password: password, userOrAdmin: userOrAdmin })
.then(response => { .then(response => {
localStorage.setItem('userinfoid', response.id);
commit('SET_TOKEN', response.token); commit('SET_TOKEN', response.token);
setToken(response.token); setToken(response.token);
resolve(); resolve();
......
...@@ -210,6 +210,7 @@ export default { ...@@ -210,6 +210,7 @@ export default {
this.$store.dispatch('user/login', this.userloginForm) this.$store.dispatch('user/login', this.userloginForm)
.then(() => { .then(() => {
this.$router.push({ path: '/' }); this.$router.push({ path: '/' });
localStorage.removeItem('isalam');
this.loading = false; this.loading = false;
}) })
.catch(() => { .catch(() => {
......
...@@ -100,7 +100,8 @@ Route::group(['middleware'=>'auth:api'],function (){ ...@@ -100,7 +100,8 @@ Route::group(['middleware'=>'auth:api'],function (){
Route::get('devices/control','DevicesController@control');//返回消防监测 Route::get('devices/control','DevicesController@control');//返回消防监测
Route::get('devices/deviceLocation','DevicesController@deviceLocation');//返回设备安装位置 Route::get('devices/deviceLocation','DevicesController@deviceLocation');//返回设备安装位置
Route::get('devices/device_info/{id}','DevicesController@device_info');//返回设备地图详情信息 Route::get('devices/device_info/{id}','DevicesController@device_info');//返回设备地图详情信息
Route::get('devices/UseridOrdeviceInfo','DevicesController@UseridOrdeviceInfo');//用户测试接口 Route::get('devices/devicepolice','DevicesController@devicepolice');//设备消警
Route::get('devices/devicepoliceinfo','DevicesController@devicepoliceinfo');//设备报警弹窗详情
}); });
//装维中心 //装维中心
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment