@@ -46,7 +46,7 @@ export default {
4646import { computed , getCurrentInstance , onBeforeMount , watch } from ' vue'
4747import { useParent } from ' ../composables/useParent'
4848import { CHECKBOX_GROUP_KEY } from ' ../wd-checkbox-group/types'
49- import { isDef } from ' ../common/util'
49+ import { getPropByPath , isDef } from ' ../common/util'
5050import { checkboxProps , type CheckboxExpose } from ' ./types'
5151
5252const props = defineProps (checkboxProps )
@@ -90,67 +90,45 @@ watch(
9090 () => props .shape ,
9191 (newValue ) => {
9292 const type = [' circle' , ' square' , ' button' ]
93- if (type .indexOf (newValue ) === - 1 ) console .error (` shape must be one of ${type .toString ()} ` )
93+ if (isDef ( newValue ) && type .indexOf (newValue ) === - 1 ) console .error (` shape must be one of ${type .toString ()} ` )
9494 }
9595)
9696
9797const innerShape = computed (() => {
98- if (! props .shape && checkboxGroup && checkboxGroup .props .shape ) {
99- return checkboxGroup .props .shape
100- } else {
101- return props .shape
102- }
98+ return props .shape || getPropByPath (checkboxGroup , ' props.shape' ) || ' circle'
10399})
104100
105101const innerCheckedColor = computed (() => {
106- if (! props .checkedColor && checkboxGroup && checkboxGroup .props .checkedColor ) {
107- return checkboxGroup .props .checkedColor
108- } else {
109- return props .checkedColor
110- }
102+ return props .checkedColor || getPropByPath (checkboxGroup , ' props.checkedColor' )
111103})
112104
113105const innerDisabled = computed (() => {
114- let innerDisabled = props .disabled
115- if (checkboxGroup ) {
116- if (
117- // max 生效时,group 已经选满,禁止其它节点再选中。
118- (checkboxGroup .props .max && checkboxGroup .props .modelValue .length >= checkboxGroup .props .max && ! isChecked .value ) ||
119- // min 生效时,group 选中的节点数量仅满足最小值,禁止取消已选中的节点。
120- (checkboxGroup .props .min && checkboxGroup .props .modelValue .length <= checkboxGroup .props .min && isChecked .value ) ||
121- // 只要子节点自己要求 disabled,那就 disabled。
122- props .disabled === true ||
123- // 父节点要求全局 disabled,子节点没吱声,那就 disabled。
124- (checkboxGroup .props .disabled && props .disabled === null )
125- ) {
126- innerDisabled = true
127- }
106+ if (! checkboxGroup ) {
107+ return props .disabled
108+ }
109+ const { max, min, modelValue, disabled } = checkboxGroup .props
110+ if (
111+ (max && modelValue .length >= max && ! isChecked .value ) ||
112+ (min && modelValue .length <= min && isChecked .value ) ||
113+ props .disabled === true ||
114+ (disabled && props .disabled === null )
115+ ) {
116+ return true
128117 }
129- return innerDisabled
118+
119+ return props .disabled
130120})
131121
132122const innerInline = computed (() => {
133- if (checkboxGroup && checkboxGroup .props .inline ) {
134- return checkboxGroup .props .inline
135- } else {
136- return false
137- }
123+ return getPropByPath (checkboxGroup , ' props.inline' ) || false
138124})
139125
140126const innerCell = computed (() => {
141- if (checkboxGroup && checkboxGroup .props .cell ) {
142- return checkboxGroup .props .cell
143- } else {
144- return false
145- }
127+ return getPropByPath (checkboxGroup , ' props.cell' ) || false
146128})
147129
148130const innerSize = computed (() => {
149- if (! props .size && checkboxGroup && checkboxGroup .props .size ) {
150- return checkboxGroup .props .size
151- } else {
152- return props .size
153- }
131+ return props .size || getPropByPath (checkboxGroup , ' props.size' )
154132})
155133
156134onBeforeMount (() => {
0 commit comments