App.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <div id="app">
  3. <!-- <router-view /> -->
  4. <router-view v-if="isRouterAlive"></router-view>
  5. <div v-if="showAlarmBox" class="alarm_box">
  6. <i class="el-icon-close" @click="closeAlarmBox"></i>
  7. <el-carousel :interval="3000" :autoplay="true" indicator-position="outside">
  8. <el-carousel-item v-for="(item,keys) in alarmData" :key="keys">
  9. <!-- {{keys}} -->
  10. <div :class=" 'student_'+keys" >
  11. <div class="student_box">
  12. <div class="student_info">
  13. <span class="student_info_title"><b>设备信息:</b></span>
  14. <span class="student_name">
  15. <font class="student_name_label">设 备 名 称 :</font>
  16. <font class="student_name_value">{{item.realname}}</font>
  17. </span>
  18. <span class="student_urgent">
  19. <font class="student_name_label">设 备 编 号 :</font>
  20. <font class="student_name_value">{{item.device_number}}</font>
  21. </span>
  22. <span class="student_urgent">
  23. <font class="student_name_label">告 警 类 型 :</font>
  24. <font class="student_name_value">异常离线</font>
  25. </span>
  26. <!-- <span class="student_urgent">
  27. <font class="student_name_label">家 长 电 话 :</font>
  28. <font class="student_urgent_value" >
  29. <el-tooltip class="item" effect="dark" :content="item.parent_phone" placement="top">
  30. <span class="scroll_title" v-text="item.parent_phone"></span>
  31. </el-tooltip>
  32. </font>
  33. </span> -->
  34. <!-- <span class="student_urgent" >
  35. <font class="student_name_label" > 紧急联系人:</font>
  36. <font class="student_urgent_value" >
  37. <el-tooltip class="item" effect="dark" :content="item.urgent_text" placement="top">
  38. <span class="scroll_title" v-text="item.urgent_text"></span>
  39. </el-tooltip>
  40. </font>
  41. </span> -->
  42. </div>
  43. <div class="student_image">
  44. <img v-if="item.avatar" :src="item.avatar" class="avatar_image">
  45. <img v-else src="/images/device1.jpg" class="avatar_image">
  46. </div>
  47. </div>
  48. <div class="location_info">
  49. <span class="student_info_title"><b>位置信息:</b></span>
  50. 定位地址:<span class="location_address">{{item.address}}</span><br>
  51. 告警时间:<span class="location_time">{{item.alarm_time}}</span><br>
  52. </div>
  53. </div>
  54. <div class="handle_box">
  55. <el-button type="danger" size="medium" @click="handleAlarm(item.device_number)">前往处理</el-button>
  56. <!-- <el-button type="danger" size="medium" @click="showRfidRoute(item.device_number)">RFID轨迹</el-button> -->
  57. <!-- <el-button type="danger" size="medium" @click="showGpsRoute(item.device_number)">查看轨迹</el-button> -->
  58. <el-button type="danger" size="medium" @click="showGpsLocation(item.device_number)">查看位置</el-button>
  59. <!-- <el-button type="danger" v-if="item.station_type == 3" size="medium" @click="showRoomAddress(item.station_mac,item.device_number)">室内定位</el-button> -->
  60. </div>
  61. </el-carousel-item>
  62. </el-carousel>
  63. <rfid-dialog
  64. v-if="formVisible"
  65. :displayVisible="formVisible"
  66. @formCancel="closeDialog"
  67. :activeRfid="currentActiveRfid"
  68. />
  69. <gps-dialog
  70. v-if="gpsFormVisible"
  71. :displayVisible="gpsFormVisible"
  72. @formCancel="closeGpsDialog"
  73. :activeRfid="currentActiveRfid"
  74. />
  75. <!-- 楼层平面图 -->
  76. <!-- <el-dialog :title="currentBuildingInfo.name" fullscreen :visible.sync="visibleFloorMap">
  77. <floor-map ref="floor_map" :buildingId="currentBuildingInfo.id" :studentId="currentStudentInfo.id" />
  78. </el-dialog> -->
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import rfidDialog from "./views/map/rfidRouteDialog";
  84. import gpsDialog from "./views/map/gpsRouteDialog";
  85. // import FloorMap from './views/building/floor/map';
  86. const ReconnectingWebSocket = require('@/components/webSocket/reconnecting-websocket.js')
  87. export default {
  88. name: "App",
  89. components:{rfidDialog,gpsDialog},
  90. provide (){
  91. return {
  92. reload:this.reload,
  93. closeAlarmNotice:this.closeAlarmNotice,
  94. startWebSocket:this.startWebSocket
  95. }
  96. },
  97. data(){
  98. return{
  99. isRouterAlive:true,
  100. showAlarmBox:false,
  101. alarmData:{
  102. '1':{
  103. 'realname':'测试',
  104. 'device_number':'0000001',
  105. 'urgent_text':'15706857065',
  106. 'address':'滨江区华城何瑞科技广场S2',
  107. 'alarm_time':'2022-03-04 11:30:35',
  108. }
  109. },
  110. currentActiveRfid:'',
  111. formVisible:false,
  112. gpsFormVisible:false,
  113. currentBuildingInfo: {}, // 当前建筑信息
  114. currentStudentInfo:{},
  115. visibleFloorMap: false, // 显示楼层平面图
  116. }
  117. },
  118. created() {
  119. // console.log(">>>>> app.vue created");
  120. // if (!this.$socket.connected && this.$store.getters.token) {
  121. // //console.log('token:',this.$store.getters.token)
  122. // console.log(">>>>> app.vue socket open");
  123. // this.$socket.io.opts.query = {
  124. // loginToken: this.$store.getters.token,
  125. // userId: this.$store.getters.user_id
  126. // };
  127. // this.$socket.open(); // 开始连接socket
  128. // }
  129. let number=0
  130. var that = this;
  131. let s=Math.round(Math.random()*300)
  132. // this.timer = setInterval(() => {
  133. // number++
  134. // if(number==s){
  135. // number=0
  136. // s=Math.round(Math.random()*300)
  137. // that.showAlarmBox=true
  138. // }
  139. // }, 1000)
  140. },
  141. methods:{
  142. fn() {
  143. let s=Math.round(Math.random()*10) *1000
  144. if(this.set1){
  145. clearInterval(set1);
  146. }
  147. // if (t > 0) {
  148. set1 = setInterval(fn, s);
  149. // }
  150. },
  151. reload(){
  152. this.isRouterAlive=false;
  153. this.$nextTick(() => {
  154. this.isRouterAlive=true;
  155. })
  156. },
  157. startWebSocket(){
  158. // console.log(this.$store.getters)
  159. // let ws = new WebSocket('ws://116.62.220.88:60002')
  160. let ws = new ReconnectingWebSocket(this.$appConfig.websocketUrl)
  161. ws.onopen = () => {
  162. // Web Socket 已连接上,使用 send() 方法发送数据
  163. var _this=this
  164. this.timer=setInterval(function(){
  165. var timestamp = new Date().getTime();
  166. var msg = {
  167. 'type': 1,
  168. 'message':{'userid':_this.$store.getters.user_id},
  169. 'time': timestamp
  170. };
  171. console.log(JSON.stringify(msg));
  172. ws.send(JSON.stringify(msg))
  173. }, 20000);
  174. }
  175. ws.onmessage = evt => {
  176. var resp = JSON.parse(evt.data);
  177. console.log(resp.message);
  178. this.showAlarmBox=true
  179. let key=resp.message.device_number
  180. this.alarmData[key]=resp.message
  181. // console.log( "Received Message: " + evt.data);
  182. }
  183. ws.onclose = function () {
  184. // 关闭 websocket
  185. console.log('连接已关闭...')
  186. }
  187. },
  188. closeAlarmNotice(){
  189. if (this.timer) {
  190. clearInterval(this.timer); // 在Vue实例销毁前,清除我们的定时器
  191. }
  192. this.alarmData={}
  193. this.showAlarmBox=false
  194. },
  195. closeAlarmBox(){
  196. this.showAlarmBox=false
  197. },
  198. handleAlarm(device_number){
  199. // const query = {device_number:device_number}
  200. // this.$http.post('AlarmRecords', query).then(response => {
  201. // if(response.message=='success'){
  202. // this.alarmData={}
  203. let newAlarmData={}
  204. Object.keys(this.alarmData).forEach((k) => {
  205. if(k!=device_number){
  206. newAlarmData[k]=this.alarmData[k]
  207. }
  208. })
  209. this.alarmData=newAlarmData
  210. // delete this.alarmData[device_number]
  211. let alarmKeys = Object.keys(this.alarmData);
  212. if(alarmKeys.length<1){
  213. this.showAlarmBox=false
  214. }
  215. // }
  216. // this.$router.push({ path:'/alarm/AlarmRecords' })
  217. this.$router.push({ path:'/alarm/alarmDevice' })
  218. // })
  219. },
  220. showRfidRoute(val){
  221. this.currentActiveRfid=val
  222. this.formVisible=true
  223. },
  224. showGpsRoute(val){
  225. this.currentActiveRfid=val
  226. this.gpsFormVisible=true
  227. },
  228. closeDialog() {
  229. this.formVisible = false // 控制dialog弹框的不显示
  230. },
  231. closeGpsDialog(){
  232. this.gpsFormVisible=false
  233. },
  234. showRoomAddress(station_mac,device_number){
  235. const query={station_mac:station_mac,device_number:device_number}
  236. this.$http.get('map/queryBuildingInfo', {params: query}).then(resp => {
  237. this.currentBuildingInfo = resp.data.build_info
  238. this.currentStudentInfo= resp.data.student_info
  239. this.visibleFloorMap = true;
  240. })
  241. },
  242. showGpsLocation(device_number){
  243. // const query = {device_number:device_number}
  244. // this.$http.post('AlarmRecords', query).then(response => {
  245. this.$router.push({ path:'/map/routemap',query:{device_number}})
  246. // })
  247. },
  248. },
  249. };
  250. </script>
  251. <style lang="scss">
  252. // 谷歌浏览器
  253. /* 这是针对缺省样式 (必须的) */
  254. ::-webkit-scrollbar {
  255. width: 5px;
  256. height: 5px;
  257. }
  258. /* 滑块颜色 */
  259. ::-webkit-scrollbar-thumb {
  260. background-color: #354059;
  261. }
  262. // firefox浏览器
  263. #app {
  264. scrollbar-color:rgba(0, 0, 0, 0.2);
  265. scrollbar-width:thin;
  266. }
  267. .el-tooltip__popper {
  268. z-index:3000 !important;
  269. max-width:600px !important;
  270. }
  271. .el-date-range-picker{
  272. z-index: 3999 !important;
  273. }
  274. .el-notification__content {
  275. max-height: 50vh;
  276. overflow: auto;
  277. }
  278. </style>
  279. <style lang="scss" scoped>
  280. .alarm_box{
  281. padding: 16px;
  282. z-index:3000;
  283. position:fixed;
  284. right:0;
  285. bottom:0;
  286. width:450px;
  287. height:300px;
  288. background-color:#00bcd4;
  289. border-radius: 5px;
  290. color:#FFF;
  291. }
  292. .student_box{
  293. text-align:left;
  294. font-size:18px;
  295. height: 110px;
  296. }
  297. .student_info{
  298. width: 70%;
  299. float: left;
  300. }
  301. .student_info_title{
  302. font-size:18px;
  303. margin-bottom: 10px;
  304. display:block;
  305. }
  306. .student_name{
  307. width:100%;
  308. display:block;
  309. }
  310. .student_name_label{
  311. display:inline-block;
  312. width:35%;
  313. }
  314. .student_name_value{
  315. display:inline-block;
  316. width:65%;
  317. }
  318. .student_urgent{
  319. display:block;
  320. width:100%;
  321. }
  322. .student_urgent_value{
  323. display:inline-block;
  324. width:65%;
  325. white-space:nowrap;
  326. word-break:keep-all;
  327. overflow:hidden;
  328. }
  329. .scroll_title{
  330. // display:inline-block;
  331. width:100%;
  332. height:100%;
  333. display:flex;align-items:flex-end;
  334. }
  335. .student_image{
  336. width: 120px;
  337. float: right;
  338. height: 120px;
  339. overflow: hidden;
  340. }
  341. .avatar_image{
  342. width: 100%;
  343. right: 100px;
  344. }
  345. .location_info{
  346. text-align:left;
  347. font-size:18px;
  348. height: 105px;
  349. margin-top: 10px;
  350. padding-top:10px;
  351. padding-right:20px;
  352. }
  353. .handle_box{
  354. text-align:center;
  355. font-size:20px;
  356. }
  357. ::v-deep .el-carousel__item{
  358. background-color: #00bcd4 !important;
  359. }
  360. .el-icon-close{
  361. float: right;
  362. color: #FFF;
  363. margin-top:-16px;
  364. margin-right:-10px;
  365. right:0px;
  366. }
  367. .el-carousel__item h3 {
  368. color: #475669;
  369. font-size: 18px;
  370. opacity: 0.75;
  371. line-height: 300px;
  372. margin: 0;
  373. }
  374. .el-carousel__item:nth-child(2n) {
  375. background-color: #d3dce6;
  376. }
  377. .el-carousel__item:nth-child(2n+1) {
  378. background-color: #d3dce6;
  379. }
  380. .app-container {
  381. height: calc(100vh - 102px);
  382. // ::v-deep .el-dialog__body {
  383. .el-dialog__body {
  384. padding: 0;
  385. }
  386. }
  387. </style>