Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
91b92481
U
uni-app
项目概览
小浣熊撸代码
/
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,发现更多精彩内容 >>
提交
91b92481
编写于
1月 14, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 优化 dataset 获取逻辑,完善非 string 类型支持
上级
2d6bcba5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
42 deletion
+26
-42
src/core/helpers/index.js
src/core/helpers/index.js
+20
-1
src/core/view/bridge/subscribe/api/request-component-info.js
src/core/view/bridge/subscribe/api/request-component-info.js
+2
-2
src/core/view/bridge/subscribe/api/request-component-observer.js
...e/view/bridge/subscribe/api/request-component-observer.js
+2
-2
src/core/view/plugins/events.js
src/core/view/plugins/events.js
+2
-2
src/platforms/app-plus/service/framework/plugins/data.js
src/platforms/app-plus/service/framework/plugins/data.js
+0
-10
src/platforms/app-plus/service/framework/plugins/vdom-sync.js
...platforms/app-plus/service/framework/plugins/vdom-sync.js
+0
-25
未找到文件。
src/core/helpers/index.js
浏览文件 @
91b92481
import
{
camelize
}
from
'
uni-shared
'
const
components
=
[
'
SystemAsyncLoading
'
,
'
SystemAsyncError
'
]
export
function
isPage
(
vm
)
{
if
(
vm
.
$parent
&&
vm
.
$parent
.
$options
.
name
===
'
PageBody
'
)
{
...
...
@@ -35,6 +39,21 @@ export function normalizeDataset (dataset = {}) {
return
result
}
export
function
getTargetDataset
(
target
)
{
let
dataset
=
{}
if
(
target
.
__vue__
)
{
const
$attrs
=
target
.
__vue__
.
$attrs
for
(
const
key
in
$attrs
)
{
if
(
key
.
startsWith
(
'
data-
'
))
{
dataset
[
camelize
(
key
.
substr
(
5
))]
=
$attrs
[
key
]
}
}
}
else
{
dataset
=
target
.
dataset
||
{}
}
return
normalizeDataset
(
dataset
)
}
export
function
upx2px
(
str
)
{
str
=
str
+
''
if
(
str
.
indexOf
(
'
upx
'
)
!==
-
1
)
{
// upx转换
...
...
@@ -53,4 +72,4 @@ export function findExistsPageIndex (url) {
}
}
return
-
1
}
}
src/core/view/bridge/subscribe/api/request-component-info.js
浏览文件 @
91b92481
import
{
normalize
Dataset
getTarget
Dataset
}
from
'
uni-helpers/index
'
import
getWindowOffset
from
'
uni-platform/helpers/get-window-offset
'
...
...
@@ -46,7 +46,7 @@ function getNodeInfo (el, fields) {
info
.
id
=
el
.
id
}
if
(
fields
.
dataset
)
{
info
.
dataset
=
normalizeDataset
(
el
.
dataset
||
{}
)
info
.
dataset
=
getTargetDataset
(
el
)
}
if
(
fields
.
rect
||
fields
.
size
)
{
const
rect
=
el
.
getBoundingClientRect
()
...
...
src/core/view/bridge/subscribe/api/request-component-observer.js
浏览文件 @
91b92481
import
'
intersection-observer
'
import
{
normalize
Dataset
getTarget
Dataset
}
from
'
uni-helpers/index
'
import
{
...
...
@@ -49,7 +49,7 @@ export function requestComponentObserver ({
boundingClientRect
:
getRect
(
entrie
.
boundingClientRect
),
relativeRect
:
getRect
(
entrie
.
rootBounds
),
time
:
Date
.
now
(),
dataset
:
normalizeDataset
(
entrie
.
target
.
dataset
||
{}
),
dataset
:
getTargetDataset
(
entrie
.
target
),
id
:
entrie
.
target
.
id
}
})
...
...
src/core/view/plugins/events.js
浏览文件 @
91b92481
...
...
@@ -3,7 +3,7 @@ import {
}
from
'
uni-shared
'
import
{
normalize
Dataset
getTarget
Dataset
}
from
'
uni-helpers/index
'
import
{
...
...
@@ -17,7 +17,7 @@ function processTarget (target, detail, checkShadowRoot = false) {
id
:
target
.
id
,
offsetLeft
:
target
.
offsetLeft
,
offsetTop
:
target
.
offsetTop
,
dataset
:
normalizeDataset
(
target
.
datas
et
)
dataset
:
getTargetDataset
(
targ
et
)
}
if
(
detail
)
{
Object
.
assign
(
res
,
detail
)
...
...
src/platforms/app-plus/service/framework/plugins/data.js
浏览文件 @
91b92481
...
...
@@ -137,10 +137,6 @@ function parseExternalClasses (clazz, vm) {
return
clazz
}
function
isNotSafeString
(
value
)
{
return
value
===
'
null
'
||
value
===
'
true
'
||
value
===
'
false
'
||
!
isNaN
(
Number
(
value
))
||
(
value
.
startsWith
(
'
[
'
)
&&
value
.
endsWith
(
'
]
'
))
||
(
value
.
startsWith
(
'
{
'
)
&&
value
.
endsWith
(
'
}
'
))
}
function
setData
(
id
,
name
,
value
)
{
switch
(
name
)
{
case
B_CLASS
:
...
...
@@ -160,12 +156,6 @@ function setData (id, name, value) {
case
V_FOR
:
return
setForData
.
call
(
this
,
id
,
value
)
}
// TODO 暂时先传递 dataset 至 view 层(理论上不需要)
if
(
name
.
indexOf
(
'
a-data-
'
)
===
0
&&
(
typeof
value
!==
'
string
'
||
isNotSafeString
(
value
)))
{
try
{
value
=
JSON
.
stringify
(
value
)
}
catch
(
e
)
{}
}
return
((
this
.
_$newData
[
id
]
||
(
this
.
_$newData
[
id
]
=
{}))[
name
]
=
value
)
}
...
...
src/platforms/app-plus/service/framework/plugins/vdom-sync.js
浏览文件 @
91b92481
...
...
@@ -31,32 +31,7 @@ import {
import
parseComponentCreateOptions
from
'
./parse-component-create-options
'
// TODO 临时通过序列化,反序列化传递dataset,后续可以全部保留在service,不做传递
function
parseDataset
(
dataset
)
{
const
ret
=
Object
.
create
(
null
)
Object
.
keys
(
dataset
).
forEach
(
name
=>
{
try
{
ret
[
name
]
=
JSON
.
parse
(
dataset
[
name
])
}
catch
(
e
)
{
// dataset 存在两种,一种是被JSON.stringify的,一种是原始的
ret
[
name
]
=
dataset
[
name
]
}
})
return
ret
}
function
parseTargets
(
event
)
{
const
targetDataset
=
event
.
target
&&
event
.
target
.
dataset
if
(
targetDataset
)
{
event
.
target
.
dataset
=
parseDataset
(
targetDataset
)
}
const
currentTargetDataset
=
event
.
currentTarget
&&
event
.
currentTarget
.
dataset
if
(
currentTargetDataset
)
{
event
.
currentTarget
.
dataset
=
parseDataset
(
currentTargetDataset
)
}
}
function
wrapperEvent
(
event
)
{
parseTargets
(
event
)
event
.
preventDefault
=
noop
event
.
stopPropagation
=
noop
return
wrapperMPEvent
(
event
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录