Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
550533bf
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
717
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
550533bf
编写于
12月 12, 2018
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复页面返回时,getCurrentPages 可能获取到上个页面
上级
cfba7df7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
102 addition
and
26 deletion
+102
-26
packages/uni-mp-baidu/dist/index.js
packages/uni-mp-baidu/dist/index.js
+89
-23
src/core/service/plugins/app/create-app.js
src/core/service/plugins/app/create-app.js
+12
-2
src/platforms/mp-baidu/service/api/protocols.js
src/platforms/mp-baidu/service/api/protocols.js
+1
-1
未找到文件。
packages/uni-mp-baidu/dist/index.js
浏览文件 @
550533bf
...
...
@@ -112,68 +112,134 @@ function upx2px (number, newDeviceWidth) {
return
number
}
var
protocols
=
{};
// 不支持的 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
;
});
const
CALLBACKS
=
[
'
success
'
,
'
fail
'
,
'
cancel
'
,
'
complete
'
];
function
processCallback
(
method
,
returnValue
)
{
function
processCallback
(
method
Name
,
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
=
{})
{
if
(
isPlainObject
(
fromArgs
))
{
// 一般 api 的参数解析
const
toArgs
=
{};
if
(
isFn
(
argsOption
))
{
argsOption
=
argsOption
(
fromArgs
,
toArgs
)
||
{};
}
Object
.
keys
(
fromArgs
).
forEach
(
key
=>
{
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
(
`
${
百度小程序
}
${
n
ame
}
暂不支持
${
key
}
`
);
console
.
warn
(
`
百度小程序
${
methodN
ame
}
暂不支持
${
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
];
}
});
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
)
{
if
(
isFn
(
protocols
.
returnValue
))
{
// 处理通用 returnValue
res
=
protocols
.
returnValue
(
methodName
,
res
);
}
return
processArgs
(
methodName
,
res
,
returnValue
)
}
function
wrapper
(
n
ame
,
method
)
{
if
(
hasOwn
(
protocols
,
n
ame
))
{
const
protocol
=
protocols
[
n
ame
];
function
wrapper
(
methodN
ame
,
method
)
{
if
(
hasOwn
(
protocols
,
methodN
ame
))
{
const
protocol
=
protocols
[
methodN
ame
];
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
||
n
ame
](
arg1
,
arg2
);
if
(
isSyncApi
(
n
ame
))
{
// 同步 api
return
processReturnValue
(
returnValue
,
options
.
returnValue
)
const
returnValue
=
swan
[
options
.
name
||
methodN
ame
](
arg1
,
arg2
);
if
(
isSyncApi
(
methodN
ame
))
{
// 同步 api
return
processReturnValue
(
methodName
,
returnValue
,
options
.
returnValue
)
}
return
returnValue
}
...
...
@@ -183,7 +249,7 @@ function wrapper (name, method) {
const
todoApis
=
Object
.
create
(
null
);
const
TODOS
=
[
const
TODOS
$1
=
[
'
subscribePush
'
,
'
unsubscribePush
'
,
'
onPush
'
,
...
...
@@ -204,7 +270,7 @@ function createTodoApi (name) {
}
}
TODOS
.
forEach
(
function
(
name
)
{
TODOS
$1
.
forEach
(
function
(
name
)
{
todoApis
[
name
]
=
createTodoApi
(
name
);
});
...
...
@@ -265,7 +331,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 +353,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
]));
}
});
...
...
src/core/service/plugins/app/create-app.js
浏览文件 @
550533bf
...
...
@@ -8,10 +8,11 @@ export function getApp () {
export
function
getCurrentPages
(
isAll
=
false
)
{
const
pages
=
[]
const
childrenVm
=
appVm
.
$children
[
0
]
const
app
=
getApp
()
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 +40,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
}
...
...
src/platforms/mp-baidu/service/api/protocols.js
浏览文件 @
550533bf
// 不支持的 API 列表
const
TODOS
=
[
'
hideKeyboard
'
'
hideKeyboard
'
]
// 需要做转换的 API 列表
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录