hookehuyr

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

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