|
@@ -1,12 +1,13 @@
|
|
|
<template>
|
|
|
<view class="printconfig">
|
|
|
- <view v-if="initPrint==false" class="initPrint">
|
|
|
+ <view v-if="hasPrint==''" class="initPrint">
|
|
|
<view class="title">使用须知</view>
|
|
|
<view class="tips">使用前先连接wifi打印机</view>
|
|
|
<uni-easyinput class="input" confirm-type="done" v-model="printInfo.ip" placeholder="请输入打印机ip地址" @confirm="connectPrint"></uni-easyinput>
|
|
|
</view>
|
|
|
- <view v-else class="printInfo">
|
|
|
- <view>当前连接打印机</view>
|
|
|
+ <view v-else class="initPrint">
|
|
|
+ <view class="title" style="font-size: 20rpx;margin-bottom: 10rpx;">已经连接打印机</view>
|
|
|
+ <view style="font-size: 16rpx;margin-bottom: 10rpx;color: chocolate;">当前连接打印机IP</view>
|
|
|
<uni-easyinput disabled v-model="printInfo.ip" placeholder="请输入打印机ip地址"></uni-easyinput>
|
|
|
<button @click="resetPrint">断开连接</button>
|
|
|
</view>
|
|
@@ -21,15 +22,17 @@
|
|
|
|
|
|
<script setup>
|
|
|
import { onMounted, ref } from 'vue'
|
|
|
+import { setIp } from '@/static/js/api.js'
|
|
|
|
|
|
const plug= uni.requireNativePlugin('Html5app-Gprinter');
|
|
|
-const initPrint = ref(false)
|
|
|
+const hasPrint = ref('')
|
|
|
const printInfo = ref({
|
|
|
ip:'',
|
|
|
port:'9100'
|
|
|
})
|
|
|
onMounted(() => {
|
|
|
-
|
|
|
+ hasPrint.value = uni.getStorageSync('hasPrinter')
|
|
|
+ printInfo.value.ip = uni.getStorageSync('printerIp')
|
|
|
})
|
|
|
|
|
|
const emit = defineEmits(['emitClose'])
|
|
@@ -49,6 +52,18 @@ const connectPrint = ()=>{
|
|
|
// _this.tip=JSON.stringify(ret);
|
|
|
// console.log(_this.tip);
|
|
|
// 关闭配置页操作
|
|
|
+ // 保持ip和端口
|
|
|
+ const param = {userId:uni.getStorageSync('userId')+'',ip:printInfo.value.ip,port:printInfo.value.port}
|
|
|
+ console.log('before setIp param',param)
|
|
|
+ const res2 = setIp({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify(param)
|
|
|
+ })
|
|
|
+ if (res2.code !== 200){
|
|
|
+ uni.$showMsg(res2.msg, 2000)
|
|
|
+ }
|
|
|
+ console.log('hasPrinter', uni.getStorageSync('hasPrinter'))
|
|
|
+ console.log('printerIp', uni.getStorageSync('printerIp'))
|
|
|
emit('emitClose')
|
|
|
} else{
|
|
|
uni.$showMsg('打印机连接失败,请重试!', 500)
|
|
@@ -64,8 +79,19 @@ const connectPrint = ()=>{
|
|
|
const resetPrint = ()=>{
|
|
|
plug.disconnect({},ret=>{
|
|
|
uni.$showMsg(ret.msg, 2000)
|
|
|
- initPrint.value = false
|
|
|
+ hasPrint.value = ''
|
|
|
+ printInfo.value.ip = ''
|
|
|
+ uni.setStorageSync('hasPrinter', '')
|
|
|
+ uni.setStorageSync('printerIp', '')
|
|
|
+ const param = {userId:uni.getStorageSync('userId')+'',ip:'',port:printInfo.value.port}
|
|
|
// console.log(_this.tip);
|
|
|
+ const res2 = setIp({
|
|
|
+ token: uni.getStorageSync('token'),
|
|
|
+ data: JSON.stringify(param)
|
|
|
+ })
|
|
|
+ if (res2.code !== 200){
|
|
|
+ uni.$showMsg(res2.msg, 2000)
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -89,6 +115,5 @@ const resetPrint = ()=>{
|
|
|
width: 300rpx;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
</style>
|