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

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

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