123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- 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);
- }
- }
- })
|