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(); const n_address = BleDevice.getAddress(); formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:138", "====<<<", name, n_address); if (BleDevice.getBondState() === bdevice.BOND_NONE && name == "T58") { if (address === BleDevice.getAddress()) { if (BleDevice.createBond()) { vlist2.push({ name, address: BleDevice.getAddress() }); BAdapter.cancelDiscovery(); uni.hideLoading(); } } else { if (name !== null && name !== on && n_address == BleDevice.getAddress()) { on = name || "未知设备"; vlist1.push({ name: on, address: BleDevice.getAddress() }); uni.hideLoading(); } } } else { if (name !== un && address == BleDevice.getAddress()) { un = name; vlist1.push({ name: un, address: BleDevice.getAddress() }); vlist2.push({ name: un, address: BleDevice.getAddress() }); uni.hideLoading(); if (address === BleDevice.getAddress()) { BAdapter.cancelDiscovery(); } } } if (name === "T58") { connect(n_address, (e) => { if (e) { uni.$emit("connect", { name: "T58", address: n_address }); BAdapter.cancelDiscovery(); } }); } } } }); 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); } const connect = (mac_address, callback) => { 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()) { bluetoothSocket.connect(); } setTimeout(() => { if (bluetoothSocket.isConnected()) { formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:216", "已连接=====", mac_address); callback(true); } else { formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:220", "未连接", mac_address); callback(false); } bluetoothSocket.close(); }, 300); }; 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); formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:249", "蓝牙", bluetoothSocket.isConnected()); 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$2 = { __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) return uni.showToast({ title: "蓝牙未连接到T58打印机, 请检查是否已配对T58打印机", icon: "exception" }); formatAppLog("log", "at pages/index/index.vue:79", "打印机地址=>", deviceId); print(deviceId, stringData, () => { uni.showToast({ title: "打印成功", duration: 2e3 }); uni.setStorageSync("deviceId", deviceId); }); }; const onmessage = (e) => { var _a, _b, _c, _d, _e, _f, _g, _h; formatAppLog("log", "at pages/index/index.vue:97", "收到消息", 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") { uni.$off("connect"); state.deviceData = []; searchDevices(""); uni.removeStorageSync("deviceId"); uni.$once("connect", (e2) => { uni.hideLoading(); if (e2.name != "T58" || !e2.address) return uni.showToast({ title: "未找到T58打印机" }); let obj = { type: "connect", data: { title: "打印机已连接", address: e2.address } }; formatAppLog("log", "at pages/index/index.vue:121", "连接成功", e2); uni.setStorageSync("deviceId", e2.address); 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$2, [["__file", "D:/里海数字乡村/cashier-paid/pages/index/index.vue"]]); const download = ({ url, onProgress, onSuccess, onFail }) => { const task = uni.downloadFile({ url, success(res) { if (res.statusCode === 200) { onSuccess && onSuccess(res.tempFilePath); } }, fail() { onFail && onFail(); } }); task.onProgressUpdate((res) => { onProgress && onProgress(res.progress); }); }; const install = (filePath, restart = false) => { plus.runtime.install(filePath, { force: true }, () => { formatAppLog("log", "at uni_modules/guyue-updater/updater.js:23", "install success..."); if (restart) { plus.runtime.restart(); } }, (e) => { formatAppLog("error", "at uni_modules/guyue-updater/updater.js:28", "install fail...", e); }); }; const _imports_0 = "/assets/bg1.741aa005.png"; const _imports_1 = "/assets/bg2.f448d13c.png"; const _imports_2 = "/assets/close.0b53e1ac.png"; const _sfc_main$1 = { data() { const data = { updateParams: {}, progress: 0, downloading: false, downloadSucc: false, downloadError: false }; return data; }, computed: { content() { return (this.updateParams.content || "").replace(/[\r\n]/gim, "
"); }, downloadText() { if (this.downloadSucc) { return this.updateParams.downSucTip; } if (this.downloadError) { return this.updateParams.downErrorTip; } if (this.downloading) { return this.updateParams.downMsgTip; } return this.updateParams.updateBtnText; } }, onLoad(params) { const data = { title: "发现新版本", updateBtnText: "立即升级", downMsgTip: "下载中,请稍后", downSucTip: "下载完成,安装中", downErrorTip: "下载失败,请重试", quiet: false, force: false, ...JSON.parse(decodeURIComponent(params.data)) }; this.updateParams = data; }, onBackPress() { return this.updateParams.force; }, methods: { back() { if (!this.updateParams.force) { uni.navigateBack(); } }, // 开始更新 start() { if (!this.updateParams.downUrl) { return; } const isResource = [".apk", ".wgt"].some((ext) => this.updateParams.downUrl.toLocaleLowerCase().includes(ext)); if (plus.os.name !== "Android" || !isResource) { plus.runtime.openURL(this.updateParams.downUrl); return; } this.downloading = true; const self = this; download({ url: self.updateParams.downUrl, onProgress(progress) { self.progress = progress; }, onSuccess(filePath) { self.downloadSucc = true; self.downloadError = false; install(filePath, true); }, onFail() { self.downloading = false; self.downloadSucc = false; self.downloadError = true; } }); }, handleButton() { if (!this.downloading) { return this.start(); } if (this.downloadError) { this.progress = 0; this.downloading = false; this.downloadSucc = false; this.downloadError = true; return this.start(); } } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return vue.openBlock(), vue.createElementBlock("view", { class: "container" }, [ vue.createElementVNode("view", { class: "main", onClick: _cache[1] || (_cache[1] = vue.withModifiers(() => { }, ["stop"])) }, [ vue.createElementVNode("view", { class: "header" }, [ vue.createElementVNode("image", { src: _imports_0, class: "bg1" }), vue.createElementVNode("image", { src: _imports_1, class: "bg2" }), vue.createElementVNode( "view", { class: "version-title" }, vue.toDisplayString(_ctx.updateParams.title), 1 /* TEXT */ ), _ctx.updateParams.versionName ? (vue.openBlock(), vue.createElementBlock( "view", { key: 0, class: "version-name" }, "V" + vue.toDisplayString(_ctx.updateParams.versionName), 1 /* TEXT */ )) : vue.createCommentVNode("v-if", true) ]), vue.createElementVNode("view", { class: "title" }, "更新内容:"), vue.createElementVNode("view", { class: "content" }, [ vue.createElementVNode("rich-text", { nodes: $options.content }, null, 8, ["nodes"]) ]), _ctx.downloading ? (vue.openBlock(), vue.createElementBlock("view", { key: 0, class: "progress" }, [ vue.createElementVNode("view", { class: "slider" }, [ vue.createElementVNode( "view", { class: "active-slider", style: vue.normalizeStyle({ width: `${_ctx.progress}%` }) }, [ vue.createElementVNode("view", { class: "bar" }), vue.createElementVNode("view", { class: "dot" }, [ vue.createElementVNode( "view", { class: "text" }, vue.toDisplayString(_ctx.progress) + "%", 1 /* TEXT */ ), vue.createElementVNode("view", { class: "circle" }) ]) ], 4 /* STYLE */ ) ]) ])) : vue.createCommentVNode("v-if", true), vue.createElementVNode( "view", { class: vue.normalizeClass(["button", { "active": !_ctx.downloading || _ctx.downloadError }]), onClick: _cache[0] || (_cache[0] = (...args) => $options.handleButton && $options.handleButton(...args)) }, vue.toDisplayString($options.downloadText), 3 /* TEXT, CLASS */ ) ]), !_ctx.updateParams.force ? (vue.openBlock(), vue.createElementBlock("view", { key: 0, class: "bottom", onClick: _cache[2] || (_cache[2] = (...args) => $options.back && $options.back(...args)) }, [ vue.createElementVNode("view", { class: "line" }), vue.createElementVNode("image", { src: _imports_2, class: "close" }) ])) : vue.createCommentVNode("v-if", true) ]); } const Uni_modulesGuyueUpdaterPagesUpdater = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render], ["__file", "D:/里海数字乡村/cashier-paid/uni_modules/guyue-updater/pages/updater.vue"]]); __definePage("pages/index/index", PagesIndexIndex); __definePage("uni_modules/guyue-updater/pages/updater", Uni_modulesGuyueUpdaterPagesUpdater); class Updater { static update(options) { if (options.quiet) { download({ url: options.downUrl, onSuccess(filePath) { install(filePath, false); } }); } else if (options.downUrl) { uni.navigateTo({ url: `/uni_modules/guyue-updater/pages/updater?data=${encodeURIComponent(JSON.stringify(options))}`, animationType: "fade-in", animationDuration: 200 }); } } } function compareVersions(version1, version2) { const arr1 = version1.split(".").map(Number); const arr2 = version2.split(".").map(Number); for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) { const num1 = i < arr1.length ? arr1[i] : 0; const num2 = i < arr2.length ? arr2[i] : 0; if (num1 > num2) { return 1; } else if (num1 < num2) { return -1; } } return 0; } const inUpdate = () => { uni.request({ url: "http://192.168.1.22:8546/api/app_update", method: "GET", success: (res) => { formatAppLog("log", "at utils/update.js:26", "更新"); formatAppLog("log", "at utils/update.js:27", "======", res); let os = uni.getSystemInfoSync(); if (Object.keys(res.data.data).length > 0) { if (compareVersions(res.data.data.version || "1.0.0", os.appWgtVersion) == 1) { try { let info = res.data.data || {}; let version = { title: info.title || "发现新版本", content: info.content || "修复了部分BUG", versionName: info.version || "1.0.1", brand: os.brand, downUrl: info.dow_url || "", force: info.force == 1 ? true : false, // 是否强制更新 quiet: info.quiet == 1 ? true : false // 是否静默更新 }; Updater.update(version); } catch (e) { uni.showToast({ title: "更新失败" }); } } } }, fail: (err) => { formatAppLog("log", "at utils/update.js:57", "err", err); }, complete: (res) => { formatAppLog("log", "at utils/update.js:60", "结束", res); } }); }; 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:24", "调用失败"), complete: () => { } }); }; onLaunch(() => { formatAppLog("log", "at App.vue:29", "App Launch"); inUpdate(); }); onShow(() => { formatAppLog("log", "at App.vue:33", "App Show"); isHaveNetwork(); }); onHide(() => { formatAppLog("log", "at App.vue:37", "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);