Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
018baeab
U
uni-app
项目概览
MuGuiLin
/
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,发现更多精彩内容 >>
提交
018baeab
编写于
4月 23, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support page selector
上级
c26c15de
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
146 addition
and
57 deletion
+146
-57
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+39
-17
packages/uni-h5/src/framework/components/layout/index.tsx
packages/uni-h5/src/framework/components/layout/index.tsx
+8
-5
packages/uni-h5/src/framework/setup/index.ts
packages/uni-h5/src/framework/setup/index.ts
+3
-2
packages/uni-h5/src/framework/setup/page.ts
packages/uni-h5/src/framework/setup/page.ts
+31
-11
packages/uni-h5/src/service/api/route/switchTab.ts
packages/uni-h5/src/service/api/route/switchTab.ts
+2
-3
packages/uni-h5/src/service/api/ui/popup/modal.tsx
packages/uni-h5/src/service/api/ui/popup/modal.tsx
+1
-0
packages/vite-plugin-uni/src/config/css.ts
packages/vite-plugin-uni/src/config/css.ts
+5
-2
packages/vite-plugin-uni/src/utils/postcss.ts
packages/vite-plugin-uni/src/utils/postcss.ts
+57
-17
未找到文件。
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
018baeab
...
...
@@ -3515,8 +3515,10 @@ function normalizeRouteKey(path, id2) {
function
useKeepAliveRoute
()
{
const
route
=
useRoute
();
const
routeKey
=
computed
(()
=>
normalizeRouteKey
(
route
.
path
,
history
.
state
.
__id__
||
1
));
const
isTabBar
=
computed
(()
=>
route
.
meta
.
isTabBar
);
return
{
routeKey
,
isTabBar
,
routeCache
};
}
...
...
@@ -3541,16 +3543,7 @@ const routeCache = {
}
};
function
isTabBarVNode
(
vnode
)
{
if
(
!
hasOwn$1
(
vnode
,
"
__isTabBar
"
))
{
const
{
component
}
=
vnode
;
if
(
component
&&
component
.
refs
.
page
)
{
const
vm
=
component
.
refs
.
page
;
if
(
vm
.
$page
)
{
vnode
.
__isTabBar
=
vm
.
__isTabBar
;
}
}
}
return
vnode
.
__isTabBar
;
return
vnode
.
props
.
type
===
"
tabBar
"
;
}
function
pruneRouteCache
(
key
)
{
const
pageId
=
parseInt
(
key
.
split
(
SEP
)[
1
]);
...
...
@@ -3570,9 +3563,33 @@ function pruneRouteCache(key) {
});
}
function
onPageShow
(
instance2
,
pageMeta
)
{
updateBodyScopeId
(
instance2
);
updateCurPageCssVar
(
pageMeta
);
initPageScrollListener
(
instance2
,
pageMeta
);
}
function
onPageReady
(
instance2
)
{
const
scopeId
=
getScopeId
(
instance2
);
scopeId
&&
updateCurPageBodyScopeId
(
scopeId
);
}
function
updateCurPageBodyScopeId
(
scopeId
)
{
const
pageBodyEl
=
document
.
querySelector
(
"
uni-page-body
"
);
if
(
pageBodyEl
)
{
pageBodyEl
.
setAttribute
(
scopeId
,
""
);
}
else
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
)
{
console
.
warn
(
"
uni-page-body not found
"
);
}
}
function
getScopeId
(
instance2
)
{
return
instance2
.
type
.
__scopeId
;
}
let
curScopeId
;
function
updateBodyScopeId
(
instance2
)
{
const
scopeId
=
getScopeId
(
instance2
);
const
{
body
}
=
document
;
curScopeId
&&
body
.
removeAttribute
(
curScopeId
);
scopeId
&&
body
.
setAttribute
(
scopeId
,
""
);
curScopeId
=
scopeId
;
}
let
curScrollListener
;
function
initPageScrollListener
(
instance2
,
pageMeta
)
{
document
.
removeEventListener
(
"
touchmove
"
,
disableScrollListener
);
...
...
@@ -3698,13 +3715,14 @@ function setupPage(comp) {
}
const
pageMeta
=
usePageMeta
();
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance2
;
onPageShow
(
instance2
,
pageMeta
);
const
{
onLoad
,
onShow
}
=
instance2
;
onLoad
&&
invokeArrayFns$1
(
onLoad
,
decodedQuery
(
route
.
query
));
instance2
.
__isVisible
=
true
;
onShow
&&
invokeArrayFns$1
(
onShow
);
});
onMounted
(()
=>
{
onPageReady
(
instance2
);
const
{
onReady
}
=
instance2
;
onReady
&&
invokeArrayFns$1
(
onReady
);
});
...
...
@@ -12698,14 +12716,13 @@ function removeNonTabBarPages() {
const
keys
=
pagesMap
.
keys
();
for
(
const
routeKey
of
keys
)
{
const
page
=
pagesMap
.
get
(
routeKey
);
const
pageMeta
=
page
.
$page
.
meta
;
if
(
!
pageMeta
.
isTabBar
)
{
if
(
!
page
.
__isTabBar
)
{
removePage
(
routeKey
);
}
else
{
page
.
$
.
__isActive
=
false
;
}
}
if
(
curTabBarPageVm
.
$page
.
meta
.
isTabBar
)
{
if
(
curTabBarPageVm
.
__
isTabBar
)
{
curTabBarPageVm
.
$
.
__isVisible
=
false
;
invokeHook
(
curTabBarPageVm
,
"
onHide
"
);
}
...
...
@@ -13447,15 +13464,20 @@ function createTabBarTsx(showTabBar2) {
function
createPageVNode
()
{
return
createVNode
(
__uniRoutes
[
0
].
component
);
}
function
createRouterViewVNode
(
keepAliveRoute
)
{
function
createRouterViewVNode
({
routeKey
,
isTabBar
,
routeCache
:
routeCache2
})
{
return
createVNode
(
RouterView
,
null
,
{
default
:
withCtx
(({
Component
})
=>
[(
openBlock
(),
createBlock
(
KeepAlive
,
{
matchBy
:
"
key
"
,
cache
:
keepAliveRoute
.
routeCache
cache
:
routeCache2
},
[(
openBlock
(),
createBlock
(
resolveDynamicComponent
(
Component
),
{
key
:
keepAliveRoute
.
routeKey
.
value
type
:
isTabBar
.
value
?
"
tabBar
"
:
""
,
key
:
routeKey
.
value
}))],
1032
,
[
"
cache
"
]))]),
_
:
1
});
...
...
packages/uni-h5/src/framework/components/layout/index.tsx
浏览文件 @
018baeab
...
...
@@ -118,19 +118,22 @@ function createPageVNode() {
return
createVNode
(
__uniRoutes
[
0
].
component
)
}
function
createRouterViewVNode
(
keepAliveRoute
:
ReturnType
<
typeof
useKeepAliveRoute
>
)
{
function
createRouterViewVNode
({
routeKey
,
isTabBar
,
routeCache
,
}:
ReturnType
<
typeof
useKeepAliveRoute
>
)
{
return
createVNode
(
RouterView
,
null
,
{
default
:
withCtx
(({
Component
}:
{
Component
:
unknown
})
=>
[
(
openBlock
(),
createBlock
(
KeepAlive
,
{
matchBy
:
'
key
'
,
cache
:
keepAliveRoute
.
routeCache
},
{
matchBy
:
'
key
'
,
cache
:
routeCache
},
[
(
openBlock
(),
createBlock
(
resolveDynamicComponent
(
Component
),
{
key
:
keepAliveRoute
.
routeKey
.
value
,
type
:
isTabBar
.
value
?
'
tabBar
'
:
''
,
key
:
routeKey
.
value
,
})),
],
1032
/* PROPS, DYNAMIC_SLOTS */
,
...
...
packages/uni-h5/src/framework/setup/index.ts
浏览文件 @
018baeab
...
...
@@ -15,7 +15,7 @@ import { useRouter } from 'vue-router'
import
{
decodedQuery
}
from
'
@dcloudio/uni-shared
'
import
{
LayoutComponent
}
from
'
../..
'
import
{
initApp
}
from
'
./app
'
import
{
initPage
,
onPageShow
}
from
'
./page
'
import
{
initPage
,
onPageShow
,
onPageReady
}
from
'
./page
'
import
{
usePageMeta
,
usePageRoute
}
from
'
./provide
'
interface
SetupComponentOptions
{
...
...
@@ -61,13 +61,14 @@ export function setupPage(comp: any) {
}
const
pageMeta
=
usePageMeta
()
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance
onPageShow
(
instance
,
pageMeta
)
const
{
onLoad
,
onShow
}
=
instance
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
instance
.
__isVisible
=
true
onShow
&&
invokeArrayFns
(
onShow
)
})
onMounted
(()
=>
{
onPageReady
(
instance
)
const
{
onReady
}
=
instance
onReady
&&
invokeArrayFns
(
onReady
)
})
...
...
packages/uni-h5/src/framework/setup/page.ts
浏览文件 @
018baeab
...
...
@@ -6,7 +6,6 @@ import {
ComponentPublicInstance
,
ComponentInternalInstance
,
}
from
'
vue
'
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
useRoute
,
RouteLocationNormalizedLoaded
}
from
'
vue-router
'
import
{
invokeHook
,
...
...
@@ -120,8 +119,10 @@ export function useKeepAliveRoute() {
const
routeKey
=
computed
(()
=>
normalizeRouteKey
(
route
.
path
,
history
.
state
.
__id__
||
1
)
)
const
isTabBar
=
computed
(()
=>
route
.
meta
.
isTabBar
)
return
{
routeKey
,
isTabBar
,
routeCache
,
}
}
...
...
@@ -162,16 +163,7 @@ const routeCache: KeepAliveCache = {
}
function
isTabBarVNode
(
vnode
:
VNode
):
boolean
{
if
(
!
hasOwn
(
vnode
,
'
__isTabBar
'
))
{
const
{
component
}
=
vnode
if
(
component
&&
component
.
refs
.
page
)
{
const
vm
=
component
.
refs
.
page
as
ComponentPublicInstance
if
(
vm
.
$page
)
{
;(
vnode
as
any
).
__isTabBar
=
vm
.
__isTabBar
}
}
}
return
(
vnode
as
any
).
__isTabBar
return
vnode
.
props
!
.
type
===
'
tabBar
'
}
function
pruneRouteCache
(
key
:
string
)
{
...
...
@@ -197,10 +189,38 @@ export function onPageShow(
instance
:
ComponentInternalInstance
,
pageMeta
:
UniApp
.
PageRouteMeta
)
{
updateBodyScopeId
(
instance
)
updateCurPageCssVar
(
pageMeta
)
initPageScrollListener
(
instance
,
pageMeta
)
}
export
function
onPageReady
(
instance
:
ComponentInternalInstance
)
{
const
scopeId
=
getScopeId
(
instance
)
scopeId
&&
updateCurPageBodyScopeId
(
scopeId
)
}
function
updateCurPageBodyScopeId
(
scopeId
:
string
)
{
const
pageBodyEl
=
document
.
querySelector
(
'
uni-page-body
'
)
if
(
pageBodyEl
)
{
pageBodyEl
.
setAttribute
(
scopeId
,
''
)
}
else
if
(
__DEV__
)
{
console
.
warn
(
'
uni-page-body not found
'
)
}
}
function
getScopeId
(
instance
:
ComponentInternalInstance
)
{
return
(
instance
.
type
as
any
).
__scopeId
}
let
curScopeId
:
string
function
updateBodyScopeId
(
instance
:
ComponentInternalInstance
)
{
const
scopeId
=
getScopeId
(
instance
)
const
{
body
}
=
document
curScopeId
&&
body
.
removeAttribute
(
curScopeId
!
)
scopeId
&&
body
.
setAttribute
(
scopeId
,
''
)
curScopeId
=
scopeId
!
}
let
curScrollListener
:
(
evt
:
Event
)
=>
any
function
initPageScrollListener
(
instance
:
ComponentInternalInstance
,
...
...
packages/uni-h5/src/service/api/route/switchTab.ts
浏览文件 @
018baeab
...
...
@@ -19,14 +19,13 @@ function removeNonTabBarPages() {
const
keys
=
pagesMap
.
keys
()
for
(
const
routeKey
of
keys
)
{
const
page
=
pagesMap
.
get
(
routeKey
)
as
ComponentPublicInstance
const
pageMeta
=
page
.
$page
.
meta
if
(
!
pageMeta
.
isTabBar
)
{
if
(
!
page
.
__isTabBar
)
{
removePage
(
routeKey
)
}
else
{
page
.
$
.
__isActive
=
false
}
}
if
(
curTabBarPageVm
.
$page
.
meta
.
isTabBar
)
{
if
(
curTabBarPageVm
.
__
isTabBar
)
{
curTabBarPageVm
.
$
.
__isVisible
=
false
invokeHook
(
curTabBarPageVm
,
'
onHide
'
)
}
...
...
packages/uni-h5/src/service/api/ui/popup/modal.tsx
浏览文件 @
018baeab
...
...
@@ -49,6 +49,7 @@ export default /*#__PURE__*/ defineComponent({
})
return
()
=>
{
const
{
title
,
content
,
showCancel
,
confirmText
,
confirmColor
}
=
props
// TODO vue3 似乎有bug,不指定passive时,应该默认加上passive:false,否则浏览器会报警告,先看看vue3 会不会修复,若不修复,可以考虑手动addEventListener
return
(
<
Transition
name
=
"uni-fade"
>
<
uni
-
modal
v
-
show
=
{
visible
.
value
}
onTouchmove
=
{
onEventPrevent
}
>
...
...
packages/vite-plugin-uni/src/config/css.ts
浏览文件 @
018baeab
...
...
@@ -4,11 +4,14 @@ import { VitePluginUniResolvedOptions } from '..'
import
{
uniapp
}
from
'
../utils
'
export
function
createCss
(
_
options
:
VitePluginUniResolvedOptions
options
:
VitePluginUniResolvedOptions
):
UserConfig
[
'
css
'
]
{
return
{
postcss
:
{
plugins
:
[
uniapp
(),
autoprefixer
()],
plugins
:
[
uniapp
({
page
:
options
.
platform
===
'
h5
'
?
'
uni-page-body
'
:
'
body
'
}),
autoprefixer
(),
],
},
preprocessorOptions
:
{
scss
:
{},
...
...
packages/vite-plugin-uni/src/utils/postcss.ts
浏览文件 @
018baeab
import
{
Rule
,
Declaration
,
Plugin
}
from
'
postcss
'
import
{
extend
}
from
'
@vue/shared
'
import
{
rule
,
Rule
,
Declaration
,
Plugin
}
from
'
postcss
'
import
selectorParser
from
'
postcss-selector-parser
'
import
{
isBuiltInComponent
,
...
...
@@ -6,30 +7,73 @@ import {
}
from
'
@dcloudio/uni-shared
'
interface
UniAppCssProcessorOptions
{
page
?:
boolean
unit
:
string
// 目标单位,默认rem
unitRatio
:
number
// 单位转换比例,默认10/320
unitPrecision
:
number
// 单位精度,默认5
page
?:
string
unit
?
:
string
// 目标单位,默认rem
unitRatio
?
:
number
// 单位转换比例,默认10/320
unitPrecision
?
:
number
// 单位精度,默认5
}
const
defaultUniAppCssProcessorOptions
=
{
page
:
false
,
page
:
'
body
'
,
unit
:
'
rem
'
,
unitRatio
:
10
/
320
,
unitPrecision
:
5
,
}
function
transform
(
selector
:
selectorParser
.
Node
)
{
if
(
selector
.
type
===
'
tag
'
&&
isBuiltInComponent
(
selector
.
value
))
{
selector
.
value
=
COMPONENT_SELECTOR_PREFIX
+
selector
.
value
const
BG_PROPS
=
[
'
background
'
,
'
background-clip
'
,
'
background-color
'
,
'
background-image
'
,
'
background-origin
'
,
'
background-position
'
,
'
background-repeat
'
,
'
background-size
'
,
'
background-attachment
'
,
]
function
transform
(
selector
:
selectorParser
.
Node
,
opts
:
UniAppCssProcessorOptions
,
state
:
{
bg
:
boolean
}
)
{
if
(
selector
.
type
!==
'
tag
'
)
{
return
}
const
{
value
}
=
selector
if
(
isBuiltInComponent
(
value
))
{
selector
.
value
=
COMPONENT_SELECTOR_PREFIX
+
value
}
else
if
(
value
===
'
page
'
)
{
const
{
page
}
=
opts
if
(
!
page
)
{
return
}
selector
.
value
=
page
if
(
page
!==
'
body
'
)
{
state
.
bg
=
true
}
}
}
function
createBodyBackgroundRule
(
origRule
:
Rule
)
{
const
bgDecls
:
Declaration
[]
=
[]
origRule
.
walkDecls
((
decl
)
=>
{
if
(
BG_PROPS
.
indexOf
(
decl
.
prop
)
!==
-
1
)
{
bgDecls
.
push
(
decl
.
clone
())
}
})
if
(
bgDecls
.
length
)
{
origRule
.
after
(
rule
({
selector
:
'
body
'
}).
append
(
bgDecls
))
}
}
function
walkRules
(
opts
:
UniAppCssProcessorOptions
)
{
return
(
rule
:
Rule
)
=>
{
const
state
=
{
bg
:
false
}
rule
.
selector
=
selectorParser
((
selectors
)
=>
selectors
.
walk
((
selector
)
=>
transform
(
selector
))
selectors
.
walk
((
selector
)
=>
transform
(
selector
,
opts
,
state
))
).
processSync
(
rule
.
selector
)
state
.
bg
&&
createBodyBackgroundRule
(
rule
)
}
}
...
...
@@ -44,7 +88,7 @@ function toFixed(number: number, precision: number) {
return
(
Math
.
round
(
wholeNumber
/
10
)
*
10
)
/
multiplier
}
function
walkDecls
(
opts
:
UniAppCssProcessorOptions
)
{
function
walkDecls
(
opts
:
Required
<
UniAppCssProcessorOptions
>
)
{
return
(
decl
:
Declaration
)
=>
{
const
{
value
}
=
decl
if
(
value
.
indexOf
(
'
rpx
'
)
===
-
1
&&
value
.
indexOf
(
'
upx
'
)
===
-
1
)
{
...
...
@@ -61,18 +105,14 @@ function walkDecls(opts: UniAppCssProcessorOptions) {
}
export
const
uniapp
=
(
opts
?:
UniAppCssProcessorOptions
)
=>
{
const
options
=
Object
.
assign
(
{},
defaultUniAppCssProcessorOptions
,
opts
||
{}
)
const
options
=
extend
({},
defaultUniAppCssProcessorOptions
,
opts
||
{})
return
{
postcssPlugin
:
'
uni-app
'
,
prepare
()
{
return
{
OnceExit
(
root
)
{
root
.
walkRules
(
walkRules
(
options
))
root
.
walkDecls
(
walkDecls
(
options
))
root
.
walkRules
(
walkRules
(
options
))
},
}
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录