对接接口
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
// import { getAllList, getChatList, bindId, chatBegin } from '@/api/message'
|
||||
// import { Message, MessageBox } from 'element-ui'
|
||||
|
||||
let timeouter = null
|
||||
let websock = null
|
||||
let isConnect = false
|
||||
@@ -8,49 +6,122 @@ let isConnect = false
|
||||
// 状态JSON
|
||||
// 打印机状态
|
||||
const PrinterStatus = {
|
||||
'I': '空闲',
|
||||
'B': '忙碌',
|
||||
'P': '正在打印'
|
||||
I: '空闲',
|
||||
B: '忙碌',
|
||||
P: '正在打印'
|
||||
}
|
||||
|
||||
// 错误状态
|
||||
const Error1 = {
|
||||
'0': '托盘移动错误',
|
||||
'1': '墨盒类型错误',
|
||||
'2': '抓取光盘时未检测到光盘光盘已用完',
|
||||
'3': '光盘掉落',
|
||||
'4': '墨水车空警告',
|
||||
'5': '光盘抓手错误',
|
||||
'6': '抓取多张光盘错误',
|
||||
'7': '机械臂挂钩错误或者机械臂归位错误',
|
||||
0: '托盘移动错误',
|
||||
1: '墨盒类型错误',
|
||||
2: '抓取光盘时未检测到光盘光盘已用完',
|
||||
3: '光盘掉落',
|
||||
4: '墨水车空警告',
|
||||
5: '光盘抓手错误',
|
||||
6: '抓取多张光盘错误',
|
||||
7: '机械臂挂钩错误或者机械臂归位错误'
|
||||
}
|
||||
|
||||
const Error2 = {
|
||||
'0': '墨水车伺服系统错误',
|
||||
'1': '墨水车失速错误',
|
||||
'2': '墨盒数据读取错误',
|
||||
'3': '打印图像超出范围',
|
||||
'4': '环境温度超出正常使用范围',
|
||||
'5': '墨盒短路',
|
||||
'6': '型号错误',
|
||||
'7': '缓冲区溢出错误',
|
||||
0: '墨水车伺服系统错误',
|
||||
1: '墨水车失速错误',
|
||||
2: '墨盒数据读取错误',
|
||||
3: '打印图像超出范围',
|
||||
4: '环境温度超出正常使用范围',
|
||||
5: '墨盒短路',
|
||||
6: '型号错误',
|
||||
7: '缓冲区溢出错误'
|
||||
}
|
||||
|
||||
const Error3 = {
|
||||
0: '光盘已经打印'
|
||||
}
|
||||
|
||||
// 光驱信息
|
||||
const CDName = {
|
||||
1: '下光驱',
|
||||
2: '上光驱'
|
||||
}
|
||||
const CDStatus = {
|
||||
0: '无法确定光盘状态',
|
||||
1: '没有光盘',
|
||||
2: '光驱托盘打开',
|
||||
3: '光驱未准备好',
|
||||
4: '光盘状态正常,光盘已插入'
|
||||
}
|
||||
// CD类型:CD:1,DVD:2, DVD_DL:3,BD:4,BD_DL:5,BD_TL:6,BD_QL:7
|
||||
const CDTypes = {
|
||||
1: 'CD',
|
||||
2: 'DVD',
|
||||
3: 'DVD_DL',
|
||||
4: 'BD',
|
||||
5: 'BD_DL',
|
||||
6: 'BD_TL',
|
||||
7: 'BD_QL'
|
||||
}
|
||||
|
||||
const getDefaultState = () => {
|
||||
return {
|
||||
reconnections: 0,
|
||||
PrinterStatus,
|
||||
Error1,
|
||||
Error2,
|
||||
Error3,
|
||||
CDName,
|
||||
CDStatus,
|
||||
CDTypes,
|
||||
// 任务列表
|
||||
task_list: [],
|
||||
// 打印机信息
|
||||
printer_info: {
|
||||
blue_last: 33, //蓝色墨盒遗留
|
||||
blue_last: 0, //蓝色墨盒遗留
|
||||
cover_flag: false, //是否盖盖
|
||||
left_strong_cd_num: 99, //左盘仓剩余盘数量
|
||||
printer_name: '', //打印机名称
|
||||
printer_status: 73, //打印机状态 数字转成字符为I
|
||||
printer_tray: 73, //打印机托盘状态 数字转成字符为I
|
||||
red_last: 29, //红色墨盒遗留
|
||||
rigth_strong_cd_num: 99, //右盘仓剩余盘数量
|
||||
yellow_last: 27 //黄色墨盒遗留
|
||||
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
|
||||
}
|
||||
]
|
||||
},
|
||||
// 光驱信息
|
||||
cd_list: [
|
||||
{
|
||||
cd_pos: 1, // 设备位置 1:下光驱,2:上光驱
|
||||
cd_status: 4, // 设备状态 0:无法确定光盘状态 ,1:没有光盘 , 2:光驱托盘打开, 3:光驱未准备好,4:光盘状态正常,光盘已插入
|
||||
cd_taskid: '', // 当前任务id
|
||||
dev_path: '', // 光驱路径
|
||||
cd_assid: '', // 作业的卷标名
|
||||
total_size: 0, // 总容量
|
||||
use_size: 0, // 已使用容量
|
||||
copy_scheduler: 0 // 任务进度
|
||||
},
|
||||
{
|
||||
cd_pos: 2,
|
||||
cd_status: 1,
|
||||
cd_taskid: '',
|
||||
dev_path: ''
|
||||
}
|
||||
],
|
||||
// 错误信息
|
||||
printer_error: {
|
||||
error1: '',
|
||||
error2: '',
|
||||
error3: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +141,6 @@ const actions = {
|
||||
if ((websock && isConnect) || !rootState.user.token) {
|
||||
return
|
||||
}
|
||||
console.log(process.env.VUE_APP_SOCKET_API)
|
||||
websock = new WebSocket(process.env.VUE_APP_SOCKET_API)
|
||||
websock.onmessage = function (res) {
|
||||
dispatch('websocketonmessage', res)
|
||||
@@ -96,30 +166,42 @@ const actions = {
|
||||
info.printer_status = String.fromCharCode(info.printer_status)
|
||||
info.printer_tray = String.fromCharCode(info.printer_tray)
|
||||
commit('chat/setData', { name: 'printer_info', data: info })
|
||||
} else if (data.resp_name === 'cd_list') {
|
||||
let info = data.resp_info
|
||||
commit('chat/setData', { name: 'cd_list', data: info })
|
||||
} else if (data.resp_name === 'printer_error') {
|
||||
let error = data.resp_info
|
||||
let info = {
|
||||
error1: '',
|
||||
error2: '',
|
||||
error3: ''
|
||||
}
|
||||
commit('chat/setData', { name: 'printer_error', data: info })
|
||||
if (error.error1) {
|
||||
let errors = error.error1.split('')
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
if (errors[i] == 1) info.error1 = i
|
||||
}
|
||||
}
|
||||
if (error.error2) {
|
||||
let errors = error.error2.split('')
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
if (errors[i] == 1) info.error2 = i
|
||||
}
|
||||
}
|
||||
if (error.error3) {
|
||||
let errors = error.error3.split('')
|
||||
for (let i = 0; i < errors.length; i++) {
|
||||
if (errors[i] == 1) info.error3 = i
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
commit('chat/setData', { name: 'printer_error', data: info })
|
||||
}, 100)
|
||||
}
|
||||
} else {
|
||||
if (data.type === 'init') {
|
||||
state.pingNum = 0
|
||||
clearTimeout(timeouter)
|
||||
dispatch('pingCheck')
|
||||
commit('set_client_id', data.client_id)
|
||||
// 初始化
|
||||
bindId({
|
||||
client_id: data.client_id
|
||||
})
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
alert(err.msg)
|
||||
// Message.error(err.msg)
|
||||
})
|
||||
} else if (data.type === 'ping') {
|
||||
// 心跳回执
|
||||
state.pingNum = 0
|
||||
dispatch('websocketsend', { type: 'pong' })
|
||||
} else {
|
||||
// 未知消息
|
||||
console.log('未知消息: ' + JSON.stringify(data))
|
||||
}
|
||||
// 未知消息
|
||||
console.log('未知消息: ' + JSON.stringify(data))
|
||||
}
|
||||
},
|
||||
// 心跳检测重连
|
||||
|
||||
Reference in New Issue
Block a user