提交 2471aaad 编写于 作者: fxy060608's avatar fxy060608

uni-mp-alipay(0.0.3),uni-mp-baidu(0.0.3)

上级 91525bb2
...@@ -19,8 +19,13 @@ function hasOwn (obj, key) { ...@@ -19,8 +19,13 @@ function hasOwn (obj, key) {
const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/; const SYNC_API_RE = /hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/;
const CONTEXT_API_RE = /^create|Manager$/;
const CALLBACK_API_RE = /^on/; const CALLBACK_API_RE = /^on/;
function isContextApi (name) {
return CONTEXT_API_RE.test(name)
}
function isSyncApi (name) { function isSyncApi (name) {
return SYNC_API_RE.test(name) return SYNC_API_RE.test(name)
} }
...@@ -112,7 +117,7 @@ function upx2px (number, newDeviceWidth) { ...@@ -112,7 +117,7 @@ function upx2px (number, newDeviceWidth) {
return number return number
} }
const TODOS = [ const TODOS = [ // 不支持的 API 列表
'hideTabBar', 'hideTabBar',
'hideTabBarRedDot', 'hideTabBarRedDot',
'removeTabBarBadge', 'removeTabBarBadge',
...@@ -120,15 +125,46 @@ const TODOS = [ ...@@ -120,15 +125,46 @@ const TODOS = [
'setTabBarItem', 'setTabBarItem',
'setTabBarStyle', 'setTabBarStyle',
'showTabBar', 'showTabBar',
'showTabBarRedDot' 'showTabBarRedDot',
'startPullDownRefresh',
'saveImageToPhotosAlbum',
'getRecorderManager',
'getBackgroundAudioManager',
'createInnerAudioContext',
'chooseVideo',
'saveVideoToPhotosAlbum',
'createVideoContext',
'openDocument',
'startAccelerometer',
'startCompass',
'addPhoneContact',
'createIntersectionObserver'
]; ];
const protocols = { 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 解析 returnValue (methodName, res) { // 通用 returnValue 解析
if (res.error || res.errorMessage) { if (res.error || res.errorMessage) {
res.errMsg = `${methodName}:fail ${res.errorMessage || res.error}`; res.errMsg = `${methodName}:fail ${res.errorMessage || res.error}`;
delete res.error; delete res.error;
delete res.errorMessage; delete res.errorMessage;
} else {
res.errMsg = `${methodName}:ok`;
} }
return res return res
}, },
...@@ -230,6 +266,141 @@ const protocols = { ...@@ -230,6 +266,141 @@ const protocols = {
returnValue: { returnValue: {
index: 'tapIndex' 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
}
} }
}; };
...@@ -245,13 +416,13 @@ function processCallback (methodName, method, returnValue) { ...@@ -245,13 +416,13 @@ function processCallback (methodName, method, returnValue) {
} }
} }
function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) { function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
if (isPlainObject(fromArgs)) { // 一般 api 的参数解析 if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
const toArgs = {}; const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
if (isFn(argsOption)) { if (isFn(argsOption)) {
argsOption = argsOption(fromArgs, toArgs) || {}; argsOption = argsOption(fromArgs, toArgs) || {};
} }
Object.keys(fromArgs).forEach(key => { for (let key in fromArgs) {
if (hasOwn(argsOption, key)) { if (hasOwn(argsOption, key)) {
let keyOption = argsOption[key]; let keyOption = argsOption[key];
if (isFn(keyOption)) { if (isFn(keyOption)) {
...@@ -267,9 +438,11 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) { ...@@ -267,9 +438,11 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) {
} else if (CALLBACKS.includes(key)) { } else if (CALLBACKS.includes(key)) {
toArgs[key] = processCallback(methodName, fromArgs[key], returnValue); toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
} else { } else {
if (!keepFromArgs) {
toArgs[key] = fromArgs[key]; toArgs[key] = fromArgs[key];
} }
}); }
}
return toArgs return toArgs
} else if (isFn(fromArgs)) { } else if (isFn(fromArgs)) {
fromArgs = processCallback(methodName, fromArgs, returnValue); fromArgs = processCallback(methodName, fromArgs, returnValue);
...@@ -277,11 +450,11 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) { ...@@ -277,11 +450,11 @@ function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}) {
return fromArgs return fromArgs
} }
function processReturnValue (methodName, res, returnValue) { function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
if (isFn(protocols.returnValue)) { // 处理通用 returnValue if (isFn(protocols.returnValue)) { // 处理通用 returnValue
res = protocols.returnValue(methodName, res); res = protocols.returnValue(methodName, res);
} }
return processArgs(methodName, res, returnValue) return processArgs(methodName, res, returnValue, {}, keepReturnValue)
} }
function wrapper (methodName, method) { function wrapper (methodName, method) {
...@@ -302,7 +475,7 @@ function wrapper (methodName, method) { ...@@ -302,7 +475,7 @@ function wrapper (methodName, method) {
const returnValue = my[options.name || methodName](arg1, arg2); const returnValue = my[options.name || methodName](arg1, arg2);
if (isSyncApi(methodName)) { // 同步 api if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue) return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
} }
return returnValue return returnValue
} }
......
{ {
"name": "@dcloudio/uni-mp-alipay", "name": "@dcloudio/uni-mp-alipay",
"version": "0.0.2", "version": "0.0.3",
"description": "uni-app mp-alipay", "description": "uni-app mp-alipay",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -135,7 +135,9 @@ const protocols = { ...@@ -135,7 +135,9 @@ const protocols = {
// data 不支持 ArrayBuffer // data 不支持 ArrayBuffer
// method 不支持 TRACE, CONNECT // method 不支持 TRACE, CONNECT
// dataType 可取值为 string/json // dataType 可取值为 string/json
return fromArgs return {
method: 'method'
}
} }
}, },
connectSocket: { connectSocket: {
...@@ -160,20 +162,12 @@ const protocols = { ...@@ -160,20 +162,12 @@ const protocols = {
fromRet.onNext = createTodoMethod('BackgroundAudioManager', 'onNext'); fromRet.onNext = createTodoMethod('BackgroundAudioManager', 'onNext');
} }
}, },
createInnerAudioContext: {
returnValue: {
buffered: false
}
},
createVideoContext: {
returnValue: {
playbackRate: false
}
},
scanCode: { scanCode: {
args: {
onlyFromCamera: false, onlyFromCamera: false,
scanType: false scanType: false
} }
}
}; };
TODOS.forEach(todoApi => { TODOS.forEach(todoApi => {
......
{ {
"name": "@dcloudio/uni-mp-baidu", "name": "@dcloudio/uni-mp-baidu",
"version": "0.0.2", "version": "0.0.3",
"description": "uni-app mp-baidu", "description": "uni-app mp-baidu",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册