if (typeof Promise !== "undefined" && !Promise.prototype.finally) { Promise.prototype.finally = function(callback) { const promise = this.constructor; return this.then( (value) => promise.resolve(callback()).then(() => value), (reason) => promise.resolve(callback()).then(() => { throw reason; }) ); }; } ; if (typeof uni !== "undefined" && uni && uni.requireGlobal) { const global = uni.requireGlobal(); ArrayBuffer = global.ArrayBuffer; Int8Array = global.Int8Array; Uint8Array = global.Uint8Array; Uint8ClampedArray = global.Uint8ClampedArray; Int16Array = global.Int16Array; Uint16Array = global.Uint16Array; Int32Array = global.Int32Array; Uint32Array = global.Uint32Array; Float32Array = global.Float32Array; Float64Array = global.Float64Array; BigInt64Array = global.BigInt64Array; BigUint64Array = global.BigUint64Array; } ; if (uni.restoreGlobal) { uni.restoreGlobal(Vue, weex, plus, setTimeout, clearTimeout, setInterval, clearInterval); } (function(vue) { "use strict"; const ON_SHOW = "onShow"; const ON_HIDE = "onHide"; const ON_LAUNCH = "onLaunch"; const ON_LOAD = "onLoad"; const ON_READY = "onReady"; function formatAppLog(type, filename, ...args) { if (uni.__log__) { uni.__log__(type, filename, ...args); } else { console[type].apply(console, [...args, filename]); } } const createHook = (lifecycle) => (hook, target = vue.getCurrentInstance()) => { !vue.isInSSRComponentSetup && vue.injectHook(lifecycle, hook, target); }; const onShow = /* @__PURE__ */ createHook(ON_SHOW); const onHide = /* @__PURE__ */ createHook(ON_HIDE); const onLaunch = /* @__PURE__ */ createHook(ON_LAUNCH); const onLoad = /* @__PURE__ */ createHook(ON_LOAD); const onReady = /* @__PURE__ */ createHook(ON_READY); var BleDevice; var device = null, BAdapter = null, BluetoothAdapter = null, uuid = null, UUID = null, bluetoothSocket = null; function getLocationManager(callback) { plus.android.requestPermissions( ["android.permission.ACCESS_FINE_LOCATION"], function(resultObj) { var result = 0; for (var i = 0; i < resultObj.granted.length; i++) { resultObj.granted[i]; result = 1; } for (var i = 0; i < resultObj.deniedPresent.length; i++) { resultObj.deniedPresent[i]; result = 0; } for (var i = 0; i < resultObj.deniedAlways.length; i++) { resultObj.deniedAlways[i]; result = -1; } if (result !== 1) { const Intent = plus.android.importClass("android.content.Intent"); const Settings = plus.android.importClass("android.provider.Settings"); const Uri = plus.android.importClass("android.net.Uri"); var mainActivity = plus.android.runtimeMainActivity(); const intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); var uri = Uri.fromParts("package", mainActivity.getPackageName(), null); intent.setData(uri); mainActivity.startActivity(intent); } else { var context = plus.android.importClass("android.content.Context"); var locationManager = plus.android.importClass("android.location.LocationManager"); var main = plus.android.runtimeMainActivity(); var mainSvr = main.getSystemService(context.LOCATION_SERVICE); var gps = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER); var agps = mainSvr.isProviderEnabled(locationManager.NETWORK_PROVIDER); if (gps || agps) { startBluetoothDiscovery(callback); } else { uni.showModal({ title: "提示", content: "请授权位置获取附近的蓝牙设备", showCancel: false, success() { if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) { var Intent = plus.android.importClass("android.content.Intent"); var Settings = plus.android.importClass("android.provider.Settings"); var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); main.startActivity(intent); } else { startBluetoothDiscovery(callback); formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:66", "定位已开启"); } } }); } } } ); } function startBluetoothDiscovery(callback) { plus.bluetooth.openBluetoothAdapter({ success: function(e) { plus.bluetooth.startBluetoothDevicesDiscovery({ success: function(e2) { callback(); }, fail: function(e2) { formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:88", "失败2"); } }); }, fail: function(e) { formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:92", "open failed: " + JSON.stringify(e)); } }); } function searchDevices(address = "", vlist1 = [], vlist2 = []) { var main = plus.android.runtimeMainActivity(); var IntentFilter = plus.android.importClass("android.content.IntentFilter"); var BluetoothAdapter2 = plus.android.importClass("android.bluetooth.BluetoothAdapter"); var BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice"); BAdapter = BluetoothAdapter2.getDefaultAdapter(); if (!BAdapter.isEnabled()) { uni.showToast({ title: "请开启蓝牙", duration: 2e3, icon: "error" }); return; } formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:113", "开始搜索设备"); var filter = new IntentFilter(); var bdevice = new BluetoothDevice(); var on = null; var un = null; let titleStr = "正在搜索请稍候"; if (address) { titleStr = "正在连接蓝牙"; } uni.showLoading({ title: titleStr }); BAdapter.startDiscovery(); var receiver = plus.android.implements("io.dcloud.android.content.BroadcastReceiver", { onReceive: function(context, intent) { plus.android.importClass(context); plus.android.importClass(intent); if (intent.getAction() === "android.bluetooth.adapter.action.DISCOVERY_FINISHED") { main.unregisterReceiver(receiver); uni.hideLoading(); } else { BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); const name = BleDevice.getName(); if (BleDevice.getBondState() === bdevice.BOND_NONE) { if (address === BleDevice.getAddress()) { if (BleDevice.createBond()) { vlist2.push({ name, address: BleDevice.getAddress() }); BAdapter.cancelDiscovery(); uni.hideLoading(); } } else { if (name !== null && name !== on) { on = name || "未知设备"; vlist1.push({ name: on, address: BleDevice.getAddress() }); uni.hideLoading(); if (on === "T58") { uni.$emit("connect", "T58"); } } } } else { if (name !== un) { un = name; vlist1.push({ name: un, address: BleDevice.getAddress() }); vlist2.push({ name: un, address: BleDevice.getAddress() }); formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:164", "=========", vlist1); uni.hideLoading(); if (address) { BAdapter.cancelDiscovery(); } if (un === "T58") { uni.$emit("connect", "T58"); } } } } } }); filter.addAction(bdevice.ACTION_FOUND); filter.addAction(BAdapter.ACTION_DISCOVERY_STARTED); filter.addAction(BAdapter.ACTION_DISCOVERY_FINISHED); filter.addAction(BAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothAdapter2.ACTION_ACL_DISCONNECTED); main.registerReceiver(receiver, filter); } function print(mac_address, data, callback) { if (!mac_address) { uni.showToast({ title: "请选择蓝牙设备", duration: 2e3, icon: "error" }); return; } plus.android.runtimeMainActivity(); BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); UUID = plus.android.importClass("java.util.UUID"); uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); BAdapter = BluetoothAdapter.getDefaultAdapter(); device = BAdapter.getRemoteDevice(mac_address); plus.android.importClass(device); bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); plus.android.importClass(bluetoothSocket); if (!bluetoothSocket.isConnected()) { uni.showToast({ title: "正在打印小票, 请耐心等待", duration: 2e3, icon: "none" }); bluetoothSocket.connect(); } if (bluetoothSocket.isConnected()) { const outputStream = bluetoothSocket.getOutputStream(); plus.android.importClass(outputStream); data.forEach((item) => { const bytes = plus.android.invoke(item, "getBytes", "gbk"); outputStream.write(bytes); }); setTimeout(function() { outputStream.flush(); device = null; bluetoothSocket.close(); callback(); }, 500); } else uni.showModal({ content: "连接打印机失败,是否重试", success: (res) => { if (res.confirm) { print(mac_address, data, callback); } } }); } const _export_sfc = (sfc, props) => { const target = sfc.__vccOpts || sfc; for (const [key, val] of props) { target[key] = val; } return target; }; const _sfc_main$1 = { __name: "index", setup(__props) { const vw = vue.ref(null); onLoad(() => { plus.navigator.setFullscreen(true); getLocationManager(() => { }); }); onReady(() => { { vue.nextTick(() => { setTimeout(() => { const pages = getCurrentPages(); vw.value = pages[pages.length - 1].$getAppWebview().children()[0]; }, 3e3); }); } }); const state = vue.reactive({ current: "esc", deviceData: [], data: [ { id: "12345", width: 100, height: 100, title1: "title_1", title2: "title_2", title3: "title_3" } ] // deviceId: '86:67:7A:2A:0B:08' }); const onPrintClick = (str) => { const stringData = []; if (str) stringData.push(str); else return uni.showToast({ title: "不可打印空内容", icon: "exception" }); formatAppLog("log", "at pages/index/index.vue:63", "打印内容", stringData); let deviceId = uni.getStorageSync("deviceId"); if (!deviceId) { let obj = state.deviceData.find((item) => item.name == "T58"); if (!obj) return uni.showToast({ title: "蓝牙未连接到T58打印机, 请检查是否已配对T58打印机", icon: "exception" }); else { deviceId = obj.address; } } formatAppLog("log", "at pages/index/index.vue:75", "打印机地址=>", deviceId); print(deviceId, stringData, () => { uni.showToast({ title: "打印成功", duration: 2e3 }); uni.setStorageSync("deviceId", deviceId); }); }; let t = 1; const onmessage = (e) => { var _a, _b, _c, _d, _e, _f, _g, _h; formatAppLog("log", "at pages/index/index.vue:93", "收到消息", e); if (((_b = (_a = e.detail) == null ? void 0 : _a.data[0]) == null ? void 0 : _b.type) == "print") { if ((_d = (_c = e.detail) == null ? void 0 : _c.data[0]) == null ? void 0 : _d.content) { onPrintClick((_f = (_e = e.detail) == null ? void 0 : _e.data[0]) == null ? void 0 : _f.content); } } else if (((_h = (_g = e.detail) == null ? void 0 : _g.data[0]) == null ? void 0 : _h.type) == "connect") { searchDevices("", state.deviceData); uni.$off("connect"); uni.$once("connect", (e2) => { uni.hideLoading(); let obj = { type: "connect", data: "打印机已连接" }; formatAppLog("log", "at pages/index/index.vue:108", "连接成功", t++); vw.value.evalJS(`receiveData('${JSON.stringify(obj)}')`); }); } }; return (_ctx, _cache) => { return vue.openBlock(), vue.createElementBlock( "web-view", { src: "http://192.168.1.55:5178/", onMessage: onmessage }, null, 32 /* NEED_HYDRATION */ ); }; } }; const PagesIndexIndex = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__file", "D:/里海数字乡村/cashier-paid/pages/index/index.vue"]]); __definePage("pages/index/index", PagesIndexIndex); const _sfc_main = { __name: "App", setup(__props) { const isHaveNetwork = () => { uni.getNetworkType({ success: (res) => { if (res.networkType == "none") { uni.showModal({ title: "网络不给力~", content: "是否重新连接", showCancel: true, confirmText: "是", cancelText: "不了", success: (res2) => { if (res2.confirm) { setTimeout(() => { isHaveNetwork(); }, 200); } } }); } }, fail: (err) => formatAppLog("error", "at App.vue:23", "调用失败"), complete: () => { } }); }; onLaunch(() => { formatAppLog("log", "at App.vue:28", "App Launch"); }); onShow(() => { formatAppLog("log", "at App.vue:31", "App Show"); isHaveNetwork(); }); onHide(() => { formatAppLog("log", "at App.vue:35", "App Hide"); }); return () => { }; } }; const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "D:/里海数字乡村/cashier-paid/App.vue"]]); function createApp() { const app = vue.createVueApp(App); return { app }; } const { app: __app__, Vuex: __Vuex__, Pinia: __Pinia__ } = createApp(); uni.Vuex = __Vuex__; uni.Pinia = __Pinia__; __app__.provide("__globalStyles", __uniConfig.styles); __app__._component.mpType = "app"; __app__._component.render = () => { }; __app__.mount("#app"); })(Vue);