From 80f4ad315ac5c4c98bff167c39ed2ee9bada3f91 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期二, 15 七月 2025 11:25:22 +0800
Subject: [PATCH] Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev
---
pages/shouliaotongzhi/table_son.vue | 370 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 366 insertions(+), 4 deletions(-)
diff --git a/pages/shouliaotongzhi/table_son.vue b/pages/shouliaotongzhi/table_son.vue
index 9373453..d7d493c 100644
--- a/pages/shouliaotongzhi/table_son.vue
+++ b/pages/shouliaotongzhi/table_son.vue
@@ -51,13 +51,13 @@
</view>
<view class="buttons">
<button class="btn-b" size="mini" type="default" @tap="getList()">鏉$爜鐢熸垚</button>
- <button class="btn-c" size="mini" type="default" @tap="search">鎵撳嵃</button>
+ <button class="btn-c" size="mini" type="default" @tap="searchLabelPrinter()">鎼滅储鎵撳嵃鏈�</button>
</view>
</view>
<view style="width: 100%;height: 16rpx;background-color: #e5e5e5;"></view>
- <view class="list" v-for="(item,index) in listData" :key="index" @tap="toSon(item)">
+ <view class="list" v-for="(item,index) in listData" :key="index">
<uni-card :title="item.鐗╂枡浠g爜" :extra="'No. ' + Number(index+1)" style="margin: 10px;">
<view class="card-detail">
<view class="detail">
@@ -73,17 +73,62 @@
<text>鏉$爜缂栧彿锛�</text>{{item.鏉$爜缂栧彿}}
</view>
</view>
-
+ <view class="detail" style="text-align: right;" @tap.stop="labelPrint(item)"><text style="color: orange;">鐐瑰嚮鎵撳嵃鏉$爜</text></view>
</uni-card>
</view>
<view class="over" v-if="listData.length == 0">鏆傛棤鏁版嵁</view>
<view class="over" v-if="listData.length != 0">宸插埌搴�</view>
+
+ <!-- 鎵撳嵃鏈洪�夋嫨鍒楄〃 -->
+ <view v-if="maskShow" class="uni-mask" @tap="maskShow = false">
+ <scroll-view class="uni-scroll_box" scroll-y>
+ <view class="uni-list-box" v-for="(device, index) in discoveredDevices" :key="index" @tap="connectBT(device)">
+ <view class="uni-list_name">鍚嶇О锛歿{ device.name }}</view>
+ <view class="uni-list_item">{{ connectedDeviceId === device.address?'宸茶繛鎺�':'鏈繛鎺�' }}</view>
+ </view>
+ </scroll-view>
+ </view>
</view>
</template>
<script>
import { getUserInfo } from "@/utils/auth.js";
+ import bluetoothTool from '@/plugins/BluetoothTool.js'
+ import permission from '@/plugins/permission.js'
+ import {
+ InputImage
+ } from '@psdk/frame-imageb';
+ import {
+ ConnectedDevice,
+ Lifecycle,
+ Raw,
+ FakeConnectedDevice,
+ WriteOptions,
+ } from '@psdk/frame-father';
+ import {
+ CBar,
+ CBox,
+ CForm,
+ CImage,
+ CLine,
+ CCodeRotation,
+ CCodeType,
+ CPage,
+ CText,
+ CFont,
+ CBold,
+ CRotation,
+ CInverse,
+ CMag,
+ CQRCode,
+ CCorrectLevel,
+ CSN,
+ CStatus,
+ } from "@psdk/cpcl";
+ import {
+ EImage
+ } from "@psdk/esc";
export default {
data() {
return {
@@ -107,6 +152,11 @@
},
sWhere:'',
listData:[],
+ printItem:'',
+
+ maskShow:false,
+ discoveredDevices: [], // 鏌ヨ鍒扮殑璁惧
+ connectedDeviceId: ""
}
},
onLoad(e) {
@@ -114,6 +164,31 @@
this.linterid = e.linterid
this.HEntryID = e.hsubid
this.getData()
+
+ //#ifdef APP-PLUS
+ // 钃濈墮
+ bluetoothTool.init({
+ listenBTStatusCallback: (state) => {
+ if (state == 'STATE_ON') {
+ console.log(state);
+ }
+ },
+ discoveryDeviceCallback: this.onDevice,
+ discoveryFinishedCallback: function() {
+ console.log("鎼滅储瀹屾垚");
+ },
+ readDataCallback: function(dataByteArr) {
+ /* if(that.receiveDataArr.length >= 200) {
+ that.receiveDataArr = [];
+ }
+ that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr); */
+ console.log("璇诲彇瀹屾垚" + dataByteArr);
+ },
+ connExceptionCallback: function(e) {
+ console.log(e);
+ }
+ });
+ //#endif
},
methods: {
getData(){
@@ -123,6 +198,7 @@
success: (res) => {
if(res.data.count == 1){
var data = res.data.data
+ console.log(data)
this.baseInfo = {
HMainID:data[0].linterid,
HSubID:data[0].HEntryID,
@@ -132,6 +208,8 @@
HMaterName:data[0].鐗╂枡鍚嶇О,
HMaterModel:data[0].瑙勬牸鍨嬪彿,
HQty:data[0].鏁伴噺,
+ HSupID:data[0].HSupID,
+ SHdate:data[0].瀹℃牳鏃ユ湡,
}
}else{
uni.showToast({
@@ -183,6 +261,7 @@
success: (res) => {
if(res.data.count == 1){
this.listData = res.data.data
+ console.log(this.listData)
}else{
uni.showToast({
title:res.data.Message,
@@ -198,7 +277,235 @@
})
},
});
- }
+ },
+ async checkPermission() { // 鎺堟潈
+ try {
+ let checkResult = await permission.androidPermissionCheck("bluetooth");
+ console.log("妫�娴嬩俊鎭細", checkResult);
+ if (checkResult.code == 1) {
+ let result = checkResult.data;
+ if (result == 1) {
+ console.log("鎺堟潈鎴愬姛!");
+ }
+ if (result == 0) {
+ console.log("鎺堟潈宸叉嫆缁�!");
+ }
+ if (result == -1) {
+ console.log("鎮ㄥ凡姘镐箙鎷掔粷鏉冮檺锛岃鍦ㄥ簲鐢ㄨ缃腑鎵嬪姩鎵撳紑!");
+ }
+ }
+ } catch (err) {
+ console.log("鎺堟潈澶辫触锛�", err);
+ }
+ },
+ async searchLabelPrinter() {
+ // 鏌ユ壘鎵撳嵃鏈�
+ var that = this
+ // 浣跨敤openBluetoothAdapter 鎺ュ彛锛屽厤鍘讳富鍔ㄧ敵璇锋潈闄愮殑楹荤儲
+ uni.openBluetoothAdapter({
+ success: async (res) => {
+ await this.checkPermission();
+ console.log('start discovery devices');
+ this.discoveredDevices = [];
+ console.log(res)
+ bluetoothTool.discoveryNewDevice();
+ this.maskShow = true
+ },
+ fail: async (e) => {
+ console.error(e)
+ switch (e.code) {
+ case "10009":
+ this.showToast("姝よ澶囦笉鏀寔璁惧鎼滅储鍔熻兘!");
+ break;
+ default:
+ console.error(e);
+ }
+ }
+ })
+
+ },
+ onDevice(device) {
+ console.log("鐩戝惉瀵绘壘鍒版柊璁惧鐨勪簨浠�---------------")
+ console.log(device)
+ if (typeof device === 'undefined') return;
+ if (typeof device.name === 'undefined') return;
+ console.log(device.name);
+ if (device.name === '') return;
+ if (device.name === null) return;
+ if (device.name.toUpperCase().endsWith('_BLE') ||
+ device.name.toUpperCase().endsWith('-LE') ||
+ device.name.toUpperCase().endsWith('-BLE')) return;
+ const isDuplicate = this.discoveredDevices.find(item => item.address === device.address);
+ if (isDuplicate) return;
+ this.discoveredDevices.push(device);
+ },
+ connectBT(device) {
+ const vm = this;
+ uni.showLoading({
+ title: '杩炴帴涓�'
+ });
+ bluetoothTool.connDevice(device.address, (result) => {
+ console.log(result)
+ uni.hideLoading()
+ if (result) {
+ // // console.log(result);
+ bluetoothTool.cancelDiscovery();
+ // console.log(vm.$printer)
+ vm.$printer.init(new FakeConnectedDevice());
+ vm.connectedDeviceId = device.address;
+ uni.showToast({
+ icon: 'none',
+ title: '杩炴帴鎴愬姛'
+ })
+ this.maskShow = false
+ } else {
+ uni.showToast({
+ icon: 'none',
+ title: '杩炴帴澶辫触'
+ })
+ }
+ });
+ },
+ stopSearchBT() {
+ console.log("鍋滄鎼滃闄勮繎鐨勮摑鐗欏鍥磋澶�---------------")
+ bluetoothTool.cancelDiscovery();
+ },
+ closeBluetooth() {
+ console.log("鍋滄钃濈墮杩炴帴")
+ const vm = this;
+ if (vm.connectedDeviceId != '') {
+ bluetoothTool.closeBtSocket();
+ vm.connectedDeviceId = "";
+ }
+ },
+ labelPrint(item) {
+ // 鎵撳嵃
+ this.printItem = item
+ // 妫�鏌ヨ摑鐗欒繛鎺�
+ let btStatus = bluetoothTool.getBluetoothStatus()
+ if(btStatus != true) {
+ this.showToast("钃濈墮杩炴帴寮傚父!")
+ return
+ }
+
+ // 妫�鏌ユ槸鍚﹁繛鎺ヨ澶�
+ let pairedDevices = bluetoothTool.getPairedDevices()
+ if(pairedDevices.length < 1) {
+ this.showToast("鏃犺澶囪繛鎺�!")
+ return
+ }
+
+ // 妫�鏌ヨ〃鍗曢」鏄惁鏈夌┖鍊�
+ for (var key in this.hform) {
+ if (this.hform[key] == "") {
+ // todo 鎻愮ず琛ㄥ崟椤逛笉鑳戒负绌�
+ this.showToast("琛ㄥ崟涓嶈兘鏈夌┖鍊�!")
+ return
+ }
+ }
+ this.printWrite()
+ },
+ showToast(msg, status = "none") {
+ uni.showToast({
+ title: msg,
+ icon: status,
+ duration: 2000
+ });
+ },
+ ///杞垚瀹夊崜鏈夌鍙风殑
+ uint8ArrayToSignedArray(uint8Array) {
+ let signedArray = new Array(uint8Array.length);
+ for (let i = 0; i < uint8Array.length; i++) {
+ if (uint8Array[i] >= 128) {
+ signedArray[i] = uint8Array[i] - 256;
+ } else {
+ signedArray[i] = uint8Array[i];
+ }
+ }
+ return signedArray;
+ },
+ async printWrite(type = "cpcl") {
+ const vm = this;
+ console.log("寮�濮嬫墦鍗�------------------")
+ switch (type) {
+ case "cpcl":
+ await vm.writeCpclModel();
+ break;
+ }
+ },
+ async writeCpclModel() {
+ const vm = this;
+ try {
+ const cpcl = await vm.$printer.cpcl().clear()
+ .page(new CPage({
+ width: 608,
+ height: 300
+ }))
+ .qrcode(new CQRCode({
+ x: 450,
+ y: 30,
+ width: 5,
+ content: vm.printItem.鏉$爜缂栧彿,
+ codeRotation: CCodeRotation.ROTATION_0,
+ level: CCorrectLevel.L
+ }))
+ .text(new CText({
+ x: 24,
+ y: 40,
+ content: vm.baseInfo.SHdate?"瀹℃牳鏃ユ湡: " + vm.baseInfo.SHdate : "瀹℃牳鏃ユ湡: ",
+ font: CFont.TSS24
+ }))
+ .text(new CText({
+ x: 24,
+ y: 80,
+ content: "鐗╂枡缂栫爜: " + vm.printItem.鐗╂枡浠g爜,
+ font: CFont.TSS24
+ }))
+ .text(new CText({
+ x: 24,
+ y: 120,
+ content: "鐗╂枡鍚嶇О: " + vm.printItem.鐗╂枡鍚嶇О,
+ font: CFont.TSS24
+ }))
+ .text(new CText({
+ x: 24,
+ y: 160,
+ content: "瑙勬牸鍨嬪彿: " + vm.printItem.瑙勬牸鍨嬪彿,
+ font: CFont.TSS24
+ }))
+ .text(new CText({
+ x: 24,
+ y: 200,
+ content: "鐗╂枡鏁伴噺: " + vm.baseInfo.HQty,
+ font: CFont.TSS24
+ }))
+ .text(new CText({
+ x: 24,
+ y: 240,
+ content: "鏉$爜鏁伴噺: " + vm.printItem.鏁伴噺,
+ font: CFont.TSS24
+ }))
+
+ .form(new CForm()) //鏍囩绾搁渶瑕佸姞瀹氫綅鎸囦护
+ .print();
+ console.log(cpcl.command().string());
+ var binary = cpcl.command().binary();
+ await this.sendMessage(Array.from(this.uint8ArrayToSignedArray(binary)));
+ } catch (e) {
+ console.error(e);
+ uni.showToast({
+ title: '澶辫触',
+ });
+ }
+ },
+ async sendMessage(cmd) {
+ console.log(cmd);
+ const result = bluetoothTool.sendByteData(cmd);
+ uni.showToast({
+ icon: 'none',
+ title: result ? '鍙戦�佹垚鍔燂紒' : '鍙戦�佸け璐�...'
+ })
+ },
}
}
</script>
@@ -295,5 +602,60 @@
}
}
}
+
+ .uni-mask {
+ position: fixed;
+ top: 0;
+ left: 0;
+ bottom: 0;
+ z-index: 9999;
+ display: flex;
+ align-items: center;
+ width: 100%;
+ background: rgba(0, 0, 0, 0.6);
+ padding: 0 30rpx;
+ box-sizing: border-box;
+ }
+
+ .uni-scroll_box {
+ height: 60%;
+ background: #fff;
+ border-radius: 20rpx;
+ }
+ .uni-list-box {
+ margin: 0 20rpx;
+ padding: 15rpx 0;
+ border-bottom: 1px #f5f5f5 solid;
+ box-sizing: border-box;
+ }
+ .uni-list:last-child {
+ border: none;
+ }
+ .uni-list_name {
+ font-size: 30rpx;
+ color: #333;
+ }
+ .uni-list_item {
+ font-size: 24rpx;
+ color: #555;
+ line-height: 1.5;
+ }
+
+ .operation-zone {
+ display: flex;
+ justify-content: space-around;
+ margin-top: 10rpx;
+
+ .op1 {
+ border: 1px solid #41a863;
+ color: #41a863;
+ }
+
+ .op4 {
+ border: 1px solid #da0000;
+ color: #da0000;
+ }
+
+ }
</style>
--
Gitblit v1.9.1