feat: connect line monitor to database
This commit is contained in:
@@ -309,6 +309,8 @@ export default {
|
||||
cameraSyncTimer: null,
|
||||
iframeReadyTimer: null,
|
||||
dmtIframeReady: false,
|
||||
lineMonitorTimer: null,
|
||||
lineMonitorRequesting: false,
|
||||
clockTimer: null,
|
||||
resizeHandler: null,
|
||||
alarmPieChart: null,
|
||||
@@ -349,6 +351,7 @@ export default {
|
||||
},
|
||||
lineMonitorRows: [
|
||||
{
|
||||
unitKey: 'longRail',
|
||||
name: '加工中心单元',
|
||||
status: '执行中',
|
||||
type: 'on',
|
||||
@@ -374,6 +377,7 @@ export default {
|
||||
]
|
||||
},
|
||||
{
|
||||
unitKey: 'shortRail',
|
||||
name: '车床加工单元',
|
||||
status: '准备就绪',
|
||||
type: 'ok',
|
||||
@@ -399,6 +403,7 @@ export default {
|
||||
]
|
||||
},
|
||||
{
|
||||
unitKey: 'joint',
|
||||
name: '插齿机单元',
|
||||
status: '异常中断',
|
||||
type: 'alarm',
|
||||
@@ -424,6 +429,7 @@ export default {
|
||||
]
|
||||
},
|
||||
{
|
||||
unitKey: 'grinder',
|
||||
name: '磨床加工单元',
|
||||
status: '预制待命',
|
||||
type: 'ok',
|
||||
@@ -608,7 +614,11 @@ export default {
|
||||
this.updateTime()
|
||||
this.setScale()
|
||||
this.$nextTick(this.initAlarmPieChart)
|
||||
this.loadLineMonitorData()
|
||||
this.clockTimer = setInterval(this.updateTime, 1000)
|
||||
this.lineMonitorTimer = setInterval(() => {
|
||||
this.loadLineMonitorData()
|
||||
}, 5000)
|
||||
this.resizeHandler = () => {
|
||||
this.setScale()
|
||||
if (this.alarmPieChart) {
|
||||
@@ -640,6 +650,10 @@ export default {
|
||||
clearTimeout(this.iframeReadyTimer)
|
||||
this.iframeReadyTimer = null
|
||||
}
|
||||
if (this.lineMonitorTimer) {
|
||||
clearInterval(this.lineMonitorTimer)
|
||||
this.lineMonitorTimer = null
|
||||
}
|
||||
if (this.alarmPieChart) {
|
||||
this.alarmPieChart.dispose()
|
||||
this.alarmPieChart = null
|
||||
@@ -655,6 +669,116 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
loadLineMonitorData() {
|
||||
if (this.lineMonitorRequesting) return
|
||||
this.lineMonitorRequesting = true
|
||||
const data = this.CreateData('11', 'TV_线体任务联动状态_查询', [])
|
||||
this.ExecDatabase(data)
|
||||
.then((response) => {
|
||||
const list = response && response.data ? response.data : null
|
||||
if (!Array.isArray(list) || list.length === 0) return
|
||||
if (list.length === 1 && list[0] && (list[0].result === '0' || list[0].result === 0)) return
|
||||
this.applyLineMonitorData(list)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('TV_线体任务联动状态_查询失败', error)
|
||||
})
|
||||
.then(() => {
|
||||
this.lineMonitorRequesting = false
|
||||
})
|
||||
},
|
||||
applyLineMonitorData(list) {
|
||||
const rowMap = {}
|
||||
list.forEach((item) => {
|
||||
const row = this.createLineMonitorRow(item)
|
||||
if (row.unitKey) {
|
||||
rowMap[row.unitKey] = row
|
||||
}
|
||||
})
|
||||
this.lineMonitorRows = this.lineMonitorRows.map((row) => {
|
||||
if (row.unitKey && rowMap[row.unitKey]) {
|
||||
return Object.assign({}, row, rowMap[row.unitKey])
|
||||
}
|
||||
return row
|
||||
})
|
||||
},
|
||||
createLineMonitorRow(item) {
|
||||
const getValue = (...keys) => {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const value = item[keys[i]]
|
||||
if (value !== undefined && value !== null) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
const unitKey = this.normalizeUnitKey(getValue('UnitKey', 'unitKey'))
|
||||
const statusType = this.normalizeStatusType(getValue('StatusType', 'statusType'))
|
||||
const taskNo = this.formatTaskNo(getValue('TaskNo', 'taskNo'))
|
||||
const startPos = this.formatDisplayValue(getValue('StartPos', 'startPos'))
|
||||
const endPos = this.formatDisplayValue(getValue('EndPos', 'endPos'))
|
||||
const recipeCode = this.formatDisplayValue(getValue('RecipeCode', 'recipeCode'))
|
||||
const palletType = this.formatDisplayValue(getValue('PalletType', 'palletType'))
|
||||
return {
|
||||
unitKey,
|
||||
name: this.formatDisplayValue(getValue('UnitName', 'unitName')),
|
||||
status: this.formatDisplayValue(getValue('StatusText', 'statusText')),
|
||||
type: statusType,
|
||||
taskNo,
|
||||
startPos,
|
||||
endPos,
|
||||
taskInfo: [
|
||||
{ label: '配方号', value: recipeCode },
|
||||
{ label: '托盘', value: palletType }
|
||||
],
|
||||
lineSignals: [
|
||||
{ label: 'PCS运行', state: this.getSignalState(getValue('PCSRun', 'pcsRun')) },
|
||||
{ label: '允许接收', state: this.getSignalState(getValue('AllowTask', 'allowTask')) },
|
||||
{ label: '自动模式', state: this.getSignalState(getValue('AutoMode', 'autoMode')) },
|
||||
{ label: '急停', state: this.getSignalState(getValue('EmergencyStop', 'emergencyStop'), true) }
|
||||
],
|
||||
handshakes: [
|
||||
{ label: '启动', state: this.getSignalState(getValue('StartFlag', 'startFlag')) },
|
||||
{ label: '准备好', state: this.getSignalState(getValue('ReadyFlag', 'readyFlag')) },
|
||||
{ label: '忙碌', state: this.getSignalState(getValue('BusyFlag', 'busyFlag')) },
|
||||
{ label: '错误', state: this.getSignalState(getValue('ErrorFlag', 'errorFlag'), true) },
|
||||
{ label: '完成', state: this.getSignalState(getValue('CompleteFlag', 'completeFlag')) }
|
||||
]
|
||||
}
|
||||
},
|
||||
normalizeUnitKey(value) {
|
||||
const key = String(value || '').trim()
|
||||
if (key) return key
|
||||
return ''
|
||||
},
|
||||
normalizeStatusType(value) {
|
||||
const type = String(value || '').trim()
|
||||
return ['on', 'ok', 'alarm'].includes(type) ? type : 'ok'
|
||||
},
|
||||
formatDisplayValue(value) {
|
||||
const text = String(value == null ? '' : value).trim()
|
||||
if (!text || text.toUpperCase() === 'NULL') {
|
||||
return '--'
|
||||
}
|
||||
return text
|
||||
},
|
||||
formatTaskNo(value) {
|
||||
const text = this.formatDisplayValue(value)
|
||||
if (text === '--' || text === '0') {
|
||||
return '无任务'
|
||||
}
|
||||
return text.indexOf('TASK') === 0 ? text : `TASK ${text}`
|
||||
},
|
||||
isSignalOn(value) {
|
||||
const text = String(value == null ? '' : value).trim().toUpperCase()
|
||||
return ['1', 'TRUE', 'ON', 'YES', '是'].includes(text)
|
||||
},
|
||||
getSignalState(value, alarmWhenOn = false) {
|
||||
if (!this.isSignalOn(value)) {
|
||||
return 'off'
|
||||
}
|
||||
return alarmWhenOn ? 'alarm' : 'on'
|
||||
},
|
||||
getHistorySegmentStyle(segment) {
|
||||
const start = Math.max(0, Math.min(24, segment.start))
|
||||
const end = Math.max(start, Math.min(24, segment.end))
|
||||
|
||||
Reference in New Issue
Block a user