feat: 1. 添加获取锁支持项方法 2. 获取离线密码入参添加 lockId

This commit is contained in:
范鹏 2024-12-09 13:48:06 +08:00
parent d1914a3eff
commit cc84733f9a
3 changed files with 45 additions and 5 deletions

View File

@ -1,4 +1,4 @@
const { init, Result, searchDevice, bindDevice, register, openDoor, deleteLock, stopSearchDevice, selectLock } = requirePlugin('starCloud')
const { init, Result, searchDevice, bindDevice, register, openDoor, deleteLock, stopSearchDevice, selectLock, getLockSupportFeatures, getOfflinePassword } = requirePlugin('starCloud')
Page({
data: {
list: [],
@ -7,9 +7,9 @@ Page({
},
async onLoad () {
init({
clientId: 'wWdVGYOHGD2Xj3TIl8v7DfeIgnnCZ6K8',
clientSecret: '8TmY144P9uf0A1FDykeebEwzCJh3o0qh',
env: 'XHJ',
clientId: 'Tmj4XoB9dkXjD7t7OHKHl564rJdmvPm9',
clientSecret: 'g1VvSbN0Ya3IqPkA8j9Xn54PE1L8zGiy',
env: 'SKY',
isReportLog: true
})
const result = await register()
@ -19,9 +19,11 @@ Page({
})
}
},
// 搜索设备
searchDevice() {
searchDevice(this.searchDeviceCallback)
},
// 搜索设备回调
searchDeviceCallback(result) {
if(result.code === Result.Success.code) {
this.setData({
@ -29,6 +31,7 @@ Page({
})
}
},
// 绑定设备
bindDevice(e) {
const { device } = e.currentTarget.dataset
wx.showModal({
@ -54,6 +57,7 @@ Page({
}
})
},
// 开门
async openDoor () {
await selectLock({
accountInfo: this.data.accountInfo,
@ -72,6 +76,7 @@ Page({
})
}
},
// 删除锁
async deleteLock () {
await selectLock({
accountInfo: this.data.accountInfo,
@ -90,5 +95,30 @@ Page({
icon: 'none',
})
}
}
},
// 获取锁支持项
async getLockSupportFeatures() {
const result = await getLockSupportFeatures({
accountInfo: this.data.accountInfo,
lockId: this.data.lock.lockId
})
console.log('锁支持项',result)
},
// 获取锁离线密码
async getOfflinePassword() {
const result = await getOfflinePassword({
accountInfo: this.data.accountInfo,
password: {
lockId: this.data.lock.lockId,
keyboardPwdName: `单次密码${new Date().getTime()}`,
keyboardPwdType: 1,
isCoerced: 2,
startDate: 0,
endDate: 0,
hoursStart: 0,
hoursEnd: 0,
}
})
console.log('锁离线密码',result)
},
})

View File

@ -5,4 +5,6 @@
</view>
<button wx:if="{{lock}}" bind:tap="openDoor">开门</button>
<button wx:if="{{lock}}" bind:tap="deleteLock">删除设备</button>
<button wx:if="{{lock}}" bind:tap="getLockSupportFeatures">获取锁支持项</button>
<button wx:if="{{lock}}" bind:tap="getOfflinePassword">获取锁离线密码</button>
</view>

View File

@ -133,5 +133,13 @@ module.exports = {
async getServerTime() {
const starCloud = getStarCloudStore()
return await starCloud.getServerTimestamp()
},
/**
* 获取锁支持的功能
* @returns Result
*/
async getLockSupportFeatures (params) {
const starCloud = getStarCloudStore()
return await starCloud.getLockSupportFeatures(params)
}
}