compreAlarm.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. var _this;
  2. var shipList = [];
  3. var nowTime;
  4. var vipUrl = "https://www.enstation.com:8083/ruico/rueigao-admin";
  5. new Vue({
  6. el: '#app',
  7. data: function() {
  8. return {
  9. userForm: {},
  10. queryParams: {
  11. searhDate: [],
  12. searhType: 0
  13. },
  14. wramList: [{ name: "驾驶员离岗", icon: "icon-ligangshenqing", key: "lgjc"},
  15. { name: "疲劳驾驶", icon: "icon-fatigue-early-warning_line", key: "pljc"},
  16. { name: "玩手机", icon: "icon-shouji", key: "sjjc"},
  17. { name: "抽烟", icon: "icon-chouyan", key: "xyjc"},
  18. { name: "定期巡检", icon: "icon-dingdianxuncha", key: "xjjc"},
  19. { name: "遮挡摄像头", icon: "icon-shexiangtou1", key: "zdjc"},
  20. { name: "安全穿戴", icon: "icon-paigong", key: "aqjc"},
  21. { name: "未瞭望", icon: "icon-yanjing", key: "lwjc"}],
  22. wramCount: {
  23. lgjc: 0,
  24. sjjc: 0,
  25. xyjc: 0,
  26. sjjc: 0,
  27. lwjc: 0,
  28. xjjc: 0,
  29. zdjc: 0,
  30. aqjc: 0
  31. },
  32. warmData: []
  33. }
  34. },
  35. created() {
  36. _this = this;
  37. nowTime = _this.getDateStr();
  38. _this.queryParams.searhDate = [nowTime[0], nowTime[6]];
  39. _this.userForm = JSON.parse(getCookie("Admin-User"));
  40. console.log(getCookie("Admin-User"),1111)
  41. },
  42. mounted:function(){
  43. warmTypeChart = echarts.init(document.getElementById('warmType'));
  44. wramTypeRankChart = echarts.init(document.getElementById('wramTypeRank'));
  45. warmByShipChart = echarts.init(document.getElementById('warmByShip'));
  46. fuelTrendsChart = echarts.init(document.getElementById('fuelTrends'));
  47. _this.getShip();
  48. },
  49. methods: {
  50. getShip(){
  51. let _opts = {
  52. url: baseUrl + "/SelCctvListByUserId",
  53. type:"GET"
  54. };
  55. let _data = {
  56. "user_id": _this.userForm.userId
  57. };
  58. let _hea = {
  59. "Authorization": "Bearer " + getCookie("Admin-Token")
  60. };
  61. getAxios(_opts,_data,_hea).then((res) => {
  62. shipList = [];
  63. if(res.code == 200&&res.data.length){
  64. shipList = res.data;
  65. _this.getNumber();
  66. _this.getLineData();
  67. }
  68. })
  69. },
  70. getLineData(_name){
  71. let _opts = {
  72. url: vipUrl + "/algorithm/snapshotPush/statisticsNumDate",
  73. type:"POST"
  74. };
  75. let _data = JSON.stringify({
  76. users: (_name?[_name]:shipList.map(item => item.en_name)),
  77. enddate: _this.queryParams.searhDate[1],
  78. startdate: _this.queryParams.searhDate[0]
  79. });
  80. let _hea = {
  81. 'Content-Type': 'application/json;charset=utf-8',
  82. };
  83. postAxios(_opts, _data, _hea).then((res) => {
  84. let _objs = (_name?res.data.filter(istem => istem.user == _name):res.data);
  85. let _data = [];
  86. _objs.forEach((item,index) => {
  87. let _obj = item.rows;
  88. for(let i=0;i<nowTime.length;i++){
  89. if(_data[i] == undefined){
  90. _data[i] = 0
  91. }
  92. _data[i] += parseFloat((_obj[nowTime[i]] == undefined)?0:_obj[nowTime[i]]);
  93. }
  94. })
  95. let fuelTrendsData = {
  96. data: _data,
  97. xAxis: nowTime
  98. };
  99. fuelTrendsChart.setOption(_this.lineOption(fuelTrendsData));
  100. })
  101. },
  102. getNumber(_name){
  103. const loading = this.$loading({
  104. background: 'rgba(0, 0, 0, 0.4)'
  105. })
  106. setTimeout(()=>{
  107. let _opts = {
  108. url: vipUrl + "/algorithm/snapshotPush/statisticsTypeNum",
  109. type:"POST"
  110. };
  111. let _data = JSON.stringify({
  112. users: (_name?[_name]:shipList.map(item => item.en_name)),
  113. enddate: _this.queryParams.searhDate[1],
  114. startdate: _this.queryParams.searhDate[0]
  115. });
  116. let _hea = {
  117. 'Content-Type': 'application/json;charset=utf-8',
  118. };
  119. postAxios(_opts, _data, _hea).then((res) => {
  120. let warmByShipTable = [];
  121. let _behavior = 0, _article = 0;
  122. let _wramCount = {
  123. lgjc: 0,
  124. sjjc: 0,
  125. xyjc: 0,
  126. pljc: 0,
  127. lwjc: 0,
  128. xjjc: 0,
  129. zdjc: 0,
  130. aqjc: 0
  131. };
  132. let _objs = (_name?res.data.filter(istem => istem.user == _name):res.data);
  133. _objs.forEach((item,index) => {
  134. let _obj = item.rows;
  135. let _count = 0;
  136. let _names = shipList.filter(istem => istem.en_name == item.user)[0];
  137. for(let key in _obj){
  138. _count += parseFloat(_obj[key]);
  139. if(key == "tkjc" || key == "gzfjc"){
  140. _article += parseFloat(_obj[key]);
  141. _wramCount["aqjc"] += parseFloat(_obj[key]);
  142. }else{
  143. _behavior += parseFloat(_obj[key]);
  144. if(key == "ddhjc" || key == "wsjjc"){
  145. _wramCount["sjjc"] += parseFloat(_obj[key]);
  146. }else if(key == "lgjc"){
  147. _wramCount["lgjc"] += parseFloat(_obj[key]);
  148. }else if(key == "xyjc"){
  149. _wramCount["xyjc"] += parseFloat(_obj[key]);
  150. }else if(key == "sjjc" || key == "dksjc"){
  151. _wramCount["pljc"] += parseFloat(_obj[key]);
  152. }else if(key == "lwjc"){
  153. _wramCount["lwjc"] += parseFloat(_obj[key]);
  154. }else if(key == "xjjc"){
  155. _wramCount["lxjj"] += parseFloat(_obj[key]);
  156. }else if(key == "zdjc"){
  157. _wramCount["zdjc"] += parseFloat(_obj[key]);
  158. }
  159. }
  160. }
  161. warmByShipTable.push({
  162. total: _count,
  163. enName: item.user,
  164. shipName: _names["dev_name"]
  165. });
  166. });
  167. let warmTypeData = {
  168. sign: 'ring',
  169. data: [{ value: _behavior, name: '行为检测' },
  170. { value: _article, name: '物品检测' }]
  171. };
  172. _this.wramCount = _wramCount;
  173. if(_name == undefined){
  174. let sortObj = warmByShipTable.sort(function(a,b){ return a.total - b.total });
  175. let fifObj = sortObj.slice(0,5);
  176. let warmByShipData = {
  177. xAxis: fifObj.map(item => item.shipName),
  178. data: fifObj.map(item => item.total),
  179. };
  180. warmByShipChart.setOption(_this.periodOption(warmByShipData));
  181. _this.warmData = warmByShipTable.sort(function(a,b){ return b.total - a.total });
  182. }
  183. var _wramTxt = [{
  184. count: _wramCount["lgjc"],
  185. name: "离岗"},{
  186. count: _wramCount["sjjc"],
  187. name: "手机"},{
  188. count: _wramCount["xyjc"],
  189. name: "抽烟"},{
  190. count: _wramCount["pljc"],
  191. name: "疲劳"},{
  192. count: _wramCount["lwjc"],
  193. name: "未瞭望"},{
  194. count: _wramCount["xyjc"],
  195. name: "巡检"},{
  196. count: _wramCount["zdjc"],
  197. name: "遮挡"},{
  198. count: _wramCount["aqjc"],
  199. name: "安全穿戴"
  200. }];
  201. let typeObj = _wramTxt.sort(function(a,b){ return a.count - b.count });
  202. let wramTypeRankData = {
  203. xAxis: typeObj.map(item => item.name),
  204. data: typeObj.map(item => item.count)
  205. };
  206. warmTypeChart.setOption(_this.typeOption(warmTypeData));
  207. wramTypeRankChart.setOption(_this.periodOption(wramTypeRankData));
  208. loading.close();
  209. })
  210. },200)
  211. },
  212. periodOption(_data){
  213. let option = {
  214. tooltip: {
  215. trigger: 'axis',
  216. axisPointer: {
  217. type: 'shadow'
  218. }
  219. },
  220. grid: {
  221. top: '0%',
  222. left: '0%',
  223. right: '5%',
  224. bottom: '-7%',
  225. containLabel: true
  226. },
  227. xAxis: {
  228. type: 'value',
  229. boundaryGap: [0, 0.01],
  230. show:false
  231. },
  232. yAxis: {
  233. type: 'category',
  234. data: _data.xAxis,
  235. axisLine: {
  236. show: false,
  237. },
  238. axisLabel: {
  239. rotate : 0,
  240. color: "#cfcfcf",
  241. },
  242. splitLine: {
  243. show: false,
  244. }
  245. },
  246. series: [{
  247. data: _data.data,
  248. name: '实时数据',
  249. type: 'bar',
  250. barWidth: '14',
  251. itemStyle: {
  252. color:{
  253. type: 'linear',
  254. x: 0,
  255. y: 0,
  256. x2: 1,
  257. y2: 1,
  258. colorStops: [{
  259. offset: 0, color: '#C2BF55'
  260. }, {
  261. offset: 1, color: '#C26F55'
  262. }],
  263. global: false
  264. },
  265. barBorderRadius:[7, 7, 7, 7]
  266. },
  267. label: {
  268. show: true,
  269. position: 'right',
  270. color:"#00aaff"
  271. }
  272. }]
  273. };
  274. return option;
  275. },
  276. typeOption(_data){
  277. let option = {
  278. tooltip: {
  279. trigger: "item",
  280. formatter: "{a} <br/>{b} : {c} 个({d}%)"
  281. },
  282. legend: {
  283. top: "bottom",
  284. textStyle: {
  285. color: "#ddd"
  286. }
  287. },
  288. series: [{
  289. name: "告警类型占比",
  290. type: "pie",
  291. radius: '50%',
  292. center: ["50%", "40%"],
  293. itemStyle: {
  294. label: {
  295. formatter: '{d}%'
  296. }
  297. },
  298. data: _data.data,
  299. animationEasing: "cubicInOut",
  300. animationDuration: 1000
  301. }]
  302. }
  303. return option;
  304. },
  305. lineOption(_data){
  306. let option = {
  307. tooltip: {
  308. trigger: 'axis',
  309. axisPointer: {
  310. type: 'cross',
  311. crossStyle: {
  312. color: '#999'
  313. }
  314. }
  315. },
  316. xAxis: {
  317. type: 'category',
  318. boundaryGap: false,
  319. axisLabel: {
  320. fontSize: 12,
  321. color: "#cfcfcf"
  322. },
  323. data: _data.xAxis
  324. },
  325. grid: {
  326. top: '6%',
  327. left: '1%',
  328. right: '4%',
  329. bottom: '1%',
  330. containLabel: true
  331. },
  332. yAxis: {
  333. type: 'value',
  334. splitNumber: 3,
  335. axisLabel: {
  336. fontSize: 12,
  337. color: "#cfcfcf",
  338. showMaxLabel: true
  339. },
  340. splitLine: {
  341. show: true,
  342. lineStyle: {
  343. color: '#616161',
  344. }
  345. }
  346. },
  347. series: [{
  348. type: 'line',
  349. smooth: 0.4,
  350. symbol: 'circle',
  351. areaStyle: {
  352. color: "#C2BF55",
  353. opacity:1
  354. },
  355. itemStyle: {
  356. normal: {
  357. color: '#218066',
  358. lineStyle: {
  359. color: '#218066'
  360. }
  361. }
  362. },
  363. data: _data.data
  364. }]
  365. }
  366. return option;
  367. },
  368. handleCurrentChange(val){
  369. _this.getNumber(val.enName);
  370. _this.getLineData(val.enName);
  371. },
  372. resetQuery(){
  373. _this.getNumber();
  374. _this.getLineData();
  375. },
  376. // 获取近七天的时间
  377. getDateStr() {
  378. var base = new Date().getTime();
  379. var oneDay = 24 * 3600 * 1000;
  380. var date = [];
  381. var data = [Math.random() * 300];
  382. var time = new Date(base);
  383. date.push(parseTime(time, `{y}-{m}-{d}`));
  384. for (var i = 1; i <7; i++) {
  385. var now = new Date(base -= oneDay);
  386. date.push(parseTime(now, `{y}-{m}-{d}`));
  387. data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
  388. }
  389. var newdate = date.reverse()
  390. return newdate;
  391. }
  392. }
  393. })