Commit a091d076 authored by 张海景's avatar 张海景

update:修改打印的方法

parent 51b1b54a
......@@ -6,6 +6,10 @@ export default {
plus.screen.lockOrientation('landscape-primary');
// #endif
},
//把想要全局的数据放在globalData对象里,globalData是uniapp的不可以自定义命名。
globalData:{
printSocket:null
},
onShow: function () {},
onHide: function () {}
};
......
......@@ -135,6 +135,7 @@ export default {
};
},
created() {
this.createSocket()
uni.$on('switchTab', (indexCode) => {
this.tabIndex = indexCode;
});
......@@ -238,8 +239,11 @@ export default {
this.$u.api.getUserPrintInfo().then((res) => {
// console.log(res, 'res888')
if (res.code === 200) {
this.$u.vuex('vuex_printerHostUrl', 'http://' + res.data.printerIp + ':' + res.data.printerPort);
this.$u.vuex('vuex_printerName', res.data.printerName);
this.$u.vuex('vuex_printerInfo', {
hostUrl:'http://'+ res.data.printerIp +':'+ res.data.printerPort,
printerName: res.data.printerName
});
this.createSocket()
}
});
this.getPrint();
......
......@@ -1534,8 +1534,12 @@ export default {
this.printTemplateData.printTemplate = this.$refs.printTemplateRef.tableSelectData[0].name
this.printTemplateVisible = false
},
doFeedback() {
async doFeedback() {
// this.reset();
if (!this.vuex_printConnect) {
this.$u.toast('打印机连接失败');
return
}
this.feedbackForms = [];
this.tableSelectData.forEach((item) => {
let defQualify = item.quantity-item.quantityQualify-item.quantityUnqualify;
......
......@@ -86,8 +86,11 @@
this.$u.api.getUserPrintInfo().then(res=> {
// console.log(res, 'res888')
if (res.code === 200) {
this.$u.vuex('vuex_printerHostUrl', 'http://'+ res.data.printerIp +':'+ res.data.printerPort);
this.$u.vuex('vuex_printerName', res.data.printerName);
this.$u.vuex('vuex_printerInfo', {
hostUrl:'http://'+ res.data.printerIp +':'+ res.data.printerPort,
printerName: res.data.printerName
});
this.createSocket()
}
})
setTimeout(() => {
......
......@@ -26,8 +26,6 @@ module.exports = {
},
data() {
return {
pdfSocket: null,
socketConnect: false,
}
},
computed: {
......@@ -35,66 +33,61 @@ module.exports = {
...mapState($uStoreKey)
},
methods: {
createSocket(params) {
this.pdfSocket = io(this.vuex_printerHostUrl, {
createSocket() {
this.$u.vuex('vuex_printConnect', false)
let socket = io(this.vuex_printerInfo.hostUrl, {
transports: ['websocket'],
auth: {
token: 'Bearer ' + this.vuex_token, // 在此处填入你 client 设置的 token,缺省可留空
},
});
this.pdfSocket.on('connect', () => {
this.socketConnect = true;
// console.log('连接成功444');
this.printPdfSocket(params)
socket.on('connect', () => {
console.log('连接成功444');
// TODO: Do something for your project
this.$u.vuex('vuex_printConnect', true);
// console.log(this.vuex_printConnect, 'vuex_printConnect');
});
this.pdfSocket.on('clients', (clients) => {
this.socketConnect = clients;
socket.on('clients', (clients) => {
console.log(clients, 'clients');
});
this.pdfSocket.on('printerList', (printerList) => {
socket.on('printerList', (printerList) => {
// globalThis.printerList = printerList;
// console.log(printerList, 'printerList');
});
this.pdfSocket.on("success", (res) => {
console.log(res, '打印成功')
})
this.pdfSocket.on("error", (res) => {
console.log(res, '打印失败')
})
this.pdfSocket.on("disconnect", () => {
this.socketConnect = false;
console.log('打印机断开')
})
setTimeout(() => {
if (!this.socketConnect) {
console.log('连接失败')
this.$u.toast('打印机连接失败')
}
}, 1000)
socket.on('success', (res) => {
console.log(res, '打印成功');
});
socket.on('error', (res) => {
console.log(res, '打印失败');
});
socket.on('disconnect', () => {
console.log('打印机断开');
this.$u.vuex('vuex_printConnect', false);
});
getApp().globalData.printSocket = socket
},
printPdfSocket(params) {
// console.log(this.pdfSocket, 'pdfSocket')
if (!this.socketConnect) {
this.createSocket(params)
return
async printPdfSocket(params) {
if (!this.vuex_printerInfo.hostUrl) {
this.$u.toast('请绑定打印机');
return;
}
this.$u.api
.getPrintDown(params)
.then((res) => {
if (this.vuex_printConnect) {
this.$u.api.getPrintDown(params).then((res) => {
if (res.code === 200) {
this.pdfSocket.emit('news', {
getApp().globalData.printSocket.emit('news', {
client: null,
printer: this.vuex_printerName,
printer: this.vuex_printerInfo.printerName,
type: 'url_pdf',
// pdf_path: 'http://192.168.3.91:8082/static/123.pdf',
pdf_path: res.fileUrl,
});
}
});
} else {
this.$u.toast('打印机连接失败');
}
}
}
}
\ No newline at end of file
......@@ -16,8 +16,16 @@ try {
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = ['vuex_user', 'vuex_token', 'vuex_remember', 'vuex_locale', 'vuex_isAgent', 'vuex_workstation',
'vuex_task', 'vuex_printerHostUrl', 'vuex_printerName'
let saveStateKeys = [
'vuex_user',
'vuex_token',
'vuex_remember',
'vuex_locale',
'vuex_isAgent',
'vuex_workstation',
'vuex_task',
'vuex_printerInfo',
'vuex_printConnect',
];
// 保存变量到本地存储中
......@@ -38,9 +46,11 @@ const store = new Vuex.Store({
state: {
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {
userName: 'Aidex'
},
vuex_user: lifeData.vuex_user
? lifeData.vuex_user
: {
userName: 'Aidex',
},
vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
vuex_remember: lifeData.vuex_remember ? lifeData.vuex_remember : '',
vuex_locale: lifeData.vuex_locale ? lifeData.vuex_locale : '',
......@@ -53,10 +63,14 @@ const store = new Vuex.Store({
vuex_workunit: null,
//当前工作站正在进行的生产任务
vuex_task: null,
// 打印机服务器地址
vuex_printerHostUrl: lifeData.vuex_printerHostUrl ? lifeData.vuex_printerHostUrl : '',
// 打印机名称s
vuex_printerName: lifeData.vuex_printerName ? lifeData.vuex_printerName : '',
// 打印机服务器信息
vuex_printerInfo: lifeData.vuex_printerInfo
? lifeData.vuex_printerInfo
: '',
// 存打印状态
vuex_printConnect: lifeData.vuex_printConnect
? lifeData.vuex_printConnect
: '',
// 自定义tabbar数据
// vuex_tabbar: [{
......@@ -99,9 +113,9 @@ const store = new Vuex.Store({
saveKey = payload.name;
}
// 保存变量到本地,见顶部函数定义
saveLifeData(saveKey, state[saveKey])
}
}
})
saveLifeData(saveKey, state[saveKey]);
},
},
});
export default store
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment