mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-04-23 18:28:34 +00:00
feat(form): group-list 支持 max 限制和 beforeAddRow 前置校验
- group-list 新增 max 配置项,限制最大行数 - group-list 支持 beforeAddRow 异步前置校验回调 - table 的 beforeAddRow 支持返回 Promise Made-with: Cursor
This commit is contained in:
parent
9bf42f9007
commit
ac755ac3d0
@ -761,7 +761,7 @@ export interface TableConfig extends FormItem {
|
|||||||
titleTip?: FilterFunction<string>;
|
titleTip?: FilterFunction<string>;
|
||||||
rowKey?: string;
|
rowKey?: string;
|
||||||
/** table 新增行时前置回调 */
|
/** table 新增行时前置回调 */
|
||||||
beforeAddRow?: (mForm: FormState | undefined, data: any) => boolean;
|
beforeAddRow?: (mForm: FormState | undefined, data: any) => boolean | Promise<boolean>;
|
||||||
addButtonConfig?: {
|
addButtonConfig?: {
|
||||||
props?: Record<string, any>;
|
props?: Record<string, any>;
|
||||||
text?: string;
|
text?: string;
|
||||||
@ -804,6 +804,9 @@ export interface GroupListConfig<T = never> extends FormItem {
|
|||||||
props?: Record<string, any>;
|
props?: Record<string, any>;
|
||||||
text?: string;
|
text?: string;
|
||||||
};
|
};
|
||||||
|
/** 最大行数 */
|
||||||
|
max?: number;
|
||||||
|
beforeAddRow?: (mForm: FormState | undefined, data: any) => boolean | Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StepItemConfig<T = never> extends FormItem, ContainerCommonConfig<T> {
|
interface StepItemConfig<T = never> extends FormItem, ContainerCommonConfig<T> {
|
||||||
|
|||||||
@ -50,7 +50,7 @@ import { computed, inject } from 'vue';
|
|||||||
import { Grid, Plus } from '@element-plus/icons-vue';
|
import { Grid, Plus } from '@element-plus/icons-vue';
|
||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
|
|
||||||
import { TMagicButton } from '@tmagic/design';
|
import { TMagicButton, tMagicMessage } from '@tmagic/design';
|
||||||
|
|
||||||
import type { ContainerChangeEventData, FormState, GroupListConfig } from '../schema';
|
import type { ContainerChangeEventData, FormState, GroupListConfig } from '../schema';
|
||||||
import { initValue } from '../utils/form';
|
import { initValue } from '../utils/form';
|
||||||
@ -102,6 +102,20 @@ const changeHandler = (v: any, eventData: ContainerChangeEventData) => {
|
|||||||
const addHandler = async () => {
|
const addHandler = async () => {
|
||||||
if (!props.name) return false;
|
if (!props.name) return false;
|
||||||
|
|
||||||
|
if (props.config.max && props.model[props.name].length >= props.config.max) {
|
||||||
|
tMagicMessage.error(`最多新增配置不能超过${props.config.max}条`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof props.config.beforeAddRow === 'function') {
|
||||||
|
const beforeCheckRes = await props.config.beforeAddRow(mForm, {
|
||||||
|
model: props.model[props.name],
|
||||||
|
formValue: mForm?.values,
|
||||||
|
prop: props.prop,
|
||||||
|
});
|
||||||
|
if (!beforeCheckRes) return;
|
||||||
|
}
|
||||||
|
|
||||||
let initValues = {};
|
let initValues = {};
|
||||||
|
|
||||||
if (typeof props.config.defaultAdd === 'function') {
|
if (typeof props.config.defaultAdd === 'function') {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export const useAdd = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof props.config.beforeAddRow === 'function') {
|
if (typeof props.config.beforeAddRow === 'function') {
|
||||||
const beforeCheckRes = props.config.beforeAddRow(mForm, {
|
const beforeCheckRes = await props.config.beforeAddRow(mForm, {
|
||||||
model: props.model[modelName],
|
model: props.model[modelName],
|
||||||
formValue: mForm?.values,
|
formValue: mForm?.values,
|
||||||
prop: props.prop,
|
prop: props.prop,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user