From 8d947a4f02065c3944efaf49ac8f2709371c4e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Thu, 5 Dec 2024 18:42:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log.js | 40 ++++++++++++++++++++----- starCloud.js | 83 +++++++++++++++++++++++++++++----------------------- 2 files changed, 79 insertions(+), 44 deletions(-) diff --git a/log.js b/log.js index ff8ab75..798ea41 100644 --- a/log.js +++ b/log.js @@ -1,40 +1,66 @@ -import { isReportLog } from '@/starCloud/starCloud' +import { useStarCloudStore } from '@/starCloud/starCloud' const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null +const logManager = wx.getRealtimeLogManager() export default { debug() { if (!log) return - if (!isReportLog) return + const $starCloud = useStarCloudStore() + if (!$starCloud.isReportLog) return + const logger = logManager.tag(arguments[0].name) + logger.info(arguments[0].message, arguments[0]) + // eslint-disable-next-line prefer-spread,prefer-rest-params log.debug.apply(log, arguments) }, info() { + console.log(11111, arguments) if (!log) return - if (!isReportLog) return + const $starCloud = useStarCloudStore() + console.log(111112, arguments) + if (!$starCloud.isReportLog) return + console.log(111113, arguments) + const logger = logManager.tag(arguments[0].name) + logger.info(arguments[0].message, arguments[0]) + // 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 + const logger = logManager.tag(arguments[0].name) + logger.warn(arguments[0].message, arguments[0]) + // 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 + const logger = logManager.tag(arguments[0].name) + logger.error(arguments[0].message, arguments[0]) + // 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 + const logger = logManager.tag(arguments[0].name) + logger.setFilterMsg(JSON.stringify(arguments[0])) 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 + const logger = logManager.tag(arguments[0].name) + logger.addFilterMsg(JSON.stringify(arguments[0])) log.addFilterMsg(msg) } } diff --git a/starCloud.js b/starCloud.js index 7a94545..f078762 100644 --- a/starCloud.js +++ b/starCloud.js @@ -296,7 +296,7 @@ export const useStarCloudStore = defineStore('starCloud', { lockList[accountInfo.uid] = [this.lockInfo] setStorage('starLockList', lockList) } - } else { + } else if (code === Result.Fail.code) { const lockList = getStorage('starLockList') if (lockList[accountInfo.uid]) { const index = lockList[accountInfo.uid].findIndex(item => item.lockId === lockId) @@ -319,8 +319,8 @@ export const useStarCloudStore = defineStore('starCloud', { async openDoor(params) { const { accountInfo, type } = params - log.info( - new Result( + log.info({ + ...new Result( Result.Success.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -329,8 +329,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `开始开门` - ) - ) + ), + name: 'openDoor' + }) // 设置执行账号 const result = await this.login(accountInfo) @@ -338,8 +339,8 @@ export const useStarCloudStore = defineStore('starCloud', { return result } - log.info( - new Result( + log.info({ + ...new Result( result.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -348,16 +349,17 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `登录星云账号: ${result.message}` - ) - ) + ), + name: 'openDoor' + }) // 确认设备连接正常 if (!params.connected) { const searchResult = await searchAndConnectDevice( this.lockInfo.bluetooth.bluetoothDeviceName ) - log.info( - new Result( + log.info({ + ...new Result( searchResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -366,8 +368,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `连接设备: ${searchResult.message}` - ) - ) + ), + name: 'openDoor' + }) if (searchResult.code !== Result.Success.code) { return searchResult } @@ -380,8 +383,8 @@ export const useStarCloudStore = defineStore('starCloud', { return checkResult } - log.info( - new Result( + log.info({ + ...new Result( checkResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -390,8 +393,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `确认是否为锁用户: ${checkResult.message}` - ) - ) + ), + name: 'openDoor' + }) // 是否需要联网 let onlineToken = '' @@ -404,8 +408,8 @@ export const useStarCloudStore = defineStore('starCloud', { } } - log.info( - new Result( + log.info({ + ...new Result( checkResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -414,8 +418,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `判断是否需要联网token: ${this.lockInfo.lockSetting.appUnlockOnline}` - ) - ) + ), + name: 'openDoor' + }) // 开门方式 let openMode @@ -473,8 +478,8 @@ export const useStarCloudStore = defineStore('starCloud', { const packageArray = createPackageEnd(headArray, cebArray) - log.info( - new Result( + log.info({ + ...new Result( Result.Success.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -483,8 +488,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `开始写入` - ) - ) + ), + name: 'openDoor' + }) const writeResult = await writeBLECharacteristicValue( this.lockInfo.deviceId, @@ -497,8 +503,8 @@ export const useStarCloudStore = defineStore('starCloud', { return writeResult } - log.info( - new Result( + log.info({ + ...new Result( writeResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -507,8 +513,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `写入完成:${writeResult.message}` - ) - ) + ), + name: 'openDoor' + }) return this.getWriteResult(this.openDoor, params) }, @@ -1573,8 +1580,8 @@ export const useStarCloudStore = defineStore('starCloud', { characteristicValueCallback = async data => { // code 6 token过期,重新获取 if (data.code === Result.NotTokenLock.code) { - log.info( - new Result( + log.info({ + ...new Result( data.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -1582,8 +1589,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `token过期:${data.message}` - ) - ) + ), + name: 'openDoor' + }) resolve(await request({ ...params, connected: true })) } else if (data.code === Result.NotRegisteredLock.code) { const checkResult = await this.checkLockUser(true) @@ -1599,8 +1607,8 @@ export const useStarCloudStore = defineStore('starCloud', { await this.disconnectDevice() } console.log('写入结果', data, request, params) - log.info( - new Result( + log.info({ + ...new Result( data.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -1608,8 +1616,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `开门结果:${data.message}` - ) - ) + ), + name: 'openDoor' + }) resolve(data) } } From 19fb63c8574a9fb75b198efe65cff2353ec8ce10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Thu, 5 Dec 2024 18:58:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log.js | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/log.js b/log.js index 798ea41..04f22ea 100644 --- a/log.js +++ b/log.js @@ -1,66 +1,50 @@ import { useStarCloudStore } from '@/starCloud/starCloud' const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null -const logManager = wx.getRealtimeLogManager() export default { debug() { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - const logger = logManager.tag(arguments[0].name) + const logger = log.tag(arguments[0].name) logger.info(arguments[0].message, arguments[0]) - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.debug.apply(log, arguments) }, info() { - console.log(11111, arguments) if (!log) return const $starCloud = useStarCloudStore() - console.log(111112, arguments) if (!$starCloud.isReportLog) return - console.log(111113, arguments) - const logger = logManager.tag(arguments[0].name) + const logger = log.tag(arguments[0].name) logger.info(arguments[0].message, arguments[0]) - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.info.apply(log, arguments) }, warn() { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - const logger = logManager.tag(arguments[0].name) + const logger = log.tag(arguments[0].name) logger.warn(arguments[0].message, arguments[0]) - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.warn.apply(log, arguments) }, error() { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - const logger = logManager.tag(arguments[0].name) + const logger = log.tag(arguments[0].name) logger.error(arguments[0].message, arguments[0]) - // 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 const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - const logger = logManager.tag(arguments[0].name) + const logger = log.tag(arguments[0].name) logger.setFilterMsg(JSON.stringify(arguments[0])) - log.setFilterMsg(msg) }, addFilterMsg(msg) { - // 从基础库2.8.1开始支持 if (!log || !log.addFilterMsg) return if (typeof msg !== 'string') return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - const logger = logManager.tag(arguments[0].name) + const logger = log.tag(arguments[0].name) logger.addFilterMsg(JSON.stringify(arguments[0])) - log.addFilterMsg(msg) } }