From 7e247648201b208cfb5a5901803f784b7dbda948 Mon Sep 17 00:00:00 2001 From: xuxueyang <xuxy@fengyuntec.com> Date: 星期三, 31 七月 2024 01:54:17 +0800 Subject: [PATCH] 1 --- pages/home/supplier-home.vue | 149 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 139 insertions(+), 10 deletions(-) diff --git a/pages/home/supplier-home.vue b/pages/home/supplier-home.vue index 5d17578..0693bff 100644 --- a/pages/home/supplier-home.vue +++ b/pages/home/supplier-home.vue @@ -14,7 +14,8 @@ </view> <view class="flex user-info" v-if="currentInfo&&(currentInfo.id)"> <!-- 头像 --> - <image class="user-icon" v-if="!currentInfo.picture" src='https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png' + <image class="user-icon" v-if="!currentInfo.picture" + src='https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png' mode="aspectFit"></image> <image class="user-icon" v-if="currentInfo.picture" :src="currentInfo.picture" mode="aspectFit"></image> @@ -163,12 +164,12 @@ </view> <view class="order-desc syst">售后理赔</view> </view> - <!-- <view class="nav row margin-tb" @click="goto('/sub_pages/supplier/order-records/order-records',true)"> + <!-- <view class="nav row margin-tb" @click="printDeliveryOrder"> <view class="img-c"> <image class="icon margin-bottom order-icon kkjl" src="/static/images/supplier/user/user-icon-kkjl.png" mode="scaleToFill" /> </view> - <view class="order-desc wbsp">扣款记录</view> + <view class="order-desc wbsp">测试蓝牙</view> </view> --> </view> </view> @@ -198,8 +199,8 @@ }, scrollable: false, - cacheUserId:'', - tj:{} + cacheUserId: '', + tj: {} }; }, @@ -211,12 +212,12 @@ const url = options.q ? decodeURIComponent(options.q) : ''; const urlcode = options.url && decodeURIComponent(options.url) || '' }, - onShow(){ + onShow() { this.getTj() }, created() { //公告 - this.$http.request('get', '/api/announcement/page', { + this.$http.request('get', '/api/pub/announcement/list', { params: { size: 5, status: 'A' @@ -258,9 +259,137 @@ }, methods: { + printDeliveryOrder(item) { + //蓝牙打印 + var that = this; + wx.getBluetoothAdapterState({ + success: (result) => { + console.log('b s', result) + console.log("蓝牙状态:\n" + result.errMsg) + if (result.adapterState.available) { + if (result.adapterState.discovering) { + that.blueSearchDeviceCheck() + } else { + that.blueSearchDevice() + } + } else { + //打开蓝牙 + wx.openBluetoothAdapter({ + success: function(res) { + console.log("蓝牙已打开") + that.blueSearchDevice() + + }, + fail: function(res) { + console.log('res', res) + that.$message.showToast('蓝牙未打开') + } + }) + + } + }, + fail: (res) => { + console.log("蓝牙状态",res) + that.$message.showToast('获取蓝牙状态失败') + + } + }) + }, + blueSearchDevice() { + var that = this; + + wx.startBluetoothDevicesDiscovery({ + success: (res) => { + //打印调试日志 + console.log("搜索设备返回" + JSON.stringify(res)) + that.blueSearchDeviceCheck() + + }, + fail: (res) => { + console.log('error search', res) + that.$message.showToast('打开蓝牙搜索设备失败') + + } + }) + + }, + blueSearchDeviceCheck() { + let that = this + wx.getBluetoothDevices({ + success: (res) => { + var printDevice = undefined + for (var device of res.devices) { + if (device.name.indexOf('GP-M') >= 0) { + printDevice = device + // RSSI: -57 + // advertisServiceUUIDs: Array(2) + // 0: "000018f0-0000-1000-8000-00805f9b34fb" + // 1: "e7810a71-73ae-499d-8c15-faa9aef0c3f2" + // length: 2 + // nv_length: (...) + // __proto__: Array(0) + // deviceId: "89:E2:AF:33:46:2B" + // name: "GP-M322-5565_BLE" + break + } else { + + } + } + if (!printDevice) { + that.$message.showToast('未找到可用打印机,请联系客服') + that.stopBluetoothDevicesDiscovery() + + } else { + wx.createBLEConnection({ + deviceId: printDevice.deviceId, + success: function(res) { + // https: //blog.csdn.net/weixin_51375107/article/details/116009436 + console.log('连接设备返回:' + res.errMsg); + that.$message.showToast('连接设备返回:' + res.errMsg) + // escpos怎么来 →点击查看智谱清言的回答https://chatglm.cn/share/FEXaC + + }, + fail: function(res) { + console.log('createBLEConnection fail',res) + that.$message.showToast('连接打印机失败') + }, + complete() { + that.stopBluetoothDevicesDiscovery() + + } + }) + } + // res.devices.forEach((device, i) => { + // console.log('device', + // device) + // // if (device.deviceId == that.data + // // .deviceId) { + // // console.log("物联网设备已找到") + // // that.$message.showToast( + // // '打印设备已找到') + // // return; + // // } + // }) + }, + fail: (res) => { + console.log('getBluetoothDevices', + res) + that.$message.showToast('获取蓝牙设备失败') + + } + }) + }, + stopBluetoothDevicesDiscovery() { + var that = this; + wx.stopBluetoothDevicesDiscovery({ + success: (res) => { + console.log("停止扫描设备") + }, + }) + }, getTj() { // /api/supplier/delivery - + if (this.currentInfo.id && this.currentInfo.id !== this.cacheUserId) { this.cacheUserId = this.currentInfo.id let that = this @@ -280,10 +409,10 @@ } }) // #endif - + }, 200) } - + }, async toFlowManage() { -- Gitblit v1.9.3