main.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. var _this,ifRef,baseTok;
  2. var webSocket;
  3. var _timeId;
  4. new Vue({
  5. el: '#app',
  6. data: function() {
  7. return {
  8. isCollapse: false,
  9. aidWid: '180px',
  10. ifSrc: 'P0',
  11. nowShip: {},
  12. nowSn: "",
  13. shipLi: [],
  14. drawer: false,
  15. userForm:{
  16. avatar:"/images/boy-01.png",
  17. nickName:"",
  18. roles: [{
  19. roleName: ""
  20. }]
  21. },
  22. routerLi: []
  23. }
  24. },
  25. created() {
  26. _this = this;
  27. baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  28. _this.setRoter();
  29. _this.checkTU();
  30. _this.checkToken();
  31. _this.SetHelemMsg();
  32. },
  33. mounted(){
  34. ifRef = this.$refs.mView.contentWindow;
  35. window.onload = () => {
  36. return (() => {
  37. if(document.body.clientWidth < 700){
  38. _this.isCollapse = true;
  39. _this.aidWid = '50px';
  40. }
  41. })();
  42. }
  43. window.onresize = () => {
  44. return (() => {
  45. if(document.body.clientWidth < 700){
  46. _this.isCollapse = true;
  47. _this.aidWid = '50px';
  48. }
  49. if(document.body.clientWidth > 1000){
  50. _this.isCollapse = false;
  51. _this.aidWid = '180px';
  52. }
  53. })();
  54. }
  55. window.addEventListener('message',(data)=>{
  56. if(data.data.id!= undefined&&(data.data.id != _this.nowSn)){
  57. _this.nowSn = data.data.id;
  58. _this.changNow(_this.nowSn);
  59. setTimeout(() => {
  60. _this.$nextTick(function() {
  61. _this.$refs.selNow.setSelected(_this.nowSn);
  62. })
  63. }, 100)
  64. }else if(data.data.change == "helemt"){
  65. _this.Play(data.data.info);
  66. }
  67. })
  68. },
  69. methods: {
  70. setRoter(){
  71. let _opts = {
  72. url: baseUrl + "/getRouters",
  73. type:"GET"
  74. };
  75. let _data = {};
  76. let _hea = {
  77. "Authorization": "Bearer " + baseTok
  78. };
  79. getAxios(_opts,_data,_hea).then((res) => {
  80. _this.routerLi = res.data;
  81. _this.ifSrc = _this.routerLi[0].children[0].path;
  82. })
  83. },
  84. checkTU(){
  85. let _ocjh = JSON.parse(getCookie("Admin-User"));
  86. if(_ocjh != null&&_ocjh != "null"){
  87. _this.userForm = _ocjh;
  88. _this.initAjax();
  89. if(_this.userForm.userId == 354){
  90. checkGenToken();
  91. }
  92. }else{
  93. _this.getUserInfo();
  94. }
  95. },
  96. getUserInfo(){
  97. let _opts = {
  98. url: baseUrl + "/getInfo",
  99. type:"GET"
  100. };
  101. let _data = {};
  102. let _hea = {
  103. "Authorization": "Bearer " + baseTok
  104. };
  105. getAxios(_opts,_data,_hea).then((res) => {
  106. if(res.user.avatar == ""){
  107. res.user.avatar = "/images/boy-01.png";
  108. }
  109. delCookie("Admin-User");
  110. setCookie("Admin-User",JSON.stringify(res.user));
  111. _this.checkTU();
  112. })
  113. },
  114. initAjax(){
  115. const loading = this.$loading({
  116. background: 'rgba(0, 0, 0, 0.4)'
  117. })
  118. let _opts = {
  119. url: baseUrl + "/SelCctvListByUserId",
  120. type:"GET"
  121. };
  122. let _data = {
  123. "user_id": _this.userForm.userId
  124. };
  125. let _hea = {
  126. "Authorization": "Bearer " + baseTok
  127. };
  128. getAxios(_opts,_data,_hea).then((res) => {
  129. if(res.code == 200&&res.data.length){
  130. _this.shipLi = res.data;
  131. let _nowTab = JSON.parse(localStorage.getItem("nowShip"));
  132. if(_nowTab !=null && _nowTab != "null"){
  133. let _ind = _this.shipLi.findIndex((i,ind) => {return i.sn == _nowTab.sn});
  134. if(_ind != -1){
  135. _nowTab = _this.shipLi[_ind];
  136. }else{
  137. _nowTab = _this.shipLi[0];
  138. }
  139. }else{
  140. _nowTab = _this.shipLi[0];
  141. }
  142. _this.nowShip = _nowTab;
  143. _this.nowSn = _this.nowShip.sn;
  144. _this.changNow(_this.nowSn);
  145. }else{
  146. _this.shipLi = [];
  147. }
  148. loading.close();
  149. })
  150. },
  151. handleOpen(key, keyPath) {
  152. },
  153. handleClose(key, keyPath) {
  154. },
  155. handleSelect(key) {
  156. if(_this.ifSrc != key){
  157. _this.ifSrc = key;
  158. }
  159. },
  160. handleCommand(e){
  161. if(e == "loginOut"){
  162. _this.$confirm('否退出当前登录?', '温馨提示', {
  163. confirmButtonText: '退出',
  164. cancelButtonText: '取消',
  165. type: 'warning'
  166. }).then(() => {
  167. ajaxErr();
  168. }).catch(() => {});
  169. }else{
  170. }
  171. },
  172. changNow(_id){
  173. let _ind = _this.shipLi.findIndex((it,ind) => {
  174. return it.sn == _id;
  175. });
  176. if(_ind != -1){
  177. _this.nowShip = _this.shipLi[_ind];
  178. _this.nowSn = _this.nowShip.sn;
  179. localStorage.removeItem("nowShip");
  180. localStorage.setItem("nowShip",JSON.stringify(_this.nowShip));
  181. ifRef.postMessage(_this.nowSn,staticUrl+"/");
  182. }
  183. },
  184. SetHelemMsg() {
  185. if('WebSocket' in window) {
  186. webSocket = new WebSocket("wss://caps.runde.pro/wss");
  187. } else if('MozWebSocket' in window) {
  188. webSocket = MozWebSocket("wss://caps.runde.pro/wss");
  189. } else {
  190. window.alert("浏览器不支持WebSocket");
  191. }
  192. webSocket.onopen = function(){
  193. console.log("链接成功");
  194. var _Tok = getCookie("hemlTok");
  195. _this.Play({
  196. access_token: _Tok,
  197. act: "ma_login",
  198. user_name: "易站智联",
  199. });
  200. }
  201. webSocket.onclose = function(){
  202. console.log("我自闭了");
  203. _this.SetHelemMsg();
  204. }
  205. webSocket.onmessage = function(msg){
  206. let _data = JSON.parse(msg.data);
  207. if(_data.cmd == "ma_get_active_devices"||_data.cmd== "ma_login"){
  208. if(_data.cmd== "ma_login"&&!_data.status){
  209. _this.$alert('登录超时,请重新登录!!!', '温馨提示', {
  210. confirmButtonText: '确定',
  211. type: 'warning'
  212. }).then(() => {
  213. ajaxErr();
  214. }).catch(() => {});
  215. }else{
  216. if(_data.cmd == "ma_login"&&_data.status){
  217. localStorage.removeItem("sipInfo");
  218. localStorage.setItem("sipInfo",JSON.stringify(_data.admin_info.sip_info));
  219. }
  220. if(_data.cmd == "ma_get_active_devices"&&_data.status){
  221. let _arr = {};
  222. _data.data.forEach((item) => { _arr[item.user_info.device_id] = item.user_info.sip_id });
  223. // localStorage.removeItem("sipIds");
  224. // localStorage.setItem("sipIds",JSON.stringify(_arr));
  225. localStorage.removeItem("sipLists");
  226. localStorage.setItem("sipLists",JSON.stringify(_data.data));
  227. }
  228. setTimeout(()=>{
  229. _this.Play({act: "ma_get_active_devices"});
  230. },5*1000);
  231. }
  232. }else{
  233. ifRef.postMessage(_data,staticUrl+"/");
  234. }
  235. }
  236. },
  237. Play(_obj){
  238. webSocket.send(JSON.stringify(_obj));
  239. },
  240. drwData(da) {
  241. _this.drawer = da;
  242. },
  243. checkToken(){
  244. clearInterval(_timeId);
  245. _timeId = setInterval(() => {
  246. getUseDict("com_maintenance_record_state");
  247. },30*1000);
  248. }
  249. }
  250. })