diff --git a/src/renderer/App.vue b/src/renderer/App.vue
index 4937a2e..09602ca 100644
--- a/src/renderer/App.vue
+++ b/src/renderer/App.vue
@@ -15,6 +15,7 @@ export default {
watch: {
'$store.state.chat.printer_error': {
handler(val) {
+ console.log(val)
if (val.message) {
this.$message({
message: val.message,
@@ -29,6 +30,33 @@ export default {
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,
immediate: true
diff --git a/src/renderer/store/modules/chat.js b/src/renderer/store/modules/chat.js
index 1e27607..e1e3c00 100644
--- a/src/renderer/store/modules/chat.js
+++ b/src/renderer/store/modules/chat.js
@@ -223,6 +223,7 @@ const getDefaultState = () => {
return {
isConnect: false,
serviceStatus: false,
+ workStatus: true,
reconnections: 0,
PrinterStatus,
CDName,
@@ -247,7 +248,7 @@ const mutations = {
const actions = {
// 初始化websocket
- initWebSocket({ state, dispatch, rootState }) {
+ initWebSocket({ state, commit, dispatch, rootState }) {
if (typeof WebSocket === 'undefined') return console.log('您的浏览器不支持websocket')
if ((websock && state.isConnect) || !rootState.user.token) {
return
@@ -342,54 +343,40 @@ const actions = {
// 打印报错处理
} else if (data.resp_name === 'printer_error') {
let error = data.resp_info
- let info = {
- error1: '',
- error2: '',
- error3: ''
- }
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++) {
- 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) {
- let errors = error.error2.split('')
+ let errors = error.error2.toString(2).split('').reverse()
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) {
- let errors = error.error3.split('')
+ let errors = error.error3.toString(2).split('').reverse()
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) {
- commit('setData', { name: 'printer_error', data: {type: 'error', notify: printer_errors[error.printer_error], message: '' } })
- dispatch('websocketsend', {
- req_name: 'next_task',
- req_type: 1,
- req_info: {}
- }).then(() => {
-
- }).catch(() => {
-
- })
+ commit('setData', { name: 'printer_error', data: {type: 'error', confirm: printer_errors[error.printer_error], req: 'continue_task' } })
}
- 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 {
// 未知消息
@@ -410,10 +397,12 @@ const actions = {
// 发送消息
websocketsend({ commit, dispatch }, res) {
return new Promise((resolve, reject) => {
- if (!websock || !state.isConnect || !state.serviceStatus) {
- commit('setData', { name: 'printer_error', data: {type: 'error', message: '服务连接失败,正在尝试重新连接', notify: '' } })
- dispatch('initWebSocket')
- reject()
+ if (!state.serviceStatus) {
+ commit('setData', { name: 'printer_error', data: {type: 'warning', message: '服务连接中,请耐心等待', notify: '' } })
+ return
+ }
+ if (!state.isConnect) {
+ commit('setData', { name: 'printer_error', data: {type: 'warning', message: '请先打开服务', notify: '' } })
return
}
websock.send(JSON.stringify(res))
@@ -427,13 +416,19 @@ const actions = {
commit('setData', { name: 'serviceStatus', data: true })
},
// 链接关闭之后执行的方法
- websocketonclose: ({ commit, dispatch }, res) => {
+ websocketonclose: ({ state, commit, dispatch }, res) => {
console.log('断开链接', res)
// 关闭
commit('setData', { name: 'isConnect', data: false })
for (let key in defaultData) {
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) {
diff --git a/src/renderer/views/dashboard/index.vue b/src/renderer/views/dashboard/index.vue
index 9bebdfd..24b97bb 100644
--- a/src/renderer/views/dashboard/index.vue
+++ b/src/renderer/views/dashboard/index.vue
@@ -11,7 +11,7 @@