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

update:修改打印加上连接失败提示

parent 842bae6b
......@@ -2,7 +2,7 @@
<view class="common-container">
<!-- <u-button @click="handleTest">跳转测试</u-button> -->
<view class="header">
<image mode="widthFix" class="header-logo" style="width: 100px; margin: 10px auto; display: block" src="/static/logo.png"></image>
<image mode="widthFix" class="header-logo" style="width: 80px; margin: 10px auto; display: block" src="/static/logo.png"></image>
<TabHeader></TabHeader>
<view class="setting-body" @click="handleUserTaped">
<u-icon name="list" size="45" class="setting-icon"></u-icon>
......@@ -303,7 +303,7 @@ export default {
}
.header {
width: 110px;
width: 90px;
background-color: #132138;
color: aliceblue;
font-size: 25px;
......
import { mapState } from 'vuex'
import {
mapState
} from 'vuex'
import store from "@/store"
import io from '@hyoga/uni-socket.io';
// 尝试将用户在根目录中的store/index.js的vuex的state变量,全部加载到全局变量中
let $uStoreKey = [];
try{
try {
$uStoreKey = store.state ? Object.keys(store.state) : [];
}catch(e){
} catch (e) {
}
......@@ -17,13 +19,15 @@ module.exports = {
// 如果要修改vuex的state的version变量为1.0.1 => this.$u.vuex('version', '1.0.1')
this.$u.vuex = (name, value) => {
this.$store.commit('$uStore', {
name,value
name,
value
})
}
},
data() {
return {
pdfSocket: null
pdfSocket: null,
socketConnect: false,
}
},
computed: {
......@@ -31,7 +35,7 @@ module.exports = {
...mapState($uStoreKey)
},
methods: {
createSocket() {
createSocket(params) {
this.pdfSocket = io(this.vuex_printerHostUrl, {
transports: ['websocket'],
auth: {
......@@ -39,23 +43,44 @@ module.exports = {
},
});
this.pdfSocket.on('connect', () => {
globalThis.connect = true;
this.socketConnect = true;
// console.log('连接成功444');
this.printPdfSocket(params)
// TODO: Do something for your project
});
this.pdfSocket.on('clients', (clients) => {
globalThis.clients = clients;
this.socketConnect = clients;
console.log(clients, 'clients');
});
this.pdfSocket.on('printerList', (printerList) => {
globalThis.printerList = printerList;
console.log(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)
},
printPdfSocket(params) {
// console.log(this.pdfSocket, 'pdfSocket')
if (!this.pdfSocket) {
this.createSocket()
if (!this.socketConnect) {
this.createSocket(params)
return
}
this.$u.api
.getPrintDown(params)
......
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