mesProductArcWeldingInfo.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <% layout('/layouts/default.html', {title: '弧焊过程参数管理', libs: ['validate']}){ %>
  2. <div class="main-content">
  3. <div class="box box-main">
  4. <div class="box-header with-border">
  5. <div class="box-title">
  6. <i class="fa icon-note"></i> ${text(mesProductArcWelding.isNewRecord ? '新增弧焊过程参数管理' : '弧焊过程参数管理详情')}
  7. </div>
  8. <div class="box-tools pull-right">
  9. <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
  10. </button>
  11. </div>
  12. </div>
  13. <div id="app">
  14. <div ref="vChart" style="width: 100%;height: 500px;"></div>
  15. <br>
  16. <br>
  17. <div ref="iChart" style="width: 100%;height:500px;"></div>
  18. <br>
  19. <br>
  20. <div ref="speedChart" style="width: 100%;height:500px;"></div>
  21. <br>
  22. <br>
  23. <div class="col-sm-12">
  24. <table class="table table-bordered" style="table-layout: fixed;white-space: normal;">
  25. <thead>
  26. <tr>
  27. <template v-for="n in welderCount">
  28. <th>电压{{n}}</th>
  29. <th>电流{{n}}</th>
  30. <th>送丝速度{{n}}</th>
  31. <th>错误码{{n}}</th>
  32. <th>JOB号{{n}}</th>
  33. </template>
  34. <th>记录时间</th>
  35. </tr>
  36. </thead>
  37. <tbody>
  38. <tr v-for="(item,index) in myData" :key="index">
  39. <template v-for="n in welderCount">
  40. <td>{{ item['V' + n] }}</td>
  41. <td>{{ item['I' + n] }}</td>
  42. <td>{{ item['speed' + n] }}</td>
  43. <td>{{ item['code' + n] }}</td>
  44. <td>{{ item['JOB' + n] }}</td>
  45. </template>
  46. <td>{{ item.createDate }}</td>
  47. </tr>
  48. </tbody>
  49. </table>
  50. </div>
  51. </div>
  52. <div class="box-footer">
  53. <div class="row">
  54. <div class="col-sm-offset-2 col-sm-10">
  55. <button type="button" class="btn btn-sm btn-default" id="btnCancel"
  56. onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}
  57. </button>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <% } %>
  64. <script>
  65. $("#inputForm").validate({
  66. submitHandler: function (form) {
  67. js.ajaxSubmitForm($(form), function (data) {
  68. js.showMessage(data.message);
  69. if (data.result == Global.TRUE) {
  70. js.closeCurrentTabPage(function (contentWindow) {
  71. contentWindow.page();
  72. });
  73. }
  74. }, "json");
  75. }
  76. });
  77. </script>
  78. <script src="${ctxStatic}/echarts/4.2/echarts.min.js"></script>
  79. <script src="${ctxStatic}/common/elementui2.15.5/vue-2.6.14.js"></script>
  80. <script>
  81. const convertToArrayOfObjects = (arr, welderCount) => {
  82. return arr.map(str => {
  83. const values = str.split('|');
  84. const obj = {};
  85. for (let i = 0; i < welderCount; i++) {
  86. const baseIndex = i * 5;
  87. if (baseIndex + 4 >= values.length) break;
  88. obj['V' + (i + 1)] = parseFloat(values[baseIndex]) || 0;
  89. obj['I' + (i + 1)] = parseFloat(values[baseIndex + 1]) || 0;
  90. obj['speed' + (i + 1)] = parseFloat(values[baseIndex + 2]) || 0;
  91. obj['code' + (i + 1)] = parseInt(values[baseIndex + 3], 10) || 0;
  92. obj['JOB' + (i + 1)] = parseInt(values[baseIndex + 4], 10) || 0;
  93. }
  94. obj.createDate = values[welderCount * 5] || '';
  95. return obj;
  96. });
  97. };
  98. const unescapeHtml = (str) => {
  99. if (!str) return str;
  100. return str.replace(/&quot;/g, '"')
  101. .replace(/&amp;/g, '&')
  102. .replace(/&lt;/g, '<')
  103. .replace(/&gt;/g, '>')
  104. .replace(/&#39;/g, "'")
  105. .replace(/&nbsp;/g, ' ');
  106. };
  107. const getWelderCount = (content) => {
  108. if (!content || content === '' || content === '[]') return 2;
  109. try {
  110. content = unescapeHtml(content);
  111. let strArr;
  112. if (content.startsWith('[')) {
  113. strArr = JSON.parse(content);
  114. } else if (content.startsWith('"')) {
  115. strArr = JSON.parse(content);
  116. } else {
  117. strArr = content.slice(2, -2).split('","');
  118. }
  119. if (!strArr || strArr.length === 0 || !strArr[0]) return 2;
  120. const firstRecord = strArr[0];
  121. const values = firstRecord.split('|');
  122. const fieldCount = values.length - 1;
  123. return Math.floor(fieldCount / 5) || 2;
  124. } catch (e) {
  125. console.error('解析焊机数量出错:', e);
  126. return 2;
  127. }
  128. };
  129. const parseContent = (content) => {
  130. if (!content || content === '' || content === '[]') return [];
  131. try {
  132. content = unescapeHtml(content);
  133. let strArr;
  134. if (content.startsWith('[')) {
  135. strArr = JSON.parse(content);
  136. } else if (content.startsWith('"')) {
  137. strArr = JSON.parse(content);
  138. } else {
  139. strArr = content.slice(2, -2).split('","');
  140. }
  141. if (!strArr || strArr.length === 0) return [];
  142. const welderCount = getWelderCount(content);
  143. return convertToArrayOfObjects(strArr, welderCount);
  144. } catch (e) {
  145. console.error('解析content出错:', e, content);
  146. return [];
  147. }
  148. };
  149. new Vue({
  150. el: '#app',
  151. data: {
  152. content: '${mesProductArcWelding.content!\'\'}',
  153. welderCount: 2,
  154. vChart: null,
  155. iChart: null,
  156. speedChart: null
  157. },
  158. computed: {
  159. myData() {
  160. return parseContent(this.content);
  161. },
  162. timeArr() {
  163. if (!this.myData || this.myData.length === 0) return [];
  164. arr = []
  165. for (let i = 0; i < this.myData.length; i++) {
  166. const {createDate} = this.myData[i]
  167. if (createDate) {
  168. arr.push(createDate.slice(14))
  169. }
  170. }
  171. return arr
  172. },
  173. vOption() {
  174. const series = [];
  175. const legendData = [];
  176. for (let i = 1; i <= this.welderCount; i++) {
  177. legendData.push('电压' + i);
  178. const arr = [];
  179. for (let j = 0; j < this.myData.length; j++) {
  180. arr.push(this.myData[j]['V' + i]);
  181. }
  182. series.push({
  183. name: '电压' + i,
  184. type: 'line',
  185. data: arr,
  186. smooth: true
  187. });
  188. }
  189. let option = {
  190. title: {
  191. text: '电压变化折线图'
  192. },
  193. tooltip: {
  194. trigger: 'axis'
  195. },
  196. legend: {
  197. data: legendData
  198. },
  199. grid: {
  200. left: '3%',
  201. right: '4%',
  202. bottom: '3%',
  203. containLabel: true
  204. },
  205. toolbox: {
  206. feature: {
  207. saveAsImage: {}
  208. }
  209. },
  210. xAxis: {
  211. type: 'category',
  212. name: '时间',
  213. boundaryGap: false,
  214. data: this.timeArr
  215. },
  216. yAxis: {
  217. name: "电压",
  218. type: 'value'
  219. },
  220. series: series
  221. };
  222. return option
  223. },
  224. iOption() {
  225. const series = [];
  226. const legendData = [];
  227. for (let i = 1; i <= this.welderCount; i++) {
  228. legendData.push('电流' + i);
  229. const arr = [];
  230. for (let j = 0; j < this.myData.length; j++) {
  231. arr.push(this.myData[j]['I' + i]);
  232. }
  233. series.push({
  234. name: '电流' + i,
  235. type: 'line',
  236. data: arr,
  237. smooth: true
  238. });
  239. }
  240. let option = {
  241. title: {
  242. text: '电流变化折线图'
  243. },
  244. tooltip: {
  245. trigger: 'axis'
  246. },
  247. legend: {
  248. data: legendData
  249. },
  250. grid: {
  251. left: '3%',
  252. right: '4%',
  253. bottom: '3%',
  254. containLabel: true
  255. },
  256. toolbox: {
  257. feature: {
  258. saveAsImage: {}
  259. }
  260. },
  261. xAxis: {
  262. type: 'category',
  263. name: '时间',
  264. boundaryGap: false,
  265. data: this.timeArr,
  266. },
  267. yAxis: {
  268. name: "电流",
  269. type: 'value'
  270. },
  271. series: series
  272. };
  273. return option
  274. },
  275. speedOption() {
  276. const series = [];
  277. const legendData = [];
  278. for (let i = 1; i <= this.welderCount; i++) {
  279. legendData.push('送丝速度' + i);
  280. const arr = [];
  281. for (let j = 0; j < this.myData.length; j++) {
  282. arr.push(this.myData[j]['speed' + i]);
  283. }
  284. series.push({
  285. name: '送丝速度' + i,
  286. type: 'line',
  287. data: arr,
  288. smooth: true
  289. });
  290. }
  291. let option = {
  292. title: {
  293. text: '送丝速度变化折线图'
  294. },
  295. tooltip: {
  296. trigger: 'axis'
  297. },
  298. legend: {
  299. data: legendData
  300. },
  301. grid: {
  302. left: '3%',
  303. right: '4%',
  304. bottom: '3%',
  305. containLabel: true
  306. },
  307. toolbox: {
  308. feature: {
  309. saveAsImage: {}
  310. }
  311. },
  312. xAxis: {
  313. type: 'category',
  314. name: '时间',
  315. boundaryGap: false,
  316. data: this.timeArr,
  317. },
  318. yAxis: {
  319. name: "速度",
  320. type: 'value'
  321. },
  322. series: series
  323. };
  324. return option
  325. }
  326. },
  327. watch: {
  328. myData: {
  329. handler() {
  330. if (this.vChart) {
  331. this.welderCount = getWelderCount(this.content);
  332. this.vChart.setOption(this.vOption, true);
  333. this.iChart.setOption(this.iOption, true);
  334. this.speedChart.setOption(this.speedOption, true);
  335. }
  336. },
  337. deep: true
  338. }
  339. },
  340. mounted() {
  341. if (this.content && this.content !== '' && this.content !== '[]') {
  342. this.welderCount = getWelderCount(this.content);
  343. }
  344. this.$nextTick(() => {
  345. this.vChart = echarts.init(this.$refs.vChart)
  346. this.iChart = echarts.init(this.$refs.iChart)
  347. this.speedChart = echarts.init(this.$refs.speedChart)
  348. this.vChart.setOption(this.vOption);
  349. this.iChart.setOption(this.iOption);
  350. this.speedChart.setOption(this.speedOption);
  351. });
  352. }
  353. })
  354. </script>