This commit is contained in:
weipengfei 2024-06-27 18:38:44 +08:00
parent 306e546dd9
commit 5079b0796a
3 changed files with 39 additions and 20 deletions

View File

@ -8,6 +8,8 @@ var device = null,
UUID = null,
bluetoothSocket = null,
num = 0;
var isShow = false;
// 开始gps定位
function getLocationManager(callback) {
plus.android.requestPermissions(
@ -289,14 +291,22 @@ function print(mac_address, data, callback) {
bluetoothSocket.close(); //必须关闭蓝牙连接否则意外断开的话打印错误
callback();
}, 500)
} else uni.showModal({
} else {
if(isShow) return;
isShow = true;
uni.showModal({
content: '连接打印机失败,是否重试',
success: (res) => {
if (res.confirm) {
print(mac_address, data, callback)
}
isShow = false
},
fail:()=> {
isShow = false
}
})
}
}
// 关闭操作

View File

@ -12,8 +12,8 @@
const vw = ref(null); // web-view
// const src = ref("https://erp-cashier.lihaink.cn/#/login");
// const src = ref("http://192.168.1.55:5181/#/");
const src = ref("http://cashier-multi-store.lihaink.cn/#/");
const src = ref("http://192.168.1.55:5181/#/");
// const src = ref("http://cashier-multi-store.lihaink.cn/#/");
onLoad(() => {
@ -125,6 +125,7 @@
}
console.log('连接成功',e);
uni.setStorageSync('deviceId', e.address);
vw.value.evalJS(`receiveData('${JSON.stringify(obj)}')`);
})
}
@ -139,5 +140,4 @@
</script>
<style>
</style>

View File

@ -53,6 +53,7 @@ if (uni.restoreGlobal) {
const onReady = /* @__PURE__ */ createHook(ON_READY);
var BleDevice;
var device = null, BAdapter = null, BluetoothAdapter = null, uuid = null, UUID = null, bluetoothSocket = null;
var isShow = false;
function getLocationManager(callback) {
plus.android.requestPermissions(
["android.permission.ACCESS_FINE_LOCATION"],
@ -102,7 +103,7 @@ if (uni.restoreGlobal) {
main.startActivity(intent);
} else {
startBluetoothDiscovery(callback);
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:66", "定位已开启");
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:68", "定位已开启");
}
}
});
@ -119,12 +120,12 @@ if (uni.restoreGlobal) {
callback();
},
fail: function(e2) {
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:88", "失败2");
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:90", "失败2");
}
});
},
fail: function(e) {
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:92", "open failed: " + JSON.stringify(e));
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:94", "open failed: " + JSON.stringify(e));
}
});
}
@ -142,7 +143,7 @@ if (uni.restoreGlobal) {
});
return;
}
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:113", "开始搜索设备");
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:115", "开始搜索设备");
var filter = new IntentFilter();
var bdevice = new BluetoothDevice();
var on = null;
@ -166,7 +167,7 @@ if (uni.restoreGlobal) {
BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
const name = BleDevice.getName();
const n_address = BleDevice.getAddress();
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:138", "====<<<", name, n_address);
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:140", "====<<<", name, n_address);
if (BleDevice.getBondState() === bdevice.BOND_NONE && name == "T58") {
if (address === BleDevice.getAddress()) {
if (BleDevice.createBond()) {
@ -232,10 +233,10 @@ if (uni.restoreGlobal) {
}
setTimeout(() => {
if (bluetoothSocket.isConnected()) {
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:220", "已连接=====", mac_address);
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:222", "已连接=====", mac_address);
callback(true);
} else {
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:224", "未连接", mac_address);
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:226", "未连接", mac_address);
callback(false);
}
bluetoothSocket.close();
@ -259,7 +260,7 @@ if (uni.restoreGlobal) {
plus.android.importClass(device);
bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
plus.android.importClass(bluetoothSocket);
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:253", "蓝牙", bluetoothSocket.isConnected());
formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:255", "蓝牙", bluetoothSocket.isConnected());
if (!bluetoothSocket.isConnected()) {
uni.showToast({
title: "正在打印小票, 请耐心等待",
@ -281,16 +282,24 @@ if (uni.restoreGlobal) {
bluetoothSocket.close();
callback();
}, 500);
} else
} else {
if (isShow)
return;
isShow = true;
uni.showModal({
content: "连接打印机失败,是否重试",
success: (res) => {
if (res.confirm) {
print(mac_address, data, callback);
}
isShow = false;
},
fail: () => {
isShow = false;
}
});
}
}
const _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
@ -302,7 +311,7 @@ if (uni.restoreGlobal) {
__name: "index",
setup(__props) {
const vw = vue.ref(null);
const src = vue.ref("http://cashier-multi-store.lihaink.cn/#/");
const src = vue.ref("http://192.168.1.55:5181/#/");
onLoad(() => {
plus.navigator.setFullscreen(true);
getLocationManager(() => {