feat(input): add auto-trimming for vxe-table input components (#3684)

* fix: Correct spelling errors in form component

* fix: Correct spelling errors in form component

* fix: Correct spelling errors in vxetable component
This commit is contained in:
zandko 2024-03-25 11:41:53 +08:00 committed by GitHub
parent 264f34e49d
commit 9882e8df86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 10 deletions

View File

@ -195,7 +195,7 @@ export function useFormEvents({
fieldList = [fields]; fieldList = [fields];
} }
for (const field of fieldList) { for (const field of fieldList) {
_removeSchemaByFeild(field, schemaList); _removeSchemaByField(field, schemaList);
} }
schemaRef.value = schemaList; schemaRef.value = schemaList;
} }
@ -203,7 +203,7 @@ export function useFormEvents({
/** /**
* @description: Delete based on field name * @description: Delete based on field name
*/ */
function _removeSchemaByFeild(field: string, schemaList: FormSchema[]): void { function _removeSchemaByField(field: string, schemaList: FormSchema[]): void {
if (isString(field)) { if (isString(field)) {
const index = schemaList.findIndex((schema) => schema.field === field); const index = schemaList.findIndex((schema) => schema.field === field);
if (index !== -1) { if (index !== -1) {

View File

@ -13,7 +13,7 @@ interface UseFormValuesContext {
} }
/** /**
* @desription deconstruct array-link key. This method will mutate the target. * @description deconstruct array-link key. This method will mutate the target.
*/ */
function tryDeconstructArray(key: string, value: any, target: Recordable) { function tryDeconstructArray(key: string, value: any, target: Recordable) {
const pattern = /^\[(.+)\]$/; const pattern = /^\[(.+)\]$/;
@ -31,7 +31,7 @@ function tryDeconstructArray(key: string, value: any, target: Recordable) {
} }
/** /**
* @desription deconstruct object-link key. This method will mutate the target. * @description deconstruct object-link key. This method will mutate the target.
*/ */
function tryDeconstructObject(key: string, value: any, target: Recordable) { function tryDeconstructObject(key: string, value: any, target: Recordable) {
const pattern = /^\{(.+)\}$/; const pattern = /^\{(.+)\}$/;

View File

@ -7,7 +7,7 @@ import {
import XEUtils from 'xe-utils'; import XEUtils from 'xe-utils';
import { componentMap } from '../componentMap'; import { componentMap } from '../componentMap';
import { ComponentType } from '../componentType'; import { ComponentType } from '../componentType';
import { createPlaceholderMessage } from '../helper'; import { createPlaceholderMessage, sanitizeInputWhitespace } from '../helper';
/** /**
* @description: * @description:
@ -102,13 +102,13 @@ export function createEvents(
}; };
}); });
if (inputFunc) { if (inputFunc) {
ons[getOnName(modelEvent)] = function (targetEvnt: any) { ons[getOnName(modelEvent)] = function (targetEvent: any) {
inputFunc(targetEvnt); inputFunc(targetEvent);
if (events && events[modelEvent]) { if (events && events[modelEvent]) {
events[modelEvent](params, targetEvnt); events[modelEvent](params, targetEvent);
} }
if (isSameEvent && changeFunc) { if (isSameEvent && changeFunc) {
changeFunc(targetEvnt); changeFunc(targetEvent);
} }
}; };
} }
@ -323,7 +323,7 @@ export function createFormItemRender(
params, params,
(value: any) => { (value: any) => {
// 处理 model 值双向绑定 // 处理 model 值双向绑定
XEUtils.set(data, property, value); XEUtils.set(data, property, sanitizeInputWhitespace(name as ComponentType, value));
}, },
() => { () => {
// 处理 change 事件相关逻辑 // 处理 change 事件相关逻辑

View File

@ -2,3 +2,8 @@
* @description: vxe-table prop * @description: vxe-table prop
*/ */
export const ignorePropKeys = ['tableClass', 'tableStyle']; export const ignorePropKeys = ['tableClass', 'tableStyle'];
/**
* @description:
*/
export const ignoreTrimInputComponents = ['AInput', 'ATextarea'];

View File

@ -1,5 +1,7 @@
import { ComponentType } from './componentType'; import { ComponentType } from './componentType';
import { useI18n } from '@/hooks/web/useI18n'; import { useI18n } from '@/hooks/web/useI18n';
import XEUtils from 'xe-utils';
import { ignoreTrimInputComponents } from './const';
const { t } = useI18n(); const { t } = useI18n();
@ -17,3 +19,14 @@ export function createPlaceholderMessage(component: ComponentType) {
return t('common.chooseText'); return t('common.chooseText');
} }
} }
/**
*
* @description:
*/
export function sanitizeInputWhitespace(component: ComponentType, value: string) {
if (ignoreTrimInputComponents.includes(component)) {
return XEUtils.trim(value);
}
return value;
}