mainPh.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. var _this, baseTok = null, userForm = null, ifView = null, allShip = [];
  2. new Vue({
  3. el: '#app',
  4. data: function() {
  5. return {
  6. tabInd: 4,
  7. shipList: [],
  8. tabShip: {},
  9. siderShow: true,
  10. queryKey: "",
  11. tabTitle: "",
  12. tabUrl: "deviceDetection",
  13. authorArr: {}
  14. }
  15. },
  16. created:function(){
  17. _this = this;
  18. baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  19. _this.checkTU();
  20. _this.setRoter();
  21. _this.SetHelemMsg();
  22. if(location.search == ""){
  23. _this.changeInd(0)
  24. }else{
  25. let dh = location.search.split("=");
  26. _this.changeInd(dh[1]);
  27. }
  28. },
  29. mounted(){
  30. ifView = this.$refs.ifView.contentWindow;
  31. window.addEventListener('message',(data)=>{
  32. console.log("main",data)
  33. if(data.data.id!= undefined&&(data.data.id != _this.tabShip.sn)){
  34. _this.changeShip(data.data.id, 12);
  35. }else if(data.data.device_id){
  36. _this.Play(data.data);
  37. }
  38. })
  39. },
  40. methods:{
  41. setRoter(){
  42. let _opts = {
  43. url: baseUrl + "/getRouters",
  44. type:"GET"
  45. };
  46. let _data = {};
  47. let _hea = {
  48. "Authorization": "Bearer " + baseTok
  49. };
  50. getAxios(_opts,_data,_hea).then((res) => {
  51. _this.authorArr = {};
  52. _this.getAuthority(res.data);
  53. localStorage.setItem("authorArr", JSON.stringify(_this.authorArr));
  54. })
  55. },
  56. getAuthority(_obj){
  57. _obj.forEach((item,index)=>{
  58. if(item.path != undefined){
  59. _this.authorArr[item.path] = true;
  60. }
  61. if(item.children != undefined){
  62. _this.getAuthority(item.children);
  63. }
  64. // break;
  65. })
  66. },
  67. checkTU(){
  68. let _ocjh = JSON.parse(getCookie("Admin-User"));
  69. if(_ocjh != null&&_ocjh != "null"){
  70. userForm = _ocjh;
  71. _this.getList()
  72. }else{
  73. _this.getUserInfo();
  74. }
  75. },
  76. getUserInfo(){
  77. let _opts = {
  78. url: baseUrl + "/getInfo",
  79. type:"GET"
  80. };
  81. let _data = {};
  82. let _hea = {
  83. "Authorization": "Bearer " + baseTok
  84. };
  85. getAxios(_opts,_data,_hea).then((res) => {
  86. if(res.user.avatar == ""){
  87. res.user.avatar = "/images/boy-01.png";
  88. }
  89. delCookie("Admin-User");
  90. setCookie("Admin-User",JSON.stringify(res.user));
  91. _this.checkTU();
  92. })
  93. },
  94. changeInd(num){
  95. _this.siderShow = false;
  96. _this.tabInd = num;
  97. let _a, _b;
  98. if(num == 2){
  99. _a = "个人中心";
  100. _b = "userInfo";
  101. }else{
  102. _a = _this.tabShip.sn != undefined?_this.tabShip.dev_name:"";
  103. if(num == 0){
  104. _b = "shipFeet";
  105. }else if(num == 1){
  106. _b = "videoLive";
  107. }else if(num == 3){
  108. _b = "hemletLive";
  109. }else if(num == 4){
  110. _b = "deviceDetection";
  111. }
  112. }
  113. _this.tabTitle = _a;
  114. _this.tabUrl = _b;
  115. },
  116. changeSider(){
  117. _this.siderShow = !_this.siderShow;
  118. },
  119. getList(){
  120. let _opts = {
  121. url: baseUrl + "/SelCctvListByUserId",
  122. type:"GET"
  123. };
  124. let _data = {
  125. "user_id": userForm.userId
  126. };
  127. let _hea = {
  128. "Authorization": "Bearer " + baseTok
  129. };
  130. getAxios(_opts,_data,_hea).then((res) => {
  131. if(res.code == 200&&res.data.length){
  132. _this.shipList = res.data;
  133. let _sn = JSON.parse(localStorage.getItem("nowShip"));
  134. if(_sn !=null && _sn != "null"){
  135. let _ind = _this.shipList.findIndex((i,ind) => {return i.sn == _sn.sn});
  136. if(_ind != -1){
  137. _sn = _this.shipList[_ind];
  138. }else{
  139. _sn = _this.shipList[0];
  140. }
  141. }else{
  142. _sn = _this.shipList[0];
  143. }
  144. _this.changeShip(_sn.sn);
  145. }else{
  146. _this.shipList = [];
  147. }
  148. allShip = _this.shipList;
  149. })
  150. },
  151. changeShip(_row, sh){
  152. let _ind = _this.shipList.findIndex((it,ind) => {return it.sn == _row;});
  153. if(_ind != -1){
  154. _this.tabShip = JSON.parse(JSON.stringify(_this.shipList[_ind]));
  155. _this.tabTitle = _this.tabShip.dev_name;
  156. localStorage.setItem("nowShip",JSON.stringify(_this.tabShip));
  157. _this.siderShow = false;
  158. if(sh == undefined){
  159. ifView.postMessage(_this.tabShip.sn, staticUrl+"/");
  160. }
  161. }
  162. },
  163. inpSearch(val){
  164. if(val == ""){
  165. _this.shipList = allShip;
  166. }else{
  167. let _arr = [], _obj = allShip;
  168. _obj.forEach(item => {
  169. if(item.dev_name.indexOf(val) != -1){
  170. _arr.push(item);
  171. }
  172. })
  173. _this.shipList = _arr;
  174. }
  175. },
  176. SetHelemMsg() {
  177. if('WebSocket' in window) {
  178. webSocket = new WebSocket("wss://caps.runde.pro/wss");
  179. } else if('MozWebSocket' in window) {
  180. webSocket = MozWebSocket("wss://caps.runde.pro/wss");
  181. } else {
  182. window.alert("浏览器不支持WebSocket");
  183. }
  184. webSocket.onopen = function(){
  185. console.log("链接成功");
  186. var _Tok = getCookie("hemlTok");
  187. _this.Play({
  188. access_token: _Tok,
  189. act: "ma_login",
  190. user_name: "易站智联",
  191. });
  192. }
  193. webSocket.onclose = function(){
  194. console.log("我自闭了");
  195. _this.SetHelemMsg();
  196. }
  197. webSocket.onmessage = function(msg){
  198. let _data = JSON.parse(msg.data);
  199. if(_data.cmd == "ma_get_active_devices"||_data.cmd== "ma_login"){
  200. if(_data.cmd== "ma_login"&&!_data.status){
  201. // ShowLoading("登录超时,请重新登录!!!",1);
  202. ajaxErr();
  203. }else{
  204. if(_data.cmd == "ma_login"&&_data.status){
  205. localStorage.removeItem("sipInfo");
  206. localStorage.setItem("sipInfo",JSON.stringify(_data.admin_info.sip_info));
  207. }
  208. if(_data.cmd == "ma_get_active_devices"&&_data.status){
  209. let _arr = {};
  210. _data.data.forEach((item) => { _arr[item.user_info.device_id] = item.user_info.sip_id });
  211. localStorage.removeItem("sipLists");
  212. localStorage.setItem("sipLists",JSON.stringify(_data.data));
  213. }
  214. setTimeout(()=>{
  215. _this.Play({act: "ma_get_active_devices"});
  216. },30*1000);
  217. }
  218. }else{
  219. _data["type"] = "helmet";
  220. ifView.postMessage(_data, staticUrl+"/");
  221. }
  222. }
  223. },
  224. Play(_obj){
  225. webSocket.send(JSON.stringify(_obj));
  226. }
  227. }
  228. })