From 5c7766a34adcffd7170f636ed4df5efd5906a761 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 2 Jan 2019 15:20:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20upx2px=20=E5=86=85=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=20uni.getSystemInfoSync=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-mp-alipay/dist/index.js | 34 +++++++++++++++++-------- packages/uni-mp-alipay/package.json | 2 +- packages/uni-mp-baidu/dist/index.js | 22 ++++++++-------- packages/uni-mp-baidu/package.json | 2 +- packages/uni-mp-weixin/dist/index.js | 22 ++++++++-------- packages/uni-mp-weixin/package.json | 2 +- src/core/runtime/index.js | 2 +- src/core/runtime/upx2px.js | 38 ++++++++++++++++++++++++++++ 8 files changed, 87 insertions(+), 37 deletions(-) create mode 100644 src/core/runtime/upx2px.js diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 8916f8377a..8cf89cd6cc 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -89,14 +89,14 @@ function checkDeviceWidth () { platform, pixelRatio, windowWidth - } = uni.getSystemInfoSync(); + } = my.getSystemInfoSync(); // runtime 编译目标是 uni 对象,内部不允许直接使用 uni deviceWidth = windowWidth; deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -function upx2px (number, newDeviceWidth) { +function upx2px (number, newDeviceWidth) { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -406,6 +406,18 @@ const protocols = { // 需要做转换的 API 列表 args: { orderInfo: 'orderStr' } + }, + getBLEDeviceServices: { + returnValue (result) { + result.services.forEach((item) => { + item.uuid = item.serviceId; + }); + } + }, + makePhoneCall: { + args: { + phoneNumber: 'number' + } } }; @@ -578,10 +590,10 @@ var api = /*#__PURE__*/Object.freeze({ removeStorageSync: removeStorageSync }); -let uni$1 = {}; +let uni = {}; if (typeof Proxy !== 'undefined') { - uni$1 = new Proxy({}, { + uni = new Proxy({}, { get (target, name) { if (name === 'upx2px') { return upx2px @@ -602,27 +614,27 @@ if (typeof Proxy !== 'undefined') { } }); } else { - uni$1.upx2px = upx2px; + uni.upx2px = upx2px; Object.keys(todoApis).forEach(name => { - uni$1[name] = promisify(name, todoApis[name]); + uni[name] = promisify(name, todoApis[name]); }); Object.keys(extraApi).forEach(name => { - uni$1[name] = promisify(name, todoApis[name]); + uni[name] = promisify(name, todoApis[name]); }); Object.keys(api).forEach(name => { - uni$1[name] = promisify(name, api[name]); + uni[name] = promisify(name, api[name]); }); Object.keys(my).forEach(name => { if (hasOwn(my, name) || hasOwn(protocols, name)) { - uni$1[name] = promisify(name, wrapper(name, my[name])); + uni[name] = promisify(name, wrapper(name, my[name])); } }); } -var uni$2 = uni$1; +var uni$1 = uni; -export default uni$2; +export default uni$1; diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json index bbd08088fe..7f9a79cf73 100644 --- a/packages/uni-mp-alipay/package.json +++ b/packages/uni-mp-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-alipay", - "version": "0.0.5", + "version": "0.0.6", "description": "uni-app mp-alipay", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index f0a8b6ab4e..baeadefccc 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -89,14 +89,14 @@ function checkDeviceWidth () { platform, pixelRatio, windowWidth - } = uni.getSystemInfoSync(); + } = swan.getSystemInfoSync(); // uni=>swan runtime 编译目标是 uni 对象,内部不允许直接使用 uni deviceWidth = windowWidth; deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -function upx2px (number, newDeviceWidth) { +function upx2px (number, newDeviceWidth) { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -332,10 +332,10 @@ var api = /*#__PURE__*/Object.freeze({ requestPayment: requestPayment }); -let uni$1 = {}; +let uni = {}; if (typeof Proxy !== 'undefined') { - uni$1 = new Proxy({}, { + uni = new Proxy({}, { get (target, name) { if (name === 'upx2px') { return upx2px @@ -356,27 +356,27 @@ if (typeof Proxy !== 'undefined') { } }); } else { - uni$1.upx2px = upx2px; + uni.upx2px = upx2px; Object.keys(todoApis).forEach(name => { - uni$1[name] = promisify(name, todoApis[name]); + uni[name] = promisify(name, todoApis[name]); }); Object.keys(extraApi).forEach(name => { - uni$1[name] = promisify(name, todoApis[name]); + uni[name] = promisify(name, todoApis[name]); }); Object.keys(api).forEach(name => { - uni$1[name] = promisify(name, api[name]); + uni[name] = promisify(name, api[name]); }); Object.keys(swan).forEach(name => { if (hasOwn(swan, name) || hasOwn(protocols, name)) { - uni$1[name] = promisify(name, wrapper(name, swan[name])); + uni[name] = promisify(name, wrapper(name, swan[name])); } }); } -var uni$2 = uni$1; +var uni$1 = uni; -export default uni$2; +export default uni$1; diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index 157ddffda2..8989d24e6d 100644 --- a/packages/uni-mp-baidu/package.json +++ b/packages/uni-mp-baidu/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-baidu", - "version": "0.0.4", + "version": "0.0.5", "description": "uni-app mp-baidu", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index b681c86130..fd8a5cc0cd 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -89,14 +89,14 @@ function checkDeviceWidth () { platform, pixelRatio, windowWidth - } = uni.getSystemInfoSync(); + } = wx.getSystemInfoSync(); // uni=>wx runtime 编译目标是 uni 对象,内部不允许直接使用 uni deviceWidth = windowWidth; deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -function upx2px (number, newDeviceWidth) { +function upx2px (number, newDeviceWidth) { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -261,10 +261,10 @@ var api = /*#__PURE__*/Object.freeze({ }); -let uni$1 = {}; +let uni = {}; if (typeof Proxy !== 'undefined') { - uni$1 = new Proxy({}, { + uni = new Proxy({}, { get (target, name) { if (name === 'upx2px') { return upx2px @@ -285,27 +285,27 @@ if (typeof Proxy !== 'undefined') { } }); } else { - uni$1.upx2px = upx2px; + uni.upx2px = upx2px; Object.keys(todoApis).forEach(name => { - uni$1[name] = promisify(name, todoApis[name]); + uni[name] = promisify(name, todoApis[name]); }); Object.keys(extraApi).forEach(name => { - uni$1[name] = promisify(name, todoApis[name]); + uni[name] = promisify(name, todoApis[name]); }); Object.keys(api).forEach(name => { - uni$1[name] = promisify(name, api[name]); + uni[name] = promisify(name, api[name]); }); Object.keys(wx).forEach(name => { if (hasOwn(wx, name) || hasOwn(protocols, name)) { - uni$1[name] = promisify(name, wrapper(name, wx[name])); + uni[name] = promisify(name, wrapper(name, wx[name])); } }); } -var uni$2 = uni$1; +var uni$1 = uni; -export default uni$2; +export default uni$1; diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 43a4cd2da3..541be565a3 100644 --- a/packages/uni-mp-weixin/package.json +++ b/packages/uni-mp-weixin/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-weixin", - "version": "0.0.3", + "version": "0.0.4", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/core/runtime/index.js b/src/core/runtime/index.js index 6c8fbb142f..045d33e1fa 100644 --- a/src/core/runtime/index.js +++ b/src/core/runtime/index.js @@ -8,7 +8,7 @@ import { import { upx2px -} from '../service/api/upx2px' +} from './upx2px' import wrapper from './wrapper' diff --git a/src/core/runtime/upx2px.js b/src/core/runtime/upx2px.js new file mode 100644 index 0000000000..38785161d9 --- /dev/null +++ b/src/core/runtime/upx2px.js @@ -0,0 +1,38 @@ +const EPS = 1e-4 +const BASE_DEVICE_WIDTH = 750 +let isIOS = false +let deviceWidth = 0 +let deviceDPR = 0 + +export function checkDeviceWidth () { + const { + platform, + pixelRatio, + windowWidth + } = __GLOBAL__.getSystemInfoSync() // uni=>__GLOBAL__ runtime 编译目标是 uni 对象,内部不允许直接使用 uni + + deviceWidth = windowWidth + deviceDPR = pixelRatio + isIOS = platform === 'ios' +} + +export function upx2px (number, newDeviceWidth) { + if (deviceWidth === 0) { + checkDeviceWidth() + } + + number = Number(number) + if (number === 0) { + return 0 + } + number = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth) + number = Math.floor(number + EPS) + if (number === 0) { + if (deviceDPR === 1 || !isIOS) { + return 1 + } else { + return 0.5 + } + } + return number +} -- GitLab