Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
anyefeiyu
uni-app
提交
177f182f
U
uni-app
项目概览
anyefeiyu
/
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,发现更多精彩内容 >>
提交
177f182f
编写于
11月 01, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(v3): webview event
上级
555262a2
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
398 addition
and
166 deletion
+398
-166
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+266
-63
src/platforms/app-plus/service/framework/app.js
src/platforms/app-plus/service/framework/app.js
+7
-4
src/platforms/app-plus/service/framework/webview/index.js
src/platforms/app-plus/service/framework/webview/index.js
+38
-99
src/platforms/app-plus/service/framework/webview/on-webview-close.js
...ms/app-plus/service/framework/webview/on-webview-close.js
+14
-0
src/platforms/app-plus/service/framework/webview/on-webview-recovery.js
...app-plus/service/framework/webview/on-webview-recovery.js
+38
-0
src/platforms/app-plus/service/framework/webview/on-webview-resize.js
...s/app-plus/service/framework/webview/on-webview-resize.js
+26
-0
src/shared/util.js
src/shared/util.js
+9
-0
未找到文件。
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
177f182f
...
...
@@ -280,6 +280,15 @@ var serviceContext = (function () {
return
Math
.
floor
(
4294967296
*
(
1
+
Math
.
random
())).
toString
(
16
).
slice
(
1
)
}
function
debounce
(
fn
,
delay
)
{
let
timeout
;
return
function
()
{
clearTimeout
(
timeout
);
const
timerFn
=
()
=>
fn
.
apply
(
this
,
arguments
);
timeout
=
setTimeout
(
timerFn
,
delay
);
}
}
const
decode
=
decodeURIComponent
;
function
parseQuery
(
query
)
{
...
...
@@ -6409,6 +6418,31 @@ var serviceContext = (function () {
}
}
const
REGEX_UPX
=
/
(\d
+
(\.\d
+
)?)[
r|u
]
px/g
;
function
transformCSS
(
css
)
{
return
css
.
replace
(
REGEX_UPX
,
(
a
,
b
)
=>
{
return
uni
.
upx2px
(
parseInt
(
b
)
||
0
)
+
'
px
'
})
}
function
parseStyleUnit
(
styles
)
{
let
newStyles
=
{};
const
stylesStr
=
JSON
.
stringify
(
styles
);
if
(
~
stylesStr
.
indexOf
(
'
upx
'
)
||
~
stylesStr
.
indexOf
(
'
rpx
'
))
{
try
{
newStyles
=
JSON
.
parse
(
transformCSS
(
stylesStr
));
}
catch
(
e
)
{
newStyles
=
styles
;
console
.
error
(
e
);
}
}
else
{
newStyles
=
JSON
.
parse
(
stylesStr
);
}
return
newStyles
}
const
WEBVIEW_STYLE_BLACKLIST
=
[
'
navigationBarBackgroundColor
'
,
'
navigationBarTextStyle
'
,
...
...
@@ -6430,10 +6464,10 @@ var serviceContext = (function () {
const
webviewStyle
=
Object
.
create
(
null
);
// 合并
routeOptions
.
window
=
Object
.
assign
(
routeOptions
.
window
=
parseStyleUnit
(
Object
.
assign
(
JSON
.
parse
(
JSON
.
stringify
(
__uniConfig
.
window
||
{})),
routeOptions
.
window
||
{}
);
)
)
;
Object
.
keys
(
routeOptions
.
window
).
forEach
(
name
=>
{
if
(
WEBVIEW_STYLE_BLACKLIST
.
indexOf
(
name
)
===
-
1
)
{
...
...
@@ -6475,62 +6509,157 @@ var serviceContext = (function () {
return
webviewStyle
}
const
PAGE_CREATE
=
2
;
const
MOUNTED_DATA
=
4
;
const
UPDATED_DATA
=
6
;
const
PAGE_CREATED
=
10
;
function
backbuttonListener
()
{
uni
.
navigateBack
({
from
:
'
backbutton
'
});
}
const
UI_EVENT
=
20
;
function
initPopupSubNVue
(
subNVueWebview
,
style
,
maskWebview
)
{
if
(
!
maskWebview
.
popupSubNVueWebviews
)
{
maskWebview
.
popupSubNVueWebviews
=
{};
}
const
VD_SYNC
=
'
vdSync
'
;
maskWebview
.
popupSubNVueWebviews
[
subNVueWebview
.
id
]
=
subNVueWebview
;
const
WEBVIEW_READY
=
'
webviewReady
'
;
const
VD_SYNC_CALLBACK
=
'
vdSyncCallback
'
;
const
INVOKE_API
=
'
invokeApi
'
;
const
WEB_INVOKE_APPSERVICE$1
=
'
WEB_INVOKE_APPSERVICE
'
;
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
maskWebview
.
id
}
]:add.popupSubNVueWebview[
${
subNVueWebview
.
id
}
]`
);
}
let
preloadWebview
;
const
hideSubNVue
=
function
()
{
maskWebview
.
setStyle
({
mask
:
'
none
'
});
subNVueWebview
.
hide
(
'
auto
'
);
};
maskWebview
.
addEventListener
(
'
maskClick
'
,
hideSubNVue
);
let
isRemoved
=
false
;
// 增加个 remove 标记,防止出错
subNVueWebview
.
addEventListener
(
'
show
'
,
()
=>
{
if
(
!
isRemoved
)
{
plus
.
key
.
removeEventListener
(
'
backbutton
'
,
backbuttonListener
);
plus
.
key
.
addEventListener
(
'
backbutton
'
,
hideSubNVue
);
isRemoved
=
true
;
}
});
subNVueWebview
.
addEventListener
(
'
hide
'
,
()
=>
{
if
(
isRemoved
)
{
plus
.
key
.
removeEventListener
(
'
backbutton
'
,
hideSubNVue
);
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
);
isRemoved
=
false
;
}
});
subNVueWebview
.
addEventListener
(
'
close
'
,
()
=>
{
delete
maskWebview
.
popupSubNVueWebviews
[
subNVueWebview
.
id
];
if
(
isRemoved
)
{
plus
.
key
.
removeEventListener
(
'
backbutton
'
,
hideSubNVue
);
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
);
isRemoved
=
false
;
}
});
}
let
id
=
2
;
function
initNormalSubNVue
(
subNVueWebview
,
style
,
webview
)
{
webview
.
append
(
subNVueWebview
);
}
const
WEBVIEW_LISTENERS
=
{
'
pullToRefresh
'
:
'
onPullDownRefresh
'
,
'
titleNViewSearchInputChanged
'
:
'
onNavigationBarSearchInputChanged
'
,
'
titleNViewSearchInputConfirmed
'
:
'
onNavigationBarSearchInputConfirmed
'
,
'
titleNViewSearchInputClicked
'
:
'
onNavigationBarSearchInputClicked
'
function
initSubNVue
(
subNVue
,
routeOptions
,
webview
)
{
if
(
!
subNVue
.
path
)
{
return
}
const
style
=
subNVue
.
style
||
{};
const
isNavigationBar
=
subNVue
.
type
===
'
navigationBar
'
;
const
isPopup
=
subNVue
.
type
===
'
popup
'
;
delete
style
.
type
;
if
(
isPopup
&&
!
subNVue
.
id
)
{
console
.
warn
(
'
subNVue[
'
+
subNVue
.
path
+
'
] 尚未配置 id
'
);
}
// TODO lazyload
style
.
uniNView
=
{
path
:
subNVue
.
path
.
replace
(
'
.nvue
'
,
'
.js
'
),
defaultFontSize
:
__uniConfig
.
defaultFontSize
,
viewport
:
__uniConfig
.
viewport
};
function
setPreloadWebview
(
webview
)
{
preloadWebview
=
webview
;
const
extras
=
{
__uniapp_host
:
routeOptions
.
path
,
__uniapp_origin
:
style
.
uniNView
.
path
.
split
(
'
?
'
)[
0
].
replace
(
'
.js
'
,
''
),
__uniapp_origin_id
:
webview
.
id
,
__uniapp_origin_type
:
webview
.
__uniapp_type
};
let
maskWebview
;
if
(
isNavigationBar
)
{
style
.
position
=
'
dock
'
;
style
.
dock
=
'
top
'
;
style
.
top
=
0
;
style
.
width
=
'
100%
'
;
style
.
height
=
TITLEBAR_HEIGHT
+
plus
.
navigator
.
getStatusbarHeight
();
delete
style
.
left
;
delete
style
.
right
;
delete
style
.
bottom
;
delete
style
.
margin
;
}
else
if
(
isPopup
)
{
style
.
position
=
'
absolute
'
;
console
.
log
(
isTabBarPage
(
routeOptions
.
path
));
if
(
isTabBarPage
(
routeOptions
.
path
))
{
maskWebview
=
tabBar$1
;
}
else
{
maskWebview
=
webview
;
}
extras
.
__uniapp_mask
=
style
.
mask
||
'
rgba(0,0,0,0.5)
'
;
extras
.
__uniapp_mask_id
=
maskWebview
.
id
;
}
function
createWebview
(
path
,
routeOptions
)
{
if
(
routeOptions
.
meta
.
isNVue
)
{
const
webviewId
=
id
++
;
const
webviewStyle
=
parseWebviewStyle
(
webviewId
,
path
,
routeOptions
);
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] createWebview`
,
webviewId
,
path
,
webviewStyle
);
console
.
log
(
`UNIAPP[webview][
${
webview
.
id
}
]:create[
${
subNVue
.
id
}
]:
${
JSON
.
stringify
(
style
)}
`
);
}
return
plus
.
webview
.
create
(
''
,
String
(
webviewId
),
webviewStyle
,
{
nvue
:
true
})
const
subNVueWebview
=
plus
.
webview
.
create
(
''
,
subNVue
.
id
,
style
,
extras
);
if
(
isPopup
)
{
initPopupSubNVue
(
subNVueWebview
,
style
,
maskWebview
);
}
else
{
initNormalSubNVue
(
subNVueWebview
,
style
,
webview
);
}
if
(
id
===
2
)
{
// 如果首页非 nvue,则直接返回 Launch Webview
return
plus
.
webview
.
getLaunchWebview
()
}
const
webview
=
preloadWebview
;
return
webview
function
initSubNVues
(
routeOptions
,
webview
)
{
const
subNVues
=
routeOptions
.
window
.
subNVues
;
if
(
!
subNVues
||
!
subNVues
.
length
)
{
return
}
subNVues
.
forEach
(
subNVue
=>
{
initSubNVue
(
subNVue
,
routeOptions
,
webview
);
});
}
function
onWebviewClose
(
webview
)
{
webview
.
addEventListener
(
'
close
'
,
()
=>
{
if
(
webview
.
popupSubNVueWebviews
)
{
// 移除所有 popupSubNVueWebview
Object
.
keys
(
webview
.
popupSubNVueWebviews
).
forEach
(
id
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
webview
.
id
}
]:popupSubNVueWebview[
${
id
}
].close`
);
}
webview
.
popupSubNVueWebviews
[
id
].
close
(
'
none
'
);
});
}
});
}
function
onWebviewResize
(
webview
)
{
webview
.
addEventListener
(
'
resize
'
,
({
const
onResize
=
function
({
width
,
height
})
=>
{
})
{
const
landscape
=
Math
.
abs
(
plus
.
navigator
.
getOrientation
())
===
90
;
const
res
=
{
deviceOrientation
:
landscape
?
'
landscape
'
:
'
portrait
'
,
...
...
@@ -6541,9 +6670,24 @@ var serviceContext = (function () {
};
publish
(
'
onViewDidResize
'
,
res
);
// API
UniServiceJSBridge
.
emit
(
'
onResize
'
,
res
,
parseInt
(
webview
.
id
));
// Page lifecycle
});
};
webview
.
addEventListener
(
'
resize
'
,
debounce
(
onResize
,
50
));
}
const
PAGE_CREATE
=
2
;
const
MOUNTED_DATA
=
4
;
const
UPDATED_DATA
=
6
;
const
PAGE_CREATED
=
10
;
const
UI_EVENT
=
20
;
const
VD_SYNC
=
'
vdSync
'
;
const
WEBVIEW_READY
=
'
webviewReady
'
;
const
VD_SYNC_CALLBACK
=
'
vdSyncCallback
'
;
const
INVOKE_API
=
'
invokeApi
'
;
const
WEB_INVOKE_APPSERVICE$1
=
'
WEB_INVOKE_APPSERVICE
'
;
function
onWebviewRecovery
(
webview
,
routeOptions
)
{
const
{
subscribe
,
...
...
@@ -6579,6 +6723,43 @@ var serviceContext = (function () {
});
}
let
preloadWebview
;
let
id
=
2
;
const
WEBVIEW_LISTENERS
=
{
'
pullToRefresh
'
:
'
onPullDownRefresh
'
,
'
titleNViewSearchInputChanged
'
:
'
onNavigationBarSearchInputChanged
'
,
'
titleNViewSearchInputConfirmed
'
:
'
onNavigationBarSearchInputConfirmed
'
,
'
titleNViewSearchInputClicked
'
:
'
onNavigationBarSearchInputClicked
'
};
function
setPreloadWebview
(
webview
)
{
preloadWebview
=
webview
;
}
function
createWebview
(
path
,
routeOptions
)
{
if
(
routeOptions
.
meta
.
isNVue
)
{
const
webviewId
=
id
++
;
const
webviewStyle
=
parseWebviewStyle
(
webviewId
,
path
,
routeOptions
);
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] createWebview`
,
webviewId
,
path
,
webviewStyle
);
}
return
plus
.
webview
.
create
(
''
,
String
(
webviewId
),
webviewStyle
,
{
nvue
:
true
})
}
if
(
id
===
2
)
{
// 如果首页非 nvue,则直接返回 Launch Webview
return
plus
.
webview
.
getLaunchWebview
()
}
const
webview
=
preloadWebview
;
return
webview
}
function
initWebview
(
webview
,
routeOptions
)
{
// 首页或非 nvue 页面
if
(
webview
.
id
===
'
1
'
||
!
routeOptions
.
meta
.
isNVue
)
{
...
...
@@ -6599,20 +6780,43 @@ var serviceContext = (function () {
emit
}
=
UniServiceJSBridge
;
// TODO subNVues
initSubNVues
(
routeOptions
,
webview
);
// TODO 优化相关依赖性
// webview.addEventListener('popGesture', e => {
// if (e.type === 'start') {
// // 开始拖拽,还原状态栏前景色
// this.restoreStatusBarStyle()
// } else if (e.type === 'end' && !e.result) {
// // 拖拽未完成,设置为当前状态栏前景色
// this.setStatusBarStyle()
// } else if (e.type === 'end' && e.result) {
// removeWebview(this.id)
// const lastWebview = getLastWebview()
// if (lastWebview) {
// publish('onAppRoute', {
// path: lastWebview.page.replace('.html', ''),
// query: {},
// openType: 'navigateBack',
// webviewId: lastWebview.id
// })
// }
// }
// })
Object
.
keys
(
WEBVIEW_LISTENERS
).
forEach
(
name
=>
{
webview
.
addEventListener
(
name
,
(
e
)
=>
{
emit
(
WEBVIEW_LISTENERS
[
name
],
e
,
parseInt
(
webview
.
id
));
});
});
onWebviewClose
(
webview
);
onWebviewResize
(
webview
);
if
(
plus
.
os
.
name
===
'
iOS
'
&&
webview
.
nvue
)
{
onWebviewRecovery
(
webview
,
routeOptions
);
}
// TODO 应该结束之前未完成的下拉刷新
on
(
webview
.
id
+
'
.startPullDownRefresh
'
,
()
=>
{
webview
.
beginPullToRefresh
();
});
...
...
@@ -9726,10 +9930,9 @@ var serviceContext = (function () {
function
initGlobalListeners
()
{
const
emit
=
UniServiceJSBridge
.
emit
;
plus
.
key
.
addEventListener
(
'
backbutton
'
,
()
=>
{
uni
.
navigateBack
({
from
:
'
backbutton
'
});
// splashclosed 时开始监听 backbutton
plus
.
globalEvent
.
addEventListener
(
'
splashclosed
'
,
()
=>
{
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
);
});
plus
.
globalEvent
.
addEventListener
(
'
pause
'
,
()
=>
{
...
...
src/platforms/app-plus/service/framework/app.js
浏览文件 @
177f182f
...
...
@@ -43,7 +43,10 @@ export function getApp () {
function
initGlobalListeners
()
{
const
emit
=
UniServiceJSBridge
.
emit
// splashclosed 时开始监听 backbutton
plus
.
globalEvent
.
addEventListener
(
'
splashclosed
'
,
()
=>
{
plus
.
key
.
addEventListener
(
'
backbutton
'
,
backbuttonListener
)
})
plus
.
globalEvent
.
addEventListener
(
'
pause
'
,
()
=>
{
emit
(
'
onAppEnterBackground
'
)
...
...
src/platforms/app-plus/service/framework/webview/index.js
浏览文件 @
177f182f
...
...
@@ -6,17 +6,21 @@ import {
initSubNVues
}
from
'
./parser/sub-nvue-parser
'
import
{
publish
}
from
'
../../bridge
'
import
{
VIEW_WEBVIEW_PATH
}
from
'
../../constants
'
import
{
WEBVIEW_READY
}
from
'
../../../constants
'
onWebviewClose
}
from
'
./on-webview-close
'
import
{
onWebviewResize
}
from
'
./on-webview-resize
'
import
{
onWebviewRecovery
}
from
'
./on-webview-recovery
'
export
let
preloadWebview
...
...
@@ -55,59 +59,6 @@ export function createWebview (path, routeOptions) {
return
webview
}
function
onWebviewResize
(
webview
)
{
webview
.
addEventListener
(
'
resize
'
,
({
width
,
height
})
=>
{
const
landscape
=
Math
.
abs
(
plus
.
navigator
.
getOrientation
())
===
90
const
res
=
{
deviceOrientation
:
landscape
?
'
landscape
'
:
'
portrait
'
,
size
:
{
windowWidth
:
Math
.
ceil
(
width
),
windowHeight
:
Math
.
ceil
(
height
)
}
}
publish
(
'
onViewDidResize
'
,
res
)
// API
UniServiceJSBridge
.
emit
(
'
onResize
'
,
res
,
parseInt
(
webview
.
id
))
// Page lifecycle
})
}
function
onWebviewRecovery
(
webview
,
routeOptions
)
{
const
{
subscribe
,
unsubscribe
}
=
UniServiceJSBridge
const
id
=
webview
.
id
const
onWebviewRecoveryReady
=
function
(
data
,
pageId
)
{
if
(
id
!==
pageId
)
{
return
}
unsubscribe
(
WEBVIEW_READY
,
onWebviewRecoveryReady
)
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
this
.
id
}
]:onWebviewRecoveryReady ready`
)
}
// 恢复目标页面
pageId
=
parseInt
(
pageId
)
const
page
=
getCurrentPages
(
true
).
find
(
page
=>
page
.
$page
.
id
===
pageId
)
if
(
!
page
)
{
return
console
.
error
(
`Page[
${
pageId
}
] not found`
)
}
page
.
$vm
.
_$vd
.
restore
()
}
webview
.
addEventListener
(
'
recovery
'
,
e
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
this
.
id
}
].recovery.reload:`
+
JSON
.
stringify
({
path
:
routeOptions
.
path
,
webviewId
:
id
}))
}
subscribe
(
WEBVIEW_READY
,
onWebviewRecoveryReady
)
})
}
export
function
initWebview
(
webview
,
routeOptions
)
{
// 首页或非 nvue 页面
if
(
webview
.
id
===
'
1
'
||
!
routeOptions
.
meta
.
isNVue
)
{
...
...
@@ -152,25 +103,13 @@ export function initWebview (webview, routeOptions) {
// }
// })
webview
.
addEventListener
(
'
close
'
,
()
=>
{
if
(
webview
.
popupSubNVueWebviews
)
{
// 移除所有 popupSubNVueWebview
Object
.
keys
(
webview
.
popupSubNVueWebviews
).
forEach
(
id
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
webview
.
id
}
]:popupSubNVueWebview[
${
id
}
].close`
)
}
webview
.
popupSubNVueWebviews
[
id
].
close
(
'
none
'
)
})
}
})
Object
.
keys
(
WEBVIEW_LISTENERS
).
forEach
(
name
=>
{
webview
.
addEventListener
(
name
,
(
e
)
=>
{
emit
(
WEBVIEW_LISTENERS
[
name
],
e
,
parseInt
(
webview
.
id
))
})
})
onWebviewClose
(
webview
)
onWebviewResize
(
webview
)
if
(
plus
.
os
.
name
===
'
iOS
'
&&
webview
.
nvue
)
{
...
...
src/platforms/app-plus/service/framework/webview/on-webview-close.js
0 → 100644
浏览文件 @
177f182f
export
function
onWebviewClose
(
webview
)
{
webview
.
addEventListener
(
'
close
'
,
()
=>
{
if
(
webview
.
popupSubNVueWebviews
)
{
// 移除所有 popupSubNVueWebview
Object
.
keys
(
webview
.
popupSubNVueWebviews
).
forEach
(
id
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
webview
.
id
}
]:popupSubNVueWebview[
${
id
}
].close`
)
}
webview
.
popupSubNVueWebviews
[
id
].
close
(
'
none
'
)
})
}
})
}
src/platforms/app-plus/service/framework/webview/on-webview-recovery.js
0 → 100644
浏览文件 @
177f182f
import
{
WEBVIEW_READY
}
from
'
../../../constants
'
export
function
onWebviewRecovery
(
webview
,
routeOptions
)
{
const
{
subscribe
,
unsubscribe
}
=
UniServiceJSBridge
const
id
=
webview
.
id
const
onWebviewRecoveryReady
=
function
(
data
,
pageId
)
{
if
(
id
!==
pageId
)
{
return
}
unsubscribe
(
WEBVIEW_READY
,
onWebviewRecoveryReady
)
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
this
.
id
}
]:onWebviewRecoveryReady ready`
)
}
// 恢复目标页面
pageId
=
parseInt
(
pageId
)
const
page
=
getCurrentPages
(
true
).
find
(
page
=>
page
.
$page
.
id
===
pageId
)
if
(
!
page
)
{
return
console
.
error
(
`Page[
${
pageId
}
] not found`
)
}
page
.
$vm
.
_$vd
.
restore
()
}
webview
.
addEventListener
(
'
recovery
'
,
e
=>
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[webview][
${
this
.
id
}
].recovery.reload:`
+
JSON
.
stringify
({
path
:
routeOptions
.
path
,
webviewId
:
id
}))
}
subscribe
(
WEBVIEW_READY
,
onWebviewRecoveryReady
)
})
}
src/platforms/app-plus/service/framework/webview/on-webview-resize.js
0 → 100644
浏览文件 @
177f182f
import
{
debounce
}
from
'
uni-shared
'
import
{
publish
}
from
'
../../bridge
'
export
function
onWebviewResize
(
webview
)
{
const
onResize
=
function
({
width
,
height
})
{
const
landscape
=
Math
.
abs
(
plus
.
navigator
.
getOrientation
())
===
90
const
res
=
{
deviceOrientation
:
landscape
?
'
landscape
'
:
'
portrait
'
,
size
:
{
windowWidth
:
Math
.
ceil
(
width
),
windowHeight
:
Math
.
ceil
(
height
)
}
}
publish
(
'
onViewDidResize
'
,
res
)
// API
UniServiceJSBridge
.
emit
(
'
onResize
'
,
res
,
parseInt
(
webview
.
id
))
// Page lifecycle
}
webview
.
addEventListener
(
'
resize
'
,
debounce
(
onResize
,
50
))
}
src/shared/util.js
浏览文件 @
177f182f
...
...
@@ -79,3 +79,12 @@ export function updateElementStyle (element, styles) {
export
function
guid
()
{
return
Math
.
floor
(
4294967296
*
(
1
+
Math
.
random
())).
toString
(
16
).
slice
(
1
)
}
export
function
debounce
(
fn
,
delay
)
{
let
timeout
return
function
()
{
clearTimeout
(
timeout
)
const
timerFn
=
()
=>
fn
.
apply
(
this
,
arguments
)
timeout
=
setTimeout
(
timerFn
,
delay
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录