提交 540e825e 编写于 作者: 郭胜强

Merge branch 'dev' of github.com:dcloudio/uni-app into dev

# Conflicts:
#	src/platforms/mp-alipay/service/api/protocols.js
......@@ -19,8 +19,13 @@ function hasOwn (obj, key) {
const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/;
const CONTEXT_API_RE = /^create|Manager$/;
const CALLBACK_API_RE = /^on/;
function isContextApi (name) {
return CONTEXT_API_RE.test(name)
}
function isSyncApi (name) {
return SYNC_API_RE.test(name)
}
......@@ -112,68 +117,137 @@ function upx2px (number, newDeviceWidth) {
return number
}
var protocols = {};
// 不支持的 API 列表
const TODOS = [
'hideKeyboard'
];
function createTodoMethod (contextName, methodName) {
return function unsupported () {
console.error(`百度小程序 ${contextName}暂不支持${methodName}`);
}
}
// 需要做转换的 API 列表
const protocols = {
request: {
args (fromArgs) {
// TODO
// data 不支持 ArrayBuffer
// method 不支持 TRACE, CONNECT
// dataType 可取值为 string/json
return fromArgs
}
},
connectSocket: {
args: {
method: false
}
},
previewImage: {
args: {
indicator: false,
loop: false
}
},
getRecorderManager: {
returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded');
}
},
getBackgroundAudioManager: {
returnValue (fromRet) {
fromRet.onPrev = createTodoMethod('BackgroundAudioManager', 'onPrev');
fromRet.onNext = createTodoMethod('BackgroundAudioManager', 'onNext');
}
},
createInnerAudioContext: {
returnValue: {
buffered: false
}
},
createVideoContext: {
returnValue: {
playbackRate: false
}
},
scanCode: {
onlyFromCamera: false,
scanType: false
}
};
TODOS.forEach(todoApi => {
protocols[todoApi] = false;
});
const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
function processCallback (method, returnValue) {
function processCallback (methodName, method, returnValue) {
return function (res) {
return method(processReturnValue(res, returnValue))
return method(processReturnValue(methodName, res, returnValue))
}
}
function processArgs (fromArgs, argsOption = {}, returnValue = {}) {
function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
const toArgs = {};
Object.keys(fromArgs).forEach(key => {
const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
if (isFn(argsOption)) {
argsOption = argsOption(fromArgs, toArgs) || {};
}
for (let key in fromArgs) {
if (hasOwn(argsOption, key)) {
let keyOption = argsOption[key];
if (isFn(keyOption)) {
keyOption = keyOption(fromArgs[key], fromArgs);
keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
}
if (!keyOption) { // 不支持的参数
console.warn(`${百度小程序} ${name}暂不支持${key}`);
console.warn(`百度小程序 ${methodName}暂不支持${key}`);
} else if (isStr(keyOption)) { // 重写参数 key
toArgs[keyOption] = fromArgs[key];
} else if (isPlainObject(keyOption)) { // {name:newName,value:value}可重新指定参数 key:value
toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
}
} else if (CALLBACKS.includes(key)) {
toArgs[key] = processCallback(fromArgs[key], returnValue);
toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
} else {
toArgs[key] = fromArgs[key];
if (!keepFromArgs) {
toArgs[key] = fromArgs[key];
}
}
});
}
return toArgs
} else if (isFn(fromArgs)) {
fromArgs = processCallback(fromArgs, returnValue);
fromArgs = processCallback(methodName, fromArgs, returnValue);
}
return fromArgs
}
function processReturnValue (res, returnValue) {
return processArgs(res, returnValue)
function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
if (isFn(protocols.returnValue)) { // 处理通用 returnValue
res = protocols.returnValue(methodName, res);
}
return processArgs(methodName, res, returnValue, {}, keepReturnValue)
}
function wrapper (name, method) {
if (hasOwn(protocols, name)) {
const protocol = protocols[name];
function wrapper (methodName, method) {
if (hasOwn(protocols, methodName)) {
const protocol = protocols[methodName];
if (!protocol) { // 暂不支持的 api
return function () {
throw new Error(`${百度小程序}暂不支持${name}`)
console.error(`百度小程序 暂不支持${methodName}`);
}
}
return function (arg1, arg2) { // 目前 api 最多两个参数
return function (arg1, arg2) { // 目前 api 最多两个参数
let options = protocol;
if (isFn(protocol)) {
options = protocol(arg1);
}
arg1 = processArgs(arg1, options.args, options.returnValue);
arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
const returnValue = swan[options.name || name](arg1, arg2);
if (isSyncApi(name)) { // 同步 api
return processReturnValue(returnValue, options.returnValue)
const returnValue = swan[options.name || methodName](arg1, arg2);
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
return returnValue
}
......@@ -183,7 +257,7 @@ function wrapper (name, method) {
const todoApis = Object.create(null);
const TODOS = [
const TODOS$1 = [
'subscribePush',
'unsubscribePush',
'onPush',
......@@ -204,7 +278,7 @@ function createTodoApi (name) {
}
}
TODOS.forEach(function (name) {
TODOS$1.forEach(function (name) {
todoApis[name] = createTodoApi(name);
});
......@@ -265,7 +339,7 @@ if (typeof Proxy !== 'undefined') {
if (todoApis[name]) {
return promisify(name, todoApis[name])
}
if (!swan.hasOwnProperty(name)) {
if (!hasOwn(swan, name) && !hasOwn(protocols, name)) {
return
}
return promisify(name, wrapper(name, swan[name]))
......@@ -287,7 +361,7 @@ if (typeof Proxy !== 'undefined') {
});
Object.keys(swan).forEach(name => {
if (swan.hasOwnProperty(name)) {
if (hasOwn(swan, name) || hasOwn(protocols, name)) {
uni$1[name] = promisify(name, wrapper(name, swan[name]));
}
});
......
......@@ -4,10 +4,15 @@ import {
const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
const CONTEXT_API_RE = /^create|Manager$/
const TASK_APIS = ['request', 'downloadFile', 'uploadFile', 'connectSocket']
const CALLBACK_API_RE = /^on/
export function isContextApi (name) {
return CONTEXT_API_RE.test(name)
}
export function isSyncApi (name) {
return SYNC_API_RE.test(name)
}
......
......@@ -6,7 +6,8 @@ import {
} from 'uni-shared'
import {
isSyncApi
isSyncApi,
isContextApi
} from '../helpers/promise'
import protocols from 'uni-platform/service/api/protocols'
......@@ -19,13 +20,13 @@ function processCallback (methodName, method, returnValue) {
}
}
function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) {
function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
const toArgs = {}
const toArgs = keepFromArgs === true ? fromArgs : {} // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
if (isFn(argsOption)) {
argsOption = argsOption(fromArgs, toArgs) || {}
}
Object.keys(fromArgs).forEach(key => {
for (let key in fromArgs) {
if (hasOwn(argsOption, key)) {
let keyOption = argsOption[key]
if (isFn(keyOption)) {
......@@ -41,9 +42,11 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) {
} else if (CALLBACKS.includes(key)) {
toArgs[key] = processCallback(methodName, fromArgs[key], returnValue)
} else {
toArgs[key] = fromArgs[key]
if (!keepFromArgs) {
toArgs[key] = fromArgs[key]
}
}
})
}
return toArgs
} else if (isFn(fromArgs)) {
fromArgs = processCallback(methodName, fromArgs, returnValue)
......@@ -51,11 +54,11 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) {
return fromArgs
}
function processReturnValue (methodName, res, returnValue) {
function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
if (isFn(protocols.returnValue)) { // 处理通用 returnValue
res = protocols.returnValue(methodName, res)
}
return processArgs(methodName, res, returnValue)
return processArgs(methodName, res, returnValue, {}, keepReturnValue)
}
export default function wrapper (methodName, method) {
......@@ -76,7 +79,7 @@ export default function wrapper (methodName, method) {
const returnValue = __GLOBAL__[options.name || methodName](arg1, arg2)
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue)
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
return returnValue
}
......
......@@ -8,10 +8,15 @@ export function getApp () {
export function getCurrentPages (isAll = false) {
const pages = []
const childrenVm = appVm.$children[0]
const app = getApp()
if (!app) {
console.error('app is not ready')
return []
}
const childrenVm = app.$children[0]
if (childrenVm && childrenVm.$children.length) {
const tabBarVm = childrenVm.$children.find(vm => vm.$options.name === 'TabBar')
const app = getApp()
childrenVm.$children.forEach(vm => {
if (tabBarVm !== vm && vm.$children.length && vm.$children[0].$options.name === 'Page' && vm.$children[0].$slots.page) {
// vm.$children[0]=Page->PageBody->RealPage
......@@ -39,6 +44,15 @@ export function getCurrentPages (isAll = false) {
}
})
}
// 当页面返回过程中,请求 getCurrentPages 时,可能会获取到前一个已经准备销毁的 page
const length = pages.length
if (length > 1) {
const currentPage = pages[length - 1]
if (currentPage.$page.path !== app.$route.path) { // 删除已经准备销毁的上个页面
pages.splice(length - 1, 1)
}
}
return pages
}
......
......@@ -97,7 +97,7 @@ function afterEach (to, from) {
const fromId = from.params.__id__
const toId = to.params.__id__
const fromVm = getCurrentPages().find(pageVm => pageVm.$page.id === fromId)
const fromVm = getCurrentPages(true).find(pageVm => pageVm.$page.id === fromId)
switch (to.type) {
case 'navigateTo': // 前一个页面触发 onHide
......
......@@ -7,19 +7,24 @@ export default function getWindowOffset () {
if (uni.canIUse('css.var')) {
const style = document.documentElement.style
return {
top: parseInt(style.getPropertyValue('--window-top')),
bottom: parseInt(style.getPropertyValue('--window-bottom'))
top: parseInt(style.getPropertyValue('--window-top')) || 0,
bottom: parseInt(style.getPropertyValue('--window-bottom')) || 0
}
}
let top = 0
let bottom = 0
const pages = getCurrentPages()
if (pages.length) {
const pageVm = pages[pages.length - 1].$parent.$parent
top = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' ? NAVBAR_HEIGHT : 0
}
const app = getApp()
if (app) {
bottom = app.$children[0].showTabBar ? TABBAR_HEIGHT : 0
}
return {
top,
bottom: getApp().$children[0].showTabBar ? TABBAR_HEIGHT : 0
bottom
}
}
......@@ -598,7 +598,9 @@ export default {
}
}
}
img.src = option.iconPath ||
console.log(option.iconPath)
console.log(this.$getRealPath(option.iconPath))
img.src = this.$getRealPath(option.iconPath) ||
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trL3VxctMMOOoi2q2r5/LnWeF5vqK90gAGyTaXTy5ZAtpXRms5jIMjcq8LQwMnywIAVgrDVwuD+9K68oZ1dxcWcrcX+IfScHKwBRWfu9H8Xn2XSm3w8LAYHfEQ5F6TVGYWM6qYsy570q5Lf+mYSRH1QFwA8AGgJsooOXe7tzl/wGchYFKtBMCwAAAAABJRU5ErkJggg=='
},
removeMarkers (markers) {
......@@ -720,7 +722,7 @@ export default {
style.top = (position.top || 0) + 'px'
style.maxWidth = 'initial'
}
img.src = option.iconPath
img.src = this.$getRealPath(option.iconPath)
onTap(img, $event => {
if (option.clickable) {
this.$trigger('controltap', $event, {
......
......@@ -6,15 +6,46 @@ const TODOS = [ // 不支持的 API 列表
'setTabBarItem',
'setTabBarStyle',
'showTabBar',
'showTabBarRedDot'
'showTabBarRedDot',
'startPullDownRefresh',
'saveImageToPhotosAlbum',
'getRecorderManager',
'getBackgroundAudioManager',
'createInnerAudioContext',
'chooseVideo',
'saveVideoToPhotosAlbum',
'createVideoContext',
'openDocument',
'startAccelerometer',
'startCompass',
'addPhoneContact',
'createIntersectionObserver'
]
function _handleNetworkInfo (result) {
switch (result.networkType) {
case 'NOTREACHABLE':
result.networkType = 'none'
break
case 'WWAN':
// TODO ?
result.networkType = '3g'
break
default:
result.networkType = result.networkType.toLowerCase()
break
}
return {}
}
const protocols = { // 需要做转换的 API 列表
returnValue (methodName, res) { // 通用 returnValue 解析
if (res.error || res.errorMessage) {
res.errMsg = `${methodName}:fail ${res.errorMessage || res.error}`
delete res.error
delete res.errorMessage
} else {
res.errMsg = `${methodName}:ok`
}
return res
},
......@@ -116,6 +147,141 @@ const protocols = { // 需要做转换的 API 列表
returnValue: {
index: 'tapIndex'
}
},
showLoading: {
args: {
title: 'content',
mask: false
}
},
uploadFile: {
args: {
name: 'fileName'
}
// 从测试结果看,是有返回对象的,文档上没有说明。
},
downloadFile: {
returnValue: {
apFilePath: 'tempFilePath'
}
},
connectSocket: {
args: {
method: false,
protocols: false
}
// TODO 有没有返回值还需要测试下
},
chooseImage: {
returnValue: {
apFilePaths: 'tempFilePaths'
}
},
previewImage: {
args (fromArgs) {
// 支付宝小程序的 current 是索引值,而非图片地址。
if (fromArgs.current && Array.isArray(fromArgs.urls)) {
const index = fromArgs.urls.indexOf(fromArgs.current)
fromArgs.current = ~index ? index : 0
}
return {
indicator: false,
loop: false
}
}
},
saveFile: {
args: {
tempFilePath: 'apFilePath'
},
returnValue: {
apFilePath: 'savedFilePath'
}
},
getSavedFileInfo: {
args: {
filePath: 'apFilePath'
},
returnValue (result) {
if (result.fileList && result.fileList.length) {
result.fileList.forEach(file => {
file.filePath = file.apFilePath
delete file.apFilePath
})
}
return {}
}
},
removeSavedFile: {
args: {
filePath: 'apFilePath'
}
},
getLocation: {
args: {
type: false,
altitude: false
}
// returnValue: {
// speed: false,
// altitude: false,
// verticalAccuracy: false
// }
},
openLocation: {
args: {
// TODO address 参数在阿里上是必传的
}
},
getSystemInfo: {
// returnValue: {
// brand: false,
// statusBarHeight: false,
// SDKVersion: false
// }
},
getSystemInfoSync: {
// returnValue: {
// brand: false,
// statusBarHeight: false,
// SDKVersion: false
// }
},
getNetworkType: {
returnValue: _handleNetworkInfo
},
onNetworkStatusChange: {
returnValue: _handleNetworkInfo
},
stopAccelerometer: {
name: 'offAccelerometerChange'
},
stopCompass: {
name: 'offCompassChange'
},
scanCode: {
name: 'scan',
args: {
onlyFromCamera: 'hideAlbum',
scanType: false
}
},
setClipboardData: {
name: 'setClipboard',
args: {
data: 'text'
}
},
getClipboardData: {
name: 'getClipboard',
returnValue: {
text: 'data'
}
},
pageScrollTo: {
args: {
duration: false
}
}
}
......
export default {}
// 不支持的 API 列表
const TODOS = [
'hideKeyboard'
]
function createTodoMethod (contextName, methodName) {
return function unsupported () {
console.error(`__PLATFORM_TITLE__ ${contextName}暂不支持${methodName}`)
}
}
// 需要做转换的 API 列表
const protocols = {
request: {
args (fromArgs) {
// TODO
// data 不支持 ArrayBuffer
// method 不支持 TRACE, CONNECT
// dataType 可取值为 string/json
return {
method: 'method'
}
}
},
connectSocket: {
args: {
method: false
}
},
previewImage: {
args: {
indicator: false,
loop: false
}
},
getRecorderManager: {
returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded')
}
},
getBackgroundAudioManager: {
returnValue (fromRet) {
fromRet.onPrev = createTodoMethod('BackgroundAudioManager', 'onPrev')
fromRet.onNext = createTodoMethod('BackgroundAudioManager', 'onNext')
}
},
scanCode: {
args: {
onlyFromCamera: false,
scanType: false
}
}
}
TODOS.forEach(todoApi => {
protocols[todoApi] = false
})
export default protocols
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册