macstatus-detail_20220127091537.js 45 KB

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