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