hookehuyr

fix(MultiRuleField): 修复验证器中未处理空值的潜在错误

在处理`props.item.value`时,添加可选链操作符以避免空值导致的错误
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-03 20:35:26
* @LastEditTime: 2025-03-27 17:18:55
* @FilePath: /data-table/src/components/MultiRuleField/index.vue
* @Description: 多选规则确认控件
-->
......@@ -106,9 +106,9 @@ const max_count = props.item.component_props.max_count;
const validator = (val) => {
if (required && !val.length) {
return false;
} else if (min_count && props.item.value.length < min_count) {
} else if (min_count && props.item.value?.length < min_count) {
return false;
} else if (max_count && props.item.value.length > max_count) {
} else if (max_count && props.item.value?.length > max_count) {
return false;
} else {
return true;
......@@ -118,9 +118,9 @@ const validator = (val) => {
const validatorMessage = (val, rule) => {
if (required && !val.length) {
return "选择项不能为空";
} else if (min_count && props.item.value.length < min_count) {
} else if (min_count && props.item.value?.length < min_count) {
return `最少选择${min_count}项`;
} else if (max_count && props.item.value.length > max_count) {
} else if (max_count && props.item.value?.length > max_count) {
return `最多选择${max_count}项`;
}
};
......