deviceInfo.js
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import store from '@/store'
const warnLocal = message => {
try {
const localWarn = uni.$logger?.local?.warn
if (typeof localWarn === 'function') {
localWarn.call(uni.$logger.local, message)
} else {
console.warn(message)
}
} catch (error) {
console.warn(message)
}
}
export const hasPrivacyConsent = () => Boolean(store.getters.hasPrivacyConsent)
export const getDeviceId = () => {
if (!hasPrivacyConsent()) return ''
try {
return uni.getDeviceInfo()?.deviceId || ''
} catch (error) {
warnLocal(`获取设备编码失败:${error?.message || error}`)
return ''
}
}
export const getSystemInfo = () => {
if (!hasPrivacyConsent()) return null
try {
return uni.getSystemInfoSync()
} catch (error) {
warnLocal(`获取系统信息失败:${error?.message || error}`)
return null
}
}
export const getOAID = () => {
if (!hasPrivacyConsent()) return Promise.resolve('')
return new Promise(resolve => {
try {
if (typeof plus === 'undefined' || typeof plus.device?.getOAID !== 'function') {
resolve(getDeviceId())
return
}
plus.device.getOAID({
success: e => {
resolve(hasPrivacyConsent() ? e?.oaid || '' : '')
},
fail: () => {
resolve(getDeviceId())
}
})
} catch (error) {
warnLocal(`获取OAID失败:${error?.message || error}`)
resolve(getDeviceId())
}
})
}