diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 13fb7ef1fcebe47faac0cce03ad4f2dc98b26cd8..b4e514f4290eaab5f43b2d5c13a746a37b822698 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -83,13 +83,13 @@ export interface DetailFieldProps { // TODO 待删除 onChange: (value: T) => Promise // 事件:设置值 - onValueSet: (path: string, value: T, validation: true | DetailFieldError[]) => Promise + onValueSet: (path: string, value: T, options?: { noPathCombination?: boolean }) => Promise // // 事件:置空值 - onValueUnset: (path: string, validation: true | DetailFieldError[]) => Promise + onValueUnset: (path: string, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | DetailFieldError[]) => Promise + onValueListAppend: (path: string, value: any, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | DetailFieldError[]) => Promise + onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise loadPageConfig: (pageID: any) => Promise diff --git a/src/components/detail/enum/index.tsx b/src/components/detail/enum/index.tsx index 9ebfa1934b9be3694439f502e5392911757fe2c5..7e5858fe92949f99d206465ce389c8d4963a28c4 100644 --- a/src/components/detail/enum/index.tsx +++ b/src/components/detail/enum/index.tsx @@ -1,4 +1,3 @@ -import { config } from 'process' import React from 'react' import { DetailField, DetailFieldProps, DetailFieldConfig, IDetailField } from '../common' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' diff --git a/src/components/detail/group/index.tsx b/src/components/detail/group/index.tsx index 3bbf31af9cedfc502b8688ca35321cf693145217..3858b556db6b3b6200d739e4db82a8245088eb42 100644 --- a/src/components/detail/group/index.tsx +++ b/src/components/detail/group/index.tsx @@ -1,7 +1,7 @@ import React from 'react' import { cloneDeep } from 'lodash' import { setValue, getValue } from '../../../util/value' -import { DetailField, DetailFieldConfig, DetailFieldError, DetailFieldProps, IDetailField } from '../common' +import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../common' import getALLComponents, { DetailFieldConfigs } from '../' import { IDetailItem } from '../../../steps/detail' import ConditionHelper from '../../../util/condition' @@ -20,7 +20,6 @@ export interface IGroupField { } interface IGroupFieldState { - detailData: { status: 'normal' | 'error' | 'loading', message?: string }[] } export default class GroupField extends DetailField implements IDetailField { @@ -33,9 +32,7 @@ export default class GroupField extends DetailField) { super(props) - this.state = { - detailData: [] - } + this.state = {} } get = async () => { @@ -68,22 +65,6 @@ export default class GroupField extends DetailField { - detailData[detailFieldIndex] = { status: 'normal' } - return { detailData: cloneDeep(detailData) } - }) - } else { - await this.setState(({ detailData }) => { - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message } - return { detailData: cloneDeep(detailData) } - }) - } await detailField?.didMount() } } @@ -118,79 +99,35 @@ export default class GroupField extends DetailField { + handleValueSet = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` - await this.props.onValueSet(fullPath, value, true) - - const detailData = cloneDeep(this.state.detailData) - if (validation === true) { - detailData[detailFieldIndex] = { status: 'normal' } - } else { - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - detailData - }) + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) + await this.props.onValueSet(fullPath, value) } } - handleValueUnset = async (detailFieldIndex: number, path: string, validation: true | DetailFieldError[]) => { + handleValueUnset = async (detailFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` - await this.props.onValueUnset(fullPath, true) - - const detailData = cloneDeep(this.state.detailData) - if (validation === true) { - detailData[detailFieldIndex] = { status: 'normal' } - } else { - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - detailData - }) + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) + await this.props.onValueUnset(fullPath) } } - handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, validation: true | DetailFieldError[]) => { + handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` - await this.props.onValueListAppend(fullPath, value, true) - - const detailData = cloneDeep(this.state.detailData) - if (validation === true) { - detailData[detailFieldIndex] = { status: 'normal' } - } else { - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - detailData - }) + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) + await this.props.onValueListAppend(fullPath, value) } } - handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, validation: true | DetailFieldError[]) => { + handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` - await this.props.onValueListSplice(fullPath, index, count, true) - - const detailData = cloneDeep(this.state.detailData) - if (validation === true) { - detailData[detailFieldIndex] = { status: 'normal' } - } else { - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - detailData - }) + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) + await this.props.onValueListSplice(fullPath, index, count) } } diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 1565bc147a81efbf2936fb564154d6420958e923..5e59af54ef5d066d09fd42bfa310611a8165d512 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -12,10 +12,11 @@ import { ColumnsConfig } from '../../../interface' /** * 子表单配置项 - * - withConfig: 拓展配置 - * - * - enable: 是否开启 - * - * - dataField: (序列化)数据 - * - * - configField: (序列化)配置 + * - configFrom: 配置来源(get用途) + * - * - type: 'data' | 'interface' // 来源类型 + * - * - dataField: 值来源字段 // 仅type为data时生效 + * - * - configField: 配置来源字段 // 仅type为data时生效 + * - * - interface: 来源接口配置 // 仅type为interface时生效 */ export interface ImportSubformFieldConfig extends DetailFieldConfig { type: 'import_subform', @@ -45,7 +46,7 @@ interface IImportSubformFieldState { formData: { status: 'normal' | 'error' | 'loading', message?: string }[] } -export default class ImportSubformField extends DetailField implements IDetailField { +export default class DetailImportSubformField extends DetailField implements IDetailField { // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Display => getALLComponents[type] @@ -98,42 +99,42 @@ export default class ImportSubformField extends DetailField { + handleValueSet = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) - await this.props.onValueSet(fullPath, value, true) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) + await this.props.onValueSet(fullPath, value) } } - handleValueUnset = async (formFieldIndex: number, path: string) => { + handleValueUnset = async (formFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) - await this.props.onValueUnset(fullPath, true) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) + await this.props.onValueUnset(fullPath) } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any) => { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) - await this.props.onValueListAppend(fullPath, value, true) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) + await this.props.onValueListAppend(fullPath, value) } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number) => { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) - await this.props.onValueListSplice(fullPath, index, count, true) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) + await this.props.onValueListSplice(fullPath, index, count) } } @@ -250,10 +251,10 @@ export default class ImportSubformField extends DetailField this.handleValueSet(formFieldIndex, path, value)} - onValueUnset={async (path) => this.handleValueUnset(formFieldIndex, path)} - onValueListAppend={async (path, value) => this.handleValueListAppend(formFieldIndex, path, value)} - onValueListSplice={async (path, index, count) => this.handleValueListSplice(formFieldIndex, path, index, count)} + onValueSet={async (path, value, options) => this.handleValueSet(formFieldIndex, path, value, options)} + onValueUnset={async (path, options) => this.handleValueUnset(formFieldIndex, path, options)} + onValueListAppend={async (path, value, options) => this.handleValueListAppend(formFieldIndex, path, value, options)} + onValueListSplice={async (path, index, count, options) => this.handleValueListSplice(formFieldIndex, path, index, count, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx new file mode 100644 index 0000000000000000000000000000000000000000..09d8f2756346807bd594a43e2d3f66f7533b7bd3 --- /dev/null +++ b/src/components/formFields/code/index.tsx @@ -0,0 +1,153 @@ +import React, { KeyboardEvent } from 'react' +import { Field, FieldConfig, FieldError, IField } from '../common' +import { getBoolean } from '../../../util/value' + +/** + * code编辑器配置项 + * - codeType: 语言类型 + * - height: 代码编辑器高度 + * - theme: 编辑器主题风格 + * - fullScreen: 是否支持全屏 + */ +export interface CodeFieldConfig extends FieldConfig { + type: 'code' + codeType: 'xml' | 'json' | 'javascript' | 'java' + height: number + theme: 'white' | 'black' + fullScreen: boolean +} + +export interface ICodeField { + codeType: 'xml' | 'json' | 'javascript' | 'java' + fullScreenStatus: boolean + height: number + theme: 'white' | 'black' + value: string + onChange: (value: string) => Promise +} + +/** + * code编辑器配置项 + * - codeType: 语言类型 + * - height: 代码编辑器高度 + * - onResetValue: 编辑器重置为默认值 + * - fullScreen: 是否支持全屏 + * - fullScreenStatus: 编辑器是不是处于全屏状态 + */ +export interface ICodeFieldContainer { + fullScreen: boolean + fullScreenStatus: boolean + theme: 'white' | 'black' + children: React.ReactNode + onResetValue: (value: string) => Promise + keydownCallback: (value: KeyboardEvent) => Promise + enterFull: () => void + exitFull: () => void +} +interface State { + fullScreenStatus: boolean // 编辑器是不是处于全屏状态 +} +export default class CodeField extends Field implements IField { + state:State = { + fullScreenStatus: false + } + + reset: () => Promise = async () => { + const defaults = await this.defaultValue() + return (defaults === undefined) ? '' : defaults + } + + validate = async (value: string): Promise => { + const { + config: { + label, + required + } + } = this.props + + const errors: FieldError[] = [] + + if (getBoolean(required)) { + if (value === '' || value === undefined || value === null || String(value).trim() === '') { + errors.push(new FieldError(`输入${label}`)) + return errors + } + } + + return errors.length ? errors : true + } + + keydownCallback = (e: KeyboardEvent) => { + e.stopPropagation() + const keyCode = e.keyCode || e.which || e.charCode + const ctrlKey = e.ctrlKey || e.metaKey + if (this.props.config.fullScreen) { + if ((e.key === 'j' || keyCode === 74) && ctrlKey) { + this.enterFull() + } else if ((e.key === 'Escape' || keyCode === 27)) { + this.exitFull() + } + } + } + + enterFull = () => { + this.setState({ fullScreenStatus: true }) + } + + exitFull = () => { + this.setState({ fullScreenStatus: false }) + } + + renderContainer = (props: ICodeFieldContainer) => { + return + 您当前使用的UI版本没有实现CodeField的container组件。 +
+ +
+
+ } + + renderComponent = (props: ICodeField) => { + return + 您当前使用的UI版本没有实现CodeField组件。 +
+ +
+
+ } + + render = () => { + const { + value, + config: { + theme, + fullScreen, + height, + codeType + } + } = this.props + const { fullScreenStatus } = this.state + + return ( + + {this.renderContainer({ + fullScreenStatus, + fullScreen, + theme, + onResetValue: async (defaultCodeValue: string) => await this.props.onValueSet('', defaultCodeValue, await this.validate(defaultCodeValue)), + keydownCallback: async (e: KeyboardEvent) => await this.keydownCallback(e), + enterFull: this.enterFull, + exitFull: this.exitFull, + children: this.renderComponent({ + codeType, + fullScreenStatus, + value, + theme, + height, + onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) + }) + })} + + ) + } +} diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 9539759b1304936677c5c761ee15c365b09314af..cf36a02b97954475cc0da669c5ddebacd04fa719 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -83,16 +83,16 @@ export interface FieldProps { config: C // TODO 待删除 onChange: (value: T) => Promise - // 事件:设置值 - onValueSet: (path: string, value: T, validation: true | FieldError[]) => Promise + // 事件:设置值 noPathCombination:为true时不做路径拼接 + onValueSet: (path: string, value: T, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:置空值 - onValueUnset: (path: string, validation: true | FieldError[]) => Promise + onValueUnset: (path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | FieldError[]) => Promise + onValueListAppend: (path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[]) => Promise + onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 修改顺序 - onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise + onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } @@ -187,13 +187,13 @@ export interface DisplayProps { step: number, config: C, // 事件:设置值 - onValueSet: (path: string, value: T, validation: true | FieldError[]) => Promise + onValueSet: (path: string, value: T, options?: { noPathCombination?: boolean }) => Promise // 事件:置空值 - onValueUnset: (path: string, validation: true | FieldError[]) => Promise + onValueUnset: (path: string, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | FieldError[]) => Promise + onValueListAppend: (path: string, value: any, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[]) => Promise + onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/formFields/diffCode/index.tsx b/src/components/formFields/diffCode/index.tsx new file mode 100644 index 0000000000000000000000000000000000000000..eea5d6f1114aa0573612d5e6b0c1598e8592f228 --- /dev/null +++ b/src/components/formFields/diffCode/index.tsx @@ -0,0 +1,146 @@ +import React, { KeyboardEvent } from 'react' +import { get } from 'lodash' +import { Field, FieldConfig, FieldError, IField } from '../common' + +/** + * diffCode编辑器配置项 + * - codeType: 语言类型 + * - height: 代码编辑器高度 + * - theme: 编辑器主题风格 + * - fullScreen: 是否支持全屏 + * - originalCodeField: 代码原始值入参字段 + * - modifiedCodeField: 代码修改值入参字段 + */ +export interface DiffCodeFieldConfig extends FieldConfig { + type: 'diffcode' + codeType: 'xml' | 'json' | 'javascript' | 'java' + height: number + theme: 'white' | 'black' + fullScreen: boolean + originalCodeField: string + modifiedCodeField: string +} + +export interface IDiffCodeField { + codeType: 'xml' | 'json' | 'javascript' | 'java' + fullScreenStatus: boolean + height: number + theme: 'white' | 'black' + originalCode: string + modifiedCode: string +} + +/** + * diffCode编辑器配置项 + * - codeType: 语言类型 + * - height: 代码编辑器高度 + * - fullScreen: 是否支持全屏 + * - fullScreenStatus: 编辑器是不是处于全屏状态 + */ +export interface IDiffCodeFieldContainer { + fullScreen: boolean + fullScreenStatus: boolean + theme: 'white' | 'black' + children: React.ReactNode + keydownCallback: (value: KeyboardEvent) => Promise + enterFull: () => void + exitFull: () => void +} +interface DiffCodeFieldValue { + [field: string]: any +} +interface State { + fullScreenStatus: boolean // 编辑器是不是处于全屏状态 +} + +export default class DiffCodeField extends Field implements IField { + state:State = { + fullScreenStatus: false + } + + get: () => Promise = async () => { + return {} + } + + reset: () => Promise = async () => { + const defaults = await this.defaultValue() + return (defaults === undefined) ? '' : defaults + } + + validate = async (value: DiffCodeFieldValue): Promise => { + return true + } + + keydownCallback = (e: KeyboardEvent) => { + const keyCode = e.keyCode || e.which || e.charCode + const ctrlKey = e.ctrlKey || e.metaKey + if (this.props.config.fullScreen) { + if ((e.key === 'j' || keyCode === 74) && ctrlKey) { + this.enterFull() + } else if ((e.key === 'Escape' || keyCode === 27)) { + this.exitFull() + } + } + } + + enterFull = () => { + this.setState({ fullScreenStatus: true }) + } + + exitFull = () => { + this.setState({ fullScreenStatus: false }) + } + + renderContainer = (props: IDiffCodeFieldContainer) => { + return + 您当前使用的UI版本没有实现CodeField的container组件。 +
+
+
+ } + + renderComponent = (props: IDiffCodeField) => { + return + 您当前使用的UI版本没有实现CodeField组件。 +
+
+
+ } + + render = () => { + const { + value, + config: { + theme, + fullScreen, + height, + codeType, + originalCodeField, + modifiedCodeField + } + } = this.props + const { fullScreenStatus } = this.state + const originalCode = get(value, originalCodeField) || '' + const modifiedCode = get(value, modifiedCodeField) || '' + return ( + + {this.renderContainer({ + fullScreenStatus, + fullScreen, + theme, + keydownCallback: async (e: KeyboardEvent) => await this.keydownCallback(e), + enterFull: this.enterFull, + exitFull: this.exitFull, + children: this.renderComponent({ + codeType, + fullScreenStatus, + originalCode, + modifiedCode, + theme, + height + }) + })} + + ) + } +} diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d95ddeaeedadd3d4e9843f6ea100c67d497c0e56..2c738f130a684c94a69b2857973c72054478a77f 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -135,7 +135,7 @@ export default class FormField extends Field { + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueSet(`[${index}]${fullPath}`, value, true) const formDataList = cloneDeep(this.state.formDataList) @@ -341,10 +341,10 @@ export default class FormField extends Field { + handleValueUnset = async (index: number, formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueUnset(`[${index}]${fullPath}`, true) const formDataList = cloneDeep(this.state.formDataList) @@ -360,10 +360,10 @@ export default class FormField extends Field { + handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListAppend(`[${index}]${fullPath}`, value, true) const formDataList = cloneDeep(this.state.formDataList) @@ -379,10 +379,10 @@ export default class FormField extends Field { + handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListSplice(`[${index}]${fullPath}`, _index, count, true) const formDataList = cloneDeep(this.state.formDataList) @@ -398,10 +398,10 @@ export default class FormField extends Field { + handleValueListSort = async (index: number, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListSort(`[${index}]${fullPath}`, _index, sortType, true) const formDataList = cloneDeep(this.state.formDataList) @@ -533,11 +533,11 @@ export default class FormField extends Field this.handleChange(index, fieldIndex, value)} - onValueSet={async (path, value, validation) => this.handleValueSet(index, fieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => 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)} + onValueSet={async (path, value, validation, options) => this.handleValueSet(index, fieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => this.handleValueUnset(index, fieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => this.handleValueListAppend(index, fieldIndex, path, value, validation, options)} + onValueListSplice={async (path, _index, count, validation, options) => this.handleValueListSplice(index, fieldIndex, path, _index, count, validation, options)} + onValueListSort={async (path, _index, sortType, validation, options) => await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation, options)} 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 22347f70218252b2865cff54c581901b6af4e888..7bec8a155412e520f4cedb18ea0134b058694cdf 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -71,7 +71,8 @@ export default class GroupField extends Field { + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueSet(fullPath, value, true) const formData = cloneDeep(this.state.formData) if (validation === true) { @@ -200,10 +201,10 @@ export default class GroupField extends Field { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueUnset(fullPath, true) const formData = cloneDeep(this.state.formData) if (validation === true) { @@ -218,10 +219,10 @@ export default class GroupField extends Field { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListAppend(fullPath, value, true) const formData = cloneDeep(this.state.formData) if (validation === true) { @@ -236,10 +237,10 @@ export default class GroupField extends Field { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListSplice(fullPath, index, count, true) const formData = cloneDeep(this.state.formData) if (validation === true) { @@ -254,10 +255,10 @@ export default class GroupField extends Field { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (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) { @@ -367,11 +368,11 @@ export default class GroupField extends Field { await this.handleChange(formFieldIndex, value) }} - onValueSet={async (path, value, validation) => this.handleValueSet(formFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => 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)} + onValueSet={async (path, value, validation, options) => this.handleValueSet(formFieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => this.handleValueUnset(formFieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => this.handleValueListAppend(formFieldIndex, path, value, validation, options)} + onValueListSplice={async (path, index, count, validation, options) => this.handleValueListSplice(formFieldIndex, path, index, count, validation, options)} + onValueListSort={async (path, index, sortType, validation, options) => this.handleValueListSort(formFieldIndex, path, index, sortType, validation, options)} 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 5735eb9ac76be88b0f40b90b7af81d263cb5af57..5863faf40970352ad204642aabebc5cd6b8fe52a 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -4,7 +4,7 @@ import { setValue, getValue, getBoolean } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' -import { cloneDeep } from 'lodash' +import { cloneDeep, isEqual } from 'lodash' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' @@ -12,7 +12,12 @@ import { ColumnsConfig } from '../../../interface' /** * 子表单配置项 - * - withConfig: 拓展配置 + * - configFrom: 配置来源(get用途) + * - * - type: 'data' | 'interface' // 来源类型 + * - * - dataField: 值来源字段 // 仅type为data时生效 + * - * - configField: 配置项来源字段 // 仅type为data时生效 + * - * - interface: 来源接口配置 // 仅type为interface时生效 + * - withConfig: 拓展配置(set用途) * - * - enable: 是否开启 * - * - dataField: (序列化)数据 * - * - configField: (序列化)配置 @@ -20,6 +25,7 @@ import { ColumnsConfig } from '../../../interface' export interface ImportSubformFieldConfig extends FieldConfig { type: 'import_subform', interface?: InterfaceConfig + configFrom?: ImportSubformConfigFromData | ImportSubformConfigFromInterface withConfig?: { enable: boolean dataField: string @@ -27,7 +33,16 @@ export interface ImportSubformFieldConfig extends FieldConfig { } childColumns?: ColumnsConfig } +interface ImportSubformConfigFromData { + type: 'data' + dataField?: string + configField?: string +} +interface ImportSubformConfigFromInterface { + type: 'interface' + interface?: InterfaceConfig +} export interface IImportSubformField { columns?: ColumnsConfig children: React.ReactNode[] @@ -85,7 +100,7 @@ export default class ImportSubformField extends Field { + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) await this.props.onValueSet(fullPath, value, true) const formData = cloneDeep(this.state.formData) @@ -233,10 +248,10 @@ export default class ImportSubformField extends Field { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) await this.props.onValueUnset(fullPath, true) const formData = cloneDeep(this.state.formData) @@ -252,10 +267,10 @@ export default class ImportSubformField extends Field { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) await this.props.onValueListAppend(fullPath, value, true) const formData = cloneDeep(this.state.formData) @@ -271,10 +286,10 @@ export default class ImportSubformField extends Field { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) await this.props.onValueListSplice(fullPath, index, count, true) const formData = cloneDeep(this.state.formData) @@ -290,10 +305,10 @@ export default class ImportSubformField extends Field { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) await this.props.onValueListSort(fullPath, index, sortType, true) const formData = cloneDeep(this.state.formData) @@ -309,6 +324,24 @@ export default class ImportSubformField extends Field { + let dataToUnstringfy = data + if (Object.prototype.toString.call(data) === '[object String]') { + try { + dataToUnstringfy = JSON.parse(data) + } catch (e) { + console.error('当前动态子表单接口响应数据格式不是合格的json字符串') + dataToUnstringfy = [] + } + } + return dataToUnstringfy + } + renderComponent = (props: IImportSubformField) => { return 您当前使用的UI版本没有实现ImportSubformField组件。 @@ -336,27 +369,36 @@ export default class ImportSubformField extends Field { - let dataToUnstringfy = data - let dataToStringfy = JSON.stringify(data) - if (Object.prototype.toString.call(data) === '[object String]') { - try { - dataToStringfy = data - dataToUnstringfy = JSON.parse(data) - } catch (e) { - console.error('当前动态子表单接口响应数据格式不是合格的json字符串') - dataToUnstringfy = [] - dataToStringfy = '[]' - } - } - (this.props.config.withConfig?.enable && this.props.config.withConfig?.configField) && this.props.onValueSet(this.props.config.withConfig.configField, data, true) - if (dataToStringfy !== JSON.stringify(this.state.fields)) { + const dataToUnstringfy = this.handleDataToUnstringfy(data) + if (this.props.config.withConfig?.enable && this.props.config.withConfig?.configField) this.props.onValueSet(this.props.config.withConfig.configField, data, true) + if (!isEqual(dataToUnstringfy, this.state.fields)) { this.setState({ fields: dataToUnstringfy }) @@ -364,7 +406,7 @@ export default class ImportSubformField extends Field } else { return ( @@ -434,11 +476,11 @@ export default class ImportSubformField extends Field { await this.handleChange(formFieldIndex, value) }} - onValueSet={async (path, value, validation) => this.handleValueSet(formFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => 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)} + onValueSet={async (path, value, validation, options) => this.handleValueSet(formFieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => this.handleValueUnset(formFieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => this.handleValueListAppend(formFieldIndex, path, value, validation, options)} + onValueListSplice={async (path, index, count, validation, options) => this.handleValueListSplice(formFieldIndex, path, index, count, validation, options)} + onValueListSort={async (path, index, sortType, validation, options) => this.handleValueListSort(formFieldIndex, path, index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/index.tsx b/src/components/formFields/index.tsx index e7735a6dd6c6f12f256e6133b149ea6f00ea69cc..d7e901304b2416ed2dbb5be77ad3caae618d6696 100644 --- a/src/components/formFields/index.tsx +++ b/src/components/formFields/index.tsx @@ -23,6 +23,8 @@ import HiddenField from './hidden' import TabsField, { TabsFieldConfig } from './tabs' import MultipleTextField, { MultipleTextFieldConfig } from './multipleText' import CustomField, { CustomFieldConfig } from './custom' +import CodeField, { CodeFieldConfig } from './code' +import DiffCodeField, { DiffCodeFieldConfig } from './diffCode' import TextDisplay from './text/display' import RadioDisplay from './radio/display' @@ -67,7 +69,9 @@ export type FieldConfigs = ObjectFieldConfig | TabsFieldConfig | MultipleTextFieldConfig | - CustomFieldConfig + CustomFieldConfig | + CodeFieldConfig | + DiffCodeFieldConfig export type componentType = 'text' | @@ -93,7 +97,9 @@ export type componentType = 'object' | 'tabs' | 'multiple_text'| - 'custom' + 'custom' | + 'code' | + 'diffcode' export default { text: TextField, @@ -118,7 +124,9 @@ export default { hidden: HiddenField, tabs: TabsField, multiple_text: MultipleTextField, - custom: CustomField + custom: CustomField, + code: CodeField, + diffcode: DiffCodeField } export const display = { diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index b0de063901f60ff11be62e7d7e9855d0ae8abca5..e3ddba50f98f7760fbaa1f0d92ecf34e59b62c38 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -83,7 +83,7 @@ export default class ObjectField extends Field extends Field extends Field { + handleValueSet = async (key: string, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueSet(fullPath === '' ? key : `${key}.${fullPath}`, value, true) const formDataList = cloneDeep(this.state.formDataList) @@ -278,10 +278,10 @@ export default class ObjectField extends Field { + handleValueUnset = async (key: string, formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueUnset(fullPath === '' ? key : `${key}.${fullPath}`, true) const formDataList = cloneDeep(this.state.formDataList) @@ -297,10 +297,10 @@ export default class ObjectField extends Field { + handleValueListAppend = async (key: string, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListAppend(fullPath === '' ? key : `${key}.${fullPath}`, value, true) const formDataList = cloneDeep(this.state.formDataList) @@ -316,10 +316,10 @@ export default class ObjectField extends Field { + handleValueListSplice = async (key: string, formFieldIndex: number, path: string, _index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) await this.props.onValueListSplice(fullPath === '' ? key : `${key}.${fullPath}`, _index, count, true) const formDataList = cloneDeep(this.state.formDataList) @@ -335,10 +335,10 @@ export default class ObjectField extends Field { + handleValueListSort = async (key: string, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (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) @@ -472,11 +472,11 @@ export default class ObjectField extends Field this.handleChange(key, formFieldIndex, value)} - onValueSet={async (path, value, validation) => this.handleValueSet(key, formFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => 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)} + onValueSet={async (path, value, validation, options) => this.handleValueSet(key, formFieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => this.handleValueUnset(key, formFieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => this.handleValueListAppend(key, formFieldIndex, path, value, validation, options)} + onValueListSplice={async (path, _index, count, validation, options) => this.handleValueListSplice(key, formFieldIndex, path, _index, count, validation, options)} + onValueListSort={async (path, _index, sortType, validation, options) => this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation, options)} 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 a32b1157b5b184b5c38df4136ce26cb4743a4a6d..6525e9bcc299772361383cdbfb4edb407c3bdd76 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -94,7 +94,7 @@ export default class TabsField extends Field extends Field extends Field { } - handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { 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 fieldPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` await this.props.onValueSet(fullPath, value, true) @@ -226,13 +226,13 @@ export default class TabsField extends Field { + handleValueUnset = async (index: number, formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { 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 fieldPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` await this.props.onValueUnset(fullPath, true) @@ -250,13 +250,13 @@ export default class TabsField extends Field { + handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { 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 fieldPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` await this.props.onValueListAppend(fullPath, value, true) @@ -274,13 +274,13 @@ export default class TabsField extends Field { + handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { 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 fieldPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` await this.props.onValueListSplice(fullPath, _index, count, true) @@ -298,13 +298,13 @@ export default class TabsField extends Field { + handleValueListSort = async (index: number, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { 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 fieldPath = options && options.noPathCombination ? path : (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) @@ -432,11 +432,11 @@ export default class TabsField extends Field this.handleChange(index, formFieldIndex, value)} - onValueSet={async (path, value, validation) => this.handleValueSet(index, formFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => 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)} + onValueSet={async (path, value, validation, options) => this.handleValueSet(index, formFieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => this.handleValueUnset(index, formFieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => this.handleValueListAppend(index, formFieldIndex, path, value, validation, options)} + onValueListSplice={async (path, _index, count, validation, options) => this.handleValueListSplice(index, formFieldIndex, path, _index, count, validation, options)} + onValueListSort={async (path, _index, sortType, validation, options) => this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/formFields/upload/index.tsx b/src/components/formFields/upload/index.tsx index 5b8fc83ecb6a6ce2d1a7483372cbf60e3a772e7d..0013ca16f7d6eb4d12cfed89c5777ce4a71a523d 100644 --- a/src/components/formFields/upload/index.tsx +++ b/src/components/formFields/upload/index.tsx @@ -11,6 +11,7 @@ export interface UploadFieldConfigBasic extends FieldConfig { interface: InterfaceConfig requireField: string responseField: string + extraResponseField: Array<{from: string, to: string}> } export interface UploadFieldConfigImage extends UploadFieldConfigBasic { @@ -150,7 +151,6 @@ export default class UploadField extends Field implements IColumn { + identifier: string = '' + entry: string = '' + container: RefObject = React.createRef() + customColumn: MicroApp | null = null + + componentDidMount () { + this.loadCustomColumn(this.props.config.entry) + } + + getSnapshotBeforeUpdate () { + const snapshot: string[] = [] + if (this.entry !== this.props.config.entry) { + snapshot.push('entry') + } + return snapshot + } + + componentDidUpdate (_: ColumnProps, __: {}, snapshot: string[]) { + if (snapshot.includes('entry')) { + this.loadCustomColumn(this.props.config.entry) + } else { + if (this.customColumn && this.customColumn.update) { + this.customColumn.update({ + value: this.props.value, + record: this.props.record, + data: cloneDeep(this.props.data), + step: this.props.step, + config: this.props.config, + table: this.props.table, + base: this.props.baseRoute, + loadDomain: this.props.loadDomain + }) + } + } + } + + loadCustomColumn = (entry: string) => { + if (this.container.current && entry) { + this.entry = this.props.config.entry + this.identifier = `custom|${moment().format('x')}|${Math.floor(Math.random() * 1000)}` + this.customColumn = loadMicroApp({ + name: this.identifier, + entry, + container: this.container.current, + props: { + value: this.props.value, + record: this.props.record, + data: cloneDeep(this.props.data), + step: this.props.step, + config: this.props.config, + table: this.props.table, + base: this.props.baseRoute, + loadDomain: this.props.loadDomain + } + }) + } + } + + render = () => { + return ( +
+ ) + } +} diff --git a/src/components/tableColumns/index.tsx b/src/components/tableColumns/index.tsx index aa8159bee59ff9bb5b32d4cb6efe4c8e28f99d6d..ff52f9443bb24c2fdad21024a94272d152b7e250 100644 --- a/src/components/tableColumns/index.tsx +++ b/src/components/tableColumns/index.tsx @@ -7,6 +7,7 @@ import DatetimeColumn, { DatetimeColumnConfig } from './datetime' import DatetimeRangeColumn, { DatetimeRangeColumnConfig } from './datetimeRange' import MultirowColumn, { MultirowColumnConfig } from './multirowText' import ImageColumn, { ImageColumnConfig } from './image' +import CustomColumn, { CustomColumnConfig } from './custom' export interface componentType { type: 'text' @@ -17,6 +18,7 @@ export interface componentType { | 'Aenum' | 'multirowText' | 'image' + | 'custom' } export type ColumnConfigs = TextColumnConfig @@ -27,6 +29,7 @@ export type ColumnConfigs = TextColumnConfig | NumberColumnConfig | NumberRangeColumnConfig | ImageColumnConfig + | CustomColumnConfig export default { text: TextColumn, @@ -36,5 +39,6 @@ export default { Aenum: EnumColumn, number: NumberColumn, numberRange: NumberRangeColumn, - image: ImageColumn + image: ImageColumn, + custom: CustomColumn } diff --git a/src/index.tsx b/src/index.tsx index 93425aae869f7f3aba8b5663458c2e47fb173e2a..04146ee53184f7031c9d80dc70534f7885ef5d74 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -26,6 +26,8 @@ export { default as HiddenField } from './components/formFields/hidden' export { default as TabsField } from './components/formFields/tabs' export { default as MultipleTextField } from './components/formFields/multipleText' export { default as CustomField } from './components/formFields/custom' +export { default as CodeField } from './components/formFields/code' +export { default as DiffCodeField } from './components/formFields/diffCode' export { default as TextDisplay } from './components/formFields/text/display' export { default as LongTextDisplay } from './components/formFields/longtext/display' @@ -50,6 +52,7 @@ export { default as NumberRangeColumn } from './components/tableColumns/numberRa export { default as MultirowTextColumn } from './components/tableColumns/multirowText' export { default as DatetimeRangeColumn } from './components/tableColumns/datetimeRange' export { default as ImageColumn } from './components/tableColumns/image' +export { default as CustomColumn } from './components/tableColumns/custom' export { default as FetchStep } from './steps/fetch' export { default as DetailStep } from './steps/detail' diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index 97fb6519cf6c7fbf34b2065c0e187cbb72e1d9eb..1e294d64b0513954553297314f76221efc01fa66 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -98,7 +98,6 @@ export interface IDetailItem { interface DetailState { ready: boolean detailValue: { [field: string]: any } - detailData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] } /** @@ -123,8 +122,7 @@ export default class DetailStep extends Step { super(props) this.state = { ready: false, - detailValue: {}, - detailData: [] + detailValue: {} } } @@ -142,8 +140,6 @@ export default class DetailStep extends Step { onMount } = this.props - const detailData = cloneDeep(this.state.detailData) - if (this.props.config.defaultValue) { let detailDefault = ParamHelper(this.props.config.defaultValue, { data, step }) if (this.props.config.unstringify) { @@ -160,14 +156,12 @@ export default class DetailStep extends Step { const detailFieldConfig = detailFieldsConfig[detailFieldIndex] const value = getValue(detailDefault, detailFieldConfig.field) this.detailValue = setValue(this.detailValue, detailFieldConfig.field, value) - detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label } } } await this.setState({ ready: true, - detailValue: this.detailValue, - detailData: cloneDeep(detailData) + detailValue: this.detailValue }) // 表单初始化结束,展示表单界面。 @@ -180,8 +174,6 @@ export default class DetailStep extends Step { } this.detailFieldsMounted[detailFieldIndex] = true - const detailData = cloneDeep(this.state.detailData) - if (this.detailFields[detailFieldIndex]) { const detailField = this.detailFields[detailFieldIndex] if (detailField) { @@ -190,20 +182,12 @@ export default class DetailStep extends Step { const value = getValue(this.detailValue, detailFieldConfig.field) this.detailValue = setValue(this.detailValue, detailFieldConfig.field, value) - const validation = await detailField.validate(value) - if (validation === true) { - detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label } - } else { - // 首次进入错误提示; - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message, name: detailFieldConfig.label } - } await detailField.didMount() } } await this.setState({ - detailValue: this.detailValue, - detailData: cloneDeep(detailData) + detailValue: this.detailValue }) } @@ -224,23 +208,13 @@ export default class DetailStep extends Step { * @param value 目标值 */ handleChange = async (detailFieldIndex: number, value: any) => { - const detailData = cloneDeep(this.state.detailData) - const detailField = this.detailFields[detailFieldIndex] const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailField && detailFieldConfig) { this.detailValue = setValue(this.detailValue, detailFieldConfig.field, value) - const validation = await detailField.validate(value) - if (validation === true) { - detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label } - } else { - detailData[detailFieldIndex] = { status: 'error', message: validation[0].message, name: detailFieldConfig.label } - } - await this.setState({ - detailValue: this.detailValue, - detailData + detailValue: this.detailValue }) if (this.props.onChange) { this.props.onChange(this.detailValue) @@ -248,10 +222,10 @@ export default class DetailStep extends Step { } } - handleValueSet = async (detailFieldIndex: number, path: string, value: any, validation: true | DetailFieldError[]) => { + handleValueSet = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) set(this.detailValue, fullPath, value) this.setState({ @@ -260,22 +234,13 @@ export default class DetailStep extends Step { if (this.props.onChange) { this.props.onChange(this.detailValue) } - - if (validation === true) { - this.detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label, hidden: false } - } else { - this.detailData[detailFieldIndex] = { status: 'error', message: validation[0].message, name: detailFieldConfig.label, hidden: false } - } - await this.setState({ - detailData: this.detailData - }) } } - handleValueUnset = async (detailFieldIndex: number, path: string, validation: true | DetailFieldError[]) => { + handleValueUnset = async (detailFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) unset(this.detailValue, fullPath) this.setState({ @@ -284,23 +249,13 @@ export default class DetailStep extends Step { if (this.props.onChange) { this.props.onChange(this.detailValue) } - - if (validation === true) { - this.detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label, hidden: false } - } else { - this.detailData[detailFieldIndex] = { status: 'error', message: validation[0].message, name: detailFieldConfig.label, hidden: false } - } - - await this.setState({ - detailData: this.detailData - }) } } - handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, validation: true | DetailFieldError[]) => { + handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) const list = get(this.detailValue, fullPath, []) list.push(value) @@ -311,23 +266,13 @@ export default class DetailStep extends Step { if (this.props.onChange) { this.props.onChange(this.detailValue) } - - if (validation === true) { - this.detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label, hidden: false } - } else { - this.detailData[detailFieldIndex] = { status: 'error', message: validation[0].message, name: detailFieldConfig.label, hidden: false } - } - - await this.setState({ - detailData: this.detailData - }) } } - handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, validation: true | DetailFieldError[]) => { + handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { - const fullPath = detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) const list = get(this.detailValue, fullPath, []) list.splice(index, count) @@ -338,16 +283,6 @@ export default class DetailStep extends Step { if (this.props.onChange) { this.props.onChange(this.detailValue) } - - if (validation === true) { - this.detailData[detailFieldIndex] = { status: 'normal', name: detailFieldConfig.label, hidden: false } - } else { - this.detailData[detailFieldIndex] = { status: 'error', message: validation[0].message, name: detailFieldConfig.label, hidden: false } - } - - await this.setState({ - detailData: this.detailData - }) } } @@ -389,8 +324,7 @@ export default class DetailStep extends Step { const { ready, - detailValue, - detailData + detailValue } = this.state if (ready) { @@ -468,10 +402,10 @@ export default class DetailStep extends Step { config={detailFieldConfig} detail={this} onChange={async (value: any) => { await this.handleChange(detailFieldIndex, value) }} - onValueSet={async (path, value, validation) => await this.handleValueSet(detailFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => await this.handleValueUnset(detailFieldIndex, path, validation)} - onValueListAppend={async (path, value, validation) => await this.handleValueListAppend(detailFieldIndex, path, value, validation)} - onValueListSplice={async (path, index, count, validation) => await this.handleValueListSplice(detailFieldIndex, path, index, count, validation)} + onValueSet={async (path, value) => await this.handleValueSet(detailFieldIndex, path, value)} + onValueUnset={async (path) => await this.handleValueUnset(detailFieldIndex, path)} + onValueListAppend={async (path, value) => await this.handleValueListAppend(detailFieldIndex, path, value)} + onValueListSplice={async (path, index, count) => await this.handleValueListSplice(detailFieldIndex, path, index, count)} 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 3f1bd371a4ba70596afeb6743f0f862c83b924db..8d828f614d2806470e25b256b7edfffe848073d4 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -278,10 +278,10 @@ export default class FilterStep extends Step { } } - handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) set(this.formValue, fullPath, value) this.setState({ @@ -303,10 +303,10 @@ export default class FilterStep extends Step { } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[]) => { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) unset(this.formValue, fullPath) this.setState({ @@ -328,10 +328,10 @@ export default class FilterStep extends Step { } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const list = get(this.formValue, fullPath, []) list.push(value) @@ -355,10 +355,10 @@ export default class FilterStep extends Step { } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[]) => { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const list = get(this.formValue, fullPath, []) list.splice(index, count) @@ -381,10 +381,11 @@ export default class FilterStep extends Step { }) } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { + + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const list = listItemMove(get(this.formValue, fullPath, []), index, sortType) set(this.formValue, fullPath, list) @@ -500,11 +501,11 @@ export default class FilterStep extends Step { step={step} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} - onValueSet={async (path, value, validation) => await this.handleValueSet(formFieldIndex, path, value, validation)} - 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)} + onValueSet={async (path, value, validation, options) => await this.handleValueSet(formFieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => await this.handleValueUnset(formFieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => await this.handleValueListAppend(formFieldIndex, path, value, validation, options)} + onValueListSplice={async (path, index, count, validation, options) => await this.handleValueListSplice(formFieldIndex, path, index, count, validation, options)} + onValueListSort={async (path, index, sortType, validation, options) => await this.handleValueListSort(formFieldIndex, path, index, sortType, validation, options)} 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 27debc884e7aebb4c56d66c25caa4cde4987e33f..ebb1f023dd178a482b5d06c275e5ce9d1eafba3b 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -313,7 +313,7 @@ export default class FormStep extends Step { if (this.formFields[formFieldIndex]) { const formField = this.formFields[formFieldIndex] const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] - if (formField && formFieldConfig) { + if (formField && formFieldConfig && !formFieldConfig.disabled) { const value = await formField.get() const validation = await formField.validate(value) @@ -391,10 +391,10 @@ export default class FormStep extends Step { } } - handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) set(this.formValue, fullPath, value) this.setState({ @@ -418,10 +418,10 @@ export default class FormStep extends Step { } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[]) => { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) unset(this.formValue, fullPath) this.setState({ @@ -443,10 +443,10 @@ export default class FormStep extends Step { } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) let list = get(this.formValue, fullPath, []) if (!Array.isArray(list)) list = [] @@ -471,10 +471,10 @@ export default class FormStep extends Step { } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[]) => { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const list = get(this.formValue, fullPath, []) list.splice(index, count) @@ -498,10 +498,10 @@ export default class FormStep extends Step { } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) const list = listItemMove(get(this.formValue, fullPath, []), index, sortType) set(this.formValue, fullPath, list) @@ -735,11 +735,11 @@ export default class FormStep extends Step { step={step} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} - onValueSet={async (path, value, validation) => await this.handleValueSet(formFieldIndex, path, value, validation)} - 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)} + onValueSet={async (path, value, validation, options) => await this.handleValueSet(formFieldIndex, path, value, validation, options)} + onValueUnset={async (path, validation, options) => await this.handleValueUnset(formFieldIndex, path, validation, options)} + onValueListAppend={async (path, value, validation, options) => await this.handleValueListAppend(formFieldIndex, path, value, validation, options)} + onValueListSplice={async (path, index, count, validation, options) => await this.handleValueListSplice(formFieldIndex, path, index, count, validation, options)} + onValueListSort={async (path, index, sortType, validation, options) => await this.handleValueListSort(formFieldIndex, path, index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 9f314599a0d235754500619276413d5f62aeb561..793a438d89467a3cf5851317ddf9ce85b1561988 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -2,6 +2,7 @@ import React from 'react' import queryString from 'query-string' import { getParam, getParamText, getValue } from '../../util/value' import getALLComponents, { ColumnConfigs } from '../../components/tableColumns' +import Column from '../../components/tableColumns/common' import Step, { StepConfig, StepProps } from '../common' import { ParamConfig } from '../../interface' import ColumnStyleComponent from './common/columnStyle' @@ -266,7 +267,7 @@ interface TableState { */ export default class TableStep extends Step { CCMS = CCMS - getALLComponents = (type: any) => getALLComponents[type] + getALLComponents = (type: any): typeof Column => getALLComponents[type] interfaceHelper = new InterfaceHelper() /** * 页面权限获取状态