123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- var _this, baseTok = null, userForm = null, ifView = null, allShip = [];
- new Vue({
- el: '#app',
- data: function() {
- return {
- tabInd: 4,
- shipList: [],
- tabShip: {},
- siderShow: true,
- queryKey: "",
- tabTitle: "",
- tabUrl: "deviceDetection",
- authorArr: {}
- }
- },
- created:function(){
- _this = this;
- baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
- _this.checkTU();
- _this.setRoter();
- _this.SetHelemMsg();
- if(location.search == ""){
- _this.changeInd(0)
- }else{
- let dh = location.search.split("=");
- _this.changeInd(dh[1]);
- }
- },
- mounted(){
- ifView = this.$refs.ifView.contentWindow;
- window.addEventListener('message',(data)=>{
- console.log("main",data)
- if(data.data.id!= undefined&&(data.data.id != _this.tabShip.sn)){
- _this.changeShip(data.data.id, 12);
- }else if(data.data.device_id){
- _this.Play(data.data);
- }
- })
- },
- methods:{
- setRoter(){
- let _opts = {
- url: baseUrl + "/getRouters",
- type:"GET"
- };
- let _data = {};
- let _hea = {
- "Authorization": "Bearer " + baseTok
- };
- getAxios(_opts,_data,_hea).then((res) => {
- _this.authorArr = {};
- _this.getAuthority(res.data);
- localStorage.setItem("authorArr", JSON.stringify(_this.authorArr));
- })
- },
- getAuthority(_obj){
- _obj.forEach((item,index)=>{
- if(item.path != undefined){
- _this.authorArr[item.path] = true;
- }
- if(item.children != undefined){
- _this.getAuthority(item.children);
- }
- // break;
- })
- },
- checkTU(){
- let _ocjh = JSON.parse(getCookie("Admin-User"));
- if(_ocjh != null&&_ocjh != "null"){
- userForm = _ocjh;
- _this.getList()
- }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();
- })
- },
- changeInd(num){
- _this.siderShow = false;
- _this.tabInd = num;
- let _a, _b;
- if(num == 2){
- _a = "个人中心";
- _b = "userInfo";
- }else{
- _a = _this.tabShip.sn != undefined?_this.tabShip.dev_name:"";
- if(num == 0){
- _b = "shipFeet";
- }else if(num == 1){
- _b = "videoLive";
- }else if(num == 3){
- _b = "hemletLive";
- }else if(num == 4){
- _b = "deviceDetection";
- }
- }
- _this.tabTitle = _a;
- _this.tabUrl = _b;
- },
- changeSider(){
- _this.siderShow = !_this.siderShow;
- },
- getList(){
- let _opts = {
- url: baseUrl + "/SelCctvListByUserId",
- type:"GET"
- };
- let _data = {
- "user_id": userForm.userId
- };
- let _hea = {
- "Authorization": "Bearer " + baseTok
- };
- getAxios(_opts,_data,_hea).then((res) => {
- if(res.code == 200&&res.data.length){
- _this.shipList = res.data;
- let _sn = JSON.parse(localStorage.getItem("nowShip"));
- if(_sn !=null && _sn != "null"){
- let _ind = _this.shipList.findIndex((i,ind) => {return i.sn == _sn.sn});
- if(_ind != -1){
- _sn = _this.shipList[_ind];
- }else{
- _sn = _this.shipList[0];
- }
- }else{
- _sn = _this.shipList[0];
- }
- _this.changeShip(_sn.sn);
- }else{
- _this.shipList = [];
- }
- allShip = _this.shipList;
- })
- },
- changeShip(_row, sh){
- let _ind = _this.shipList.findIndex((it,ind) => {return it.sn == _row;});
- if(_ind != -1){
- _this.tabShip = JSON.parse(JSON.stringify(_this.shipList[_ind]));
- _this.tabTitle = _this.tabShip.dev_name;
- localStorage.setItem("nowShip",JSON.stringify(_this.tabShip));
- _this.siderShow = false;
- if(sh == undefined){
- ifView.postMessage(_this.tabShip.sn, staticUrl+"/");
- }
- }
- },
- inpSearch(val){
- if(val == ""){
- _this.shipList = allShip;
- }else{
- let _arr = [], _obj = allShip;
- _obj.forEach(item => {
- if(item.dev_name.indexOf(val) != -1){
- _arr.push(item);
- }
- })
- _this.shipList = _arr;
- }
- },
- 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){
- // ShowLoading("登录超时,请重新登录!!!",1);
- ajaxErr();
- }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("sipLists");
- localStorage.setItem("sipLists",JSON.stringify(_data.data));
- }
- setTimeout(()=>{
- _this.Play({act: "ma_get_active_devices"});
- },30*1000);
- }
- }else{
- _data["type"] = "helmet";
- ifView.postMessage(_data, staticUrl+"/");
- }
- }
- },
- Play(_obj){
- webSocket.send(JSON.stringify(_obj));
- }
- }
- })
|