2 lines
7.4 KiB
JavaScript
Raw Normal View History

2024-12-03 14:14:39 +08:00
"use strict";var e=Object.defineProperty,t=(t,s,a)=>(((t,s,a)=>{s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[s]=a})(t,"symbol"!=typeof s?s+"":s,a),a);const s=require("../common/vendor.js"),a=class e{constructor(t,s,a){const o=e.resultsMap.get(t);o?(this.code=t,this.message=a||o.message,this.data=s||o.data):(this.code=t,this.message=a||"",this.data=s||{})}static get Success(){return new e(e.codes.Success)}static get Fail(){return new e(e.codes.Fail)}static get NotMoreData(){return new e(e.codes.NotMoreData)}static get NotAvailableBluetooth(){return new e(e.codes.NotAvailableBluetooth)}static get NotAvailableBluetoothPermission(){return new e(e.codes.NotAvailableBluetoothPermission)}static get NotAvailableWeChatNearbyDevicesPermission(){return new e(e.codes.NotAvailableWeChatNearbyDevicesPermission)}static get NotAvailableWeChatLocationPermission(){return new e(e.codes.NotAvailableWeChatLocationPermission)}static get NotAvailableWeChatNearbyDevicesEmpty(){return new e(e.codes.NotAvailableWeChatNearbyDevicesEmpty)}static get NotAvailableWeChatBluetoothPermission(){return new e(e.codes.NotAvailableWeChatBluetoothPermission)}static get DeviceHasBeenReset(){return new e(e.codes.DeviceHasBeenReset)}static get NotRegisteredLock(){return new e(e.codes.NotRegisteredLock)}static get NotTokenLock(){return new e(e.codes.NotTokenLock)}static get NotMoreKeyLock(){return new e(e.codes.NotMoreKeyLock)}static get ReadyHasKeyLock(){return new e(e.codes.ReadyHasKeyLock)}static get ReadyHasPassword(){return new e(e.codes.ReadyHasPassword)}};t(a,"codes",{Success:0,Fail:-1,NotMoreData:-10,NotAvailableBluetooth:-20,NotAvailableBluetoothPermission:-21,NotAvailableWeChatNearbyDevicesPermission:-22,NotAvailableWeChatLocationPermission:-23,NotAvailableWeChatNearbyDevicesEmpty:-24,NotAvailableWeChatBluetoothPermission:-25,DeviceHasBeenReset:-30,NotRegisteredLock:4,NotTokenLock:6,NotMoreKeyLock:12,ReadyHasKeyLock:15,ReadyHasPassword:251}),t(a,"resultsMap",new Map([[a.codes.Success,{message:"成功",data:{}}],[a.codes.Fail,{message:"失败",data:{}}],[a.codes.NotMoreData,{message:"没有更多数据",data:{}}],[a.codes.NotAvailableBluetooth,{message:"蓝牙尚未打开,请先打开蓝牙",data:{}}],[a.codes.NotAvailableBluetoothPermission,{message:"小程序蓝牙功能被禁用,请打开小程序蓝牙权限",data:{}}],[a.codes.NotAvailableWeChatNearbyDevicesPermission,{message:"蓝牙功能需要附近设备权限,请前往设置开启微信的附近设备权限后再试",data:{}}],[a.codes.NotAvailableWeChatLocationPermission,{message:"蓝牙功能需要定位权限,请前往设置开启微信的定位权限后再试",data:{}}],[a.codes.NotAvailableWeChatNearbyDevicesEmpty,{message:"蓝牙功能需要定位服务,请前往设置开启定位服务后再试",data:{}}],[a.codes.NotAvailableWeChatBluetoothPermission,{message:"微信的蓝牙权限被禁用,请前往设置开启微信的蓝牙权限后再试",data:{}}],[a.codes.DeviceHasBeenReset,{message:"设备已被重置",data:{}}],[a.codes.NotRegisteredLock,{message:"用户在锁端未注册",data:{}}],[a.codes.NotTokenLock,{message:"用户在锁端token失效",data:{}}],[a.codes.NotMoreKeyLock,{message:"锁端钥匙数量已达上限",data:{}}],[a.codes.ReadyHasKeyLock,{message:"用户已是锁端用户",data:{}}],[a.codes.ReadyHasPassword,{message:"该密码已存在",data:{}}]]));let o=a;async function i(e,t){if(1e4===e.errCode){const e=await new Promise((e=>{s.index.openBluetoothAdapter({success(){e(o.Success)},async fail(t){e(await i(t))}})}));return e.code===o.Success.code?await t():e}return 10001===e.errCode?3===e.state?o.NotAvailableWeChatBluetoothPermission:o.NotAvailableBluetooth:3===e.errno?o.NotAvailableWeChatNearbyDevicesPermission:103===e.errno?o.NotAvailableBluetoothPermission:1509008===e.errno?o.NotAvailableWeChatLocationPermission:"openBluetoothAdapter:fail already opened"===e.errMsg?o.Success:o.Fail}function c(){return new Promise((e=>{s.index.startBluetoothDevicesDiscovery({success(){e(o.Success)},async fail(t){e(await i(t,c))}})}))}function r(