ZengTao
2025-05-27 46ebf3e9ce29ccdd12a6c566280fc88212da2422
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<template>
  <div>
    <div style="display: flex;width: 1770px;">
      <el-date-picker v-model="timeRange" type="daterange" range-separator="至"
        :start-placeholder="$t('reportmanage.starttime')" :end-placeholder="$t('reportmanage.endtime')"
        value-format="YYYY-MM-DD" style="margin-left: 15px;">
      </el-date-picker>
      <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="sethistorical()">{{
        $t('reportmanage.inquire') }}</el-button>
        <el-button type="primary" @click="exportToExcel">{{$t('large.ExporttoExcel')}}</el-button>
        <el-button type="primary" @click="showchart=!showchart" style="margin-left: 10px;">{{ $t('large.switch') }}</el-button>
    </div>
    <el-table v-show="!showchart" ref="table" style="margin-top: 20px;height: 580px;width: 1770px;" :data="tableDatax"
      :header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129' }">
      <el-table-column prop="date" align="center" :label="$t('large.date')" min-width="70" />
      <el-table-column prop="countOutOne" align="center" :label="$t('large.countOutOne')" min-width="40" />
      <el-table-column prop="totalAreaOutOne" align="center" :label="$t('large.totalAreaOutOne')" min-width="40" />
      <el-table-column prop="countOutTwo" align="center" :label="$t('large.countOutTwo')" min-width="50" />
      <el-table-column prop="totalAreaOutTwo" align="center" :label="$t('large.totalAreaOutTwo')" min-width="50" />
      <el-table-column prop="countIn" align="center" :label="$t('large.countIn')" min-width="50" />
      <el-table-column prop="totalAreaIn" align="center" :label="$t('large.totalAreaIn')" min-width="50" />
      <el-table-column prop="countOut" align="center" :label="$t('large.countOut')" min-width="40" />
      <el-table-column prop="totalAreaOut" align="center" :label="$t('large.totalAreaOut')" min-width="40" />
      <el-table-column prop="hollowCountOutOne" align="center" :label="$t('large.hollowCountOutOne')" min-width="40" />
      <el-table-column prop="hollowTotalAreaOutOne" align="center" :label="$t('large.hollowTotalAreaOutOne')"
        min-width="40" />
      <el-table-column prop="hollowCountOutTwo" align="center" :label="$t('large.hollowCountOutTwo')" min-width="40" />
      <el-table-column prop="hollowTotalAreaOutTwo" align="center" :label="$t('large.hollowTotalAreaOutTwo')"
        min-width="40" />
    </el-table>
    <div v-show="!showchart" style="margin-top: 20px;margin-left: 40%;">
      <el-pagination v-model:current-page="currentPage2" :page-size="pageSize" :size="large" :disabled="disabled"
        layout="prev, pager, next, jumper" :total="totalRecords" @current-change="handlePageChange2"
        style="margin-top: 10px;" />
    </div>
    <div v-show="showchart" id="ss" style="width: 100%; display: flex; justify-content: center;">
          <div ref="chartRef" style="width: 1770px; height: 320px;"></div>
    </div>
    <div v-show="showchart" id="ss" style="width: 100%; display: flex; justify-content: center;">
          <div ref="chartRef2" style="width: 1770px; height: 320px;"></div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
import { useRouter } from "vue-router"
import request from "@/utils/request"
import { host, WebSocketHost } from '@/utils/constants'
import { onBeforeUnmount, onMounted, onUnmounted, reactive, ref , nextTick} from "vue";
import { closeWebSocket, initializeWebSocket } from '@/utils/WebSocketService';
import { ElMessage, ElMessageBox } from 'element-plus'
import * as echarts from 'echarts';
const { t } = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
import { inject } from 'vue';
const globalDate = inject('globalDate');
const router = useRouter()
const timeRange = ref([])
const selectValuesa = reactive([]);
const tableDatax = ref([])
const currentPage2 = ref(1)
const totalRecords = ref(0)
const rawGlassHeight = ref('');
const rawGlassThickness = ref('');
const rawGlassWidth = ref('');
const rawGlassfilmsId = ref('');
const slot = ref('');
let getglobalDate = window.localStorage.getItem('getglobalDate')
const historical = async () => {
  try {
    let startTime = window.localStorage.getItem('startTime')
    const response = await request.post("/loadGlass/largenScreen/queryDailyProduction", {
      pageNo: 1,
      pageSize: 20,
      beginDate: startTime,
      endDate: getglobalDate
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      const formattedData = response.data.records.map(record => ({
        ...record,
        formattedCreateTime: formatTimestamp(record.createTime),
        formattedUpdateTime: formatTimestamp(record.updateTime),
      }));
      // tableDatax.value = response.data.records;
      tableDatax.value = formattedData;
      createchart(tableDatax);
      totalRecords.value = response.data.total / 2 || 0
    } else {
      ElMessage.error(response.message);
    }
  }
  catch (error) {
    console.error(error);
  }
}
const handlePageChange2 = (newPage) => {
  currentPage2.value = newPage;
  window.localStorage.setItem('pagenumber', currentPage2.value)
  historicala(currentPage2.value);
};
const historicala = async (page) => {
  try {
    let pslot = ''
    let celllist = []
    if (selectValuesa[0] != null && selectValuesa[0] != 'undefined') {
      if (selectValuesa[0] != "") {
        celllist = [selectValuesa[0]];
      }
    }
    if (slot.value != "") {
      pslot = slot.value
    } else {
      pslot = '0'
    }
    let page = window.localStorage.getItem('pagenumber')
    let startTime = window.localStorage.getItem('startTime')
    const response = await request.post("/loadGlass/largenScreen/queryDailyProduction", {
      pageNo: page,
      pageSize: 20,
      beginDate: (timeRange.value && timeRange.value[0]) || '',
      endDate: (timeRange.value && timeRange.value[1]) || '',
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      const formattedData = response.data.records.map(record => ({
        ...record,
        formattedCreateTime: formatTimestamp(record.createTime),
        formattedUpdateTime: formatTimestamp(record.updateTime),
      }));
      // tableDatax.value = response.data.records;
      tableDatax.value = formattedData;
      createchart(tableDatax);
      totalRecords.value = response.data.total / 2 || 0
    } else {
      ElMessage.error(response.message);
    }
  }
  catch (error) {
    console.error(error);
  }
}
// 历史查询点击
const sethistorical = async () => {
  try {
    let pslot = ''
    let celllist = []
    if (selectValuesa[0] != null && selectValuesa[0] != 'undefined') {
      if (selectValuesa[0] != "") {
        celllist = [selectValuesa[0]];
      }
    }
    if (slot.value != "") {
      pslot = slot.value
    } else {
      pslot = '0'
    }
    let startTime = window.localStorage.getItem('startTime')
    let page = window.localStorage.getItem('pagenumber')
    const response = await request.post("/loadGlass/largenScreen/queryDailyProduction", {
      pageNo: 1,
      pageSize: 20,
      beginDate: (timeRange.value && timeRange.value[0]) || '',
      endDate: (timeRange.value && timeRange.value[1]) || '',
    })
    if (response.code == 200) {
      currentPage2.value = 1
      ElMessage.success(response.message);
      const formattedData = response.data.records.map(record => ({
        ...record,
        formattedCreateTime: formatTimestamp(record.createTime),
        formattedUpdateTime: formatTimestamp(record.updateTime),
      }));
      // tableDatax.value = response.data.records;
      tableDatax.value = formattedData;
      createchart(tableDatax);
      totalRecords.value = response.data.total / 2 || 0
    } else {
      ElMessage.error(response.message);
    }
  }
  catch (error) {
    console.error(error);
  }
}
// 格式化时间戳为年月日时间字符串的函数
function formatTimestamp(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并补零
  const day = String(date.getDate()).padStart(2, '0'); // 补零
  const hours = String(date.getHours()).padStart(2, '0'); // 补零(如果需要显示时间)
  const minutes = String(date.getMinutes()).padStart(2, '0'); // 补零(如果需要显示时间)
  const seconds = String(date.getSeconds()).padStart(2, '0'); // 补零(如果需要显示时间)
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
// 格式化后端时间并计算一周前的时间
const defaultTime = ref<[Date, Date]>([new Date(), new Date()]);
function parseAndSetTime() {
  const backendTime = new Date(getglobalDate);
  const oneWeekAgo = new Date(backendTime.getTime() - 7 * 24 * 60 * 60 * 1000); // 减去7天
  oneWeekAgo.setHours(0, 0, 0, 0);
  timeRange.value = [formatTimestamp(oneWeekAgo), formatTimestamp(backendTime)];
  window.localStorage.setItem('startTime', formatTimestamp(oneWeekAgo))
}
function getStatusTypeb(taskState: number) {
  switch (taskState) {
    case 0:
      return 'primary';
    case 1:
      return 'success';
    case 2:
      return 'info';
  }
}
function getStatusTextb(taskState: number) {
  switch (taskState) {
    case 0:
      return t('searchOrder.empty');
    case 1:
      return t('film.execution');
    case 2:
      return t('searchOrder.endtask');
  }
}
function getStatusTypea(taskRunning: number) {
  switch (taskRunning) {
    case 0:
      return 'primary';
    case 1:
      return 'success';
  }
}
onMounted(() => {
  parseAndSetTime();
  historical();
});
 
import * as XLSX from 'xlsx';
import { saveAs } from 'file-saver';
 
const exportToExcel = () => {
  // 表格数据(深拷贝防止污染)
  const data = JSON.parse(JSON.stringify(tableDatax.value));
 
  // 表头转换为中文或国际化文本
  const headerMap = {
    date: t('large.date'),
    countOutOne: t('large.countOutOne'),
    totalAreaOutOne: t('large.totalAreaOutOne'),
    countOutTwo: t('large.countOutTwo'),
    totalAreaOutTwo: t('large.totalAreaOutTwo'),
    countIn: t('large.countIn'),
    totalAreaIn: t('large.totalAreaIn'),
    countOut: t('large.countOut'),
    totalAreaOut: t('large.totalAreaOut'),
    hollowCountOutOne: t('large.hollowCountOutOne'),
    hollowTotalAreaOutOne: t('large.hollowTotalAreaOutOne'),
    hollowCountOutTwo: t('large.hollowCountOutTwo'),
    hollowTotalAreaOutTwo: t('large.hollowTotalAreaOutTwo')
  };
 
  // 将数据中的 key 替换为中文表头
  const exportData = data.map(row => {
    const newRow = {};
    for (const key in headerMap) {
      newRow[headerMap[key]] = row[key];
    }
    return newRow;
  });
 
  // 转换为工作表
  const worksheet = XLSX.utils.json_to_sheet(exportData);
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
 
  // 导出为文件
  const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
  const blob = new Blob([excelBuffer], { type: 'application/octet-stream' });
  saveAs(blob, t('large.Productionsituation'));
};
let categories = ref([]); // 获取日期作为 x 轴
let totalAreaOutOne = ref([]);
let countIn = ref([]);
let totalAreaOutTwo = ref([]);
let totalAreaOut = ref([]);
let countOut = ref([]);
let hollowTotalAreaOutTwo = ref([]);
let hollowCountOutOne = ref([]);
let countOutTwo = ref([]);
let hollowCountOutTwo = ref([]);
let hollowTotalAreaOutOne = ref([]);
let totalAreaIn = ref([]);
let countOutOne = ref([]);
let myChart = null;
let myChart2 = null;
const chartRef = ref(null)
const chartRef2 = ref(null)
const showchart = ref(false)
const switchNoorAreaLeft = ref(true)
const switchNoorAreaRight = ref(true)
const createchart = (productionVO) => {
  categories = productionVO.value.map(item => item.date); // 获取日期作为 x 轴
  totalAreaOutOne = productionVO.value.map(item => item.totalAreaOutOne);
  countIn = productionVO.value.map(item => item.countIn);
  totalAreaOutTwo = productionVO.value.map(item => item.totalAreaOutTwo);
  totalAreaOut = productionVO.value.map(item => item.totalAreaOut);
  countOut = productionVO.value.map(item => item.countOut);
  hollowTotalAreaOutTwo = productionVO.value.map(item => item.hollowTotalAreaOutTwo);
  hollowCountOutOne = productionVO.value.map(item => item.hollowCountOutOne);
  countOutTwo = productionVO.value.map(item => item.countOutTwo);
  hollowCountOutTwo = productionVO.value.map(item => item.hollowCountOutTwo);
  hollowTotalAreaOutOne = productionVO.value.map(item => item.hollowTotalAreaOutOne);
  totalAreaIn = productionVO.value.map(item => item.totalAreaIn);
  countOutOne = productionVO.value.map(item => item.countOutOne);
  //图表
    nextTick() // 确保 DOM 加载完成
  const chartDom = chartRef.value;
  if (!chartDom) {
    console.error('图表容器未找到');
    return;
  }
  if (!myChart) {
    myChart = echarts.init(chartDom);
  }
  let loadOneData;
  let loadTwoData;
  let tempfontData;
  if (switchNoorAreaLeft.value) {
    loadOneData = countOutOne;
    loadTwoData = countOutTwo;
    tempfontData = countIn;
  } else {
    loadOneData = totalAreaOutOne;
    loadTwoData = totalAreaOutTwo;
    tempfontData = totalAreaIn;
  }
 
 
 
 
  const option = {
    title: { text: '' },
    tooltip: { trigger: 'axis' },
    legend: {
      data: [
        t('large.countOutOne'),
        // t('large.totalAreaOutOne'),
        t('large.countOutTwo'),
        // t('large.totalAreaOutTwo'),
        t('large.countIn'),
        // t('large.totalAreaIn')
      ]
    },
    grid: { top: '20%', left: '3%', right: '4%', bottom: '3%', containLabel: true },
    toolbox: {
      feature: {
        saveAsImage: {},
        myTool1: {
          show: true,
          title: t('large.switch'),
          icon: 'path://M512 0C229.234 0 0 229.234 0 512s229.234 512 512 512 512-229.234 512-512S794.766 0 512 0z m0 960C264.602 960 64 759.398 64 512S264.602 64 512 64s448 200.602 448 448-200.602 448-448 448z m0-768c-176.448 0-320 143.552-320 320s143.552 320 320 320 320-143.552 320-320-143.552-320-320-320z', // 圆形按钮图标(可换)
          onclick: function () {
            switchNoorAreaLeft.value = !switchNoorAreaLeft.value;
            createchart(productionVO);
            // customButtonClick(); // 调用你自定义的方法
          }
        }
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      data: categories // 这是日期数据
    },
    yAxis: { type: 'value' },
    series: [
      { name: t('large.countOutOne'), type: 'bar', data: loadOneData },
      // { name: t('large.totalAreaOutOne'), type: 'bar', data: totalAreaOutOne },
      { name: t('large.countOutTwo'), type: 'bar', data: loadTwoData },
      // { name: t('large.totalAreaOutTwo'), type: 'bar', data: totalAreaOutTwo },
      { name: t('large.countIn'), type: 'bar', data: tempfontData },
      // { name: t('large.totalAreaIn'), type: 'bar', data: totalAreaIn }
    ]
  };
 
  myChart.setOption(option, true);
 
 
  const chartDom2 = chartRef2.value;
  if (!chartDom2) {
    console.error('图表容器未找到');
    return;
  }
  // myChart2 = echarts.init(chartDom2);
  if (!myChart2) {
    myChart2 = echarts.init(chartDom2);
  }
  // else {
  //     myChart2.clear();
  //   }
  let tempData;
  let hollowOneData;
  let hollowTwoData;
  if (switchNoorAreaRight.value) {
    tempData = countOut;
    hollowOneData = hollowCountOutOne;
    hollowTwoData = hollowCountOutTwo;
  } else {
    tempData = totalAreaOut;
    hollowOneData = hollowTotalAreaOutOne;
    hollowTwoData = hollowTotalAreaOutTwo;
  }
  const option2 = {
    title: { text: '' },
    tooltip: { trigger: 'axis' },
    legend: {
      data: [
        t('large.countOut'),
        // t('large.totalAreaOut'),
        t('large.hollowCountOutOne'),
        // t('large.hollowTotalAreaOutOne'),
        t('large.hollowCountOutTwo'),
        // t('large.hollowTotalAreaOutTwo')
      ]
    },
    grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
    toolbox: {
      feature: {
        saveAsImage: {},
        myTool1: {
          show: true,
          title: t('large.switch'),
          icon: 'path://M512 0C229.234 0 0 229.234 0 512s229.234 512 512 512 512-229.234 512-512S794.766 0 512 0z m0 960C264.602 960 64 759.398 64 512S264.602 64 512 64s448 200.602 448 448-200.602 448-448 448z m0-768c-176.448 0-320 143.552-320 320s143.552 320 320 320 320-143.552 320-320-143.552-320-320-320z', // 圆形按钮图标(可换)
          onclick: function () {
            switchNoorAreaRight.value = !switchNoorAreaRight.value;
            createchart(productionVO);
            // customButtonClick(); // 调用你自定义的方法
          }
        }
      }
    },
    xAxis: {
      type: 'category',
      boundaryGap: true,
      data: categories // 这是日期数据
    },
    yAxis: { type: 'value' },
    series: [
      // { name: t('large.totalAreaOut'), type: 'bar', data: tempData },
      { name: t('large.countOut'), type: 'bar', data: tempData },
      // { name: t('large.hollowTotalAreaOutOne'), type: 'bar', data: hollowOneData },
      { name: t('large.hollowCountOutOne'), type: 'bar', data: hollowOneData },
      // { name: t('large.hollowTotalAreaOutTwo'), type: 'bar', data: hollowTwoData },
      { name: t('large.hollowCountOutTwo'), type: 'bar', data: hollowTwoData }
    ]
  };
 
  myChart2.setOption(option2, true);
}
 
 
 
</script>
<style scoped></style>