Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
2bc43dfa
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,发现更多精彩内容 >>
提交
2bc43dfa
编写于
4月 22, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: onPageScroll
上级
d2181186
变更
36
展开全部
隐藏空白更改
内联
并排
Showing
36 changed file
with
675 addition
and
312 deletion
+675
-312
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+2
-0
packages/uni-core/src/helpers/index.ts
packages/uni-core/src/helpers/index.ts
+1
-0
packages/uni-core/src/helpers/scroll.ts
packages/uni-core/src/helpers/scroll.ts
+72
-0
packages/uni-core/src/service/plugin/index.ts
packages/uni-core/src/service/plugin/index.ts
+4
-1
packages/uni-core/src/service/plugin/on.ts
packages/uni-core/src/service/plugin/on.ts
+26
-0
packages/uni-core/src/service/plugin/page.ts
packages/uni-core/src/service/plugin/page.ts
+11
-0
packages/uni-core/src/service/plugin/subscribe.ts
packages/uni-core/src/service/plugin/subscribe.ts
+10
-18
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+424
-236
packages/uni-h5/src/framework/components/layout/index.tsx
packages/uni-h5/src/framework/components/layout/index.tsx
+2
-2
packages/uni-h5/src/framework/components/layout/tabBar.tsx
packages/uni-h5/src/framework/components/layout/tabBar.tsx
+1
-1
packages/uni-h5/src/framework/components/page/index.ts
packages/uni-h5/src/framework/components/page/index.ts
+1
-1
packages/uni-h5/src/framework/components/page/page-refresh/component.vue
.../src/framework/components/page/page-refresh/component.vue
+1
-1
packages/uni-h5/src/framework/components/page/page-refresh/index.ts
...ni-h5/src/framework/components/page/page-refresh/index.ts
+1
-1
packages/uni-h5/src/framework/components/page/pageBody.tsx
packages/uni-h5/src/framework/components/page/pageBody.tsx
+1
-1
packages/uni-h5/src/framework/components/page/pageHead.tsx
packages/uni-h5/src/framework/components/page/pageHead.tsx
+1
-1
packages/uni-h5/src/framework/index.ts
packages/uni-h5/src/framework/index.ts
+2
-2
packages/uni-h5/src/framework/plugin/index.ts
packages/uni-h5/src/framework/plugin/index.ts
+0
-3
packages/uni-h5/src/framework/plugin/router.ts
packages/uni-h5/src/framework/plugin/router.ts
+1
-1
packages/uni-h5/src/framework/setup/app.ts
packages/uni-h5/src/framework/setup/app.ts
+0
-0
packages/uni-h5/src/framework/setup/index.ts
packages/uni-h5/src/framework/setup/index.ts
+6
-32
packages/uni-h5/src/framework/setup/page.ts
packages/uni-h5/src/framework/setup/page.ts
+73
-1
packages/uni-h5/src/framework/setup/provide/index.ts
packages/uni-h5/src/framework/setup/provide/index.ts
+0
-0
packages/uni-h5/src/framework/setup/provide/layout.ts
packages/uni-h5/src/framework/setup/provide/layout.ts
+0
-0
packages/uni-h5/src/framework/setup/provide/page.ts
packages/uni-h5/src/framework/setup/provide/page.ts
+21
-2
packages/uni-h5/src/framework/setup/state.ts
packages/uni-h5/src/framework/setup/state.ts
+0
-0
packages/uni-h5/src/helpers/cssVar.ts
packages/uni-h5/src/helpers/cssVar.ts
+1
-1
packages/uni-h5/src/index.ts
packages/uni-h5/src/index.ts
+1
-1
packages/uni-h5/src/service/api/route/reLaunch.ts
packages/uni-h5/src/service/api/route/reLaunch.ts
+1
-1
packages/uni-h5/src/service/api/route/redirectTo.ts
packages/uni-h5/src/service/api/route/redirectTo.ts
+1
-1
packages/uni-h5/src/service/api/route/switchTab.ts
packages/uni-h5/src/service/api/route/switchTab.ts
+1
-1
packages/uni-h5/src/service/api/route/utils.ts
packages/uni-h5/src/service/api/route/utils.ts
+1
-1
packages/uni-h5/src/service/api/ui/tabBar.ts
packages/uni-h5/src/service/api/ui/tabBar.ts
+1
-1
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+2
-0
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+2
-0
packages/uni-shared/dist/uni-shared.esm.js
packages/uni-shared/dist/uni-shared.esm.js
+2
-1
packages/uni-shared/src/constants.ts
packages/uni-shared/src/constants.ts
+1
-0
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
2bc43dfa
...
@@ -128,9 +128,11 @@ declare namespace UniApp {
...
@@ -128,9 +128,11 @@ declare namespace UniApp {
}
}
interface
PagesJsonPageStyle
extends
PagesJsonPagePlatformStyle
{
interface
PagesJsonPageStyle
extends
PagesJsonPagePlatformStyle
{
disableScroll
?:
boolean
enablePullDownRefresh
?:
boolean
enablePullDownRefresh
?:
boolean
navigationBar
:
PageNavigationBar
navigationBar
:
PageNavigationBar
refreshOptions
?:
PageRefreshOptions
refreshOptions
?:
PageRefreshOptions
onReachBottomDistance
?:
number
}
}
interface
PageRouteMeta
extends
PagesJsonPageStyle
{
interface
PageRouteMeta
extends
PagesJsonPageStyle
{
id
:
number
id
:
number
...
...
packages/uni-core/src/helpers/index.ts
浏览文件 @
2bc43dfa
export
*
from
'
./util
'
export
*
from
'
./util
'
export
*
from
'
./icon
'
export
*
from
'
./icon
'
export
*
from
'
./scroll
'
export
*
from
'
./getRealRoute
'
export
*
from
'
./getRealRoute
'
export
*
from
'
./updateCssVar
'
export
*
from
'
./updateCssVar
'
export
*
from
'
./getWindowOffset
'
export
*
from
'
./getWindowOffset
'
packages/uni-core/src/helpers/scroll.ts
0 → 100644
浏览文件 @
2bc43dfa
export
interface
CreateScrollListenerOptions
{
onPageScroll
?:
(
scrollTop
:
number
)
=>
void
onReachBottom
?:
()
=>
void
onReachBottomDistance
?:
number
}
export
function
disableScrollListener
(
evt
:
Event
)
{
evt
.
preventDefault
()
}
let
testReachBottomTimer
:
number
let
lastScrollHeight
=
0
export
function
createScrollListener
({
onPageScroll
,
onReachBottom
,
onReachBottomDistance
,
}:
CreateScrollListenerOptions
)
{
let
ticking
=
false
let
hasReachBottom
=
false
let
reachBottomLocking
=
true
const
isReachBottom
=
()
=>
{
const
{
scrollHeight
}
=
document
.
documentElement
// 部分浏览器窗口高度变化后document.documentelement.clientheight不会变化,采用window.innerHeight
const
windowHeight
=
window
.
innerHeight
const
scrollY
=
window
.
scrollY
const
isBottom
=
scrollY
>
0
&&
scrollHeight
>
windowHeight
&&
scrollY
+
windowHeight
+
onReachBottomDistance
!
>=
scrollHeight
// 兼容部分浏览器滚动时scroll事件不触发
const
heightChanged
=
Math
.
abs
(
scrollHeight
-
lastScrollHeight
)
>
onReachBottomDistance
!
if
(
isBottom
&&
(
!
hasReachBottom
||
heightChanged
))
{
lastScrollHeight
=
scrollHeight
hasReachBottom
=
true
return
true
}
if
(
!
isBottom
&&
hasReachBottom
)
{
hasReachBottom
=
false
}
return
false
}
const
trigger
=
()
=>
{
onPageScroll
&&
onPageScroll
(
window
.
pageYOffset
)
function
testReachBottom
()
{
if
(
isReachBottom
())
{
onReachBottom
&&
onReachBottom
()
reachBottomLocking
=
false
setTimeout
(
function
()
{
reachBottomLocking
=
true
},
350
)
return
true
}
}
if
(
onReachBottom
&&
reachBottomLocking
)
{
if
(
testReachBottom
())
{
}
else
{
// 解决部分浏览器滚动中js获取窗口高度不准确导致的问题
testReachBottomTimer
=
setTimeout
(
testReachBottom
,
300
)
}
}
ticking
=
false
}
return
function
onScroll
()
{
clearTimeout
(
testReachBottomTimer
)
if
(
!
ticking
)
{
requestAnimationFrame
(
trigger
)
}
ticking
=
true
}
}
packages/uni-core/src/service/plugin/index.ts
浏览文件 @
2bc43dfa
import
{
App
}
from
'
vue
'
import
{
App
}
from
'
vue
'
import
{
initAppConfig
}
from
'
./appConfig
'
import
{
initAppConfig
}
from
'
./appConfig
'
import
{
initOn
}
from
'
./on
'
import
{
initSubscribe
}
from
'
./subscribe
'
import
{
initSubscribe
}
from
'
./subscribe
'
export
*
from
'
./page
'
export
*
from
'
./page
'
export
function
initService
(
app
:
App
)
{
export
function
initService
(
app
:
App
)
{
init
AppConfig
(
app
.
_context
.
config
)
init
On
(
)
initSubscribe
()
initSubscribe
()
initAppConfig
(
app
.
_context
.
config
)
}
}
packages/uni-core/src/service/plugin/on.ts
0 → 100644
浏览文件 @
2bc43dfa
import
{
ComponentPublicInstance
}
from
'
@vue/runtime-core
'
import
{
getCurrentPage
,
invokeHook
}
from
'
./page
'
export
function
initOn
()
{
UniServiceJSBridge
.
on
(
'
onAppEnterForeground
'
,
onAppEnterForeground
)
UniServiceJSBridge
.
on
(
'
onAppEnterBackground
'
,
onAppEnterBackground
)
}
function
onAppEnterForeground
()
{
const
page
=
getCurrentPage
()
const
showOptions
=
{
path
:
''
,
query
:
{},
}
if
(
page
)
{
showOptions
.
path
=
page
.
$page
.
route
showOptions
.
query
=
page
.
$page
.
options
}
invokeHook
(
getApp
()
as
ComponentPublicInstance
,
'
onShow
'
,
showOptions
)
invokeHook
(
page
as
ComponentPublicInstance
,
'
onShow
'
)
}
function
onAppEnterBackground
()
{
invokeHook
(
getApp
()
as
ComponentPublicInstance
,
'
onHide
'
)
invokeHook
(
getCurrentPage
()
as
ComponentPublicInstance
,
'
onHide
'
)
}
packages/uni-core/src/service/plugin/page.ts
浏览文件 @
2bc43dfa
...
@@ -2,6 +2,17 @@ import { isString } from '@vue/shared'
...
@@ -2,6 +2,17 @@ import { isString } from '@vue/shared'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
invokeArrayFns
}
from
'
@dcloudio/uni-shared
'
import
{
invokeArrayFns
}
from
'
@dcloudio/uni-shared
'
export
function
getPageById
(
id
:
number
)
{
return
getCurrentPages
().
find
((
page
)
=>
page
.
$page
.
id
===
id
)
}
export
function
getPageVmById
(
id
:
number
)
{
const
page
=
getPageById
(
id
)
if
(
page
)
{
return
(
page
as
any
).
$vm
as
ComponentPublicInstance
}
}
export
function
getCurrentPage
()
{
export
function
getCurrentPage
()
{
const
pages
=
getCurrentPages
()
const
pages
=
getCurrentPages
()
const
len
=
pages
.
length
const
len
=
pages
.
length
...
...
packages/uni-core/src/service/plugin/subscribe.ts
浏览文件 @
2bc43dfa
import
{
ComponentPublicInstance
}
from
'
@vue/runtime-core
'
import
{
getPageVmById
,
invokeHook
}
from
'
./page
'
import
{
getCurrentPage
,
invokeHook
}
from
'
./page
'
export
function
initSubscribe
()
{
export
function
initSubscribe
()
{
UniServiceJSBridge
.
on
(
'
onAppEnterForeground
'
,
()
=>
{
UniServiceJSBridge
.
subscribe
(
'
onPageScroll
'
,
createPageEvent
(
'
onPageScroll
'
))
const
page
=
getCurrentPage
()
}
const
showOptions
=
{
path
:
''
,
function
createPageEvent
(
name
:
string
)
{
query
:
{},
return
(
args
:
unknown
,
pageId
:
number
)
=>
{
}
const
vm
=
getPageVmById
(
pageId
)
if
(
page
)
{
if
(
vm
)
{
showOptions
.
path
=
page
.
$page
.
route
invokeHook
(
vm
,
name
,
args
)
showOptions
.
query
=
page
.
$page
.
options
}
}
invokeHook
(
getApp
()
as
ComponentPublicInstance
,
'
onShow
'
,
showOptions
)
}
invokeHook
(
page
as
ComponentPublicInstance
,
'
onShow
'
)
})
UniServiceJSBridge
.
on
(
'
onAppEnterBackground
'
,
()
=>
{
invokeHook
(
getApp
()
as
ComponentPublicInstance
,
'
onHide
'
)
invokeHook
(
getCurrentPage
()
as
ComponentPublicInstance
,
'
onHide
'
)
})
}
}
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
2bc43dfa
此差异已折叠。
点击以展开。
packages/uni-h5/src/framework/components/layout/index.tsx
浏览文件 @
2bc43dfa
...
@@ -17,8 +17,8 @@ import {
...
@@ -17,8 +17,8 @@ import {
import
{
RouterView
,
useRoute
}
from
'
vue-router
'
import
{
RouterView
,
useRoute
}
from
'
vue-router
'
import
{
useTabBar
}
from
'
../../
plugin
/state
'
import
{
useTabBar
}
from
'
../../
setup
/state
'
import
{
useKeepAliveRoute
}
from
'
../../
plugin
/page
'
import
{
useKeepAliveRoute
}
from
'
../../
setup
/page
'
import
TabBar
from
'
./tabBar
'
import
TabBar
from
'
./tabBar
'
...
...
packages/uni-h5/src/framework/components/layout/tabBar.tsx
浏览文件 @
2bc43dfa
...
@@ -6,7 +6,7 @@ import {
...
@@ -6,7 +6,7 @@ import {
OnTabBarMidButtonTap
,
OnTabBarMidButtonTap
,
}
from
'
@dcloudio/uni-api
'
}
from
'
@dcloudio/uni-api
'
import
{
getRealPath
}
from
'
../../../platform
'
import
{
getRealPath
}
from
'
../../../platform
'
import
{
useTabBar
}
from
'
../../
plugin
/state
'
import
{
useTabBar
}
from
'
../../
setup
/state
'
import
{
cssBackdropFilter
}
from
'
../../../service/api/base/canIUse
'
import
{
cssBackdropFilter
}
from
'
../../../service/api/base/canIUse
'
import
{
normalizeWindowBottom
}
from
'
../../../helpers/cssVar
'
import
{
normalizeWindowBottom
}
from
'
../../../helpers/cssVar
'
...
...
packages/uni-h5/src/framework/components/page/index.ts
浏览文件 @
2bc43dfa
...
@@ -10,7 +10,7 @@ import {
...
@@ -10,7 +10,7 @@ import {
import
PageHead
from
'
./pageHead
'
import
PageHead
from
'
./pageHead
'
import
PageBody
from
'
./pageBody
'
import
PageBody
from
'
./pageBody
'
import
{
providePageMeta
}
from
'
../../
plugin
/provide
'
import
{
providePageMeta
}
from
'
../../
setup
/provide
'
export
default
defineComponent
({
export
default
defineComponent
({
name
:
'
Page
'
,
name
:
'
Page
'
,
...
...
packages/uni-h5/src/framework/components/page/page-refresh/component.vue
浏览文件 @
2bc43dfa
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
</uni-page-refresh>
</uni-page-refresh>
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
{
usePageMeta
}
from
'
../../../
plugin
/provide
'
import
{
usePageMeta
}
from
'
../../../
setup
/provide
'
export
default
{
export
default
{
name
:
'
PageRefresh
'
,
name
:
'
PageRefresh
'
,
setup
()
{
setup
()
{
...
...
packages/uni-h5/src/framework/components/page/page-refresh/index.ts
浏览文件 @
2bc43dfa
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
API_STOP_PULL_DOWN_REFRESH
,
API_STOP_PULL_DOWN_REFRESH
,
}
from
'
@dcloudio/uni-api
'
}
from
'
@dcloudio/uni-api
'
import
{
useSubscribe
}
from
'
@dcloudio/uni-components
'
import
{
useSubscribe
}
from
'
@dcloudio/uni-components
'
import
{
usePageMeta
}
from
'
../../../
plugin
/provide
'
import
{
usePageMeta
}
from
'
../../../
setup
/provide
'
function
processDeltaY
(
function
processDeltaY
(
ev
:
TouchEvent
,
ev
:
TouchEvent
,
...
...
packages/uni-h5/src/framework/components/page/pageBody.tsx
浏览文件 @
2bc43dfa
import
{
ref
,
renderSlot
,
defineComponent
,
Ref
}
from
'
vue
'
import
{
ref
,
renderSlot
,
defineComponent
,
Ref
}
from
'
vue
'
import
{
usePageMeta
}
from
'
../../
plugin
/provide
'
import
{
usePageMeta
}
from
'
../../
setup
/provide
'
import
PageRefresh
from
'
./page-refresh/component.vue
'
import
PageRefresh
from
'
./page-refresh/component.vue
'
...
...
packages/uni-h5/src/framework/components/page/pageHead.tsx
浏览文件 @
2bc43dfa
...
@@ -7,7 +7,7 @@ import {
...
@@ -7,7 +7,7 @@ import {
createSvgIconVNode
,
createSvgIconVNode
,
invokeHook
,
invokeHook
,
}
from
'
@dcloudio/uni-core
'
}
from
'
@dcloudio/uni-core
'
import
{
usePageMeta
}
from
'
../../
plugin
/provide
'
import
{
usePageMeta
}
from
'
../../
setup
/provide
'
import
{
import
{
usePageHeadTransparent
,
usePageHeadTransparent
,
usePageHeadTransparentBackgroundColor
,
usePageHeadTransparentBackgroundColor
,
...
...
packages/uni-h5/src/framework/index.ts
浏览文件 @
2bc43dfa
export
{
getApp
}
from
'
./
plugin
/app
'
export
{
getApp
}
from
'
./
setup
/app
'
export
{
getCurrentPages
}
from
'
./
plugin
/page
'
export
{
getCurrentPages
}
from
'
./
setup
/page
'
packages/uni-h5/src/framework/plugin/index.ts
浏览文件 @
2bc43dfa
...
@@ -4,7 +4,6 @@ import { initApp } from '@dcloudio/uni-vue'
...
@@ -4,7 +4,6 @@ import { initApp } from '@dcloudio/uni-vue'
import
{
initView
,
initService
}
from
'
@dcloudio/uni-core
'
import
{
initView
,
initService
}
from
'
@dcloudio/uni-core
'
import
{
initRouter
}
from
'
./router
'
import
{
initRouter
}
from
'
./router
'
// import { initMixin } from './mixin'
export
default
{
export
default
{
install
(
app
:
App
)
{
install
(
app
:
App
)
{
...
@@ -12,8 +11,6 @@ export default {
...
@@ -12,8 +11,6 @@ export default {
initView
(
app
)
initView
(
app
)
initService
(
app
)
initService
(
app
)
// initMixin(app)
if
(
__UNI_FEATURE_PAGES__
)
{
if
(
__UNI_FEATURE_PAGES__
)
{
initRouter
(
app
)
initRouter
(
app
)
}
}
...
...
packages/uni-h5/src/framework/plugin/router.ts
浏览文件 @
2bc43dfa
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
createWebHistory
,
createWebHistory
,
createWebHashHistory
,
createWebHashHistory
,
}
from
'
vue-router
'
}
from
'
vue-router
'
import
{
getCurrentPages
,
normalizeRouteKey
,
removePage
}
from
'
./page
'
import
{
getCurrentPages
,
normalizeRouteKey
,
removePage
}
from
'
.
./setup
/page
'
export
function
initRouter
(
app
:
App
)
{
export
function
initRouter
(
app
:
App
)
{
app
.
use
(
createAppRouter
(
createRouter
(
createRouterOptions
())))
app
.
use
(
createAppRouter
(
createRouter
(
createRouterOptions
())))
...
...
packages/uni-h5/src/framework/
plugin
/app.ts
→
packages/uni-h5/src/framework/
setup
/app.ts
浏览文件 @
2bc43dfa
文件已移动
packages/uni-h5/src/framework/
plugin/setup
.ts
→
packages/uni-h5/src/framework/
setup/index
.ts
浏览文件 @
2bc43dfa
...
@@ -11,13 +11,12 @@ import {
...
@@ -11,13 +11,12 @@ import {
onBeforeDeactivate
,
onBeforeDeactivate
,
onBeforeMount
,
onBeforeMount
,
}
from
'
vue
'
}
from
'
vue
'
import
{
useRoute
,
useRoute
r
}
from
'
vue-router
'
import
{
useRouter
}
from
'
vue-router
'
import
{
parseQuery
,
decodedQuery
}
from
'
@dcloudio/uni-shared
'
import
{
decodedQuery
}
from
'
@dcloudio/uni-shared
'
import
{
LayoutComponent
}
from
'
../..
'
import
{
LayoutComponent
}
from
'
../..
'
import
{
initApp
}
from
'
./app
'
import
{
initApp
}
from
'
./app
'
import
{
initPage
}
from
'
./page
'
import
{
initPage
,
onPageShow
}
from
'
./page
'
import
{
usePageMeta
}
from
'
./provide
'
import
{
usePageMeta
,
usePageRoute
}
from
'
./provide
'
import
{
updateCurPageCssVar
}
from
'
../../helpers/cssVar
'
interface
SetupComponentOptions
{
interface
SetupComponentOptions
{
init
:
(
vm
:
ComponentPublicInstance
)
=>
void
init
:
(
vm
:
ComponentPublicInstance
)
=>
void
...
@@ -25,27 +24,6 @@ interface SetupComponentOptions {
...
@@ -25,27 +24,6 @@ interface SetupComponentOptions {
after
?:
(
comp
:
DefineComponent
)
=>
void
after
?:
(
comp
:
DefineComponent
)
=>
void
}
}
export
function
usePageRoute
()
{
if
(
__UNI_FEATURE_PAGES__
)
{
return
useRoute
()
}
const
url
=
location
.
href
const
searchPos
=
url
.
indexOf
(
'
?
'
)
const
hashPos
=
url
.
indexOf
(
'
#
'
,
searchPos
>
-
1
?
searchPos
:
0
)
let
query
=
{}
if
(
searchPos
>
-
1
)
{
query
=
parseQuery
(
url
.
slice
(
searchPos
+
1
,
hashPos
>
-
1
?
hashPos
:
url
.
length
)
)
}
const
{
meta
}
=
__uniRoutes
[
0
]
return
{
meta
,
query
:
query
,
path
:
'
/
'
+
meta
.
route
,
}
}
function
wrapperComponentSetup
(
function
wrapperComponentSetup
(
comp
:
DefineComponent
,
comp
:
DefineComponent
,
{
init
,
setup
,
after
}:
SetupComponentOptions
{
init
,
setup
,
after
}:
SetupComponentOptions
...
@@ -71,10 +49,6 @@ function setupComponent(comp: any, options: SetupComponentOptions) {
...
@@ -71,10 +49,6 @@ function setupComponent(comp: any, options: SetupComponentOptions) {
return
comp
return
comp
}
}
function
onPageShow
(
pageMeta
:
UniApp
.
PageRouteMeta
)
{
updateCurPageCssVar
(
pageMeta
)
}
export
function
setupPage
(
comp
:
any
)
{
export
function
setupPage
(
comp
:
any
)
{
return
setupComponent
(
comp
,
{
return
setupComponent
(
comp
,
{
init
:
initPage
,
init
:
initPage
,
...
@@ -88,7 +62,7 @@ export function setupPage(comp: any) {
...
@@ -88,7 +62,7 @@ export function setupPage(comp: any) {
const
pageMeta
=
usePageMeta
()
const
pageMeta
=
usePageMeta
()
onBeforeMount
(()
=>
{
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance
const
{
onLoad
,
onShow
}
=
instance
onPageShow
(
pageMeta
)
onPageShow
(
instance
,
pageMeta
)
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
instance
.
__isVisible
=
true
instance
.
__isVisible
=
true
onShow
&&
invokeArrayFns
(
onShow
)
onShow
&&
invokeArrayFns
(
onShow
)
...
@@ -99,7 +73,7 @@ export function setupPage(comp: any) {
...
@@ -99,7 +73,7 @@ export function setupPage(comp: any) {
})
})
onBeforeActivate
(()
=>
{
onBeforeActivate
(()
=>
{
if
(
!
instance
.
__isVisible
)
{
if
(
!
instance
.
__isVisible
)
{
onPageShow
(
pageMeta
)
onPageShow
(
instance
,
pageMeta
)
instance
.
__isVisible
=
true
instance
.
__isVisible
=
true
const
{
onShow
}
=
instance
const
{
onShow
}
=
instance
onShow
&&
invokeArrayFns
(
onShow
)
onShow
&&
invokeArrayFns
(
onShow
)
...
...
packages/uni-h5/src/framework/
plugin
/page.ts
→
packages/uni-h5/src/framework/
setup
/page.ts
浏览文件 @
2bc43dfa
...
@@ -4,11 +4,19 @@ import {
...
@@ -4,11 +4,19 @@ import {
computed
,
computed
,
ConcreteComponent
,
ConcreteComponent
,
ComponentPublicInstance
,
ComponentPublicInstance
,
ComponentInternalInstance
,
}
from
'
vue
'
}
from
'
vue
'
import
{
useRoute
,
RouteLocationNormalizedLoaded
}
from
'
vue-router
'
import
{
useRoute
,
RouteLocationNormalizedLoaded
}
from
'
vue-router
'
import
{
invokeHook
}
from
'
@dcloudio/uni-core
'
import
{
invokeHook
,
disableScrollListener
,
createScrollListener
,
CreateScrollListenerOptions
,
}
from
'
@dcloudio/uni-core
'
import
{
ON_REACH_BOTTOM_DISTANCE
}
from
'
@dcloudio/uni-shared
'
import
{
usePageMeta
}
from
'
./provide
'
import
{
usePageMeta
}
from
'
./provide
'
import
{
NavigateType
}
from
'
../../service/api/route/utils
'
import
{
NavigateType
}
from
'
../../service/api/route/utils
'
import
{
updateCurPageCssVar
}
from
'
../../helpers/cssVar
'
const
SEP
=
'
$$
'
const
SEP
=
'
$$
'
...
@@ -176,3 +184,67 @@ function pruneRouteCache(key: string) {
...
@@ -176,3 +184,67 @@ function pruneRouteCache(key: string) {
}
}
})
})
}
}
export
function
onPageShow
(
instance
:
ComponentInternalInstance
,
pageMeta
:
UniApp
.
PageRouteMeta
)
{
updateCurPageCssVar
(
pageMeta
)
initPageScrollListener
(
instance
,
pageMeta
)
}
let
curScrollListener
:
(
evt
:
Event
)
=>
any
function
initPageScrollListener
(
instance
:
ComponentInternalInstance
,
pageMeta
:
UniApp
.
PageRouteMeta
)
{
document
.
removeEventListener
(
'
touchmove
'
,
disableScrollListener
)
if
(
curScrollListener
)
{
document
.
removeEventListener
(
'
scroll
'
,
curScrollListener
)
}
if
(
pageMeta
.
disableScroll
)
{
return
document
.
addEventListener
(
'
touchmove
'
,
disableScrollListener
)
}
const
{
onPageScroll
,
onReachBottom
}
=
instance
const
navigationBarTransparent
=
pageMeta
.
navigationBar
.
type
===
'
transparent
'
if
(
!
onPageScroll
&&
!
onReachBottom
&&
!
navigationBarTransparent
)
{
return
}
const
opts
:
CreateScrollListenerOptions
=
{}
const
pageId
=
instance
.
proxy
!
.
$page
.
id
if
(
onPageScroll
||
navigationBarTransparent
)
{
opts
.
onPageScroll
=
createOnPageScroll
(
pageId
,
onPageScroll
,
navigationBarTransparent
)
}
if
(
onReachBottom
)
{
opts
.
onReachBottomDistance
=
pageMeta
.
onReachBottomDistance
||
ON_REACH_BOTTOM_DISTANCE
opts
.
onReachBottom
=
()
=>
UniViewJSBridge
.
publishHandler
(
'
onReachBottom
'
,
{},
pageId
)
}
curScrollListener
=
createScrollListener
(
opts
)
// 避免监听太早,直接触发了 scroll
requestAnimationFrame
(()
=>
document
.
addEventListener
(
'
scroll
'
,
curScrollListener
)
)
}
function
createOnPageScroll
(
pageId
:
number
,
onPageScroll
:
unknown
,
navigationBarTransparent
:
boolean
)
{
return
(
scrollTop
:
number
)
=>
{
if
(
onPageScroll
)
{
UniViewJSBridge
.
publishHandler
(
'
onPageScroll
'
,
{
scrollTop
},
pageId
)
}
if
(
navigationBarTransparent
)
{
UniViewJSBridge
.
emit
(
pageId
+
'
.onPageScroll
'
,
{
scrollTop
,
})
}
}
}
packages/uni-h5/src/framework/
plugin
/provide/index.ts
→
packages/uni-h5/src/framework/
setup
/provide/index.ts
浏览文件 @
2bc43dfa
文件已移动
packages/uni-h5/src/framework/
plugin
/provide/layout.ts
→
packages/uni-h5/src/framework/
setup
/provide/layout.ts
浏览文件 @
2bc43dfa
文件已移动
packages/uni-h5/src/framework/
plugin
/provide/page.ts
→
packages/uni-h5/src/framework/
setup
/provide/page.ts
浏览文件 @
2bc43dfa
import
{
reactive
,
provide
,
inject
}
from
'
vue
'
import
{
reactive
,
provide
,
inject
}
from
'
vue
'
import
{
useRoute
}
from
'
vue-router
'
import
{
useRoute
}
from
'
vue-router
'
import
{
NAVBAR_HEIGHT
}
from
'
@dcloudio/uni-shared
'
import
{
NAVBAR_HEIGHT
,
parseQuery
}
from
'
@dcloudio/uni-shared
'
import
{
PolySymbol
,
rpx2px
}
from
'
@dcloudio/uni-core
'
import
{
PolySymbol
,
rpx2px
}
from
'
@dcloudio/uni-core
'
import
safeAreaInsets
from
'
safe-area-insets
'
import
safeAreaInsets
from
'
safe-area-insets
'
...
@@ -17,7 +17,26 @@ export function providePageMeta(id: number) {
...
@@ -17,7 +17,26 @@ export function providePageMeta(id: number) {
provide
(
pageMetaKey
,
pageMeta
)
provide
(
pageMetaKey
,
pageMeta
)
return
pageMeta
return
pageMeta
}
}
export
function
usePageRoute
()
{
if
(
__UNI_FEATURE_PAGES__
)
{
return
useRoute
()
}
const
url
=
location
.
href
const
searchPos
=
url
.
indexOf
(
'
?
'
)
const
hashPos
=
url
.
indexOf
(
'
#
'
,
searchPos
>
-
1
?
searchPos
:
0
)
let
query
=
{}
if
(
searchPos
>
-
1
)
{
query
=
parseQuery
(
url
.
slice
(
searchPos
+
1
,
hashPos
>
-
1
?
hashPos
:
url
.
length
)
)
}
const
{
meta
}
=
__uniRoutes
[
0
]
return
{
meta
,
query
:
query
,
path
:
'
/
'
+
meta
.
route
,
}
}
function
initPageMeta
(
id
:
number
)
{
function
initPageMeta
(
id
:
number
)
{
if
(
__UNI_FEATURE_PAGES__
)
{
if
(
__UNI_FEATURE_PAGES__
)
{
return
reactive
<
UniApp
.
PageRouteMeta
>
(
return
reactive
<
UniApp
.
PageRouteMeta
>
(
...
...
packages/uni-h5/src/framework/
plugin
/state.ts
→
packages/uni-h5/src/framework/
setup
/state.ts
浏览文件 @
2bc43dfa
文件已移动
packages/uni-h5/src/helpers/cssVar.ts
浏览文件 @
2bc43dfa
import
{
NAVBAR_HEIGHT
}
from
'
@dcloudio/uni-shared
'
import
{
NAVBAR_HEIGHT
}
from
'
@dcloudio/uni-shared
'
import
{
updatePageCssVar
}
from
'
@dcloudio/uni-core
'
import
{
updatePageCssVar
}
from
'
@dcloudio/uni-core
'
import
{
useTabBar
}
from
'
../framework/
plugin
/state
'
import
{
useTabBar
}
from
'
../framework/
setup
/state
'
import
{
cssEnv
,
cssConstant
}
from
'
../service/api/base/canIUse
'
import
{
cssEnv
,
cssConstant
}
from
'
../service/api/base/canIUse
'
const
envMethod
=
/*#__PURE__*/
(()
=>
const
envMethod
=
/*#__PURE__*/
(()
=>
...
...
packages/uni-h5/src/index.ts
浏览文件 @
2bc43dfa
export
{
default
as
plugin
}
from
'
./framework/plugin
'
export
{
default
as
plugin
}
from
'
./framework/plugin
'
export
*
from
'
./framework/
plugin/
setup
'
export
*
from
'
./framework/setup
'
export
*
from
'
@dcloudio/uni-components
'
export
*
from
'
@dcloudio/uni-components
'
export
*
from
'
./view/components
'
export
*
from
'
./view/components
'
...
...
packages/uni-h5/src/service/api/route/reLaunch.ts
浏览文件 @
2bc43dfa
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
ReLaunchOptions
,
ReLaunchOptions
,
ReLaunchProtocol
,
ReLaunchProtocol
,
}
from
'
@dcloudio/uni-api
'
}
from
'
@dcloudio/uni-api
'
import
{
getCurrentPagesMap
,
removePage
}
from
'
../../../framework/
plugin
/page
'
import
{
getCurrentPagesMap
,
removePage
}
from
'
../../../framework/
setup
/page
'
import
{
navigate
}
from
'
./utils
'
import
{
navigate
}
from
'
./utils
'
function
removeAllPages
()
{
function
removeAllPages
()
{
...
...
packages/uni-h5/src/service/api/route/redirectTo.ts
浏览文件 @
2bc43dfa
...
@@ -6,7 +6,7 @@ import {
...
@@ -6,7 +6,7 @@ import {
RedirectToProtocol
,
RedirectToProtocol
,
}
from
'
@dcloudio/uni-api
'
}
from
'
@dcloudio/uni-api
'
import
{
getCurrentPage
}
from
'
@dcloudio/uni-core
'
import
{
getCurrentPage
}
from
'
@dcloudio/uni-core
'
import
{
removePage
,
normalizeRouteKey
}
from
'
../../../framework/
plugin
/page
'
import
{
removePage
,
normalizeRouteKey
}
from
'
../../../framework/
setup
/page
'
import
{
navigate
}
from
'
./utils
'
import
{
navigate
}
from
'
./utils
'
function
removeLastPage
()
{
function
removeLastPage
()
{
...
...
packages/uni-h5/src/service/api/route/switchTab.ts
浏览文件 @
2bc43dfa
...
@@ -7,7 +7,7 @@ import {
...
@@ -7,7 +7,7 @@ import {
SwitchTabProtocol
,
SwitchTabProtocol
,
}
from
'
@dcloudio/uni-api
'
}
from
'
@dcloudio/uni-api
'
import
{
getCurrentPageVm
,
invokeHook
}
from
'
@dcloudio/uni-core
'
import
{
getCurrentPageVm
,
invokeHook
}
from
'
@dcloudio/uni-core
'
import
{
getCurrentPagesMap
,
removePage
}
from
'
../../../framework/
plugin
/page
'
import
{
getCurrentPagesMap
,
removePage
}
from
'
../../../framework/
setup
/page
'
import
{
navigate
}
from
'
./utils
'
import
{
navigate
}
from
'
./utils
'
function
removeNonTabBarPages
()
{
function
removeNonTabBarPages
()
{
...
...
packages/uni-h5/src/service/api/route/utils.ts
浏览文件 @
2bc43dfa
import
{
isNavigationFailure
,
Router
}
from
'
vue-router
'
import
{
isNavigationFailure
,
Router
}
from
'
vue-router
'
import
{
createPageState
}
from
'
../../../framework/
plugin
/page
'
import
{
createPageState
}
from
'
../../../framework/
setup
/page
'
export
type
NavigateType
=
export
type
NavigateType
=
|
'
navigateTo
'
|
'
navigateTo
'
...
...
packages/uni-h5/src/service/api/ui/tabBar.ts
浏览文件 @
2bc43dfa
...
@@ -32,7 +32,7 @@ import {
...
@@ -32,7 +32,7 @@ import {
ShowTabBarRedDotOptions
,
ShowTabBarRedDotOptions
,
ShowTabBarRedDotProtocol
,
ShowTabBarRedDotProtocol
,
}
from
'
@dcloudio/uni-api
'
}
from
'
@dcloudio/uni-api
'
import
{
useTabBar
}
from
'
../../../framework/
plugin
/state
'
import
{
useTabBar
}
from
'
../../../framework/
setup
/state
'
const
setTabBarItemProps
=
[
'
text
'
,
'
iconPath
'
,
'
selectedIconPath
'
]
const
setTabBarItemProps
=
[
'
text
'
,
'
iconPath
'
,
'
selectedIconPath
'
]
const
setTabBarStyleProps
=
[
const
setTabBarStyleProps
=
[
'
color
'
,
'
color
'
,
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
2bc43dfa
...
@@ -292,6 +292,7 @@ function debounce(fn, delay) {
...
@@ -292,6 +292,7 @@ function debounce(fn, delay) {
const
NAVBAR_HEIGHT
=
44
;
const
NAVBAR_HEIGHT
=
44
;
const
TABBAR_HEIGHT
=
50
;
const
TABBAR_HEIGHT
=
50
;
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
const
RESPONSIVE_MIN_WIDTH
=
768
;
const
RESPONSIVE_MIN_WIDTH
=
768
;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
PRIMARY_COLOR
=
'
#007aff
'
;
const
PRIMARY_COLOR
=
'
#007aff
'
;
...
@@ -301,6 +302,7 @@ exports.COMPONENT_NAME_PREFIX = COMPONENT_NAME_PREFIX;
...
@@ -301,6 +302,7 @@ exports.COMPONENT_NAME_PREFIX = COMPONENT_NAME_PREFIX;
exports
.
COMPONENT_PREFIX
=
COMPONENT_PREFIX
;
exports
.
COMPONENT_PREFIX
=
COMPONENT_PREFIX
;
exports
.
COMPONENT_SELECTOR_PREFIX
=
COMPONENT_SELECTOR_PREFIX
;
exports
.
COMPONENT_SELECTOR_PREFIX
=
COMPONENT_SELECTOR_PREFIX
;
exports
.
NAVBAR_HEIGHT
=
NAVBAR_HEIGHT
;
exports
.
NAVBAR_HEIGHT
=
NAVBAR_HEIGHT
;
exports
.
ON_REACH_BOTTOM_DISTANCE
=
ON_REACH_BOTTOM_DISTANCE
;
exports
.
PLUS_RE
=
PLUS_RE
;
exports
.
PLUS_RE
=
PLUS_RE
;
exports
.
PRIMARY_COLOR
=
PRIMARY_COLOR
;
exports
.
PRIMARY_COLOR
=
PRIMARY_COLOR
;
exports
.
RESPONSIVE_MIN_WIDTH
=
RESPONSIVE_MIN_WIDTH
;
exports
.
RESPONSIVE_MIN_WIDTH
=
RESPONSIVE_MIN_WIDTH
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
2bc43dfa
...
@@ -47,6 +47,8 @@ export declare function normalizeTarget(el: HTMLElement): {
...
@@ -47,6 +47,8 @@ export declare function normalizeTarget(el: HTMLElement): {
offsetLeft
:
number
;
offsetLeft
:
number
;
};
};
export
declare
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
export
declare
function
once
(
fn
:
(...
args
:
any
[])
=>
any
,
ctx
?:
unknown
):
(...
args
:
any
[])
=>
any
;
export
declare
function
once
(
fn
:
(...
args
:
any
[])
=>
any
,
ctx
?:
unknown
):
(...
args
:
any
[])
=>
any
;
/**
/**
...
...
packages/uni-shared/dist/uni-shared.esm.js
浏览文件 @
2bc43dfa
...
@@ -288,8 +288,9 @@ function debounce(fn, delay) {
...
@@ -288,8 +288,9 @@ function debounce(fn, delay) {
const
NAVBAR_HEIGHT
=
44
;
const
NAVBAR_HEIGHT
=
44
;
const
TABBAR_HEIGHT
=
50
;
const
TABBAR_HEIGHT
=
50
;
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
const
RESPONSIVE_MIN_WIDTH
=
768
;
const
RESPONSIVE_MIN_WIDTH
=
768
;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
;
const
PRIMARY_COLOR
=
'
#007aff
'
;
const
PRIMARY_COLOR
=
'
#007aff
'
;
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
addFont
,
debounce
,
decode
,
decodedQuery
,
getLen
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
addFont
,
debounce
,
decode
,
decodedQuery
,
getLen
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/constants.ts
浏览文件 @
2bc43dfa
export
const
NAVBAR_HEIGHT
=
44
export
const
NAVBAR_HEIGHT
=
44
export
const
TABBAR_HEIGHT
=
50
export
const
TABBAR_HEIGHT
=
50
export
const
ON_REACH_BOTTOM_DISTANCE
=
50
export
const
RESPONSIVE_MIN_WIDTH
=
768
export
const
RESPONSIVE_MIN_WIDTH
=
768
export
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
export
const
COMPONENT_NAME_PREFIX
=
'
VUni
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录