Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
16da3b7b
U
uni-app
项目概览
ChenYFan_OHHH
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
16da3b7b
编写于
12月 12, 2018
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持配置 context,manager 类型 api 转换
上级
3ee221ef
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
156 addition
and
139 deletion
+156
-139
packages/uni-mp-baidu/dist/index.js
packages/uni-mp-baidu/dist/index.js
+76
-68
src/core/helpers/promise.js
src/core/helpers/promise.js
+5
-0
src/core/runtime/wrapper.js
src/core/runtime/wrapper.js
+12
-9
src/platforms/mp-baidu/service/api/protocols.js
src/platforms/mp-baidu/service/api/protocols.js
+63
-62
未找到文件。
packages/uni-mp-baidu/dist/index.js
浏览文件 @
16da3b7b
...
...
@@ -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,66 +117,67 @@ function upx2px (number, newDeviceWidth) {
return
number
}
// 不支持的 API 列表
const
TODOS
=
[
'
hideKeyboard
'
];
// 需要做转换的 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
:
{
onFrameRecorded
:
false
// TODO start 方法的参数有差异,暂时没有提供配置处理。
}
},
getBackgroundAudioManager
:
{
returnValue
:
{
buffered
:
false
,
webUrl
:
false
,
protocol
:
false
,
onPrev
:
false
,
onNext
:
false
}
},
createInnerAudioContext
:
{
returnValue
:
{
buffered
:
false
}
},
createVideoContext
:
{
returnValue
:
{
playbackRate
:
false
}
},
scanCode
:
{
onlyFromCamera
:
false
,
scanType
:
false
}
};
TODOS
.
forEach
(
todoApi
=>
{
protocols
[
todoApi
]
=
false
;
// 不支持的 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
'
];
...
...
@@ -182,13 +188,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
))
{
...
...
@@ -204,9 +210,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
);
...
...
@@ -214,11 +222,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
)
}
function
wrapper
(
methodName
,
method
)
{
...
...
@@ -239,7 +247,7 @@ function wrapper (methodName, method) {
const
returnValue
=
swan
[
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
}
...
...
src/core/helpers/promise.js
浏览文件 @
16da3b7b
...
...
@@ -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
)
}
...
...
src/core/runtime/wrapper.js
浏览文件 @
16da3b7b
...
...
@@ -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
}
...
...
src/platforms/mp-baidu/service/api/protocols.js
浏览文件 @
16da3b7b
// 不支持的 API 列表
const
TODOS
=
[
'
hideKeyboard
'
]
// 需要做转换的 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
:
{
onFrameRecorded
:
false
// TODO start 方法的参数有差异,暂时没有提供配置处理。
}
},
getBackgroundAudioManager
:
{
returnValue
:
{
buffered
:
false
,
webUrl
:
false
,
protocol
:
false
,
onPrev
:
false
,
onNext
:
false
}
},
createInnerAudioContext
:
{
returnValue
:
{
buffered
:
false
}
},
createVideoContext
:
{
returnValue
:
{
playbackRate
:
false
}
},
scanCode
:
{
onlyFromCamera
:
false
,
scanType
:
false
}
}
TODOS
.
forEach
(
todoApi
=>
{
protocols
[
todoApi
]
=
false
})
// 不支持的 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
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
})
export
default
protocols
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录