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:
parent
264f34e49d
commit
9882e8df86
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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 = /^\{(.+)\}$/;
|
||||||
|
|
|
||||||
|
|
@ -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 事件相关逻辑
|
||||||
|
|
|
||||||
|
|
@ -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'];
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue