Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
1b4d1705
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
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,发现更多精彩内容 >>
提交
1b4d1705
编写于
4月 21, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add updateCssVar
上级
a9482721
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
4501 addition
and
4309 deletion
+4501
-4309
packages/uni-core/src/helpers/index.ts
packages/uni-core/src/helpers/index.ts
+1
-0
packages/uni-core/src/helpers/updateCssVar.ts
packages/uni-core/src/helpers/updateCssVar.ts
+28
-0
packages/uni-core/src/service/plugin/index.ts
packages/uni-core/src/service/plugin/index.ts
+4
-65
packages/uni-core/src/service/plugin/page.ts
packages/uni-core/src/service/plugin/page.ts
+64
-0
packages/uni-core/src/service/plugin/subscribe.ts
packages/uni-core/src/service/plugin/subscribe.ts
+20
-2
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+4298
-4227
packages/uni-h5/src/framework/components/layout/tabBar.tsx
packages/uni-h5/src/framework/components/layout/tabBar.tsx
+17
-2
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/plugin/setup.ts
packages/uni-h5/src/framework/plugin/setup.ts
+30
-12
packages/uni-h5/src/helpers/cssVar.ts
packages/uni-h5/src/helpers/cssVar.ts
+38
-0
未找到文件。
packages/uni-core/src/helpers/index.ts
浏览文件 @
1b4d1705
export
*
from
'
./util
'
export
*
from
'
./icon
'
export
*
from
'
./getRealRoute
'
export
*
from
'
./updateCssVar
'
export
*
from
'
./getWindowOffset
'
packages/uni-core/src/helpers/updateCssVar.ts
0 → 100644
浏览文件 @
1b4d1705
interface
PageCssVars
{
'
--window-top
'
?:
string
'
--window-bottom
'
?:
string
'
--window-left
'
?:
string
'
--window-right
'
?:
string
'
--window-margin
'
?:
string
'
--top-window-height
'
?:
string
}
const
style
=
document
.
documentElement
.
style
function
updateCssVar
(
cssVars
:
Record
<
string
,
any
>
)
{
Object
.
keys
(
cssVars
).
forEach
((
name
)
=>
{
style
.
setProperty
(
name
,
cssVars
[
name
])
})
}
export
function
updatePageCssVar
(
cssVars
:
PageCssVars
)
{
return
updateCssVar
(
cssVars
)
}
interface
AppCssVar
{
'
--status-bar-height
'
?:
string
'
--tab-bar-height
'
?:
string
}
export
function
updateAppCssVar
(
cssVars
:
AppCssVar
)
{
return
updateCssVar
(
cssVars
)
}
packages/uni-core/src/service/plugin/index.ts
浏览文件 @
1b4d1705
import
{
App
,
ComponentPublicInstance
}
from
'
vue
'
import
{
isString
}
from
'
@vue/shared
'
import
{
invokeArrayFns
}
from
'
@dcloudio/uni-shared
'
import
{
App
}
from
'
vue
'
import
{
initAppConfig
}
from
'
./appConfig
'
import
{
initSubscribe
}
from
'
./subscribe
'
export
*
from
'
./page
'
export
function
initService
(
app
:
App
)
{
initAppConfig
(
app
.
_context
.
config
)
}
export
function
getCurrentPage
()
{
const
pages
=
getCurrentPages
()
const
len
=
pages
.
length
if
(
len
)
{
return
pages
[
len
-
1
]
}
}
export
function
getCurrentPageMeta
()
{
const
page
=
getCurrentPage
()
if
(
page
)
{
return
page
.
$page
.
meta
}
}
export
function
getCurrentPageId
()
{
const
meta
=
getCurrentPageMeta
()
if
(
meta
)
{
return
meta
.
id
}
return
-
1
}
export
function
getCurrentPageVm
()
{
const
page
=
getCurrentPage
()
if
(
page
)
{
return
(
page
as
any
).
$vm
as
ComponentPublicInstance
}
}
export
function
invokeHook
(
name
:
string
,
args
?:
unknown
):
unknown
export
function
invokeHook
(
id
:
number
,
name
:
string
,
args
?:
unknown
):
unknown
export
function
invokeHook
(
vm
:
ComponentPublicInstance
,
name
:
string
,
args
?:
unknown
):
unknown
export
function
invokeHook
(
vm
:
ComponentPublicInstance
|
string
|
number
,
name
?:
string
|
unknown
,
args
?:
unknown
)
{
if
(
isString
(
vm
))
{
args
=
name
name
=
vm
vm
=
getCurrentPageVm
()
!
}
else
if
(
typeof
vm
===
'
number
'
)
{
const
page
=
getCurrentPages
().
find
((
page
)
=>
page
.
$page
.
id
===
vm
)
if
(
page
)
{
vm
=
(
page
as
any
).
$vm
as
ComponentPublicInstance
}
else
{
vm
=
getCurrentPageVm
()
as
ComponentPublicInstance
}
}
if
(
!
vm
)
{
return
}
const
hooks
=
vm
.
$
[
name
as
string
]
return
hooks
&&
invokeArrayFns
(
hooks
,
args
)
initSubscribe
()
}
packages/uni-core/src/service/plugin/page.ts
0 → 100644
浏览文件 @
1b4d1705
import
{
isString
}
from
'
@vue/shared
'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
invokeArrayFns
}
from
'
@dcloudio/uni-shared
'
export
function
getCurrentPage
()
{
const
pages
=
getCurrentPages
()
const
len
=
pages
.
length
if
(
len
)
{
return
pages
[
len
-
1
]
}
}
export
function
getCurrentPageMeta
()
{
const
page
=
getCurrentPage
()
if
(
page
)
{
return
page
.
$page
.
meta
}
}
export
function
getCurrentPageId
()
{
const
meta
=
getCurrentPageMeta
()
if
(
meta
)
{
return
meta
.
id
}
return
-
1
}
export
function
getCurrentPageVm
()
{
const
page
=
getCurrentPage
()
if
(
page
)
{
return
(
page
as
any
).
$vm
as
ComponentPublicInstance
}
}
export
function
invokeHook
(
name
:
string
,
args
?:
unknown
):
unknown
export
function
invokeHook
(
id
:
number
,
name
:
string
,
args
?:
unknown
):
unknown
export
function
invokeHook
(
vm
:
ComponentPublicInstance
,
name
:
string
,
args
?:
unknown
):
unknown
export
function
invokeHook
(
vm
:
ComponentPublicInstance
|
string
|
number
,
name
?:
string
|
unknown
,
args
?:
unknown
)
{
if
(
isString
(
vm
))
{
args
=
name
name
=
vm
vm
=
getCurrentPageVm
()
!
}
else
if
(
typeof
vm
===
'
number
'
)
{
const
page
=
getCurrentPages
().
find
((
page
)
=>
page
.
$page
.
id
===
vm
)
if
(
page
)
{
vm
=
(
page
as
any
).
$vm
as
ComponentPublicInstance
}
else
{
vm
=
getCurrentPageVm
()
as
ComponentPublicInstance
}
}
if
(
!
vm
)
{
return
}
const
hooks
=
vm
.
$
[
name
as
string
]
return
hooks
&&
invokeArrayFns
(
hooks
,
args
)
}
packages/uni-core/src/service/plugin/subscribe.ts
浏览文件 @
1b4d1705
import
{
ComponentPublicInstance
}
from
'
@vue/runtime-core
'
import
{
getCurrentPage
,
invokeHook
}
from
'
./page
'
export
function
initSubscribe
()
{
UniServiceJSBridge
.
on
(
'
onAppEnterForeground
'
,
()
=>
{})
UniServiceJSBridge
.
on
(
'
onAppEnterBackground
'
,
()
=>
{})
UniServiceJSBridge
.
on
(
'
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
'
)
})
UniServiceJSBridge
.
on
(
'
onAppEnterBackground
'
,
()
=>
{
invokeHook
(
getApp
()
as
ComponentPublicInstance
,
'
onHide
'
)
invokeHook
(
getCurrentPage
()
as
ComponentPublicInstance
,
'
onHide
'
)
})
}
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
1b4d1705
此差异已折叠。
点击以展开。
packages/uni-h5/src/framework/components/layout/tabBar.tsx
浏览文件 @
1b4d1705
import
{
watchEffect
,
computed
,
defineComponent
}
from
'
vue
'
import
{
watch
,
watch
Effect
,
computed
,
defineComponent
}
from
'
vue
'
import
{
RouteLocationNormalizedLoaded
,
useRoute
}
from
'
vue-router
'
import
{
invokeHook
}
from
'
@dcloudio/uni-core
'
import
{
invokeHook
,
updatePageCssVar
}
from
'
@dcloudio/uni-core
'
import
{
API_ON_TAB_BAR_MID_BUTTON_TAP
,
OnTabBarMidButtonTap
,
...
...
@@ -8,11 +8,13 @@ import {
import
{
getRealPath
}
from
'
../../../platform
'
import
{
useTabBar
}
from
'
../../plugin/state
'
import
{
cssBackdropFilter
}
from
'
../../../service/api/base/canIUse
'
import
{
normalizeWindowBottom
}
from
'
../../../helpers/cssVar
'
export
default
/*#__PURE__*/
defineComponent
({
name
:
'
TabBar
'
,
setup
()
{
const
tabBar
=
useTabBar
()
!
useTabBarCssVar
(
tabBar
)
const
onSwitchTab
=
useSwitchTab
(
useRoute
(),
tabBar
)
const
{
style
,
borderStyle
,
placeholderStyle
}
=
useTabBarStyle
(
tabBar
)
return
()
=>
{
...
...
@@ -30,6 +32,19 @@ export default /*#__PURE__*/ defineComponent({
},
})
function
useTabBarCssVar
(
tabBar
:
UniApp
.
TabBarOptions
)
{
watch
(
()
=>
tabBar
.
shown
,
(
value
)
=>
{
updatePageCssVar
({
'
--window-bottom
'
:
normalizeWindowBottom
(
value
?
parseInt
(
tabBar
.
height
!
)
:
0
),
})
}
)
}
function
useSwitchTab
(
route
:
RouteLocationNormalizedLoaded
,
tabBar
:
UniApp
.
TabBarOptions
...
...
packages/uni-h5/src/framework/components/page/pageHead.tsx
浏览文件 @
1b4d1705
import
{
computed
,
defineComponent
,
Ref
,
ref
}
from
'
vue
'
import
{
computed
,
defineComponent
,
ref
}
from
'
vue
'
import
{
isArray
}
from
'
@vue/shared
'
import
{
Input
}
from
'
@dcloudio/uni-components
'
import
{
getRealPath
}
from
'
@dcloudio/uni-platform
'
...
...
packages/uni-h5/src/framework/plugin/setup.ts
浏览文件 @
1b4d1705
import
{
extend
,
invokeArrayFns
}
from
'
@vue/shared
'
import
{
invokeArrayFns
}
from
'
@vue/shared
'
import
{
ComponentInternalInstance
,
ComponentPublicInstance
,
...
...
@@ -11,11 +11,13 @@ import {
onBeforeDeactivate
,
onBeforeMount
,
}
from
'
vue
'
import
{
useRoute
}
from
'
vue-router
'
import
{
useRoute
,
useRouter
}
from
'
vue-router
'
import
{
parseQuery
,
decodedQuery
}
from
'
@dcloudio/uni-shared
'
import
{
LayoutComponent
}
from
'
../..
'
import
{
initApp
}
from
'
./app
'
import
{
initPage
}
from
'
./page
'
import
{
usePageMeta
}
from
'
./provide
'
import
{
updateCurPageCssVar
}
from
'
../../helpers/cssVar
'
interface
SetupComponentOptions
{
init
:
(
vm
:
ComponentPublicInstance
)
=>
void
...
...
@@ -36,9 +38,11 @@ export function usePageRoute() {
url
.
slice
(
searchPos
+
1
,
hashPos
>
-
1
?
hashPos
:
url
.
length
)
)
}
const
{
meta
}
=
__uniRoutes
[
0
]
return
{
meta
:
__uniRoutes
[
0
].
meta
,
meta
,
query
:
query
,
path
:
'
/
'
+
meta
.
route
,
}
}
...
...
@@ -67,6 +71,10 @@ function setupComponent(comp: any, options: SetupComponentOptions) {
return
comp
}
function
onPageShow
(
pageMeta
:
UniApp
.
PageRouteMeta
)
{
updateCurPageCssVar
(
pageMeta
)
}
export
function
setupPage
(
comp
:
any
)
{
return
setupComponent
(
comp
,
{
init
:
initPage
,
...
...
@@ -77,8 +85,10 @@ export function setupPage(comp: any) {
//初始化时,状态肯定是激活
instance
.
__isActive
=
true
}
const
pageMeta
=
usePageMeta
()
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance
onPageShow
(
pageMeta
)
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
instance
.
__isVisible
=
true
onShow
&&
invokeArrayFns
(
onShow
)
...
...
@@ -89,6 +99,7 @@ export function setupPage(comp: any) {
})
onBeforeActivate
(()
=>
{
if
(
!
instance
.
__isVisible
)
{
onPageShow
(
pageMeta
)
instance
.
__isVisible
=
true
const
{
onShow
}
=
instance
onShow
&&
invokeArrayFns
(
onShow
)
...
...
@@ -111,16 +122,23 @@ export function setupApp(comp: any) {
init
:
initApp
,
setup
(
instance
)
{
const
route
=
usePageRoute
()
onBeforeMount
(
()
=>
{
const
onLaunch
=
()
=>
{
const
{
onLaunch
,
onShow
}
=
instance
onLaunch
&&
invokeArrayFns
(
onLaunch
,
{
path
:
route
.
meta
.
route
,
query
:
decodedQuery
(
route
.
query
),
scene
:
1001
,
})
onShow
&&
invokeArrayFns
(
onShow
)
})
const
path
=
route
.
path
.
substr
(
1
)
const
launchOptions
=
{
path
:
path
||
__uniRoutes
[
0
].
meta
.
route
,
query
:
decodedQuery
(
route
.
query
),
scene
:
1001
,
}
onLaunch
&&
invokeArrayFns
(
onLaunch
,
launchOptions
)
onShow
&&
invokeArrayFns
(
onShow
,
launchOptions
)
}
if
(
__UNI_FEATURE_PAGES__
)
{
// 等待ready后,再onLaunch,可以顺利获取到正确的path和query
useRouter
().
isReady
().
then
(
onLaunch
)
}
else
{
onBeforeMount
(
onLaunch
)
}
onMounted
(()
=>
{
document
.
addEventListener
(
'
visibilitychange
'
,
function
()
{
if
(
document
.
visibilityState
===
'
visible
'
)
{
...
...
packages/uni-h5/src/helpers/cssVar.ts
0 → 100644
浏览文件 @
1b4d1705
import
{
NAVBAR_HEIGHT
}
from
'
@dcloudio/uni-shared
'
import
{
updatePageCssVar
}
from
'
@dcloudio/uni-core
'
import
{
useTabBar
}
from
'
../framework/plugin/state
'
import
{
cssEnv
,
cssConstant
}
from
'
../service/api/base/canIUse
'
const
envMethod
=
/*#__PURE__*/
(()
=>
cssEnv
?
'
env
'
:
cssConstant
?
'
constant
'
:
''
)()
export
function
updateCurPageCssVar
(
pageMeta
:
UniApp
.
PageRouteMeta
)
{
let
windowTopValue
=
0
let
windowBottomValue
=
0
if
(
__UNI_FEATURE_NAVIGATIONBAR__
&&
[
'
default
'
,
'
float
'
].
indexOf
(
pageMeta
.
navigationBar
.
type
!
)
>
-
1
)
{
windowTopValue
=
NAVBAR_HEIGHT
}
if
(
__UNI_FEATURE_TABBAR__
&&
pageMeta
.
isTabBar
)
{
const
tabBar
=
useTabBar
()
!
tabBar
.
shown
&&
(
windowBottomValue
=
parseInt
(
tabBar
.
height
!
))
}
updatePageCssVar
({
'
--window-top
'
:
normalizeWindowBottom
(
windowTopValue
),
'
--window-bottom
'
:
normalizeWindowBottom
(
windowBottomValue
),
})
}
export
function
normalizeWindowTop
(
windowTop
:
number
)
{
return
envMethod
?
`calc(
${
windowTop
}
px +
${
envMethod
}
(safe-area-inset-top))`
:
`
${
windowTop
}
px`
}
export
function
normalizeWindowBottom
(
windowBottom
:
number
)
{
return
envMethod
?
`calc(
${
windowBottom
}
px +
${
envMethod
}
(safe-area-inset-bottom))`
:
`
${
windowBottom
}
px`
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录