优化服务
This commit is contained in:
+130
-124
@@ -1,7 +1,6 @@
|
||||
// import { getAllList, getChatList, bindId, chatBegin } from '@/api/message'
|
||||
let timeouter = null
|
||||
let websock = null
|
||||
let isConnect = false
|
||||
|
||||
// 状态JSON
|
||||
// 打印机状态
|
||||
@@ -103,8 +102,100 @@ const cd_types = [
|
||||
}
|
||||
]
|
||||
|
||||
const defaultData = {
|
||||
// 任务列表
|
||||
task_list: [
|
||||
// {
|
||||
// task_uuid: '20204215',
|
||||
// task_name: '复制任务',
|
||||
// task_size: 100000,
|
||||
// finish_freq: 2,
|
||||
// total_freq: 10,
|
||||
// task_status: 2,
|
||||
// ass_task: [
|
||||
// {
|
||||
// task_size: 100000,
|
||||
// cd_type: 2,
|
||||
// start_time: '2024-04-01 12:00:00',
|
||||
// finish_time: '2024-04-01 12:00:00',
|
||||
// task_status: 2
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
],
|
||||
// 打印机信息
|
||||
printer_info: {
|
||||
blue_last: 0, //蓝色墨盒遗留
|
||||
cover_flag: false, //是否盖盖
|
||||
printer_name: '', //打印机名称
|
||||
printer_status: 'I', //打印机状态 数字转成字符为I
|
||||
printer_tray: 'I', //打印机托盘状态 数字转成字符为I
|
||||
red_last: 0, //红色墨盒遗留
|
||||
yellow_last: 0, //黄色墨盒遗留
|
||||
system_ip: '', //主机IP
|
||||
system_name: '', //主机名称
|
||||
// 左右盘仓
|
||||
strong_list: [
|
||||
{
|
||||
strong_pos: 1, // 1:左盘仓,2:右盘仓
|
||||
cd_type: 2, //CD类型:CD:1,DVD:2, DVD_DL:3,BD:4,BD_DL:5,BD_TL:6,BD_QL:7
|
||||
cd_num: 0
|
||||
},
|
||||
{
|
||||
strong_pos: 2,
|
||||
cd_type: 1,
|
||||
cd_num: 0
|
||||
}
|
||||
],
|
||||
strongList: {
|
||||
1: {
|
||||
strong_pos: 1,
|
||||
cd_type: 2,
|
||||
cd_num: 0
|
||||
},
|
||||
2: {
|
||||
strong_pos: 2,
|
||||
cd_type: 1,
|
||||
cd_num: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
// 光驱信息
|
||||
cd_list: [
|
||||
{
|
||||
cd_pos: 1, // 设备位置 1:下光驱,2:上光驱
|
||||
cd_status: 1, // 设备状态 0:无法确定光盘状态 ,1:没有光盘 , 2:光驱托盘打开, 3:光驱未准备好,4:光盘状态正常,光盘已插入
|
||||
cd_taskid: '', // 当前任务id
|
||||
dev_path: '', // 光驱路径
|
||||
dev_type: 2, // 光驱类型
|
||||
cd_assid: '', // 作业的卷标名
|
||||
total_size: 0, // 总容量
|
||||
use_size: 0, // 已使用容量
|
||||
copy_scheduler: 0 // 任务进度
|
||||
},
|
||||
{
|
||||
cd_pos: 2,
|
||||
cd_status: 1,
|
||||
cd_taskid: '',
|
||||
dev_path: '',
|
||||
dev_type: 1
|
||||
}
|
||||
],
|
||||
// 日志信息
|
||||
logList: [
|
||||
// {
|
||||
// time: '2024-04-01 12:00:00',
|
||||
// text: '任务开始',
|
||||
// status: 'INFO'
|
||||
// }
|
||||
],
|
||||
allLogList: []
|
||||
}
|
||||
|
||||
const getDefaultState = () => {
|
||||
return {
|
||||
isConnect: false,
|
||||
serviceStatus: false,
|
||||
reconnections: 0,
|
||||
PrinterStatus,
|
||||
Error1,
|
||||
@@ -115,99 +206,10 @@ const getDefaultState = () => {
|
||||
diskTypes,
|
||||
CDTypes,
|
||||
cd_types,
|
||||
// 任务列表
|
||||
task_list: [
|
||||
// {
|
||||
// task_uuid: '20204215',
|
||||
// task_name: '复制任务',
|
||||
// task_size: 100000,
|
||||
// finish_freq: 2,
|
||||
// total_freq: 10,
|
||||
// task_status: 2,
|
||||
// ass_task: [
|
||||
// {
|
||||
// task_size: 100000,
|
||||
// cd_type: 2,
|
||||
// start_time: '2024-04-01 12:00:00',
|
||||
// finish_time: '2024-04-01 12:00:00',
|
||||
// task_status: 2
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
],
|
||||
// 打印机信息
|
||||
printer_info: {
|
||||
blue_last: 0, //蓝色墨盒遗留
|
||||
cover_flag: false, //是否盖盖
|
||||
printer_name: '', //打印机名称
|
||||
printer_status: 'I', //打印机状态 数字转成字符为I
|
||||
printer_tray: 'I', //打印机托盘状态 数字转成字符为I
|
||||
red_last: 0, //红色墨盒遗留
|
||||
yellow_last: 0, //黄色墨盒遗留
|
||||
system_ip: '', //主机IP
|
||||
system_name: '', //主机名称
|
||||
// 左右盘仓
|
||||
strong_list: [
|
||||
{
|
||||
strong_pos: 1, // 1:左盘仓,2:右盘仓
|
||||
cd_type: 2, //CD类型:CD:1,DVD:2, DVD_DL:3,BD:4,BD_DL:5,BD_TL:6,BD_QL:7
|
||||
cd_num: 0
|
||||
},
|
||||
{
|
||||
strong_pos: 2,
|
||||
cd_type: 1,
|
||||
cd_num: 0
|
||||
}
|
||||
],
|
||||
strongList: {
|
||||
1: {
|
||||
strong_pos: 1,
|
||||
cd_type: 2,
|
||||
cd_num: 0
|
||||
},
|
||||
2: {
|
||||
strong_pos: 2,
|
||||
cd_type: 1,
|
||||
cd_num: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
// 光驱信息
|
||||
cd_list: [
|
||||
{
|
||||
cd_pos: 1, // 设备位置 1:下光驱,2:上光驱
|
||||
cd_status: 1, // 设备状态 0:无法确定光盘状态 ,1:没有光盘 , 2:光驱托盘打开, 3:光驱未准备好,4:光盘状态正常,光盘已插入
|
||||
cd_taskid: '', // 当前任务id
|
||||
dev_path: '', // 光驱路径
|
||||
dev_type: 2, // 光驱类型
|
||||
cd_assid: '', // 作业的卷标名
|
||||
total_size: 0, // 总容量
|
||||
use_size: 0, // 已使用容量
|
||||
copy_scheduler: 0 // 任务进度
|
||||
},
|
||||
{
|
||||
cd_pos: 2,
|
||||
cd_status: 1,
|
||||
cd_taskid: '',
|
||||
dev_path: '',
|
||||
dev_type: 1
|
||||
}
|
||||
],
|
||||
refreshTime: 10,
|
||||
// 错误信息
|
||||
printer_error: {
|
||||
error1: '',
|
||||
error2: '',
|
||||
error3: ''
|
||||
},
|
||||
// 日志信息
|
||||
logList: [
|
||||
// {
|
||||
// time: '2024-04-01 12:00:00',
|
||||
// text: '任务开始',
|
||||
// status: 'INFO'
|
||||
// }
|
||||
],
|
||||
allLogList: []
|
||||
printer_error: {},
|
||||
...defaultData
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,9 +223,9 @@ const mutations = {
|
||||
|
||||
const actions = {
|
||||
// 初始化websocket
|
||||
initWebSocket({ commit, dispatch, rootState }) {
|
||||
initWebSocket({ state, dispatch, rootState }) {
|
||||
if (typeof WebSocket === 'undefined') return console.log('您的浏览器不支持websocket')
|
||||
if ((websock && isConnect) || !rootState.user.token) {
|
||||
if ((websock && state.isConnect) || !rootState.user.token) {
|
||||
return
|
||||
}
|
||||
websock = new WebSocket(process.env.VUE_APP_SOCKET_API)
|
||||
@@ -311,7 +313,6 @@ const actions = {
|
||||
error2: '',
|
||||
error3: ''
|
||||
}
|
||||
commit('setData', { name: 'printer_error', data: info })
|
||||
if (error.error1) {
|
||||
let errors = error.error1.split('')
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
@@ -331,7 +332,17 @@ const actions = {
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
commit('setData', { name: 'printer_error', data: info })
|
||||
if (info.error1 || info.error1 === 0) {
|
||||
commit('setData', { name: 'printer_error', data: {type: 'error', notify: this.$store.state.Error1[info.error1], message: '' } })
|
||||
}
|
||||
if (info.error2 || info.error2 === 0) {
|
||||
commit('setData', { name: 'printer_error', data: {type: 'error', notify: this.$store.state.Error2[info.error2], message: '' } })
|
||||
|
||||
}
|
||||
if (info.error3 || info.error3 === 0) {
|
||||
commit('setData', { name: 'printer_error', data: {type: 'error', notify: this.$store.state.Error3[info.error3], message: '' } })
|
||||
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
} else {
|
||||
@@ -352,46 +363,41 @@ const actions = {
|
||||
},
|
||||
// 发送消息
|
||||
websocketsend({ commit, dispatch }, res) {
|
||||
if (!websock) {
|
||||
// Message.info('webSocket未连接,正在尝试连接')
|
||||
dispatch('initWebSocket')
|
||||
return
|
||||
}
|
||||
websock.send(JSON.stringify(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()
|
||||
return
|
||||
}
|
||||
websock.send(JSON.stringify(res))
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
// 链接建立之后执行的方法
|
||||
websocketonopen: ({ commit, dispatch }, res) => {
|
||||
console.log('链接建立之后执行send方法发送数据', res)
|
||||
isConnect = true
|
||||
commit('setData', { name: 'isConnect', data: true })
|
||||
commit('setData', { name: 'serviceStatus', data: true })
|
||||
},
|
||||
// 链接关闭之后执行的方法
|
||||
websocketonclose: ({ commit, dispatch }, res) => {
|
||||
console.log('断开链接', res)
|
||||
// 关闭
|
||||
if (isConnect) {
|
||||
isConnect = false
|
||||
dispatch('initWebSocket')
|
||||
commit('setData', { name: 'isConnect', data: false })
|
||||
for (let key in defaultData) {
|
||||
commit('setData', { name: key, data: defaultData[key] })
|
||||
}
|
||||
},
|
||||
// 链接错误之后执行的方法
|
||||
websocketonerror({ commit, dispatch }, res) {
|
||||
isConnect = false
|
||||
websocketonerror({ state, commit, dispatch }, res) {
|
||||
commit('setData', { name: 'isConnect', data: false })
|
||||
commit('setData', { name: 'serviceStatus', data: false })
|
||||
state.reconnections += 1
|
||||
if (state.reconnections <= 3) {
|
||||
setTimeout(() => {
|
||||
dispatch('initWebSocket')
|
||||
}, 5000)
|
||||
} else {
|
||||
// state.reconnections = 0
|
||||
// dispatch('initWebSocket')
|
||||
// MessageBox.alert('服务器启动异常,请刷新重试', '温馨提示', {
|
||||
// confirmButtonText: '刷新',
|
||||
// showCancelButton: true
|
||||
// })
|
||||
// .then(() => {
|
||||
// })
|
||||
// .catch(() => {})
|
||||
}
|
||||
const refreshTime = parseInt(state.refreshTime)*1000
|
||||
setTimeout(() => {
|
||||
dispatch('initWebSocket')
|
||||
}, refreshTime)
|
||||
},
|
||||
// 关闭
|
||||
closeWebsocket: () => {
|
||||
|
||||
Reference in New Issue
Block a user