fix: 星云SDK支持纯web
This commit is contained in:
commit
3914dcc3f3
@ -29,7 +29,7 @@ import {
|
||||
uploadRecordRequest
|
||||
} from './api'
|
||||
import { getStorage, setStorage } from './export'
|
||||
import log from '@/starCloud/uni/log'
|
||||
import log from './log'
|
||||
|
||||
/**
|
||||
* 同步开门记录
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { getStorageUni, removeStorageUni, setStorageUni } from './uni/storage'
|
||||
import { getStorageWeb, removeStorageWeb, setStorageWeb } from './web/storage'
|
||||
import requestUni from '@/starCloud/uni/request'
|
||||
import requestWeb from '@/starCloud/web/request'
|
||||
import requestUni from './uni/request'
|
||||
import requestWeb from './web/request'
|
||||
import starCloudInstance from './star-cloud'
|
||||
|
||||
export const setStorage = (key, value) => {
|
||||
|
||||
60
log.js
Normal file
60
log.js
Normal file
@ -0,0 +1,60 @@
|
||||
import starCloudInstance from './star-cloud'
|
||||
|
||||
export default {
|
||||
debug() {
|
||||
const log = starCloudInstance.platform === 1 ? wx.getRealtimeLogManager() : null
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
if (starCloudInstance.platform === 1) {
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.info(arguments[0].message, arguments[0])
|
||||
}
|
||||
},
|
||||
info() {
|
||||
const log = starCloudInstance.platform === 1 ? wx.getRealtimeLogManager() : null
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
if (starCloudInstance.platform === 1) {
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.info(arguments[0].message, arguments[0])
|
||||
}
|
||||
},
|
||||
warn() {
|
||||
const log = starCloudInstance.platform === 1 ? wx.getRealtimeLogManager() : null
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
if (starCloudInstance.platform === 1) {
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.warn(arguments[0].message, arguments[0])
|
||||
}
|
||||
},
|
||||
error() {
|
||||
const log = starCloudInstance.platform === 1 ? wx.getRealtimeLogManager() : null
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
if (starCloudInstance.platform === 1) {
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.error(arguments[0].message, arguments[0])
|
||||
}
|
||||
},
|
||||
setFilterMsg(msg) {
|
||||
const log = starCloudInstance.platform === 1 ? wx.getRealtimeLogManager() : null
|
||||
if (!log || !log.setFilterMsg) return
|
||||
if (typeof msg !== 'string') return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
if (starCloudInstance.platform === 1) {
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.setFilterMsg(JSON.stringify(arguments[0]))
|
||||
}
|
||||
},
|
||||
addFilterMsg(msg) {
|
||||
const log = starCloudInstance.platform === 1 ? wx.getRealtimeLogManager() : null
|
||||
if (!log || !log.addFilterMsg) return
|
||||
if (typeof msg !== 'string') return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
if (starCloudInstance.platform === 1) {
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.addFilterMsg(JSON.stringify(arguments[0]))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ import { searchAndConnectDevice, writeBLECharacteristicValue } from '../uni/basi
|
||||
import { createPackageEnd, md5Encrypt, timestampToArray } from '../format'
|
||||
import { getLockDetailRequest, getLockSettingDataRequest } from '../api'
|
||||
import { getStorage, setStorage } from '../export'
|
||||
import log from '../uni/log'
|
||||
import log from '../log'
|
||||
|
||||
/**
|
||||
* 选择锁
|
||||
|
||||
44
uni/log.js
44
uni/log.js
@ -1,44 +0,0 @@
|
||||
import starCloudInstance from '../star-cloud'
|
||||
|
||||
const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null
|
||||
|
||||
export default {
|
||||
debug() {
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.info(arguments[0].message, arguments[0])
|
||||
},
|
||||
info() {
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.info(arguments[0].message, arguments[0])
|
||||
},
|
||||
warn() {
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.warn(arguments[0].message, arguments[0])
|
||||
},
|
||||
error() {
|
||||
if (!log) return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.error(arguments[0].message, arguments[0])
|
||||
},
|
||||
setFilterMsg(msg) {
|
||||
if (!log || !log.setFilterMsg) return
|
||||
if (typeof msg !== 'string') return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.setFilterMsg(JSON.stringify(arguments[0]))
|
||||
},
|
||||
addFilterMsg(msg) {
|
||||
if (!log || !log.addFilterMsg) return
|
||||
if (typeof msg !== 'string') return
|
||||
if (!starCloudInstance.isReportLog) return
|
||||
const logger = log.tag(arguments[0].name)
|
||||
logger.addFilterMsg(JSON.stringify(arguments[0]))
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { getStorage, removeStorage } from '../export'
|
||||
import starCloudInstance from '@/starCloud/star-cloud'
|
||||
import { Result } from '@/constants/result'
|
||||
import { getStorage, removeStorage } from '../export.js'
|
||||
import starCloudInstance from '../star-cloud'
|
||||
import { Result } from '../constant'
|
||||
|
||||
/*
|
||||
* config
|
||||
@ -13,11 +13,10 @@ import { Result } from '@/constants/result'
|
||||
* */
|
||||
|
||||
const request = config => {
|
||||
const starCloud = starCloudInstance
|
||||
let timer
|
||||
let res = null // 在外部定义res,避免finally块报错
|
||||
return new Promise(async resolve => {
|
||||
const baseConfig = starCloud.getConfig()
|
||||
const baseConfig = starCloudInstance.getConfig()
|
||||
|
||||
const token = config?.token ? config.token : getStorage('starCloudToken')
|
||||
// 请求地址
|
||||
@ -35,7 +34,7 @@ const request = config => {
|
||||
const data = {
|
||||
...config.data,
|
||||
accessToken: token,
|
||||
clientId: starCloud.clientId
|
||||
clientId: starCloudInstance.clientId
|
||||
}
|
||||
const timestamp = new Date().getTime()
|
||||
|
||||
@ -64,10 +63,10 @@ const request = config => {
|
||||
if (errcode === 10003) {
|
||||
removeStorage('starCloudToken')
|
||||
removeStorage('starCloudUser')
|
||||
const { code } = await starCloud.login({
|
||||
username: starCloud.starCloudAccountInfo.username,
|
||||
password: starCloud.starCloudAccountInfo.password,
|
||||
uid: starCloud.starCloudAccountInfo.uid
|
||||
const { code } = await starCloudInstance.login({
|
||||
username: starCloudInstance.starCloudAccountInfo.username,
|
||||
password: starCloudInstance.starCloudAccountInfo.password,
|
||||
uid: starCloudInstance.starCloudAccountInfo.uid
|
||||
})
|
||||
if (code === Result.Success.code) {
|
||||
resolve(await request(config))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user