From b26a83be27b200413b334035e1721c106faebbc2 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 17 Nov 2021 20:30:27 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E8=A1=A8=E5=8D=95=E9=A1=B9list?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=AF=E6=B7=BB=E5=8A=A0=E3=80=81=E5=8F=AF?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E3=80=81=E5=8F=AF=E6=8E=92=E5=BA=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/any/index.tsx | 3 ++ src/components/formFields/common.tsx | 2 + src/components/formFields/form/index.tsx | 50 ++++++++++++++++--- src/components/formFields/group/index.tsx | 20 ++++++++ .../formFields/importSubform/index.tsx | 18 +++++++ src/components/formFields/object/index.tsx | 20 ++++++++ src/components/formFields/tabs/index.tsx | 24 +++++++++ src/steps/filter/index.tsx | 28 ++++++++++- src/steps/form/index.tsx | 28 ++++++++++- src/util/value.ts | 18 +++++++ 10 files changed, 203 insertions(+), 8 deletions(-) diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index b0f9666..ad029b2 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -93,6 +93,7 @@ export default class AnyField extends Field : ( @@ -109,6 +110,7 @@ export default class AnyField extends Field : diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index b5c5c7e..6c6b5eb 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -92,6 +92,8 @@ export interface FieldProps { onValueListAppend: (path: string, value: any, validation: true | FieldError[]) => Promise // 事件:修改值 - 列表 - 删除 onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[]) => Promise + // 事件:修改值 - 列表 - 修改顺序 + onValueListSort: (path: string, index: number, sortType: string, validation: true | FieldError[]) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d57ede7..02982d0 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from '../common' import getALLComponents from '../' -import { getValue } from '../../../util/value' +import { getValue, listItemMove } from '../../../util/value' import { cloneDeep } from 'lodash' import ConditionHelper from '../../../util/condition' @@ -14,19 +14,24 @@ export interface FormFieldConfig extends FieldConfig { initialValues?: any // 新增子项时的默认值 mode?: 'show' // 子项仅显示列表 modeValue?: string + canInsert?: boolean + canRemove?: boolean + canSort?: boolean } export interface IFormField { insertText: string - onInsert: () => Promise + onInsert?: () => Promise children: React.ReactNode[] } export interface IFormFieldItem { index: number + isLastIndex: boolean title: string removeText: string - onRemove: () => Promise + onRemove?: () => Promise + onSort?: (sortType: string) => Promise children: React.ReactNode[] } @@ -204,6 +209,15 @@ export default class FormField extends Field { + const formDataList = listItemMove(cloneDeep(this.state.formDataList), index, sortType) + this.setState({ + formDataList + }) + this.formFieldsMountedList = listItemMove(this.formFieldsMountedList, index, sortType) + await this.props.onValueListSort('', index, sortType, true) + } handleChange = async (index: number, formFieldIndex: number, value: any) => { // const formField = this.formItemsList[index][formFieldIndex] @@ -308,6 +322,24 @@ export default class FormField extends Field { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListSort(`[${index}]${fullPath}`, _index, sortType, true) + + const formDataList = cloneDeep(this.state.formDataList) + if (validation === true) { + formDataList[index][formFieldIndex] = { status: 'normal' } + } else { + formDataList[index][formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formDataList + }) + } + } /** * 用于展示子表单组件中的每一子项中的每一个子表单项组件 @@ -353,7 +385,10 @@ export default class FormField extends Field await this.handleInsert(), + onInsert: canInsert? async () => await this.handleInsert(): undefined, children: ( (Array.isArray(value) ? value : []).map((itemValue: any, index: number) => { return {this.renderItemComponent({ index, + isLastIndex: value.length - 1 === index? true: false, title: primaryField !== undefined ? getValue(itemValue, primaryField) : index.toString(), removeText: removeText === undefined ? `删除 ${label}` : removeText, - onRemove: async () => await this.handleRemove(index), + onRemove: canRemove? async () => await this.handleRemove(index): undefined, + onSort: canSort? async (sortType: string) => await this.handleSort(index, sortType): undefined, children: (fields || []).map((formFieldConfig, fieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step })) { return null @@ -408,6 +445,7 @@ export default class FormField extends Field this.handleValueUnset(index, fieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => this.handleValueListAppend(index, fieldIndex, path, value, validation)} onValueListSplice={async (path, _index, count, validation) => this.handleValueListSplice(index, fieldIndex, path, _index, count, validation)} + onValueListSort={async (path, _index, sortType, validation) => await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index ebd9de7..692c48e 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -228,6 +228,25 @@ export default class GroupField extends Field { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListSort(fullPath, index, sortType, true) + + const formData = cloneDeep(this.state.formData) + if (validation === true) { + formData[formFieldIndex] = { status: 'normal' } + } else { + formData[formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formData + }) + } + } + renderComponent = (props: IGroupField) => { return 您当前使用的UI版本没有实现GroupField组件。 @@ -304,6 +323,7 @@ export default class GroupField extends Field this.handleValueUnset(formFieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => this.handleValueListAppend(formFieldIndex, path, value, validation)} onValueListSplice={async (path, index, count, validation) => this.handleValueListSplice(formFieldIndex, path, index, count, validation)} + onValueListSort={async (path, index, sortType, validation) => this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 366b6e8..c018257 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -246,7 +246,24 @@ export default class ImportSubformField extends Field { + const formFieldConfig = (this.state.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListSort(fullPath, index, sortType, true) + + const formData = cloneDeep(this.state.formData) + if (validation === true) { + formData[formFieldIndex] = { status: 'normal' } + } else { + formData[formFieldIndex] = { status: 'error', message: validation[0].message } + } + this.setState({ + formData + }) + } + } renderComponent = (props: IImportSubformField) => { return 您当前使用的UI版本没有实现ImportSubformField组件。 @@ -339,6 +356,7 @@ export default class ImportSubformField extends Field this.handleValueUnset(formFieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => this.handleValueListAppend(formFieldIndex, path, value, validation)} onValueListSplice={async (path, index, count, validation) => this.handleValueListSplice(formFieldIndex, path, index, count, validation)} + onValueListSort={async (path, index, sortType, validation) => this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 42179c9..6e62d03 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -320,6 +320,25 @@ export default class ObjectField extends Field { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListSort(fullPath === '' ? key : `${key}.${fullPath}`, _index, sortType, true) + + const formDataList = cloneDeep(this.state.formDataList) + if (validation === true) { + formDataList[key][formFieldIndex] = { status: 'normal' } + } else { + formDataList[key][formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formDataList + }) + } + } + /** * 用于展示子表单组件 * @param _props @@ -428,6 +447,7 @@ export default class ObjectField extends Field this.handleValueUnset(key, formFieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => this.handleValueListAppend(key, formFieldIndex, path, value, validation)} onValueListSplice={async (path, _index, count, validation) => this.handleValueListSplice(key, formFieldIndex, path, _index, count, validation)} + onValueListSort={async (path, _index, sortType, validation) => this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index dee3213..2247fc7 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -282,6 +282,29 @@ export default class TabsField extends Field { + const tab = (this.props.config.tabs || [])[index] + + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + const formFieldConfig = fields[formFieldIndex] + if (formFieldConfig) { + const fieldPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` + await this.props.onValueListSort(fullPath, _index, sortType, true) + + const formDataList = cloneDeep(this.state.formDataList) + if (!formDataList[index]) formDataList[index] = [] + if (validation === true) { + formDataList[index][formFieldIndex] = { status: 'normal' } + } else { + formDataList[index][formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formDataList + }) + } + } /** * 用于展示子表单组件 @@ -385,6 +408,7 @@ export default class TabsField extends Field this.handleValueUnset(index, formFieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => this.handleValueListAppend(index, formFieldIndex, path, value, validation)} onValueListSplice={async (path, _index, count, validation) => this.handleValueListSplice(index, formFieldIndex, path, _index, count, validation)} + onValueListSort={async (path, _index, sortType, validation) => this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 05bc4f6..9428f95 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -6,7 +6,7 @@ import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' import { cloneDeep, get, set, unset } from 'lodash' import ConditionHelper from '../../util/condition' -import { getValue, setValue } from '../../util/value' +import { getValue, setValue, listItemMove } from '../../util/value' /** * 表单步骤配置文件格式定义 @@ -381,6 +381,31 @@ export default class FilterStep extends Step { }) } } + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: string, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + + const list = listItemMove(get(this.formValue, fullPath, []), index, sortType) + set(this.formValue, fullPath, list) + this.setState({ + formValue: this.formValue + }) + if (this.props.onChange) { + this.props.onChange(this.formValue) + } + + if (validation === true) { + this.formData[formFieldIndex] = { status: 'normal' } + } else { + this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + } + + await this.setState({ + formData: cloneDeep(this.formData) + }) + } + } /** * 表单步骤组件 - UI渲染方法 @@ -472,6 +497,7 @@ export default class FilterStep extends Step { onValueUnset={async (path, validation) => await this.handleValueUnset(formFieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => await this.handleValueListAppend(formFieldIndex, path, value, validation)} onValueListSplice={async (path, index, count, validation) => await this.handleValueListSplice(formFieldIndex, path, index, count, validation)} + onValueListSort={async (path, index, sortType, validation) => await this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 4a658bb..ef72aed 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import { Field, FieldConfigs, FieldError } from '../../components/formFields/common' import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' -import { getValue, setValue } from '../../util/value' +import { getValue, setValue, listItemMove } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' import { cloneDeep, get, set, unset } from 'lodash' @@ -364,6 +364,31 @@ export default class FormStep extends Step { }) } } + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: string, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + + const list = listItemMove(get(this.formValue, fullPath, []), index, sortType) + set(this.formValue, fullPath, list) + this.setState({ + formValue: this.formValue + }) + if (this.props.onChange) { + this.props.onChange(this.formValue) + } + + if (validation === true) { + this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + } else { + this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + } + + await this.setState({ + formData: cloneDeep(this.formData) + }) + } + } /** * 表单步骤组件 - UI渲染方法 @@ -467,6 +492,7 @@ export default class FormStep extends Step { onValueUnset={async (path, validation) => await this.handleValueUnset(formFieldIndex, path, validation)} onValueListAppend={async (path, value, validation) => await this.handleValueListAppend(formFieldIndex, path, value, validation)} onValueListSplice={async (path, index, count, validation) => await this.handleValueListSplice(formFieldIndex, path, index, count, validation)} + onValueListSort={async (path, index, sortType, validation) => await this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/util/value.ts b/src/util/value.ts index 8588af3..4de4b66 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -103,3 +103,21 @@ export const getBoolean = (value: any) => { } return false } + +/** + * 处理list元素上移、下移 + * @param list list + * @param currentIndex 当前操作元素在list索引 + * @param sortType up或down + */ + export const listItemMove = (list: any[], currentIndex: number, sortType: string) => { + switch (sortType) { + case 'up': + currentIndex!==0 && (list[currentIndex] = list.splice(currentIndex - 1, 1, list[currentIndex])[0]) + break; + case 'down': + currentIndex < list.length - 1 && (list[currentIndex] = list.splice(currentIndex + 1, 1, list[currentIndex])[0]) + break; + } + return list +} -- Gitee From a8e00b70269a3ddd97e6311f659c26d181ac9c5c Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 18 Nov 2021 18:14:22 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E8=A1=A8=E5=8D=95=E9=A1=B9?= =?UTF-8?q?=E6=94=AF=E6=8C=81Collapse=E6=8A=98=E5=8F=A0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 02982d0..bc5784c 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -17,6 +17,7 @@ export interface FormFieldConfig extends FieldConfig { canInsert?: boolean canRemove?: boolean canSort?: boolean + canCollapse?: boolean // 是否用Collapse折叠展示 } export interface IFormField { @@ -32,6 +33,7 @@ export interface IFormFieldItem { removeText: string onRemove?: () => Promise onSort?: (sortType: string) => Promise + canCollapse?: boolean children: React.ReactNode[] } @@ -388,7 +390,8 @@ export default class FormField extends Field await this.handleRemove(index): undefined, onSort: canSort? async (sortType: string) => await this.handleSort(index, sortType): undefined, + canCollapse, children: (fields || []).map((formFieldConfig, fieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step })) { return null -- Gitee From 0b47ba1a613c9793fa2dac2842ab662926918994 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 19 Nov 2021 12:23:07 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84canCollapse?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index bc5784c..18d5036 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -23,6 +23,7 @@ export interface FormFieldConfig extends FieldConfig { export interface IFormField { insertText: string onInsert?: () => Promise + canCollapse?: boolean children: React.ReactNode[] } @@ -401,6 +402,7 @@ export default class FormField extends Field await this.handleInsert(): undefined, + canCollapse, children: ( (Array.isArray(value) ? value : []).map((itemValue: any, index: number) => { return -- Gitee From 10012626c59928836a8580910c3526e8600bac53 Mon Sep 17 00:00:00 2001 From: niuxiaoguang Date: Tue, 23 Nov 2021 19:00:15 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 2 +- src/components/formFields/form/index.tsx | 8 ++++---- src/components/formFields/group/index.tsx | 2 +- src/components/formFields/importSubform/index.tsx | 2 +- src/components/formFields/object/index.tsx | 2 +- src/components/formFields/tabs/index.tsx | 2 +- src/steps/filter/index.tsx | 2 +- src/steps/form/index.tsx | 2 +- src/util/value.ts | 14 +++++++------- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 6c6b5eb..4d6814e 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -93,7 +93,7 @@ export interface FieldProps { // 事件:修改值 - 列表 - 删除 onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[]) => Promise // 事件:修改值 - 列表 - 修改顺序 - onValueListSort: (path: string, index: number, sortType: string, validation: true | FieldError[]) => Promise + onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 18d5036..ca01bb3 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -33,7 +33,7 @@ export interface IFormFieldItem { title: string removeText: string onRemove?: () => Promise - onSort?: (sortType: string) => Promise + onSort?: (sortType: 'up' | 'down') => Promise canCollapse?: boolean children: React.ReactNode[] } @@ -213,7 +213,7 @@ export default class FormField extends Field { + handleSort = async (index: number, sortType: 'up' | 'down') => { const formDataList = listItemMove(cloneDeep(this.state.formDataList), index, sortType) this.setState({ formDataList @@ -325,7 +325,7 @@ export default class FormField extends Field { + handleValueListSort = async (index: number, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` @@ -414,7 +414,7 @@ export default class FormField extends Field await this.handleRemove(index): undefined, - onSort: canSort? async (sortType: string) => await this.handleSort(index, sortType): undefined, + onSort: canSort? async (sortType: 'up' | 'down') => await this.handleSort(index, sortType): undefined, canCollapse, children: (fields || []).map((formFieldConfig, fieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step })) { diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index c082e2b..03c50ee 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -228,7 +228,7 @@ export default class GroupField extends Field { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 45fe93f..0a446a0 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -246,7 +246,7 @@ export default class ImportSubformField extends Field { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 6e62d03..e9ad5c3 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -320,7 +320,7 @@ export default class ObjectField extends Field { + handleValueListSort = async (key: string, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 2247fc7..21615d5 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -282,7 +282,7 @@ export default class TabsField extends Field { + handleValueListSort = async (index: number, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const tab = (this.props.config.tabs || [])[index] const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 9428f95..c6cd09c 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -381,7 +381,7 @@ export default class FilterStep extends Step { }) } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: string, validation: true | FieldError[]) => { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 9ef5d7a..16a52f3 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -366,7 +366,7 @@ export default class FormStep extends Step { }) } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: string, validation: true | FieldError[]) => { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` diff --git a/src/util/value.ts b/src/util/value.ts index 4de4b66..f10cbd7 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -13,15 +13,15 @@ export const getValue = (obj: any, path: string = '', defaultValue: any = undefi } const merge = (a: any, b: any): any => { - return assignInWith(a, b, (a,b) => { + return assignInWith(a, b, (a, b) => { if (isUndefined(a) && isArray(b)) { a = [] } if (isObject(b)) { if (isArray(a)) { - return merge(a,b).filter((i: any) => i !== undefined) + return merge(a, b).filter((i: any) => i !== undefined) } else { - return merge(a,b) + return merge(a, b) } } }) @@ -110,13 +110,13 @@ export const getBoolean = (value: any) => { * @param currentIndex 当前操作元素在list索引 * @param sortType up或down */ - export const listItemMove = (list: any[], currentIndex: number, sortType: string) => { +export const listItemMove = (list: any[], currentIndex: number, sortType: 'up' | 'down') => { switch (sortType) { case 'up': - currentIndex!==0 && (list[currentIndex] = list.splice(currentIndex - 1, 1, list[currentIndex])[0]) + currentIndex !== 0 && (list[currentIndex] = list.splice(currentIndex - 1, 1, list[currentIndex])[0]) break; - case 'down': - currentIndex < list.length - 1 && (list[currentIndex] = list.splice(currentIndex + 1, 1, list[currentIndex])[0]) + case 'down': + currentIndex < list.length - 1 && (list[currentIndex] = list.splice(currentIndex + 1, 1, list[currentIndex])[0]) break; } return list -- Gitee From feb3d52218e26e9a366f71e1dc66dd2d3976eab4 Mon Sep 17 00:00:00 2001 From: niuxiaoguang Date: Tue, 23 Nov 2021 19:14:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E9=80=BB=E8=BE=91=E5=85=BC=E5=AE=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF=E6=83=85=E5=86=B5?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/form/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 16a52f3..320cfc2 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -318,7 +318,8 @@ export default class FormStep extends Step { if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - const list = get(this.formValue, fullPath, []) + let list = get(this.formValue, fullPath, []) + if (!Array.isArray(list)) list = [] list.push(value) set(this.formValue, fullPath, list) this.setState({ -- Gitee