diff --git a/common/js/common/common.js b/common/js/common/common.js index cb49ac18..49397b75 100644 --- a/common/js/common/common.js +++ b/common/js/common/common.js @@ -907,4 +907,29 @@ export const color_change = (length) => { } else { return predefine_colors[length]; } +}; + +/** + * 格式化数字字符串或数值 + * 此函数根据是否需要转换,将输入的数字字符串或数值格式化为带有逗号分隔的字符串 + * 如果不需要转换,则移除输入中的所有逗号 + * + * @param num - 输入的数字字符串或数值 + * @param is_convert - 指示是否需要转换的布尔值 + * @returns 格式化后的数字字符串 + */ +export const formatNumber = (num, is_convert) => { + if (is_convert) { + // 将输入转换为字符串形式以便处理 + const number = num.toString(); + // 使用正则表达式将整数部分每三位用逗号分隔 + const integerPart = number.split('.')[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); + // 避免小数为空的时候也处理 + const decimalPart = number.split('.')[1] == null ? '' : '.' + number.split('.')[1]; + // 组合整数部分和小数部分 + return integerPart + decimalPart; + } else { + // 如果不需要转换,移除所有逗号并返回 + return num.toString().replace(/,/g, ''); + } }; \ No newline at end of file diff --git a/pages/form-input/components/form-input/checkbox.vue b/pages/form-input/components/form-input/checkbox.vue index bc2de08e..0d5d6868 100644 --- a/pages/form-input/components/form-input/checkbox.vue +++ b/pages/form-input/components/form-input/checkbox.vue @@ -2,7 +2,7 @@ diff --git a/pages/form-input/components/form-input/number.vue b/pages/form-input/components/form-input/number.vue index e4bb16a4..0cf1047c 100644 --- a/pages/form-input/components/form-input/number.vue +++ b/pages/form-input/components/form-input/number.vue @@ -1,12 +1,17 @@ \ No newline at end of file diff --git a/pages/form-input/components/form-input/radio.vue b/pages/form-input/components/form-input/radio.vue index b90ba5ec..cdeb19da 100644 --- a/pages/form-input/components/form-input/radio.vue +++ b/pages/form-input/components/form-input/radio.vue @@ -62,10 +62,6 @@ form_value: com_data?.form_value || [], }); }, - data_check(e) { - const { is_error = '0', error_text = '' } = get_format_checks(this.com_data, e.detail.value, false, 'radio'); - this.$emit('dataCheck', { is_error, error_text, value: e.detail.value, index: this.propDataIndex }); - }, data_change(e) { // 重新编辑一下历史数据 this.setData({ diff --git a/pages/form-input/components/form-input/select-multi.vue b/pages/form-input/components/form-input/select-multi.vue index 3b2150ab..d42e0134 100644 --- a/pages/form-input/components/form-input/select-multi.vue +++ b/pages/form-input/components/form-input/select-multi.vue @@ -5,7 +5,7 @@ @@ -34,12 +34,12 @@ @@ -163,10 +163,6 @@ form_value_data: form_value_data, }); }, - data_check(e) { - const { is_error = '0', error_text = '' } = get_format_checks(this.com_data, e.detail.value); - this.$emit('dataCheck', { is_error, error_text, value: e.detail.value, index: this.propDataIndex }); - }, /** * 下拉框选择事件 */ @@ -274,6 +270,10 @@ popup_status: false, form_value_data: form_value_data, }); + const { is_error = '0', error_text = '' } = get_format_checks(this.com_data, this.popup_list, true, 'checkbox'); + // 校验数据 + this.$emit('dataCheck', { is_error, error_text, value: this.popup_list, index: this.propDataIndex }); + // 数据更新时的处理 this.$emit('dataChange', { value: this.popup_list, index: this.propDataIndex }); } } diff --git a/pages/form-input/components/form-input/select.vue b/pages/form-input/components/form-input/select.vue index db217664..1762ad99 100644 --- a/pages/form-input/components/form-input/select.vue +++ b/pages/form-input/components/form-input/select.vue @@ -141,10 +141,6 @@ form_value_data: form_value_data, }); }, - data_check(e) { - const { is_error = '0', error_text = '' } = get_format_checks(this.com_data, e.detail.value); - this.$emit('dataCheck', { is_error, error_text, value: e.detail.value, index: this.propDataIndex }); - }, /** * 下拉框选择事件 */