Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
af653a11
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,发现更多精彩内容 >>
提交
af653a11
编写于
5月 24, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(App): element support $getComponentDescriptor
上级
8a2a140e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
86 addition
and
14 deletion
+86
-14
src/core/view/plugins/index.js
src/core/view/plugins/index.js
+9
-9
src/core/view/plugins/wxs/component-descriptor.js
src/core/view/plugins/wxs/component-descriptor.js
+8
-4
src/platforms/app-plus/view/elements/element.js
src/platforms/app-plus/view/elements/element.js
+69
-1
未找到文件。
src/core/view/plugins/index.js
浏览文件 @
af653a11
...
@@ -61,18 +61,18 @@ export default {
...
@@ -61,18 +61,18 @@ export default {
Vue
.
prototype
.
$handleWxsEvent
=
function
(
$event
)
{
Vue
.
prototype
.
$handleWxsEvent
=
function
(
$event
)
{
if
(
$event
instanceof
Event
)
{
// 未处理的 event 对象 需要对 target 校正及包装
if
(
$event
instanceof
Event
)
{
// 未处理的 event 对象 需要对 target 校正及包装
const
currentTarget
=
$event
.
currentTarget
const
currentTarget
=
$event
.
currentTarget
const
instance
=
currentTarget
&&
// vue component / web component
currentTarget
.
__vue__
&&
const
component
=
currentTarget
&&
(
currentTarget
.
__vue__
||
currentTarget
)
currentTarget
.
__vue__
.
$getComponentDescriptor
(
currentTarget
.
__vue__
,
false
)
const
instance
=
currentTarget
&&
component
.
$getComponentDescriptor
&&
component
.
$getComponentDescriptor
(
component
,
false
)
const
$origEvent
=
$event
const
$origEvent
=
$event
$event
=
processEvent
.
call
(
this
,
$origEvent
.
type
,
$origEvent
,
{},
findUniTarget
(
$origEvent
,
this
.
$el
)
||
$origEvent
.
target
,
$event
=
processEvent
.
call
(
this
,
$origEvent
.
type
,
$origEvent
,
{},
findUniTarget
(
$origEvent
,
this
.
$el
)
||
$origEvent
.
target
,
$origEvent
.
currentTarget
)
$origEvent
.
currentTarget
)
$event
.
instance
=
instance
$event
.
instance
=
instance
$event
.
preventDefault
=
function
()
{
$event
.
preventDefault
=
function
()
{
return
$origEvent
.
preventDefault
()
return
$origEvent
.
preventDefault
()
}
}
$event
.
stopPropagation
=
function
()
{
$event
.
stopPropagation
=
function
()
{
return
$origEvent
.
stopPropagation
()
return
$origEvent
.
stopPropagation
()
}
}
}
}
return
$event
return
$event
...
...
src/core/view/plugins/wxs/component-descriptor.js
浏览文件 @
af653a11
...
@@ -28,7 +28,7 @@ function getWxsClsArr (clsArr, classList, isAdd) {
...
@@ -28,7 +28,7 @@ function getWxsClsArr (clsArr, classList, isAdd) {
return
wxsClsArr
return
wxsClsArr
}
}
function
parseStyleText
(
cssText
)
{
export
function
parseStyleText
(
cssText
)
{
const
res
=
{}
const
res
=
{}
const
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
const
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
const
propertyDelimiter
=
/:
(
.+
)
/
const
propertyDelimiter
=
/:
(
.+
)
/
...
@@ -41,7 +41,7 @@ function parseStyleText (cssText) {
...
@@ -41,7 +41,7 @@ function parseStyleText (cssText) {
return
res
return
res
}
}
class
ComponentDescriptor
{
export
class
ComponentDescriptor
{
constructor
(
vm
)
{
constructor
(
vm
)
{
this
.
$vm
=
vm
this
.
$vm
=
vm
Object
.
defineProperty
(
this
,
'
$el
'
,
{
Object
.
defineProperty
(
this
,
'
$el
'
,
{
...
@@ -56,7 +56,9 @@ class ComponentDescriptor {
...
@@ -56,7 +56,9 @@ class ComponentDescriptor {
return
return
}
}
const
el
=
this
.
$el
.
querySelector
(
selector
)
const
el
=
this
.
$el
.
querySelector
(
selector
)
return
el
&&
el
.
__vue__
&&
createComponentDescriptor
(
el
.
__vue__
,
false
)
// vue component / web component
const
component
=
el
.
__vue__
||
el
return
component
.
$getComponentDescriptor
&&
component
.
$getComponentDescriptor
(
component
,
false
)
}
}
selectAllComponents
(
selector
)
{
selectAllComponents
(
selector
)
{
...
@@ -67,7 +69,9 @@ class ComponentDescriptor {
...
@@ -67,7 +69,9 @@ class ComponentDescriptor {
const
els
=
this
.
$el
.
querySelectorAll
(
selector
)
const
els
=
this
.
$el
.
querySelectorAll
(
selector
)
for
(
let
i
=
0
;
i
<
els
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
els
.
length
;
i
++
)
{
const
el
=
els
[
i
]
const
el
=
els
[
i
]
el
.
__vue__
&&
descriptors
.
push
(
createComponentDescriptor
(
el
.
__vue__
,
false
))
// vue component / web component
const
component
=
el
.
__vue__
||
el
component
.
$getComponentDescriptor
&&
descriptors
.
push
(
component
.
$getComponentDescriptor
(
component
,
false
))
}
}
return
descriptors
return
descriptors
}
}
...
...
src/platforms/app-plus/view/elements/element.js
浏览文件 @
af653a11
import
{
import
{
camelize
camelize
,
isPlainObject
}
from
'
uni-shared
'
}
from
'
uni-shared
'
import
{
ComponentDescriptor
as
ComponentDescriptorClass
,
parseStyleText
}
from
'
uni-core/view/plugins/wxs/component-descriptor
'
// upx,rpx 正则匹配
const
unitRE
=
/
\b([
+-
]?\d
+
(\.\d
+
)?)[
r|u
]
px
\b
/g
const
transformUnit
=
(
val
)
=>
{
if
(
typeof
val
===
'
string
'
)
{
return
val
.
replace
(
unitRE
,
(
a
,
b
)
=>
{
/* eslint-disable no-undef */
return
uni
.
upx2px
(
b
)
+
'
px
'
})
}
return
val
}
class
ComponentDescriptor
extends
ComponentDescriptorClass
{
setStyle
(
style
)
{
if
(
!
this
.
$el
||
!
style
)
{
return
this
}
if
(
typeof
style
===
'
string
'
)
{
style
=
parseStyleText
(
style
)
}
if
(
isPlainObject
(
style
))
{
for
(
const
key
in
style
)
{
this
.
$el
.
style
[
key
]
=
transformUnit
(
style
[
key
])
}
}
return
this
}
addClass
(...
clsArr
)
{
if
(
!
this
.
$el
||
!
clsArr
.
length
)
{
return
this
}
this
.
$el
.
classList
.
add
(...
clsArr
)
return
this
}
removeClass
(...
clsArr
)
{
if
(
!
this
.
$el
||
!
clsArr
.
length
)
{
return
this
}
this
.
$el
.
classList
.
remove
(...
clsArr
)
return
this
}
callMethod
()
{
}
triggerEvent
()
{
}
}
function
formatKey
(
key
)
{
function
formatKey
(
key
)
{
return
camelize
(
key
.
substring
(
5
))
return
camelize
(
key
.
substring
(
5
))
...
@@ -21,4 +80,13 @@ export default class UniElement extends HTMLElement {
...
@@ -21,4 +80,13 @@ export default class UniElement extends HTMLElement {
}
}
super
.
removeAttribute
(
key
)
super
.
removeAttribute
(
key
)
}
}
$getComponentDescriptor
()
{
if
(
!
(
'
__wxsComponentDescriptor
'
in
this
))
{
this
.
__wxsComponentDescriptor
=
new
ComponentDescriptor
({
$el
:
this
})
}
return
this
.
__wxsComponentDescriptor
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录