|
|
|
@ -292,6 +292,9 @@ export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
currentTime: '', |
|
|
|
timeInterval: null, // 时间更新定时器 |
|
|
|
serverTimeOffset: 0, // 服务器时间偏移量(毫秒) |
|
|
|
refreshCheckInterval: null, // 定时刷新检查定时器 |
|
|
|
|
|
|
|
// WebSocket相关 |
|
|
|
useWebSocket: true, // 是否使用WebSocket(可切换为false降级到本地数据) |
|
|
|
@ -373,7 +376,7 @@ export default { |
|
|
|
const empty = this.storageData.emptyContainerInventory || {} |
|
|
|
return (empty.flatPallet || 0) + (empty.framePallet || 0) + (empty.steelPallet || 0) |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 计算可用库位数(总库位 - 已使用库位) |
|
|
|
*/ |
|
|
|
@ -383,8 +386,16 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
mounted() { |
|
|
|
this.updateTime() |
|
|
|
this.timeInterval = setInterval(this.updateTime, 1000) |
|
|
|
// 初始化时间显示 |
|
|
|
this.currentTime = '等待服务器时间同步...' |
|
|
|
|
|
|
|
// 启动时钟定时器(每秒更新) |
|
|
|
this.timeInterval = setInterval(() => { |
|
|
|
this.updateTime() |
|
|
|
}, 1000) |
|
|
|
|
|
|
|
// 启动定时刷新检查(每分钟检查一次) |
|
|
|
this.startRefreshCheck() |
|
|
|
|
|
|
|
// 延迟初始化图表,确保DOM已渲染 |
|
|
|
this.$nextTick(() => { |
|
|
|
@ -407,9 +418,14 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
beforeDestroy() { |
|
|
|
// 清理时间更新定时器 |
|
|
|
if (this.timeInterval) { |
|
|
|
clearInterval(this.timeInterval) |
|
|
|
} |
|
|
|
// 清理定时刷新检查定时器 |
|
|
|
if (this.refreshCheckInterval) { |
|
|
|
clearInterval(this.refreshCheckInterval) |
|
|
|
} |
|
|
|
// 移除窗口resize监听 |
|
|
|
window.removeEventListener('resize', this.handleResize) |
|
|
|
// 销毁所有图表 |
|
|
|
@ -421,6 +437,34 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
/** |
|
|
|
* 启动定时刷新检查 |
|
|
|
* 每分钟检查一次,如果到达凌晨5点则自动刷新页面 |
|
|
|
*/ |
|
|
|
startRefreshCheck() { |
|
|
|
console.log('[智能立体仓库看板] 已启动定时刷新检查,将在每天凌晨5:00自动刷新页面') |
|
|
|
|
|
|
|
// 每分钟检查一次 |
|
|
|
this.refreshCheckInterval = setInterval(() => { |
|
|
|
this.checkAndRefreshPage() |
|
|
|
}, 60000) // 60秒 = 1分钟 |
|
|
|
|
|
|
|
// 立即执行一次检查 |
|
|
|
this.checkAndRefreshPage() |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查当前时间,如果是凌晨5点则刷新页面 |
|
|
|
*/ |
|
|
|
checkAndRefreshPage() { |
|
|
|
const now = new Date() |
|
|
|
const hours = now.getHours() |
|
|
|
const minutes = now.getMinutes() |
|
|
|
// 判断是否为凌晨5:00-5:10之间 |
|
|
|
if (hours === 5 && minutes === 10) { |
|
|
|
location.reload() |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理窗口大小变化 |
|
|
|
@ -435,10 +479,32 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新时间显示 |
|
|
|
* 更新服务器时间偏移量 |
|
|
|
* |
|
|
|
* @param {string} serverTimeString - 服务器时间字符串 |
|
|
|
*/ |
|
|
|
updateServerTimeOffset(serverTimeString) { |
|
|
|
try { |
|
|
|
// 解析服务器时间字符串 "2025-11-01 14:30:25 星期五" |
|
|
|
const timeStr = serverTimeString.split(' ')[0] + ' ' + serverTimeString.split(' ')[1] |
|
|
|
const serverTime = new Date(timeStr).getTime() |
|
|
|
const localTime = new Date().getTime() |
|
|
|
|
|
|
|
if (!isNaN(serverTime)) { |
|
|
|
this.serverTimeOffset = serverTime - localTime |
|
|
|
console.log('服务器时间偏移量更新:', this.serverTimeOffset, 'ms') |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
console.warn('解析服务器时间失败:', error) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新时间显示(使用服务器时间偏移量) |
|
|
|
*/ |
|
|
|
updateTime() { |
|
|
|
const now = new Date() |
|
|
|
// 使用本地时间 + 偏移量来计算服务器时间 |
|
|
|
const now = new Date(new Date().getTime() + this.serverTimeOffset) |
|
|
|
const year = now.getFullYear() |
|
|
|
const month = String(now.getMonth() + 1).padStart(2, '0') |
|
|
|
const date = String(now.getDate()).padStart(2, '0') |
|
|
|
@ -498,6 +564,11 @@ export default { |
|
|
|
handleWebSocketMessage(message) { |
|
|
|
if (message && message.code === 0) { |
|
|
|
console.log('[智能立体仓库看板] 收到WebSocket推送数据:', message.data) |
|
|
|
|
|
|
|
// 更新服务器时间偏移量 |
|
|
|
if (message.serverTime) { |
|
|
|
this.updateServerTimeOffset(message.serverTime) |
|
|
|
} |
|
|
|
|
|
|
|
// 更新任务统计数据 |
|
|
|
if (message.data.taskData && Object.keys(message.data.taskData).length > 0) { |
|
|
|
@ -519,9 +590,9 @@ export default { |
|
|
|
...(message.data.storageData.emptyContainerInventory || {}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('[智能立体仓库看板] 库位数据已更新:', this.storageData) |
|
|
|
|
|
|
|
|
|
|
|
// 重新初始化库位利用率图表 |
|
|
|
this.$nextTick(() => { |
|
|
|
this.initStorageChart() |
|
|
|
@ -644,7 +715,7 @@ export default { |
|
|
|
const materialSteelPallet = materialInventory.steelPallet || 0 |
|
|
|
const materialFramePallet = materialInventory.framePallet || 0 |
|
|
|
const materialFlatPallet = materialInventory.flatPallet || 0 |
|
|
|
|
|
|
|
|
|
|
|
// 计算可用库位数 |
|
|
|
const availableSlots = this.availableSlots |
|
|
|
|
|
|
|
@ -759,7 +830,7 @@ export default { |
|
|
|
}, |
|
|
|
{ |
|
|
|
value: availableSlots, |
|
|
|
name: '可用库位数(' + availableSlots + ')', |
|
|
|
name: '可用库位(' + availableSlots + ')', |
|
|
|
itemStyle: { |
|
|
|
color: { |
|
|
|
type: 'linear', |
|
|
|
|