feat: 1. 锁相关 2.一键登录
This commit is contained in:
parent
64beacd035
commit
ef5be48f4b
@ -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
|
||||
|
||||
31
basic.js
31
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) {
|
||||
|
||||
13
starCloud.js
13
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({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user