Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
5f44b33e
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,发现更多精彩内容 >>
提交
5f44b33e
编写于
2月 18, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue scroll-view
上级
e3b2f59d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
145 addition
and
11 deletion
+145
-11
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+1
-0
packages/uni-app-vite/src/nvue/plugin/index.ts
packages/uni-app-vite/src/nvue/plugin/index.ts
+2
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformRootNode.ts
...-app-vite/src/nvue/plugin/transforms/transformRootNode.ts
+103
-0
packages/uni-app-vite/src/nvue/plugin/transforms/transformScrollView.ts
...pp-vite/src/nvue/plugin/transforms/transformScrollView.ts
+0
-8
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
+39
-3
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
5f44b33e
...
...
@@ -199,6 +199,7 @@ declare namespace UniApp {
backgroundColor
?:
string
maxWidth
?:
string
|
number
// app-plus
scrollIndicator
?:
'
none
'
animationType
?:
string
animationDuration
?:
number
subNVues
?:
PagesJsonPageStyleSubNVue
[]
...
...
packages/uni-app-vite/src/nvue/plugin/index.ts
浏览文件 @
5f44b33e
...
...
@@ -24,6 +24,7 @@ import { transformText } from './transforms/transformText'
import
{
createConfigResolved
}
from
'
../../plugin/configResolved
'
import
{
defaultNVueRpx2Unit
}
from
'
@dcloudio/uni-shared
'
import
{
external
,
globals
}
from
'
../utils
'
import
{
transformRootNode
}
from
'
./transforms/transformRootNode
'
const
uTags
=
{
text
:
'
u-text
'
,
...
...
@@ -38,6 +39,7 @@ const uTags = {
export
function
initNVueNodeTransforms
()
{
// 优先级必须确保 renderWhole > appendAsTree
return
[
transformRootNode
,
createTransformTag
(
uTags
),
transformText
,
transformVideo
,
...
...
packages/uni-app-vite/src/nvue/plugin/transforms/transformRootNode.ts
0 → 100644
浏览文件 @
5f44b33e
import
{
createBindDirectiveNode
}
from
'
@dcloudio/uni-cli-shared
'
import
{
AttributeNode
,
createSimpleExpression
,
DirectiveNode
,
ElementNode
,
ElementTypes
,
locStub
,
NodeTransform
,
NodeTypes
,
RootNode
,
TemplateChildNode
,
}
from
'
@vue/compiler-core
'
const
SCROLLER_COMPONENTS
=
[
'
list
'
,
'
scroller
'
,
'
scroll-view
'
,
'
waterfall
'
,
'
recycle-list
'
,
]
export
const
transformRootNode
:
NodeTransform
=
(
node
,
context
)
=>
{
if
(
node
.
type
!==
NodeTypes
.
ROOT
||
!
context
.
bindingMetadata
.
__pageOptions
)
{
return
}
const
{
disableScroll
,
scrollIndicator
}
=
context
.
bindingMetadata
.
__pageOptions
as
{
disableScroll
?:
boolean
scrollIndicator
?:
'
none
'
}
// 禁用滚动,或已包含滚动元素
if
(
disableScroll
||
hasScrollerElement
(
node
))
{
return
wrapperByView
(
node
)
}
return
wrapperByScrollView
(
node
,
{
scrollIndicator
})
}
function
hasScrollerElement
(
node
:
RootNode
)
{
return
node
.
children
.
some
((
child
)
=>
{
if
(
child
.
type
===
NodeTypes
.
ELEMENT
)
{
return
SCROLLER_COMPONENTS
.
includes
(
child
.
tag
)
}
})
}
function
wrapperByScrollView
(
node
:
RootNode
,
{
scrollIndicator
}:
{
scrollIndicator
?:
'
none
'
}
)
{
node
.
children
=
[
createElement
(
'
scroll-view
'
,
createScrollViewProps
({
scrollIndicator
}),
node
.
children
),
]
}
const
trueExpr
=
createSimpleExpression
(
'
true
'
)
const
falseExpr
=
createSimpleExpression
(
'
false
'
)
function
createScrollViewProps
({
scrollIndicator
,
}:
{
scrollIndicator
?:
'
none
'
})
{
return
[
createBindDirectiveNode
(
'
scrollY
'
,
trueExpr
),
createBindDirectiveNode
(
'
showScrollbar
'
,
scrollIndicator
===
'
none
'
?
falseExpr
:
trueExpr
),
createBindDirectiveNode
(
'
enableBackToTop
'
,
trueExpr
),
createBindDirectiveNode
(
'
bubble
'
,
trueExpr
),
createBindDirectiveNode
(
'
style
'
,
`{flexDirection:'column'}`
),
]
}
/**
* 目前暂不支持多节点,故发现多节点时,自动补充一个 view 根节点
* @param node
*/
function
wrapperByView
(
node
:
RootNode
)
{
if
(
node
.
children
.
length
>
1
)
{
node
.
children
=
[
createElement
(
'
view
'
,
[],
node
.
children
)]
}
}
function
createElement
(
tag
:
string
,
props
:
(
AttributeNode
|
DirectiveNode
)[],
children
:
TemplateChildNode
[]
):
ElementNode
{
return
{
type
:
NodeTypes
.
ELEMENT
,
ns
:
0
,
tag
,
isSelfClosing
:
false
,
props
,
children
,
tagType
:
ElementTypes
.
ELEMENT
,
codegenNode
:
undefined
,
loc
:
locStub
,
}
}
packages/uni-app-vite/src/nvue/plugin/transforms/transformScrollView.ts
已删除
100644 → 0
浏览文件 @
e3b2f59d
import
{
NodeTransform
,
NodeTypes
}
from
'
@vue/compiler-core
'
export
const
transformScrollView
:
NodeTransform
=
(
node
,
context
)
=>
{
if
(
node
.
type
!==
NodeTypes
.
ROOT
)
{
return
}
console
.
log
(
context
)
}
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
浏览文件 @
5f44b33e
import
path
from
'
path
'
import
{
Plugin
}
from
'
vite
'
import
type
{
Plugin
}
from
'
vite
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-sfc
'
import
{
defineUniPagesJsonPlugin
,
normalizeAppConfigService
,
...
...
@@ -9,8 +9,17 @@ import {
getLocaleFiles
,
normalizeAppNVuePagesJson
,
APP_CONFIG_SERVICE
,
resolveBuiltIn
,
normalizePath
,
}
from
'
@dcloudio/uni-cli-shared
'
interface
NVuePages
{
[
filename
:
string
]:
{
disableScroll
?:
boolean
scrollIndicator
?:
'
none
'
}
}
export
function
uniPagesJsonPlugin
({
renderer
,
appService
,
...
...
@@ -18,6 +27,11 @@ export function uniPagesJsonPlugin({
renderer
?:
'
native
'
appService
:
boolean
}):
Plugin
{
const
nvuePages
:
NVuePages
=
{}
// 仅编译nvue页面时重写
if
(
!
appService
)
{
rewriteBindingMetadata
(
nvuePages
)
}
return
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-nvue-pages-json
'
,
...
...
@@ -35,9 +49,14 @@ export function uniPagesJsonPlugin({
const
pagesJson
=
normalizePagesJson
(
code
,
process
.
env
.
UNI_PLATFORM
)
pagesJson
.
pages
.
forEach
((
page
)
=>
{
if
(
page
.
style
.
isNVue
)
{
this
.
addWatchFile
(
const
filename
=
normalizePath
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
page
.
path
+
'
.nvue
'
)
)
nvuePages
[
filename
]
=
{
disableScroll
:
page
.
style
.
disableScroll
,
scrollIndicator
:
page
.
style
.
scrollIndicator
,
}
this
.
addWatchFile
(
filename
)
}
})
if
(
renderer
===
'
native
'
&&
appService
)
{
...
...
@@ -62,3 +81,20 @@ export function uniPagesJsonPlugin({
}
})
}
/**
* 在 BindingMetadata 中补充页面标记
*/
function
rewriteBindingMetadata
(
nvuePages
:
NVuePages
)
{
const
compilerDom
=
require
(
resolveBuiltIn
(
'
@vue/compiler-dom
'
))
const
{
compile
}
=
compilerDom
compilerDom
.
compile
=
(
template
:
string
,
options
:
CompilerOptions
=
{})
=>
{
if
(
options
.
filename
&&
options
.
bindingMetadata
)
{
if
(
nvuePages
[
options
.
filename
])
{
;(
options
.
bindingMetadata
as
any
).
__pageOptions
=
nvuePages
[
options
.
filename
]
}
}
return
compile
(
template
,
options
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录