优化错误

This commit is contained in:
24kycj
2026-06-24 11:13:47 +08:00
parent dee6029642
commit c727492da2
3 changed files with 42 additions and 29 deletions
+1
View File
@@ -65,6 +65,7 @@ function startRenderer () {
contentBase: path.join(__dirname, '../'),
quiet: true,
hot: true,
disableHostCheck: true,
before (app, ctx) {
app.use(hotMiddleware)
ctx.middleware.waitUntilValid(() => {
+38 -26
View File
@@ -13,6 +13,10 @@ function getSocketUrl() {
return envUrl || 'ws://127.0.0.1:10010'
}
function asArray(val) {
return Array.isArray(val) ? val : []
}
// 状态JSON
// 设备状态
const PrinterStatus = {
@@ -376,20 +380,28 @@ const actions = {
},
// 接收消息
websocketonmessage({ state, commit, dispatch }, e) {
const data = JSON.parse(e.data) // 转json对象
if (data.resp_name) {
let data
try {
data = JSON.parse(e.data)
} catch (err) {
console.warn('websocket parse error:', err)
return
}
if (!data.resp_name) return
try {
const resp = data.resp_info || {}
// 作业列表
if (data.resp_name === 'task_list') {
commit('setData', { name: 'task_list', data: data.resp_info.task_list })
commit('setData', { name: 'task_list', data: asArray(resp.task_list) })
// 设备信息
} else if (data.resp_name === 'printer_info') {
let info = data.resp_info
info.printer_status = String.fromCharCode(info.printer_status)
info.printer_tray = String.fromCharCode(info.printer_tray)
let strong_list = {}
for (let i = 0; i < info.strong_list.length; i++) {
strong_list[info.strong_list[i].strong_pos] = info.strong_list[i]
}
const info = { ...resp }
if (info.printer_status != null) info.printer_status = String.fromCharCode(info.printer_status)
if (info.printer_tray != null) info.printer_tray = String.fromCharCode(info.printer_tray)
const strong_list = {}
asArray(info.strong_list).forEach((item) => {
strong_list[item.strong_pos] = item
})
info.strongList = strong_list
// if (info.cover_flag && info.printer_name !== 'SE3') {
// commit('setData', { name: 'printer_error', data: { type: 'error', notify: '设备门盖被打开,请关闭门盖。' } })
@@ -400,7 +412,7 @@ const actions = {
commit('setData', { name: 'printer_info', data: info })
// 驱动信息
} else if (data.resp_name === 'cd_info') {
const list = data.resp_info.cd_list
const list = asArray(resp.cd_list)
let cds = []
let isBD = false
for (let i = 0; i < list.length; i++) {
@@ -429,13 +441,13 @@ const actions = {
commit('setData', { name: 'cd_list', data: cds })
// 手动设置驱动
} else if (data.resp_name === 'get_all_cdlist') {
commit('setData', { name: 'cdList', data: data.resp_info.cd_list || [] })
commit('setData', { name: 'cdList', data: asArray(resp.cd_list) })
// 系统配置
} else if (data.resp_name === 'get_system_config') {
commit('setData', { name: 'settings', data: data.resp_info })
commit('setData', { name: 'settings', data: resp })
// 新增日志
} else if (data.resp_name === 'add_log') {
let logs = data.resp_info.add_log
const logs = asArray(resp.add_log)
let loglist = []
let logLists = [...state.logList]
for (let i = 0; i < logs.length; i++) {
@@ -451,7 +463,7 @@ const actions = {
commit('setData', { name: 'logList', data: list })
// 全部日志
} else if (data.resp_name === 'all_log') {
let logs = data.resp_info.add_log
const logs = asArray(resp.add_log)
let loglist = []
for (let i = 0; i < logs.length; i++) {
let texts = logs[i].split('|')
@@ -464,14 +476,15 @@ const actions = {
commit('setData', { name: 'logList', data: loglist })
// 提交任务报错处理
} else if (data.resp_name === 'submit_task_res') {
let error = data.resp_info
let task_res = '0x' + error.task_res.toString(16)
commit('setData', { name: 'printer_error', data: { type: 'error', notify: '任务' + error.task_uuid + '提交失败:' + submitErros[task_res] } })
if (resp.task_res != null) {
const task_res = '0x' + resp.task_res.toString(16)
commit('setData', { name: 'printer_error', data: { type: 'error', notify: '任务' + resp.task_uuid + '提交失败:' + submitErros[task_res] } })
}
// 打印报错处理
} else if (data.resp_name === 'printer_error') {
let error = data.resp_info
if (error.error) {
let errors = error.error
const error = resp
const errors = asArray(error.error)
if (errors.length) {
let continues = [8, 9, 10, 11, 12, 17, 19]
let nojumps = [7, 8, 9, 10, 11, 12, 17, 19]
let isClears = [20, 21]
@@ -540,15 +553,14 @@ const actions = {
}, 1000);
// 执行错误提示
} else {
if (data.resp_info.res_code === 0) {
if (resp.res_code === 0) {
} else {
commit('setData', { name: 'printer_error', data: { type: 'error', notify: data.resp_info.res_msg || '操作失败' } })
commit('setData', { name: 'printer_error', data: { type: 'error', notify: resp.res_msg || '操作失败' } })
}
}
} else {
// 未知消息
console.log('报错信息: ' + JSON.stringify(data))
} catch (err) {
console.warn('websocket handle error:', data.resp_name, err)
}
},
// 心跳检测重连
+3 -3
View File
@@ -923,7 +923,7 @@ export default {
that.serviceLoading = true
that.serviceText = '服务启动中'
that
.$runCmd(`bash ${shPath} start ${value}`)
.$runCmd(`bash ${that.shPath} start ${value}`)
.then((res) => {
that.$store.dispatch('chat/setDatas', { name: 'workStatus', data: true })
setTimeout(() => {
@@ -954,7 +954,7 @@ export default {
that.serviceLoading = true
that.serviceText = '服务关闭中'
that
.$runCmd(`bash ${shPath} stop ${value}`)
.$runCmd(`bash ${that.shPath} stop ${value}`)
.then((res) => {
that.$store.dispatch('chat/setDatas', { name: 'workStatus', data: false })
setTimeout(() => {
@@ -989,7 +989,7 @@ export default {
})
.then(({ value }) => {
that
.$runCmd(`bash ${activePath} ${value}`)
.$runCmd(`bash ${that.activePath} ${value}`)
.then((res) => {
})