Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
e6e6a362
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e6e6a362
编写于
2月 15, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
差异文件
chore: merge
上级
77951dd9
f635c351
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
16 deletion
+96
-16
packages/uni-components/dist/components.js
packages/uni-components/dist/components.js
+63
-9
packages/uni-components/src/nvue/button/index.tsx
packages/uni-components/src/nvue/button/index.tsx
+33
-7
未找到文件。
packages/uni-components/dist/components.js
浏览文件 @
e6e6a362
import
{
createElementVNode
,
defineComponent
,
createVNode
,
mergeProps
,
getCurrentInstance
,
provide
,
watch
,
onUnmounted
,
ref
,
inject
,
onBeforeUnmount
,
Text
,
isVNode
,
Fragment
,
onMounted
,
compu
ted
}
from
"
vue
"
;
import
{
createElementVNode
,
defineComponent
,
createVNode
,
mergeProps
,
getCurrentInstance
,
provide
,
watch
,
onUnmounted
,
shallowRef
,
reactive
,
watchEffect
,
ref
,
inject
,
onBeforeUnmount
,
computed
,
Text
,
isVNode
,
Fragment
,
onMoun
ted
}
from
"
vue
"
;
import
{
hasOwn
,
extend
,
isPlainObject
}
from
"
@vue/shared
"
;
import
{
cacheStringFunction
}
from
"
@dcloudio/uni-shared
"
;
const
OPEN_TYPES
=
[
...
...
@@ -230,6 +230,43 @@ function _removeListeners(id, listeners, watch2) {
}
});
}
function
entries
(
obj
)
{
return
Object
.
keys
(
obj
).
map
((
key
)
=>
[
key
,
obj
[
key
]]);
}
const
DEFAULT_EXCLUDE_KEYS
=
[
"
class
"
,
"
style
"
];
const
LISTENER_PREFIX
=
/^on
[
A-Z
]
+/
;
const
useAttrs
=
(
params
=
{})
=>
{
const
{
excludeListeners
=
false
,
excludeKeys
=
[]
}
=
params
;
const
instance
=
getCurrentInstance
();
const
attrs
=
shallowRef
({});
const
listeners
=
shallowRef
({});
const
excludeAttrs
=
shallowRef
({});
const
allExcludeKeys
=
excludeKeys
.
concat
(
DEFAULT_EXCLUDE_KEYS
);
instance
.
attrs
=
reactive
(
instance
.
attrs
);
watchEffect
(()
=>
{
const
res
=
entries
(
instance
.
attrs
).
reduce
((
acc
,
[
key
,
val
])
=>
{
if
(
allExcludeKeys
.
includes
(
key
))
{
acc
.
exclude
[
key
]
=
val
;
}
else
if
(
LISTENER_PREFIX
.
test
(
key
))
{
if
(
!
excludeListeners
)
{
acc
.
attrs
[
key
]
=
val
;
}
acc
.
listeners
[
key
]
=
val
;
}
else
{
acc
.
attrs
[
key
]
=
val
;
}
return
acc
;
},
{
exclude
:
{},
attrs
:
{},
listeners
:
{}
});
attrs
.
value
=
res
.
attrs
;
listeners
.
value
=
res
.
listeners
;
excludeAttrs
.
value
=
res
.
exclude
;
});
return
{
$attrs
:
attrs
,
$listeners
:
listeners
,
$excludeAttrs
:
excludeAttrs
};
};
const
buttonProps
=
{
id
:
{
type
:
String
,
...
...
@@ -455,6 +492,7 @@ const TYPES = {
warn
:
"
w
"
};
var
Button
=
defineComponent
({
inheritAttrs
:
false
,
name
:
"
Button
"
,
props
:
extend
(
buttonProps
,
{
type
:
{
...
...
@@ -471,15 +509,22 @@ var Button = defineComponent({
slots
,
attrs
})
{
const
{
$attrs
,
$excludeAttrs
,
$listeners
}
=
useAttrs
({
excludeListeners
:
true
});
const
type
=
props
.
type
;
const
rootRef
=
ref
(
null
);
const
onClick
=
(
e2
,
isLabelClick
)
=>
{
const
_onClick
=
$listeners
.
value
.
onClick
||
(()
=>
{
});
if
(
props
.
disabled
)
{
return
;
}
if
(
isLabelClick
)
{
rootRef
.
value
.
event
.
click
.
handler
(
e2
);
}
_onClick
(
e2
);
};
const
_getClass
=
(
t2
)
=>
{
let
cl
=
"
ub-
"
+
TYPES
[
type
]
+
t2
;
...
...
@@ -506,6 +551,15 @@ var Button = defineComponent({
useListeners
(
props
,
{
"
label-click
"
:
onClick
});
const
_listeners
=
computed
(()
=>
{
const
obj
=
{};
for
(
const
eventName
in
$listeners
.
value
)
{
const
event
=
$listeners
.
value
[
eventName
];
if
(
eventName
!==
"
onClick
"
)
obj
[
eventName
]
=
event
;
}
return
obj
;
});
const
wrapSlots
=
()
=>
{
if
(
!
slots
.
default
)
return
[];
...
...
@@ -518,14 +572,14 @@ var Button = defineComponent({
return
vnodes
;
};
return
()
=>
{
const
_attrs
=
extend
({},
useHoverClass
(
props
),
{
hoverClass
:
_getHoverClass
(
""
)
},
$attrs
.
value
,
$excludeAttrs
.
value
,
_listeners
.
value
);
return
createVNode
(
"
view
"
,
mergeProps
({
"
ref
"
:
rootRef
,
"
class
"
:
[
"
ub
"
,
_getClass
(
""
)]
},
extend
({},
useHoverClass
(
props
),
{
hoverClass
:
_getHoverClass
(
""
)
}),
{
"
class
"
:
[
"
ub
"
,
_getClass
(
""
)],
"
onClick
"
:
onClick
}),
[
props
.
loading
?
createVNode
(
"
loading-indicator
"
,
mergeProps
({
}
,
_attrs
),
[
props
.
loading
?
createVNode
(
"
loading-indicator
"
,
mergeProps
({
"
class
"
:
[
"
ub-loading
"
,
`ub-
${
TYPES
[
type
]}
-loading`
]
},
{
arrow
:
"
false
"
,
...
...
packages/uni-components/src/nvue/button/index.tsx
浏览文件 @
e6e6a362
import
{
inject
,
onBeforeUnmount
,
ref
,
defineComponent
,
Text
}
from
'
vue
'
import
{
inject
,
onBeforeUnmount
,
ref
,
defineComponent
,
Text
,
computed
,
}
from
'
vue
'
import
{
uniLabelKey
,
UniLabelCtx
}
from
'
../label
'
import
{
useListeners
}
from
'
../../helpers/useListeners
'
import
{
useAttrs
}
from
'
../../helpers/useAttrs
'
import
{
createNVueTextVNode
,
useHoverClass
}
from
'
../utils
'
import
{
buttonProps
}
from
'
../../components/button
'
import
{
extend
}
from
'
@vue/shared
'
...
...
@@ -191,6 +199,7 @@ const TYPES = {
}
export
default
defineComponent
({
inheritAttrs
:
false
,
name
:
'
Button
'
,
props
:
extend
(
buttonProps
,
{
type
:
{
...
...
@@ -204,15 +213,17 @@ export default defineComponent({
}),
styles
:
buttonStyle
,
setup
(
props
,
{
slots
,
attrs
})
{
const
{
$attrs
,
$excludeAttrs
,
$listeners
}
=
useAttrs
({
excludeListeners
:
true
,
})
const
type
=
props
.
type
as
keyof
typeof
TYPES
const
rootRef
=
ref
<
HTMLElement
|
null
>
(
null
)
const
onClick
=
(
e
:
Event
,
isLabelClick
?:
boolean
)
=>
{
const
_onClick
=
(
$listeners
.
value
as
any
).
onClick
||
(()
=>
{})
if
(
props
.
disabled
)
{
return
}
if
(
isLabelClick
)
{
;(
rootRef
.
value
as
any
).
event
.
click
.
handler
(
e
)
}
_onClick
(
e
)
/* const formType = props.formType
if (formType) {
if (!uniForm) {
...
...
@@ -254,6 +265,15 @@ export default defineComponent({
}
useListeners
(
props
,
{
'
label-click
'
:
onClick
})
const
_listeners
=
computed
(()
=>
{
const
obj
=
{}
for
(
const
eventName
in
$listeners
.
value
)
{
const
event
=
(
$listeners
.
value
as
any
)[
eventName
]
if
(
eventName
!==
'
onClick
'
)
(
obj
as
any
)[
eventName
]
=
event
}
return
obj
})
const
wrapSlots
=
()
=>
{
if
(
!
slots
.
default
)
return
[]
const
vnodes
=
slots
.
default
()
...
...
@@ -268,16 +288,22 @@ export default defineComponent({
}
return
()
=>
{
const
_attrs
=
extend
(
{},
useHoverClass
(
props
),
{
hoverClass
:
_getHoverClass
(
''
)
},
$attrs
.
value
,
$excludeAttrs
.
value
,
_listeners
.
value
)
return
(
<
view
ref
=
{
rootRef
}
class
=
"ub"
// @ts-expect-error
class
=
{
_getClass
(
''
)
}
{
...
extend
({},
useHoverClass
(
props
),
{
hoverClass
:
_getHoverClass
(
''
),
})
}
onClick
=
{
onClick
}
{
...
_attrs
}
>
{
props
.
loading
?
(
<
loading
-
indicator
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录