index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px" style="text-align: center;">
  4. <el-form-item style="width: 208px; display: inline-block;">
  5. <div style="display: flex; align-items: center; justify-content: center;">
  6. <el-button icon="ArrowLeft" @click="navigateDay(-1)" size="small" style="margin-right: 15px;"></el-button>
  7. <el-date-picker clearable
  8. v-model="queryParams.dataDate"
  9. type="date"
  10. value-format="YYYY-MM-DD"
  11. placeholder="请选择日期"
  12. style="width: 130px"
  13. @change="handleQuery">
  14. </el-date-picker>
  15. <el-button icon="ArrowRight" @click="navigateDay(1)" size="small" style="margin-left: 15px;"></el-button>
  16. </div>
  17. </el-form-item>
  18. </el-form>
  19. <!-- 产线选择 -->
  20. <el-row :gutter="20" style="margin-bottom: 20px;">
  21. <el-col :span="24">
  22. <el-card>
  23. <div style="display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px;">
  24. <span>选择产线进行对比:</span>
  25. <el-button size="small" @click="selectAllLines">全选</el-button>
  26. <el-button size="small" @click="invertSelection">反选</el-button>
  27. <el-checkbox-group v-model="selectedLines" @change="getList" style="padding-left: 30px;">
  28. <el-checkbox v-for="line in allLines" :key="line" :label="line">{{ line }}</el-checkbox>
  29. </el-checkbox-group>
  30. </div>
  31. <!-- <div style="display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px;">-->
  32. <!-- <el-checkbox-group v-model="selectedLines" @change="getList">-->
  33. <!-- <el-checkbox v-for="line in allLines" :key="line" :label="line">{{ line }}</el-checkbox>-->
  34. <!-- </el-checkbox-group>-->
  35. <!-- </div>-->
  36. <div style="display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px;">
  37. <span>选择指标:</span>
  38. <el-button size="small" @click="selectAllMetrics">全选</el-button>
  39. <el-button size="small" @click="invertMetrics">反选</el-button>
  40. <el-checkbox-group v-model="selectedMetrics" @change="updateChart" style="padding-left: 30px;">
  41. <el-checkbox label="开机率">开机率</el-checkbox>
  42. <el-checkbox label="温度">温度</el-checkbox>
  43. <el-checkbox label="速度">速度</el-checkbox>
  44. <el-checkbox label="电量">电量</el-checkbox>
  45. <el-checkbox label="电流">电流</el-checkbox>
  46. </el-checkbox-group>
  47. </div>
  48. <!-- <div style="display: flex; align-items: center; flex-wrap: wrap; gap: 10px;">-->
  49. <!-- <el-checkbox-group v-model="selectedMetrics" @change="updateChart">-->
  50. <!-- <el-checkbox label="开机率">开机率</el-checkbox>-->
  51. <!-- <el-checkbox label="温度">温度</el-checkbox>-->
  52. <!-- <el-checkbox label="速度">速度</el-checkbox>-->
  53. <!-- <el-checkbox label="电量">电量</el-checkbox>-->
  54. <!-- <el-checkbox label="电流">电流</el-checkbox>-->
  55. <!-- </el-checkbox-group>-->
  56. <!-- </div>-->
  57. </el-card>
  58. </el-col>
  59. </el-row>
  60. <!-- 折线图和表格左右布局 -->
  61. <el-row :gutter="20">
  62. <!-- 左侧折线图 -->
  63. <el-col :span="12">
  64. <el-card style="margin-bottom: 20px;">
  65. <div ref="chartRef" style="width: 100%; height: 520px;"></div>
  66. </el-card>
  67. </el-col>
  68. <!-- 右侧表格 -->
  69. <el-col :span="12">
  70. <el-card style="margin-bottom: 20px;">
  71. <el-table :data="rzLineList" height="520" :span-method="spanMethod">
  72. <el-table-column label="小时" align="center" prop="hour" width="60" />
  73. <el-table-column label="产线" align="center" prop="line" width="60" />
  74. <el-table-column label="开机率(%)" align="center" prop="openRate" />
  75. <el-table-column label="温度(°C)" align="center" prop="tmp" />
  76. <el-table-column label="速度(米/min)" align="center" prop="speed" />
  77. <el-table-column label="电量(kW·h)" align="center" prop="energy" />
  78. <el-table-column label="电流(A)" align="center" prop="amp" />
  79. </el-table>
  80. </el-card>
  81. </el-col>
  82. </el-row>
  83. </div>
  84. </template>
  85. <script setup name="RzLine">
  86. import * as echarts from 'echarts';
  87. import { listRzLine, getRzLine, delRzLine, addRzLine, updateRzLine } from "@/api/dyeing/rzLine";
  88. const { proxy } = getCurrentInstance();
  89. const rzLineList = ref([]);
  90. const open = ref(false);
  91. const loading = ref(true);
  92. const showSearch = ref(true);
  93. const ids = ref([]);
  94. const single = ref(true);
  95. const multiple = ref(true);
  96. const total = ref(0);
  97. const title = ref("");
  98. const chartRef = ref(null);
  99. let chartInstance = null;
  100. const data = reactive({
  101. form: {},
  102. queryParams: {
  103. pageNum: 1,
  104. pageSize: 10000,
  105. dataDate: new Date(new Date().getTime() - 24 * 60 * 60 * 1000).Format('yyyy-MM-dd'),
  106. hour: null,
  107. lines: null,
  108. openRate: null,
  109. length: null,
  110. tmp: null,
  111. speed: null,
  112. energy: null,
  113. amp: null,
  114. createdBy: null,
  115. createdTime: null,
  116. updatedBy: null,
  117. updatedTime: null,
  118. remark: null
  119. },
  120. rules: {
  121. }
  122. });
  123. const selectedMetrics = ref(['开机率', '温度', '速度', '电量', '电流']);
  124. const selectedLines = ref(['1', '2', '3', '4', '5', '6', '7', '8']);
  125. const allLines = ref(['1', '2', '3', '4', '5', '6', '7', '8']);
  126. const { queryParams, form, rules } = toRefs(data);
  127. // 按产线分组的数据
  128. const groupedRzLineList = computed(() => {
  129. const grouped = {};
  130. rzLineList.value.forEach(item => {
  131. if (!grouped[item.line]) {
  132. grouped[item.line] = [];
  133. }
  134. grouped[item.line].push(item);
  135. });
  136. // 按产线编号排序
  137. const sortedGrouped = {};
  138. Object.keys(grouped).sort().forEach(key => {
  139. sortedGrouped[key] = grouped[key];
  140. });
  141. return sortedGrouped;
  142. });
  143. // 合并单元格处理函数
  144. const spanMethod = ({ row, column, rowIndex, columnIndex }) => {
  145. if (columnIndex === 0) { // 小时列
  146. // 获取当前行小时值
  147. const currentHour = row.hour;
  148. // 计算当前小时值第一次出现的位置
  149. let firstIndex = -1;
  150. for (let i = 0; i < rzLineList.value.length; i++) {
  151. if (rzLineList.value[i].hour === currentHour) {
  152. firstIndex = i;
  153. break;
  154. }
  155. }
  156. // 如果当前行是该小时值第一次出现的位置
  157. if (firstIndex === rowIndex) {
  158. // 计算该小时值连续出现的次数
  159. let spanCount = 0;
  160. for (let i = firstIndex; i < rzLineList.value.length; i++) {
  161. if (rzLineList.value[i].hour === currentHour) {
  162. spanCount++;
  163. } else {
  164. break;
  165. }
  166. }
  167. return [spanCount, 1];
  168. } else {
  169. // 如果不是第一次出现,隐藏该单元格
  170. return [0, 0];
  171. }
  172. }
  173. return [1, 1]; // 其他列不合并
  174. };
  175. function navigateDay(offset) {
  176. const currentDate = new Date(queryParams.value.dataDate);
  177. currentDate.setDate(currentDate.getDate() + offset);
  178. queryParams.value.dataDate = currentDate.toISOString().split('T')[0];
  179. handleQuery();
  180. }
  181. /** 查询染整线产线小时统计数据列表 */
  182. function getList() {
  183. // 检查是否选择了产线
  184. if (selectedLines.value.length === 0) {
  185. proxy.$modal.msgWarning("请至少选择一条产线进行对比");
  186. return;
  187. }
  188. // 设置查询参数
  189. queryParams.value.lines = selectedLines.value.join(',');
  190. loading.value = true;
  191. listRzLine(queryParams.value).then(response => {
  192. // 按小时排序
  193. rzLineList.value = response.rows.sort((a, b) => {
  194. if (a.hour !== b.hour) {
  195. return a.hour - b.hour;
  196. }
  197. return a.line - b.line;
  198. });
  199. total.value = response.total;
  200. loading.value = false;
  201. // 更新图表
  202. nextTick(() => {
  203. updateChart();
  204. });
  205. });
  206. }
  207. // 初始化图表
  208. function initChart() {
  209. if (chartRef.value) {
  210. chartInstance = echarts.init(chartRef.value);
  211. }
  212. }
  213. // 更新图表
  214. function updateChart() {
  215. if (!chartInstance || !rzLineList.value.length) {
  216. return;
  217. }
  218. // 按产线分组数据,只处理已选择的产线
  219. const lineMap = new Map();
  220. rzLineList.value.forEach(item => {
  221. // 只处理已选择的产线
  222. if (selectedLines.value.includes(item.line)) {
  223. if (!lineMap.has(item.line)) {
  224. lineMap.set(item.line, []);
  225. }
  226. lineMap.get(item.line).push(item);
  227. }
  228. });
  229. // 获取所有唯一的时间点
  230. const allTimePoints = [...new Set(rzLineList.value.map(item =>
  231. `${item.dataDate} ${item.hour.toString().padStart(2, '0')}:00`))].sort();
  232. // 准备图表数据
  233. const series = [];
  234. const legendData = [];
  235. // 为每个产线生成数据系列
  236. for (let [line, items] of lineMap) {
  237. // 为每个产线生成选定指标的数据系列
  238. const dataMap = new Map();
  239. items.forEach(item => {
  240. const timePoint = `${item.dataDate} ${item.hour.toString().padStart(2, '0')}:00`;
  241. dataMap.set(timePoint, item);
  242. });
  243. // 基于统一时间轴生成数据
  244. const openRateData = selectedMetrics.value.includes('开机率') ? allTimePoints.map(timePoint => {
  245. const item = dataMap.get(timePoint);
  246. return item && item.openRate !== null ? parseFloat(item.openRate) : null;
  247. }) : [];
  248. const tmpData = selectedMetrics.value.includes('温度') ? allTimePoints.map(timePoint => {
  249. const item = dataMap.get(timePoint);
  250. return item && item.tmp !== null ? parseFloat(item.tmp) : null;
  251. }) : [];
  252. const speedData = selectedMetrics.value.includes('速度') ? allTimePoints.map(timePoint => {
  253. const item = dataMap.get(timePoint);
  254. return item && item.speed !== null ? parseFloat(item.speed) : null;
  255. }) : [];
  256. const energyData = selectedMetrics.value.includes('电量') ? allTimePoints.map(timePoint => {
  257. const item = dataMap.get(timePoint);
  258. return item && item.energy !== null ? parseFloat(item.energy) : null;
  259. }) : [];
  260. const ampData = selectedMetrics.value.includes('电流') ? allTimePoints.map(timePoint => {
  261. const item = dataMap.get(timePoint);
  262. return item && item.amp !== null ? parseFloat(item.amp) : null;
  263. }) : [];
  264. // 添加产线+指标的数据系列
  265. if (selectedMetrics.value.includes('开机率')) {
  266. legendData.push(`${line}-开机率`);
  267. series.push({
  268. name: `${line}-开机率`,
  269. type: 'line',
  270. data: openRateData,
  271. smooth: true,
  272. showSymbol: false
  273. });
  274. }
  275. if (selectedMetrics.value.includes('温度')) {
  276. legendData.push(`${line}-温度`);
  277. series.push({
  278. name: `${line}-温度`,
  279. type: 'line',
  280. data: tmpData,
  281. smooth: true,
  282. showSymbol: false
  283. });
  284. }
  285. if (selectedMetrics.value.includes('速度')) {
  286. legendData.push(`${line}-速度`);
  287. series.push({
  288. name: `${line}-速度`,
  289. type: 'line',
  290. data: speedData,
  291. smooth: true,
  292. showSymbol: false
  293. });
  294. }
  295. if (selectedMetrics.value.includes('电量')) {
  296. legendData.push(`${line}-电量`);
  297. series.push({
  298. name: `${line}-电量`,
  299. type: 'line',
  300. data: energyData,
  301. smooth: true,
  302. showSymbol: false
  303. });
  304. }
  305. if (selectedMetrics.value.includes('电流')) {
  306. legendData.push(`${line}-电流`);
  307. series.push({
  308. name: `${line}-电流`,
  309. type: 'line',
  310. data: ampData,
  311. smooth: true,
  312. showSymbol: false
  313. });
  314. }
  315. }
  316. const option = {
  317. title: {
  318. text: '前整车间产线对比',
  319. left: 'center'
  320. },
  321. tooltip: {
  322. trigger: 'axis',
  323. formatter: function (params) {
  324. let result = params[0].axisValue + '<br/>';
  325. params.forEach(param => {
  326. let valueText = '';
  327. if (param.seriesName.includes('开机率')) {
  328. valueText = param.value !== null ? param.value + ' (%)' : '无数据';
  329. } else if (param.seriesName.includes('温度')) {
  330. valueText = param.value !== null ? param.value + ' (°C)' : '无数据';
  331. } else if (param.seriesName.includes('速度')) {
  332. valueText = param.value !== null ? param.value + ' (米/min)' : '无数据';
  333. } else if (param.seriesName.includes('电量')) {
  334. valueText = param.value !== null ? param.value + ' (kW·h)' : '无数据';
  335. } else if (param.seriesName.includes('电流')) {
  336. valueText = param.value !== null ? param.value + ' (A)' : '无数据';
  337. } else {
  338. valueText = param.value !== null ? param.value : '无数据';
  339. }
  340. result += `<div style="display:flex;align-items:center;">
  341. <span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${param.color};"></span>
  342. ${param.seriesName}: ${valueText}
  343. </div>`;
  344. });
  345. return result;
  346. }
  347. },
  348. legend: [
  349. ...Array.from(lineMap.keys()).map((line, index) => {
  350. const lineLegendData = [];
  351. if (selectedMetrics.value.includes('开机率')) lineLegendData.push(`${line}-开机率`);
  352. if (selectedMetrics.value.includes('温度')) lineLegendData.push(`${line}-温度`);
  353. if (selectedMetrics.value.includes('速度')) lineLegendData.push(`${line}-速度`);
  354. if (selectedMetrics.value.includes('电量')) lineLegendData.push(`${line}-电量`);
  355. if (selectedMetrics.value.includes('电流')) lineLegendData.push(`${line}-电流`);
  356. return {
  357. data: lineLegendData,
  358. top: 40 + index * 25,
  359. left: 'center',
  360. textStyle: {
  361. fontSize: 10
  362. },
  363. itemWidth: 10,
  364. itemHeight: 10
  365. };
  366. })
  367. ],
  368. grid: {
  369. left: '3%',
  370. right: '4%',
  371. top: '25%',
  372. bottom: 20,
  373. containLabel: true
  374. },
  375. xAxis: {
  376. type: 'category',
  377. boundaryGap: false,
  378. data: allTimePoints
  379. },
  380. yAxis: {
  381. type: 'value',
  382. name: ''
  383. },
  384. series: series
  385. };
  386. chartInstance.setOption(option, true);
  387. }
  388. // 窗口大小改变时重置图表大小
  389. function resizeChart() {
  390. if (chartInstance) {
  391. chartInstance.resize();
  392. }
  393. }
  394. onMounted(() => {
  395. initChart();
  396. window.addEventListener('resize', resizeChart);
  397. // 默认选择所有产线
  398. selectedLines.value = [...allLines.value];
  399. // 初始加载数据
  400. getList();
  401. });
  402. onUnmounted(() => {
  403. window.removeEventListener('resize', resizeChart);
  404. if (chartInstance) {
  405. chartInstance.dispose();
  406. }
  407. });
  408. onActivated(() => {
  409. resizeChart();
  410. });
  411. // 取消按钮
  412. function cancel() {
  413. open.value = false;
  414. reset();
  415. }
  416. // 表单重置
  417. function reset() {
  418. form.value = {
  419. id: null,
  420. dataDate: null,
  421. hour: null,
  422. line: null,
  423. openRate: null,
  424. length: null,
  425. tmp: null,
  426. speed: null,
  427. energy: null,
  428. amp: null,
  429. createdBy: null,
  430. createdTime: null,
  431. updatedBy: null,
  432. updatedTime: null,
  433. remark: null
  434. };
  435. proxy.resetForm("rzLineRef");
  436. }
  437. /** 搜索按钮操作 */
  438. function handleQuery() {
  439. queryParams.value.pageNum = 1;
  440. // 检查查询条件
  441. if (!queryParams.value.dataDate) {
  442. proxy.$modal.msgWarning("请选择日期");
  443. return;
  444. }
  445. getList();
  446. }
  447. /** 重置按钮操作 */
  448. function resetQuery() {
  449. proxy.resetForm("queryRef");
  450. // 设置默认日期为当前日期
  451. const now = new Date();
  452. const year = now.getFullYear();
  453. const month = (now.getMonth() + 1).toString().padStart(2, '0');
  454. const day = now.getDate().toString().padStart(2, '0');
  455. queryParams.value.dataDate = `${year}-${month}-${day}`;
  456. // 默认选择所有产线
  457. selectedLines.value = [...allLines.value];
  458. handleQuery();
  459. }
  460. // 全选产线
  461. function selectAllLines() {
  462. selectedLines.value = [...allLines.value];
  463. getList();
  464. }
  465. // 反选产线
  466. function invertSelection() {
  467. const newSelectedLines = [];
  468. allLines.value.forEach(line => {
  469. if (!selectedLines.value.includes(line)) {
  470. newSelectedLines.push(line);
  471. }
  472. });
  473. selectedLines.value = newSelectedLines;
  474. getList();
  475. }
  476. // 全选指标
  477. function selectAllMetrics() {
  478. selectedMetrics.value = ['开机率', '温度', '速度', '电量', '电流'];
  479. updateChart();
  480. }
  481. // 反选指标
  482. function invertMetrics() {
  483. const allMetrics = ['开机率', '温度', '速度', '电量', '电流'];
  484. const newSelectedMetrics = [];
  485. allMetrics.forEach(metric => {
  486. if (!selectedMetrics.value.includes(metric)) {
  487. newSelectedMetrics.push(metric);
  488. }
  489. });
  490. selectedMetrics.value = newSelectedMetrics;
  491. updateChart();
  492. }
  493. // 多选框选中数据
  494. function handleSelectionChange(selection) {
  495. ids.value = selection.map(item => item.id);
  496. single.value = selection.length != 1;
  497. multiple.value = !selection.length;
  498. }
  499. /** 新增按钮操作 */
  500. function handleAdd() {
  501. reset();
  502. open.value = true;
  503. title.value = "添加染整线产线小时统计数据";
  504. }
  505. /** 修改按钮操作 */
  506. function handleUpdate(row) {
  507. reset();
  508. const _id = row.id || ids.value
  509. getRzLine(_id).then(response => {
  510. form.value = response.data;
  511. open.value = true;
  512. title.value = "修改染整线产线小时统计数据";
  513. });
  514. }
  515. /** 提交按钮 */
  516. function submitForm() {
  517. proxy.$refs["rzLineRef"].validate(valid => {
  518. if (valid) {
  519. if (form.value.id != null) {
  520. updateRzLine(form.value).then(response => {
  521. proxy.$modal.msgSuccess("修改成功");
  522. open.value = false;
  523. getList();
  524. });
  525. } else {
  526. addRzLine(form.value).then(response => {
  527. proxy.$modal.msgSuccess("新增成功");
  528. open.value = false;
  529. getList();
  530. });
  531. }
  532. }
  533. });
  534. }
  535. /** 删除按钮操作 */
  536. function handleDelete(row) {
  537. const _ids = row.id || ids.value;
  538. proxy.$modal.confirm('是否确认删除染整线产线小时统计数据编号为"' + _ids + '"的数据项?').then(function() {
  539. return delRzLine(_ids);
  540. }).then(() => {
  541. getList();
  542. proxy.$modal.msgSuccess("删除成功");
  543. }).catch(() => {});
  544. }
  545. /** 导出按钮操作 */
  546. function handleExport() {
  547. proxy.download('dyeing/rzLine/export', {
  548. ...queryParams.value
  549. }, `rzLine_${new Date().getTime()}.xlsx`)
  550. }
  551. getList();
  552. </script>