main.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. var _this, screenWidth, timeId;
  2. var myChart1, myChart2, myChart3, mapView, angView;
  3. new Vue({
  4. el: '#app',
  5. data: function() {
  6. return {
  7. imgHei: 0,
  8. gutter: 5,
  9. fontS: 16,
  10. echTxt: 0,
  11. shipLi: [],
  12. tabDiv: 39,
  13. nowTab: {},
  14. selVis: false,
  15. shipCount: [{name: "船舶总数",count: 0,icon: "../img/shipnum.png"},
  16. {name: "在线船舶",count: 0,icon: "../img/online.png"},
  17. {name: "离线船舶",count: 0,icon: "../img/offline.png"}
  18. ],
  19. shipPeol: [{name: "在船人数",count: 297,col:"#51a3f4"},
  20. {name: "预警人数",count: 7,col:"#fbbd08"},
  21. {name: "超载人数",count: 10,col:"#fa0000"}],
  22. switLi: []
  23. }
  24. },
  25. created() {
  26. _this = this;
  27. _this.init(0);
  28. // timeId = setInterval(()=>{
  29. // _this.init(1);
  30. // },60*1000)
  31. },
  32. mounted() {
  33. let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  34. _this.gutter = Math.ceil(screenWidth / 320);
  35. _this.fontS = (screenWidth / 1440) * 16;
  36. mapView = this.$refs.mapView.contentWindow;
  37. angView = this.$refs.angView.contentWindow;
  38. this.$nextTick(() => {
  39. myChart1 = echarts.init(document.getElementById("myChart1"));
  40. myChart2 = echarts.init(document.getElementById("myChart2"));
  41. myChart3 = echarts.init(document.getElementById("myChart3"));
  42. _this.tabDiv = _this.$refs.titleDiv.offsetHeight;
  43. });
  44. window.onresize = () => {
  45. _this.imgLoad();
  46. }
  47. window.addEventListener('message',(res)=>{
  48. if(res.data.nowSn != undefined){
  49. _this.getSn(res.data.nowSn);
  50. }
  51. })
  52. },
  53. destroyed(){
  54. clearInterval(timeId);
  55. },
  56. methods: {
  57. init(num) {
  58. let loading = null;
  59. if(num == 0){
  60. loading = this.$loading({
  61. background: 'rgba(0, 0, 0, 0.4)'
  62. })
  63. }
  64. getList(function acb(_obj, _online){
  65. let _sn = _this.nowTab.mmsi;
  66. if (_sn != undefined) {
  67. let _ind = _obj.findIndex((i, ind) => {
  68. return i.mmsi == _sn
  69. });
  70. if (_ind != -1) {
  71. _sn = _obj[_ind];
  72. } else {
  73. _sn = _obj[0];
  74. }
  75. } else {
  76. _sn = _obj[0];
  77. }
  78. _this.shipLi = _obj;
  79. _this.nowTab = _sn;
  80. _this.shipCount[0].count = _this.shipLi.length;
  81. _this.shipCount[1].count = _online;
  82. _this.shipCount[2].count = parseInt(_this.shipLi.length) - _online;
  83. _this.openInfo(_this.nowTab.mmsi);
  84. angView.onload = function () {
  85. angView.postMessage({
  86. nowSn: _this.nowTab,
  87. gutter: _this.gutter,
  88. fontS: _this.fontS
  89. },"*");
  90. }
  91. mapView.onload = function () {
  92. mapView.postMessage({
  93. gutter: _this.gutter,
  94. fontS: _this.fontS,
  95. nowSn: _this.nowTab,
  96. shipLi: _this.shipLi
  97. },"*");
  98. }
  99. if(num == 0){loading.close();}
  100. })
  101. },
  102. setEchart() {
  103. this.$nextTick(() => {
  104. myChart1.setOption(_this.setOption1([100, 140, 125, 160, 130, 145, 128]));
  105. myChart2.setOption(_this.setOption2([25, 28, 10, 17, 20],["在航", "故障", "维修", "靠泊", "锚泊"]));
  106. myChart3.setOption(_this.setOption2([25, 28, 10, 17, 20],[">20年", "15-20年", "10-15年", "5-10年", "<5年"]));
  107. myChart1.resize();
  108. myChart2.resize();
  109. myChart3.resize();
  110. })
  111. },
  112. openInfo(_sn) {
  113. let _cmk = _this.shipLi;
  114. for (var i = 0; i < _cmk.length; i++) {
  115. if (_sn == _cmk[i].mmsi) {
  116. var _str = _cmk[i];
  117. _this.nowTab = _str;
  118. _this.setEchart();
  119. }
  120. }
  121. },
  122. imgLoad() {
  123. var _Img = document.getElementById('headImg');
  124. this.$nextTick(() => {
  125. _this.imgHei = _Img.clientHeight
  126. })
  127. let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  128. _this.gutter = Math.ceil(screenWidth / 320);
  129. _this.fontS = (screenWidth / 1440) * 16;
  130. },
  131. changeSn(_key) {
  132. _this.getSn(_key);
  133. mapView.postMessage({
  134. nowSn: _this.nowTab,
  135. type: "changsn"
  136. },"*")
  137. angView.postMessage({
  138. nowSn: _this.nowTab,
  139. type: "changsn"
  140. },"*");
  141. },
  142. getSn(key){
  143. let _ind = _this.shipLi.findIndex((i, ind) => {
  144. return i.mmsi == key
  145. });
  146. if (_ind != -1) {
  147. _sn = _this.shipLi[_ind];
  148. } else {
  149. _sn = _this.shipLi[0];
  150. }
  151. _this.selVis = false;
  152. _this.nowTab = _sn;
  153. _this.setEchart();
  154. _this.openInfo(_this.nowTab.mmsi);
  155. },
  156. setOption1(_arr) {
  157. option = {
  158. tooltip: {
  159. trigger: 'axis',
  160. axisPointer: {
  161. type: 'cross',
  162. label: {
  163. backgroundColor: '#6a7985'
  164. }
  165. }
  166. },
  167. grid: {
  168. top: '10%',
  169. left: '1%',
  170. right: '2%',
  171. bottom: '2%',
  172. containLabel: true
  173. },
  174. xAxis: {
  175. type: 'category',
  176. boundaryGap: true,
  177. splitLine: {
  178. show: true,
  179. lineStyle: {
  180. color: '#29437c'
  181. }
  182. },
  183. axisLabel: {
  184. textStyle: {
  185. color: '#fff',
  186. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  187. },
  188. showMaxLabel: true
  189. },
  190. data: ['2016', '2017', '2018', '2019', '2020', '2021', '2022']
  191. },
  192. yAxis: {
  193. type: 'value',
  194. axisLabel: {
  195. textStyle: {
  196. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  197. },
  198. showMaxLabel: true
  199. },
  200. axisLine: {
  201. show: true,
  202. lineStyle: {
  203. color: ['#5f6ee1']
  204. }
  205. },
  206. splitLine: {
  207. show: true,
  208. lineStyle: {
  209. color: ['#29437c']
  210. }
  211. }
  212. },
  213. series: [{
  214. data: _arr,
  215. type: 'line',
  216. label: {
  217. show: true,
  218. position: 'top',
  219. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  220. },
  221. itemStyle: {
  222. normal: {
  223. color: '#5f6ee1', //改变折线点的颜色
  224. lineStyle: {
  225. color: '#5f6ee1' //改变折线颜色
  226. }
  227. }
  228. }
  229. }]
  230. };
  231. return option;
  232. },
  233. setOption2(Num,Name) {
  234. option = {
  235. tooltip: {
  236. trigger: 'item',
  237. formatter: '{a} <br/>{b}: {c} ({d}%)'
  238. },
  239. legend: {
  240. show: true,
  241. itemWidth: ((_this.fontS > 16) ? (_this.gutter * 0.8) : 10) ,
  242. itemHeight: ((_this.fontS > 16) ? (_this.gutter * 0.8) : 10),
  243. right: '3%',
  244. y: "center",
  245. itemGap: _this.gutter,
  246. orient: 'vertical',
  247. data:Name,
  248. textStyle: {
  249. color: "#fff",
  250. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  251. }
  252. },
  253. color: ['#4f6dcd', '#fad972', '#f88582', '#3ae3bc', '#9299f3'],
  254. series: [{
  255. name: '实时数据统计',
  256. type: 'pie',
  257. center: ['45%', '50%'],
  258. radius: ['50%', '60%'],
  259. avoidLabelOverlap: false,
  260. label: {
  261. show: false,
  262. position: 'center'
  263. },
  264. emphasis: {
  265. label: {
  266. show: true,
  267. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  268. fontWeight: 'bold'
  269. }
  270. },
  271. itemStyle: {
  272. normal: {
  273. borderRadius: 10,
  274. borderColor: '#323740',
  275. borderWidth: 2,
  276. label: {
  277. show: true,
  278. formatter: '{d}%',
  279. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  280. color: "#fff"
  281. },
  282. labelLine: {
  283. show: true
  284. }
  285. }
  286. },
  287. labelLine: {
  288. show: true
  289. },
  290. data: [{
  291. value: Num[0],
  292. name: Name[0]
  293. },
  294. {
  295. value: Num[1],
  296. name: Name[1]
  297. },
  298. {
  299. value: Num[2],
  300. name: Name[2]
  301. },
  302. {
  303. value: Num[3],
  304. name: Name[3]
  305. },
  306. {
  307. value: Num[4],
  308. name: Name[4]
  309. },
  310. {
  311. value: Num[5],
  312. name: Name[5]
  313. }
  314. ]
  315. }]
  316. };
  317. return option;
  318. }
  319. }
  320. })