This commit is contained in:
parent
306e546dd9
commit
5079b0796a
|
@ -8,6 +8,8 @@ var device = null,
|
||||||
UUID = null,
|
UUID = null,
|
||||||
bluetoothSocket = null,
|
bluetoothSocket = null,
|
||||||
num = 0;
|
num = 0;
|
||||||
|
var isShow = false;
|
||||||
|
|
||||||
// 开始gps定位
|
// 开始gps定位
|
||||||
function getLocationManager(callback) {
|
function getLocationManager(callback) {
|
||||||
plus.android.requestPermissions(
|
plus.android.requestPermissions(
|
||||||
|
@ -289,14 +291,22 @@ function print(mac_address, data, callback) {
|
||||||
bluetoothSocket.close(); //必须关闭蓝牙连接否则意外断开的话打印错误
|
bluetoothSocket.close(); //必须关闭蓝牙连接否则意外断开的话打印错误
|
||||||
callback();
|
callback();
|
||||||
}, 500)
|
}, 500)
|
||||||
} else uni.showModal({
|
} else {
|
||||||
|
if(isShow) return;
|
||||||
|
isShow = true;
|
||||||
|
uni.showModal({
|
||||||
content: '连接打印机失败,是否重试',
|
content: '连接打印机失败,是否重试',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
print(mac_address, data, callback)
|
print(mac_address, data, callback)
|
||||||
}
|
}
|
||||||
|
isShow = false
|
||||||
|
},
|
||||||
|
fail:()=> {
|
||||||
|
isShow = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关闭操作
|
// 关闭操作
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
const vw = ref(null); // web-view
|
const vw = ref(null); // web-view
|
||||||
|
|
||||||
// const src = ref("https://erp-cashier.lihaink.cn/#/login");
|
// const src = ref("https://erp-cashier.lihaink.cn/#/login");
|
||||||
// const src = ref("http://192.168.1.55:5181/#/");
|
const src = ref("http://192.168.1.55:5181/#/");
|
||||||
const src = ref("http://cashier-multi-store.lihaink.cn/#/");
|
// const src = ref("http://cashier-multi-store.lihaink.cn/#/");
|
||||||
|
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
|
@ -125,6 +125,7 @@
|
||||||
}
|
}
|
||||||
console.log('连接成功',e);
|
console.log('连接成功',e);
|
||||||
uni.setStorageSync('deviceId', e.address);
|
uni.setStorageSync('deviceId', e.address);
|
||||||
|
|
||||||
vw.value.evalJS(`receiveData('${JSON.stringify(obj)}')`);
|
vw.value.evalJS(`receiveData('${JSON.stringify(obj)}')`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -139,5 +140,4 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
</style>
|
</style>
|
|
@ -53,6 +53,7 @@ if (uni.restoreGlobal) {
|
||||||
const onReady = /* @__PURE__ */ createHook(ON_READY);
|
const onReady = /* @__PURE__ */ createHook(ON_READY);
|
||||||
var BleDevice;
|
var BleDevice;
|
||||||
var device = null, BAdapter = null, BluetoothAdapter = null, uuid = null, UUID = null, bluetoothSocket = null;
|
var device = null, BAdapter = null, BluetoothAdapter = null, uuid = null, UUID = null, bluetoothSocket = null;
|
||||||
|
var isShow = false;
|
||||||
function getLocationManager(callback) {
|
function getLocationManager(callback) {
|
||||||
plus.android.requestPermissions(
|
plus.android.requestPermissions(
|
||||||
["android.permission.ACCESS_FINE_LOCATION"],
|
["android.permission.ACCESS_FINE_LOCATION"],
|
||||||
|
@ -102,7 +103,7 @@ if (uni.restoreGlobal) {
|
||||||
main.startActivity(intent);
|
main.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
startBluetoothDiscovery(callback);
|
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();
|
callback();
|
||||||
},
|
},
|
||||||
fail: function(e2) {
|
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) {
|
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;
|
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 filter = new IntentFilter();
|
||||||
var bdevice = new BluetoothDevice();
|
var bdevice = new BluetoothDevice();
|
||||||
var on = null;
|
var on = null;
|
||||||
|
@ -166,7 +167,7 @@ if (uni.restoreGlobal) {
|
||||||
BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
const name = BleDevice.getName();
|
const name = BleDevice.getName();
|
||||||
const n_address = BleDevice.getAddress();
|
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 (BleDevice.getBondState() === bdevice.BOND_NONE && name == "T58") {
|
||||||
if (address === BleDevice.getAddress()) {
|
if (address === BleDevice.getAddress()) {
|
||||||
if (BleDevice.createBond()) {
|
if (BleDevice.createBond()) {
|
||||||
|
@ -232,10 +233,10 @@ if (uni.restoreGlobal) {
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (bluetoothSocket.isConnected()) {
|
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);
|
callback(true);
|
||||||
} else {
|
} 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);
|
callback(false);
|
||||||
}
|
}
|
||||||
bluetoothSocket.close();
|
bluetoothSocket.close();
|
||||||
|
@ -259,7 +260,7 @@ if (uni.restoreGlobal) {
|
||||||
plus.android.importClass(device);
|
plus.android.importClass(device);
|
||||||
bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
|
bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid);
|
||||||
plus.android.importClass(bluetoothSocket);
|
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()) {
|
if (!bluetoothSocket.isConnected()) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "正在打印小票, 请耐心等待",
|
title: "正在打印小票, 请耐心等待",
|
||||||
|
@ -281,16 +282,24 @@ if (uni.restoreGlobal) {
|
||||||
bluetoothSocket.close();
|
bluetoothSocket.close();
|
||||||
callback();
|
callback();
|
||||||
}, 500);
|
}, 500);
|
||||||
} else
|
} else {
|
||||||
|
if (isShow)
|
||||||
|
return;
|
||||||
|
isShow = true;
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
content: "连接打印机失败,是否重试",
|
content: "连接打印机失败,是否重试",
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
print(mac_address, data, callback);
|
print(mac_address, data, callback);
|
||||||
}
|
}
|
||||||
|
isShow = false;
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
isShow = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const _export_sfc = (sfc, props) => {
|
const _export_sfc = (sfc, props) => {
|
||||||
const target = sfc.__vccOpts || sfc;
|
const target = sfc.__vccOpts || sfc;
|
||||||
for (const [key, val] of props) {
|
for (const [key, val] of props) {
|
||||||
|
@ -302,7 +311,7 @@ if (uni.restoreGlobal) {
|
||||||
__name: "index",
|
__name: "index",
|
||||||
setup(__props) {
|
setup(__props) {
|
||||||
const vw = vue.ref(null);
|
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(() => {
|
onLoad(() => {
|
||||||
plus.navigator.setFullscreen(true);
|
plus.navigator.setFullscreen(true);
|
||||||
getLocationManager(() => {
|
getLocationManager(() => {
|
||||||
|
|
Loading…
Reference in New Issue