Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
84017bc5
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,发现更多精彩内容 >>
提交
84017bc5
编写于
2月 18, 2022
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(nvue3): checkbox-group
上级
ff73947e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
50 deletion
+105
-50
packages/uni-components/src/components/checkbox-group.ts
packages/uni-components/src/components/checkbox-group.ts
+21
-0
packages/uni-components/src/nvue/checkbox-group/index.tsx
packages/uni-components/src/nvue/checkbox-group/index.tsx
+12
-33
packages/uni-components/src/nvue/checkbox/index.tsx
packages/uni-components/src/nvue/checkbox/index.tsx
+72
-17
未找到文件。
packages/uni-components/src/components/checkbox-group.ts
浏览文件 @
84017bc5
import
{
ComputedRef
,
ExtractPropTypes
}
from
'
vue
'
import
{
PolySymbol
}
from
'
@dcloudio/uni-core
'
export
const
uniCheckGroupKey
=
PolySymbol
(
__DEV__
?
'
uniCheckGroup
'
:
'
ucg
'
)
export
type
UniCheckGroupFieldCtx
=
ComputedRef
<
{
checkboxChecked
:
boolean
value
:
string
}
>
export
interface
UniCheckGroupCtx
{
addField
:
(
field
:
UniCheckGroupFieldCtx
)
=>
void
removeField
:
(
field
:
UniCheckGroupFieldCtx
)
=>
void
checkboxChange
:
(
$event
:
Event
)
=>
void
}
export
const
checkboxGroupProps
=
{
name
:
{
type
:
String
,
default
:
''
,
},
}
export
type
CheckBoxGroupProps
=
ExtractPropTypes
<
typeof
checkboxGroupProps
>
packages/uni-components/src/nvue/checkbox-group/index.tsx
浏览文件 @
84017bc5
import
{
defineComponent
,
inject
,
provide
,
ComputedRef
,
ref
,
ExtractPropTypes
,
}
from
'
vue
'
import
{
uniCheckGroupKey
}
from
'
../../components/checkbox-group
'
import
{
UniFormCtx
,
uniFormKey
}
from
'
../../components/form
'
import
{
defineComponent
,
inject
,
provide
,
ref
}
from
'
vue
'
import
{
CustomEventTrigger
,
useCustomEvent
,
EmitEvent
,
}
from
'
../../helpers/useEvent
'
type
UniCheckGroupFieldCtx
=
ComputedRef
<
{
checkboxChecked
:
boolean
value
:
string
}
>
const
props
=
{
name
:
{
type
:
String
,
default
:
''
,
},
}
type
CheckBoxGroupProps
=
ExtractPropTypes
<
typeof
props
>
export
interface
UniCheckGroupCtx
{
addField
:
(
field
:
UniCheckGroupFieldCtx
)
=>
void
removeField
:
(
field
:
UniCheckGroupFieldCtx
)
=>
void
checkboxChange
:
(
$event
:
Event
)
=>
void
}
}
from
'
../../helpers/useNVueEvent
'
import
{
uniCheckGroupKey
,
UniCheckGroupCtx
,
UniCheckGroupFieldCtx
,
CheckBoxGroupProps
,
checkboxGroupProps
,
}
from
'
../../components/checkbox-group
'
import
{
UniFormCtx
,
uniFormKey
}
from
'
../../components/form
'
export
default
defineComponent
({
name
:
'
CheckboxGroup
'
,
props
,
props
:
checkboxGroupProps
,
emits
:
[
'
change
'
],
setup
(
props
,
{
slots
,
emit
})
{
const
rootRef
=
ref
<
HTMLElement
|
null
>
(
null
)
...
...
@@ -76,7 +55,7 @@ function useProvideCheckGroup(
fields
.
splice
(
fields
.
indexOf
(
field
),
1
)
},
checkboxChange
(
$event
)
{
trigger
(
'
change
'
,
$event
,
{
trigger
(
'
change
'
,
{
value
:
getFieldsValue
(),
})
},
...
...
packages/uni-components/src/nvue/checkbox/index.tsx
浏览文件 @
84017bc5
...
...
@@ -2,14 +2,20 @@ import {
defineComponent
,
inject
,
onBeforeUnmount
,
Ref
,
ref
,
computed
,
watch
,
}
from
'
vue
'
import
{
uniLabelKey
,
UniLabelCtx
}
from
'
../label
'
import
{
useListeners
}
from
'
../../helpers/useListeners
'
import
{
NVueComponentStyles
,
createNVueTextVNode
}
from
'
../utils
'
import
{
checkboxProps
}
from
'
../../components/checkbox
'
import
{
uniCheckGroupKey
,
UniCheckGroupCtx
,
}
from
'
../../components/checkbox-group
'
import
{
UniFormCtx
,
uniFormKey
}
from
'
../../components/form
'
import
{
uniLabelKey
,
UniLabelCtx
}
from
'
../label
'
const
checkboxStyles
:
NVueComponentStyles
=
[
{
...
...
@@ -69,7 +75,16 @@ export default defineComponent({
const
rootRef
=
ref
<
HTMLElement
|
null
>
(
null
)
const
checkboxChecked
=
ref
(
props
.
checked
)
const
checkboxValue
=
ref
(
props
.
value
)
const
onClick
=
(
e
:
Event
,
isLabelClick
?:
boolean
)
=>
{
const
checkboxColor
=
computed
(()
=>
props
.
disabled
?
'
#adadad
'
:
props
.
color
)
const
reset
=
()
=>
{
checkboxChecked
.
value
=
false
}
const
_onClick
=
(
$event
:
Event
,
isLabelClick
?:
boolean
)
=>
{
if
(
props
.
disabled
)
{
return
}
...
...
@@ -77,12 +92,23 @@ export default defineComponent({
rootRef
.
value
!
.
click
()
}
checkboxChecked
.
value
=
!
checkboxChecked
.
value
uniCheckGroup
&&
uniCheckGroup
.
checkboxChange
(
$event
)
}
const
checkboxColor
=
computed
(()
=>
props
.
disabled
?
'
#adadad
'
:
props
.
color
const
{
uniCheckGroup
,
uniLabel
}
=
useCheckboxInject
(
checkboxChecked
,
checkboxValue
,
reset
)
if
(
uniLabel
)
{
uniLabel
.
addHandler
(
_onClick
)
onBeforeUnmount
(()
=>
{
uniLabel
.
removeHandler
(
_onClick
)
})
}
useListeners
(
props
,
{
'
label-click
'
:
_onClick
})
watch
(
[()
=>
props
.
checked
,
()
=>
props
.
value
],
([
newChecked
,
newModelValue
])
=>
{
...
...
@@ -91,18 +117,6 @@ export default defineComponent({
}
)
const
uniLabel
=
inject
<
UniLabelCtx
>
(
uniLabelKey
,
false
as
unknown
as
UniLabelCtx
)
if
(
uniLabel
)
{
uniLabel
.
addHandler
(
onClick
)
onBeforeUnmount
(()
=>
{
uniLabel
.
removeHandler
(
onClick
)
})
}
useListeners
(
props
,
{
'
label-click
'
:
onClick
})
const
wrapSlots
=
()
=>
{
if
(
!
slots
.
default
)
return
[]
const
vnodes
=
slots
.
default
()
...
...
@@ -121,7 +135,7 @@ export default defineComponent({
<
div
ref
=
{
rootRef
}
{
...{
dataUncType
:
'
uni-checkbox
'
}
}
onClick
=
{
onClick
}
onClick
=
{
_
onClick
}
class
=
"uni-checkbox"
>
<
div
...
...
@@ -144,3 +158,44 @@ export default defineComponent({
}
},
})
function
useCheckboxInject
(
checkboxChecked
:
Ref
<
string
|
boolean
>
,
checkboxValue
:
Ref
<
string
>
,
reset
:
()
=>
void
)
{
const
field
=
computed
(()
=>
({
checkboxChecked
:
Boolean
(
checkboxChecked
.
value
),
value
:
checkboxValue
.
value
,
}))
const
formField
=
{
reset
}
const
uniCheckGroup
=
inject
<
UniCheckGroupCtx
>
(
uniCheckGroupKey
,
false
as
unknown
as
UniCheckGroupCtx
)
if
(
!!
uniCheckGroup
)
{
uniCheckGroup
.
addField
(
field
)
}
const
uniForm
=
inject
<
UniFormCtx
>
(
uniFormKey
,
false
as
unknown
as
UniFormCtx
)
if
(
!!
uniForm
)
{
uniForm
.
addField
(
formField
)
}
const
uniLabel
=
inject
<
UniLabelCtx
>
(
uniLabelKey
,
false
as
unknown
as
UniLabelCtx
)
onBeforeUnmount
(()
=>
{
uniCheckGroup
&&
uniCheckGroup
.
removeField
(
field
)
uniForm
&&
uniForm
.
removeField
(
formField
)
})
return
{
uniCheckGroup
,
uniForm
,
uniLabel
,
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录