From ef5be48f4b33a7a90d57721f3392378a97fb0659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Thu, 31 Oct 2024 18:41:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=20=E9=94=81=E7=9B=B8=E5=85=B3=202.?= =?UTF-8?q?=E4=B8=80=E9=94=AE=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ basic.js | 31 +++++++++++++++++++++++++------ starCloud.js | 13 ++++++++++++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7dac3f5..7415b4a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,11 @@ if (code === Result.Success.code) { */ const { code, data, message } = await $starCloud.login(username, password) +/** + * 退出登录(未做请求,实际上不会失败) + */ +const { code, data, message } = await $starCloud.logout() + /** * 选择锁 * @property {Number} lockId - 锁Id diff --git a/basic.js b/basic.js index 95be775..e942dff 100644 --- a/basic.js +++ b/basic.js @@ -10,6 +10,7 @@ export class Result { NotAvailableWeChatNearbyDevicesPermission: -22, NotAvailableWeChatLocationPermission: -23, NotAvailableWeChatNearbyDevicesEmpty: -24, + NotAvailableWeChatBluetoothPermission: -25, DeviceHasBeenReset: -30, NotRegisteredLock: 4, @@ -24,20 +25,30 @@ export class Result { [Result.codes.NotMoreData, { message: '没有更多数据', data: {} }], - [Result.codes.NotAvailableBluetooth, { message: '蓝牙未开启', data: {} }], - [Result.codes.NotAvailableBluetoothPermission, { message: '小程序蓝牙权限被禁用', data: {} }], + [Result.codes.NotAvailableBluetooth, { message: '蓝牙尚未打开,请先打开蓝牙', data: {} }], + [ + Result.codes.NotAvailableBluetoothPermission, + { message: '小程序蓝牙功能被禁用,请打开小程序蓝牙权限', data: {} } + ], [ Result.codes.NotAvailableWeChatNearbyDevicesPermission, - { message: '微信附近的设备权限被禁用', data: {} } + { message: '蓝牙功能需要附近设备权限,请前往设置开启微信的附近设备权限后再试', data: {} } ], [ Result.codes.NotAvailableWeChatLocationPermission, - { message: '微信定位权限被禁用', data: {} } + { message: '蓝牙功能需要定位权限,请前往设置开启微信的定位权限后再试', data: {} } ], [ Result.codes.NotAvailableWeChatNearbyDevicesEmpty, { - message: '手机定位服务被关闭', + message: '蓝牙功能需要定位服务,请前往设置开启定位服务后再试', + data: {} + } + ], + [ + Result.codes.NotAvailableWeChatBluetoothPermission, + { + message: '微信的蓝牙权限被禁用,请前往设置开启微信的蓝牙权限后再试', data: {} } ], @@ -97,11 +108,16 @@ export class Result { return new Result(Result.codes.NotAvailableWeChatLocationPermission) } - // 微信附近的设备权限无法使用(针对小米空白通行证,鸿蒙系统隐私中的定位服务) + // 手机定位服务被关闭 static get NotAvailableWeChatNearbyDevicesEmpty() { return new Result(Result.codes.NotAvailableWeChatNearbyDevicesEmpty) } + // 微信的蓝牙权限被禁用 + static get NotAvailableWeChatBluetoothPermission() { + return new Result(Result.codes.NotAvailableWeChatBluetoothPermission) + } + // 设备已被重置 static get DeviceHasBeenReset() { return new Result(Result.codes.DeviceHasBeenReset) @@ -199,6 +215,9 @@ async function handleError(err, event) { return result } if (err.errCode === 10001) { + if (err.state === 3) { + return Result.NotAvailableWeChatBluetoothPermission + } return Result.NotAvailableBluetooth } if (err.errno === 3) { diff --git a/starCloud.js b/starCloud.js index 6bd215b..0f062d9 100644 --- a/starCloud.js +++ b/starCloud.js @@ -14,7 +14,7 @@ import { updateLockUserNoRequest, updatePasswordRequest } from '@/starCloud/api' -import { getStorage, setStorage } from '@/starCloud/storage' +import { getStorage, removeStorage, setStorage } from '@/starCloud/storage' import { closeBLEConnection, createBLEConnection, @@ -218,6 +218,17 @@ export const useStarCloudStore = defineStore('starCloud', { } return new Result(code, {}, message) }, + // 退出登录 + logout() { + this.loginStarCloud = false + this.userInfo = null + this.accountInfo = null + removeStorage('starCloudToken') + removeStorage('starCloudUser') + removeStorage('lockList') + + return Result.Success + }, // 选择锁 async selectLock(lockId) { const { code, data, message } = await getLockDetailRequest({