Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
9550e4b5
U
uni-app
项目概览
小浣熊撸代码
/
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,发现更多精彩内容 >>
提交
9550e4b5
编写于
7月 30, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): preloadPage、unPreloadPage
上级
daa52d3c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
163 addition
and
7 deletion
+163
-7
packages/uni-app-plus/src/service/api/index.ts
packages/uni-app-plus/src/service/api/index.ts
+1
-0
packages/uni-app-plus/src/service/api/route/preloadPage.ts
packages/uni-app-plus/src/service/api/route/preloadPage.ts
+56
-0
packages/uni-app-plus/src/service/api/route/redirectTo.ts
packages/uni-app-plus/src/service/api/route/redirectTo.ts
+7
-4
packages/uni-app-plus/src/service/framework/page/preLoad.ts
packages/uni-app-plus/src/service/framework/page/preLoad.ts
+68
-0
packages/uni-app-plus/src/service/framework/page/register.ts
packages/uni-app-plus/src/service/framework/page/register.ts
+31
-3
未找到文件。
packages/uni-app-plus/src/service/api/index.ts
浏览文件 @
9550e4b5
...
@@ -66,6 +66,7 @@ export * from './route/navigateTo'
...
@@ -66,6 +66,7 @@ export * from './route/navigateTo'
export
*
from
'
./route/redirectTo
'
export
*
from
'
./route/redirectTo
'
export
*
from
'
./route/reLaunch
'
export
*
from
'
./route/reLaunch
'
export
*
from
'
./route/switchTab
'
export
*
from
'
./route/switchTab
'
export
*
from
'
./route/preloadPage
'
export
{
export
{
upx2px
,
upx2px
,
...
...
packages/uni-app-plus/src/service/api/route/preloadPage.ts
0 → 100644
浏览文件 @
9550e4b5
import
{
parseQuery
}
from
'
@dcloudio/uni-shared
'
import
{
API_PRELOAD_PAGE
,
API_TYPE_PRELOAD_PAGE
,
PreloadPageProtocol
,
API_UN_PRELOAD_PAGE
,
API_TYPE_UN_PRELOAD_PAGE
,
UnPreloadPageProtocol
,
defineAsyncApi
,
defineSyncApi
,
}
from
'
@dcloudio/uni-api
'
import
{
preloadWebview
,
closePreloadWebview
,
}
from
'
../../framework/page/preLoad
'
export
const
unPreloadPage
=
defineSyncApi
<
API_TYPE_UN_PRELOAD_PAGE
>
(
API_UN_PRELOAD_PAGE
,
({
url
})
=>
{
const
webview
=
closePreloadWebview
({
url
,
})
if
(
webview
)
{
return
{
id
:
webview
.
id
,
url
,
errMsg
:
'
unPreloadPage:ok
'
,
}
}
return
{
url
,
errMsg
:
'
unPreloadPage:fail not found
'
,
}
},
UnPreloadPageProtocol
)
export
const
preloadPage
=
defineAsyncApi
<
API_TYPE_PRELOAD_PAGE
>
(
API_PRELOAD_PAGE
,
({
url
},
{
resolve
,
reject
})
=>
{
const
urls
=
url
.
split
(
'
?
'
)
const
path
=
urls
[
0
]
const
query
=
parseQuery
(
urls
[
1
]
||
''
)
const
webview
=
preloadWebview
({
url
,
path
,
query
,
})
resolve
({
id
:
webview
.
id
,
url
,
errMsg
:
'
preloadPage:ok
'
,
})
},
PreloadPageProtocol
)
packages/uni-app-plus/src/service/api/route/redirectTo.ts
浏览文件 @
9550e4b5
...
@@ -13,6 +13,10 @@ import { navigate, RouteOptions } from './utils'
...
@@ -13,6 +13,10 @@ import { navigate, RouteOptions } from './utils'
import
{
showWebview
}
from
'
./webview
'
import
{
showWebview
}
from
'
./webview
'
import
{
setStatusBarStyle
}
from
'
../../statusBar
'
import
{
setStatusBarStyle
}
from
'
../../statusBar
'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
removePreloadWebview
,
PreloadWebviewObject
,
}
from
'
../../framework/page/preLoad
'
export
const
redirectTo
=
defineAsyncApi
<
API_TYPE_REDIRECT_TO
>
(
export
const
redirectTo
=
defineAsyncApi
<
API_TYPE_REDIRECT_TO
>
(
API_REDIRECT_TO
,
API_REDIRECT_TO
,
...
@@ -73,10 +77,9 @@ function _redirectTo({
...
@@ -73,10 +77,9 @@ function _redirectTo({
if
(
lastPage
)
{
if
(
lastPage
)
{
const
webview
=
(
lastPage
as
ComponentPublicInstance
)
const
webview
=
(
lastPage
as
ComponentPublicInstance
)
.
$getAppWebview
!
()
.
$getAppWebview
!
()
// TODO preload
if
((
webview
as
PreloadWebviewObject
).
__preload__
)
{
// if (webview.__preload__) {
removePreloadWebview
(
webview
)
// removePreloadWebview(webview)
}
// }
webview
.
close
(
'
none
'
)
webview
.
close
(
'
none
'
)
}
}
resolve
(
undefined
)
resolve
(
undefined
)
...
...
packages/uni-app-plus/src/service/framework/page/preLoad.ts
0 → 100644
浏览文件 @
9550e4b5
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
createWebview
}
from
'
../webview
'
export
interface
PreloadWebviewObject
extends
PlusWebviewWebviewObject
{
__preload__
?:
boolean
__query__
?:
string
__page__
?:
ComponentPublicInstance
}
export
const
preloadWebviews
:
Record
<
string
,
PreloadWebviewObject
>
=
{}
export
function
removePreloadWebview
(
webview
:
PreloadWebviewObject
)
{
const
url
=
Object
.
keys
(
preloadWebviews
).
find
(
(
url
)
=>
preloadWebviews
[
url
].
id
===
webview
.
id
)
if
(
url
)
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] removePreloadWebview(
${
webview
.
id
}
)`
)
}
delete
preloadWebviews
[
url
]
}
}
export
function
closePreloadWebview
({
url
}:
{
url
:
string
})
{
const
webview
=
preloadWebviews
[
url
]
if
(
webview
)
{
if
(
webview
.
__page__
)
{
if
(
!
getCurrentPages
().
find
((
page
)
=>
page
===
webview
.
__page__
))
{
// 未使用
webview
.
close
(
'
none
'
)
}
else
{
// 被使用
webview
.
__preload__
=
false
}
}
else
{
// 未使用
webview
.
close
(
'
none
'
)
}
delete
preloadWebviews
[
url
]
}
return
webview
}
export
function
preloadWebview
({
url
,
path
,
query
,
}:
{
url
:
string
path
:
string
query
:
Record
<
string
,
string
>
})
{
if
(
!
preloadWebviews
[
url
])
{
const
routeOptions
:
UniApp
.
UniRoute
=
JSON
.
parse
(
JSON
.
stringify
(
__uniRoutes
.
find
((
route
)
=>
route
.
path
===
path
))
)
preloadWebviews
[
url
]
=
createWebview
({
path
,
routeOptions
,
query
,
webviewStyle
:
{
__preload__
:
true
,
__query__
:
JSON
.
stringify
(
query
),
},
})
}
return
preloadWebviews
[
url
]
}
packages/uni-app-plus/src/service/framework/page/register.ts
浏览文件 @
9550e4b5
...
@@ -6,7 +6,7 @@ import {
...
@@ -6,7 +6,7 @@ import {
ON_REACH_BOTTOM_DISTANCE
,
ON_REACH_BOTTOM_DISTANCE
,
PageNodeOptions
,
PageNodeOptions
,
}
from
'
@dcloudio/uni-shared
'
}
from
'
@dcloudio/uni-shared
'
import
{
initPageInternalInstance
}
from
'
@dcloudio/uni-core
'
import
{
initPageInternalInstance
,
initPageVm
}
from
'
@dcloudio/uni-core
'
import
{
initEntry
}
from
'
../app/initEntry
'
import
{
initEntry
}
from
'
../app/initEntry
'
import
{
initRouteOptions
}
from
'
./routeOptions
'
import
{
initRouteOptions
}
from
'
./routeOptions
'
...
@@ -16,6 +16,7 @@ import { getStatusbarHeight } from '../../../helpers/statusBar'
...
@@ -16,6 +16,7 @@ import { getStatusbarHeight } from '../../../helpers/statusBar'
import
tabBar
from
'
../app/tabBar
'
import
tabBar
from
'
../app/tabBar
'
import
{
addCurrentPage
}
from
'
./getCurrentPages
'
import
{
addCurrentPage
}
from
'
./getCurrentPages
'
import
{
getBaseSystemInfo
}
from
'
../../api/base/getBaseSystemInfo
'
import
{
getBaseSystemInfo
}
from
'
../../api/base/getBaseSystemInfo
'
import
{
preloadWebviews
,
PreloadWebviewObject
}
from
'
./preLoad
'
interface
RegisterPageOptions
{
interface
RegisterPageOptions
{
url
:
string
url
:
string
...
@@ -39,7 +40,29 @@ export function registerPage({
...
@@ -39,7 +40,29 @@ export function registerPage({
if
(
webview
)
{
if
(
webview
)
{
initEntry
()
initEntry
()
}
}
// TODO preloadWebview
if
(
preloadWebviews
[
url
])
{
webview
=
preloadWebviews
[
url
]
const
_webview
=
webview
as
PreloadWebviewObject
if
(
_webview
.
__page__
)
{
// 该预载页面已处于显示状态,不再使用该预加载页面,直接新开
if
(
getCurrentPages
().
find
((
page
)
=>
page
===
_webview
.
__page__
))
{
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] preloadWebview(
${
path
}
,
${
_webview
.
id
}
) already in use`
)
}
webview
=
undefined
}
else
{
// TODO eventChannel
addCurrentPage
(
_webview
.
__page__
)
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`[uni-app] reuse preloadWebview(
${
path
}
,
${
_webview
.
id
}
)`
)
}
return
_webview
}
}
}
const
routeOptions
=
initRouteOptions
(
path
,
openType
)
const
routeOptions
=
initRouteOptions
(
path
,
openType
)
...
@@ -82,7 +105,12 @@ export function registerPage({
...
@@ -82,7 +105,12 @@ export function registerPage({
initPageOptions
(
routeOptions
)
initPageOptions
(
routeOptions
)
)
)
}
else
{
}
else
{
vm
&&
addCurrentPage
(
vm
)
initPageVm
(
vm
!
,
pageInstance
)
addCurrentPage
(
vm
!
)
if
((
webview
as
any
).
__preload__
)
{
;(
webview
as
any
).
__page__
=
vm
}
}
}
return
webview
return
webview
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录