wireRope.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. var snData = { 412373470: "ZJ217027175898243052,ZJ217027176114406053", 413871376: "ZJ216801593395575538,ZJ217008114043323047" }
  2. var _this;
  3. var myChart;
  4. var nowYsy = null;
  5. var toDay = null;
  6. var data1 = [], xdata = [];
  7. var timeOutOnline = null, timeOutReal = null, timeOutLine = null;
  8. new Vue({
  9. el: '#app',
  10. data: function() {
  11. return {
  12. activeName: "0",
  13. wireImeiLi: [],
  14. wireItem: {},
  15. wireInfo: {
  16. maxSS: 0,
  17. avgSS: 0,
  18. data: []
  19. },
  20. queryParams: {
  21. imei: null,
  22. startime: null,
  23. endtime: null,
  24. orderSql: "time desc",
  25. page: 1,
  26. rows: 12,
  27. accessToken: getCookie("wireToken")
  28. },
  29. orderSqlLi: [{
  30. value: 'time desc',
  31. label: '时间降序'
  32. },{
  33. value: 'time asc',
  34. label: '时间升序'
  35. }],
  36. wireHis: [],
  37. allTotal: 0,
  38. loading: false
  39. }
  40. },
  41. created() {
  42. _this = this;
  43. nowYsy = JSON.parse(localStorage.getItem("nowShip"));
  44. toDay = parseTime(new Date(), '{y}-{m}-{d}');
  45. _this.queryParams.startime = toDay+" 00:00:00";
  46. _this.queryParams.endtime = toDay+" 23:59:59";
  47. },
  48. mounted:function(){
  49. myChart = echarts.init(document.getElementById('myChart'));
  50. _this.getStatus(0);
  51. window.addEventListener('message',(data)=>{
  52. nowYsy = JSON.parse(localStorage.getItem("nowShip"));
  53. clearTimeout(timeOutOnline);
  54. clearTimeout(timeOutReal);
  55. clearTimeout(timeOutLine);
  56. _this.getStatus(0);
  57. })
  58. },
  59. methods: {
  60. getStatus(num){
  61. if(snData[nowYsy.mmsi].length){
  62. if(num == 0){
  63. _this.loading = true;
  64. _this.wireItem = {};
  65. }
  66. getWireStatus(snData[nowYsy.mmsi], function(result){
  67. let _sta = false;
  68. var _obj = [], _data = result.data;
  69. let imeiArr = snData[nowYsy.mmsi].split(",");
  70. imeiArr.forEach((item,index) => {
  71. let _def = [];
  72. if(_data.length){
  73. _def = _data.filter(fitem => { return fitem.clientId == item; })
  74. };
  75. _obj.push({
  76. imei: item,
  77. name: nowYsy.dev_name + " - 钢丝绳"+(index+1),
  78. online: _def.length?_def[0].online:0,
  79. time: _def.length?_def[0].time:"----/--/-- --:--:--",
  80. });
  81. if(_def.length&&_def[0].online == 1){
  82. _sta = true;
  83. }
  84. });
  85. _this.wireImeiLi = _obj;
  86. if(_this.wireItem.imei == undefined){
  87. _this.wireItem = _obj[0];
  88. }else{
  89. _this.wireItem = _obj.filter(fitem => { return fitem.imei == _this.wireItem.imei })[0];
  90. }
  91. _this.queryParams.imei = _this.wireItem.imei;
  92. timeOutOnline = setTimeout(()=>{
  93. _this.getStatus(1);
  94. },(_sta?15*1000:30*1000))
  95. if(num == 0){
  96. _this.loading = false;
  97. if(_this.wireItem.online != 1){
  98. _this.$message({
  99. showClose: true,
  100. message: "设备离线中",
  101. type: 'warning'
  102. });
  103. _this.unlineReset();
  104. }else{
  105. _this.getWireReal(0);
  106. _this.getWireLine(0);
  107. }
  108. }
  109. });
  110. }else{
  111. _this.wireImeiLi = [];
  112. _this.unlineReset();
  113. }
  114. },
  115. getWireReal(num){
  116. if(_this.queryParams.imei != null){
  117. getWireTeal(_this.queryParams.imei,function(res){
  118. let data1 = [], data2 = [], xdata = [];
  119. _this.wireInfo = {
  120. maxSS: 0,
  121. avgSS: 0,
  122. data: []
  123. };
  124. if(res.data != undefined){
  125. let _obj = res.data;
  126. _this.wireInfo = _obj;
  127. }
  128. timeOutReal = setTimeout(()=>{
  129. _this.getWireReal(1);
  130. },(_this.wireItem.online == 1?5*1000:30*1000))
  131. });
  132. }
  133. },
  134. getWireLine(num){
  135. if(_this.queryParams.imei != null){
  136. if(num == 0){ data1 = [], xdata = [];}
  137. getWireTealLine(_this.queryParams.imei,function(res){
  138. if(res.data != undefined){
  139. data1.push({ value: res.data.val });
  140. xdata.push(getDTime(new Date(parseInt(res.data.ts)*1000))[1])
  141. }
  142. timeOutLine = setTimeout(()=>{
  143. _this.getWireLine(1);
  144. },(_this.wireItem.online == 1?5*1000:30*1000))
  145. if(num == 0){
  146. myChart.setOption(_this.getOption(data1, xdata));
  147. }else{
  148. myChart.setOption({
  149. xAxis: {
  150. data: xdata
  151. },
  152. series: [{
  153. data: data1
  154. }]
  155. });
  156. }
  157. });
  158. }
  159. },
  160. getOption(_data1, _xdata){
  161. let option = {
  162. title: {
  163. text: '检测时间',
  164. top: 'bottom',
  165. left: 'center',
  166. textStyle: {
  167. fontSize: 14,
  168. color: "#cecece",
  169. }
  170. },
  171. tooltip: {
  172. trigger: 'axis',
  173. axisPointer: {
  174. animation: false
  175. }
  176. },
  177. grid: {
  178. left: '3%',
  179. right: '1%',
  180. bottom: '10%',
  181. top: '4%',
  182. containLabel: true
  183. },
  184. xAxis: {
  185. type: 'category',
  186. data: _xdata,
  187. splitLine: {
  188. show: true,
  189. lineStyle: {
  190. color: '#7E85AB',
  191. type: 'dashed',
  192. },
  193. },
  194. axisLine: {
  195. lineStyle: {
  196. color: '#fff',
  197. width: 2
  198. }
  199. },
  200. axisLabel:{
  201. textStyle:{
  202. color: "#cecece"
  203. }
  204. }
  205. },
  206. yAxis: {
  207. type: 'value',
  208. min: 0,
  209. max: 1200,
  210. splitNumber: 6,
  211. splitLine: {
  212. show: true,
  213. lineStyle: {
  214. color: '#7E85AB',
  215. type: 'dashed',
  216. },
  217. },
  218. axisLabel:{
  219. show: IsPC(),
  220. textStyle:{
  221. color: "#cecece"
  222. }
  223. }
  224. },
  225. series: [{
  226. name: '模数值',
  227. type: 'line',
  228. data: _data1
  229. }]
  230. };
  231. return option;
  232. },
  233. handleQuery(){
  234. _this.queryParams.page = 1;
  235. _this.getWireHis();
  236. },
  237. resetQuery(){
  238. _this.queryParams = {
  239. imei: _this.wireItem.imei,
  240. startime: toDay+" 00:00:00",
  241. endtime: toDay+" 23:59:59",
  242. orderSql: "time desc",
  243. page: 1,
  244. rows: 12,
  245. accessToken: getCookie("wireToken")
  246. };
  247. _this.wireHis = [];
  248. _this.allTotal = 0;
  249. },
  250. unlineReset(){
  251. _this.wireInfo = {
  252. maxSS: 0,
  253. avgSS: 0,
  254. data: []
  255. };
  256. myChart.setOption(_this.getOption([], []));
  257. _this.resetQuery();
  258. },
  259. handleCurrentChange(val) {
  260. if(val != _this.queryParams.page){
  261. _this.queryParams.page = val;
  262. _this.getWireHis();
  263. }
  264. },
  265. handleChange(row){
  266. _this.wireItem = row;
  267. _this.queryParams.imei = row.imei;
  268. if(_this.wireItem.online != 1){
  269. _this.$message({
  270. showClose: true,
  271. message: "设备离线中",
  272. type: 'warning'
  273. });
  274. _this.unlineReset();
  275. }else{
  276. clearTimeout(timeOutReal);
  277. clearTimeout(timeOutLine);
  278. _this.getWireReal(0);
  279. _this.getWireLine(0);
  280. _this.queryParams.page = 1;
  281. _this.getWireHis();
  282. }
  283. },
  284. getWireHis(){
  285. // if(_this.queryParams.startime == null){
  286. // _this.$message({
  287. // showClose: true,
  288. // message: "请选择开始时间",
  289. // type: 'error'
  290. // });
  291. // return;
  292. // }
  293. // if(_this.queryParams.endtime == null){
  294. // _this.$message({
  295. // showClose: true,
  296. // message: "请选择结束间",
  297. // type: 'error'
  298. // });
  299. // return;
  300. // }
  301. if(_this.queryParams.imei != null){
  302. _this.loading = true;
  303. _this.queryParams.gt = new Date(_this.queryParams.startime).getTime()/1000;
  304. _this.queryParams.lt = new Date(_this.queryParams.endtime).getTime()/1000;
  305. getWireHistory(_this.queryParams,function(res){
  306. _this.wireHis = res.data;
  307. _this.allTotal = res.total;
  308. _this.loading = false;
  309. });
  310. }
  311. },
  312. goBack(){
  313. top.location.href = "../mainPh.html?sn=4";
  314. }
  315. }
  316. })