diff --git a/src/starCloud/log.js b/src/starCloud/log.js index 684e025..04f22ea 100644 --- a/src/starCloud/log.js +++ b/src/starCloud/log.js @@ -7,44 +7,44 @@ export default { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.debug.apply(log, arguments) + const logger = log.tag(arguments[0].name) + logger.info(arguments[0].message, arguments[0]) }, info() { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.info.apply(log, arguments) + const logger = log.tag(arguments[0].name) + logger.info(arguments[0].message, arguments[0]) }, warn() { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.warn.apply(log, arguments) + const logger = log.tag(arguments[0].name) + logger.warn(arguments[0].message, arguments[0]) }, error() { if (!log) return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - // eslint-disable-next-line prefer-spread,prefer-rest-params - log.error.apply(log, arguments) + const logger = log.tag(arguments[0].name) + logger.error(arguments[0].message, arguments[0]) }, setFilterMsg(msg) { - // 从基础库2.7.3开始支持 if (!log || !log.setFilterMsg) return if (typeof msg !== 'string') return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - log.setFilterMsg(msg) + const logger = log.tag(arguments[0].name) + logger.setFilterMsg(JSON.stringify(arguments[0])) }, addFilterMsg(msg) { - // 从基础库2.8.1开始支持 if (!log || !log.addFilterMsg) return if (typeof msg !== 'string') return const $starCloud = useStarCloudStore() if (!$starCloud.isReportLog) return - log.addFilterMsg(msg) + const logger = log.tag(arguments[0].name) + logger.addFilterMsg(JSON.stringify(arguments[0])) } } diff --git a/src/starCloud/starCloud.js b/src/starCloud/starCloud.js index 9f85a83..a941826 100644 --- a/src/starCloud/starCloud.js +++ b/src/starCloud/starCloud.js @@ -295,7 +295,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) @@ -318,8 +318,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, @@ -328,8 +328,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `开始开门` - ) - ) + ), + name: 'openDoor' + }) // 设置执行账号 const result = await this.login(accountInfo) @@ -337,8 +338,8 @@ export const useStarCloudStore = defineStore('starCloud', { return result } - log.info( - new Result( + log.info({ + ...new Result( result.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -347,16 +348,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, @@ -365,8 +367,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `连接设备: ${searchResult.message}` - ) - ) + ), + name: 'openDoor' + }) if (searchResult.code !== Result.Success.code) { return searchResult } @@ -379,8 +382,8 @@ export const useStarCloudStore = defineStore('starCloud', { return checkResult } - log.info( - new Result( + log.info({ + ...new Result( checkResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -389,8 +392,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `确认是否为锁用户: ${checkResult.message}` - ) - ) + ), + name: 'openDoor' + }) // 是否需要联网 let onlineToken = '' @@ -403,8 +407,8 @@ export const useStarCloudStore = defineStore('starCloud', { } } - log.info( - new Result( + log.info({ + ...new Result( checkResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -413,8 +417,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `判断是否需要联网token: ${this.lockInfo.lockSetting.appUnlockOnline}` - ) - ) + ), + name: 'openDoor' + }) // 开门方式 let openMode @@ -472,8 +477,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, @@ -482,8 +487,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `开始写入` - ) - ) + ), + name: 'openDoor' + }) const writeResult = await writeBLECharacteristicValue( this.lockInfo.deviceId, @@ -496,8 +502,8 @@ export const useStarCloudStore = defineStore('starCloud', { return writeResult } - log.info( - new Result( + log.info({ + ...new Result( writeResult.code, { lockName: this.lockInfo.bluetooth.bluetoothDeviceName, @@ -506,8 +512,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `写入完成:${writeResult.message}` - ) - ) + ), + name: 'openDoor' + }) return this.getWriteResult(this.openDoor, params) }, @@ -1570,8 +1577,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, @@ -1579,8 +1586,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) @@ -1596,8 +1604,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, @@ -1605,8 +1613,9 @@ export const useStarCloudStore = defineStore('starCloud', { time: new Date().getTime() }, `开门结果:${data.message}` - ) - ) + ), + name: 'openDoor' + }) resolve(data) } } @@ -1834,9 +1843,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({ @@ -1914,7 +1923,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) } @@ -1954,6 +1963,21 @@ export const useStarCloudStore = defineStore('starCloud', { } characteristicValueCallback(new Result(decrypted[6], { lock: this.lockInfo })) break + case cmdIds.resetDevice: + this.updateLockInfo({ + token: decrypted.slice(2, 6), + electricQuantity: decrypted[7], + electricQuantityStandby: decrypted[9] + }) + if (decrypted[6] === Result.Success.code) { + updateElectricQuantityRequest({ + lockId: this.lockInfo.lockId, + electricQuantity: decrypted[7], + electricQuantityStandby: decrypted[9] + }) + } + characteristicValueCallback(new Result(decrypted[6], { lock: this.lockInfo })) + break case cmdIds.resetDevice: this.updateLockInfo({ token: decrypted.slice(2, 6)