Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcloud-robot committed Jan 8, 2019
2 parents 86e93b0 + 3c31e1a commit c7c506e
Show file tree
Hide file tree
Showing 27 changed files with 584 additions and 607 deletions.
34 changes: 23 additions & 11 deletions packages/uni-mp-alipay/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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'
}
}
};

Expand Down Expand Up @@ -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
Expand All @@ -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;
2 changes: 1 addition & 1 deletion packages/uni-mp-alipay/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
22 changes: 11 additions & 11 deletions packages/uni-mp-baidu/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
2 changes: 1 addition & 1 deletion packages/uni-mp-baidu/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
22 changes: 11 additions & 11 deletions packages/uni-mp-weixin/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
2 changes: 1 addition & 1 deletion packages/uni-mp-weixin/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

import {
upx2px
} from '../service/api/upx2px'
} from './upx2px'

import wrapper from './wrapper'

Expand Down
38 changes: 38 additions & 0 deletions src/core/runtime/upx2px.js
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 20 additions & 3 deletions src/core/service/plugins/app/router-guard.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ function reLaunch (toName) {
this.keepAliveInclude = []
}

let currentPages = []

function beforeEach (to, from, next, routes) {
currentPages = getCurrentPages(true) // 每次 beforeEach 时获取当前currentPages,因为 afterEach 之后,获取不到上一个 page 了,导致无法调用 onUnload
const fromId = from.params.__id__
const toId = to.params.__id__
if (toId === fromId) { // 相同页面阻止
Expand All @@ -58,12 +61,26 @@ function beforeEach (to, from, next, routes) {
case 'redirectTo':
// 关闭前一个页面
removeKeepAliveInclude.call(this, fromName)
if (from.meta) {
if (from.meta.isQuit) { // 如果 redirectTo 的前一个页面是 quit 类型,则新打开的页面也是 quit
to.meta.isQuit = true
to.meta.isEntry = !!from.meta.isEntry
}
if (from.meta.isTabBar) { // 如果是 tabBar,需要更新系统组件 tabBar 内的 list 数据
to.meta.isTabBar = true
to.meta.tabBarIndex = from.meta.tabBarIndex
const appVm = getApp().$children[0]
appVm.$set(appVm.tabBar.list[to.meta.tabBarIndex], 'pagePath', to.meta.pagePath)
}
}

break
case 'switchTab':
switchTab.call(this, routes)
break
case 'reLaunch':
reLaunch.call(this, toName)
to.meta.isQuit = true // reLaunch后,该页面为 quit 类型
break
default:
// 后退或非 API 访问
Expand Down Expand Up @@ -97,7 +114,7 @@ function afterEach (to, from) {
const fromId = from.params.__id__
const toId = to.params.__id__

const fromVm = getCurrentPages(true).find(pageVm => pageVm.$page.id === fromId)
const fromVm = currentPages.find(pageVm => pageVm.$page.id === fromId) // 使用 beforeEach 时的 pages

switch (to.type) {
case 'navigateTo': // 前一个页面触发 onHide
Expand All @@ -121,10 +138,10 @@ function afterEach (to, from) {
}
if (to.type !== 'reLaunch') { // 因为 reLaunch 会重置 id,故不触发 onShow,switchTab 在 beforeRouteEnter 中触发
// 直接获取所有 pages,getCurrentPages 正常情况下仅返回页面栈内,传 true 则返回所有已存在(主要是 tabBar 页面)
const toVm = getCurrentPages(true).find(pageVm => pageVm.$page.id === toId)
const toVm = getCurrentPages(true).find(pageVm => pageVm.$page.id === toId) // 使用最新的 pages
if (toVm) { // 目标页面若已存在,则触发 onShow
// 延迟执行 onShow,防止与 UniServiceJSBridge.emit('onHidePopup') 冲突。
setTimeout(function () {
setTimeout(function () {
callPageHook(toVm, 'onShow')
}, 0)
}
Expand Down
14 changes: 10 additions & 4 deletions src/core/view/bridge/subscribe/request-component-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,25 @@ function getNodeInfo (el, fields) {
function getNodesInfo (pageVm, component, selector, single, fields) {
const $el = pageVm.$el
if (single) {
const node = $el.querySelector(selector)
const node = $el && ($el.matches(selector) ? $el : $el.querySelector(selector))
if (node) {
return getNodeInfo(node, fields)
}
return null
} else if (!$el) {
return []
} else {
let infos = []
const nodeList = $el.querySelectorAll(selector)
if (nodeList && nodeList.length) {
return ([]).map.call(nodeList, node => {
infos = ([]).map.call(nodeList, node => {
return getNodeInfo(node, fields)
})
}
return []
if ($el.matches(selector)) {
infos.unshift($el)
}
return infos
}
}

Expand Down Expand Up @@ -118,4 +124,4 @@ export default function requestComponentInfo ({
reqId,
res: result
}, pageVm.$page.id)
}
}
3 changes: 2 additions & 1 deletion src/core/view/bridge/subscribe/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function pageScrollTo ({
scrollTop = Math.min(scrollTop, scrollHeight - clientHeight)

if (duration === 0) {
documentElement.scrollTop = scrollTop
// 部分浏览器(比如微信)中 scrollTop 的值需要通过 document.body 来控制
documentElement.scrollTop = document.body.scrollTop = scrollTop
return
}

Expand Down
Loading

0 comments on commit c7c506e

Please sign in to comment.