From cd96d258f618d4a93584307b4100eee448a58884 Mon Sep 17 00:00:00 2001 From: xuqingkai Date: Wed, 14 Aug 2024 21:33:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8Dcheckbo?= =?UTF-8?q?x-group=E7=9A=84shape=E6=97=A0=E6=B3=95=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E5=88=B0=E5=AD=90=E7=BB=84=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #519 --- .../components/wd-checkbox/types.ts | 4 +- .../components/wd-checkbox/wd-checkbox.vue | 62 ++++++------------- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/src/uni_modules/wot-design-uni/components/wd-checkbox/types.ts b/src/uni_modules/wot-design-uni/components/wd-checkbox/types.ts index 6c4bced15..86bafc7ea 100644 --- a/src/uni_modules/wot-design-uni/components/wd-checkbox/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-checkbox/types.ts @@ -18,7 +18,9 @@ export const checkboxProps = { /** * 单选框形状,可选值:circle / square / button */ - shape: makeStringProp('circle'), + shape: { + type: String as PropType + }, /** * 选中的颜色 */ diff --git a/src/uni_modules/wot-design-uni/components/wd-checkbox/wd-checkbox.vue b/src/uni_modules/wot-design-uni/components/wd-checkbox/wd-checkbox.vue index b463ecfa7..eb33f3923 100644 --- a/src/uni_modules/wot-design-uni/components/wd-checkbox/wd-checkbox.vue +++ b/src/uni_modules/wot-design-uni/components/wd-checkbox/wd-checkbox.vue @@ -46,7 +46,7 @@ export default { import { computed, getCurrentInstance, onBeforeMount, watch } from 'vue' import { useParent } from '../composables/useParent' import { CHECKBOX_GROUP_KEY } from '../wd-checkbox-group/types' -import { isDef } from '../common/util' +import { getPropByPath, isDef } from '../common/util' import { checkboxProps, type CheckboxExpose } from './types' const props = defineProps(checkboxProps) @@ -90,67 +90,45 @@ watch( () => props.shape, (newValue) => { const type = ['circle', 'square', 'button'] - if (type.indexOf(newValue) === -1) console.error(`shape must be one of ${type.toString()}`) + if (isDef(newValue) && type.indexOf(newValue) === -1) console.error(`shape must be one of ${type.toString()}`) } ) const innerShape = computed(() => { - if (!props.shape && checkboxGroup && checkboxGroup.props.shape) { - return checkboxGroup.props.shape - } else { - return props.shape - } + return props.shape || getPropByPath(checkboxGroup, 'props.shape') || 'circle' }) const innerCheckedColor = computed(() => { - if (!props.checkedColor && checkboxGroup && checkboxGroup.props.checkedColor) { - return checkboxGroup.props.checkedColor - } else { - return props.checkedColor - } + return props.checkedColor || getPropByPath(checkboxGroup, 'props.checkedColor') }) const innerDisabled = computed(() => { - let innerDisabled = props.disabled - if (checkboxGroup) { - if ( - // max 生效时,group 已经选满,禁止其它节点再选中。 - (checkboxGroup.props.max && checkboxGroup.props.modelValue.length >= checkboxGroup.props.max && !isChecked.value) || - // min 生效时,group 选中的节点数量仅满足最小值,禁止取消已选中的节点。 - (checkboxGroup.props.min && checkboxGroup.props.modelValue.length <= checkboxGroup.props.min && isChecked.value) || - // 只要子节点自己要求 disabled,那就 disabled。 - props.disabled === true || - // 父节点要求全局 disabled,子节点没吱声,那就 disabled。 - (checkboxGroup.props.disabled && props.disabled === null) - ) { - innerDisabled = true - } + if (!checkboxGroup) { + return props.disabled + } + const { max, min, modelValue, disabled } = checkboxGroup.props + if ( + (max && modelValue.length >= max && !isChecked.value) || + (min && modelValue.length <= min && isChecked.value) || + props.disabled === true || + (disabled && props.disabled === null) + ) { + return true } - return innerDisabled + + return props.disabled }) const innerInline = computed(() => { - if (checkboxGroup && checkboxGroup.props.inline) { - return checkboxGroup.props.inline - } else { - return false - } + return getPropByPath(checkboxGroup, 'props.inline') || false }) const innerCell = computed(() => { - if (checkboxGroup && checkboxGroup.props.cell) { - return checkboxGroup.props.cell - } else { - return false - } + return getPropByPath(checkboxGroup, 'props.cell') || false }) const innerSize = computed(() => { - if (!props.size && checkboxGroup && checkboxGroup.props.size) { - return checkboxGroup.props.size - } else { - return props.size - } + return props.size || getPropByPath(checkboxGroup, 'props.size') }) onBeforeMount(() => {