fix: 添加锁状态判断

This commit is contained in:
范鹏 2024-12-03 10:21:27 +08:00
parent ddb35d32f9
commit 758363cd10
3 changed files with 43 additions and 32 deletions

View File

@ -159,4 +159,10 @@ const data = await $starCloud.updateAdminPassword(params)
* @returns {Promise<Result>} * @returns {Promise<Result>}
*/ */
const data = await $starCloud.syncAllOpenRecord(params) const data = await $starCloud.syncAllOpenRecord(params)
/**
* 获取服务器时间
* @returns {Promise<Result>}
*/
const data = await $starCloud.getServerTimestamp()
``` ```

24
log.js
View File

@ -1,40 +1,50 @@
import { isReportLog } from '@/starCloud/starCloud' import { useStarCloudStore } from '@/starCloud/starCloud'
const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null
export default { export default {
debug() { debug() {
if (!log) return if (!log) return
if (!isReportLog) return const $starCloud = useStarCloudStore()
if (!$starCloud.isReportLog) return
// eslint-disable-next-line prefer-spread,prefer-rest-params
log.debug.apply(log, arguments) log.debug.apply(log, arguments)
}, },
info() { info() {
if (!log) return if (!log) return
if (!isReportLog) return const $starCloud = useStarCloudStore()
if (!$starCloud.isReportLog) return
// eslint-disable-next-line prefer-spread,prefer-rest-params
log.info.apply(log, arguments) log.info.apply(log, arguments)
}, },
warn() { warn() {
if (!log) return if (!log) return
if (!isReportLog) return const $starCloud = useStarCloudStore()
if (!$starCloud.isReportLog) return
// eslint-disable-next-line prefer-spread,prefer-rest-params
log.warn.apply(log, arguments) log.warn.apply(log, arguments)
}, },
error() { error() {
if (!log) return if (!log) return
if (!isReportLog) return const $starCloud = useStarCloudStore()
if (!$starCloud.isReportLog) return
// eslint-disable-next-line prefer-spread,prefer-rest-params
log.error.apply(log, arguments) log.error.apply(log, arguments)
}, },
setFilterMsg(msg) { setFilterMsg(msg) {
// 从基础库2.7.3开始支持 // 从基础库2.7.3开始支持
if (!log || !log.setFilterMsg) return if (!log || !log.setFilterMsg) return
if (typeof msg !== 'string') return if (typeof msg !== 'string') return
if (!isReportLog) return const $starCloud = useStarCloudStore()
if (!$starCloud.isReportLog) return
log.setFilterMsg(msg) log.setFilterMsg(msg)
}, },
addFilterMsg(msg) { addFilterMsg(msg) {
// 从基础库2.8.1开始支持 // 从基础库2.8.1开始支持
if (!log || !log.addFilterMsg) return if (!log || !log.addFilterMsg) return
if (typeof msg !== 'string') return if (typeof msg !== 'string') return
if (!isReportLog) return const $starCloud = useStarCloudStore()
if (!$starCloud.isReportLog) return
log.addFilterMsg(msg) log.addFilterMsg(msg)
} }
} }

View File

@ -140,9 +140,6 @@ import log from '@/starCloud/log'
* @property {String} userNos - 设备ID * @property {String} userNos - 设备ID
*/ */
// 是否上报日志
export const isReportLog = false
// 命令ID // 命令ID
const cmdIds = { const cmdIds = {
// 获取公钥 // 获取公钥
@ -210,7 +207,9 @@ export const useStarCloudStore = defineStore('starCloud', {
// 账户信息 // 账户信息
accountInfo: null, accountInfo: null,
// 消息序号 // 消息序号
messageCount: 1 messageCount: 1,
// 是否上报日志
isReportLog: false
} }
}, },
actions: { actions: {
@ -227,7 +226,7 @@ export const useStarCloudStore = defineStore('starCloud', {
const appInfo = uni.getAccountInfoSync() const appInfo = uni.getAccountInfoSync()
this.envVersion = appInfo.miniProgram.envVersion this.envVersion = appInfo.miniProgram.envVersion
isReportLog = params.isReportLog this.isReportLog = params.isReportLog
this.env = env || 'XHJ' this.env = env || 'XHJ'
this.clientId = clientId this.clientId = clientId
@ -1013,7 +1012,6 @@ export const useStarCloudStore = defineStore('starCloud', {
return this.getWriteResult(this.updateAdminPassword, params) return this.getWriteResult(this.updateAdminPassword, params)
}, },
/** /**
* 同步全部开门记录 * 同步全部开门记录
* @param params * @param params
@ -1035,17 +1033,14 @@ export const useStarCloudStore = defineStore('starCloud', {
accountInfo, accountInfo,
disconnect disconnect
}) })
} else {
if (disconnect) {
await this.disconnectDevice()
}
return new Result(code, data, message)
} }
} else { if (disconnect) {
await this.disconnectDevice()
}
return new Result(code, data, message) return new Result(code, data, message)
} }
return new Result(code, data, message)
}, },
/** /**
* 同步开门记录 * 同步开门记录
* @param params * @param params
@ -1150,6 +1145,15 @@ export const useStarCloudStore = defineStore('starCloud', {
return this.getWriteResult(this.syncOpenRecord, params) return this.getWriteResult(this.syncOpenRecord, params)
}, },
// 获取服务器时间
async getServerTimestamp() {
const { code, data, message } = await getServerDatetimeRequest({})
if (code === Result.Success.code) {
this.serverTimestamp = Math.ceil(data.date / 1000)
this.timeDifference = Math.ceil((data.date - new Date().getTime()) / 1000)
}
return new Result(code, data, message)
},
/** /**
* 清理用户 * 清理用户
@ -1444,15 +1448,6 @@ export const useStarCloudStore = defineStore('starCloud', {
}) })
return new Result(code, data, message) return new Result(code, data, message)
}, },
// 获取服务器时间
async getServerTimestamp() {
const { code, data, message } = await getServerDatetimeRequest({})
if (code === Result.Success.code) {
this.serverTimestamp = Math.ceil(data.date / 1000)
this.timeDifference = Math.ceil((data.date - new Date().getTime()) / 1000)
}
return new Result(code, data, message)
},
// 添加用户 // 添加用户
async addLockUser(params) { async addLockUser(params) {
const { params: data } = params const { params: data } = params
@ -1837,9 +1832,9 @@ export const useStarCloudStore = defineStore('starCloud', {
lockId: this.lockInfo.lockId lockId: this.lockInfo.lockId
}) })
return characteristicValueCallback(new Result(result.code)) return characteristicValueCallback(new Result(result.code))
} else {
characteristicValueCallback(new Result(decrypted[2]))
} }
characteristicValueCallback(new Result(decrypted[2]))
break break
case subCmdIds.resetLockPassword: case subCmdIds.resetLockPassword:
this.updateLockInfo({ this.updateLockInfo({
@ -1917,7 +1912,7 @@ export const useStarCloudStore = defineStore('starCloud', {
user: decrypted[8 + 17 * i] * 256 + decrypted[9 + 17 * i], user: decrypted[8 + 17 * i] * 256 + decrypted[9 + 17 * i],
date: arrayToTimestamp(decrypted.slice(10 + 17 * i, 14 + 17 * i)) * 1000, date: arrayToTimestamp(decrypted.slice(10 + 17 * i, 14 + 17 * i)) * 1000,
success: 1, success: 1,
password: password password
} }
records.push(record) records.push(record)
} }