From 758363cd101aa5e0a544a224b5871dab4d2f2f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Tue, 3 Dec 2024 10:21:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E9=94=81=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ log.js | 24 +++++++++++++++++------- starCloud.js | 45 ++++++++++++++++++++------------------------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 82a110e..36e3797 100644 --- a/README.md +++ b/README.md @@ -159,4 +159,10 @@ const data = await $starCloud.updateAdminPassword(params) * @returns {Promise} */ const data = await $starCloud.syncAllOpenRecord(params) + +/** + * 获取服务器时间 + * @returns {Promise} + */ +const data = await $starCloud.getServerTimestamp() ``` diff --git a/log.js b/log.js index ff8ab75..684e025 100644 --- a/log.js +++ b/log.js @@ -1,40 +1,50 @@ -import { isReportLog } from '@/starCloud/starCloud' +import { useStarCloudStore } from '@/starCloud/starCloud' const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null export default { debug() { 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) }, info() { 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) }, warn() { 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) }, error() { 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) }, setFilterMsg(msg) { // 从基础库2.7.3开始支持 if (!log || !log.setFilterMsg) return if (typeof msg !== 'string') return - if (!isReportLog) return + const $starCloud = useStarCloudStore() + if (!$starCloud.isReportLog) return log.setFilterMsg(msg) }, addFilterMsg(msg) { // 从基础库2.8.1开始支持 if (!log || !log.addFilterMsg) return if (typeof msg !== 'string') return - if (!isReportLog) return + const $starCloud = useStarCloudStore() + if (!$starCloud.isReportLog) return log.addFilterMsg(msg) } } diff --git a/starCloud.js b/starCloud.js index 7a94545..6977b39 100644 --- a/starCloud.js +++ b/starCloud.js @@ -140,9 +140,6 @@ import log from '@/starCloud/log' * @property {String} userNos - 设备ID */ -// 是否上报日志 -export const isReportLog = false - // 命令ID const cmdIds = { // 获取公钥 @@ -210,7 +207,9 @@ export const useStarCloudStore = defineStore('starCloud', { // 账户信息 accountInfo: null, // 消息序号 - messageCount: 1 + messageCount: 1, + // 是否上报日志 + isReportLog: false } }, actions: { @@ -227,7 +226,7 @@ export const useStarCloudStore = defineStore('starCloud', { const appInfo = uni.getAccountInfoSync() this.envVersion = appInfo.miniProgram.envVersion - isReportLog = params.isReportLog + this.isReportLog = params.isReportLog this.env = env || 'XHJ' this.clientId = clientId @@ -1013,7 +1012,6 @@ export const useStarCloudStore = defineStore('starCloud', { return this.getWriteResult(this.updateAdminPassword, params) }, - /** * 同步全部开门记录 * @param params @@ -1035,17 +1033,14 @@ export const useStarCloudStore = defineStore('starCloud', { accountInfo, 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) }, - /** * 同步开门记录 * @param params @@ -1150,6 +1145,15 @@ export const useStarCloudStore = defineStore('starCloud', { 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) }, - // 获取服务器时间 - 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) { const { params: data } = params @@ -1837,9 +1832,9 @@ export const useStarCloudStore = defineStore('starCloud', { lockId: this.lockInfo.lockId }) return characteristicValueCallback(new Result(result.code)) - } else { - characteristicValueCallback(new Result(decrypted[2])) } + characteristicValueCallback(new Result(decrypted[2])) + break case subCmdIds.resetLockPassword: this.updateLockInfo({ @@ -1917,7 +1912,7 @@ export const useStarCloudStore = defineStore('starCloud', { user: decrypted[8 + 17 * i] * 256 + decrypted[9 + 17 * i], date: arrayToTimestamp(decrypted.slice(10 + 17 * i, 14 + 17 * i)) * 1000, success: 1, - password: password + password } records.push(record) }