macstatus-detail.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  1. var prefix = server + "/eap/api/";
  2. var types = [
  3. { name: "RUN", desc: "运行", color: "rgb(61, 149, 73)" },
  4. { name: "DISCONN", desc: "未连接", color: "rgb(178, 178, 178)" },
  5. { name: "REPAIR", desc: "维修", color: "rgb(178, 0, 89)" },
  6. { name: "PM", desc: "保养", color: "rgb(178, 98, 0)" },
  7. { name: "ERROR", desc: "错误", color: "rgb(178, 30, 30)" },
  8. { name: "IDLE", desc: "空闲", color: "rgba(178, 178, 0, 1)" },
  9. { name: "CHANGE", desc: "改机", color: "rgb(7, 87, 126)" },
  10. ];
  11. var chartLoading = {
  12. text: "正在加载...",
  13. color: "#B21E1E",
  14. textColor: "#B21E1E",
  15. };
  16. var macCode = getQueryStringByName("macCode");
  17. var time = getQueryStringByName("date");
  18. var shift = "";
  19. var alarmBarChart;
  20. var timeOut = null;
  21. $(function () {
  22. if (!macCode) {
  23. alert("请传入正确的设备号");
  24. return;
  25. }
  26. alarmBarChart = echarts.init(document.getElementById("alarmBar"));
  27. initPage({
  28. macCode: macCode,
  29. time: time || dateFormat("yyyy-MM-dd HH:mm:ss", new Date()),
  30. shift: shift,
  31. });
  32. alarmBarChart.on("click", function (params) {
  33. layer.open({
  34. type: 2,
  35. title: `机台【${macCode} ${params.name} ${params.seriesName}】报警明细`,
  36. shadeClose: true,
  37. shade: false,
  38. maxmin: true, //开启最大化最小化按钮
  39. area: ["993px", "600px"],
  40. content: `./mac-alarm-detail.html?fcode=${macCode}&date=${
  41. params.name
  42. }&shift=${escape(params.seriesName)}`,
  43. });
  44. });
  45. });
  46. function showLoading() {
  47. layer.load();
  48. }
  49. var intervalOne = "";
  50. var intervalTwo = "";
  51. function getMacCode() {
  52. return {
  53. date: dateFormat("yyyy-MM-dd", new Date(time)),
  54. macCode: macCode,
  55. };
  56. }
  57. function showLoading() {
  58. hideNav($(".rightNav"), $(".bgDiv"));
  59. layer.load();
  60. }
  61. // 检查机台号是否存在
  62. function checkMchineIfExist(macCode) {
  63. return axios.get(`${server}/eap/api/machine/getbycode?code=${macCode}`);
  64. }
  65. // 初始化页面
  66. function initPage(obj) {
  67. macCode = obj.macCode;
  68. time = new Date(obj.time);
  69. shift = obj.shift;
  70. checkMchineIfExist(obj.macCode).then((res) => {
  71. // console.log(res);
  72. if (res && res.data) {
  73. var startTime = dateFormat(
  74. "yyyy-MM-dd HH:mm:ss",
  75. new Date(getStartTime(obj.time, shift))
  76. );
  77. var dateStart = new Date(startTime);
  78. var et = new Date(startTime);
  79. var endTime = "";
  80. var isBetween = isBetweenZeroAndShiftStart(et);
  81. if (
  82. dateFormat("yyyy-MM-dd", et) === dateFormat("yyyy-MM-dd", new Date()) ||
  83. isBetween
  84. ) {
  85. endTime = dateFormat("yyyy-MM-dd HH:mm:ss", new Date());
  86. } else {
  87. endTime = dateFormat(
  88. "yyyy-MM-dd HH:mm:ss",
  89. new Date(et.setHours(et.getHours() + 24))
  90. );
  91. }
  92. $("#equipmentID").text(macCode);
  93. $("#date").text(dateFormat("yyyy-MM-dd", new Date(startTime)));
  94. if (intervalOne) {
  95. clearInterval(intervalOne);
  96. }
  97. // if (intervalTwo) {
  98. // clearInterval(intervalTwo);
  99. // }
  100. layer.load();
  101. initHeader(macCode, startTime, endTime);
  102. loadStatusAndAlarm(macCode, startTime, endTime);
  103. loadDayOutput(macCode, startTime, endTime);
  104. loadTimeOutput(macCode, startTime, endTime);
  105. renderRunHistory(macCode, startTime, endTime);
  106. if (
  107. dateFormat("yyyy-MM-dd", dateStart) ===
  108. dateFormat("yyyy-MM-dd", new Date()) ||
  109. isBetweenZeroAndShiftStart(dateStart)
  110. ) {
  111. intervalOne = setInterval(() => {
  112. //if (dateFormat('yyyy-MM-dd', et) === dateFormat('yyyy-MM-dd', new Date())) {
  113. endTime = dateFormat("yyyy-MM-dd HH:mm:ss", new Date());
  114. //}
  115. initHeader(macCode, startTime, endTime);
  116. loadStatusAndAlarm(macCode, startTime, endTime);
  117. loadDayOutput(macCode, startTime, endTime);
  118. loadTimeOutput(macCode, startTime, endTime);
  119. }, 60 * 1000);
  120. // intervalTwo = setInterval(() => {
  121. // //if (dateFormat('yyyy-MM-dd', et) === dateFormat('yyyy-MM-dd', new Date())) {
  122. // }, 60 * 1000);
  123. }
  124. } else {
  125. layer.closeAll("loading");
  126. alert("设备ID不存在");
  127. }
  128. });
  129. }
  130. //获取班别开始时间
  131. function getStartTime(time, shift) {
  132. var dateTime = new Date(time);
  133. var hhmmss = dateFormat("HH:mm", dateTime) + "";
  134. var startTime;
  135. // if (typeof shift == "undefined" || shift == null || shift == "") {
  136. // if ('00:00' <= hhmmss && hhmmss <= '08:00') {
  137. // startTime = dateFormat('yyyy-MM-dd', (new Date(dateTime.setDate(dateTime.getDate() - 1)))) + ' 20:00:00';
  138. // } else if ('08:00' <= hhmmss && hhmmss <= '20:00') {
  139. // startTime = dateFormat('yyyy-MM-dd', dateTime) + ' 08:00:00';
  140. // } else if ('20:00' <= hhmmss && hhmmss <= '23:59') {
  141. // startTime = dateFormat('yyyy-MM-dd', dateTime) + ' 20:00:00';
  142. // }
  143. startTime = dateFormat("yyyy-MM-dd", new Date(time)) + " 08:30:00";
  144. var dateNow = new Date();
  145. if (dateNow < new Date(startTime)) {
  146. var st = new Date(startTime);
  147. st = new Date(st.setDate(st.getDate() - 1));
  148. startTime = dateFormat("yyyy-MM-dd", st) + " 08:30:00";
  149. }
  150. //}
  151. // else if (shift == '1') {
  152. // startTime = dateFormat('yyyy-MM-dd', new Date(time)) + ' 08:30:00';
  153. // } else {
  154. // startTime = dateFormat('yyyy-MM-dd', new Date(time)) + ' 20:30:00';
  155. // }
  156. //console.log(startTime, shift);
  157. return startTime;
  158. }
  159. function isBetweenZeroAndShiftStart(time) {
  160. var dateDiff =
  161. (new Date().getTime() - time.getTime()) / (24 * 60 * 60 * 1000);
  162. // alert(dateDiff);
  163. var todayShiftStartDate = new Date(
  164. dateFormat("yyyy-MM-dd", new Date()) + " 08:30:00"
  165. );
  166. //alert(todayShiftStartDate);
  167. return dateDiff < 1 && new Date() < todayShiftStartDate;
  168. }
  169. // 加载头部数据
  170. function initHeader(macCode, startTime, endTime) {
  171. axios
  172. .get(`${prefix}MacStatusTotalInfo/GetTotalInfoDeatil`, {
  173. params: {
  174. macCode: macCode,
  175. startTime: startTime,
  176. endTime: endTime,
  177. t: new Date().getMilliseconds(),
  178. },
  179. })
  180. .then((res) => {
  181. layer.closeAll("loading");
  182. if (res && res.code === 1) {
  183. var obj = res.data;
  184. $("#alarmCount").text(obj.alarmCount);
  185. // $('#runTimes').text(obj.runTime);
  186. // $('#runRate').text(obj.runRate + '%');
  187. $("#todayOutput").text(obj.todayCount);
  188. $("#monthOutput").text(obj.monthCount);
  189. $("#recipe").text(obj.recipe);
  190. $("#status")
  191. .removeClass()
  192. .addClass("conuts")
  193. .css(
  194. "color",
  195. `rgb(${obj.color.red},${obj.color.green},${obj.color.blue})`
  196. );
  197. $("#status").text(obj.statusCode);
  198. $("#regionName").text(obj.factory);
  199. } else {
  200. alert("获取数据失败");
  201. }
  202. })
  203. .catch((resp) => {
  204. console.log("请求失败:" + resp.status + "," + resp.statusText);
  205. });
  206. }
  207. // 加载机台状态分布与报警统计
  208. function loadStatusAndAlarm(macCode, startTime, endTime) {
  209. var statusChart = echarts.init(document.getElementById("macStatusPie"));
  210. var dateNow = new Date();
  211. alarmBarChart.showLoading(chartLoading);
  212. statusChart.showLoading(chartLoading);
  213. axios
  214. .get(prefix + "MacStatusTotalInfo/GetTotalInfoDeatilForAnalysis", {
  215. params: {
  216. macCode,
  217. startTime: startTime,
  218. endTime: endTime,
  219. },
  220. })
  221. .then((res) => {
  222. if (res && res.code === 1) {
  223. if (res.data.runrate && res.data.runrate.length > 0) {
  224. var legends = [];
  225. var data = [];
  226. var runRates = res.data.runrate;
  227. var totalTime = 0;
  228. var runTime = 0;
  229. runRates.forEach((element) => {
  230. if (element.name === "运行") runTime = element.value;
  231. totalTime += element.value;
  232. legends.push(element.name);
  233. data.push({
  234. name: element.name,
  235. y: element.value,
  236. dataLabels: {
  237. distance: 12,
  238. style: {
  239. color: "#eee",
  240. fontSize: "12px",
  241. textOutline: "none",
  242. },
  243. // backgroundColor:`transparent`,
  244. // fontWeight:'bold',
  245. // color: `rgb(${element.color.red},${element.color.green},${element.color.blue})`
  246. formatter: function () {
  247. return (
  248. '<p style="color:' +
  249. this.color +
  250. '">' +
  251. this.point.name +
  252. '</p><br><p style="color:' +
  253. this.color +
  254. '">' +
  255. this.percentage.toFixed(1) +
  256. "%</p>"
  257. );
  258. },
  259. },
  260. color: `rgb(${element.color.red},${element.color.green},${element.color.blue})`,
  261. });
  262. // data.push({
  263. // value: element.value,
  264. // name: element.name,
  265. // itemStyle: {
  266. // normal: {
  267. // color: `rgb(${element.color.red},${element.color.green},${element.color.blue})`
  268. // }
  269. // }
  270. // });
  271. });
  272. render3DStatusPie("macStatusPie", legends, data);
  273. $("#runTimes").text(runTime);
  274. $("#runRate").text(((runTime / totalTime) * 100).toFixed(2) + "%");
  275. }
  276. if (res.data.runTimes && res.data.runTimes.length > 0) {
  277. //#region
  278. // var alarms = res.data.runTimes;
  279. // var xdata = [];
  280. // var ydata = [];
  281. // alarms.forEach(item => {
  282. // item.alarmCount = parseInt(item.alarmCount);
  283. // xdata.push(item.alarmCode);
  284. // ydata.push(parseInt(item.alarmCount));
  285. // });
  286. // var chartDto = {
  287. // title: '报警统计图',
  288. // legend: [],
  289. // xdata: xdata,
  290. // ydata: ydata
  291. // };
  292. // renderAlarmBar(alarmBarChart, chartDto, res.data.runTimes);
  293. var datas = res.data.runTimes;
  294. var xDatas = []; // X轴文字
  295. var legends = []; // 图例文字
  296. var seriesData = [];
  297. datas.forEach((item) => {
  298. if (xDatas.indexOf(item.day) === -1) {
  299. xDatas.push(item.day);
  300. }
  301. if (legends.indexOf(item.class) === -1) {
  302. legends.push(item.class);
  303. }
  304. });
  305. if (legends.length > 0) {
  306. legends.forEach((item) => {
  307. var classOutPuts = [];
  308. datas.forEach((element) => {
  309. if (element.class === item) {
  310. classOutPuts.push(parseInt(element.count));
  311. }
  312. });
  313. seriesData.push({
  314. key: item,
  315. values: classOutPuts,
  316. });
  317. });
  318. }
  319. var colorStopses = [
  320. [
  321. {
  322. offset: 0,
  323. color: "#E69D87",
  324. },
  325. {
  326. offset: 1,
  327. color: "#E69D87",
  328. },
  329. ],
  330. [
  331. {
  332. offset: 0,
  333. color: "#D43239",
  334. },
  335. {
  336. offset: 1,
  337. color: "#D43239",
  338. },
  339. ],
  340. ];
  341. var barColors = ["#0035f9", "#25f3e6"];
  342. var series = [];
  343. seriesData.forEach((item, index) => {
  344. //#region ECharts数据
  345. // var obj = {
  346. // name: item.key,
  347. // type: "bar",
  348. // data: item.values,
  349. // barWidth: "30%",
  350. // itemStyle: {
  351. // normal: {
  352. // color: {
  353. // type: "linear",
  354. // x: 0,
  355. // y: 0,
  356. // x2: 0,
  357. // y2: 1,
  358. // colorStops: colorStopses[index],
  359. // globalCoord: false
  360. // }
  361. // }
  362. // },
  363. // label: {
  364. // show: true,
  365. // color: '#fff',
  366. // position: 'top',
  367. // formatter: function (params) {
  368. // if (params.data == 0) {
  369. // return '';
  370. // }
  371. // return params.data;
  372. // }
  373. // },
  374. // barGap: "0"
  375. // };
  376. //#endregion
  377. var obj = {
  378. name: item.key,
  379. data: item.values,
  380. dataLabels: {
  381. enabled: true,
  382. color: "#FFFFFF",
  383. align: "center",
  384. },
  385. };
  386. series.push(obj);
  387. });
  388. var chartDto = {
  389. legends: legends,
  390. series: series,
  391. };
  392. statusChart.hideLoading();
  393. render3DTwoDayAlarm("alarmBar", series, xDatas);
  394. } else {
  395. }
  396. } else {
  397. alert("加载机台状态与报警数据失败");
  398. }
  399. })
  400. .catch((resp) => {
  401. console.log("请求失败:" + resp.status + "," + resp.statusText);
  402. });
  403. }
  404. // 绘制饼图
  405. function renderMacStatusPie(chart, legends, data) {
  406. // 基于准备好的dom,初始化echarts实例
  407. chart.hideLoading();
  408. var option = {
  409. tooltip: {
  410. trigger: "item",
  411. formatter: "{b} : {c} 分钟 ({d}%)",
  412. },
  413. legend: {
  414. top: "15%",
  415. data: legends,
  416. icon: "circle",
  417. textStyle: {
  418. color: "rgba(255,255,255,.6)",
  419. },
  420. show: false,
  421. },
  422. grid: {
  423. left: "15%",
  424. top: "15%",
  425. right: "15%",
  426. bottom: "15%",
  427. show: false,
  428. },
  429. calculable: true,
  430. series: [
  431. {
  432. name: "",
  433. color: [
  434. "#62c98d",
  435. "#2f89cf",
  436. "#4cb9cf",
  437. "#53b666",
  438. "#62c98d",
  439. "#205acf",
  440. "#c9c862",
  441. "#c98b62",
  442. "#c962b9",
  443. "#c96262",
  444. ],
  445. type: "pie",
  446. radius: "70%",
  447. //饼图的半径,数组的第一项是内半径,第二项是外半径
  448. radius: ["30%", "70%"],
  449. //支持设置成百分比,设置成百分比时第一项是相对于容器宽度,第二项是相对于容器高度
  450. center: ["50%", "55%"],
  451. //是否展示成南丁格尔图,通过半径区分数据大小。可选择两种模式:
  452. // 'radius' 面积展现数据的百分比,半径展现数据的大小。
  453. // 'area' 所有扇区面积相同,仅通过半径展现数据大小
  454. // roseType: 'radius',
  455. //是否启用防止标签重叠策略,默认开启,圆环图这个例子中需要强制所有标签放在中心位置,可以将该值设为 false。
  456. avoidLabelOverlap: false,
  457. label: {
  458. normal: {
  459. show: true,
  460. // formatter: '{c}辆'
  461. },
  462. // emphasis: {
  463. // show: true
  464. // }
  465. },
  466. labelLine: {
  467. normal: {
  468. show: true,
  469. length2: 1,
  470. },
  471. emphasis: {
  472. show: true,
  473. },
  474. },
  475. data: data,
  476. },
  477. ],
  478. };
  479. // 使用刚指定的配置项和数据显示图表。
  480. chart.setOption(option);
  481. window.addEventListener("resize", function () {
  482. chart.resize();
  483. });
  484. }
  485. // 绘制机台状态3D饼图
  486. function render3DStatusPie(chart, legends, data) {
  487. var chartPie;
  488. var option = {
  489. chart: {
  490. type: "pie",
  491. backgroundColor: "transparent",
  492. options3d: {
  493. enabled: true,
  494. alpha: 45,
  495. },
  496. renderTo: chart,
  497. },
  498. title: {
  499. text: null,
  500. },
  501. plotOptions: {
  502. pie: {
  503. innerSize: 45,
  504. depth: 35,
  505. },
  506. },
  507. credits: {
  508. enabled: false,
  509. },
  510. tooltip: {
  511. formatter: function () {
  512. return (
  513. "<b>" +
  514. this.point.name +
  515. "</b>: " +
  516. Highcharts.numberFormat(this.percentage, 2) +
  517. "% (" +
  518. Highcharts.numberFormat(this.y, 2, ".") +
  519. " 分钟)"
  520. );
  521. },
  522. },
  523. series: [
  524. {
  525. name: "状态",
  526. // dataLabels: {
  527. // enabled: true,
  528. // color:'#fff'
  529. // },
  530. data: [],
  531. },
  532. ],
  533. };
  534. option.series[0].data = data;
  535. chartPie = Highcharts.chart(option);
  536. }
  537. // 加载两日产量
  538. function loadDayOutput(macCode, startTime, endTime) {
  539. var myChart = echarts.init(document.getElementById("twoDaysOutputBar"));
  540. myChart.showLoading(chartLoading);
  541. axios
  542. .get(`${prefix}MacStatusTotalInfo/GetTotalInfoDeatilForCount`, {
  543. params: {
  544. macCode,
  545. time: dateFormat("yyyy-MM-dd HH:mm:ss", new Date(startTime)),
  546. },
  547. })
  548. .then((res) => {
  549. if (res && res.code === 1) {
  550. var datas = res.data;
  551. var xDatas = []; // X轴文字
  552. var legends = []; // 图例文字
  553. var seriesData = [];
  554. datas.forEach((item) => {
  555. if (xDatas.indexOf(item.day) === -1) {
  556. xDatas.push(item.day);
  557. }
  558. if (legends.indexOf(item.class) === -1) {
  559. legends.push(item.class);
  560. }
  561. });
  562. if (legends.length > 0) {
  563. legends.forEach((item) => {
  564. var classOutPuts = [];
  565. datas.forEach((element) => {
  566. if (element.class === item) {
  567. var count = element.count;
  568. // if (count === '0') {
  569. // classOutPuts.push(null);
  570. // } else {
  571. classOutPuts.push(parseInt(element.count));
  572. //}
  573. }
  574. });
  575. seriesData.push({
  576. key: item,
  577. values: classOutPuts,
  578. });
  579. });
  580. }
  581. var colorStopses = [
  582. [
  583. {
  584. offset: 0,
  585. color: "#AE48F2",
  586. },
  587. {
  588. offset: 1,
  589. color: "#AE48F2",
  590. },
  591. ],
  592. [
  593. {
  594. offset: 0,
  595. color: "#66b8a7",
  596. },
  597. {
  598. offset: 1,
  599. color: "#66b8a7",
  600. },
  601. ],
  602. ];
  603. var barColors = ["#45C295", "#75FDD4"];
  604. var series = [];
  605. seriesData.forEach((item, index) => {
  606. //#region Ecahrts数据
  607. // var obj = {
  608. // name: item.key,
  609. // type: "bar",
  610. // data: item.values,
  611. // barWidth: "30%",
  612. // itemStyle: {
  613. // normal: {
  614. // color: {
  615. // type: "linear",
  616. // x: 0,
  617. // y: 0,
  618. // x2: 0,
  619. // y2: 1,
  620. // colorStops: colorStopses[index],
  621. // globalCoord: false
  622. // }
  623. // }
  624. // },
  625. // label: {
  626. // show: true,
  627. // color: '#fff',
  628. // position: 'top',
  629. // formatter: function (params) {
  630. // if (params.data == 0) {
  631. // return '';
  632. // }
  633. // return params.data;
  634. // }
  635. // },
  636. // barGap: "0"
  637. // };
  638. //#endregion
  639. var obj = {
  640. name: item.key,
  641. data: item.values,
  642. dataLabels: {
  643. enabled: true,
  644. color: "#FFFFFF",
  645. align: "center",
  646. formatter: function () {
  647. return this.y;
  648. },
  649. },
  650. };
  651. series.push(obj);
  652. });
  653. var chartDto = {
  654. legends: legends,
  655. series: series,
  656. };
  657. }
  658. myChart.hideLoading();
  659. render3DTwoDayOutput("twoDaysOutputBar", series, xDatas);
  660. // renderTwoDaysOutputBar(myChart, legends, xDatas, series);
  661. // renderTwoDaysOutputNew(myChart, chartDto);
  662. })
  663. .catch((resp) => {
  664. console.log("请求失败:" + resp.status + "," + resp.statusText);
  665. });
  666. }
  667. function renderTwoDaysOutputNew(chart, chartDto) {
  668. var myData = chartDto.legends;
  669. var databeast = {
  670. 1: [38, 25, 26, 32],
  671. };
  672. var databeauty = {
  673. 1: [11, 38, 23, 30],
  674. };
  675. var timeLineData = [1];
  676. var option = {
  677. baseOption: {
  678. backgroundColor: "transparent",
  679. timeline: {
  680. show: false,
  681. top: 0,
  682. data: [],
  683. },
  684. legend: {
  685. show: true,
  686. left: "30%",
  687. top: 30,
  688. icon: "rect",
  689. textStyle: {
  690. itemGap: 12, //图例每项之间的间隔
  691. color: [],
  692. fontStyle: "normal",
  693. fontFamily: "微软雅黑",
  694. fontSize: 14,
  695. },
  696. },
  697. tooltip: {
  698. show: true,
  699. trigger: "axis",
  700. formatter: "{b}<br/>{c} {a}",
  701. axisPointer: {
  702. type: "shadow",
  703. },
  704. },
  705. grid: [
  706. {
  707. show: false,
  708. left: "8%",
  709. top: 60,
  710. bottom: 0,
  711. containLabel: true,
  712. width: "30%",
  713. },
  714. {
  715. show: false,
  716. left: "57%",
  717. top: 60,
  718. bottom: 0,
  719. width: "0%",
  720. },
  721. {
  722. show: false,
  723. right: "8%",
  724. top: 60,
  725. bottom: 0,
  726. containLabel: true,
  727. width: "30%",
  728. },
  729. ],
  730. xAxis: [
  731. {
  732. type: "value",
  733. inverse: true,
  734. axisLine: {
  735. show: false,
  736. },
  737. axisTick: {
  738. show: false,
  739. },
  740. position: "top",
  741. axisLabel: {
  742. show: false,
  743. },
  744. splitLine: {
  745. show: false,
  746. },
  747. },
  748. {
  749. gridIndex: 1,
  750. show: false,
  751. },
  752. {
  753. gridIndex: 2,
  754. nameTextStyle: {
  755. color: "#50afff",
  756. fontSize: 14,
  757. },
  758. axisLine: {
  759. show: false,
  760. },
  761. axisTick: {
  762. show: false,
  763. },
  764. position: "top",
  765. axisLabel: {
  766. show: false,
  767. },
  768. splitLine: {
  769. show: false,
  770. },
  771. },
  772. ],
  773. yAxis: [
  774. {
  775. type: "category",
  776. inverse: true,
  777. position: "right",
  778. axisLine: {
  779. show: false,
  780. },
  781. axisTick: {
  782. show: false,
  783. },
  784. axisLabel: {
  785. show: false,
  786. },
  787. data: myData,
  788. },
  789. {
  790. gridIndex: 1,
  791. type: "category",
  792. inverse: true,
  793. position: "left",
  794. axisLine: {
  795. show: false,
  796. },
  797. axisTick: {
  798. show: false,
  799. },
  800. axisLabel: {
  801. show: true,
  802. textStyle: {
  803. color: "#fff",
  804. fontSize: 14,
  805. },
  806. },
  807. data: myData.map(function (value) {
  808. return {
  809. value: value,
  810. textStyle: {
  811. align: "center",
  812. },
  813. };
  814. }),
  815. },
  816. {
  817. gridIndex: 2,
  818. type: "category",
  819. inverse: true,
  820. position: "left",
  821. axisLine: {
  822. show: false,
  823. },
  824. axisTick: {
  825. show: false,
  826. },
  827. axisLabel: {
  828. show: false,
  829. },
  830. data: myData,
  831. },
  832. ],
  833. series: [
  834. ,
  835. {
  836. name: "今天",
  837. type: "bar",
  838. barWidth: 18,
  839. xAxisIndex: 2,
  840. yAxisIndex: 2,
  841. label: {
  842. normal: {
  843. show: true,
  844. position: "right",
  845. offset: [0, 0],
  846. textStyle: {
  847. color: "#fff",
  848. fontSize: 14,
  849. },
  850. },
  851. },
  852. itemStyle: {
  853. normal: {
  854. color: "#25f3e6",
  855. // barBorderRadius: 50
  856. },
  857. },
  858. data: databeauty[timeLineData[0]],
  859. },
  860. ],
  861. },
  862. options: [],
  863. };
  864. chart.hideLoading();
  865. chart.setOption(option);
  866. window.addEventListener("resize", function () {
  867. chart.resize();
  868. });
  869. }
  870. // 俩日产量3D柱状图
  871. function render3DTwoDayOutput(elementName, series, xdata) {
  872. var chart;
  873. var options = {
  874. chart: {
  875. type: "column",
  876. renderTo: elementName,
  877. // marginBottom: 30,
  878. // marginLeft: 20,
  879. // marginTop: 20,
  880. // marginRight: 20,
  881. margin: 30,
  882. backgroundColor: "rgba(0,0,0,0)",
  883. options3d: {
  884. enabled: true,
  885. alpha: 30,
  886. beta: 0,
  887. depth: 100,
  888. viewDistance: 100, // 视图距离,它对于计算角度影响在柱图和散列图非常重要。此值不能用于3D的饼图
  889. frame: {
  890. // Frame框架,3D图包含柱的面板,我们以X ,Y,Z的坐标系来理解,X轴与 Z轴所形成
  891. // 的面为bottom,Y轴与Z轴所形成的面为side,X轴与Y轴所形成的面为back,bottom、
  892. // side、back的属性一样,其中size为感官理解的厚度,color为面板颜色
  893. bottom: {
  894. size: 20,
  895. },
  896. side: {
  897. size: 1,
  898. color: "transparent",
  899. },
  900. back: {
  901. size: 1,
  902. color: "transparent",
  903. },
  904. },
  905. },
  906. },
  907. title: {
  908. text: null,
  909. },
  910. plotOptions: {
  911. column: {
  912. depth: 25,
  913. },
  914. },
  915. colors: ["#7cb5ec", "#e4d354"],
  916. credits: {
  917. enabled: false,
  918. },
  919. legend: {
  920. enabled: false,
  921. },
  922. xAxis: {
  923. categories: xdata,
  924. labels: {
  925. style: {
  926. color: "#fff",
  927. },
  928. },
  929. gridLineColor: "rgba(255,255,255,0.3)",
  930. },
  931. yAxis: {
  932. min: 0,
  933. minRange: 100,
  934. title: {
  935. text: null,
  936. },
  937. labels: {
  938. style: {
  939. color: "#fff",
  940. },
  941. },
  942. gridLineColor: "rgba(255,255,255,0.3)",
  943. },
  944. series: [],
  945. };
  946. options.series = series;
  947. chart = Highcharts.chart(options);
  948. }
  949. // 加载分时产量
  950. function loadTimeOutput(macCode, startTime, endTime) {
  951. var timeOutputBarCharat = echarts.init(
  952. document.getElementById("timeOutputBar", "walden")
  953. );
  954. timeOutputBarCharat.showLoading(chartLoading);
  955. axios
  956. .get(`${prefix}MacStatusTotalInfo/GetTotalInfoDeatilForCountHour`, {
  957. params: {
  958. macCode,
  959. time: dateFormat("yyyy-MM-dd HH:mm:ss", new Date(startTime)),
  960. },
  961. })
  962. .then((res) => {
  963. if (res && res.code === 1) {
  964. // appendOutputBar(timeOutputBarCharat, chartDto); // 渲染分时产量柱状图
  965. appendOutputLine(timeOutputBarCharat, res.data.countHour);
  966. } else {
  967. alert("加载分时产量失败");
  968. }
  969. })
  970. .catch((resp) => {
  971. console.log("请求失败:" + resp.status + "," + resp.statusText);
  972. });
  973. }
  974. // 分时产量折线图
  975. function appendOutputLine(chart, data) {
  976. var xData = [];
  977. var yData = [];
  978. xData.push(8);
  979. yData.push(null);
  980. data.forEach((item) => {
  981. if (item.hour === 8) {
  982. xData.push(item.hour + ":" + "30");
  983. } else {
  984. xData.push(item.hour);
  985. }
  986. yData.push(parseInt(item.count));
  987. });
  988. var chartDto = {
  989. xData: xData,
  990. yData: yData,
  991. };
  992. renderHourOutputLine(chart, chartDto);
  993. }
  994. // 根据返回的数据渲染分时产量柱状图
  995. function appendOutputBar(chart, data) {
  996. var xdata = [];
  997. var ydata = [];
  998. var countHours = res.data.countHour;
  999. if (countHours && countHours.length > 0) {
  1000. countHours.forEach((item) => {
  1001. xdata.push(item.hour.split(" ")[1].split(":")[0]);
  1002. ydata.push(item.count);
  1003. });
  1004. var chartDto = {
  1005. title: "分时产量",
  1006. legend: [],
  1007. xdata: xdata,
  1008. ydata: ydata,
  1009. };
  1010. }
  1011. renderHourOutputBar(chart, chartDto);
  1012. }
  1013. // 绘制两日报警柱状图
  1014. function renderTwoDaysAlarmBar(chart, legends, xData, series) {
  1015. var option = {
  1016. tooltip: {
  1017. trigger: "axis",
  1018. axisPointer: {
  1019. lineStyle: {
  1020. color: "#57617B",
  1021. },
  1022. },
  1023. },
  1024. legend: {
  1025. data: legends,
  1026. top: "0%",
  1027. textStyle: {
  1028. color: "rgba(255,255,255,0.9)", //图例文字
  1029. },
  1030. show: false,
  1031. },
  1032. xAxis: [
  1033. {
  1034. type: "category",
  1035. data: xData,
  1036. axisLine: { lineStyle: { color: "rgba(255,255,255,.1)" } },
  1037. axisLabel: {
  1038. textStyle: { color: "rgba(255,255,255,1)", fontSize: "14" },
  1039. },
  1040. },
  1041. ],
  1042. yAxis: [
  1043. {
  1044. type: "value",
  1045. name: "",
  1046. // "interval": 10,
  1047. axisLabel: {
  1048. show: true,
  1049. color: "#fff",
  1050. },
  1051. axisLine: { lineStyle: { color: "rgba(255,255,255,.4)" } }, //左线色
  1052. },
  1053. ],
  1054. grid: {
  1055. top: "15%",
  1056. right: "15%",
  1057. bottom: "15%",
  1058. left: "15%",
  1059. show: false,
  1060. },
  1061. series: series,
  1062. };
  1063. // 使用刚指定的配置项和数据显示图表。
  1064. chart.hideLoading();
  1065. chart.setOption(option);
  1066. window.addEventListener("resize", function () {
  1067. chart.resize();
  1068. });
  1069. }
  1070. // 俩日报警3D柱状图
  1071. function render3DTwoDayAlarm(elementName, series, xdata) {
  1072. var chart;
  1073. var options = {
  1074. chart: {
  1075. type: "column",
  1076. renderTo: elementName,
  1077. // marginBottom: 30,
  1078. // marginLeft: 20,
  1079. // marginTop: 20,
  1080. // marginRight: 20,
  1081. margin: 30,
  1082. backgroundColor: "rgba(0,0,0,0)",
  1083. options3d: {
  1084. enabled: true,
  1085. alpha: 30,
  1086. beta: 0,
  1087. depth: 100,
  1088. viewDistance: 100, // 视图距离,它对于计算角度影响在柱图和散列图非常重要。此值不能用于3D的饼图
  1089. frame: {
  1090. // Frame框架,3D图包含柱的面板,我们以X ,Y,Z的坐标系来理解,X轴与 Z轴所形成
  1091. // 的面为bottom,Y轴与Z轴所形成的面为side,X轴与Y轴所形成的面为back,bottom、
  1092. // side、back的属性一样,其中size为感官理解的厚度,color为面板颜色
  1093. bottom: {
  1094. size: 20,
  1095. },
  1096. side: {
  1097. size: 1,
  1098. color: "transparent",
  1099. },
  1100. back: {
  1101. size: 1,
  1102. color: "transparent",
  1103. },
  1104. },
  1105. },
  1106. },
  1107. title: {
  1108. text: null,
  1109. },
  1110. plotOptions: {
  1111. column: {
  1112. depth: 30,
  1113. },
  1114. cursor: "pointer",
  1115. series: {
  1116. cursor: "pointer",
  1117. events: {
  1118. click: function (event) {
  1119. layer.open({
  1120. type: 2,
  1121. title: `机台【${macCode} ${event.point.category} ${event.point.series.name}】报警明细`,
  1122. shadeClose: true,
  1123. shade: false,
  1124. maxmin: true, //开启最大化最小化按钮
  1125. area: ["993px", "600px"],
  1126. content: `./mac-alarm-detail.html?fcode=${macCode}&date=${
  1127. event.point.category
  1128. }&shift=${escape(event.point.series.name)}`,
  1129. });
  1130. },
  1131. },
  1132. },
  1133. },
  1134. colors: ["#E69D87", "#D43239"],
  1135. credits: {
  1136. enabled: false,
  1137. },
  1138. legend: {
  1139. enabled: false,
  1140. },
  1141. xAxis: {
  1142. categories: xdata,
  1143. labels: {
  1144. style: {
  1145. color: "#fff",
  1146. },
  1147. },
  1148. splitLine: {
  1149. show: false,
  1150. },
  1151. gridLineColor: "rgba(255,255,255,0.3)",
  1152. },
  1153. yAxis: {
  1154. min: 0,
  1155. minRange: 100,
  1156. title: {
  1157. text: null,
  1158. },
  1159. labels: {
  1160. style: {
  1161. color: "#fff",
  1162. },
  1163. },
  1164. gridLineColor: "rgba(255,255,255,0.3)",
  1165. },
  1166. series: [],
  1167. };
  1168. options.series = series;
  1169. chart = Highcharts.chart(options);
  1170. }
  1171. // 绘制两日产量柱状图
  1172. function renderTwoDaysOutputBar(chart, legends, xData, series) {
  1173. var option = {
  1174. tooltip: {
  1175. trigger: "axis",
  1176. axisPointer: {
  1177. lineStyle: {
  1178. color: "#57617B",
  1179. },
  1180. },
  1181. },
  1182. legend: {
  1183. data: legends,
  1184. top: "0%",
  1185. textStyle: {
  1186. color: "rgba(255,255,255,0.9)", //图例文字
  1187. },
  1188. show: false,
  1189. },
  1190. xAxis: [
  1191. {
  1192. type: "category",
  1193. data: xData,
  1194. axisLine: { lineStyle: { color: "rgba(255,255,255,.1)" } },
  1195. axisLabel: {
  1196. textStyle: { color: "rgba(255,255,255,1)", fontSize: "14" },
  1197. },
  1198. },
  1199. ],
  1200. yAxis: [
  1201. {
  1202. type: "value",
  1203. name: "",
  1204. // "interval": 10,
  1205. axisLabel: {
  1206. show: true,
  1207. color: "#fff",
  1208. },
  1209. axisLine: { lineStyle: { color: "rgba(255,255,255,.4)" } }, //左线色
  1210. },
  1211. ],
  1212. grid: {
  1213. top: "15%",
  1214. right: "15%",
  1215. bottom: "15%",
  1216. left: "15%",
  1217. show: false,
  1218. },
  1219. series: series,
  1220. };
  1221. // 使用刚指定的配置项和数据显示图表。
  1222. chart.hideLoading();
  1223. chart.setOption(option);
  1224. window.addEventListener("resize", function () {
  1225. chart.resize();
  1226. });
  1227. }
  1228. // 渲染分时产量柱状图
  1229. function renderHourOutputBar(chart, chartDto) {
  1230. var options = {
  1231. title: {
  1232. text: chartDto.text,
  1233. },
  1234. tooltip: {
  1235. // formatter: function (params, ticket, callback) {
  1236. // var toolTip = '';
  1237. // alarms.forEach(item => {
  1238. // if (item.alarmCode === params.name) {
  1239. // toolTip = item.alarmDescribe;
  1240. // }
  1241. // });
  1242. // return toolTip;
  1243. // }
  1244. },
  1245. legend: {
  1246. data: chartDto.legend,
  1247. },
  1248. grid: {
  1249. right: "15%",
  1250. bottom: "15%",
  1251. top: "15%",
  1252. left: "15%",
  1253. },
  1254. xAxis: {
  1255. data: chartDto.xdata,
  1256. axisLabel: {
  1257. interval: 2,
  1258. textStyle: {
  1259. color: "#fff",
  1260. },
  1261. },
  1262. },
  1263. yAxis: {
  1264. axisLabel: {
  1265. textStyle: {
  1266. color: "#fff",
  1267. },
  1268. },
  1269. },
  1270. series: [
  1271. {
  1272. name: "产量",
  1273. type: "bar",
  1274. barMaxWidth: 35,
  1275. data: chartDto.ydata,
  1276. itemStyle: {
  1277. normal: {
  1278. color: "rgb(120,200,235)",
  1279. label: {
  1280. show: false, // 开启显示
  1281. position: "top", // 在上方显示
  1282. textStyle: {
  1283. // 数值样式
  1284. color: "#fff",
  1285. fontSize: 12,
  1286. interval: 2,
  1287. },
  1288. },
  1289. },
  1290. },
  1291. },
  1292. ],
  1293. };
  1294. chart.hideLoading();
  1295. chart.setOption(options);
  1296. window.addEventListener("resize", function () {
  1297. chart.resize();
  1298. });
  1299. }
  1300. // 渲染分时产量折线图
  1301. function renderHourOutputLine(chart, chartDto) {
  1302. var options = {
  1303. tooltip: {
  1304. axisPointer: {
  1305. axis: "x",
  1306. type: "none",
  1307. },
  1308. position: function (pt) {
  1309. return [pt[0], "5%"];
  1310. },
  1311. formatter: function (params) {
  1312. // console.log(params);
  1313. return params.name + "点产量:" + params.value;
  1314. },
  1315. },
  1316. title: {
  1317. left: "left",
  1318. show: false,
  1319. },
  1320. legend: {
  1321. width: "70%",
  1322. show: false,
  1323. },
  1324. grid: {
  1325. right: "15%",
  1326. bottom: "15%",
  1327. top: "15%",
  1328. left: "15%",
  1329. },
  1330. xAxis: {
  1331. type: "category",
  1332. boundaryGap: false,
  1333. data: chartDto.xData,
  1334. axisLabel: {
  1335. // interval: 2,
  1336. textStyle: {
  1337. color: "#fff",
  1338. },
  1339. },
  1340. },
  1341. yAxis: {
  1342. type: "value",
  1343. axisLabel: {
  1344. // interval: 2,
  1345. textStyle: {
  1346. color: "#fff",
  1347. },
  1348. },
  1349. },
  1350. dataZoom: [
  1351. {
  1352. type: "inside",
  1353. start: 0,
  1354. end: 100,
  1355. },
  1356. {
  1357. start: 0,
  1358. end: 10,
  1359. handleSize: "80%",
  1360. show: false,
  1361. handleStyle: {
  1362. color: "#fff",
  1363. shadowBlur: 3,
  1364. shadowColor: "rgba(0, 0, 0, 0.6)",
  1365. shadowOffsetX: 2,
  1366. shadowOffsetY: 2,
  1367. },
  1368. },
  1369. ],
  1370. series: {
  1371. name: "产量",
  1372. type: "line",
  1373. data: chartDto.yData,
  1374. itemStyle: {
  1375. normal: {
  1376. color: "#F6C948",
  1377. label: {
  1378. show: true, // 开启显示
  1379. position: "top", // 在上方显示
  1380. textStyle: {
  1381. // 数值样式
  1382. color: "#fff",
  1383. fontSize: 11,
  1384. interval: 0,
  1385. },
  1386. },
  1387. },
  1388. },
  1389. },
  1390. };
  1391. chart.hideLoading();
  1392. chart.setOption(options);
  1393. window.addEventListener("resize", function () {
  1394. chart.resize();
  1395. });
  1396. }
  1397. // 渲染报警统计柱状图
  1398. function renderAlarmBar(chart, chartDto, alarms) {
  1399. var max = 0;
  1400. if (alarms && alarms.length > 0) {
  1401. max = alarms[0].alarmCount;
  1402. alarms.forEach((item) => {
  1403. if (max < item.alarmCount) {
  1404. max = item.alarmCount;
  1405. }
  1406. });
  1407. }
  1408. var options = {
  1409. title: {
  1410. text: chartDto.text,
  1411. },
  1412. tooltip: {
  1413. formatter: function (params, ticket, callback) {
  1414. var toolTip = "";
  1415. alarms.forEach((item) => {
  1416. if (item.alarmCode === params.name) {
  1417. toolTip = item.alarmDescribe;
  1418. }
  1419. });
  1420. return toolTip;
  1421. },
  1422. },
  1423. legend: {
  1424. data: chartDto.legend,
  1425. },
  1426. grid: {
  1427. right: "15%",
  1428. bottom: "15%",
  1429. top: "15%",
  1430. left: "15%",
  1431. },
  1432. xAxis: {
  1433. data: chartDto.xdata,
  1434. axisLabel: {
  1435. interval: 2,
  1436. textStyle: {
  1437. color: "#fff",
  1438. },
  1439. },
  1440. },
  1441. yAxis: {
  1442. // min: 0,
  1443. // max: max,
  1444. // splitNumber: 2,
  1445. axisLabel: {
  1446. textStyle: {
  1447. color: "#fff",
  1448. },
  1449. },
  1450. },
  1451. series: [
  1452. {
  1453. name: "报警次数",
  1454. type: "bar",
  1455. barMaxWidth: 35,
  1456. data: chartDto.ydata,
  1457. itemStyle: {
  1458. normal: {
  1459. color: "rgb(255,0,0)",
  1460. label: {
  1461. show: true, // 开启显示
  1462. position: "top", // 在上方显示
  1463. textStyle: {
  1464. // 数值样式
  1465. color: "#fff",
  1466. fontSize: 12,
  1467. },
  1468. },
  1469. },
  1470. },
  1471. },
  1472. ],
  1473. };
  1474. chart.hideLoading();
  1475. chart.setOption(options);
  1476. window.addEventListener("resize", function () {
  1477. chart.resize();
  1478. });
  1479. }
  1480. var legends = ["RUN", "DISCONN", "REPAIR", "PM", "ERROR", "IDLE", "CHANGE"];
  1481. //#region 稼动历史
  1482. // 渲染机台稼动历史图表
  1483. function renderRunHistory(macCode, startTime, endTime) {
  1484. var dateNow = new Date();
  1485. var dateStart = startTime;
  1486. var dateEnd = endTime;
  1487. axios
  1488. .get(`${prefix}MacStatusTotalInfo/GetRunHistroy`, {
  1489. params: {
  1490. macCode,
  1491. startTime: dateStart,
  1492. endTime: dateEnd,
  1493. },
  1494. })
  1495. .then((res) => {
  1496. if (res && res.code === 1) {
  1497. var data = [];
  1498. var categories = [""];
  1499. var datas = res.data;
  1500. datas.forEach((item, index) => {
  1501. data.push({
  1502. name: item.name,
  1503. value: [
  1504. index,
  1505. item.startTime,
  1506. item.endTime,
  1507. item.timeLen,
  1508. item.startString,
  1509. item.endString,
  1510. item.statusName,
  1511. item.duration,
  1512. ],
  1513. itemStyle: {
  1514. normal: {
  1515. color: `rgb(${item.color.red},${item.color.green},${item.color.blue})`,
  1516. },
  1517. },
  1518. });
  1519. });
  1520. option = {
  1521. tooltip: {
  1522. formatter: function (params) {
  1523. return (
  1524. params.marker +
  1525. params.value[6] +
  1526. ": " +
  1527. "从 " +
  1528. params.value[4] +
  1529. " 到 " +
  1530. params.value[5] +
  1531. " 持续 " +
  1532. params.value[7]
  1533. );
  1534. },
  1535. },
  1536. title: {
  1537. show: false,
  1538. },
  1539. grid: {
  1540. right: "5%",
  1541. height: 60,
  1542. top: "4%",
  1543. left: "5%",
  1544. },
  1545. legend: {
  1546. data: legends,
  1547. bottom: 0,
  1548. left: "center",
  1549. textStyle: {
  1550. color: "#ffffff",
  1551. },
  1552. },
  1553. dataZoom: [
  1554. {
  1555. type: "slider",
  1556. filterMode: "weakFilter",
  1557. showDataShadow: false,
  1558. show: false,
  1559. top: 150,
  1560. height: 5,
  1561. borderColor: "transparent",
  1562. backgroundColor: "#e2e2e2",
  1563. handleIcon:
  1564. "M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z", // jshint ignore:line
  1565. handleSize: 10,
  1566. handleStyle: {
  1567. shadowBlur: 6,
  1568. shadowOffsetX: 1,
  1569. shadowOffsetY: 2,
  1570. shadowColor: "#aaa",
  1571. },
  1572. labelFormatter: "",
  1573. },
  1574. {
  1575. type: "inside",
  1576. filterMode: "weakFilter",
  1577. },
  1578. ],
  1579. // grid: {
  1580. //
  1581. // },
  1582. xAxis: {
  1583. type: "time",
  1584. min: dateStart,
  1585. max: dateEnd,
  1586. axisLabel: {
  1587. formatter: function (val) {
  1588. var date = new Date(val);
  1589. var valStr = dateFormat("yyyy-MM-dd H:mm", date);
  1590. return valStr.split(" ")[1];
  1591. },
  1592. color: "#fff",
  1593. interval: 0,
  1594. },
  1595. },
  1596. yAxis: {
  1597. data: categories,
  1598. axisLabel: {
  1599. show: false,
  1600. },
  1601. },
  1602. series: [
  1603. {
  1604. type: "custom",
  1605. progressive: 0,
  1606. progressiveThreshold: 1,
  1607. renderItem: renderItem,
  1608. itemStyle: {
  1609. opacity: 1,
  1610. },
  1611. encode: {
  1612. x: [1, 2],
  1613. y: 0,
  1614. },
  1615. data: data,
  1616. },
  1617. ],
  1618. };
  1619. var runHistoryChart = echarts.init(
  1620. document.getElementById("runHistory", "walden")
  1621. );
  1622. runHistoryChart.setOption(option);
  1623. window.addEventListener("resize", function () {
  1624. runHistoryChart.resize();
  1625. });
  1626. var nowStr = dateFormat("yyyy-MM-dd", new Date()) + " 08:30:00";
  1627. var dayStart = new Date(
  1628. dateFormat("yyyy-MM-dd", new Date()) + " 00:00:00"
  1629. );
  1630. var todayShiftStart = new Date(
  1631. dateFormat("yyyy-MM-dd", new Date()) + " 08:30:00"
  1632. );
  1633. var now = new Date();
  1634. if (timeOut) {
  1635. clearTimeout(timeOut);
  1636. }
  1637. if (
  1638. dateStart == nowStr ||
  1639. isBetweenZeroAndShiftStart(new Date(dateStart))
  1640. ) {
  1641. timeOut = setTimeout(() => {
  1642. appendRunHistory(macCode, runHistoryChart, dateStart, true);
  1643. }, 60 * 1000);
  1644. }
  1645. } else {
  1646. alert("加载机台运行状态失败");
  1647. }
  1648. })
  1649. .catch((resp) => {
  1650. console.log("请求失败:" + resp.status + "," + resp.statusText);
  1651. });
  1652. }
  1653. function renderItem(params, api) {
  1654. var categoryIndex = api.value(0);
  1655. var start = api.coord([api.value(1), categoryIndex]);
  1656. var end = api.coord([api.value(2), categoryIndex]);
  1657. var height = api.size([0, 1])[1] * 1;
  1658. var rectShape = echarts.graphic.clipRectByRect(
  1659. {
  1660. x: start[0],
  1661. y: start[1] - height / 2,
  1662. width: end[0] - start[0],
  1663. height: height,
  1664. },
  1665. {
  1666. x: params.coordSys.x,
  1667. y: params.coordSys.y,
  1668. width: params.coordSys.width,
  1669. height: params.coordSys.height,
  1670. }
  1671. );
  1672. return (
  1673. rectShape && {
  1674. type: "rect",
  1675. shape: rectShape,
  1676. style: api.style(),
  1677. }
  1678. );
  1679. }
  1680. function appendRunHistory(macCode, runHistoryChart, startTime, interval) {
  1681. var dateNow = new Date();
  1682. var dateEndNew = dateFormat("yyyy-MM-dd HH:mm:ss", dateNow);
  1683. axios
  1684. .get(`${prefix}MacStatusTotalInfo/GetRunHistroy`, {
  1685. params: {
  1686. macCode,
  1687. startTime: startTime,
  1688. endTime: dateEndNew,
  1689. },
  1690. })
  1691. .then((res) => {
  1692. if (res && res.code === 1) {
  1693. var data = [];
  1694. var categories = [""];
  1695. var datas = res.data;
  1696. datas.forEach((item, index) => {
  1697. // var typeItem;
  1698. // types.forEach(t => {
  1699. // if (t.name === item.status) {
  1700. // typeItem = t;
  1701. // }
  1702. // });
  1703. data.push({
  1704. name: item.name,
  1705. value: [
  1706. index,
  1707. item.startTime,
  1708. item.endTime,
  1709. item.timeLen,
  1710. item.startString,
  1711. item.endString,
  1712. item.statusName,
  1713. item.duration,
  1714. ],
  1715. itemStyle: {
  1716. normal: {
  1717. color: `rgb(${item.color.red},${item.color.green},${item.color.blue})`,
  1718. },
  1719. },
  1720. });
  1721. });
  1722. runHistoryChart.setOption({
  1723. series: {
  1724. data: data,
  1725. },
  1726. xAxis: {
  1727. max: dateEndNew,
  1728. },
  1729. });
  1730. }
  1731. if (timeOut) {
  1732. clearTimeout(timeOut);
  1733. }
  1734. timeOut = setTimeout(() => {
  1735. appendRunHistory(macCode, runHistoryChart, startTime);
  1736. }, 60 * 1000);
  1737. })
  1738. .catch((resp) => {
  1739. console.log("请求失败:" + resp.status + "," + resp.statusText);
  1740. });
  1741. }
  1742. // 获取状态对应的颜色
  1743. function returnColor(status) {
  1744. var color = "#ccc";
  1745. types.forEach((item) => {
  1746. if (item.desc === status) {
  1747. color = item.color;
  1748. }
  1749. });
  1750. return color;
  1751. }
  1752. //#endregion