提交 b1f3aaae 编写于 作者: Q qiang

feat(mp): getSystemInfo add deviceId

上级 94eeea65
import { isPlainObject, isArray, hasOwn } from '@vue/shared'
import { addSafeAreaInsets } from '@dcloudio/uni-mp-core'
import { addSafeAreaInsets, useDeviceId } from '@dcloudio/uni-mp-core'
import { getStorageSync } from './shims'
export { redirectTo, navigateTo } from '@dcloudio/uni-mp-core'
......@@ -28,6 +30,9 @@ function handleSystemInfo(
toRes: UniApp.GetSystemInfoResult
) {
addSafeAreaInsets(fromRes, toRes)
useDeviceId({
getStorageSync,
})(fromRes, toRes)
let platform = fromRes.platform ? fromRes.platform.toLowerCase() : 'devtools'
if (!~['android', 'ios'].indexOf(platform)) {
......
import { addSafeAreaInsets } from './addSafeAreaInsets'
import { useDeviceId } from './useDeviceId'
import { MPProtocol } from './types'
export const getSystemInfo: MPProtocol = {
returnValue: addSafeAreaInsets,
returnValue: (fromRes, toRes) => {
addSafeAreaInsets(fromRes, toRes)
useDeviceId()(fromRes, toRes)
},
}
export { addSafeAreaInsets } from './addSafeAreaInsets'
export { useDeviceId } from './useDeviceId'
export { getSystemInfo } from './getSystemInfo'
export { getSystemInfoSync } from './getSystemInfoSync'
export { redirectTo } from './redirectTo'
......
const UUID_KEY = '__DC_STAT_UUID'
let deviceId: string
interface Global {
getStorageSync: UniApp.Uni['getStorageSync']
}
export function useDeviceId(global: Global = __GLOBAL__ as Global) {
return function addDeviceId(_: any, toRes: UniApp.GetSystemInfoResult) {
deviceId = deviceId || global.getStorageSync(UUID_KEY)
if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7)
__GLOBAL__.setStorage({
key: UUID_KEY,
data: deviceId,
})
}
toRes.deviceId = deviceId
}
}
......@@ -50,6 +50,7 @@ export {
getSystemInfo,
getSystemInfoSync,
addSafeAreaInsets,
useDeviceId,
} from './api/protocols'
// types
export { MiniProgramAppOptions, MiniProgramAppInstance } from './runtime/app'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册