var _this,ifRef,baseTok; var webSocket; var _timeId; new Vue({ el: '#app', data: function() { return { isCollapse: false, aidWid: '180px', ifSrc: 'P0', nowShip: {}, nowSn: "", shipLi: [], drawer: false, userForm:{ avatar:"/images/boy-01.png", nickName:"", roles: [{ roleName: "" }] }, routerLi: [] } }, created() { _this = this; baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : ""; _this.setRoter(); _this.checkTU(); _this.checkToken(); _this.SetHelemMsg(); }, mounted(){ ifRef = this.$refs.mView.contentWindow; window.onload = () => { return (() => { if(document.body.clientWidth < 700){ _this.isCollapse = true; _this.aidWid = '50px'; } })(); } window.onresize = () => { return (() => { if(document.body.clientWidth < 700){ _this.isCollapse = true; _this.aidWid = '50px'; } if(document.body.clientWidth > 1000){ _this.isCollapse = false; _this.aidWid = '180px'; } })(); } window.addEventListener('message',(data)=>{ if(data.data.id!= undefined&&(data.data.id != _this.nowSn)){ _this.nowSn = data.data.id; _this.changNow(_this.nowSn); setTimeout(() => { _this.$nextTick(function() { _this.$refs.selNow.setSelected(_this.nowSn); }) }, 100) }else if(data.data.change == "helemt"){ _this.Play(data.data.info); } }) }, methods: { setRoter(){ let _opts = { url: baseUrl + "/getRouters", type:"GET" }; let _data = {}; let _hea = { "Authorization": "Bearer " + baseTok }; getAxios(_opts,_data,_hea).then((res) => { _this.routerLi = res.data; _this.ifSrc = _this.routerLi[0].children[0].path; }) }, checkTU(){ let _ocjh = JSON.parse(getCookie("Admin-User")); if(_ocjh != null&&_ocjh != "null"){ _this.userForm = _ocjh; _this.initAjax(); if(_this.userForm.userId == 354){ checkGenToken(); } }else{ _this.getUserInfo(); } }, getUserInfo(){ let _opts = { url: baseUrl + "/getInfo", type:"GET" }; let _data = {}; let _hea = { "Authorization": "Bearer " + baseTok }; getAxios(_opts,_data,_hea).then((res) => { if(res.user.avatar == ""){ res.user.avatar = "/images/boy-01.png"; } delCookie("Admin-User"); setCookie("Admin-User",JSON.stringify(res.user)); _this.checkTU(); }) }, initAjax(){ const loading = this.$loading({ background: 'rgba(0, 0, 0, 0.4)' }) let _opts = { url: baseUrl + "/SelCctvListByUserId", type:"GET" }; let _data = { "user_id": _this.userForm.userId }; let _hea = { "Authorization": "Bearer " + baseTok }; getAxios(_opts,_data,_hea).then((res) => { if(res.code == 200&&res.data.length){ _this.shipLi = res.data; let _nowTab = JSON.parse(localStorage.getItem("nowShip")); if(_nowTab !=null && _nowTab != "null"){ let _ind = _this.shipLi.findIndex((i,ind) => {return i.sn == _nowTab.sn}); if(_ind != -1){ _nowTab = _this.shipLi[_ind]; }else{ _nowTab = _this.shipLi[0]; } }else{ _nowTab = _this.shipLi[0]; } _this.nowShip = _nowTab; _this.nowSn = _this.nowShip.sn; _this.changNow(_this.nowSn); }else{ _this.shipLi = []; } loading.close(); }) }, handleOpen(key, keyPath) { }, handleClose(key, keyPath) { }, handleSelect(key) { if(_this.ifSrc != key){ _this.ifSrc = key; } }, handleCommand(e){ if(e == "loginOut"){ _this.$confirm('否退出当前登录?', '温馨提示', { confirmButtonText: '退出', cancelButtonText: '取消', type: 'warning' }).then(() => { ajaxErr(); }).catch(() => {}); }else{ } }, changNow(_id){ let _ind = _this.shipLi.findIndex((it,ind) => { return it.sn == _id; }); if(_ind != -1){ _this.nowShip = _this.shipLi[_ind]; _this.nowSn = _this.nowShip.sn; localStorage.removeItem("nowShip"); localStorage.setItem("nowShip",JSON.stringify(_this.nowShip)); ifRef.postMessage(_this.nowSn,staticUrl+"/"); } }, SetHelemMsg() { if('WebSocket' in window) { webSocket = new WebSocket("wss://caps.runde.pro/wss"); } else if('MozWebSocket' in window) { webSocket = MozWebSocket("wss://caps.runde.pro/wss"); } else { window.alert("浏览器不支持WebSocket"); } webSocket.onopen = function(){ console.log("链接成功"); var _Tok = getCookie("hemlTok"); _this.Play({ access_token: _Tok, act: "ma_login", user_name: "易站智联", }); } webSocket.onclose = function(){ console.log("我自闭了"); _this.SetHelemMsg(); } webSocket.onmessage = function(msg){ let _data = JSON.parse(msg.data); if(_data.cmd == "ma_get_active_devices"||_data.cmd== "ma_login"){ if(_data.cmd== "ma_login"&&!_data.status){ _this.$alert('登录超时,请重新登录!!!', '温馨提示', { confirmButtonText: '确定', type: 'warning' }).then(() => { ajaxErr(); }).catch(() => {}); }else{ if(_data.cmd == "ma_login"&&_data.status){ localStorage.removeItem("sipInfo"); localStorage.setItem("sipInfo",JSON.stringify(_data.admin_info.sip_info)); } if(_data.cmd == "ma_get_active_devices"&&_data.status){ let _arr = {}; _data.data.forEach((item) => { _arr[item.user_info.device_id] = item.user_info.sip_id }); // localStorage.removeItem("sipIds"); // localStorage.setItem("sipIds",JSON.stringify(_arr)); localStorage.removeItem("sipLists"); localStorage.setItem("sipLists",JSON.stringify(_data.data)); } setTimeout(()=>{ _this.Play({act: "ma_get_active_devices"}); },5*1000); } }else{ ifRef.postMessage(_data,staticUrl+"/"); } } }, Play(_obj){ webSocket.send(JSON.stringify(_obj)); }, drwData(da) { _this.drawer = da; }, checkToken(){ clearInterval(_timeId); _timeId = setInterval(() => { getUseDict("com_maintenance_record_state"); },30*1000); } } })