<template>
|
<div>
|
<div style="display: flex;width: 1770px;justify-content: center;">
|
<el-date-picker v-model="timeRange[1]" type="date" :placeholder="$t('reportmanage.starttime')"
|
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>
|
</div>
|
<div style="width: 100%;height: 20%;display: flex;justify-content: center;">
|
<div ref="chart" style="width: 100%;"></div>
|
</div>
|
<el-table ref="table" style="margin-top: 20px;height: 500px;width: 100%;" :data="tableDataTime(true)"
|
:header-cell-style="{ background: '#F2F3F5 ', color: '#1D2129' }">
|
<el-table-column prop="firstTimestamp" align="center" :label="$t('large.starttime')" min-width="70" />
|
<el-table-column prop="secondTimestamp" align="center" :label="$t('large.endtime')" min-width="70" />
|
<!-- <el-table-column prop="diffMinutes" align="center" :label="$t('large.diffMinutes')" min-width="70" /> -->
|
<el-table-column prop="state" align="center" :label="$t('large.warehousing')" min-width="70">
|
<template #default="scope">
|
<span v-if="scope.row.state === 1">{{ $t('large.running') }}</span>
|
<span v-else>{{ $t('large.stopping') }}</span>
|
</template>
|
</el-table-column>
|
</el-table>
|
<!-- <div 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>
|
</template>
|
<script lang="ts" setup>
|
import { useI18n } from 'vue-i18n'
|
import { useRouter, useRoute } from "vue-router"
|
import request from "@/utils/request"
|
import { host, WebSocketHost } from '@/utils/constants'
|
import { onBeforeUnmount, onMounted, onUnmounted, reactive, ref } from "vue";
|
import { closeWebSocket, initializeWebSocket } from '@/utils/WebSocketService';
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
import * as echarts from 'echarts';
|
import { inject } from 'vue';
|
const { t } = useI18n()
|
let language = ref(localStorage.getItem('lang') || 'zh')
|
const globalDate = inject('globalDate');
|
const router = useRoute()
|
const key = router.query.key;
|
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.get("/cacheGlass/edgStorageDeviceTaskHistory/queryRunTimes?days=" + 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;
|
timeAxisCreate("", chart.value, myChart, tableDataTime(false));
|
// tableDatax.value = formattedData;
|
// 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 tableDataTime = (result) => {
|
const tableData = [];
|
if (tableDatax.value.length > 0) {
|
tableDatax.value.forEach((item, index) => {
|
tableData.push({
|
firstTimestamp: index == 0 ? item.startTimestamp : tableDatax.value[index - 1].secondTimestamp,
|
secondTimestamp: index == tableDatax.length - 1 ? item.endTimestamp : item.firstTimestamp,
|
diffMinutes: item.diffMinutes,
|
startTimestamp: item.startTimestamp,
|
endTimestamp: item.endTimestamp,
|
state: 1
|
});
|
if (result) {
|
tableData.push({
|
firstTimestamp: item.firstTimestamp,
|
secondTimestamp: item.secondTimestamp,
|
diffMinutes: item.diffMinutes,
|
startTimestamp: item.startTimestamp,
|
endTimestamp: item.endTimestamp,
|
state: 2
|
});
|
}
|
});
|
}
|
return tableData;
|
};
|
|
|
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.get("/cacheGlass/edgStorageDeviceTaskHistory/queryRunTimes?days=" + 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;
|
timeAxisCreate("", chart.value, myChart, tableDataTime(false));
|
// tableDatax.value = formattedData;
|
// 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.get("/cacheGlass/edgStorageDeviceTaskHistory/queryRunTimes?days=" + 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;
|
timeAxisCreate("", chart.value, myChart, tableDataTime(false));
|
// tableDatax.value = formattedData;
|
// 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}`;
|
return `${year}-${month}-${day}`;
|
}
|
// 格式化后端时间并计算一周前的时间
|
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);
|
backendTime.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.Productionandoperationstatus'));
|
};
|
|
let myChart = null;
|
const chart = ref(null)
|
const timeAxisCreate = (title, chartDom, mychart, RunTimes) => {
|
if (!chartDom) {
|
console.error('图表容器未找到');
|
return;
|
}
|
|
if (!mychart) {
|
mychart = echarts.init(chartDom);
|
}
|
let firstTime = null;
|
let secondTime = null;
|
if (RunTimes.length == 0) {
|
firstTime = "00-00-00 00:00:00";
|
secondTime = "00-00-00 00:00:00";
|
} else {
|
firstTime = RunTimes[0].startTimestamp;
|
secondTime = RunTimes[0].endTimestamp;
|
}
|
|
// 构建线段数组
|
const segments = RunTimes.map(item => ({
|
type: 'line',
|
symbol: 'none',
|
data: [
|
{
|
value: [item.firstTimestamp, 0],
|
extra: {
|
start: item.firstTimestamp,
|
end: item.secondTimestamp
|
}
|
},
|
{
|
value: [item.secondTimestamp, 0],
|
extra: {
|
start: item.firstTimestamp,
|
end: item.secondTimestamp
|
}
|
}
|
],
|
lineStyle: {
|
color: 'red', // 支持不同颜色
|
width: 4
|
},
|
z: 1
|
}));
|
|
|
const optionOne = {
|
title: {
|
text: title,
|
left: 'center',
|
top: '5%',
|
textStyle: {
|
fontSize: 16,
|
fontWeight: 'bold',
|
color: '#333'
|
}
|
},
|
tooltip: {
|
trigger: 'axis',
|
axisPointer: { type: 'line' },
|
backgroundColor: 'rgba(50,50,50,0.7)',
|
textStyle: { color: '#fff' },
|
formatter: (params) => {
|
const items = params
|
.map(p => {
|
const start = p.data?.extra?.start;
|
const end = p.data?.extra?.end;
|
const timeStr = p.axisValueLabel;
|
if (start && end) {
|
return `开始时间:${start}<br/>结束时间:${end}`;
|
}
|
return `时间:${timeStr}`;
|
})
|
.filter(Boolean);
|
return items.join('<br/>');
|
}
|
},
|
grid: {
|
top: '20%',
|
left: '5%',
|
right: '5%',
|
bottom: '15%'
|
},
|
xAxis: {
|
type: 'time',
|
axisLabel: {
|
formatter: function (value) {
|
const date = new Date(value);
|
return (
|
date.getHours().toString().padStart(2, '0') + ':' +
|
date.getMinutes().toString().padStart(2, '0') + ':' +
|
date.getSeconds().toString().padStart(2, '0')
|
);
|
},
|
fontSize: 10,
|
color: '#666'
|
},
|
splitLine: { show: false },
|
axisLine: { lineStyle: { color: '#aaa' } }
|
},
|
yAxis: {
|
type: 'value',
|
min: -1,
|
max: 1,
|
show: false
|
},
|
series: [
|
// 主时间线(蓝色渐变,稍微加粗)
|
{
|
type: 'line',
|
symbol: 'none',
|
data: [
|
[firstTime, 0],
|
[secondTime, 0]
|
],
|
lineStyle: {
|
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
|
{ offset: 0, color: 'red' },
|
{ offset: 1, color: 'red' }
|
]),
|
width: 5,
|
shadowColor: 'rgba(0,0,0,0.2)',
|
shadowBlur: 8
|
},
|
z: 0
|
},
|
// 小段时间线(统一柔和的黄色)
|
...segments.map(seg => ({
|
...seg,
|
lineStyle: {
|
color: '#4facfe',
|
width: 3,
|
shadowColor: 'rgba(255,204,0,0.5)',
|
shadowBlur: 5
|
}
|
})),
|
]
|
};
|
|
mychart.setOption(optionOne);
|
};
|
|
</script>
|
<style scoped></style>
|