提交 ab38f1db 编写于 作者: Q qiang

feat: uni.getSystemInfo 增加属性 uuid

上级 e16be182
......@@ -37,7 +37,8 @@
"base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0",
"pako": "^1.0.11",
"safe-area-insets": "^1.4.1"
"safe-area-insets": "^1.4.1",
"uuid": "3.4.0"
},
"private": true,
"devDependencies": {
......
import { v4 } from 'uuid';
import Vue from 'vue';
const _toString = Object.prototype.toString;
......@@ -527,10 +528,45 @@ var previewImage = {
}
};
const UUID_KEY = '__DC_UUID';
let uuid;
function addUuid (result) {
uuid = uuid || wx.getStorageSync(UUID_KEY);
if (!uuid) {
uuid = v4();
wx.setStorage({
key: UUID_KEY,
data: uuid
});
}
result.uuid = uuid;
}
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea;
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom
};
}
}
var getSystemInfo = {
returnValue: function (result) {
addUuid(result);
addSafeAreaInsets(result);
}
};
const protocols = {
navigateTo,
redirectTo,
previewImage
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo
};
const todos = [
'preloadPage',
......
......@@ -97,6 +97,7 @@ export function getSystemInfo () {
right: safeAreaInsets.right,
bottom: safeAreaInsets.bottom,
left: safeAreaInsets.left
}
},
uuid: plus.runtime.getDCloudId()
}
}
import { v4 as uuidv4 } from 'uuid'
const UUID_KEY = '__DC_UUID'
const storage = window.localStorage || window.sessionStorage || {}
let uuid
export default function () {
uuid = uuid || storage[UUID_KEY]
if (!uuid) {
uuid = uuidv4()
try {
storage[UUID_KEY] = uuid
} catch (error) {
}
}
return uuid
}
import getWindowOffset from 'uni-platform/helpers/get-window-offset'
import uuid from 'uni-platform/helpers/uuid'
import safeAreaInsets from 'safe-area-insets'
const ua = navigator.userAgent
......@@ -111,7 +112,8 @@ export function getSystemInfoSync () {
right: safeAreaInsets.right,
bottom: safeAreaInsets.bottom,
left: safeAreaInsets.left
}
},
uuid: uuid()
}
}
/**
......
export function setStorageSync (key, data) {
return my.setStorageSync({
key,
data
})
}
export function getStorageSync (key) {
const result = my.getStorageSync({
key
})
// 支付宝平台会返回一个 success 值,但是目前测试的结果这个始终是 true。当没有存储数据的时候,其它平台会返回空字符串。
return result.data !== null ? result.data : ''
}
export function removeStorageSync (key) {
return my.removeStorageSync({
key
})
}
import { v4 as uuidv4 } from 'uuid'
import { getStorageSync } from './storage'
const UUID_KEY = '__DC_UUID'
let uuid
function addUuid (result) {
uuid = uuid || getStorageSync(UUID_KEY)
if (!uuid) {
uuid = uuidv4()
__GLOBAL__.setStorage({
key: UUID_KEY,
data: uuid
})
}
result.uuid = uuid
}
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom
}
}
}
function normalizePlatform (result) {
let platform = result.platform ? result.platform.toLowerCase() : 'devtools'
if (!~['android', 'ios'].indexOf(platform)) {
platform = 'devtools'
}
result.platform = platform
}
export default {
returnValue: function (result) {
addUuid(result)
addSafeAreaInsets(result)
normalizePlatform(result)
}
}
......@@ -4,24 +4,11 @@ import {
hasOwn
} from 'uni-shared'
export function setStorageSync (key, data) {
return my.setStorageSync({
key,
data
})
}
export function getStorageSync (key) {
const result = my.getStorageSync({
key
})
// 支付宝平台会返回一个 success 值,但是目前测试的结果这个始终是 true。当没有存储数据的时候,其它平台会返回空字符串。
return result.data !== null ? result.data : ''
}
export function removeStorageSync (key) {
return my.removeStorageSync({
key
})
}
export {
setStorageSync,
getStorageSync,
removeStorageSync
} from '../../helpers/storage'
export function startGyroscope (params) {
if (hasOwn(params, 'interval')) {
......
......@@ -3,6 +3,7 @@ import {
} from 'uni-shared'
import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import getSystemInfo from '../../helpers/system-info'
// 不支持的 API 列表
const todos = [
......@@ -73,14 +74,6 @@ function _handleNetworkInfo (result) {
return {}
}
function _handleSystemInfo (result) {
let platform = result.platform ? result.platform.toLowerCase() : 'devtools'
if (!~['android', 'ios'].indexOf(platform)) {
platform = 'devtools'
}
result.platform = platform
}
const protocols = { // 需要做转换的 API 列表
navigateTo,
redirectTo,
......@@ -426,12 +419,8 @@ const protocols = { // 需要做转换的 API 列表
stopGyroscope: {
name: 'offGyroscopeChange'
},
getSystemInfo: {
returnValue: _handleSystemInfo
},
getSystemInfoSync: {
returnValue: _handleSystemInfo
},
getSystemInfo: getSystemInfo,
getSystemInfoSync: getSystemInfo,
// 文档没提到,但是实测可用。
canvasToTempFilePath: {
returnValue (result) {
......
import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// 不支持的 API 列表
const todos = [
......@@ -86,6 +87,8 @@ const protocols = {
navigateTo,
redirectTo,
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo,
getRecorderManager: {
returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded')
......
import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
export const protocols = {
navigateTo,
redirectTo,
previewImage
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo
}
export const todos = [
'vibrate'
......
import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
export const protocols = {
navigateTo,
redirectTo,
previewImage
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo
}
export const todos = [
'preloadPage',
......
import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
import getSystemInfo from '../../../mp-weixin/helpers/system-info'
// 不支持的 API 列表
const todos = [
......@@ -104,6 +105,8 @@ const protocols = {
navigateTo,
redirectTo,
previewImage,
getSystemInfo,
getSystemInfoSync: getSystemInfo,
connectSocket: {
args: {
method: false
......
import { v4 as uuidv4 } from 'uuid'
const UUID_KEY = '__DC_UUID'
let uuid
function addUuid (result) {
uuid = uuid || __GLOBAL__.getStorageSync(UUID_KEY)
if (!uuid) {
uuid = uuidv4()
__GLOBAL__.setStorage({
key: UUID_KEY,
data: uuid
})
}
result.uuid = uuid
}
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom
}
}
}
export default {
returnValue: function (result) {
addUuid(result)
addSafeAreaInsets(result)
}
}
// import navigateTo from 'uni-helpers/navigate-to'
import redirectTo from '../../helpers/redirect-to'
import previewImage from '../../helpers/normalize-preview-image'
import getSystemInfo from '../../helpers/system-info'
function addSafeAreaInsets (result) {
if (result.safeArea) {
const safeArea = result.safeArea
result.safeAreaInsets = {
top: safeArea.top,
left: safeArea.left,
right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom
}
}
}
export const protocols = {
redirectTo,
// navigateTo, // 由于在微信开发者工具的页面参数,会显示__id__参数,因此暂时关闭mp-weixin对于navigateTo的AOP
previewImage,
getSystemInfo: {
returnValue: addSafeAreaInsets
},
getSystemInfoSync: {
returnValue: addSafeAreaInsets
}
getSystemInfo,
getSystemInfoSync: getSystemInfo
}
export const todos = [
'vibrate',
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册