Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
018baeab
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
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) {
...
@@ -3515,8 +3515,10 @@ function normalizeRouteKey(path, id2) {
function
useKeepAliveRoute
()
{
function
useKeepAliveRoute
()
{
const
route
=
useRoute
();
const
route
=
useRoute
();
const
routeKey
=
computed
(()
=>
normalizeRouteKey
(
route
.
path
,
history
.
state
.
__id__
||
1
));
const
routeKey
=
computed
(()
=>
normalizeRouteKey
(
route
.
path
,
history
.
state
.
__id__
||
1
));
const
isTabBar
=
computed
(()
=>
route
.
meta
.
isTabBar
);
return
{
return
{
routeKey
,
routeKey
,
isTabBar
,
routeCache
routeCache
};
};
}
}
...
@@ -3541,16 +3543,7 @@ const routeCache = {
...
@@ -3541,16 +3543,7 @@ const routeCache = {
}
}
};
};
function
isTabBarVNode
(
vnode
)
{
function
isTabBarVNode
(
vnode
)
{
if
(
!
hasOwn$1
(
vnode
,
"
__isTabBar
"
))
{
return
vnode
.
props
.
type
===
"
tabBar
"
;
const
{
component
}
=
vnode
;
if
(
component
&&
component
.
refs
.
page
)
{
const
vm
=
component
.
refs
.
page
;
if
(
vm
.
$page
)
{
vnode
.
__isTabBar
=
vm
.
__isTabBar
;
}
}
}
return
vnode
.
__isTabBar
;
}
}
function
pruneRouteCache
(
key
)
{
function
pruneRouteCache
(
key
)
{
const
pageId
=
parseInt
(
key
.
split
(
SEP
)[
1
]);
const
pageId
=
parseInt
(
key
.
split
(
SEP
)[
1
]);
...
@@ -3570,9 +3563,33 @@ function pruneRouteCache(key) {
...
@@ -3570,9 +3563,33 @@ function pruneRouteCache(key) {
});
});
}
}
function
onPageShow
(
instance2
,
pageMeta
)
{
function
onPageShow
(
instance2
,
pageMeta
)
{
updateBodyScopeId
(
instance2
);
updateCurPageCssVar
(
pageMeta
);
updateCurPageCssVar
(
pageMeta
);
initPageScrollListener
(
instance2
,
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
;
let
curScrollListener
;
function
initPageScrollListener
(
instance2
,
pageMeta
)
{
function
initPageScrollListener
(
instance2
,
pageMeta
)
{
document
.
removeEventListener
(
"
touchmove
"
,
disableScrollListener
);
document
.
removeEventListener
(
"
touchmove
"
,
disableScrollListener
);
...
@@ -3698,13 +3715,14 @@ function setupPage(comp) {
...
@@ -3698,13 +3715,14 @@ function setupPage(comp) {
}
}
const
pageMeta
=
usePageMeta
();
const
pageMeta
=
usePageMeta
();
onBeforeMount
(()
=>
{
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance2
;
onPageShow
(
instance2
,
pageMeta
);
onPageShow
(
instance2
,
pageMeta
);
const
{
onLoad
,
onShow
}
=
instance2
;
onLoad
&&
invokeArrayFns$1
(
onLoad
,
decodedQuery
(
route
.
query
));
onLoad
&&
invokeArrayFns$1
(
onLoad
,
decodedQuery
(
route
.
query
));
instance2
.
__isVisible
=
true
;
instance2
.
__isVisible
=
true
;
onShow
&&
invokeArrayFns$1
(
onShow
);
onShow
&&
invokeArrayFns$1
(
onShow
);
});
});
onMounted
(()
=>
{
onMounted
(()
=>
{
onPageReady
(
instance2
);
const
{
onReady
}
=
instance2
;
const
{
onReady
}
=
instance2
;
onReady
&&
invokeArrayFns$1
(
onReady
);
onReady
&&
invokeArrayFns$1
(
onReady
);
});
});
...
@@ -12698,14 +12716,13 @@ function removeNonTabBarPages() {
...
@@ -12698,14 +12716,13 @@ function removeNonTabBarPages() {
const
keys
=
pagesMap
.
keys
();
const
keys
=
pagesMap
.
keys
();
for
(
const
routeKey
of
keys
)
{
for
(
const
routeKey
of
keys
)
{
const
page
=
pagesMap
.
get
(
routeKey
);
const
page
=
pagesMap
.
get
(
routeKey
);
const
pageMeta
=
page
.
$page
.
meta
;
if
(
!
page
.
__isTabBar
)
{
if
(
!
pageMeta
.
isTabBar
)
{
removePage
(
routeKey
);
removePage
(
routeKey
);
}
else
{
}
else
{
page
.
$
.
__isActive
=
false
;
page
.
$
.
__isActive
=
false
;
}
}
}
}
if
(
curTabBarPageVm
.
$page
.
meta
.
isTabBar
)
{
if
(
curTabBarPageVm
.
__
isTabBar
)
{
curTabBarPageVm
.
$
.
__isVisible
=
false
;
curTabBarPageVm
.
$
.
__isVisible
=
false
;
invokeHook
(
curTabBarPageVm
,
"
onHide
"
);
invokeHook
(
curTabBarPageVm
,
"
onHide
"
);
}
}
...
@@ -13447,15 +13464,20 @@ function createTabBarTsx(showTabBar2) {
...
@@ -13447,15 +13464,20 @@ function createTabBarTsx(showTabBar2) {
function
createPageVNode
()
{
function
createPageVNode
()
{
return
createVNode
(
__uniRoutes
[
0
].
component
);
return
createVNode
(
__uniRoutes
[
0
].
component
);
}
}
function
createRouterViewVNode
(
keepAliveRoute
)
{
function
createRouterViewVNode
({
routeKey
,
isTabBar
,
routeCache
:
routeCache2
})
{
return
createVNode
(
RouterView
,
null
,
{
return
createVNode
(
RouterView
,
null
,
{
default
:
withCtx
(({
default
:
withCtx
(({
Component
Component
})
=>
[(
openBlock
(),
createBlock
(
KeepAlive
,
{
})
=>
[(
openBlock
(),
createBlock
(
KeepAlive
,
{
matchBy
:
"
key
"
,
matchBy
:
"
key
"
,
cache
:
keepAliveRoute
.
routeCache
cache
:
routeCache2
},
[(
openBlock
(),
createBlock
(
resolveDynamicComponent
(
Component
),
{
},
[(
openBlock
(),
createBlock
(
resolveDynamicComponent
(
Component
),
{
key
:
keepAliveRoute
.
routeKey
.
value
type
:
isTabBar
.
value
?
"
tabBar
"
:
""
,
key
:
routeKey
.
value
}))],
1032
,
[
"
cache
"
]))]),
}))],
1032
,
[
"
cache
"
]))]),
_
:
1
_
:
1
});
});
...
...
packages/uni-h5/src/framework/components/layout/index.tsx
浏览文件 @
018baeab
...
@@ -118,19 +118,22 @@ function createPageVNode() {
...
@@ -118,19 +118,22 @@ function createPageVNode() {
return
createVNode
(
__uniRoutes
[
0
].
component
)
return
createVNode
(
__uniRoutes
[
0
].
component
)
}
}
function
createRouterViewVNode
(
function
createRouterViewVNode
({
keepAliveRoute
:
ReturnType
<
typeof
useKeepAliveRoute
>
routeKey
,
)
{
isTabBar
,
routeCache
,
}:
ReturnType
<
typeof
useKeepAliveRoute
>
)
{
return
createVNode
(
RouterView
,
null
,
{
return
createVNode
(
RouterView
,
null
,
{
default
:
withCtx
(({
Component
}:
{
Component
:
unknown
})
=>
[
default
:
withCtx
(({
Component
}:
{
Component
:
unknown
})
=>
[
(
openBlock
(),
(
openBlock
(),
createBlock
(
createBlock
(
KeepAlive
,
KeepAlive
,
{
matchBy
:
'
key
'
,
cache
:
keepAliveRoute
.
routeCache
},
{
matchBy
:
'
key
'
,
cache
:
routeCache
},
[
[
(
openBlock
(),
(
openBlock
(),
createBlock
(
resolveDynamicComponent
(
Component
),
{
createBlock
(
resolveDynamicComponent
(
Component
),
{
key
:
keepAliveRoute
.
routeKey
.
value
,
type
:
isTabBar
.
value
?
'
tabBar
'
:
''
,
key
:
routeKey
.
value
,
})),
})),
],
],
1032
/* PROPS, DYNAMIC_SLOTS */
,
1032
/* PROPS, DYNAMIC_SLOTS */
,
...
...
packages/uni-h5/src/framework/setup/index.ts
浏览文件 @
018baeab
...
@@ -15,7 +15,7 @@ import { useRouter } from 'vue-router'
...
@@ -15,7 +15,7 @@ import { useRouter } from 'vue-router'
import
{
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
,
onPageShow
}
from
'
./page
'
import
{
initPage
,
onPageShow
,
onPageReady
}
from
'
./page
'
import
{
usePageMeta
,
usePageRoute
}
from
'
./provide
'
import
{
usePageMeta
,
usePageRoute
}
from
'
./provide
'
interface
SetupComponentOptions
{
interface
SetupComponentOptions
{
...
@@ -61,13 +61,14 @@ export function setupPage(comp: any) {
...
@@ -61,13 +61,14 @@ export function setupPage(comp: any) {
}
}
const
pageMeta
=
usePageMeta
()
const
pageMeta
=
usePageMeta
()
onBeforeMount
(()
=>
{
onBeforeMount
(()
=>
{
const
{
onLoad
,
onShow
}
=
instance
onPageShow
(
instance
,
pageMeta
)
onPageShow
(
instance
,
pageMeta
)
const
{
onLoad
,
onShow
}
=
instance
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
onLoad
&&
invokeArrayFns
(
onLoad
,
decodedQuery
(
route
.
query
))
instance
.
__isVisible
=
true
instance
.
__isVisible
=
true
onShow
&&
invokeArrayFns
(
onShow
)
onShow
&&
invokeArrayFns
(
onShow
)
})
})
onMounted
(()
=>
{
onMounted
(()
=>
{
onPageReady
(
instance
)
const
{
onReady
}
=
instance
const
{
onReady
}
=
instance
onReady
&&
invokeArrayFns
(
onReady
)
onReady
&&
invokeArrayFns
(
onReady
)
})
})
...
...
packages/uni-h5/src/framework/setup/page.ts
浏览文件 @
018baeab
...
@@ -6,7 +6,6 @@ import {
...
@@ -6,7 +6,6 @@ import {
ComponentPublicInstance
,
ComponentPublicInstance
,
ComponentInternalInstance
,
ComponentInternalInstance
,
}
from
'
vue
'
}
from
'
vue
'
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
useRoute
,
RouteLocationNormalizedLoaded
}
from
'
vue-router
'
import
{
useRoute
,
RouteLocationNormalizedLoaded
}
from
'
vue-router
'
import
{
import
{
invokeHook
,
invokeHook
,
...
@@ -120,8 +119,10 @@ export function useKeepAliveRoute() {
...
@@ -120,8 +119,10 @@ export function useKeepAliveRoute() {
const
routeKey
=
computed
(()
=>
const
routeKey
=
computed
(()
=>
normalizeRouteKey
(
route
.
path
,
history
.
state
.
__id__
||
1
)
normalizeRouteKey
(
route
.
path
,
history
.
state
.
__id__
||
1
)
)
)
const
isTabBar
=
computed
(()
=>
route
.
meta
.
isTabBar
)
return
{
return
{
routeKey
,
routeKey
,
isTabBar
,
routeCache
,
routeCache
,
}
}
}
}
...
@@ -162,16 +163,7 @@ const routeCache: KeepAliveCache = {
...
@@ -162,16 +163,7 @@ const routeCache: KeepAliveCache = {
}
}
function
isTabBarVNode
(
vnode
:
VNode
):
boolean
{
function
isTabBarVNode
(
vnode
:
VNode
):
boolean
{
if
(
!
hasOwn
(
vnode
,
'
__isTabBar
'
))
{
return
vnode
.
props
!
.
type
===
'
tabBar
'
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
}
}
function
pruneRouteCache
(
key
:
string
)
{
function
pruneRouteCache
(
key
:
string
)
{
...
@@ -197,10 +189,38 @@ export function onPageShow(
...
@@ -197,10 +189,38 @@ export function onPageShow(
instance
:
ComponentInternalInstance
,
instance
:
ComponentInternalInstance
,
pageMeta
:
UniApp
.
PageRouteMeta
pageMeta
:
UniApp
.
PageRouteMeta
)
{
)
{
updateBodyScopeId
(
instance
)
updateCurPageCssVar
(
pageMeta
)
updateCurPageCssVar
(
pageMeta
)
initPageScrollListener
(
instance
,
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
let
curScrollListener
:
(
evt
:
Event
)
=>
any
function
initPageScrollListener
(
function
initPageScrollListener
(
instance
:
ComponentInternalInstance
,
instance
:
ComponentInternalInstance
,
...
...
packages/uni-h5/src/service/api/route/switchTab.ts
浏览文件 @
018baeab
...
@@ -19,14 +19,13 @@ function removeNonTabBarPages() {
...
@@ -19,14 +19,13 @@ function removeNonTabBarPages() {
const
keys
=
pagesMap
.
keys
()
const
keys
=
pagesMap
.
keys
()
for
(
const
routeKey
of
keys
)
{
for
(
const
routeKey
of
keys
)
{
const
page
=
pagesMap
.
get
(
routeKey
)
as
ComponentPublicInstance
const
page
=
pagesMap
.
get
(
routeKey
)
as
ComponentPublicInstance
const
pageMeta
=
page
.
$page
.
meta
if
(
!
page
.
__isTabBar
)
{
if
(
!
pageMeta
.
isTabBar
)
{
removePage
(
routeKey
)
removePage
(
routeKey
)
}
else
{
}
else
{
page
.
$
.
__isActive
=
false
page
.
$
.
__isActive
=
false
}
}
}
}
if
(
curTabBarPageVm
.
$page
.
meta
.
isTabBar
)
{
if
(
curTabBarPageVm
.
__
isTabBar
)
{
curTabBarPageVm
.
$
.
__isVisible
=
false
curTabBarPageVm
.
$
.
__isVisible
=
false
invokeHook
(
curTabBarPageVm
,
'
onHide
'
)
invokeHook
(
curTabBarPageVm
,
'
onHide
'
)
}
}
...
...
packages/uni-h5/src/service/api/ui/popup/modal.tsx
浏览文件 @
018baeab
...
@@ -49,6 +49,7 @@ export default /*#__PURE__*/ defineComponent({
...
@@ -49,6 +49,7 @@ export default /*#__PURE__*/ defineComponent({
})
})
return
()
=>
{
return
()
=>
{
const
{
title
,
content
,
showCancel
,
confirmText
,
confirmColor
}
=
props
const
{
title
,
content
,
showCancel
,
confirmText
,
confirmColor
}
=
props
// TODO vue3 似乎有bug,不指定passive时,应该默认加上passive:false,否则浏览器会报警告,先看看vue3 会不会修复,若不修复,可以考虑手动addEventListener
return
(
return
(
<
Transition
name
=
"uni-fade"
>
<
Transition
name
=
"uni-fade"
>
<
uni
-
modal
v
-
show
=
{
visible
.
value
}
onTouchmove
=
{
onEventPrevent
}
>
<
uni
-
modal
v
-
show
=
{
visible
.
value
}
onTouchmove
=
{
onEventPrevent
}
>
...
...
packages/vite-plugin-uni/src/config/css.ts
浏览文件 @
018baeab
...
@@ -4,11 +4,14 @@ import { VitePluginUniResolvedOptions } from '..'
...
@@ -4,11 +4,14 @@ import { VitePluginUniResolvedOptions } from '..'
import
{
uniapp
}
from
'
../utils
'
import
{
uniapp
}
from
'
../utils
'
export
function
createCss
(
export
function
createCss
(
_
options
:
VitePluginUniResolvedOptions
options
:
VitePluginUniResolvedOptions
):
UserConfig
[
'
css
'
]
{
):
UserConfig
[
'
css
'
]
{
return
{
return
{
postcss
:
{
postcss
:
{
plugins
:
[
uniapp
(),
autoprefixer
()],
plugins
:
[
uniapp
({
page
:
options
.
platform
===
'
h5
'
?
'
uni-page-body
'
:
'
body
'
}),
autoprefixer
(),
],
},
},
preprocessorOptions
:
{
preprocessorOptions
:
{
scss
:
{},
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
selectorParser
from
'
postcss-selector-parser
'
import
{
import
{
isBuiltInComponent
,
isBuiltInComponent
,
...
@@ -6,30 +7,73 @@ import {
...
@@ -6,30 +7,73 @@ import {
}
from
'
@dcloudio/uni-shared
'
}
from
'
@dcloudio/uni-shared
'
interface
UniAppCssProcessorOptions
{
interface
UniAppCssProcessorOptions
{
page
?:
boolean
page
?:
string
unit
:
string
// 目标单位,默认rem
unit
?
:
string
// 目标单位,默认rem
unitRatio
:
number
// 单位转换比例,默认10/320
unitRatio
?
:
number
// 单位转换比例,默认10/320
unitPrecision
:
number
// 单位精度,默认5
unitPrecision
?
:
number
// 单位精度,默认5
}
}
const
defaultUniAppCssProcessorOptions
=
{
const
defaultUniAppCssProcessorOptions
=
{
page
:
false
,
page
:
'
body
'
,
unit
:
'
rem
'
,
unit
:
'
rem
'
,
unitRatio
:
10
/
320
,
unitRatio
:
10
/
320
,
unitPrecision
:
5
,
unitPrecision
:
5
,
}
}
function
transform
(
selector
:
selectorParser
.
Node
)
{
const
BG_PROPS
=
[
if
(
selector
.
type
===
'
tag
'
&&
isBuiltInComponent
(
selector
.
value
))
{
'
background
'
,
selector
.
value
=
COMPONENT_SELECTOR_PREFIX
+
selector
.
value
'
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
)
{
function
walkRules
(
opts
:
UniAppCssProcessorOptions
)
{
return
(
rule
:
Rule
)
=>
{
return
(
rule
:
Rule
)
=>
{
const
state
=
{
bg
:
false
}
rule
.
selector
=
selectorParser
((
selectors
)
=>
rule
.
selector
=
selectorParser
((
selectors
)
=>
selectors
.
walk
((
selector
)
=>
transform
(
selector
))
selectors
.
walk
((
selector
)
=>
transform
(
selector
,
opts
,
state
))
).
processSync
(
rule
.
selector
)
).
processSync
(
rule
.
selector
)
state
.
bg
&&
createBodyBackgroundRule
(
rule
)
}
}
}
}
...
@@ -44,7 +88,7 @@ function toFixed(number: number, precision: number) {
...
@@ -44,7 +88,7 @@ function toFixed(number: number, precision: number) {
return
(
Math
.
round
(
wholeNumber
/
10
)
*
10
)
/
multiplier
return
(
Math
.
round
(
wholeNumber
/
10
)
*
10
)
/
multiplier
}
}
function
walkDecls
(
opts
:
UniAppCssProcessorOptions
)
{
function
walkDecls
(
opts
:
Required
<
UniAppCssProcessorOptions
>
)
{
return
(
decl
:
Declaration
)
=>
{
return
(
decl
:
Declaration
)
=>
{
const
{
value
}
=
decl
const
{
value
}
=
decl
if
(
value
.
indexOf
(
'
rpx
'
)
===
-
1
&&
value
.
indexOf
(
'
upx
'
)
===
-
1
)
{
if
(
value
.
indexOf
(
'
rpx
'
)
===
-
1
&&
value
.
indexOf
(
'
upx
'
)
===
-
1
)
{
...
@@ -61,18 +105,14 @@ function walkDecls(opts: UniAppCssProcessorOptions) {
...
@@ -61,18 +105,14 @@ function walkDecls(opts: UniAppCssProcessorOptions) {
}
}
export
const
uniapp
=
(
opts
?:
UniAppCssProcessorOptions
)
=>
{
export
const
uniapp
=
(
opts
?:
UniAppCssProcessorOptions
)
=>
{
const
options
=
Object
.
assign
(
const
options
=
extend
({},
defaultUniAppCssProcessorOptions
,
opts
||
{})
{},
defaultUniAppCssProcessorOptions
,
opts
||
{}
)
return
{
return
{
postcssPlugin
:
'
uni-app
'
,
postcssPlugin
:
'
uni-app
'
,
prepare
()
{
prepare
()
{
return
{
return
{
OnceExit
(
root
)
{
OnceExit
(
root
)
{
root
.
walkRules
(
walkRules
(
options
))
root
.
walkDecls
(
walkDecls
(
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录