This commit is contained in:
24kycj
2024-11-29 10:35:43 +08:00
parent f125b5cace
commit af7380352b
3 changed files with 74 additions and 52 deletions
+28
View File
@@ -15,6 +15,7 @@ export default {
watch: { watch: {
'$store.state.chat.printer_error': { '$store.state.chat.printer_error': {
handler(val) { handler(val) {
console.log(val)
if (val.message) { if (val.message) {
this.$message({ this.$message({
message: val.message, message: val.message,
@@ -29,6 +30,33 @@ export default {
duration: 0 duration: 0
}) })
} }
if (val.confirm) {
this.$confirm(val.confirm, '温馨提示', {
confirmButtonText: '确定',
showClose: false,
showCancelButton: false,
type: 'warning'
}).then(() => {
if (val.req && val.req === 'continue_task') {
// 下一个任务
this.$store.dispatch('websocketsend', {
req_name: 'continue_task',
req_type: 1,
req_info: {}
}).then(() => {
}).catch(() => {
})
}
}).catch(() => {
});
this.$messageBox({
message: val.messageBox,
type: val.type,
})
}
}, },
deep: true, deep: true,
immediate: true immediate: true
+35 -40
View File
@@ -223,6 +223,7 @@ const getDefaultState = () => {
return { return {
isConnect: false, isConnect: false,
serviceStatus: false, serviceStatus: false,
workStatus: true,
reconnections: 0, reconnections: 0,
PrinterStatus, PrinterStatus,
CDName, CDName,
@@ -247,7 +248,7 @@ const mutations = {
const actions = { const actions = {
// 初始化websocket // 初始化websocket
initWebSocket({ state, dispatch, rootState }) { initWebSocket({ state, commit, dispatch, rootState }) {
if (typeof WebSocket === 'undefined') return console.log('您的浏览器不支持websocket') if (typeof WebSocket === 'undefined') return console.log('您的浏览器不支持websocket')
if ((websock && state.isConnect) || !rootState.user.token) { if ((websock && state.isConnect) || !rootState.user.token) {
return return
@@ -342,54 +343,40 @@ const actions = {
// 打印报错处理 // 打印报错处理
} else if (data.resp_name === 'printer_error') { } else if (data.resp_name === 'printer_error') {
let error = data.resp_info let error = data.resp_info
let info = {
error1: '',
error2: '',
error3: ''
}
if (error.error1) { if (error.error1) {
let errors = error.error1.split('') let errors = error.error1.toString(2).split('').reverse()
console.log(errors)
for (let i = 0; i < errors.length; i++) { for (let i = 0; i < errors.length; i++) {
if (errors[i] == 1) info.error1 = i if (errors[i] == 1) {
setTimeout(() => {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error1[i] } })
}, 500);
}
} }
} }
if (error.error2) { if (error.error2) {
let errors = error.error2.split('') let errors = error.error2.toString(2).split('').reverse()
for (let i = 0; i < errors.length; i++) { for (let i = 0; i < errors.length; i++) {
if (errors[i] == 1) info.error2 = i if (errors[i] == 1) {
setTimeout(() => {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error2[i] } })
}, 500);
}
} }
} }
if (error.error3) { if (error.error3) {
let errors = error.error3.split('') let errors = error.error3.toString(2).split('').reverse()
for (let i = 0; i < errors.length; i++) { for (let i = 0; i < errors.length; i++) {
if (errors[i] == 1) info.error3 = i if (errors[i] == 1) {
setTimeout(() => {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error3[i] } })
}, 500);
}
} }
} }
if (error.printer_error) { if (error.printer_error) {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: printer_errors[error.printer_error], message: '' } }) commit('setData', { name: 'printer_error', data: {type: 'error', confirm: printer_errors[error.printer_error], req: 'continue_task' } })
dispatch('websocketsend', {
req_name: 'next_task',
req_type: 1,
req_info: {}
}).then(() => {
}).catch(() => {
})
} }
setTimeout(() => {
if (info.error1 || info.error1 === 0) {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error1[info.error1], message: '' } })
}
if (info.error2 || info.error2 === 0) {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error2[info.error2], message: '' } })
}
if (info.error3 || info.error3 === 0) {
commit('setData', { name: 'printer_error', data: {type: 'error', notify: Error3[info.error3], message: '' } })
}
}, 100)
} }
} else { } else {
// 未知消息 // 未知消息
@@ -410,10 +397,12 @@ const actions = {
// 发送消息 // 发送消息
websocketsend({ commit, dispatch }, res) { websocketsend({ commit, dispatch }, res) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!websock || !state.isConnect || !state.serviceStatus) { if (!state.serviceStatus) {
commit('setData', { name: 'printer_error', data: {type: 'error', message: '服务连接失败,正在尝试重新连接', notify: '' } }) commit('setData', { name: 'printer_error', data: {type: 'warning', message: '服务连接中,请耐心等待', notify: '' } })
dispatch('initWebSocket') return
reject() }
if (!state.isConnect) {
commit('setData', { name: 'printer_error', data: {type: 'warning', message: '请先打开服务', notify: '' } })
return return
} }
websock.send(JSON.stringify(res)) websock.send(JSON.stringify(res))
@@ -427,13 +416,19 @@ const actions = {
commit('setData', { name: 'serviceStatus', data: true }) commit('setData', { name: 'serviceStatus', data: true })
}, },
// 链接关闭之后执行的方法 // 链接关闭之后执行的方法
websocketonclose: ({ commit, dispatch }, res) => { websocketonclose: ({ state, commit, dispatch }, res) => {
console.log('断开链接', res) console.log('断开链接', res)
// 关闭 // 关闭
commit('setData', { name: 'isConnect', data: false }) commit('setData', { name: 'isConnect', data: false })
for (let key in defaultData) { for (let key in defaultData) {
commit('setData', { name: key, data: defaultData[key] }) commit('setData', { name: key, data: defaultData[key] })
} }
if (state.workStatus) {
const refreshTime = parseInt(state.refreshTime)*1000
setTimeout(() => {
dispatch('initWebSocket')
}, refreshTime)
}
}, },
// 链接错误之后执行的方法 // 链接错误之后执行的方法
websocketonerror({ state, commit, dispatch }, res) { websocketonerror({ state, commit, dispatch }, res) {
+9 -10
View File
@@ -11,7 +11,7 @@
<img src="@/assets/images/Search_icon.png" /> <img src="@/assets/images/Search_icon.png" />
<div>打开作业文件</div> <div>打开作业文件</div>
</div> </div>
<div @click="goUrl('/manage')" class="flex_box flex_row_center top_btn2"> <div @click="goSet('/manage')" class="flex_box flex_row_center top_btn2">
<img src="@/assets/images/Setting_icon.png" /> <img src="@/assets/images/Setting_icon.png" />
<div>系统设置</div> <div>系统设置</div>
</div> </div>
@@ -541,9 +541,15 @@ export default {
return return
} }
if (e) { if (e) {
that.store.commit('setData', { name: 'workStatus', data: true })
setTimeout(() => {
that.$store.dispatch('chat/initWebSocket') that.$store.dispatch('chat/initWebSocket')
}, 500);
} else { } else {
that.store.commit('setData', { name: 'workStatus', data: false })
setTimeout(() => {
that.$store.dispatch('chat/closeWebsocket') that.$store.dispatch('chat/closeWebsocket')
}, 500);
} }
}, },
// 执行 // 执行
@@ -716,15 +722,8 @@ export default {
} }
that.showAll = !that.showAll that.showAll = !that.showAll
}, },
// 跳转 // 跳转设置
goUrl(e) { goSet(e) {
if (!that.workStatus) {
that.$message({
message: '请先连接服务',
type: 'warning'
})
return
}
that.$router.push({ path: e }) that.$router.push({ path: e })
}, },
// 退出登录 // 退出登录