Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
4f88281d
U
uni-app
项目概览
DCloud
/
uni-app
2 天 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4f88281d
编写于
9月 29, 2019
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: nvue 支持 uni.createSelectorQuery (仅支持id)
上级
73a47030
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
191 addition
and
3 deletion
+191
-3
src/platforms/app-plus-nvue/service/api/index.js
src/platforms/app-plus-nvue/service/api/index.js
+3
-1
src/platforms/app-plus-nvue/service/api/ui/create-selector-query.js
...rms/app-plus-nvue/service/api/ui/create-selector-query.js
+185
-0
src/platforms/app-plus-nvue/services/api/legacy/api.js
src/platforms/app-plus-nvue/services/api/legacy/api.js
+3
-2
未找到文件。
src/platforms/app-plus-nvue/service/api/index.js
浏览文件 @
4f88281d
...
...
@@ -2,10 +2,12 @@ export * from './context/live-pusher'
export
*
from
'
./context/map
'
export
*
from
'
./context/video
'
export
*
from
'
./ui/create-selector-query
'
export
*
from
'
./plugin/require-native-plugin
'
export
*
from
'
./route/navigate-back
'
export
*
from
'
./route/navigate-to
'
export
*
from
'
./route/re-launch
'
export
*
from
'
./route/redirect-to
'
export
*
from
'
./route/switch-tab
'
export
*
from
'
./route/switch-tab
'
src/platforms/app-plus-nvue/service/api/ui/create-selector-query.js
0 → 100644
浏览文件 @
4f88281d
import
{
isFn
}
from
'
uni-shared
'
class
NodesRef
{
constructor
(
selectorQuery
,
component
,
selector
,
single
)
{
this
.
_selectorQuery
=
selectorQuery
this
.
_component
=
component
this
.
_selector
=
selector
this
.
_single
=
single
}
boundingClientRect
(
callback
)
{
this
.
_selectorQuery
.
_push
(
this
.
_selector
,
this
.
_component
,
this
.
_single
,
{
id
:
true
,
dataset
:
true
,
rect
:
true
,
size
:
true
},
callback
)
return
this
.
_selectorQuery
}
fields
(
fields
,
callback
)
{
this
.
_selectorQuery
.
_push
(
this
.
_selector
,
this
.
_component
,
this
.
_single
,
fields
,
callback
)
return
this
.
_selectorQuery
}
scrollOffset
(
callback
)
{
this
.
_selectorQuery
.
_push
(
this
.
_selector
,
this
.
_component
,
this
.
_single
,
{
id
:
true
,
dataset
:
true
,
scrollOffset
:
true
},
callback
)
return
this
.
_selectorQuery
}
}
function
processDataset
(
attr
)
{
const
dataset
=
{}
Object
.
keys
(
attr
||
{}).
forEach
(
key
=>
{
if
(
key
.
indexOf
(
'
data
'
)
===
0
)
{
let
str
=
key
.
replace
(
'
data
'
,
''
)
str
=
str
.
charAt
(
0
).
toLowerCase
()
+
str
.
slice
(
1
)
dataset
[
str
]
=
attr
[
key
]
}
})
return
dataset
}
function
findAttrs
(
ids
,
elm
,
result
)
{
let
nodes
=
elm
.
children
if
(
!
Array
.
isArray
(
nodes
))
{
return
false
}
for
(
let
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
let
node
=
nodes
[
i
]
if
(
node
.
attr
)
{
let
index
=
ids
.
indexOf
(
'
#
'
+
node
.
attr
.
id
)
if
(
index
>=
0
)
{
result
[
index
]
=
{
id
:
ids
[
index
],
ref
:
node
.
ref
,
dataset
:
processDataset
(
node
.
attr
)
}
if
(
ids
.
length
===
1
)
{
break
}
}
}
if
(
node
.
children
)
{
findAttrs
(
ids
,
node
,
result
)
}
}
}
function
getSelectors
(
queue
)
{
let
ids
=
[]
for
(
let
i
=
0
;
i
<
queue
.
length
;
i
++
)
{
const
selector
=
queue
[
i
].
selector
if
(
selector
.
indexOf
(
'
#
'
)
===
0
)
{
ids
.
push
(
selector
)
}
}
return
ids
}
function
getComponentRectAll
(
dom
,
attrs
,
index
,
result
,
callback
)
{
const
attr
=
attrs
[
index
]
dom
.
getComponentRect
(
attr
.
ref
,
option
=>
{
option
.
size
.
id
=
attr
.
id
option
.
size
.
dataset
=
attr
.
dataset
result
.
push
(
option
.
size
)
index
+=
1
if
(
index
<
attrs
.
length
)
{
getComponentRectAll
(
dom
,
attrs
,
index
,
result
,
callback
)
}
else
{
callback
(
result
)
}
})
}
function
requestComponentInfo
(
dom
,
component
,
queue
,
callback
)
{
const
selectors
=
getSelectors
(
queue
)
let
outAttrs
=
new
Array
(
selectors
.
length
)
findAttrs
(
selectors
,
component
.
$el
,
outAttrs
)
getComponentRectAll
(
dom
,
outAttrs
,
0
,
[],
(
result
)
=>
{
callback
(
result
)
})
}
class
SelectorQuery
{
constructor
(
pageId
)
{
this
.
pageId
=
pageId
this
.
_queue
=
[]
this
.
_queueCb
=
[]
}
exec
(
callback
)
{
if
(
!
this
.
_component
)
{
return
}
this
.
_dom
=
this
.
_component
.
_$weex
.
requireModule
(
'
dom
'
)
requestComponentInfo
(
this
.
_dom
,
this
.
_component
,
this
.
_queue
,
res
=>
{
const
queueCbs
=
this
.
_queueCb
res
.
forEach
((
result
,
index
)
=>
{
const
queueCb
=
queueCbs
[
index
]
if
(
isFn
(
queueCb
))
{
queueCb
.
call
(
this
,
result
)
}
})
isFn
(
callback
)
&&
callback
.
call
(
this
,
res
)
})
}
[
'
in
'
]
(
component
)
{
if
(
!
component
)
{
return
console
.
warn
(
'
uni.createSelectorQuery 必须传入当前 vm 对象(this)
'
)
}
this
.
_component
=
component
return
this
}
select
(
selector
)
{
return
new
NodesRef
(
this
,
this
.
_component
,
selector
,
true
)
}
selectAll
(
selector
)
{
return
new
NodesRef
(
this
,
this
.
_component
,
selector
,
false
)
}
selectViewport
()
{
return
new
NodesRef
(
this
,
0
,
''
,
true
)
}
_push
(
selector
,
component
,
single
,
fields
,
callback
)
{
this
.
_queue
.
push
({
component
,
selector
,
single
,
fields
})
this
.
_queueCb
.
push
(
callback
)
}
}
export
function
createSelectorQuery
()
{
return
new
SelectorQuery
()
}
src/platforms/app-plus-nvue/services/api/legacy/api.js
浏览文件 @
4f88281d
...
...
@@ -13,5 +13,6 @@ export {
export
*
from
'
../../../service/api/context/map
'
export
*
from
'
../../../service/api/context/video
'
export
*
from
'
../../../service/api/context/live-pusher
'
export
*
from
'
uni-core/service/api/base/interceptor
'
export
*
from
'
../../../service/api/context/live-pusher
'
export
*
from
'
../../../service/api/ui/create-selector-query
'
export
*
from
'
uni-core/service/api/base/interceptor
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录