From 682e5eec556bbddb4419047246abcba17b19dfcb Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Fri, 10 Dec 2021 11:34:13 +0800 Subject: [PATCH 001/164] =?UTF-8?q?fixed:=E4=BF=AE=E5=A4=8D=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E8=AF=AD=E5=8F=A5=E5=85=A5=E5=8F=82?= =?UTF-8?q?=E4=B8=BAunderfind=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/condition.ts | 98 ++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/src/util/condition.ts b/src/util/condition.ts index 7d7542b..4cf13eb 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -23,12 +23,16 @@ export interface ConditionConfig { } export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { + // 条件语句模版 + let conditionTemplate = ''; + // 条件语句模版入参 + let statementParams = {}; + if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { if (condition.template) { - const statementTemplate = template(condition.template) - let statementParams = {} + conditionTemplate = condition.template; if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -41,46 +45,15 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } }) } - - try { - const statement = statementTemplate(statementParams) - try { - const result = eval(statement) - if (result) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => true') - } - return true - } else { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => false') - } - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.template + '` => `' + statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.template, statement) - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.template + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.template) - return false - } } else { // 用于兼容旧版本中的通配符 // V2新增逻辑段 - 开始 // const statementTemplate = template(condition.statement) // V2新增逻辑段 - 结束 // V2移除逻辑段 - 开始 - const statementPolyfill = condition.statement?.replace(/([^\$])\{/g, '$1${') - const statementTemplate = template(statementPolyfill) + conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || ''; // V2移除逻辑段 - 结束 - let statementParams = {} + if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -92,36 +65,39 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } }) } - + } + + return execConditionHandler(condition, conditionTemplate, statementParams); + } +} + +// 执行条件语句,返回结果 +const execConditionHandler = (condition: ConditionConfig | undefined, conditionTemplate: string, statementParams: object): boolean => { + try { + if (Object.values(statementParams).some((param) => param === undefined)) { + if (condition?.debug) { + console.info(`CCMS debug: condition ${conditionTemplate} => false`); + } + return false + } else { + const statement = template(conditionTemplate)(statementParams); + try { - const statement = statementTemplate(statementParams) - try { - const result = eval(statement) - if (result) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => true') - } - return true - } else { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => false') - } - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.statement + '` => `' + statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.statement, statement) - return false + const result = eval(statement); + if (condition?.debug) { + console.info(`CCMS debug: condition ${statement} => ${result}`); } + return result; } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.statement) + console.error('表单项展示条件语句执行错误。', conditionTemplate, statement); return false } } + } catch (e) { + if (condition?.debug) { + console.info('CCMS debug: condition - `' + conditionTemplate + '` => error'); + } + console.error('表单项展示条件语句执行错误。', conditionTemplate); + return false; } -} \ No newline at end of file +} \ No newline at end of file -- Gitee From c3cd84dd5d112d1f546dbfe25ea8ab0a38c52ce4 Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Mon, 20 Dec 2021 16:54:39 +0800 Subject: [PATCH 002/164] =?UTF-8?q?change:=E6=A0=BC=E5=BC=8F=E6=A0=87?= =?UTF-8?q?=E5=87=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/condition.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/util/condition.ts b/src/util/condition.ts index 4cf13eb..a8358a6 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,6 +1,6 @@ -import { set, cloneDeep, template } from "lodash" -import { ParamConfig } from "../interface"; -import ParamHelper from "./param"; +import { set, cloneDeep, template } from 'lodash' +import { ParamConfig } from '../interface' +import ParamHelper from './param' export interface ConditionConfig { /** @@ -22,17 +22,17 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { +export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { // 条件语句模版 - let conditionTemplate = ''; + let conditionTemplate = '' // 条件语句模版入参 - let statementParams = {}; - + let statementParams = {} + if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { if (condition.template) { - conditionTemplate = condition.template; + conditionTemplate = condition.template if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -51,7 +51,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, // const statementTemplate = template(condition.statement) // V2新增逻辑段 - 结束 // V2移除逻辑段 - 开始 - conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || ''; + conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || '' // V2移除逻辑段 - 结束 if (condition.params) { @@ -67,7 +67,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } } - return execConditionHandler(condition, conditionTemplate, statementParams); + return execConditionHandler(condition, conditionTemplate, statementParams) } } @@ -76,28 +76,28 @@ const execConditionHandler = (condition: ConditionConfig | undefined, conditionT try { if (Object.values(statementParams).some((param) => param === undefined)) { if (condition?.debug) { - console.info(`CCMS debug: condition ${conditionTemplate} => false`); + console.info(`CCMS debug: condition ${conditionTemplate} => false`) } return false } else { - const statement = template(conditionTemplate)(statementParams); + const statement = template(conditionTemplate)(statementParams) try { - const result = eval(statement); + const result = eval(statement) if (condition?.debug) { - console.info(`CCMS debug: condition ${statement} => ${result}`); + console.info(`CCMS debug: condition ${statement} => ${result}`) } - return result; + return result } catch (e) { - console.error('表单项展示条件语句执行错误。', conditionTemplate, statement); + console.error('表单项展示条件语句执行错误。', conditionTemplate, statement) return false } } } catch (e) { if (condition?.debug) { - console.info('CCMS debug: condition - `' + conditionTemplate + '` => error'); + console.info('CCMS debug: condition - `' + conditionTemplate + '` => error') } - console.error('表单项展示条件语句执行错误。', conditionTemplate); - return false; + console.error('表单项展示条件语句执行错误。', conditionTemplate) + return false } -} \ No newline at end of file +} -- Gitee From f75ac9b3649048ba73ff024f44d3f2b0539fbfbc Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 4 Jan 2022 17:18:21 +0800 Subject: [PATCH 003/164] =?UTF-8?q?immutable=E5=AE=9E=E7=8E=B0=E6=96=B9?= =?UTF-8?q?=E6=A1=88demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/components/formFields/any/index.tsx | 3 + src/components/formFields/common.tsx | 20 +- src/components/formFields/form/index.tsx | 9 +- src/components/formFields/group/index.tsx | 3 +- .../formFields/importSubform/index.tsx | 4 +- src/components/formFields/object/index.tsx | 3 +- src/components/formFields/tabs/index.tsx | 3 +- src/steps/filter/index.tsx | 3 +- src/steps/form/index.tsx | 382 +++++++++++++++++- src/util/value.ts | 13 + 11 files changed, 412 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 91472ce..ddc84db 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@types/react": "^16.9.46", "@types/react-router-dom": "^5.1.5", "axios": "^0.20.0", + "immutable": "^4.0.0", "lodash": "^4.17.21", "marked": "^1.2.5", "moment": "^2.29.0", diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index e93f34e..a4a051d 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -97,6 +97,7 @@ export default class AnyField extends Field : ( type === 'number' ? {}} @@ -115,6 +116,7 @@ export default class AnyField extends Field : {}} form={this.props.form} @@ -132,6 +134,7 @@ export default class AnyField extends Field ) })} diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 9b2f8f6..20302e2 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -5,7 +5,8 @@ import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' - +import { is, getIn, fromJS } from 'immutable' + /** * 表单项基类配置文件格式定义 * - field: 表单项字段名 @@ -92,6 +93,7 @@ export interface FieldProps { // 事件:修改值 - 列表 - 修改顺序 onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, + path: string, // 组件所在路径以字段拼接展示 loadDomain: (domain: string) => Promise } @@ -170,7 +172,21 @@ export class Field extends React.Component< 当前UI库未实现该表单类型 } - + + shouldComponentUpdate(nextProps= {} as any, nextState = {}) { + if (!is(nextProps.config, this.props.config) || !is(nextProps.value, this.props.value)) { + console.log('props-true'); + return true; + } + if (!is(this.state, nextState)) { + console.log('state-true'); + return true; + } + + console.log('no update' ); + + return false; + } render = () => { return ( 当前UI库未实现该表单类型 diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d95ddea..c32ab6c 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, listItemMove, setValue, getBoolean } from '../../../util/value' +import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' import { cloneDeep } from 'lodash' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' @@ -235,7 +235,8 @@ export default class FormField extends Field await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + path={getChainPath(formFieldConfig.field, this.props.path)} /> ) }) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 2f28e43..a80f77a 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { setValue, getValue, getBoolean } from '../../../util/value' +import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' @@ -344,6 +344,7 @@ export default class GroupField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + path={getChainPath(formFieldConfig.field, this.props.path)} /> ) } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index bfda6b1..2f18940 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { setValue, getValue, getBoolean } from '../../../util/value' +import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' @@ -8,6 +8,7 @@ import { cloneDeep } from 'lodash' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' +import { setIn } from 'immutable' /** * 子表单配置项 @@ -428,6 +429,7 @@ export default class ImportSubformField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + path={getChainPath(formFieldConfig.field, this.props.path)} /> ) } diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index b0de063..a68d174 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -3,7 +3,7 @@ import getALLComponents from '../' import React from 'react' import ConditionHelper from '../../../util/condition' import { cloneDeep } from 'lodash' -import { getValue, setValue, getBoolean } from '../../../util/value' +import { getValue, setValue, getBoolean, getChainPath } from '../../../util/value' import StatementHelper from '../../../util/statement' export interface ObjectFieldConfig extends FieldConfig { @@ -479,6 +479,7 @@ export default class ObjectField extends Field this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => this.props.loadDomain(domain)} + path={getChainPath(formFieldConfig.field, this.props.path)} /> ) }) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index a32b115..72e98d6 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -3,7 +3,7 @@ import getALLComponents from '../' import React from 'react' import ConditionHelper from '../../../util/condition' import { cloneDeep } from 'lodash' -import { getValue, setValue, getBoolean } from '../../../util/value' +import { getValue, setValue, getBoolean, getChainPath } from '../../../util/value' import StatementHelper from '../../../util/statement' export type TabsFieldConfig = TabsFieldConfig_Same | TabsFieldConfig_Diff @@ -439,6 +439,7 @@ export default class TabsField extends Field this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + path={getChainPath(formFieldConfig.field, this.props.path)} /> ) })} diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 3f1bd37..b280205 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, listItemMove } from '../../util/value' +import { getValue, setValue, listItemMove, getChainPath } from '../../util/value' /** * 表单步骤配置文件格式定义 @@ -507,6 +507,7 @@ export default class FilterStep extends Step { 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)} + path={getChainPath(formFieldIndex, formFieldConfig.field)} /> ) } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 5c641fa..3de7aef 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -2,13 +2,15 @@ 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, listItemMove, getBoolean } from '../../util/value' +import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' -import { cloneDeep, get, set, unset } from 'lodash' +import { cloneDeep, get, set, unset, update } from 'lodash' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' +import fp from 'lodash/fp' +import { Map, List, getIn, setIn, updateIn, fromJS } from 'immutable' /** * 表单步骤配置文件格式定义 @@ -170,10 +172,318 @@ export default class FormStep extends Step { formFields: Array | null> = [] formFieldsMounted: Array = [] + // formValue: { [field: string]: any } = Map({}) formValue: { [field: string]: any } = {} formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] = [] canSubmit: boolean = false submitData: object = {} + record_:object = { + "pageFormData": { + "dataAssociation": { + "sourceMaterial": { + "fields": [ + { + "label": "上提12", + "field": "liftUp", + "type": "switch", + "extra": { + "statement": "", + "params": [] + }, + "valueTrue": true, + "valueFalse": false, + "defaultValue": { + "source": "static", + "value": false + }, + "required": true, + "condition": { + "params": [] + } + }, + { + "label": "上提楼层尾icon-短文本链接", + "field": "upTailIcon", + "type": "text", + "extra": { + "params": [] + }, + "placeholder": "请输入尾icon地址", + "regExp": {}, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [ + { + "field": "upward", + "data": { + "source": "record", + "field": "material.liftUp" + } + } + ], + "template": "${upward} === true" + } + }, + { + "label": "尾icon高度-数值", + "field": "upTailIconHight", + "type": "number", + "extra": { + "params": [] + }, + "precision": 0, + "step": 1, + "max": 120, + "regExp": {}, + "defaultValue": { + "source": "static", + "value": 0 + }, + "required": true, + "condition": { + "params": [ + { + "field": "upward", + "data": { + "source": "record", + "field": "material.liftUp" + } + } + ], + "template": "${upward} === true" + } + }, + { + "label": "上提楼层头icon-短文本", + "field": "upHeadIcon", + "type": "text", + "extra": { + "params": [] + }, + "placeholder": "请输入头icon地址", + "cjkLength": 2, + "regExp": {}, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [ + { + "field": "upward", + "data": { + "source": "record", + "field": "material.liftUp" + } + } + ], + "template": "${upward} === true" + } + }, + { + "label": "业务标题-短文本", + "field": "title", + "type": "text", + "extra": { + "params": [] + }, + "placeholder": "请输入展示文案", + "maxLength": 12, + "minLength": null, + "cjkLength": 2, + "regExp": { + "expression": "", + "message": "业务标题重复" + }, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [] + } + }, + { + "label": "业务标题色值", + "field": "titleColor", + "type": "color", + "extra": { + "params": [] + }, + "defaultValue": { + "source": "static", + "value": "#ffffff" + }, + "required": true, + "condition": { + "params": [ + { + "field": "upward", + "data": { + "source": "record", + "field": "material.liftUp" + } + } + ], + "template": "${upward} === true" + } + }, + { + "label": "业务副标题-文本1", + "field": "subTitle", + "type": "text", + "extra": { + "params": [] + }, + "placeholder": "请输入展示文案", + "maxLength": 16, + "minLength": null, + "cjkLength": 2, + "regExp": { + "expression": "", + "message": "文案超过8个字" + }, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [] + } + }, + { + "label": "业务副标题色值", + "field": "subtitleColor", + "type": "color", + "extra": { + "params": [] + }, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [ + { + "field": "upward", + "data": { + "source": "record", + "field": "material.liftUp" + } + } + ], + "template": "${upward} === true " + } + }, + { + "label": "icon图片", + "field": "icon", + "type": "upload", + "extra": { + "statement": "icon尺寸33x44,支持png格式,50K以内", + "params": [] + }, + "interface": { + "domain": "jdg", + "url": "/upload/imageUpload", + "urlParams": [], + "method": "POST", + "contentType": "json", + "withCredentials": true, + "params": [], + "data": [], + "condition": { + "enable": true, + "success": {}, + "fail": {} + }, + "response": [ + { + "path": "data" + } + ], + "cache": {} + }, + "requireField": "file", + "mode": "image", + "sizeCheck": { + "maxSize": 50, + "sizeUnit": "K", + "height": null, + "width": null + }, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [], + "template": "" + } + }, + { + "label": "背景颜色-取色器", + "field": "bgColor", + "type": "color", + "extra": { + "params": [] + }, + "defaultValue": { + "source": "static", + "value": "#ffffff" + }, + "required": true, + "condition": { + "params": [ + { + "field": "upward", + "data": { + "source": "record", + "field": "material.liftUp" + } + } + ], + "template": "${upward} === true" + } + }, + { + "label": "跳转链接", + "field": "jumpUrl", + "type": "text", + "extra": { + "statement": "1、跳转地址必须经西格玛审核; 2、跳转地址需在APP白名单中,不在可找商详技术处理", + "params": [] + }, + "placeholder": "请输入跳转链接", + "regExp": { + "expression": "(ht|f)tp(s?)\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\'\\/\\\\\\+&%$#_]*)?", + "message": "请输入正确格式" + }, + "defaultValue": { + "source": "static", + "value": "" + }, + "required": true, + "condition": { + "params": [], + "template": "" + } + } + ] + } + } + } +} +data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sourceMaterial.fields"],"defaultValue":{"source":"step","field":"data","step":1,"unstringify":["data.pageFormData.dataAssociation.sourceMaterial.field"]},"businessSuffix":"","unstringify":["pageFormData.dataAssociation.sourceMaterial.fields"],"version":"1.0.0","subversion":"0","fields":[{"canInsert":true,"canSort":true,"canRemove":true,"label":"字段设置","primaryField":"label","fields":[{"label":"字段描述","field":"label","type":"text"},{"label":"字段名","field":"field","type":"text"},{"field":"","label":"","type":"import_subform","interface":{"url":"https://storage.jd.com/swm-plus/prod-floor-fields/config/form/index.json","urlParams":[],"method":"GET"},"defaultValue":{"source":"record","field":""}}],"field":"pageFormData.dataAssociation.sourceMaterial.fields","type":"form","canCollapse":true}],"type":"form","applicationName":"example","actions":[{"type":"ccms","mode":"primary","label":"保存并发布","callback":{"type":"cancel"},"handle":{"type":"ccms","page":822,"mode":"popup","label":"","params":[{"field":"systemId","data":{"source":"record","value":"create","field":"systemId"}},{"field":"type","data":{"source":"record","field":"type"}},{"field":"appName","data":{"source":"record","field":"appName"}},{"field":"pageFormData","data":{"source":"record","field":"pageFormData"}},{"data":{"source":"static","value":1},"field":"saveAndPublish"},{"field":"templateUseType","data":{"source":"step","value":1,"field":"data.jdgBusiFloor.templateUseType","step":1}},{"field":"id","data":{"source":"record","field":"jdgBusiFloor.id"}}]},"condition":{"debug":true}},{"type":"submit","mode":"primary","label":"保存为草稿","callback":{"type":"none"},"handle":{"type":"ccms"},"condition":{"params":[]}}]},"fields":[{"canInsert":true,"canSort":true,"defaultValue":{"source":"static","value":""},"canRemove":true,"label":"字段设置","primaryField":"label","fields":[{"label":"字段描述","field":"label","type":"text"},{"label":"字段名","field":"field","type":"text"},{"field":"","label":"","type":"import_subform","interface":{"url":"https://storage.jd.com/swm-plus/prod-floor-fields/config/form/index.json","urlParams":[],"method":"GET"},"defaultValue":{"source":"record","field":""}}],"field":"pageFormData.dataAssociation.sourceMaterial.fields","type":"form","canCollapse":true}],"stringify":["pageFormData.dataAssociation.sourceMaterial.fields"],"actions":[{"type":"ccms","mode":"primary","label":"保存并发布","callback":{"type":"cancel"},"handle":{"type":"ccms","page":822,"mode":"popup","label":"","params":[{"field":"systemId","data":{"source":"record","value":"create","field":"systemId"}},{"field":"type","data":{"source":"record","field":"type"}},{"field":"appName","data":{"source":"record","field":"appName"}},{"field":"pageFormData","data":{"source":"record","field":"pageFormData"}},{"data":{"source":"static","value":1},"field":"saveAndPublish"},{"field":"templateUseType","data":{"source":"step","value":1,"field":"data.jdgBusiFloor.templateUseType","step":1}},{"field":"id","data":{"source":"record","field":"jdgBusiFloor.id"}}]},"condition":{"debug":true}},{"type":"submit","mode":"primary","label":"保存为草稿","callback":{"type":"none"},"handle":{"type":"ccms"},"condition":{"params":[]}}],"applicationName":"example","businessSuffix":"","version":"1.0.0","subversion":"0"}] /** * 初始化表单的值 @@ -183,7 +493,8 @@ export default class FormStep extends Step { super(props) this.state = { ready: false, - formValue: {}, + // formValue: {}, + formValue: Map({}), formData: [] } } @@ -203,6 +514,7 @@ export default class FormStep extends Step { } = this.props this.formValue = {} + // this.formValue = Map({}) this.formData = [] if (this.props.config.defaultValue) { @@ -222,7 +534,10 @@ export default class FormStep extends Step { for (const formFieldIndex in formFieldsConfig) { const formFieldConfig = formFieldsConfig[formFieldIndex] const value = getValue(formDefault, formFieldConfig.field) - this.formValue = setValue(this.formValue, formFieldConfig.field, value) + + const fieldPathArr = formFieldConfig.field.split('.') + // this.formValue = setValue(this.formValue, formFieldConfig.field, value) + this.formValue = setIn(this.formValue, fieldPathArr, value) this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } } } @@ -247,14 +562,16 @@ export default class FormStep extends Step { const formField = this.formFields[formFieldIndex] if (formField) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] - - let value = getValue(this.formValue, formFieldConfig.field) + const fieldPathArr = formFieldConfig.field.split('.') + // let value = getValue(this.formValue, formFieldConfig.field) + let value = getIn(this.formValue, fieldPathArr) if ((formFieldConfig.defaultValue) && value === undefined) { value = await formField.reset() } value = await formField.set(value) - this.formValue = setValue(this.formValue, formFieldConfig.field, value) - + // this.formValue = setValue(this.formValue, formFieldConfig.field, value) + this.formValue = setIn(this.formValue, fieldPathArr, value) + if (value !== undefined) { const validation = await formField.validate(value) if (validation === true) { @@ -378,25 +695,39 @@ export default class FormStep extends Step { if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - set(this.formValue, fullPath, value) - this.setState({ - formValue: this.formValue + const fullPathArr = fullPath.split('.') + + + // set(this.formValue, fullPath, value) + // this.formValue = setIn(this.formValue, fullPathArr, value) + // this.setState({ + // formValue: this.formValue + // }) + this.setState(({formValue}) => { + // return {formValue: set(formValue, fullPath, value)} + // return {formValue: fp.update(fullPath, ()=> value, formValue)} + // return {formValue: setIn(this.formValue, fullPathArr, value)} + return {formValue: updateIn(formValue, fullPathArr, () => value)} }) + var temp = [fullPathArr[0]] + this.formValue = updateIn(this.formValue, fullPathArr, () => value) + // this.setState(({formValue}) => ({formValue: this.formValue})) + console.log('set--', this.formValue, fullPath, fullPathArr, value); 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 } - } + // if (validation === true) { + // this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + // } else { + // this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + // } console.log('form set data', this.formData) - await this.setState({ - formData: cloneDeep(this.formData) - }) + // await this.setState({ + // formData: cloneDeep(this.formData) + // }) } } @@ -669,7 +1000,8 @@ export default class FormStep extends Step { if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { status = 'normal' } - + const fieldPathArr = formFieldConfig.field.split('.') + const renderData = { key: formFieldIndex, label: formFieldConfig.label, @@ -690,10 +1022,14 @@ export default class FormStep extends Step { } }} formLayout={layout} - value={formFieldConfig.field !== undefined ? getValue(formValue, formFieldConfig.field) : undefined} + // value={formFieldConfig.field !== undefined ? getValue(formValue, formFieldConfig.field) : undefined} + value={formFieldConfig.field !== undefined ? getIn(formValue, fieldPathArr) : undefined} + // record={formValue.toJS()} record={formValue} + // record={this.record_} form={this} - data={cloneDeep(data)} + // data={cloneDeep(data)} + data={this.data_} step={step} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} @@ -704,6 +1040,7 @@ export default class FormStep extends Step { 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)} + path={getChainPath(formFieldIndex, formFieldConfig.field)} /> ) } @@ -722,3 +1059,4 @@ export default class FormStep extends Step { } } } + diff --git a/src/util/value.ts b/src/util/value.ts index 35a8463..b9d9e4c 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -121,3 +121,16 @@ export const listItemMove = (list: any[], currentIndex: number, sortType: 'up' | } return list } + +/** + * 组件所在的字符串链式路径 + * @param currentPath + * @param sourcePath + * @returns + */ +export const getChainPath = (currentPath: string | number = '', sourcePath: string | number = '') => { + if (!currentPath && currentPath !== 0) {currentPath = ''} else {currentPath = currentPath.toString()} + if (!sourcePath && sourcePath !== 0) {sourcePath = ''} else {sourcePath = sourcePath.toString()} + const finalPath = (sourcePath +'.'+ currentPath).replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') + return finalPath +} \ No newline at end of file -- Gitee From da62fecb53c32bf382373a8a869efd5ff2bf0072 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 7 Jan 2022 16:21:26 +0800 Subject: [PATCH 004/164] feat: redux demo --- package.json | 5 +- src/HOC/stepComponentHOC.jsx | 29 +++++++ src/components/formFields/common.tsx | 2 +- .../formFields/importSubform/index.tsx | 1 - src/main.tsx | 27 ++++--- src/steps/common.tsx | 34 ++++++-- src/steps/form/index.tsx | 80 ++++++++++++------- src/steps/table/index.tsx | 6 +- src/store/common.tsx | 7 ++ src/store/index.tsx | 1 + src/store/reducers/data.tsx | 43 ++++++++++ src/store/reducers/formValue.tsx | 38 +++++++++ src/store/reducers/index.tsx | 2 + src/store/store.tsx | 52 ++++++++++++ 14 files changed, 273 insertions(+), 54 deletions(-) create mode 100644 src/HOC/stepComponentHOC.jsx create mode 100644 src/store/common.tsx create mode 100644 src/store/index.tsx create mode 100644 src/store/reducers/data.tsx create mode 100644 src/store/reducers/formValue.tsx create mode 100644 src/store/reducers/index.tsx create mode 100644 src/store/store.tsx diff --git a/package.json b/package.json index ddc84db..4a2484e 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@types/react": "^16.9.46", "@types/react-router-dom": "^5.1.5", "axios": "^0.20.0", + "immer": "^9.0.7", "immutable": "^4.0.0", "lodash": "^4.17.21", "marked": "^1.2.5", @@ -80,7 +81,9 @@ "qiankun": "^2.5.1", "query-string": "^6.13.8", "rc-table": "^7.9.10", - "react-loadable": "^5.5.0" + "react-loadable": "^5.5.0", + "react-redux": "^7.2.6", + "redux": "^4.1.2" }, "peerDependencies": { "react": "^16.13.1", diff --git a/src/HOC/stepComponentHOC.jsx b/src/HOC/stepComponentHOC.jsx new file mode 100644 index 0000000..3f46d7d --- /dev/null +++ b/src/HOC/stepComponentHOC.jsx @@ -0,0 +1,29 @@ +import React from 'react' +import {connect} from 'react-redux' +import { compose } from 'redux' +import { InterfaceState, PreloadedState } from '../store/store' +import { setFormValue } from '../store/reducers/formValue' + +const StepComponentHOC = function (WrappedComponent) { + class StepContainer extends React.Component { + render () { + console.log('props==', this.props); + return ( + WrappedComponent + ) + } + } + const mapStateToProps = (state) => { + return { + data: state.data.data, + formValue: state.formValue.formValue + } + } + const mapDispatchToProps = (dispatch) => { + return { + handleFormValue: () => dispatch(setFormValue(payload)) + } + } + return connect(mapStateToProps, mapDispatchToProps)(StepContainer) +} +export { StepComponentHOC as default } \ No newline at end of file diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 20302e2..f5ecdac 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -5,7 +5,7 @@ import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' -import { is, getIn, fromJS } from 'immutable' +import { is } from 'immutable' /** * 表单项基类配置文件格式定义 diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 2f18940..cdf3171 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -8,7 +8,6 @@ import { cloneDeep } from 'lodash' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' -import { setIn } from 'immutable' /** * 子表单配置项 diff --git a/src/main.tsx b/src/main.tsx index d580507..0ab033d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,9 +1,12 @@ -import React from 'react' +import React, { forwardRef } from 'react' import marked from 'marked' +import { Provider, connect } from 'react-redux' import Step, { StepProps } from './steps/common' import StepComponents, { StepConfigs } from './steps' import { RichStringConfig } from './interface' - +import { store } from './store' +import { compose } from 'redux' +import { InterfaceState, PreloadedState } from './store/store' /** * 页面配置文件格式定义 * - basic: 页面基本配置 @@ -38,7 +41,7 @@ export interface ICCMS { * - config: 页面配置文件 * - sourceData: 传入数据 */ -export interface CCMSProps { +export interface CCMSProps { config: CCMSConfig sourceData: any baseRoute: string @@ -50,6 +53,7 @@ export interface CCMSProps { handlePageRedirect?: (path: string) => void callback: (success: boolean) => void onMount?: () => void + handleFormValue?: (payload: object) => object } /** @@ -58,7 +62,7 @@ export interface CCMSProps { * - viewStep: 界面当前所在步骤 * - data: 各步骤数据 */ -interface CCMSState { +export interface CCMSState { realStep: number viewStep: number[] data: any[] @@ -67,7 +71,7 @@ interface CCMSState { /** * 页面组件 */ -export default class CCMS extends React.Component { +export default class CCMS1 extends React.Component { getStepComponent = (key: string) => StepComponents[key] /** @@ -236,7 +240,7 @@ export default class CCMS extends React.Component { loadDomain, handlePageRedirect } = this.props - + const handleFormValue = this.props.handleFormValue ? this.props.handleFormValue : (payload: object) => ({}) const { realStep, viewStep, @@ -256,7 +260,7 @@ export default class CCMS extends React.Component { // 调用UI渲染方法 return ( - + {this.renderComponent({ title, description, @@ -276,12 +280,13 @@ export default class CCMS extends React.Component { loadPageFrameURL, loadPageConfig, loadDomain, - handlePageRedirect + handlePageRedirect, + handleFormValue } - + const StepComponent = this.getStepComponent(currentStep.type) const children = ( - StepComponent ? : 您当前使用的UI版本没有实现{currentStep.type}步骤组件。 + StepComponent ? : 您当前使用的UI版本没有实现{currentStep.type}步骤组件。 ) return (
{children}
@@ -291,7 +296,7 @@ export default class CCMS extends React.Component { } })) })} -
+ ) } } diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 88da0fd..863e59f 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -1,6 +1,9 @@ import React from 'react' import { CCMSConfig } from '../main' - +import {connect} from 'react-redux' +import { compose } from 'redux' +import { InterfaceState, PreloadedState } from '../store/store' +import { setFormValue } from '../store/reducers/formValue' /** * 页面流转步骤基类配置定义 * - type: 类型,对应各子类 @@ -33,16 +36,17 @@ export interface StepProps { baseRoute: string loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string) => void + handleFormValue?: (payload: object) => object } /** * 页面步骤基类 */ -export default class Step extends React.Component, S> { - static defaultProps = { - config: { - } - }; + export default class Step extends React.Component, S> { + // static defaultProps = { // 暂时注释 + // config: { + // } + // }; stepPush = () => { this.props.onMount() @@ -60,3 +64,21 @@ export default class Step extends React.Component< return <> } } + +// const mapStateToProps = (state: PreloadedState) => { +// return { +// data: state.data.data, +// formValue: state.formValue.formValue +// } +// // return { +// // data: state.ccmsStore.data, +// // formValue: state.ccmsStore.formValue +// // } +// } +// const mapDispatchToProps = (dispatch: Function) => { +// return { +// handleFormValue: (payload: any):object => dispatch(setFormValue(payload)) +// } +// } +// connect(mapStateToProps, mapDispatchToProps)(Step) + diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 3de7aef..e89edb3 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -10,8 +10,11 @@ import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' import fp from 'lodash/fp' -import { Map, List, getIn, setIn, updateIn, fromJS } from 'immutable' - +import produce from 'immer' +import { connect } from 'react-redux' +import { InterfaceState, PreloadedState } from '../../store/store' +import { setFormValue } from '../../store/reducers/formValue' +import StepComponentHOC from '../../HOC/stepComponentHOC' /** * 表单步骤配置文件格式定义 * - layout: 表单布局类型 @@ -154,7 +157,7 @@ export interface IFormItem { * 表单步骤组件 - 状态 * - formData: 表单的值 */ -interface FormState { +export interface FormState { ready: boolean formValue: { [field: string]: any } formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] @@ -163,7 +166,7 @@ interface FormState { /** * 表单步骤组件 */ -export default class FormStep extends Step { + const FormStepTemp = class FormStep extends Step { // ts对class的声明文件报错,临时解决 // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Field => getALLComponents[type] OperationHelper = OperationHelper @@ -172,7 +175,6 @@ export default class FormStep extends Step { formFields: Array | null> = [] formFieldsMounted: Array = [] - // formValue: { [field: string]: any } = Map({}) formValue: { [field: string]: any } = {} formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] = [] canSubmit: boolean = false @@ -493,8 +495,7 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour super(props) this.state = { ready: false, - // formValue: {}, - formValue: Map({}), + formValue: {}, formData: [] } } @@ -514,7 +515,6 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour } = this.props this.formValue = {} - // this.formValue = Map({}) this.formData = [] if (this.props.config.defaultValue) { @@ -534,10 +534,13 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour for (const formFieldIndex in formFieldsConfig) { const formFieldConfig = formFieldsConfig[formFieldIndex] const value = getValue(formDefault, formFieldConfig.field) - - const fieldPathArr = formFieldConfig.field.split('.') + // this.formValue = setValue(this.formValue, formFieldConfig.field, value) - this.formValue = setIn(this.formValue, fieldPathArr, value) + console.log('this.formValue', this.formValue, formFieldConfig.field); + + this.formValue = produce(this.formValue, draft => { + setValue(draft, formFieldConfig.field, value) + }) this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } } } @@ -563,14 +566,16 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour if (formField) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const fieldPathArr = formFieldConfig.field.split('.') - // let value = getValue(this.formValue, formFieldConfig.field) - let value = getIn(this.formValue, fieldPathArr) + let value = getValue(this.formValue, formFieldConfig.field) + // let value = immuHelperX.$apply(this.formValue, formFieldConfig.field, (val:any)=>val) if ((formFieldConfig.defaultValue) && value === undefined) { value = await formField.reset() } value = await formField.set(value) // this.formValue = setValue(this.formValue, formFieldConfig.field, value) - this.formValue = setIn(this.formValue, fieldPathArr, value) + this.formValue = produce(this.formValue, draft => { + setValue(draft, formFieldConfig.field, value) + }) if (value !== undefined) { const validation = await formField.validate(value) @@ -697,22 +702,18 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour const fullPathArr = fullPath.split('.') + if(this.props.handleFormValue) { + this.props.handleFormValue({path: fullPath, value}) + } // set(this.formValue, fullPath, value) - // this.formValue = setIn(this.formValue, fullPathArr, value) - // this.setState({ - // formValue: this.formValue - // }) - this.setState(({formValue}) => { - // return {formValue: set(formValue, fullPath, value)} - // return {formValue: fp.update(fullPath, ()=> value, formValue)} - // return {formValue: setIn(this.formValue, fullPathArr, value)} - return {formValue: updateIn(formValue, fullPathArr, () => value)} + this.formValue = produce(this.formValue, draft => { + setValue(draft, fullPath, value) }) - var temp = [fullPathArr[0]] - this.formValue = updateIn(this.formValue, fullPathArr, () => value) - // this.setState(({formValue}) => ({formValue: this.formValue})) console.log('set--', this.formValue, fullPath, fullPathArr, value); + this.setState({ + formValue: this.formValue + }) if (this.props.onChange) { this.props.onChange(this.formValue) } @@ -725,9 +726,9 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour console.log('form set data', this.formData) - // await this.setState({ - // formData: cloneDeep(this.formData) - // }) + await this.setState({ + formData: cloneDeep(this.formData) + }) } } @@ -1022,8 +1023,8 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour } }} formLayout={layout} - // value={formFieldConfig.field !== undefined ? getValue(formValue, formFieldConfig.field) : undefined} - value={formFieldConfig.field !== undefined ? getIn(formValue, fieldPathArr) : undefined} + value={formFieldConfig.field !== undefined ? getValue(formValue, formFieldConfig.field) : undefined} + // value={formFieldConfig.field !== undefined ? immuHelperX.$apply(formValue, formFieldConfig.field, (v:any) => v) : undefined} // record={formValue.toJS()} record={formValue} // record={this.record_} @@ -1059,4 +1060,21 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour } } } +const mapStateToProps = (state: PreloadedState) => { + return { + data: state.data.data, + formValue: state.formValue.formValue + } +} +const mapDispatchToProps = (dispatch: Function) => { + return { + handleFormValue: (payload: any):object => dispatch(setFormValue(payload)) + } +} +const mergeProps = (stateProps:any, dispatchProps: any, ownProps: any) => Object.assign( + {}, stateProps, dispatchProps, ownProps +) + +const FormStep_ = connect(mapStateToProps, mapDispatchToProps, mergeProps)(FormStepTemp) +export default FormStep_ diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 72111dc..18f421e 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -5,7 +5,7 @@ import getALLComponents, { ColumnConfigs } from '../../components/tableColumns' import Step, { StepConfig, StepProps } from '../common' import { ParamConfig } from '../../interface' import ColumnStyleComponent from './common/columnStyle' -import CCMS, { CCMSConfig } from '../../main' +import CCMS_123, { CCMSConfig } from '../../main' import { cloneDeep, get, set } from 'lodash' import InterfaceHelper, { InterfaceConfig } from '../../util/interface' import ConditionHelper, { ConditionConfig } from '../../util/condition' @@ -217,7 +217,7 @@ interface TableState { * 表格步骤组件 */ export default class TableStep extends Step { - CCMS = CCMS + CCMS_ = CCMS_123 getALLComponents = (type: any) => getALLComponents[type] interfaceHelper = new InterfaceHelper() /** @@ -660,7 +660,7 @@ export default class TableStep extends Step { }) } - const CCMS = this.CCMS + const CCMS = this.CCMS_ return ( diff --git a/src/store/common.tsx b/src/store/common.tsx new file mode 100644 index 0000000..c7e81da --- /dev/null +++ b/src/store/common.tsx @@ -0,0 +1,7 @@ +export declare interface actionInterface { + type: string + payload: { + path: string + value: any + } +} \ No newline at end of file diff --git a/src/store/index.tsx b/src/store/index.tsx new file mode 100644 index 0000000..9a3b2c8 --- /dev/null +++ b/src/store/index.tsx @@ -0,0 +1 @@ +export { default as store } from './store' \ No newline at end of file diff --git a/src/store/reducers/data.tsx b/src/store/reducers/data.tsx new file mode 100644 index 0000000..d278ade --- /dev/null +++ b/src/store/reducers/data.tsx @@ -0,0 +1,43 @@ +const SET_FULL_SCREEN = 'ccms/mode/SET_FULL_SCREEN'; +const SET_PLAYER = 'ccms/mode/SET_PLAYER'; + +const initialState = { + data: [] +}; + +const reducer = function (state: object, action: object) { + if (typeof state === 'undefined') state = initialState; + // switch (action.type) { + // case SET_FULL_SCREEN: + // return Object.assign({}, state, { + // isFullScreen: action.isFullScreen + // }); + // case SET_PLAYER: + // return Object.assign({}, state, { + // isPlayerOnly: action.isPlayerOnly, + // hasEverEnteredEditor: state.hasEverEnteredEditor || !action.isPlayerOnly + // }); + // default: + return state; + // } +}; + +// const setFullScreen = function (isFullScreen) { +// return { +// type: SET_FULL_SCREEN, +// isFullScreen: isFullScreen +// }; +// }; +// const setPlayer = function (isPlayerOnly) { +// return { +// type: SET_PLAYER, +// isPlayerOnly: isPlayerOnly +// }; +// }; + +export { + reducer as default, + initialState as dataInitialState, + // setFullScreen, + // setPlayer +}; diff --git a/src/store/reducers/formValue.tsx b/src/store/reducers/formValue.tsx new file mode 100644 index 0000000..ace1170 --- /dev/null +++ b/src/store/reducers/formValue.tsx @@ -0,0 +1,38 @@ +import produce from "immer"; +import { set } from 'lodash' +import { actionInterface } from '../common' + +const SET_FORM_VALUE = 'ccms/formValue/SET_FORM_VALUE'; + +const initialState = { + formValue: {}, +}; + + +const reducer = async function (state: object, action: actionInterface) { + const { payload } = action + if (typeof state === 'undefined' || !payload) state = initialState; + switch (payload && payload.value) { + case SET_FORM_VALUE: + set(state, payload.path, payload.value) + return Object.assign({}, state) + // const a = await produce(state, (draft) => { + + // }) + default: + return state; + } +}; + +const setFormValue = function (payload:{ path: string, value: any }):actionInterface { + return { + type: SET_FORM_VALUE, + payload + }; +}; + +export { + reducer as default, + initialState as formValueInitialState, + setFormValue +}; diff --git a/src/store/reducers/index.tsx b/src/store/reducers/index.tsx new file mode 100644 index 0000000..9ffdc7b --- /dev/null +++ b/src/store/reducers/index.tsx @@ -0,0 +1,2 @@ +export { default as dataReducer, dataInitialState} from './data' +export { default as formValueReducer, formValueInitialState } from './formValue' \ No newline at end of file diff --git a/src/store/store.tsx b/src/store/store.tsx new file mode 100644 index 0000000..8a0ec21 --- /dev/null +++ b/src/store/store.tsx @@ -0,0 +1,52 @@ +import { createStore, combineReducers, compose } from 'redux' +import { dataReducer, dataInitialState, formValueReducer, formValueInitialState } from './reducers' + +export interface InterfaceState { + data: object, + formValue: object +} + + +declare const $CombinedState: unique symbol +interface EmptyObject { + readonly [$CombinedState]?: undefined +} +type CombinedState = EmptyObject & S + +/** + * Recursively makes combined state objects partial. Only combined state _root + * objects_ (i.e. the generated higher level object with keys mapping to + * individual reducers) are partial. + */ +export type PreloadedState = Required extends EmptyObject + ? S extends CombinedState + ? { + [K in keyof S1]?: S1[K] extends object ? PreloadedState : S1[K] + } + : S + : { + [K in keyof S]: S[K] extends string | number | boolean | symbol + ? S[K] + : PreloadedState + } + + + + +const initialState: PreloadedState = { + // ccmsStore: { + // ...dataInitialState, + // ...formValueInitialState + // } + data: dataInitialState, + formValue: formValueInitialState +} +const reducers = { + data: dataReducer, + formValue: formValueReducer +} +// @ts-ignore +const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; +const reducers_ = combineReducers(reducers) +let store = createStore(reducers_, initialState, composeEnhancers()) +export default store \ No newline at end of file -- Gitee From 50d22c1efb8805a0b3bfabefe88f28117391c9db Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 7 Jan 2022 20:00:16 +0800 Subject: [PATCH 005/164] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8redux=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HOC/stepComponentHOC.jsx | 29 ------------------ src/main.tsx | 8 ++--- src/steps/common.tsx | 23 +------------- src/steps/form/index.tsx | 31 +++---------------- src/store/common.tsx | 7 ----- src/store/index.tsx | 1 - src/store/reducers/data.tsx | 43 -------------------------- src/store/reducers/formValue.tsx | 38 ----------------------- src/store/reducers/index.tsx | 2 -- src/store/store.tsx | 52 -------------------------------- 10 files changed, 8 insertions(+), 226 deletions(-) delete mode 100644 src/HOC/stepComponentHOC.jsx delete mode 100644 src/store/common.tsx delete mode 100644 src/store/index.tsx delete mode 100644 src/store/reducers/data.tsx delete mode 100644 src/store/reducers/formValue.tsx delete mode 100644 src/store/reducers/index.tsx delete mode 100644 src/store/store.tsx diff --git a/src/HOC/stepComponentHOC.jsx b/src/HOC/stepComponentHOC.jsx deleted file mode 100644 index 3f46d7d..0000000 --- a/src/HOC/stepComponentHOC.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react' -import {connect} from 'react-redux' -import { compose } from 'redux' -import { InterfaceState, PreloadedState } from '../store/store' -import { setFormValue } from '../store/reducers/formValue' - -const StepComponentHOC = function (WrappedComponent) { - class StepContainer extends React.Component { - render () { - console.log('props==', this.props); - return ( - WrappedComponent - ) - } - } - const mapStateToProps = (state) => { - return { - data: state.data.data, - formValue: state.formValue.formValue - } - } - const mapDispatchToProps = (dispatch) => { - return { - handleFormValue: () => dispatch(setFormValue(payload)) - } - } - return connect(mapStateToProps, mapDispatchToProps)(StepContainer) -} -export { StepComponentHOC as default } \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index 0ab033d..86e32d1 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,12 +1,8 @@ import React, { forwardRef } from 'react' import marked from 'marked' -import { Provider, connect } from 'react-redux' import Step, { StepProps } from './steps/common' import StepComponents, { StepConfigs } from './steps' import { RichStringConfig } from './interface' -import { store } from './store' -import { compose } from 'redux' -import { InterfaceState, PreloadedState } from './store/store' /** * 页面配置文件格式定义 * - basic: 页面基本配置 @@ -260,7 +256,7 @@ export default class CCMS1 extends React.Component { // 调用UI渲染方法 return ( - + {this.renderComponent({ title, description, @@ -296,7 +292,7 @@ export default class CCMS1 extends React.Component { } })) })} - + ) } } diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 863e59f..579e3e2 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -1,9 +1,6 @@ import React from 'react' import { CCMSConfig } from '../main' -import {connect} from 'react-redux' -import { compose } from 'redux' -import { InterfaceState, PreloadedState } from '../store/store' -import { setFormValue } from '../store/reducers/formValue' + /** * 页面流转步骤基类配置定义 * - type: 类型,对应各子类 @@ -64,21 +61,3 @@ export interface StepProps { return <> } } - -// const mapStateToProps = (state: PreloadedState) => { -// return { -// data: state.data.data, -// formValue: state.formValue.formValue -// } -// // return { -// // data: state.ccmsStore.data, -// // formValue: state.ccmsStore.formValue -// // } -// } -// const mapDispatchToProps = (dispatch: Function) => { -// return { -// handleFormValue: (payload: any):object => dispatch(setFormValue(payload)) -// } -// } -// connect(mapStateToProps, mapDispatchToProps)(Step) - diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index e89edb3..4a7e78c 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -10,11 +10,7 @@ import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' import fp from 'lodash/fp' -import produce from 'immer' -import { connect } from 'react-redux' -import { InterfaceState, PreloadedState } from '../../store/store' -import { setFormValue } from '../../store/reducers/formValue' -import StepComponentHOC from '../../HOC/stepComponentHOC' +import produce from 'immer' /** * 表单步骤配置文件格式定义 * - layout: 表单布局类型 @@ -157,7 +153,7 @@ export interface IFormItem { * 表单步骤组件 - 状态 * - formData: 表单的值 */ -export interface FormState { +interface FormState { ready: boolean formValue: { [field: string]: any } formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] @@ -166,7 +162,7 @@ export interface FormState { /** * 表单步骤组件 */ - const FormStepTemp = class FormStep extends Step { // ts对class的声明文件报错,临时解决 +export default class FormStep extends Step { // ts对class的声明文件报错,临时解决 // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Field => getALLComponents[type] OperationHelper = OperationHelper @@ -1029,8 +1025,8 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour record={formValue} // record={this.record_} form={this} - // data={cloneDeep(data)} - data={this.data_} + data={cloneDeep(data)} + // data={this.data_} step={step} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} @@ -1060,21 +1056,4 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour } } } -const mapStateToProps = (state: PreloadedState) => { - return { - data: state.data.data, - formValue: state.formValue.formValue - } -} -const mapDispatchToProps = (dispatch: Function) => { - return { - handleFormValue: (payload: any):object => dispatch(setFormValue(payload)) - } -} -const mergeProps = (stateProps:any, dispatchProps: any, ownProps: any) => Object.assign( - {}, stateProps, dispatchProps, ownProps -) - -const FormStep_ = connect(mapStateToProps, mapDispatchToProps, mergeProps)(FormStepTemp) -export default FormStep_ diff --git a/src/store/common.tsx b/src/store/common.tsx deleted file mode 100644 index c7e81da..0000000 --- a/src/store/common.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export declare interface actionInterface { - type: string - payload: { - path: string - value: any - } -} \ No newline at end of file diff --git a/src/store/index.tsx b/src/store/index.tsx deleted file mode 100644 index 9a3b2c8..0000000 --- a/src/store/index.tsx +++ /dev/null @@ -1 +0,0 @@ -export { default as store } from './store' \ No newline at end of file diff --git a/src/store/reducers/data.tsx b/src/store/reducers/data.tsx deleted file mode 100644 index d278ade..0000000 --- a/src/store/reducers/data.tsx +++ /dev/null @@ -1,43 +0,0 @@ -const SET_FULL_SCREEN = 'ccms/mode/SET_FULL_SCREEN'; -const SET_PLAYER = 'ccms/mode/SET_PLAYER'; - -const initialState = { - data: [] -}; - -const reducer = function (state: object, action: object) { - if (typeof state === 'undefined') state = initialState; - // switch (action.type) { - // case SET_FULL_SCREEN: - // return Object.assign({}, state, { - // isFullScreen: action.isFullScreen - // }); - // case SET_PLAYER: - // return Object.assign({}, state, { - // isPlayerOnly: action.isPlayerOnly, - // hasEverEnteredEditor: state.hasEverEnteredEditor || !action.isPlayerOnly - // }); - // default: - return state; - // } -}; - -// const setFullScreen = function (isFullScreen) { -// return { -// type: SET_FULL_SCREEN, -// isFullScreen: isFullScreen -// }; -// }; -// const setPlayer = function (isPlayerOnly) { -// return { -// type: SET_PLAYER, -// isPlayerOnly: isPlayerOnly -// }; -// }; - -export { - reducer as default, - initialState as dataInitialState, - // setFullScreen, - // setPlayer -}; diff --git a/src/store/reducers/formValue.tsx b/src/store/reducers/formValue.tsx deleted file mode 100644 index ace1170..0000000 --- a/src/store/reducers/formValue.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import produce from "immer"; -import { set } from 'lodash' -import { actionInterface } from '../common' - -const SET_FORM_VALUE = 'ccms/formValue/SET_FORM_VALUE'; - -const initialState = { - formValue: {}, -}; - - -const reducer = async function (state: object, action: actionInterface) { - const { payload } = action - if (typeof state === 'undefined' || !payload) state = initialState; - switch (payload && payload.value) { - case SET_FORM_VALUE: - set(state, payload.path, payload.value) - return Object.assign({}, state) - // const a = await produce(state, (draft) => { - - // }) - default: - return state; - } -}; - -const setFormValue = function (payload:{ path: string, value: any }):actionInterface { - return { - type: SET_FORM_VALUE, - payload - }; -}; - -export { - reducer as default, - initialState as formValueInitialState, - setFormValue -}; diff --git a/src/store/reducers/index.tsx b/src/store/reducers/index.tsx deleted file mode 100644 index 9ffdc7b..0000000 --- a/src/store/reducers/index.tsx +++ /dev/null @@ -1,2 +0,0 @@ -export { default as dataReducer, dataInitialState} from './data' -export { default as formValueReducer, formValueInitialState } from './formValue' \ No newline at end of file diff --git a/src/store/store.tsx b/src/store/store.tsx deleted file mode 100644 index 8a0ec21..0000000 --- a/src/store/store.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { createStore, combineReducers, compose } from 'redux' -import { dataReducer, dataInitialState, formValueReducer, formValueInitialState } from './reducers' - -export interface InterfaceState { - data: object, - formValue: object -} - - -declare const $CombinedState: unique symbol -interface EmptyObject { - readonly [$CombinedState]?: undefined -} -type CombinedState = EmptyObject & S - -/** - * Recursively makes combined state objects partial. Only combined state _root - * objects_ (i.e. the generated higher level object with keys mapping to - * individual reducers) are partial. - */ -export type PreloadedState = Required extends EmptyObject - ? S extends CombinedState - ? { - [K in keyof S1]?: S1[K] extends object ? PreloadedState : S1[K] - } - : S - : { - [K in keyof S]: S[K] extends string | number | boolean | symbol - ? S[K] - : PreloadedState - } - - - - -const initialState: PreloadedState = { - // ccmsStore: { - // ...dataInitialState, - // ...formValueInitialState - // } - data: dataInitialState, - formValue: formValueInitialState -} -const reducers = { - data: dataReducer, - formValue: formValueReducer -} -// @ts-ignore -const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; -const reducers_ = combineReducers(reducers) -let store = createStore(reducers_, initialState, composeEnhancers()) -export default store \ No newline at end of file -- Gitee From bf46f801cdd2d3b0a5a9297ff123c63cc8e67321 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 11 Jan 2022 14:58:15 +0800 Subject: [PATCH 006/164] =?UTF-8?q?feat:=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E5=8F=98immer=E5=A4=84=E7=90=86=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 41 +- src/components/formFields/form/index.tsx | 15 +- .../formFields/importSubform/index.tsx | 9 +- src/components/formFields/text/index.tsx | 6 +- src/steps/form/index.tsx | 377 ++---------------- src/util/param.ts | 4 +- src/util/produce.tsx | 55 +++ 7 files changed, 134 insertions(+), 373 deletions(-) create mode 100644 src/util/produce.tsx diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index f5ecdac..a85039a 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -5,8 +5,8 @@ import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' -import { is } from 'immutable' - +import { isEqual } from 'lodash' + /** * 表单项基类配置文件格式定义 * - field: 表单项字段名 @@ -172,21 +172,36 @@ export class Field extends React.Component< 当前UI库未实现该表单类型 } - shouldComponentUpdate(nextProps= {} as any, nextState = {}) { - if (!is(nextProps.config, this.props.config) || !is(nextProps.value, this.props.value)) { - console.log('props-true'); - return true; - } - if (!is(this.state, nextState)) { - console.log('state-true'); - return true; + console.log('nextProps', nextProps, this.props); + //@ts-ignore + // if (!isEqual(this.state, nextState) || (window.needUpdatePath && window.needUpdatePath.indexOf(nextProps.path) != -1)) { + // return true + // } + // console.log('no update' ); + // return false + + if (isEqual(this.state, nextState) && isEqual(nextProps.config, this.props.config) && nextProps.value === this.props.value && nextProps.record === this.props.record && isEqual(nextProps.data, this.props.data)) { + if (nextProps.value === this.props.value) { + console.log(123, this.props.value); } - console.log('no update' ); - return false; - } + } + return true; + + + // if (is(nextProps.value, this.props.value)) { + // console.log('=is=', nextProps.value, this.props.value); + // } + + // if (!isEqual(this.state, nextState) || !isEqual(nextProps.value, this.props.value) || !isEqual(nextProps.record, this.props.record) || !isEqual(nextProps.config, this.props.config) || !isEqual(nextProps.data, this.props.data)) { + // return true; + // } + // console.log('no update' ); + // return false; +} + render = () => { return ( 当前UI库未实现该表单类型 diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index c32ab6c..c1a16d0 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -2,7 +2,8 @@ import React from 'react' import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from '../common' import getALLComponents from '../' import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' -import { cloneDeep } from 'lodash' +// import { cloneDeep } from 'lodash' +import { cloneDeep } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' @@ -235,8 +236,8 @@ export default class FormField extends Field implements IField { @@ -415,8 +416,8 @@ export default class ImportSubformField extends Field await this.props.onValueSet('', value, await this.validate(value)) + onChange: async (value: string) => { + //@ts-ignore + window.needUpdatePath = this.props.path + return await this.props.onValueSet('', value, await this.validate(value)) + } })} ) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 4a7e78c..74c5ced 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -5,7 +5,8 @@ import getALLComponents from '../../components/formFields' import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' -import { cloneDeep, get, set, unset, update } from 'lodash' +import { get, set, unset, update } from 'lodash' +import { cloneDeep, splice, sort } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' @@ -175,313 +176,6 @@ export default class FormStep extends Step { // ts对clas formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] = [] canSubmit: boolean = false submitData: object = {} - record_:object = { - "pageFormData": { - "dataAssociation": { - "sourceMaterial": { - "fields": [ - { - "label": "上提12", - "field": "liftUp", - "type": "switch", - "extra": { - "statement": "", - "params": [] - }, - "valueTrue": true, - "valueFalse": false, - "defaultValue": { - "source": "static", - "value": false - }, - "required": true, - "condition": { - "params": [] - } - }, - { - "label": "上提楼层尾icon-短文本链接", - "field": "upTailIcon", - "type": "text", - "extra": { - "params": [] - }, - "placeholder": "请输入尾icon地址", - "regExp": {}, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [ - { - "field": "upward", - "data": { - "source": "record", - "field": "material.liftUp" - } - } - ], - "template": "${upward} === true" - } - }, - { - "label": "尾icon高度-数值", - "field": "upTailIconHight", - "type": "number", - "extra": { - "params": [] - }, - "precision": 0, - "step": 1, - "max": 120, - "regExp": {}, - "defaultValue": { - "source": "static", - "value": 0 - }, - "required": true, - "condition": { - "params": [ - { - "field": "upward", - "data": { - "source": "record", - "field": "material.liftUp" - } - } - ], - "template": "${upward} === true" - } - }, - { - "label": "上提楼层头icon-短文本", - "field": "upHeadIcon", - "type": "text", - "extra": { - "params": [] - }, - "placeholder": "请输入头icon地址", - "cjkLength": 2, - "regExp": {}, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [ - { - "field": "upward", - "data": { - "source": "record", - "field": "material.liftUp" - } - } - ], - "template": "${upward} === true" - } - }, - { - "label": "业务标题-短文本", - "field": "title", - "type": "text", - "extra": { - "params": [] - }, - "placeholder": "请输入展示文案", - "maxLength": 12, - "minLength": null, - "cjkLength": 2, - "regExp": { - "expression": "", - "message": "业务标题重复" - }, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [] - } - }, - { - "label": "业务标题色值", - "field": "titleColor", - "type": "color", - "extra": { - "params": [] - }, - "defaultValue": { - "source": "static", - "value": "#ffffff" - }, - "required": true, - "condition": { - "params": [ - { - "field": "upward", - "data": { - "source": "record", - "field": "material.liftUp" - } - } - ], - "template": "${upward} === true" - } - }, - { - "label": "业务副标题-文本1", - "field": "subTitle", - "type": "text", - "extra": { - "params": [] - }, - "placeholder": "请输入展示文案", - "maxLength": 16, - "minLength": null, - "cjkLength": 2, - "regExp": { - "expression": "", - "message": "文案超过8个字" - }, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [] - } - }, - { - "label": "业务副标题色值", - "field": "subtitleColor", - "type": "color", - "extra": { - "params": [] - }, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [ - { - "field": "upward", - "data": { - "source": "record", - "field": "material.liftUp" - } - } - ], - "template": "${upward} === true " - } - }, - { - "label": "icon图片", - "field": "icon", - "type": "upload", - "extra": { - "statement": "icon尺寸33x44,支持png格式,50K以内", - "params": [] - }, - "interface": { - "domain": "jdg", - "url": "/upload/imageUpload", - "urlParams": [], - "method": "POST", - "contentType": "json", - "withCredentials": true, - "params": [], - "data": [], - "condition": { - "enable": true, - "success": {}, - "fail": {} - }, - "response": [ - { - "path": "data" - } - ], - "cache": {} - }, - "requireField": "file", - "mode": "image", - "sizeCheck": { - "maxSize": 50, - "sizeUnit": "K", - "height": null, - "width": null - }, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [], - "template": "" - } - }, - { - "label": "背景颜色-取色器", - "field": "bgColor", - "type": "color", - "extra": { - "params": [] - }, - "defaultValue": { - "source": "static", - "value": "#ffffff" - }, - "required": true, - "condition": { - "params": [ - { - "field": "upward", - "data": { - "source": "record", - "field": "material.liftUp" - } - } - ], - "template": "${upward} === true" - } - }, - { - "label": "跳转链接", - "field": "jumpUrl", - "type": "text", - "extra": { - "statement": "1、跳转地址必须经西格玛审核; 2、跳转地址需在APP白名单中,不在可找商详技术处理", - "params": [] - }, - "placeholder": "请输入跳转链接", - "regExp": { - "expression": "(ht|f)tp(s?)\\:\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*(:(0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\'\\/\\\\\\+&%$#_]*)?", - "message": "请输入正确格式" - }, - "defaultValue": { - "source": "static", - "value": "" - }, - "required": true, - "condition": { - "params": [], - "template": "" - } - } - ] - } - } - } -} -data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sourceMaterial.fields"],"defaultValue":{"source":"step","field":"data","step":1,"unstringify":["data.pageFormData.dataAssociation.sourceMaterial.field"]},"businessSuffix":"","unstringify":["pageFormData.dataAssociation.sourceMaterial.fields"],"version":"1.0.0","subversion":"0","fields":[{"canInsert":true,"canSort":true,"canRemove":true,"label":"字段设置","primaryField":"label","fields":[{"label":"字段描述","field":"label","type":"text"},{"label":"字段名","field":"field","type":"text"},{"field":"","label":"","type":"import_subform","interface":{"url":"https://storage.jd.com/swm-plus/prod-floor-fields/config/form/index.json","urlParams":[],"method":"GET"},"defaultValue":{"source":"record","field":""}}],"field":"pageFormData.dataAssociation.sourceMaterial.fields","type":"form","canCollapse":true}],"type":"form","applicationName":"example","actions":[{"type":"ccms","mode":"primary","label":"保存并发布","callback":{"type":"cancel"},"handle":{"type":"ccms","page":822,"mode":"popup","label":"","params":[{"field":"systemId","data":{"source":"record","value":"create","field":"systemId"}},{"field":"type","data":{"source":"record","field":"type"}},{"field":"appName","data":{"source":"record","field":"appName"}},{"field":"pageFormData","data":{"source":"record","field":"pageFormData"}},{"data":{"source":"static","value":1},"field":"saveAndPublish"},{"field":"templateUseType","data":{"source":"step","value":1,"field":"data.jdgBusiFloor.templateUseType","step":1}},{"field":"id","data":{"source":"record","field":"jdgBusiFloor.id"}}]},"condition":{"debug":true}},{"type":"submit","mode":"primary","label":"保存为草稿","callback":{"type":"none"},"handle":{"type":"ccms"},"condition":{"params":[]}}]},"fields":[{"canInsert":true,"canSort":true,"defaultValue":{"source":"static","value":""},"canRemove":true,"label":"字段设置","primaryField":"label","fields":[{"label":"字段描述","field":"label","type":"text"},{"label":"字段名","field":"field","type":"text"},{"field":"","label":"","type":"import_subform","interface":{"url":"https://storage.jd.com/swm-plus/prod-floor-fields/config/form/index.json","urlParams":[],"method":"GET"},"defaultValue":{"source":"record","field":""}}],"field":"pageFormData.dataAssociation.sourceMaterial.fields","type":"form","canCollapse":true}],"stringify":["pageFormData.dataAssociation.sourceMaterial.fields"],"actions":[{"type":"ccms","mode":"primary","label":"保存并发布","callback":{"type":"cancel"},"handle":{"type":"ccms","page":822,"mode":"popup","label":"","params":[{"field":"systemId","data":{"source":"record","value":"create","field":"systemId"}},{"field":"type","data":{"source":"record","field":"type"}},{"field":"appName","data":{"source":"record","field":"appName"}},{"field":"pageFormData","data":{"source":"record","field":"pageFormData"}},{"data":{"source":"static","value":1},"field":"saveAndPublish"},{"field":"templateUseType","data":{"source":"step","value":1,"field":"data.jdgBusiFloor.templateUseType","step":1}},{"field":"id","data":{"source":"record","field":"jdgBusiFloor.id"}}]},"condition":{"debug":true}},{"type":"submit","mode":"primary","label":"保存为草稿","callback":{"type":"none"},"handle":{"type":"ccms"},"condition":{"params":[]}}],"applicationName":"example","businessSuffix":"","version":"1.0.0","subversion":"0"}] /** * 初始化表单的值 @@ -531,12 +225,7 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour const formFieldConfig = formFieldsConfig[formFieldIndex] const value = getValue(formDefault, formFieldConfig.field) - // this.formValue = setValue(this.formValue, formFieldConfig.field, value) - console.log('this.formValue', this.formValue, formFieldConfig.field); - - this.formValue = produce(this.formValue, draft => { - setValue(draft, formFieldConfig.field, value) - }) + this.formValue = setValue(this.formValue, formFieldConfig.field, value) this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } } } @@ -568,10 +257,7 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour value = await formField.reset() } value = await formField.set(value) - // this.formValue = setValue(this.formValue, formFieldConfig.field, value) - this.formValue = produce(this.formValue, draft => { - setValue(draft, formFieldConfig.field, value) - }) + this.formValue = setValue(this.formValue, formFieldConfig.field, value) if (value !== undefined) { const validation = await formField.validate(value) @@ -695,30 +381,27 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - - const fullPathArr = fullPath.split('.') - - if(this.props.handleFormValue) { + + if(this.props.handleFormValue) { this.props.handleFormValue({path: fullPath, value}) } // set(this.formValue, fullPath, value) - this.formValue = produce(this.formValue, draft => { - setValue(draft, fullPath, value) - }) - console.log('set--', this.formValue, fullPath, fullPathArr, value); - this.setState({ + this.formValue = cloneDeep(this.formValue, 'set', fullPath, value) + console.log('test--->set--', this.formValue, fullPath, value); + this.setState(({formValue})=>({ 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 } - // } + if (validation === true) { + this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + } else { + this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + } console.log('form set data', this.formData) @@ -759,9 +442,10 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` let list = get(this.formValue, fullPath, []) - if (!Array.isArray(list)) list = [] - list.push(value) - set(this.formValue, fullPath, list) + console.log('list---', list, value); + let cloneList = cloneDeep(list,'push', fullPath, value) + // set(this.formValue, fullPath, list) + this.formValue = cloneDeep(this.formValue, 'set', fullPath, cloneList) this.setState({ formValue: this.formValue }) @@ -787,8 +471,9 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` const list = get(this.formValue, fullPath, []) - list.splice(index, count) - set(this.formValue, fullPath, list) + const cloneList = splice(list, index, count) + // set(this.formValue, fullPath, list) + this.formValue = cloneDeep(this.formValue, 'set', fullPath, cloneList) this.setState({ formValue: this.formValue }) @@ -813,8 +498,10 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour 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) + // const list = listItemMove(get(this.formValue, fullPath, []), index, sortType) + const list = sort(get(this.formValue, fullPath, []), index, sortType) + // set(this.formValue, fullPath, list) + this.formValue = cloneDeep(this.formValue, 'set', fullPath, list) this.setState({ formValue: this.formValue }) @@ -1019,18 +706,16 @@ data_: any = [{"type":"form","":{"stringify":["pageFormData.dataAssociation.sour } }} formLayout={layout} - value={formFieldConfig.field !== undefined ? getValue(formValue, formFieldConfig.field) : undefined} - // value={formFieldConfig.field !== undefined ? immuHelperX.$apply(formValue, formFieldConfig.field, (v:any) => v) : undefined} - // record={formValue.toJS()} - record={formValue} - // record={this.record_} + value={formFieldConfig.field !== undefined ? cloneDeep(getValue(formValue, formFieldConfig.field)) : undefined} + record={cloneDeep(formValue)} form={this} data={cloneDeep(data)} - // data={this.data_} step={step} + // stepValue={cloneDeep(formValue)} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} onValueSet={async (path, value, validation) => await this.handleValueSet(formFieldIndex, path, value, validation)} + // onDidMountSet 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)} diff --git a/src/util/param.ts b/src/util/param.ts index 0742e6b..cbe4e5a 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -2,7 +2,7 @@ import { get, set } from "lodash" import qs from "query-string" import { ParamConfig } from "../interface"; -export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: number }) { +export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: number }) { // step--> stepValue switch (config.source) { case 'record': if (datas.record) { @@ -18,7 +18,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj if (config.field === '') { return datas.data[datas.step] } else { - return get(datas.data[datas.step], config.field) + return get(datas.data[datas.step], config.field) //return get(stepValue, config.field) } } break diff --git a/src/util/produce.tsx b/src/util/produce.tsx new file mode 100644 index 0000000..4f077e3 --- /dev/null +++ b/src/util/produce.tsx @@ -0,0 +1,55 @@ +import produce, { setAutoFreeze, original } from 'immer' +import lodash from 'lodash' +import { listItemMove } from '../util/value' + +type OperationType = 'set' | 'push' | 'splice' +type FormValue = { [field: string]: any } +type FormData = { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] +type FormDataList = { status: 'normal' | 'error' | 'loading', message?: string }[][] +type Data = any[] +type Data_ = Data | FormData | FormValue | FormDataList +setAutoFreeze(false) + +/** + * immer使用produce的封装 + * @param current 当前数据 + * @param operationType 修改方法,只读项没必要用,对应lodash的操作方法 + * @param path lodash链式路径 + * @param value 要修改为的值 + * @returns 修改后数据 + */ + export const cloneDeep = (current: any, operationType?: OperationType, path?: string, value?: any) => { + if (!operationType) return current // 注意这里没有深拷贝,只有在修改时才使用immer的api + let target = produce(current, (draft: any) => { + if (!path) path='' + // const method = lodash[operationType] + // @ts-ignore + // method(draft, path, value) // 写return method(draft, path, value)会卡顿 + switch (operationType) { + case 'set': + return lodash.set(draft, path, value) + break + // case 'get': + // return lodash.get(draft, path, value) + // break + case 'push': + return lodash.concat(draft, value) + break + } + }) + return target +} + +export const splice = (current: any, index:number, count:number) => { + let target = produce(current, (draft: any)=>{ + draft.splice(index, count) + }) + return target +} + +export const sort = (current: any, index: number, sortType: 'up' | 'down') => { + let target = produce(current, (draft: any)=>{ + return listItemMove(draft, index, sortType) + }) + return target +} \ No newline at end of file -- Gitee From ac656f118c5c262c7fcdae17d26400addc561a44 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 11 Jan 2022 17:26:10 +0800 Subject: [PATCH 007/164] =?UTF-8?q?fix:immer=E4=BF=AE=E6=94=B9=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=E5=88=B0=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/form/index.tsx | 6 +++--- src/util/produce.tsx | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 74c5ced..f4699ca 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -2,11 +2,12 @@ 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, listItemMove, getBoolean, getChainPath } from '../../util/value' +// import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' +import { getValue, listItemMove, getBoolean, getChainPath } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' import { get, set, unset, update } from 'lodash' -import { cloneDeep, splice, sort } from '../../util/produce' +import { cloneDeep, splice, sort, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' @@ -252,7 +253,6 @@ export default class FormStep extends Step { // ts对clas const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const fieldPathArr = formFieldConfig.field.split('.') let value = getValue(this.formValue, formFieldConfig.field) - // let value = immuHelperX.$apply(this.formValue, formFieldConfig.field, (val:any)=>val) if ((formFieldConfig.defaultValue) && value === undefined) { value = await formField.reset() } diff --git a/src/util/produce.tsx b/src/util/produce.tsx index 4f077e3..9a75f7a 100644 --- a/src/util/produce.tsx +++ b/src/util/produce.tsx @@ -52,4 +52,39 @@ export const sort = (current: any, index: number, sortType: 'up' | 'down') => { return listItemMove(draft, index, sortType) }) return target +} + +const merge = (a: any, b: any): any => { + return lodash.assignInWith(a, b, (a, b) => { + if (lodash.isUndefined(a) && lodash.isArray(b)) { + a = [] + } + if (lodash.isObject(b)) { + if (lodash.isArray(a)) { + return merge(a, b).filter((i: any) => i !== undefined) + } else { + return merge(a, b) + } + } + }) +} + +export const setValue = (obj: any, path: string = '', value: any) => { + let target = produce(obj, (draft: any) => { + if (path === '') { + if (Object.prototype.toString.call(value) === '[object Object]') { + draft = merge(draft, value) + } else if (value !== undefined) { + draft = value + } + } else { + const source = lodash.get(draft, path) + if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(source) === '[object Object]') { + lodash.set(draft, path, merge(source, value)) + } else { + lodash.set(draft, path, value) + } + } + }) + return target } \ No newline at end of file -- Gitee From 031a53eba304ece5d3ab58b55e9257bedd41ea27 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 14 Jan 2022 15:30:00 +0800 Subject: [PATCH 008/164] =?UTF-8?q?feat:=20=E7=BB=84=E4=BB=B6=E6=8C=82?= =?UTF-8?q?=E8=BD=BDstep=E4=B8=BAformValue=E7=9A=84=E5=80=BC=E3=80=81?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5condition=E4=BE=9D=E8=B5=96=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 3 +- src/components/formFields/common.tsx | 49 ++++++------ src/components/formFields/form/index.tsx | 80 +++++++++++++------ .../formFields/importSubform/index.tsx | 21 ++++- src/components/formFields/text/index.test.tsx | 4 +- src/components/formFields/text/index.tsx | 7 +- .../formFields/treeSelect/index.tsx | 2 +- .../tableColumns/enum/index.test.tsx | 3 +- src/interface.ts | 4 +- src/main.tsx | 3 +- src/steps/common.tsx | 3 +- src/steps/detail/index.tsx | 3 +- src/steps/fetch/index.tsx | 2 +- src/steps/filter/index.tsx | 3 +- src/steps/form/index.tsx | 39 +++++---- src/steps/skip/index.tsx | 6 +- src/steps/table/index.tsx | 8 +- src/util/condition.ts | 10 ++- src/util/interface.ts | 14 ++-- src/util/operation.tsx | 11 +-- src/util/param.ts | 10 +-- src/util/produce.tsx | 9 ++- src/util/statement.ts | 8 +- src/util/value.ts | 6 +- 24 files changed, 187 insertions(+), 121 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index a112c87..9985d6d 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -73,7 +73,8 @@ export interface DetailFieldProps { value: T, record: { [field: string]: any }, data: any[], - step: number, + step: { [field: string]: any } // formValue挂载 + // step: number, config: C // TODO 待删除 onChange: (value: T) => Promise diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index a85039a..1d870ed 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -5,7 +5,7 @@ import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' -import { isEqual } from 'lodash' +import { isEqual, get } from 'lodash' /** * 表单项基类配置文件格式定义 @@ -78,7 +78,7 @@ export interface FieldProps { value: T, record: { [field: string]: any }, data: any[], - step: number, + // step: number, config: C // TODO 待删除 onChange: (value: T) => Promise @@ -94,6 +94,7 @@ export interface FieldProps { onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, path: string, // 组件所在路径以字段拼接展示 + step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise } @@ -172,34 +173,32 @@ export class Field extends React.Component< 当前UI库未实现该表单类型 } - shouldComponentUpdate(nextProps= {} as any, nextState = {}) { - console.log('nextProps', nextProps, this.props); - //@ts-ignore - // if (!isEqual(this.state, nextState) || (window.needUpdatePath && window.needUpdatePath.indexOf(nextProps.path) != -1)) { - // return true - // } - // console.log('no update' ); - // return false - - if (isEqual(this.state, nextState) && isEqual(nextProps.config, this.props.config) && nextProps.value === this.props.value && nextProps.record === this.props.record && isEqual(nextProps.data, this.props.data)) { - if (nextProps.value === this.props.value) { - console.log(123, this.props.value); + dependentFieldsArr: any + shouldComponentUpdate(nextProps:FieldProps, nextState: S) { + console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); + console.log('this.dependentFieldsArr',this.dependentFieldsArr); + const dependentFieldsArr = this.dependentFieldsArr + let dependentIsChange = false + if (dependentFieldsArr) { + for (let i=0;i< dependentFieldsArr.length;i++) { + const nextDependentField = get(nextProps.step, dependentFieldsArr[i]) + const currentDependentField = get(this.props.step, dependentFieldsArr[i]) + if (nextDependentField !== currentDependentField) { + dependentIsChange = true + break + } + } } + +/** + * config受value影响变化 ,data提交前不变, 去掉这两项的比较 + * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 + * */ + if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value) { console.log('no update' ); return false; } return true; - - - // if (is(nextProps.value, this.props.value)) { - // console.log('=is=', nextProps.value, this.props.value); - // } - - // if (!isEqual(this.state, nextState) || !isEqual(nextProps.value, this.props.value) || !isEqual(nextProps.record, this.props.record) || !isEqual(nextProps.config, this.props.config) || !isEqual(nextProps.data, this.props.data)) { - // return true; - // } - // console.log('no update' ); - // return false; } render = () => { diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index c1a16d0..3fd3abf 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -1,9 +1,10 @@ import React from 'react' import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from '../common' import getALLComponents from '../' -import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' +// import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' // import { cloneDeep } from 'lodash' -import { cloneDeep } from '../../../util/produce' +import { getValue, getBoolean, getChainPath } from '../../../util/value' +import { cloneDeep, setValue , sort, splice} from '../../../util/produce' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' @@ -67,6 +68,7 @@ export default class FormField extends Field | null>> = [] formFieldsMountedList: Array> = [] + dependentFieldsArr: string[] = [] //condition中依赖字段的存放数组 constructor (props: FieldProps) { super(props) @@ -214,15 +216,17 @@ export default class FormField extends Field { if (!this.formFieldsMountedList[index]) { - this.formFieldsMountedList[index] = [] + // this.formFieldsMountedList[index] = [] + cloneDeep(this.formFieldsMountedList, 'set', `[${index}]`, []) } if (this.formFieldsMountedList[index][formFieldIndex]) { return true } - this.formFieldsMountedList[index][formFieldIndex] = true + // this.formFieldsMountedList[index][formFieldIndex] = true + this.formFieldsMountedList = cloneDeep(this.formFieldsMountedList, 'set', `[${index}][${formFieldIndex}]`, true) - const formDataList = cloneDeep(this.state.formDataList) - if (!formDataList[index]) formDataList[index] = [] + let formDataList = cloneDeep(this.state.formDataList) + if (!formDataList[index]) formDataList = cloneDeep(formDataList, 'set', `[${index}]`, []) if (this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex]) { const formField = this.formFieldsList[index][formFieldIndex] @@ -261,38 +265,46 @@ export default class FormField extends Field { const index = (this.props.value || []).length - const formDataList = cloneDeep(this.state.formDataList) - formDataList[index] = [] + const formDataList = cloneDeep(this.state.formDataList, 'set', `[${index}]`, []) this.setState({ formDataList }) - this.formFieldsList[index] = [] - this.formFieldsMountedList[index] = [] + // this.formFieldsList[index] = [] + this.formFieldsList = cloneDeep(this.formFieldsList, 'set', `${index}`, []) + // this.formFieldsMountedList[index] = [] + this.formFieldsMountedList = cloneDeep(this.formFieldsMountedList, 'set', `${index}`, []) await this.props.onValueListAppend('', this.props.config.initialValues === undefined ? {} : cloneDeep(this.props.config.initialValues), true) } handleRemove = async (index: number) => { - const formDataList = cloneDeep(this.state.formDataList) - formDataList.splice(index, 1) + // const formDataList = cloneDeep(this.state.formDataList) + const formDataList = splice(this.state.formDataList, index, 1) this.setState({ + //@ts-ignore formDataList }) - - this.formFieldsList.splice(index, 1) - this.formFieldsMountedList.splice(index, 1) - + // this.formFieldsList.splice(index, 1) + //@ts-ignore + this.formFieldsList = splice(this.formFieldsList,index, 1) + // this.formFieldsMountedList.splice(index, 1) + //@ts-ignore + this.formFieldsMountedList = splice(this.formFieldsMountedList,index, 1) await this.props.onValueListSplice('', index, 1, true) } handleSort = async (index: number, sortType: 'up' | 'down') => { - const formDataList = listItemMove(cloneDeep(this.state.formDataList), index, sortType) + var list = cloneDeep(this.state.formDataList) + let formDataList = sort(list, index, sortType) this.setState({ - formDataList + //@ts-ignore + formDataList: formDataList }) - this.formFieldsList = listItemMove(this.formFieldsList, index, sortType) - this.formFieldsMountedList = listItemMove(this.formFieldsMountedList, index, sortType) + //@ts-ignore + this.formFieldsList = sort(this.formFieldsList, index, sortType) + //@ts-ignore + this.formFieldsMountedList = sort(this.formFieldsMountedList, index, sortType) await this.props.onValueListSort('', index, sortType, true) } @@ -494,9 +506,23 @@ export default class FormField extends Field await this.handleSort(index, sortType) : undefined, canCollapse, children: (fields || []).map((formFieldConfig, fieldIndex) => { + const conditionParams = formFieldConfig.condition?.params + if (conditionParams && Array.isArray(conditionParams)) { + const dependentFieldsArr = conditionParams.map(ite => { + if (ite.data?.source === 'record') { + return ite?.data?.field && `${this.props.path}.${ite.data.field}` + } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { + return ite?.data?.field && `${ite.data.field}` + } + return '' + }).filter(ite=>ite) + this.dependentFieldsArr = dependentFieldsArr + console.log('this.dependentFieldsArr--formList', this.dependentFieldsArr); + } if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step })) { - if (!this.formFieldsMountedList[index]) this.formFieldsMountedList[index] = [] - this.formFieldsMountedList[index][fieldIndex] = false + // if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = cloneDeep(this.formFieldsMountedList, 'set', `${index}`, [] ) + // this.formFieldsMountedList[index][fieldIndex] = false + this.formFieldsMountedList = cloneDeep(this.formFieldsMountedList, 'set', `${[index]}.${fieldIndex}`, false) return null } const FormField = this.getALLComponents(formFieldConfig.type) || Field @@ -523,8 +549,9 @@ export default class FormField extends Field | null) => { if (fieldRef) { - if (!this.formFieldsList[index]) this.formFieldsList[index] = [] - this.formFieldsList[index][fieldIndex] = fieldRef + if (!this.formFieldsList[index]) this.formFieldsList = cloneDeep(this.formFieldsList, 'set', `[${index}]`, []) + // this.formFieldsList[index][fieldIndex] = fieldRef + this.formFieldsList = cloneDeep(this.formFieldsList, 'set', `[${index}][${fieldIndex}]`, fieldRef) this.handleMount(index, fieldIndex) } }} @@ -532,8 +559,9 @@ export default class FormField extends Field this.handleChange(index, fieldIndex, value)} onValueSet={async (path, value, validation) => this.handleValueSet(index, fieldIndex, path, value, validation)} @@ -543,7 +571,7 @@ export default class FormField extends Field await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(formFieldConfig.field, this.props.path)} + path={getChainPath(`${fieldIndex}.${formFieldConfig.field}`, this.props.path)} /> ) }) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 9042cb0..eecdbc4 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -1,11 +1,12 @@ import React from 'react' -import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' +// import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' +import { getValue, getBoolean, getChainPath } 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 } from '../../../util/produce' +import { cloneDeep, setValue } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' @@ -370,6 +371,19 @@ export default class ImportSubformField extends Field { + const conditionParams = formFieldConfig.condition?.params + if (conditionParams && Array.isArray(conditionParams)) { + const dependentFieldsArr = conditionParams.map(ite => { + if (ite.data?.source === 'record') { + return ite?.data?.field && `${this.props.path}.${ite.data.field}` + } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { + return ite?.data?.field && `${ite.data.field}` + } + return '' + }).filter(ite=>ite) + this.dependentFieldsArr = dependentFieldsArr + console.log('this.dependentFieldsArr--子表单', this.dependentFieldsArr); + } if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { this.formFieldsMounted[formFieldIndex] = false return null @@ -418,8 +432,9 @@ export default class ImportSubformField extends Field { await this.handleChange(formFieldIndex, value) }} onValueSet={async (path, value, validation) => this.handleValueSet(formFieldIndex, path, value, validation)} diff --git a/src/components/formFields/text/index.test.tsx b/src/components/formFields/text/index.test.tsx index 1633d3f..61e5844 100644 --- a/src/components/formFields/text/index.test.tsx +++ b/src/components/formFields/text/index.test.tsx @@ -89,7 +89,7 @@ test('文本框默认值 -数据值 query', () => { cleanup() resolve(true) }} - config={{ field: 'jest', label: 'jest', type: 'text', defaultValue: { source: 'query', filed: 'default' } }} + config={{ field: 'jest', label: 'jest', type: 'text', defaultValue: { source: 'query', field: 'default' } }} /> ) }) @@ -108,7 +108,7 @@ test('文本框默认值 -数据值 hash', () => { cleanup() resolve(true) }} - config={{ field: 'jest', label: 'jest', type: 'text', defaultValue: { source: 'hash', filed: 'default' } }} + config={{ field: 'jest', label: 'jest', type: 'text', defaultValue: { source: 'hash', field: 'default' } }} /> ) }) diff --git a/src/components/formFields/text/index.tsx b/src/components/formFields/text/index.tsx index ae4adeb..7150c17 100644 --- a/src/components/formFields/text/index.tsx +++ b/src/components/formFields/text/index.tsx @@ -1,4 +1,5 @@ import React from 'react' +import { isEqual, get } from 'lodash' import { getBoolean } from '../../../util/value' import { Field, FieldConfig, FieldError, IField } from '../common' @@ -161,11 +162,7 @@ export default class TextField extends Field { - //@ts-ignore - window.needUpdatePath = this.props.path - return await this.props.onValueSet('', value, await this.validate(value)) - } + onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) })} ) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 6d3973a..9440c97 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -99,7 +99,7 @@ export default class TreeSelectField extends Field { if (config) { diff --git a/src/components/tableColumns/enum/index.test.tsx b/src/components/tableColumns/enum/index.test.tsx index 1560a5a..b0e744c 100644 --- a/src/components/tableColumns/enum/index.test.tsx +++ b/src/components/tableColumns/enum/index.test.tsx @@ -16,12 +16,13 @@ const defaultProps: ColumnProps = { label: 'test', valueType: 'string', multiple: true, + align: 'left', options: { from: 'manual', data: [{ extra: 'a', // todo label: '1', - key: 'filed' + key: 'field' }] }, defaultValue: '' diff --git a/src/interface.ts b/src/interface.ts index 594c704..ac9b062 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -40,11 +40,11 @@ interface URLParamConfig { } interface QueryParamConfig { source: 'query', - filed: any + field: string } interface HashParamConfig { source: 'hash', - filed: any + field: string } interface InterfaceParamConfig { source: 'interface', diff --git a/src/main.tsx b/src/main.tsx index 86e32d1..1dac8e5 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -265,7 +265,8 @@ export default class CCMS1 extends React.Component { const props: StepProps = { ref: (e) => { this.steps[index] = e }, data, - step: index, + // step: index, + step: data[index], onSubmit: (data: any, unmountView: boolean = true) => this.handleSubmit(index, data, unmountView), onMount: () => this.handleMount(index), onUnmount: (reload: boolean = false, data?: any) => this.handleUnmount(index, reload, data), diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 579e3e2..d24543a 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -20,7 +20,8 @@ export interface StepConfig { export interface StepProps { ref: (instance: Step | null) => void data: any[] - step: number + step: {[field: string]: any} + // step: number config: C onChange?: (data: any) => Promise onSubmit: (data: any, unmountView?: boolean) => Promise diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index 6b5b504..f58c069 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -411,8 +411,9 @@ export default class DetailStep extends Step { formLayout={layout} value={detailFieldConfig.field !== undefined ? getValue(detailValue, detailFieldConfig.field) : undefined} record={detailValue} + step={cloneDeep(detailValue)} + // step={step} data={cloneDeep(data)} - step={step} config={detailFieldConfig} onChange={async (value: any) => { await this.handleChange(detailFieldIndex, value) }} onValueSet={async (path, value, validation) => await this.handleValueSet(detailFieldIndex, path, value, validation)} diff --git a/src/steps/fetch/index.tsx b/src/steps/fetch/index.tsx index 19f631e..9545263 100644 --- a/src/steps/fetch/index.tsx +++ b/src/steps/fetch/index.tsx @@ -40,7 +40,7 @@ export default class FetchStep extends Step { try { const content = await this.interfaceHelper.request( merge(config.interface, { cache: { disabled: true } }), - {...(this.popData || {}), ...(init_data || {}), ...(this.props.data[this.props.step] || {})}, + {...(this.popData || {}), ...(init_data || {}), ...(this.props.step || {})}, { data: this.props.data, step: this.props.step diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index b280205..74562d7 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -496,8 +496,9 @@ export default class FilterStep extends Step { formLayout={'inline'} value={formFieldConfig.field !== undefined ? get(formValue, formFieldConfig.field) : undefined} record={formValue} + step={cloneDeep(formValue)} + // step={step} data={cloneDeep(data)} - 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)} diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index f4699ca..be6c385 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -6,13 +6,12 @@ import getALLComponents from '../../components/formFields' import { getValue, listItemMove, getBoolean, getChainPath } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' -import { get, set, unset, update } from 'lodash' +import { get, set, unset, update , isEqual } from 'lodash' import { cloneDeep, splice, sort, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' -import fp from 'lodash/fp' -import produce from 'immer' + /** * 表单步骤配置文件格式定义 * - layout: 表单布局类型 @@ -168,6 +167,8 @@ export default class FormStep extends Step { // ts对clas // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Field => getALLComponents[type] OperationHelper = OperationHelper + dependentFieldsArr: string[] = [] //condition中依赖字段的存放数组 + // 各表单项所使用的UI组件的实例 formFields: Array | null> = [] @@ -251,7 +252,6 @@ export default class FormStep extends Step { // ts对clas const formField = this.formFields[formFieldIndex] if (formField) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] - const fieldPathArr = formFieldConfig.field.split('.') let value = getValue(this.formValue, formFieldConfig.field) if ((formFieldConfig.defaultValue) && value === undefined) { value = await formField.reset() @@ -285,9 +285,9 @@ export default class FormStep extends Step { // ts对clas this.submitData = {} if (this.props.config.validations) { for (const validation of this.props.config.validations) { - if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.props.step })) { + if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.formValue })) { this.canSubmit = false - const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.props.step }) || '未填写失败文案或失败文案配置异常' + const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.formValue }) || '未填写失败文案或失败文案配置异常' this.renderModalComponent({ message }) return } @@ -601,7 +601,7 @@ export default class FormStep extends Step { // ts对clas if (Object.prototype.toString.call(actions) === '[object Array]') { actions_ = [] for (let index = 0, len = actions.length; index < len; index++) { - if (!ConditionHelper(actions[index].condition, { record: formValue, data, step })) { + if (!ConditionHelper(actions[index].condition, { record: formValue, data, step: formValue })) { continue } if (actions[index].type === 'submit') { @@ -655,7 +655,20 @@ export default class FormStep extends Step { // ts对clas submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 cancelText: this.props.config?.cancelText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { + const conditionParams = formFieldConfig.condition?.params + if (conditionParams && Array.isArray(conditionParams)) { + const dependentFieldsArr = conditionParams.map(ite => { + if (ite.data?.source === 'record') { + return ite?.data?.field && `${getChainPath(formFieldConfig.field)}.${ite.data.field}` + } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { + return ite?.data?.field && `${ite.data.field}` + } + return '' + }).filter(ite=>ite) + this.dependentFieldsArr = dependentFieldsArr + console.log('this.dependentFieldsArr--formStep', this.dependentFieldsArr); + } + if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue })) { this.formFieldsMounted[formFieldIndex] = false return null } @@ -684,14 +697,13 @@ export default class FormStep extends Step { // ts对clas if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { status = 'normal' } - const fieldPathArr = formFieldConfig.field.split('.') const renderData = { key: formFieldIndex, label: formFieldConfig.label, status, message: formData[formFieldIndex]?.message || '', - extra: StatementHelper(formFieldConfig.extra, { data: this.props.data, step: this.props.step }), + extra: StatementHelper(formFieldConfig.extra, { data: this.props.data, step: formValue }), required: getBoolean(formFieldConfig.required), layout, visitable: display, @@ -710,19 +722,18 @@ export default class FormStep extends Step { // ts对clas record={cloneDeep(formValue)} form={this} data={cloneDeep(data)} - step={step} - // stepValue={cloneDeep(formValue)} + // step={step} + step={cloneDeep(formValue)} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} onValueSet={async (path, value, validation) => await this.handleValueSet(formFieldIndex, path, value, validation)} - // onDidMountSet 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)} - path={getChainPath(formFieldIndex, formFieldConfig.field)} + path={formFieldConfig.field} /> ) } diff --git a/src/steps/skip/index.tsx b/src/steps/skip/index.tsx index 955b549..1579c48 100644 --- a/src/steps/skip/index.tsx +++ b/src/steps/skip/index.tsx @@ -52,11 +52,11 @@ export default class SkipStep extends Step { } break case 'data': - if (data && data[step]) { + if (data && step) { if (defaultField) { - formDefault = getValue(data[step], defaultField) + formDefault = getValue(step, defaultField) } else { - formDefault = data[step] + formDefault = step } } break diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 18f421e..85ebdc1 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -477,7 +477,7 @@ export default class TableStep extends Step { pageAuth } = this.state - let getDate = field ? getValue(data[step], field) : data[step] + let getDate = field ? getValue(step, field) : step if (Object.prototype.toString.call(getDate) !== '[object Array]') { getDate = [] } @@ -565,9 +565,9 @@ export default class TableStep extends Step { } if (pagination && pagination.mode === 'server') { - const paginationCurrent = Number((pagination.current === undefined || pagination.current === '') ? data[step] : get(data[step], pagination.current, 1)) - const paginationPageSize = Number((pagination.pageSize === undefined || pagination.pageSize === '') ? data[step] : get(data[step], pagination.pageSize, 10)) - const paginationTotal = Number((pagination.total === undefined || pagination.total === '') ? data[step] : get(data[step], pagination.total, 0)) + const paginationCurrent = Number((pagination.current === undefined || pagination.current === '') ? step : get(step, pagination.current, 1)) + const paginationPageSize = Number((pagination.pageSize === undefined || pagination.pageSize === '') ? step : get(step, pagination.pageSize, 10)) + const paginationTotal = Number((pagination.total === undefined || pagination.total === '') ? step : get(step, pagination.total, 0)) props.pagination = { current: Number.isNaN(paginationCurrent) ? 1 : paginationCurrent, diff --git a/src/util/condition.ts b/src/util/condition.ts index 7d7542b..edd3016 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,4 +1,6 @@ -import { set, cloneDeep, template } from "lodash" +// import { set, cloneDeep, template } from "lodash" +import { template } from "lodash" +import { cloneDeep } from '../util/produce' import { ParamConfig } from "../interface"; import ParamHelper from "./param"; @@ -22,7 +24,7 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { +export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; } }): boolean { if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { @@ -36,7 +38,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, if (param.field === '') { statementParams = value === undefined ? 'undefined' : JSON.stringify(value) } else { - set(statementParams, param.field, value === undefined ? 'undefined' : JSON.stringify(value)) + statementParams = cloneDeep(statementParams, 'set', param.field, value === undefined ? 'undefined' : JSON.stringify(value)) } } }) @@ -87,7 +89,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, if (param.field === '') { statementParams = ParamHelper(param.data, cloneDeep(datas)) } else { - set(statementParams, param.field, ParamHelper(param.data, cloneDeep(datas))) + statementParams = cloneDeep(statementParams, 'set', param.field, ParamHelper(param.data, cloneDeep(datas))) } } }) diff --git a/src/util/interface.ts b/src/util/interface.ts index 5e4783b..58ecba1 100644 --- a/src/util/interface.ts +++ b/src/util/interface.ts @@ -1,4 +1,6 @@ -import { isEqual, cloneDeep, template, get, set, merge } from "lodash" +// import { isEqual, cloneDeep, template, get, set, merge } from "lodash" +import { isEqual, template, get, merge } from "lodash" +import { cloneDeep } from '../util/produce' import axios, { AxiosRequestConfig } from 'axios' import { ParamConfig } from "../interface"; import ParamHelper from "./param"; @@ -96,7 +98,7 @@ export default class InterfaceHelper { public request ( config: InterfaceConfig, source: any, - datas: { record?: object, data: object[], step: number }, + datas: { record?: object, data: object[], step: { [field: string]: any; } }, option?: { loadDomain?: (domain: string) => Promise extra_data?: { params?: any, data?: any } @@ -112,7 +114,7 @@ export default class InterfaceHelper { if (param.field === '') { urlParams = ParamHelper(param.data, datas) } else { - set(urlParams, param.field, ParamHelper(param.data, datas)) + urlParams = cloneDeep(urlParams, 'set', param.field, ParamHelper(param.data, datas)) } } }) @@ -145,7 +147,7 @@ export default class InterfaceHelper { if (param.field === '') { params = ParamHelper(param.data, datas) } else { - set(params, param.field, ParamHelper(param.data, datas)) + params = cloneDeep(params, 'set', param.field, ParamHelper(param.data, datas)) } } }) @@ -173,7 +175,7 @@ export default class InterfaceHelper { if (param.field === '') { data = ParamHelper(param.data, datas) } else { - set(data, param.field, ParamHelper(param.data, datas)) + data = cloneDeep(data, 'set', param.field, ParamHelper(param.data, datas)) } } }) @@ -252,7 +254,7 @@ export default class InterfaceHelper { if (field === undefined || field === '') { content = value } else { - set(content, field, value) + content = cloneDeep(content, 'set', field, value) } } this._response = content diff --git a/src/util/operation.tsx b/src/util/operation.tsx index 3f9f3b9..f4bf008 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -1,6 +1,7 @@ import React from 'react'; import queryString from 'query-string'; -import { set } from "lodash"; +// import { set } from "lodash"; +import { cloneDeep } from '../util/produce' import { ParamConfig } from "../interface"; import { CCMSConfig, CCMSProps } from "../main"; import { getParam } from "./value"; @@ -51,7 +52,7 @@ type CCMSOperationConfig = CCMSPopupOperationConfig | CCMSRedirectOperationConfi interface OperationHelperProps { config?: OperationConfig, - datas: { record?: object, data: object[], step: number }, + datas: { record?: object, data: object[], step: { [field: string]: any; } }, checkPageAuth: (pageID: any) => Promise, loadPageURL: (pageID: any) => Promise, loadPageFrameURL: (pageID: any) => Promise, @@ -100,16 +101,16 @@ export default class OperationHelper extends React.Component { if (config.type === 'ccms') { - const sourceData = {} + let sourceData = {} if (config.params === undefined) { for (const [field, param] of Object.entries(config.data || {})) { const value = getParam(param, datas) - set(sourceData, field, value) + sourceData = cloneDeep(sourceData, 'set', field, value) } } else { for (const {field, data} of config.params) { const value = getParam(data, datas) - set(sourceData, field, value) + sourceData = cloneDeep(sourceData, 'set', field, value) } } if (config.mode === 'popup' || config.mode === 'invisible') { diff --git a/src/util/param.ts b/src/util/param.ts index cbe4e5a..867187b 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -1,8 +1,8 @@ -import { get, set } from "lodash" +import { get } from "lodash" import qs from "query-string" import { ParamConfig } from "../interface"; -export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: number }) { // step--> stepValue +export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: any } }) { // step--> stepValue switch (config.source) { case 'record': if (datas.record) { @@ -14,11 +14,11 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj } break case 'data': - if (datas.data[datas.step]) { + if (datas.step) { if (config.field === '') { - return datas.data[datas.step] + return datas.step } else { - return get(datas.data[datas.step], config.field) //return get(stepValue, config.field) + return get(datas.step, config.field) //return get(step, config.field) } } break diff --git a/src/util/produce.tsx b/src/util/produce.tsx index 9a75f7a..98f5159 100644 --- a/src/util/produce.tsx +++ b/src/util/produce.tsx @@ -8,6 +8,12 @@ type FormData = { status: 'normal' | 'error' | 'loading', message?: string, nam type FormDataList = { status: 'normal' | 'error' | 'loading', message?: string }[][] type Data = any[] type Data_ = Data | FormData | FormValue | FormDataList + +/** + * setAutoFreeze + * 默认为true, 防止外部修改,维护数据不可变 + * 为false 可以修改数据源 + */ setAutoFreeze(false) /** @@ -29,9 +35,6 @@ setAutoFreeze(false) case 'set': return lodash.set(draft, path, value) break - // case 'get': - // return lodash.get(draft, path, value) - // break case 'push': return lodash.concat(draft, value) break diff --git a/src/util/statement.ts b/src/util/statement.ts index 81ea1e5..61f95fa 100644 --- a/src/util/statement.ts +++ b/src/util/statement.ts @@ -1,4 +1,6 @@ -import { set, cloneDeep, template } from "lodash" +// import { set, cloneDeep, template } from "lodash" +import { template } from "lodash" +import { cloneDeep } from '../util/produce' import { ParamConfig } from "../interface"; import ParamHelper from "./param"; @@ -7,7 +9,7 @@ export interface StatementConfig { params: { field: string, data: ParamConfig }[] } -export default function StatementHelper(config: StatementConfig | undefined, datas: { record?: object, data: object[], step: number }): string { +export default function StatementHelper(config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }}): string { if (config === undefined || config.statement === undefined || config.statement === '') { return '' } else { @@ -19,7 +21,7 @@ export default function StatementHelper(config: StatementConfig | undefined, dat if (param.field === '') { statementParams = ParamHelper(param.data, cloneDeep(datas)) } else { - set(statementParams, param.field, ParamHelper(param.data, cloneDeep(datas))) + statementParams = cloneDeep(statementParams, 'set', param.field, ParamHelper(param.data, cloneDeep(datas))) } } }) diff --git a/src/util/value.ts b/src/util/value.ts index b9d9e4c..87e6014 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -51,14 +51,14 @@ export const getParam = ( datas: { record?: object data: object[] - step: number + step: { [field: string]: any; } } ) => { switch (config.source) { case 'record': return getValue(datas.record || {}, config.field) case 'data': - return getValue(datas.data[datas.step], config.field) + return getValue(datas.step, config.field) case 'source': return getValue(datas.data[0] || {}, config.field) case 'step': @@ -79,7 +79,7 @@ export const getParamText = ( datas: { record?: object data: object[] - step: number + step: { [field: string]: any; } } ) => { for (const { field, data } of params) { -- Gitee From 0eeff92928fc49b2e764dbb14959387e95262405 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 17 Jan 2022 18:04:50 +0800 Subject: [PATCH 009/164] =?UTF-8?q?feat:=20produce=E5=86=99=E6=B3=95?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 96 ++++++++---------- .../formFields/importSubform/index.tsx | 26 ++--- src/steps/form/index.tsx | 50 ++++------ src/util/condition.ts | 10 +- src/util/interface.ts | 16 +-- src/util/operation.tsx | 6 +- src/util/produce.tsx | 99 ++++++++++++------- src/util/statement.ts | 6 +- 8 files changed, 159 insertions(+), 150 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 3fd3abf..d3e15a5 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -4,7 +4,7 @@ import getALLComponents from '../' // import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' // import { cloneDeep } from 'lodash' import { getValue, getBoolean, getChainPath } from '../../../util/value' -import { cloneDeep, setValue , sort, splice} from '../../../util/produce' +import { set, setValue , sort, splice} from '../../../util/produce' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' @@ -131,7 +131,7 @@ export default class FormField extends Field { if (!this.formFieldsMountedList[index]) { - // this.formFieldsMountedList[index] = [] - cloneDeep(this.formFieldsMountedList, 'set', `[${index}]`, []) + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) } if (this.formFieldsMountedList[index][formFieldIndex]) { return true } // this.formFieldsMountedList[index][formFieldIndex] = true - this.formFieldsMountedList = cloneDeep(this.formFieldsMountedList, 'set', `[${index}][${formFieldIndex}]`, true) + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, true) - let formDataList = cloneDeep(this.state.formDataList) - if (!formDataList[index]) formDataList = cloneDeep(formDataList, 'set', `[${index}]`, []) + let formDataList = this.state.formDataList + if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) if (this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex]) { const formField = this.formFieldsList[index][formFieldIndex] @@ -247,9 +246,9 @@ export default class FormField extends Field { const index = (this.props.value || []).length - const formDataList = cloneDeep(this.state.formDataList, 'set', `[${index}]`, []) + const formDataList = set(this.state.formDataList, `[${index}]`, []) this.setState({ formDataList }) - // this.formFieldsList[index] = [] - this.formFieldsList = cloneDeep(this.formFieldsList, 'set', `${index}`, []) - // this.formFieldsMountedList[index] = [] - this.formFieldsMountedList = cloneDeep(this.formFieldsMountedList, 'set', `${index}`, []) + this.formFieldsList = set(this.formFieldsList, `${index}`, []) + this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, []) - await this.props.onValueListAppend('', this.props.config.initialValues === undefined ? {} : cloneDeep(this.props.config.initialValues), true) + await this.props.onValueListAppend('', this.props.config.initialValues === undefined ? {} : this.props.config.initialValues, true) } handleRemove = async (index: number) => { - // const formDataList = cloneDeep(this.state.formDataList) - const formDataList = splice(this.state.formDataList, index, 1) + const formDataList = splice(this.state.formDataList, '', index, 1) this.setState({ - //@ts-ignore formDataList }) - // this.formFieldsList.splice(index, 1) - //@ts-ignore - this.formFieldsList = splice(this.formFieldsList,index, 1) - // this.formFieldsMountedList.splice(index, 1) - //@ts-ignore - this.formFieldsMountedList = splice(this.formFieldsMountedList,index, 1) + this.formFieldsList = splice(this.formFieldsList, '', index, 1) + this.formFieldsMountedList = splice(this.formFieldsMountedList, '', index, 1) await this.props.onValueListSplice('', index, 1, true) } handleSort = async (index: number, sortType: 'up' | 'down') => { - var list = cloneDeep(this.state.formDataList) - let formDataList = sort(list, index, sortType) + var list = this.state.formDataList + let formDataList = sort(list, '', index, sortType) this.setState({ - //@ts-ignore formDataList: formDataList }) - //@ts-ignore - this.formFieldsList = sort(this.formFieldsList, index, sortType) - //@ts-ignore - this.formFieldsMountedList = sort(this.formFieldsMountedList, index, sortType) + this.formFieldsList = sort(this.formFieldsList,'', index, sortType) + this.formFieldsMountedList = sort(this.formFieldsMountedList, '', index, sortType) await this.props.onValueListSort('', index, sortType, true) } @@ -343,11 +331,11 @@ export default class FormField extends Field | null) => { if (fieldRef) { - if (!this.formFieldsList[index]) this.formFieldsList = cloneDeep(this.formFieldsList, 'set', `[${index}]`, []) + if (!this.formFieldsList[index]) this.formFieldsList = set(this.formFieldsList, `[${index}]`, []) // this.formFieldsList[index][fieldIndex] = fieldRef - this.formFieldsList = cloneDeep(this.formFieldsList, 'set', `[${index}][${fieldIndex}]`, fieldRef) + this.formFieldsList = set(this.formFieldsList, `[${index}][${fieldIndex}]`, fieldRef) this.handleMount(index, fieldIndex) } }} form={this.props.form} formLayout={formLayout} - value={cloneDeep(getValue(value[index], formFieldConfig.field))} - record={cloneDeep(value[index])} - step={cloneDeep(this.props.step)} - data={cloneDeep(data)} + value={getValue(value[index], formFieldConfig.field)} + record={value[index]} + step={this.props.step} + data={data} // step={step} config={formFieldConfig} onChange={(value: any) => this.handleChange(index, fieldIndex, value)} diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index eecdbc4..0442aa7 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -6,7 +6,7 @@ import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' // import { cloneDeep } from 'lodash' -import { cloneDeep, setValue } from '../../../util/produce' +import { setValue } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' @@ -116,7 +116,7 @@ export default class ImportSubformField extends Field { formData[formFieldIndex] = { status: 'normal' } - return { formData: cloneDeep(formData) } + return { formData: formData } }) } else { await this.setState(({ formData }) => { formData[formFieldIndex] = { status: 'error', message: validation[0].message } - return { formData: cloneDeep(formData) } + return { formData: formData } }) } } @@ -219,7 +219,7 @@ export default class ImportSubformField extends Field { await this.handleChange(formFieldIndex, value) }} diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index be6c385..929b021 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -6,8 +6,8 @@ import getALLComponents from '../../components/formFields' import { getValue, listItemMove, getBoolean, getChainPath } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' -import { get, set, unset, update , isEqual } from 'lodash' -import { cloneDeep, splice, sort, setValue } from '../../util/produce' +import { get, unset, update , isEqual } from 'lodash' +import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' @@ -235,7 +235,7 @@ export default class FormStep extends Step { // ts对clas await this.setState({ ready: true, formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) // 表单初始化结束,展示表单界面。 @@ -273,7 +273,7 @@ export default class FormStep extends Step { // ts对clas await this.setState({ formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) } @@ -321,7 +321,7 @@ export default class FormStep extends Step { // ts对clas } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } @@ -369,7 +369,7 @@ export default class FormStep extends Step { // ts对clas await this.setState({ formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) if (this.props.onChange) { this.props.onChange(this.formValue) @@ -386,8 +386,8 @@ export default class FormStep extends Step { // ts对clas this.props.handleFormValue({path: fullPath, value}) } - // set(this.formValue, fullPath, value) - this.formValue = cloneDeep(this.formValue, 'set', fullPath, value) + + this.formValue = set(this.formValue, fullPath, value) console.log('test--->set--', this.formValue, fullPath, value); this.setState(({formValue})=>({ formValue: this.formValue @@ -406,7 +406,7 @@ export default class FormStep extends Step { // ts对clas console.log('form set data', this.formData) await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -431,7 +431,7 @@ export default class FormStep extends Step { // ts对clas } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -441,11 +441,7 @@ export default class FormStep extends Step { // ts对clas if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - let list = get(this.formValue, fullPath, []) - console.log('list---', list, value); - let cloneList = cloneDeep(list,'push', fullPath, value) - // set(this.formValue, fullPath, list) - this.formValue = cloneDeep(this.formValue, 'set', fullPath, cloneList) + this.formValue = push(this.formValue, fullPath, value) //向this.formValue的fullPath下的值添加value this.setState({ formValue: this.formValue }) @@ -460,7 +456,7 @@ export default class FormStep extends Step { // ts对clas } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -470,10 +466,7 @@ export default class FormStep extends Step { // ts对clas if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - const list = get(this.formValue, fullPath, []) - const cloneList = splice(list, index, count) - // set(this.formValue, fullPath, list) - this.formValue = cloneDeep(this.formValue, 'set', fullPath, cloneList) + this.formValue = splice(this.formValue, fullPath, index, count) this.setState({ formValue: this.formValue }) @@ -488,7 +481,7 @@ export default class FormStep extends Step { // ts对clas } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -498,10 +491,7 @@ export default class FormStep extends Step { // ts对clas if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - // const list = listItemMove(get(this.formValue, fullPath, []), index, sortType) - const list = sort(get(this.formValue, fullPath, []), index, sortType) - // set(this.formValue, fullPath, list) - this.formValue = cloneDeep(this.formValue, 'set', fullPath, list) + this.formValue = sort(this.formValue, fullPath, index, sortType) this.setState({ formValue: this.formValue }) @@ -516,7 +506,7 @@ export default class FormStep extends Step { // ts对clas } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -718,12 +708,12 @@ export default class FormStep extends Step { // ts对clas } }} formLayout={layout} - value={formFieldConfig.field !== undefined ? cloneDeep(getValue(formValue, formFieldConfig.field)) : undefined} - record={cloneDeep(formValue)} + value={formFieldConfig.field !== undefined ? getValue(formValue, formFieldConfig.field) : undefined} + record={formValue} form={this} - data={cloneDeep(data)} + data={data} // step={step} - step={cloneDeep(formValue)} + step={formValue} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} onValueSet={async (path, value, validation) => await this.handleValueSet(formFieldIndex, path, value, validation)} diff --git a/src/util/condition.ts b/src/util/condition.ts index edd3016..633e565 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,6 +1,6 @@ // import { set, cloneDeep, template } from "lodash" import { template } from "lodash" -import { cloneDeep } from '../util/produce' +import { set } from '../util/produce' import { ParamConfig } from "../interface"; import ParamHelper from "./param"; @@ -34,11 +34,11 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { - const value = ParamHelper(param.data, cloneDeep(datas)) + const value = ParamHelper(param.data, datas) if (param.field === '') { statementParams = value === undefined ? 'undefined' : JSON.stringify(value) } else { - statementParams = cloneDeep(statementParams, 'set', param.field, value === undefined ? 'undefined' : JSON.stringify(value)) + statementParams = set(statementParams, param.field, value === undefined ? 'undefined' : JSON.stringify(value)) } } }) @@ -87,9 +87,9 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - statementParams = ParamHelper(param.data, cloneDeep(datas)) + statementParams = ParamHelper(param.data,datas) } else { - statementParams = cloneDeep(statementParams, 'set', param.field, ParamHelper(param.data, cloneDeep(datas))) + statementParams = set(statementParams, param.field, ParamHelper(param.data, datas)) } } }) diff --git a/src/util/interface.ts b/src/util/interface.ts index 58ecba1..8e1d80b 100644 --- a/src/util/interface.ts +++ b/src/util/interface.ts @@ -1,6 +1,6 @@ // import { isEqual, cloneDeep, template, get, set, merge } from "lodash" import { isEqual, template, get, merge } from "lodash" -import { cloneDeep } from '../util/produce' +import { set } from '../util/produce' import axios, { AxiosRequestConfig } from 'axios' import { ParamConfig } from "../interface"; import ParamHelper from "./param"; @@ -114,7 +114,7 @@ export default class InterfaceHelper { if (param.field === '') { urlParams = ParamHelper(param.data, datas) } else { - urlParams = cloneDeep(urlParams, 'set', param.field, ParamHelper(param.data, datas)) + urlParams = set(urlParams, param.field, ParamHelper(param.data, datas)) } } }) @@ -147,7 +147,7 @@ export default class InterfaceHelper { if (param.field === '') { params = ParamHelper(param.data, datas) } else { - params = cloneDeep(params, 'set', param.field, ParamHelper(param.data, datas)) + params = set(params, param.field, ParamHelper(param.data, datas)) } } }) @@ -175,7 +175,7 @@ export default class InterfaceHelper { if (param.field === '') { data = ParamHelper(param.data, datas) } else { - data = cloneDeep(data, 'set', param.field, ParamHelper(param.data, datas)) + data = set(data, param.field, ParamHelper(param.data, datas)) } } }) @@ -197,10 +197,10 @@ export default class InterfaceHelper { ) { return this._response } else { - this._config = cloneDeep(config) + this._config = config this._url = url - this._params = cloneDeep(params) - this._data = cloneDeep(data) + this._params = params + this._data = data const request: AxiosRequestConfig = { url, @@ -254,7 +254,7 @@ export default class InterfaceHelper { if (field === undefined || field === '') { content = value } else { - content = cloneDeep(content, 'set', field, value) + content = set(content, field, value) } } this._response = content diff --git a/src/util/operation.tsx b/src/util/operation.tsx index f4bf008..05a63ff 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -1,7 +1,7 @@ import React from 'react'; import queryString from 'query-string'; // import { set } from "lodash"; -import { cloneDeep } from '../util/produce' +import { set } from '../util/produce' import { ParamConfig } from "../interface"; import { CCMSConfig, CCMSProps } from "../main"; import { getParam } from "./value"; @@ -105,12 +105,12 @@ export default class OperationHelper extends React.Component { - if (!operationType) return current // 注意这里没有深拷贝,只有在修改时才使用immer的api - let target = produce(current, (draft: any) => { - if (!path) path='' - // const method = lodash[operationType] - // @ts-ignore - // method(draft, path, value) // 写return method(draft, path, value)会卡顿 - switch (operationType) { - case 'set': - return lodash.set(draft, path, value) - break - case 'push': - return lodash.concat(draft, value) - break - } +export const set = (current: any, path?: string, value?: any) => { + let target = produce(current, (draft: any) => { + if (path) { + return lodash.set(draft, path, value) + } + return draft + }) + return target +} +/** + * current指定路径下的数组添加元素 + * @param current + * @param path + * @param value + * @returns + */ +export const push = (current: any, path: string = '', value?: any) => { + let list + const target = produce(current, (draft: any) => { + if (!path) list = draft // path为空时,向current根路径push + else list = lodash.get(draft, path, []) + console.log('error', lodash.concat(list, value)); + list.push(value) }) return target } -export const splice = (current: any, index:number, count:number) => { - let target = produce(current, (draft: any)=>{ - draft.splice(index, count) +/** + * current指定路径下的数组删除元素 + * @param current + * @param path + * @param index + * @param count + * @returns + */ +export const splice = (current: any, path: string='', index: number, count: number) => { + let list + const target = produce(current, (draft: any) => { + if (!path) list = draft + else list = lodash.get(draft, path, []) + list.splice(index, count) }) return target } -export const sort = (current: any, index: number, sortType: 'up' | 'down') => { - let target = produce(current, (draft: any)=>{ - return listItemMove(draft, index, sortType) +/** + * 数组排序 + * @param current + * @param path + * @param index + * @param sortType + * @returns + */ +export const sort = (current: any, path: string='', index: number, sortType: 'up' | 'down') => { + let list + const target = produce(current, (draft: any) => { + if (!path) list = draft + else list = lodash.get(draft, path, []) + listItemMove(list, index, sortType) }) return target } +/** + * lodash 递归合并来源对象的自身和继承的可枚举属性到目标对象 + * @param a 目标对象 + * @param b 来源对象 + * @returns + */ const merge = (a: any, b: any): any => { return lodash.assignInWith(a, b, (a, b) => { if (lodash.isUndefined(a) && lodash.isArray(b)) { @@ -73,7 +104,7 @@ const merge = (a: any, b: any): any => { } export const setValue = (obj: any, path: string = '', value: any) => { - let target = produce(obj, (draft: any) => { + let target = produce(obj, (draft: any) => { if (path === '') { if (Object.prototype.toString.call(value) === '[object Object]') { draft = merge(draft, value) diff --git a/src/util/statement.ts b/src/util/statement.ts index 61f95fa..73e59c5 100644 --- a/src/util/statement.ts +++ b/src/util/statement.ts @@ -1,6 +1,6 @@ // import { set, cloneDeep, template } from "lodash" import { template } from "lodash" -import { cloneDeep } from '../util/produce' +import { set } from '../util/produce' import { ParamConfig } from "../interface"; import ParamHelper from "./param"; @@ -19,9 +19,9 @@ export default function StatementHelper(config: StatementConfig | undefined, dat config.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - statementParams = ParamHelper(param.data, cloneDeep(datas)) + statementParams = ParamHelper(param.data, datas) } else { - statementParams = cloneDeep(statementParams, 'set', param.field, ParamHelper(param.data, cloneDeep(datas))) + statementParams = set(statementParams, param.field, ParamHelper(param.data, datas)) } } }) -- Gitee From 7be7d6e9b54caa1dc9055489ceeaeb09620210f4 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 18 Jan 2022 18:56:13 +0800 Subject: [PATCH 010/164] =?UTF-8?q?feat:=E6=9B=BF=E6=8D=A2form=E3=80=81fil?= =?UTF-8?q?ter=E6=AD=A5=E9=AA=A4=E6=B7=B1=E6=8B=B7=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/any/index.tsx | 7 +- src/components/formFields/custom/index.tsx | 6 +- src/components/formFields/form/index.tsx | 12 +- src/components/formFields/group/index.tsx | 55 ++++----- .../formFields/importSubform/index.tsx | 46 ++++---- src/components/formFields/object/index.tsx | 107 +++++++++--------- src/components/formFields/tabs/index.tsx | 73 ++++++------ src/steps/common.tsx | 8 +- src/steps/filter/index.tsx | 85 +++++++------- src/steps/form/index.tsx | 50 ++++---- src/steps/table/index.tsx | 6 +- src/util/produce.tsx | 29 ++--- 12 files changed, 245 insertions(+), 239 deletions(-) diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index a4a051d..5b2ea1e 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -1,6 +1,7 @@ import React, { ReactNode } from 'react' import { Field, FieldConfig, IField, FieldInterface } from '../common' +import { getChainPath } from '../../../util/value' import TextField from '../text' import * as _ from 'lodash' import NumberField from '../number' @@ -97,7 +98,7 @@ export default class AnyField extends Field : ( type === 'number' ? {}} @@ -116,7 +117,7 @@ export default class AnyField extends Field : {}} form={this.props.form} @@ -134,7 +135,7 @@ export default class AnyField extends Field ) })} diff --git a/src/components/formFields/custom/index.tsx b/src/components/formFields/custom/index.tsx index 492ef98..672607e 100644 --- a/src/components/formFields/custom/index.tsx +++ b/src/components/formFields/custom/index.tsx @@ -2,7 +2,7 @@ import React, { RefObject } from 'react' import { Field, FieldConfig, IField, FieldInterface, FieldProps, FieldError } from '../common' import { loadMicroApp, MicroApp } from 'qiankun' import moment from 'moment' -import { cloneDeep } from 'lodash' +// import { cloneDeep } from 'lodash' export interface CustomFieldConfig extends FieldConfig, FieldInterface { type: 'custom' @@ -53,7 +53,7 @@ export default class CustomField extends Field imple this.customField.update({ value: this.props.value, record: this.props.record, - data: cloneDeep(this.props.data), + data: this.props.data, form: this.props.form, step: this.props.step, config: this.props.config, @@ -82,7 +82,7 @@ export default class CustomField extends Field imple props: { value: this.props.value, record: this.props.record, - data: cloneDeep(this.props.data), + data: this.props.data, form: this.props.form, step: this.props.step, config: this.props.config, diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d3e15a5..1709298 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -131,7 +131,7 @@ export default class FormField extends Field { - formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } - return { formData: cloneDeep(formData) } + formData = set(formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) + return { formData: formData } }) } else { await this.setState(({ formData }) => { - formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } - return { formData: cloneDeep(formData) } + formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + return { formData: formData } }) } } @@ -168,11 +169,11 @@ export default class GroupField extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { - this.formFieldsMounted[formFieldIndex] = false + this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } let hidden: boolean = true @@ -325,7 +326,7 @@ export default class GroupField extends Field | null) => { if (formField) { - this.formFields[formFieldIndex] = formField + this.formFields = set(this.formFields, `[${formFieldIndex}]`, formField) this.handleMount(formFieldIndex) } }} @@ -333,7 +334,7 @@ export default class GroupField extends Field { await this.handleChange(formFieldIndex, value) }} diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 0442aa7..9514d35 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -6,7 +6,7 @@ import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' // import { cloneDeep } from 'lodash' -import { setValue } from '../../../util/produce' +import { set, setValue } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' @@ -116,7 +116,7 @@ export default class ImportSubformField extends Field { - formData[formFieldIndex] = { status: 'normal' } + formData = set(formData, `[${formFieldIndex}]`, { status: 'normal' }) return { formData: formData } }) } else { await this.setState(({ formData }) => { - formData[formFieldIndex] = { status: 'error', message: validation[0].message } + formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) return { formData: formData } }) } @@ -219,11 +219,11 @@ export default class ImportSubformField extends Field | null) => { if (formField) { - this.formFields[formFieldIndex] = formField + this.formFields = set(this.formFields, `[${formFieldIndex}]`, formField) this.handleMount(formFieldIndex) } }} diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index a68d174..5025b52 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -2,8 +2,9 @@ import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from import getALLComponents from '../' import React from 'react' import ConditionHelper from '../../../util/condition' -import { cloneDeep } from 'lodash' -import { getValue, setValue, getBoolean, getChainPath } from '../../../util/value' +// import { cloneDeep } from 'lodash' +import { set, setValue } from '../../../util/produce' +import { getValue, getBoolean, getChainPath } from '../../../util/value' import StatementHelper from '../../../util/statement' export interface ObjectFieldConfig extends FieldConfig { @@ -105,10 +106,10 @@ export default class ObjectField extends Field extends Field extends Field { if (!this.formFieldsMountedList[key]) { - this.formFieldsMountedList[key] = [] + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${key}]`, []) } if (this.formFieldsMountedList[key][formFieldIndex]) { return true } - this.formFieldsMountedList[key][formFieldIndex] = true + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${key}][${formFieldIndex}]`, true) if (this.formFieldsList[key] && this.formFieldsList[key][formFieldIndex]) { const formField = this.formFieldsList[key][formFieldIndex] @@ -164,15 +165,15 @@ export default class ObjectField extends Field { - if (!formDataList[key]) formDataList[key] = [] - formDataList[key][formFieldIndex] = { status: 'normal' } - return { formDataList: cloneDeep(formDataList) } + if (!formDataList[key]) formDataList= set(formDataList, `[${key}]`, []) + formDataList = set(formDataList, `[${key}][${formFieldIndex}]`, { status: 'normal' }) + return { formDataList: formDataList } }) } else { await this.setState(({ formDataList }) => { - if (!formDataList[key]) formDataList[key] = [] - formDataList[key][formFieldIndex] = { status: 'error', message: validation[0].message } - return { formDataList: cloneDeep(formDataList) } + if (!formDataList[key]) formDataList= set(formDataList, `[${key}]`, []) + formDataList = set(formDataList, `[${key}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) + return { formDataList: formDataList } }) } } @@ -190,11 +191,11 @@ export default class ObjectField extends Field { formDataList[key] = [] - return { formDataList: cloneDeep(formDataList) } + return { formDataList: formDataList } }) this.props.onValueSet(key, {}, true) @@ -203,27 +204,27 @@ export default class ObjectField extends Field { - delete this.formFieldsList[key] - delete this.formFieldsMountedList[key] + this.formFieldsList = set(this.formFieldsList, `${this.formFieldsList[key]}`) + this.formFieldsMountedList = set(this.formFieldsMountedList, `${this.formFieldsMountedList[key]}`) await this.setState(({ formDataList }) => { - delete formDataList[key] - return { formDataList: cloneDeep(formDataList) } + formDataList = set(formDataList, `${formDataList[key]}`) + return { formDataList: formDataList } }) this.props.onValueUnset(key, true) } handleChangeKey = async (prev: string, next: string) => { - this.formFieldsList[next] = this.formFieldsList[prev] - delete this.formFieldsList[prev] + this.formFieldsList = set(this.formFieldsList, `[${next}]`, this.formFieldsList[prev]) + this.formFieldsList = set(this.formFieldsList, `${this.formFieldsList[prev]}`) - this.formFieldsMountedList[next] = this.formFieldsMountedList[prev] - delete this.formFieldsMountedList[prev] + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${next}]`, this.formFieldsMountedList[prev]) + this.formFieldsMountedList = set(this.formFieldsMountedList, `${this.formFieldsMountedList[prev]}`) await this.setState(({ formDataList }) => { - formDataList[next] = formDataList[prev] - delete formDataList[prev] - return { formDataList: cloneDeep(formDataList) } + formDataList = set(formDataList, `[${next}]`, formDataList[prev]) + formDataList = set(formDataList, `${formDataList[prev]}`) + return { formDataList: formDataList } }) this.props.onValueSet(next, this.props.value[prev], true) @@ -242,17 +243,17 @@ export default class ObjectField extends Field { - // if (!formDataList[key]) formDataList[key] = [] - // formDataList[key][formFieldIndex] = { value, status: 'normal' } + // if (!formDataList[key]) formDataList = set(formDataList, `[${key}]`, []) + // formDataList = set(formDataList, `[${key}][${formFieldIndex}]`, { status: 'normal' }) // return { formDataList: cloneDeep(formDataList) } // }) // } else { // await this.setState(({ formDataList }) => { - // if (!formDataList[key]) formDataList[key] = [] - // formDataList[key][formFieldIndex] = { value, status: 'error', message: validation[0].message } + // if (!formDataList[key]) formDataList = set(formDataList, `[${key}]`, []) + // formDataList = set(formDataList, `[${key}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) // return { formDataList: cloneDeep(formDataList) } // }) // } @@ -265,11 +266,11 @@ export default class ObjectField extends Field extends Field extends Field extends Field extends Field extends Field await this.handleRemove(key), children: (Array.isArray(this.props.config.fields) ? this.props.config.fields : []).map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { - if (!this.formFieldsMountedList[key]) this.formFieldsMountedList[key] = [] - this.formFieldsMountedList[key][formFieldIndex] = false + if (!this.formFieldsMountedList[key]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${key}]`, []) + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${key}][${formFieldIndex}]`, false) return null } let hidden: boolean = true @@ -459,8 +460,8 @@ export default class ObjectField extends Field | null) => { if (formField) { - if (!this.formFieldsList[key]) this.formFieldsList[key] = [] - this.formFieldsList[key][formFieldIndex] = formField + if (!this.formFieldsList[key]) this.formFieldsList = set(this.formFieldsList, `[${key}]`, []) + this.formFieldsList = set(this.formFieldsList, `[${key}][${formFieldIndex}]`, formField) this.handleMount(key, formFieldIndex) } }} @@ -468,7 +469,7 @@ export default class ObjectField extends Field this.handleChange(key, formFieldIndex, value)} diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 72e98d6..1a286fb 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -2,8 +2,9 @@ import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from import getALLComponents from '../' import React from 'react' import ConditionHelper from '../../../util/condition' -import { cloneDeep } from 'lodash' -import { getValue, setValue, getBoolean, getChainPath } from '../../../util/value' +// import { cloneDeep } from 'lodash' +import { set, setValue } from '../../../util/produce' +import { getValue, getBoolean, getChainPath } from '../../../util/value' import StatementHelper from '../../../util/statement' export type TabsFieldConfig = TabsFieldConfig_Same | TabsFieldConfig_Diff @@ -114,7 +115,7 @@ export default class TabsField extends Field extends Field extends Field { - if (!formDataList[index]) formDataList[index] = [] - formDataList[index][formFieldIndex] = { status: 'normal' } - return { formDataList: cloneDeep(formDataList) } + if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) + formDataList= set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'normal' }) + return { formDataList: formDataList } }) } else { await this.setState(({ formDataList }) => { - if (!formDataList[index]) formDataList[index] = [] - formDataList[index][formFieldIndex] = { status: 'error', message: validation[0].message } - return { formDataList: cloneDeep(formDataList) } + if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) + formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) + return { formDataList: formDataList } }) } } @@ -212,12 +213,12 @@ export default class TabsField extends Field extends Field extends Field extends Field extends Field extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { - if (!this.formFieldsMountedList[index]) this.formFieldsMountedList[index] = [] - this.formFieldsMountedList[index][formFieldIndex] = false + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) return null } let hidden: boolean = true @@ -420,15 +421,15 @@ export default class TabsField extends Field | null) => { - if (!this.formFieldsList[index]) this.formFieldsList[index] = [] - this.formFieldsList[index][formFieldIndex] = formField + if (!this.formFieldsList[index]) this.formFieldsList = set(this.formFieldsList, `[${index}]`, []) + this.formFieldsList = set(this.formFieldsList, `[${index}][${formFieldIndex}]`, formField) this.handleMount(index, formFieldIndex) }} form={this.props.form} formLayout={this.props.formLayout} value={getValue(getValue(value, tab.field), formFieldConfig.field)} record={getValue(value, tab.field)} - data={cloneDeep(this.props.data)} + data={this.props.data} step={this.props.step} config={formFieldConfig} onChange={(value: any) => this.handleChange(index, formFieldIndex, value)} diff --git a/src/steps/common.tsx b/src/steps/common.tsx index d24543a..c76cbec 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -41,10 +41,10 @@ export interface StepProps { * 页面步骤基类 */ export default class Step extends React.Component, S> { - // static defaultProps = { // 暂时注释 - // config: { - // } - // }; + static defaultProps = { + config: { + } + }; stepPush = () => { this.props.onMount() diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 74562d7..6994b28 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -4,9 +4,10 @@ import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' -import { cloneDeep, get, set, unset } from 'lodash' +import { get } from 'lodash' +import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper from '../../util/condition' -import { getValue, setValue, listItemMove, getChainPath } from '../../util/value' +import { getValue, getChainPath } from '../../util/value' /** * 表单步骤配置文件格式定义 @@ -118,13 +119,13 @@ export default class FilterStep extends Step { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const value = (formFieldConfig.field === undefined || formFieldConfig.field === '') ? formDefault : get(formDefault, formFieldConfig.field) this.formValue = setValue(this.formValue, formFieldConfig.field, value) - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } } await this.setState({ formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) // 表单初始化结束,展示表单界面。 @@ -141,7 +142,7 @@ export default class FilterStep extends Step { return true } - this.formFieldsMounted[formFieldIndex] = true + this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, true) if (this.formFields[formFieldIndex]) { const formField = this.formFields[formFieldIndex] @@ -157,16 +158,16 @@ export default class FilterStep extends Step { if (value !== undefined) { const validation = await formField.validate(value) if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } } } } await this.setState({ formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) } @@ -198,7 +199,7 @@ export default class FilterStep extends Step { console.info('表单校验通过', data) await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) if (canSubmit && this.props.onSubmit) { @@ -235,16 +236,16 @@ export default class FilterStep extends Step { const validation = await formField.validate(value) if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } } } await this.setState({ formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) this.handleSubmit() @@ -263,14 +264,14 @@ export default class FilterStep extends Step { const validation = await formField.validate(value) if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } await this.setState({ formValue: this.formValue, - formData: cloneDeep(this.formData) + formData: this.formData }) if (this.props.onChange) { this.props.onChange(this.formValue) @@ -283,7 +284,7 @@ export default class FilterStep extends Step { if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - set(this.formValue, fullPath, value) + this.formValue = set(this.formValue, fullPath, value) this.setState({ formValue: this.formValue }) @@ -292,13 +293,13 @@ export default class FilterStep extends Step { } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -308,7 +309,8 @@ export default class FilterStep extends Step { if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - unset(this.formValue, fullPath) + // unset(this.formValue, fullPath) + this.formValue = set(this.formValue, fullPath) this.setState({ formValue: this.formValue }) @@ -317,13 +319,13 @@ export default class FilterStep extends Step { } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -333,9 +335,7 @@ export default class FilterStep extends Step { if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - const list = get(this.formValue, fullPath, []) - list.push(value) - set(this.formValue, fullPath, list) + this.formValue = push(this.formValue, fullPath, value) this.setState({ formValue: this.formValue }) @@ -344,13 +344,13 @@ export default class FilterStep extends Step { } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -360,9 +360,7 @@ export default class FilterStep extends Step { if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - const list = get(this.formValue, fullPath, []) - list.splice(index, count) - set(this.formValue, fullPath, list) + this.formValue = splice(this.formValue, fullPath, index, count) this.setState({ formValue: this.formValue }) @@ -371,13 +369,13 @@ export default class FilterStep extends Step { } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -386,8 +384,7 @@ export default class FilterStep extends Step { 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.formValue = sort(this.formValue, fullPath, index, sortType) this.setState({ formValue: this.formValue }) @@ -396,13 +393,13 @@ export default class FilterStep extends Step { } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal' } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) } await this.setState({ - formData: cloneDeep(this.formData) + formData: this.formData }) } } @@ -453,7 +450,7 @@ export default class FilterStep extends Step { resetText: this.props.config?.resetText?.replace(/(^\s*)|(\s*$)/g, ""), children: fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { - this.formFieldsMounted[formFieldIndex] = false + this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } let hidden: boolean = true @@ -488,7 +485,7 @@ export default class FilterStep extends Step { key={formFieldIndex} ref={(formField: Field | null) => { if (formFieldIndex !== null) { - this.formFields[formFieldIndex] = formField + this.formFields = set(this.formFields, `[${formFieldIndex}]`, formField) this.handleFormFieldMount(formFieldIndex) } }} @@ -496,9 +493,9 @@ export default class FilterStep extends Step { formLayout={'inline'} value={formFieldConfig.field !== undefined ? get(formValue, formFieldConfig.field) : undefined} record={formValue} - step={cloneDeep(formValue)} + step={formValue} // step={step} - data={cloneDeep(data)} + data={data} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} onValueSet={async (path, value, validation) => await this.handleValueSet(formFieldIndex, path, value, validation)} diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 929b021..83ef800 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -3,10 +3,10 @@ import { Field, FieldConfigs, FieldError } from '../../components/formFields/com import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' // import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' -import { getValue, listItemMove, getBoolean, getChainPath } from '../../util/value' +import { getValue, getBoolean, getChainPath } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' -import { get, unset, update , isEqual } from 'lodash' +import { get, unset } from 'lodash' import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' @@ -226,9 +226,9 @@ export default class FormStep extends Step { // ts对clas for (const formFieldIndex in formFieldsConfig) { const formFieldConfig = formFieldsConfig[formFieldIndex] const value = getValue(formDefault, formFieldConfig.field) - + this.formValue = setValue(this.formValue, formFieldConfig.field, value) - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } } @@ -246,7 +246,7 @@ export default class FormStep extends Step { // ts对clas if (this.formFieldsMounted[formFieldIndex]) { return true } - this.formFieldsMounted[formFieldIndex] = true + this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, true) if (this.formFields[formFieldIndex]) { const formField = this.formFields[formFieldIndex] @@ -262,9 +262,9 @@ export default class FormStep extends Step { // ts对clas if (value !== undefined) { const validation = await formField.validate(value) if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } } await formField.didMount() @@ -305,7 +305,7 @@ export default class FormStep extends Step { // ts对clas if (validation !== true) { console.warn('表单项中存在问题', value, formFieldConfig) - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) this.canSubmit = false } this.submitData = setValue(this.submitData, formFieldConfig.field, value) @@ -362,9 +362,9 @@ export default class FormStep extends Step { // ts对clas const validation = await formField.validate(value) if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } await this.setState({ @@ -398,9 +398,9 @@ export default class FormStep extends Step { // ts对clas } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } console.log('form set data', this.formData) @@ -416,7 +416,8 @@ export default class FormStep extends Step { // ts对clas if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - unset(this.formValue, fullPath) + // unset(this.formValue, fullPath) + this.formValue = set(this.formValue, fullPath) this.setState({ formValue: this.formValue }) @@ -425,9 +426,9 @@ export default class FormStep extends Step { // ts对clas } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } await this.setState({ @@ -440,6 +441,7 @@ export default class FormStep extends Step { // ts对clas const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` +console.log('step handleValueListAppend', fullPath, value); this.formValue = push(this.formValue, fullPath, value) //向this.formValue的fullPath下的值添加value this.setState({ @@ -450,9 +452,9 @@ export default class FormStep extends Step { // ts对clas } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } await this.setState({ @@ -475,9 +477,9 @@ export default class FormStep extends Step { // ts对clas } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } await this.setState({ @@ -500,9 +502,9 @@ export default class FormStep extends Step { // ts对clas } if (validation === true) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) } await this.setState({ @@ -659,7 +661,7 @@ export default class FormStep extends Step { // ts对clas console.log('this.dependentFieldsArr--formStep', this.dependentFieldsArr); } if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue })) { - this.formFieldsMounted[formFieldIndex] = false + this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } let hidden: boolean = true @@ -677,7 +679,7 @@ export default class FormStep extends Step { // ts对clas // 隐藏项同时打标录入数据并清空填写项 if (!hidden) { - this.formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } const FormField = this.getALLComponents(formFieldConfig.type) || Field @@ -703,7 +705,7 @@ export default class FormStep extends Step { // ts对clas key={formFieldIndex} ref={(formField: Field | null) => { if (formField !== null) { - this.formFields[formFieldIndex] = formField + this.formFields = set(this.formFields, `[${formFieldIndex}]`, formField) this.handleFormFieldMount(formFieldIndex) } }} diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 85ebdc1..9c05ee7 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -5,7 +5,7 @@ import getALLComponents, { ColumnConfigs } from '../../components/tableColumns' import Step, { StepConfig, StepProps } from '../common' import { ParamConfig } from '../../interface' import ColumnStyleComponent from './common/columnStyle' -import CCMS_123, { CCMSConfig } from '../../main' +import CCMS, { CCMSConfig } from '../../main' import { cloneDeep, get, set } from 'lodash' import InterfaceHelper, { InterfaceConfig } from '../../util/interface' import ConditionHelper, { ConditionConfig } from '../../util/condition' @@ -217,7 +217,7 @@ interface TableState { * 表格步骤组件 */ export default class TableStep extends Step { - CCMS_ = CCMS_123 + CCMS = CCMS getALLComponents = (type: any) => getALLComponents[type] interfaceHelper = new InterfaceHelper() /** @@ -660,7 +660,7 @@ export default class TableStep extends Step { }) } - const CCMS = this.CCMS_ + const CCMS = this.CCMS return ( diff --git a/src/util/produce.tsx b/src/util/produce.tsx index 40ea1f3..70651ad 100644 --- a/src/util/produce.tsx +++ b/src/util/produce.tsx @@ -19,10 +19,14 @@ type OperationType = 'set' | 'push' | 'splice' * @param value * @returns */ -export const set = (current: any, path?: string, value?: any) => { +export function set (current: any, path?: string, value?: any) { let target = produce(current, (draft: any) => { if (path) { - return lodash.set(draft, path, value) + if (arguments.length == 2) { // 移除对象路径的属性 参数改动时同步修改这块 + lodash.unset(draft, path) + } else { + return lodash.set(draft, path, value) + } } return draft }) @@ -36,12 +40,15 @@ export const set = (current: any, path?: string, value?: any) => { * @returns */ export const push = (current: any, path: string = '', value?: any) => { - let list const target = produce(current, (draft: any) => { - if (!path) list = draft // path为空时,向current根路径push - else list = lodash.get(draft, path, []) - console.log('error', lodash.concat(list, value)); - list.push(value) + let list = lodash.get(draft, path) + if (!Array.isArray(list)) { // 如果指定路径下不是数组类型 + var tempArr = [] + tempArr.push(value) + lodash.set(draft, path, tempArr) + } else { + list.push(value) + } }) return target } @@ -55,10 +62,8 @@ export const push = (current: any, path: string = '', value?: any) => { * @returns */ export const splice = (current: any, path: string='', index: number, count: number) => { - let list const target = produce(current, (draft: any) => { - if (!path) list = draft - else list = lodash.get(draft, path, []) + const list = lodash.get(draft, path, []) list.splice(index, count) }) return target @@ -73,10 +78,8 @@ export const splice = (current: any, path: string='', index: number, count: numb * @returns */ export const sort = (current: any, path: string='', index: number, sortType: 'up' | 'down') => { - let list const target = produce(current, (draft: any) => { - if (!path) list = draft - else list = lodash.get(draft, path, []) + const list = lodash.get(draft, path, []) listItemMove(list, index, sortType) }) return target -- Gitee From 3d5b69742d3d98c82100250ed842944c4538cf2b Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 19 Jan 2022 17:12:26 +0800 Subject: [PATCH 011/164] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0dependentFiel?= =?UTF-8?q?ds=E3=80=81onReportFields?= 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 | 14 ++++--- src/components/formFields/form/index.tsx | 33 ++++++++-------- src/components/formFields/group/index.tsx | 22 +++++++++-- .../formFields/importSubform/index.tsx | 39 ++++++++++--------- src/components/formFields/object/index.tsx | 18 ++++++++- src/components/formFields/tabs/index.tsx | 20 +++++++++- src/steps/filter/index.tsx | 20 +++++++++- src/steps/form/index.tsx | 35 ++++++++++------- src/util/produce.tsx | 3 +- src/util/value.ts | 24 +++++++++++- 11 files changed, 168 insertions(+), 63 deletions(-) diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index 5b2ea1e..63c6865 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -99,6 +99,7 @@ export default class AnyField extends Field : ( type === 'number' ? {}} @@ -118,6 +119,7 @@ export default class AnyField extends Field : {}} form={this.props.form} @@ -136,6 +138,7 @@ export default class AnyField extends Field ) })} diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 1d870ed..8f1c3f9 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -94,6 +94,8 @@ export interface FieldProps { onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, path: string, // 组件所在路径以字段拼接展示 + dependentFields: string[] // condition依赖字段存放数组 + onReportFields?:(fields: string[]) => Promise //向上层上报依赖字段 step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise } @@ -173,17 +175,19 @@ export class Field extends React.Component< 当前UI库未实现该表单类型 } - dependentFieldsArr: any shouldComponentUpdate(nextProps:FieldProps, nextState: S) { console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); - console.log('this.dependentFieldsArr',this.dependentFieldsArr); - const dependentFieldsArr = this.dependentFieldsArr + const dependentFieldsArr = nextProps.dependentFields + // console.log('dependentFieldsArr',dependentFieldsArr); let dependentIsChange = false - if (dependentFieldsArr) { + if (dependentFieldsArr && dependentFieldsArr.length) { for (let i=0;i< dependentFieldsArr.length;i++) { const nextDependentField = get(nextProps.step, dependentFieldsArr[i]) const currentDependentField = get(this.props.step, dependentFieldsArr[i]) - if (nextDependentField !== currentDependentField) { + if ((nextDependentField || currentDependentField) && nextDependentField !== currentDependentField) { + dependentIsChange = true + break + } else if (dependentFieldsArr[i].includes(nextProps.path)) { dependentIsChange = true break } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 1709298..9bab838 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -3,8 +3,8 @@ import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from import getALLComponents from '../' // import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' // import { cloneDeep } from 'lodash' -import { getValue, getBoolean, getChainPath } from '../../../util/value' -import { set, setValue , sort, splice} from '../../../util/produce' +import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' +import { set, setValue , sort, splice, push } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' @@ -68,7 +68,7 @@ export default class FormField extends Field | null>> = [] formFieldsMountedList: Array> = [] - dependentFieldsArr: string[] = [] //condition中依赖字段的存放数组 + dependentFields_: string[] = [] constructor (props: FieldProps) { super(props) @@ -232,6 +232,10 @@ export default class FormField extends Field { + const dependentFields_ = this.dependentFields_.concat(fields) + this.props.onReportFields && await this.props.onReportFields(dependentFields_) + } /** * 用于展示子表单组件中的每一子项中的每一个子表单项组件 * @param props @@ -494,19 +506,6 @@ export default class FormField extends Field await this.handleSort(index, sortType) : undefined, canCollapse, children: (fields || []).map((formFieldConfig, fieldIndex) => { - const conditionParams = formFieldConfig.condition?.params - if (conditionParams && Array.isArray(conditionParams)) { - const dependentFieldsArr = conditionParams.map(ite => { - if (ite.data?.source === 'record') { - return ite?.data?.field && `${this.props.path}.${ite.data.field}` - } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { - return ite?.data?.field && `${ite.data.field}` - } - return '' - }).filter(ite=>ite) - this.dependentFieldsArr = dependentFieldsArr - console.log('this.dependentFieldsArr--formList', this.dependentFieldsArr); - } if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step })) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, [] ) // this.formFieldsMountedList[index][fieldIndex] = false @@ -560,6 +559,8 @@ export default class FormField extends Field await this.props.loadDomain(domain)} path={getChainPath(`${fieldIndex}.${formFieldConfig.field}`, this.props.path)} + dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} + onReportFields={async (fields: string[]) => await this.handleReportFields(fields)} /> ) }) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index d80055c..1b8ebd6 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { getValue, getBoolean, getChainPath } from '../../../util/value' +import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' @@ -28,7 +28,8 @@ export default class GroupField extends Field | null> = [] formFieldsMounted: Array = [] - + dependentFields_: string[] = [] + constructor (props: FieldProps) { super(props) @@ -99,12 +100,16 @@ export default class GroupField extends Field { + const dependentFields_ = this.dependentFields_.concat(fields) + this.props.onReportFields && await this.props.onReportFields(dependentFields_) + } + renderComponent = (props: IGroupField) => { return 您当前使用的UI版本没有实现GroupField组件。 @@ -346,6 +360,8 @@ export default class GroupField extends Field await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field, this.props.path)} + dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} + onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} /> ) } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 9514d35..9efde32 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -1,12 +1,12 @@ import React from 'react' // import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' -import { getValue, getBoolean, getChainPath } from '../../../util/value' +import { getValue, getBoolean, getChainPath, getDependentFieldsArr } 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 { set, setValue } from '../../../util/produce' +import { concat, uniq } from 'lodash' +import { set, setValue, push } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' @@ -48,7 +48,8 @@ export default class ImportSubformField extends Field | null> = [] formFieldsMounted: Array = [] - + dependentFields_: string[] = [] + interfaceHelper = new InterfaceHelper() constructor (props: FieldProps) { @@ -148,13 +149,17 @@ export default class ImportSubformField extends Field { + const dependentFields_ = this.dependentFields_.concat(fields) + this.props.onReportFields && await this.props.onReportFields(dependentFields_) + } + renderComponent = (props: IImportSubformField) => { return 您当前使用的UI版本没有实现ImportSubformField组件。 @@ -371,19 +385,6 @@ export default class ImportSubformField extends Field { - const conditionParams = formFieldConfig.condition?.params - if (conditionParams && Array.isArray(conditionParams)) { - const dependentFieldsArr = conditionParams.map(ite => { - if (ite.data?.source === 'record') { - return ite?.data?.field && `${this.props.path}.${ite.data.field}` - } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { - return ite?.data?.field && `${ite.data.field}` - } - return '' - }).filter(ite=>ite) - this.dependentFieldsArr = dependentFieldsArr - console.log('this.dependentFieldsArr--子表单', this.dependentFieldsArr); - } if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null @@ -445,6 +446,8 @@ export default class ImportSubformField extends Field await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field, this.props.path)} + dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} + onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} /> ) } diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 5025b52..cd88f6c 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -4,7 +4,7 @@ import React from 'react' import ConditionHelper from '../../../util/condition' // import { cloneDeep } from 'lodash' import { set, setValue } from '../../../util/produce' -import { getValue, getBoolean, getChainPath } from '../../../util/value' +import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' import StatementHelper from '../../../util/statement' export interface ObjectFieldConfig extends FieldConfig { @@ -54,6 +54,7 @@ export default class ObjectField extends Field | null> } = {} formFieldsMountedList: { [key: string]: Array } = {} + dependentFields_: string[] = [] constructor (props: FieldProps) { super(props) @@ -150,6 +151,10 @@ export default class ObjectField extends Field extends Field { + const dependentFields_ = this.dependentFields_.concat(fields) + this.props.onReportFields && await this.props.onReportFields(dependentFields_) + } + /** * 用于展示子表单组件 * @param _props @@ -481,6 +495,8 @@ export default class ObjectField extends Field this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field, this.props.path)} + dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} + onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} /> ) }) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 1a286fb..d956464 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -4,7 +4,7 @@ import React from 'react' import ConditionHelper from '../../../util/condition' // import { cloneDeep } from 'lodash' import { set, setValue } from '../../../util/produce' -import { getValue, getBoolean, getChainPath } from '../../../util/value' +import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' import StatementHelper from '../../../util/statement' export type TabsFieldConfig = TabsFieldConfig_Same | TabsFieldConfig_Diff @@ -66,7 +66,8 @@ export default class TabsField extends Field | null>> = [] formFieldsMountedList: Array> = [] - + dependentFields_: string[] = [] + constructor (props: FieldProps) { super(props) @@ -167,6 +168,10 @@ export default class TabsField extends Field extends Field { + const dependentFields_ = this.dependentFields_.concat(fields) + this.props.onReportFields && await this.props.onReportFields(dependentFields_) + } + /** * 用于展示子表单组件 * @param _props @@ -441,6 +455,8 @@ export default class TabsField extends Field await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field, this.props.path)} + dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} + onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} /> ) })} diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 6994b28..0998c97 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -7,7 +7,7 @@ import ParamHelper from '../../util/param' import { get } from 'lodash' import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper from '../../util/condition' -import { getValue, getChainPath } from '../../util/value' +import { getValue, getChainPath, getDependentFieldsArr } from '../../util/value' /** * 表单步骤配置文件格式定义 @@ -89,6 +89,7 @@ export default class FilterStep extends Step { // 各表单项所使用的UI组件的实例 formFields: Array | null> = [] formFieldsMounted: Array = [] + dependentFields_: string[] = [] formValue: { [field: string]: any } = {} formData: { status: 'normal' | 'error' | 'loading', message?: string }[] = [] @@ -404,6 +405,21 @@ export default class FilterStep extends Step { } } + /** + * 上报condition依赖字段名称 + * @param fields + */ + handleReportFields = async (fields: string[]) => { + const dependentFields_ = this.dependentFields_ + for(let i=0;i { baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={getChainPath(formFieldIndex, formFieldConfig.field)} + dependentFields={this.dependentFields_} + onReportFields={async (fields: string[]) => await this.handleReportFields(fields)} /> ) } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 83ef800..d8420fa 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -3,7 +3,7 @@ import { Field, FieldConfigs, FieldError } from '../../components/formFields/com import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' // import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' -import { getValue, getBoolean, getChainPath } from '../../util/value' +import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../util/value' import { ParamConfig } from '../../interface' import ParamHelper from '../../util/param' import { get, unset } from 'lodash' @@ -11,6 +11,7 @@ import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' +import { timingSafeEqual } from 'crypto' /** * 表单步骤配置文件格式定义 @@ -167,12 +168,12 @@ export default class FormStep extends Step { // ts对clas // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Field => getALLComponents[type] OperationHelper = OperationHelper - dependentFieldsArr: string[] = [] //condition中依赖字段的存放数组 // 各表单项所使用的UI组件的实例 formFields: Array | null> = [] formFieldsMounted: Array = [] + dependentFields_: string[] = [] formValue: { [field: string]: any } = {} formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] = [] @@ -525,6 +526,21 @@ console.log('step handleValueListAppend', fullPath, value); } } } +/** + * 上报condition依赖字段名称 + * @param fields + */ + handleReportFields = async (fields: string[]) => { + const dependentFields_ = this.dependentFields_ + for(let i=0;i { - const conditionParams = formFieldConfig.condition?.params - if (conditionParams && Array.isArray(conditionParams)) { - const dependentFieldsArr = conditionParams.map(ite => { - if (ite.data?.source === 'record') { - return ite?.data?.field && `${getChainPath(formFieldConfig.field)}.${ite.data.field}` - } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { - return ite?.data?.field && `${ite.data.field}` - } - return '' - }).filter(ite=>ite) - this.dependentFieldsArr = dependentFieldsArr - console.log('this.dependentFieldsArr--formStep', this.dependentFieldsArr); - } if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue })) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null @@ -726,6 +729,8 @@ console.log('step handleValueListAppend', fullPath, value); baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={formFieldConfig.field} + dependentFields={this.dependentFields_} + onReportFields={async (fields: string[]) => await this.handleReportFields(fields)} /> ) } diff --git a/src/util/produce.tsx b/src/util/produce.tsx index 70651ad..5f5889a 100644 --- a/src/util/produce.tsx +++ b/src/util/produce.tsx @@ -70,7 +70,7 @@ export const splice = (current: any, path: string='', index: number, count: numb } /** - * 数组排序 + * current指定路径下数组排序 * @param current * @param path * @param index @@ -85,6 +85,7 @@ export const sort = (current: any, path: string='', index: number, sortType: 'up return target } + /** * lodash 递归合并来源对象的自身和继承的可枚举属性到目标对象 * @param a 目标对象 diff --git a/src/util/value.ts b/src/util/value.ts index 87e6014..766dc5f 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -1,6 +1,7 @@ import queryString from 'query-string' import { ParamConfig } from '../interface' import { set, get, isArray, assignInWith, isObject, isUndefined } from 'lodash' +import { FieldConfig } from '../components/formFields/common' export const getValue = (obj: any, path: string = '', defaultValue: any = undefined) => { if (path === undefined) { @@ -133,4 +134,25 @@ export const getChainPath = (currentPath: string | number = '', sourcePath: stri if (!sourcePath && sourcePath !== 0) {sourcePath = ''} else {sourcePath = sourcePath.toString()} const finalPath = (sourcePath +'.'+ currentPath).replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') return finalPath -} \ No newline at end of file +} + +/** + * 获取condition依赖字段存放数组 + * @param formFieldConfig + * @returns + */ + export const getDependentFieldsArr = (formFieldConfig: FieldConfig, props: any) => { + const conditionParams = formFieldConfig.condition?.params + if (conditionParams && Array.isArray(conditionParams) && conditionParams.length) { + return conditionParams.map(ite => { + if (ite.data?.source === 'record') { + return ite?.data?.field && `${props.path}.${ite.data.field}` + } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { + return ite?.data?.field && `${ite.data.field}` + } + return '' + }).filter(ite=>ite) + } + return [] +} + -- Gitee From f9d215be601b5d75675cba5f602b5809e5108d32 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 20 Jan 2022 11:33:17 +0800 Subject: [PATCH 012/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9SCU=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index df8d10d..9189179 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -186,9 +186,11 @@ export class Field extends React.Component< for (let i=0;i< dependentFieldsArr.length;i++) { const nextDependentField = get(nextProps.step, dependentFieldsArr[i]) const currentDependentField = get(this.props.step, dependentFieldsArr[i]) - if ((nextDependentField || currentDependentField) && nextDependentField !== currentDependentField) { - dependentIsChange = true - break + if ((nextDependentField || currentDependentField) ) { + if (nextDependentField !== currentDependentField) { + dependentIsChange = true + break + } } else if (dependentFieldsArr[i].includes(nextProps.path)) { dependentIsChange = true break -- Gitee From 2664a3dcbaa75bb258a7c69f47b81a05c354900c Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 20 Jan 2022 11:51:02 +0800 Subject: [PATCH 013/164] =?UTF-8?q?fix:=20tabs=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E6=8B=93=E5=B1=95=E5=B1=9E=E6=80=A7=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/tabs/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index d956464..fa16644 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -153,12 +153,12 @@ export default class TabsField extends Field { if (!this.formFieldsMountedList[index]) { - this.formFieldsMountedList[index] = [] + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) } if (this.formFieldsMountedList[index][formFieldIndex]) { return true } - this.formFieldsMountedList[index][formFieldIndex] = true + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, true) const tab = (this.props.config.tabs || [])[index] -- Gitee From d90c90dc9ab1e3253363669d254dbea313f807b2 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 20 Jan 2022 18:43:29 +0800 Subject: [PATCH 014/164] =?UTF-8?q?fix:=E5=AD=97=E6=AE=B5=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=E6=9B=B4=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 9189179..195a09c 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -186,12 +186,12 @@ export class Field extends React.Component< for (let i=0;i< dependentFieldsArr.length;i++) { const nextDependentField = get(nextProps.step, dependentFieldsArr[i]) const currentDependentField = get(this.props.step, dependentFieldsArr[i]) - if ((nextDependentField || currentDependentField) ) { - if (nextDependentField !== currentDependentField) { + if (dependentFieldsArr[i] === nextProps.path) { // 处于最后一层依赖字段 + if ((nextDependentField || currentDependentField) && (nextDependentField !== currentDependentField)) { dependentIsChange = true break } - } else if (dependentFieldsArr[i].includes(nextProps.path)) { + } else if (dependentFieldsArr[i].includes(nextProps.path)){ dependentIsChange = true break } -- Gitee From 362162d897b67712be885dadd5d2bf6ec23f2a89 Mon Sep 17 00:00:00 2001 From: zhenjintao Date: Thu, 20 Jan 2022 19:22:08 +0800 Subject: [PATCH 015/164] =?UTF-8?q?feat:=20hidden=E3=80=81group=E3=80=81fo?= =?UTF-8?q?rm=E3=80=81tabs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 27 +- src/components/formFields/form/display.tsx | 344 +++++++++++++++++ src/components/formFields/group/display.tsx | 277 ++++++++++++++ src/components/formFields/hidden/display.tsx | 5 + .../formFields/importSubform/display.tsx | 272 +++++++++++++ src/components/formFields/index.tsx | 12 +- src/components/formFields/tabs/display.tsx | 362 ++++++++++++++++++ src/index.tsx | 5 + 8 files changed, 1295 insertions(+), 9 deletions(-) create mode 100644 src/components/formFields/form/display.tsx create mode 100644 src/components/formFields/group/display.tsx create mode 100644 src/components/formFields/hidden/display.tsx create mode 100644 src/components/formFields/importSubform/display.tsx create mode 100644 src/components/formFields/tabs/display.tsx diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index d56f6ab..5b0e44f 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -151,16 +151,11 @@ export default class ImportSubformField extends DetailField } - render = () => { + getConfigData=() => { const { config, - formLayout, - value, - record, - data, - step + value } = this.props - if (config.configFrom && config.configFrom.type === 'interface' && config.configFrom.interface) { this.interfaceHelper.request( config.configFrom.interface, @@ -187,7 +182,6 @@ export default class ImportSubformField extends DetailField { + const { + config, + formLayout, + value, + record, + data, + step + } = this.props + + const fields = this.state.fields if (!fields || !Array.isArray(fields) || fields.length === 0) { return } else { diff --git a/src/components/formFields/form/display.tsx b/src/components/formFields/form/display.tsx new file mode 100644 index 0000000..f6a861a --- /dev/null +++ b/src/components/formFields/form/display.tsx @@ -0,0 +1,344 @@ +import React from 'react' +import { display as getALLComponents } from '../' +import { FormFieldConfig } from '.' +import { Display, FieldConfigs, FieldError, FieldProps } from '../common' +import { getValue, setValue } from '../../../util/value' +import { cloneDeep } from 'lodash' +import ConditionHelper from '../../../util/condition' + +export interface IFormField { + canCollapse?: boolean + children: React.ReactNode[] +} + +export interface IFormFieldItem { + index: number + title: string + canCollapse?: boolean + children: React.ReactNode[] +} + +export interface IFormFieldItemField { + index: number + label: string + fieldType: string + children: React.ReactNode +} + +interface FormState { + didMount: boolean + formDataList: { status: 'normal' | 'error' | 'loading', message?: string }[][] + showItem: boolean + showIndex: number +} + +export default class FormField extends Display, FormState> { + getALLComponents = (type: any): typeof Display => getALLComponents[type] + + formFieldsList: Array | null>> = [] + formFieldsMountedList: Array> = [] + + constructor (props: FieldProps) { + super(props) + + this.state = { + didMount: false, + formDataList: [], + showItem: false, + showIndex: 0 + } + } + + didMount = async () => { + await this.setState({ + didMount: true + }) + } + + set = async (value: any) => { + if (this.props.config.unstringify && this.props.config.unstringify.length > 0 && Array.isArray(value)) { + for (let index = 0; index < value.length; index++) { + if (value[index]) { + for (const field of this.props.config.unstringify) { + const info = getValue(value[index], field) + try { + value[index] = setValue(value[index], field, JSON.parse(info)) + } catch (e) {} + } + } + } + } + + return value + } + + get = async () => { + const data: any[] = [] + + for (let index = 0; index < this.formFieldsList.length; index++) { + if (this.formFieldsList[index]) { + let item: any = {} + + if (Array.isArray(this.props.config.fields)) { + for (const formFieldIndex in this.props.config.fields) { + const formFieldConfig = this.props.config.fields[formFieldIndex] + if (!ConditionHelper(formFieldConfig.condition, { record: this.props.value[index], data: this.props.data, step: this.props.step })) { + continue + } + const formField = this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex] + if (formField) { + const value = await formField.get() + item = setValue(item, formFieldConfig.field, value) + } + } + } + + if (this.props.config.stringify) { + for (const field of this.props.config.stringify) { + const info = getValue(item, field) + item = setValue(item, field, JSON.stringify(info)) + } + } + + data[index] = item + } + } + + return data + } + + handleMount = async (index: number, formFieldIndex: number) => { + if (!this.formFieldsMountedList[index]) { + this.formFieldsMountedList[index] = [] + } + if (this.formFieldsMountedList[index][formFieldIndex]) { + return true + } + this.formFieldsMountedList[index][formFieldIndex] = true + + const formDataList = cloneDeep(this.state.formDataList) + if (!formDataList[index]) formDataList[index] = [] + + if (this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex]) { + const formField = this.formFieldsList[index][formFieldIndex] + if (formField) { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + + let value = getValue(this.props.value[index] === undefined ? {} : this.props.value[index], formFieldConfig.field) + const source = value + if ((formFieldConfig.defaultValue) && value === undefined) { + value = await formField.reset() + } + value = await formField.set(value) + if (source !== value) { + this.props.onValueSet(`[${index}]${formFieldConfig.field}`, value, true) + } + + if (value !== undefined) { + formDataList[index][formFieldIndex] = { status: 'normal' } + } + + await formField.didMount() + } + } + + await this.setState({ + formDataList + }) + } + + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueSet(`[${index}]${fullPath}`, value, 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 + }) + } + } + + handleValueUnset = async (index: number, formFieldIndex: number, path: string, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueUnset(`[${index}]${fullPath}`, 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 + }) + } + } + + handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListAppend(`[${index}]${fullPath}`, value, 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 + }) + } + } + + handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListSplice(`[${index}]${fullPath}`, _index, count, 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 + }) + } + } + + /** + * 用于展示子表单组件中的每一子项中的每一个子表单项组件 + * @param props + * @returns + */ + renderItemFieldComponent = (props: IFormFieldItemField) => { + return + 您当前使用的UI版本没有实现FormField组件的renderItemFieldComponent方法。 + + } + + /** + * 用于展示子表单组件中的每一个子项 + * @param props + * @returns + */ + renderItemComponent = (props: IFormFieldItem) => { + return + 您当前使用的UI版本没有实现FormField组件的renderItemComponent方法。 + + } + + /** + * 用于展示子表单组件 + * @param _props + * @returns + */ + renderComponent = (_props: IFormField) => { + return + 您当前使用的UI版本没有实现FormField组件。 + + } + + render = () => { + const { + value = [], + data, + step, + config: { + fields, + primaryField, + canCollapse + } + } = this.props + + return ( + + { + this.renderComponent({ + canCollapse, + children: ( + this.state.didMount + ? (Array.isArray(value) ? value : []).map((itemValue: any, index: number) => { + return + {this.renderItemComponent({ + index, + title: primaryField !== undefined ? getValue(itemValue, primaryField, '').toString() : index.toString(), + canCollapse, + children: (fields || []).map((formFieldConfig, fieldIndex) => { + if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step })) { + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList[index] = [] + this.formFieldsMountedList[index][fieldIndex] = false + return null + } + const FormField = this.getALLComponents(formFieldConfig.type) || Display + + let status = ((this.state.formDataList[index] || [])[fieldIndex] || {}).status || 'normal' + + if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { + status = 'normal' + } + // 渲染表单项容器 + return ( +
+ { + this.renderItemFieldComponent({ + index: fieldIndex, + label: formFieldConfig.label, + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (fieldRef) { + if (!this.formFieldsList[index]) this.formFieldsList[index] = [] + this.formFieldsList[index][fieldIndex] = fieldRef + this.handleMount(index, fieldIndex) + } + }} + value={getValue(value[index], formFieldConfig.field)} + record={value[index]} + data={cloneDeep(data)} + step={step} + config={formFieldConfig} + 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + /> + ) + }) + } +
+ ) + }) + }) + } +
+ } + ) + : [] + ) + }) + } +
+ ) + } +} diff --git a/src/components/formFields/group/display.tsx b/src/components/formFields/group/display.tsx new file mode 100644 index 0000000..fc9a131 --- /dev/null +++ b/src/components/formFields/group/display.tsx @@ -0,0 +1,277 @@ +import React from 'react' +import { display as getALLComponents, FieldConfigs } from '../' +import { GroupFieldConfig, IGroupField } from '.' +import { setValue, getValue, getBoolean } from '../../../util/value' +import { Display, FieldError, FieldProps } from '../common' +import { IFormItem } from '../../../steps/form' +import { cloneDeep } from 'lodash' +import ConditionHelper from '../../../util/condition' +import StatementHelper from '../../../util/statement' + +interface IGroupFieldState { + didMount: boolean + formData: { status: 'normal' | 'error' | 'loading', message?: string, name?: string }[] +} + +export default class GroupField extends Display { + // 各表单项对应的类型所使用的UI组件的类 + getALLComponents = (type: any): typeof Display => getALLComponents[type] + + formFields: Array | null> = [] + formFieldsMounted: Array = [] + + constructor (props: FieldProps) { + super(props) + + this.state = { + didMount: false, + formData: [] + } + } + + didMount = async () => { + await this.setState({ + didMount: true + }) + } + + get = async () => { + let data: any = {} + + if (Array.isArray(this.props.config.fields)) { + for (let formFieldIndex = 0; formFieldIndex < this.props.config.fields.length; formFieldIndex++) { + const formFieldConfig = this.props.config.fields[formFieldIndex] + if (!ConditionHelper(formFieldConfig.condition, { record: this.props.value, data: this.props.data, step: this.props.step })) { + continue + } + const formField = this.formFields[formFieldIndex] + if (formField) { + const value = await formField.get() + data = setValue(data, formFieldConfig.field, value) + } + } + } + return data + } + + handleMount = async (formFieldIndex: number) => { + if (this.formFieldsMounted[formFieldIndex]) { + return true + } + this.formFieldsMounted[formFieldIndex] = true + + if (this.formFields[formFieldIndex]) { + const formField = this.formFields[formFieldIndex] + if (formField) { + const formFieldConfig = this.props.config.fields[formFieldIndex] + + let value = getValue(this.props.value, formFieldConfig.field) + const source = value + if ((formFieldConfig.defaultValue) && value === undefined) { + value = await formField.reset() + } + value = await formField.set(value) + if (source !== value) { + this.props.onValueSet(formFieldConfig.field, value, true) + } + + if (value !== undefined) { + this.setState(({ formData }) => { + formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } + return { formData: cloneDeep(formData) } + }) + } + await formField.didMount() + } + } + } + + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = 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) { + formData[formFieldIndex] = { status: 'normal' } + } else { + formData[formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formData + }) + } + } + + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueUnset(fullPath, 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 + }) + } + } + + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = 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) { + formData[formFieldIndex] = { status: 'normal' } + } else { + formData[formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formData + }) + } + } + + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = 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) { + formData[formFieldIndex] = { status: 'normal' } + } else { + formData[formFieldIndex] = { status: 'error', message: validation[0].message } + } + + this.setState({ + formData + }) + } + } + + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { + const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] + if (formFieldConfig) { + 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组件。 + + } + + /** + * 表单项组件 - UI渲染方法 + * 各UI库需重写该方法 + * @param props + */ + renderItemComponent = (props: IFormItem) => { + return + 您当前使用的UI版本没有实现FormItem组件。 + + } + + render = () => { + const { + value, + record, + data, + step + } = this.props + + return ( + + {this.renderComponent({ + children: this.state.didMount + ? (this.props.config.fields || []).map((formFieldConfig, formFieldIndex) => { + if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { + this.formFieldsMounted[formFieldIndex] = false + return null + } + let hidden: boolean = true + let display: boolean = true + + if (formFieldConfig.type === 'hidden') { + hidden = true + display = false + } + + if (formFieldConfig.display === 'none') { + hidden = true + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Display + + let status = (this.state.formData[formFieldIndex] || {}).status || 'normal' + + if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { + status = 'normal' + } + + const renderData = { + key: formFieldIndex, + label: formFieldConfig.label, + status, + layout: 'horizontal' as 'horizontal', + message: (this.state.formData[formFieldIndex] || {}).message || '', + extra: StatementHelper(formFieldConfig.extra, { record: this.props.record, data: this.props.data, step: this.props.step }), + required: getBoolean(formFieldConfig.required), + visitable: display, + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (formField) { + this.formFields[formFieldIndex] = formField + this.handleMount(formFieldIndex) + } + }} + value={getValue(value, formFieldConfig.field)} + record={record} + data={cloneDeep(data)} + step={step} + config={formFieldConfig} + 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + /> + ) + } + // 渲染表单项容器 + return ( + hidden + ? this.renderItemComponent(renderData) + : + ) + }) + : [] + })} + + ) + } +} diff --git a/src/components/formFields/hidden/display.tsx b/src/components/formFields/hidden/display.tsx new file mode 100644 index 0000000..0ff145f --- /dev/null +++ b/src/components/formFields/hidden/display.tsx @@ -0,0 +1,5 @@ +import { HiddenFieldConfig } from '.' +import { Display } from '../common' + +export default class HiddenField extends Display { +} diff --git a/src/components/formFields/importSubform/display.tsx b/src/components/formFields/importSubform/display.tsx new file mode 100644 index 0000000..98e797e --- /dev/null +++ b/src/components/formFields/importSubform/display.tsx @@ -0,0 +1,272 @@ +import React from 'react' +import { getValue } from '../../../util/value' + +import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../../detail/common' +import { Display } from '../../formFields/common' +import { display as getALLComponents, FieldConfigs } from '../../formFields' +import { IDetailItem } from '../../../steps/detail' +import { cloneDeep, isEqual } from 'lodash' +import ConditionHelper from '../../../util/condition' +import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' +/** + * 子表单配置项 + * - withConfig: 拓展配置 + * - * - enable: 是否开启 + * - * - dataField: (序列化)数据 + * - * - configField: (序列化)配置 + */ +export interface ImportSubformFieldConfig extends DetailFieldConfig { + type: 'import_subform', + configFrom?: ImportSubformConfigFromData | ImportSubformConfigFromInterface +} + +interface ImportSubformConfigFromData { + type: 'data' + dataField?: string + configField?: string +} + +interface ImportSubformConfigFromInterface { + type: 'interface' + interface?: InterfaceConfig +} + +export interface IImportSubformField { + children: React.ReactNode[] +} + +interface IImportSubformFieldState { + didMount: boolean + fields: FieldConfigs[] + formData: { status: 'normal' | 'error' | 'loading', message?: string }[] +} + +export default class ImportSubformFieldDisplay extends DetailField implements IDetailField { + // 各表单项对应的类型所使用的UI组件的类 + getALLComponents = (type: any): typeof Display => getALLComponents[type] + + // 用于请求防频的判断条件 + requestConfig: string = '' + value: string = '' + + formFields: Array | null> = [] + formFieldsMounted: Array = [] + + interfaceHelper = new InterfaceHelper() + + constructor (props: DetailFieldProps) { + super(props) + + this.state = { + didMount: false, + fields: [], + formData: [] + } + } + + getFullpath + (field: string, path: string = '') { + const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' + const _fullPath = `${withConfigPath}.${field}.${path}.` + const fullPath = _fullPath.replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') + return fullPath + } + + didMount = async () => { + await this.setState({ + didMount: true + }) + } + + set: (value: any) => Promise = async (value) => { + return value + }; + + handleMount = async (formFieldIndex: number) => { + if (this.formFieldsMounted[formFieldIndex]) { + return true + } + this.formFieldsMounted[formFieldIndex] = true + if (this.formFields[formFieldIndex]) { + const formField = this.formFields[formFieldIndex] + if (formField) { + const formFieldConfig = this.state.fields[formFieldIndex] + + let value = getValue(this.props.value, this.getFullpath(formFieldConfig.field)) + const source = value + if ((formFieldConfig.defaultValue) && value === undefined) { + value = await formField.reset() + } + value = await formField.set(value) + if (source !== value) { + this.props.onValueSet(this.getFullpath(formFieldConfig.field), value, true) + } + await formField.didMount() + } + } + } + + getConfigData= () => { + const { + config, + value + } = this.props + if (config.configFrom && config.configFrom.type === 'interface' && config.configFrom.interface) { + this.interfaceHelper.request( + config.configFrom.interface, + {}, + { record: this.props.record, data: this.props.data, step: this.props.step }, + { loadDomain: this.props.loadDomain } + ).then((data: any) => { + 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 = '[]' + } + } + if (dataToStringfy !== JSON.stringify(this.state.fields)) { + this.setState({ + fields: dataToUnstringfy + }) + } + }) + } + let fields = this.state.fields + if (config.configFrom && config.configFrom.type === 'data') { + fields = config.configFrom.configField ? getValue(value, config.configFrom.configField) : [] + if (!isEqual(fields, this.state.fields)) { + this.setState({ + fields + }) + } + } + } + + componentDidMount () { + this.getConfigData() + } + + handleValueSet = async (formFieldIndex: number, path: string, value: any) => { + const formFieldConfig = (this.state.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = this.getFullpath(formFieldConfig.field, path) + await this.props.onValueSet(fullPath, value, true) + } + } + + handleValueUnset = async (formFieldIndex: number, path: string) => { + const formFieldConfig = (this.state.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = this.getFullpath(formFieldConfig.field, path) + await this.props.onValueUnset(fullPath, true) + } + } + + handleValueListAppend = async (formFieldIndex: number, path: string, value: any) => { + const formFieldConfig = (this.state.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = this.getFullpath(formFieldConfig.field, path) + await this.props.onValueListAppend(fullPath, value, true) + } + } + + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number) => { + const formFieldConfig = (this.state.fields || [])[formFieldIndex] + if (formFieldConfig) { + const fullPath = this.getFullpath(formFieldConfig.field, path) + await this.props.onValueListSplice(fullPath, index, count, true) + } + } + + renderComponent = (props: IImportSubformField) => { + return + 您当前使用的UI版本没有实现ImportSubformField组件。 + + } + + /** + * 表单项组件 - UI渲染方法 + * 各UI库需重写该方法 + * @param props + */ + renderItemComponent = (props: IDetailItem) => { + return + 您当前使用的UI版本没有实现FormItem组件。 + + } + + render = () => { + const { + config, + value, + record, + data, + step + } = this.props + const fields = this.state.fields + + if (!fields || !Array.isArray(fields) || fields.length === 0) { + return + } else { + return ( + + {this.renderComponent({ + children: this.state.didMount + ? fields.map((formFieldConfig, formFieldIndex) => { + if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { + this.formFieldsMounted[formFieldIndex] = false + return null + } + let display: boolean = true + + if (formFieldConfig.type === 'hidden' || formFieldConfig.display === 'none') { + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Display + + const renderData: IDetailItem = { + key: formFieldIndex, + label: formFieldConfig.label, + visitable: display, + fieldType: formFieldConfig.type, + layout: 'horizontal' as 'horizontal', + children: ( + | null) => { + if (formField) { + this.formFields[formFieldIndex] = formField + this.handleMount(formFieldIndex) + } + }} + value={getValue(value, this.getFullpath(formFieldConfig.field))} + record={record} + data={cloneDeep(data)} + step={step} + config={formFieldConfig} + onValueSet={async (path, value) => 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + /> + ) + } + // 渲染表单项容器 + return this.renderItemComponent(renderData) + }) + : [] + })} + + ) + } + } +} diff --git a/src/components/formFields/index.tsx b/src/components/formFields/index.tsx index e7735a6..3fbf89a 100644 --- a/src/components/formFields/index.tsx +++ b/src/components/formFields/index.tsx @@ -25,6 +25,7 @@ import MultipleTextField, { MultipleTextFieldConfig } from './multipleText' import CustomField, { CustomFieldConfig } from './custom' import TextDisplay from './text/display' +import FormDisplay from './form/display' import RadioDisplay from './radio/display' import ColorDisplay from './color/display' import UploadDisplay from './upload/display' @@ -34,8 +35,12 @@ import DatetimeDisplay from './datetime/display' import DatetimeRangeDisplay from './datetimeRange/display' import SelectSingleDisplay from './select/single/display' import SelectMultipleDisplay from './select/multiple/display' +import ImportSubformDisplay from './importSubform/display' +import GroupDisplay from './group/display' import SwitchDisplay from './switch/display' +import TabsDisplay from './tabs/display' import MultipleTextDisplay from './multipleText/display' +import HiddenDisplay from './hidden/display' export interface HiddenFieldConfig extends FieldConfig { type: 'hidden' | 'none' @@ -124,14 +129,19 @@ export default { export const display = { text: TextDisplay, longtext: LongtextDisplay, + form: FormDisplay, radio: RadioDisplay, color: ColorDisplay, upload: UploadDisplay, + import_subform: ImportSubformDisplay, + group: GroupDisplay, number: NumberDisplay, datetime: DatetimeDisplay, datetimeRange: DatetimeRangeDisplay, select_single: SelectSingleDisplay, select_multiple: SelectMultipleDisplay, switch: SwitchDisplay, - multiple_text: MultipleTextDisplay + tabs: TabsDisplay, + multiple_text: MultipleTextDisplay, + hidden: HiddenDisplay } diff --git a/src/components/formFields/tabs/display.tsx b/src/components/formFields/tabs/display.tsx new file mode 100644 index 0000000..c7ba0d4 --- /dev/null +++ b/src/components/formFields/tabs/display.tsx @@ -0,0 +1,362 @@ +import React from 'react' +import { display as getALLComponents } from '../' +import { TabsFieldConfig, TabsFieldState } from '.' +import { Display, FieldConfigs, DisplayProps, FieldError } from '../common' +import ConditionHelper from '../../../util/condition' +import { getValue, setValue, getBoolean } from '../../../util/value' +import { cloneDeep } from 'lodash' + +export interface ITabsField { + children: React.ReactNode[] +} + +export interface ITabsFieldItem { + key: string + label: string + children: React.ReactNode[] +} + +export interface ITabsFieldItemField { + index: number + label: string + required: boolean + status: 'normal' | 'error' | 'loading' + description?: string + message?: string + extra?: string + fieldType: string + children: React.ReactNode +} + +export default class TabsField extends Display> { + // 各表单项对应的类型所使用的UI组件的类 + getALLComponents = (type: any): typeof Display => getALLComponents[type] + + formFieldsList: Array | null>> = [] + formFieldsMountedList: Array> = [] + + constructor (props: DisplayProps) { + super(props) + + this.state = { + didMount: false, + formDataList: [] + } + } + + didMount = async () => { + await this.setState({ + didMount: true + }) + } + + get = async () => { + let data: any = {} + + for (let index = 0; index < (this.props.config.tabs || []).length; index++) { + const tab = (this.props.config.tabs || [])[index] + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + + for (let formFieldIndex = 0; formFieldIndex < fields.length; formFieldIndex++) { + const formFieldConfig = fields[formFieldIndex] + if (!ConditionHelper(formFieldConfig.condition, { record: getValue(this.props.value, tab.field), data: this.props.data, step: this.props.step })) { + continue + } + const formField = this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex] + if (formField) { + const value = await formField.get() + const fullPath = tab.field === '' || formFieldConfig.field === '' ? `${tab.field}${formFieldConfig.field}` : `${tab.field}.${formFieldConfig.field}` + data = setValue(data, fullPath, value) + } + } + } + + return data + } + + handleMount = async (index: number, formFieldIndex: number) => { + if (!this.formFieldsMountedList[index]) { + this.formFieldsMountedList[index] = [] + } + if (this.formFieldsMountedList[index][formFieldIndex]) { + return true + } + this.formFieldsMountedList[index][formFieldIndex] = true + + const tab = (this.props.config.tabs || [])[index] + + if (this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex]) { + const formField = this.formFieldsList[index][formFieldIndex] + if (formField) { + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + const formFieldConfig = fields[formFieldIndex] + + const fullPath = tab.field === '' || formFieldConfig.field === '' ? `${tab.field}${formFieldConfig.field}` : `${tab.field}.${formFieldConfig.field}` + + let value = getValue(this.props.value, fullPath) + const source = value + if ((formFieldConfig.defaultValue) && value === undefined) { + value = await formField.reset() + } + value = await formField.set(value) + if (source !== value) { + this.props.onValueSet(fullPath, value, true) + } + + if (value !== undefined) { + this.setState(({ formDataList }) => { + if (!formDataList[index]) formDataList[index] = [] + formDataList[index][formFieldIndex] = { status: 'normal' } + return { formDataList: cloneDeep(formDataList) } + }) + } + await formField.didMount() + } + } + } + + handleChange = async (index: number, formFieldIndex: number, value: any) => { + } + + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, 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 || []) + 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.onValueSet(fullPath, value, 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 + }) + } + } + + handleValueUnset = async (index: number, formFieldIndex: number, path: string, 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 || []) + 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.onValueUnset(fullPath, 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 + }) + } + } + + handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, 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 || []) + 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.onValueListAppend(fullPath, value, 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 + }) + } + } + + handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, 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 || []) + 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.onValueListSplice(fullPath, _index, count, 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 + }) + } + } + + handleValueListSort = async (index: number, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + const formFieldConfig = fields[formFieldIndex] + if (formFieldConfig) { + 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 + }) + } + } + + /** + * 用于展示子表单组件 + * @param _props + * @returns + */ + renderComponent = (_props: ITabsField) => { + return + 您当前使用的UI版本没有实现FormField组件。 + + } + + /** + * 用于展示子表单组件中的每一个子项 + * @param props + * @returns + */ + renderItemComponent = (props: ITabsFieldItem) => { + return + 您当前使用的UI版本没有实现FormField组件的renderItemComponent方法。 + + } + + /** + * 用于展示子表单组件中的每一子项中的每一个子表单项组件 + * @param props + * @returns + */ + renderItemFieldComponent = (props: ITabsFieldItemField) => { + return + 您当前使用的UI版本没有实现FormField组件的renderItemFieldComponent方法。 + + } + + render = () => { + const { + value = {} + } = this.props + + return ( + + { + this.renderComponent({ + children: ( + this.state.didMount + ? (this.props.config.tabs || []).map((tab: any, index: number) => { + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + return ( + + {this.renderItemComponent({ + key: index.toString(), + label: tab.label, + children: fields.map((formFieldConfig, formFieldIndex) => { + if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList[index] = [] + this.formFieldsMountedList[index][formFieldIndex] = false + return null + } + let hidden: boolean = true + let display: boolean = true + + if (formFieldConfig.type === 'hidden') { + hidden = true + display = false + } + + if (formFieldConfig.display === 'none') { + hidden = true + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Display + + let status = ((this.state.formDataList[index] || [])[formFieldIndex] || {}).status || 'normal' + + if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { + status = 'normal' + } + // 渲染表单项容器 + if (hidden) { + return ( +
+ {this.renderItemFieldComponent({ + index: formFieldIndex, + label: formFieldConfig.label, + status, + message: ((this.state.formDataList[index] || [])[formFieldIndex] || {}).message || '', + required: getBoolean(formFieldConfig.required), + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (!this.formFieldsList[index]) this.formFieldsList[index] = [] + this.formFieldsList[index][formFieldIndex] = formField + this.handleMount(index, formFieldIndex) + }} + value={getValue(getValue(value, tab.field), formFieldConfig.field)} + record={getValue(value, tab.field)} + data={cloneDeep(this.props.data)} + step={this.props.step} + config={formFieldConfig} + 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + /> + ) + })} +
+ ) + } else { + return + } + }) + })} + + ) + }) + : [] + ) + }) + } +
+ ) + } +} diff --git a/src/index.tsx b/src/index.tsx index c8abdd5..d911d62 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -28,6 +28,7 @@ export { default as MultipleTextField } from './components/formFields/multipleTe export { default as CustomField } from './components/formFields/custom' export { default as TextDisplay } from './components/formFields/text/display' +export { default as FormDisplay } from './components/formFields/form/display' export { default as LongTextDisplay } from './components/formFields/longtext/display' export { default as RadioDisplay } from './components/formFields/radio/display' export { default as ColorDisplay } from './components/formFields/color/display' @@ -38,7 +39,11 @@ export { default as DatetimeDisplay } from './components/formFields/datetime/dis export { default as DatetimeRangeDisplay } from './components/formFields/datetimeRange/display' export { default as SelectSingleDisplay } from './components/formFields/select/single/display' export { default as SelectMultipleDisplay } from './components/formFields/select/multiple/display' +export { default as ImportSubformDisplay } from './components/formFields/importSubform/display' +export { default as GroupDisplay } from './components/formFields/group/display' +export { default as TabsDisplay } from './components/formFields/tabs/display' export { default as MultipleTextDisplay } from './components/formFields/multipleText/display' +export { default as HiddenDisplay } from './components/formFields/hidden/display' export { default as TableStep } from './steps/table' export { default as TextColumn } from './components/tableColumns/text' -- Gitee From 404f4c01f499b649955624457046fa423b3c8e51 Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Thu, 20 Jan 2022 22:13:02 +0800 Subject: [PATCH 016/164] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=93=8D=E4=BD=9C=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 72111dc..b50eefa 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -54,7 +54,7 @@ export interface TableOperationConfig { level?: 'normal' | 'primary' | 'danger' check?: { enable: false } | TableOperationCheckConfig confirm?: { enable: false } | TableOperationConfirmConfig - handle: TableCCMSOperationConfig + handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig } @@ -69,6 +69,15 @@ export interface TableCCMSOperationConfig { debug?: boolean } +export interface TableLinkOperationConfig { + type: 'link' + target: '_blank' | '_self' + targetURL: string + params?: { field: string, data: ParamConfig }[] + callback?: boolean + debug?: boolean +} + interface TableOperationCheckConfig { enable: true interface: InterfaceConfig @@ -338,6 +347,42 @@ export default class TableStep extends Step { window.open(`${targetURL}${targetKey}`) } } + + // 当按钮的响应类型是第三方链接时 + if (operation.handle.type === 'link') { + const params = {} + if (operation.handle.params !== undefined) { + for (const { field, data: dataConfig } of operation.handle.params) { + const value = getParam(dataConfig, { record, data, step }) + set(params, field, value) + } + + if (operation.handle.debug) { + console.log('CCMS debug: operation - operation.handle.type === link', params) + } + + // 提取跳转URL地址,合并URL参数拼接 + const targetURL = operation.handle.targetURL || '' + const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) + const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: fragmentIdentifier?.replace('/', '') }, { arrayFormat: 'bracket' }) || '' + + this.urlJumpHandler(jumpUrl, operation.handle.target) + } + } + } + + /** + * 链接跳转处理方法 + * @param url 跳转地址 + * @param target 跳转方式 + */ + urlJumpHandler = (url: string, target: string) => { + const a = document.createElement('a') + document.body.appendChild(a) + a.href = url + a.target = target + a.click() + document.body.removeChild(a) } /** -- Gitee From 458e47aead80a854a2f38e088e9572e33ba21ed8 Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 21 Jan 2022 19:19:07 +0800 Subject: [PATCH 017/164] =?UTF-8?q?feat:=20=E8=AF=A6=E6=83=85=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0image=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/enum/index.tsx | 5 +- src/components/detail/image/index.tsx | 66 +++++++++++++++++++++++++++ src/components/detail/index.tsx | 4 ++ src/index.tsx | 1 + 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/components/detail/image/index.tsx diff --git a/src/components/detail/enum/index.tsx b/src/components/detail/enum/index.tsx index c79b2cf..ac2517b 100644 --- a/src/components/detail/enum/index.tsx +++ b/src/components/detail/enum/index.tsx @@ -1,6 +1,5 @@ -import { config } from 'process' import React from 'react' -import { DetailField, DetailFieldConfig, DetailFieldError, DetailFieldProps, IDetailField } from '../common' +import { DetailField, DetailFieldConfig, IDetailField } from '../common' export interface EnumDetailConfig extends DetailFieldConfig { type: 'detail_enum' @@ -58,7 +57,7 @@ export default class EnumDetail extends DetailField implements IDetailField { + renderComponent = (props: IImageDetail) => { + return + 您当前使用的UI版本没有实现Image组件。 +
+
+
+ } + + getValue = () => { + const { + value, + config: { + url, + defaultValue + } + } = this.props + if (value === undefined || value === null || value === '') { + if (url) { + return url + } + return defaultValue !== undefined ? defaultValue : '' + } + return value + } + + render = () => { + const { + config: { + height, + width, + preview + } + } = this.props + const props: any = { + height, + width, + preview, + value: this.getValue() + } + + return ( + + {this.renderComponent(props)} + + ) + } +} diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index 24ae057..a88014b 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -2,6 +2,7 @@ import TextField, { TextFieldConfig } from './text' import EnumDetail, { EnumDetailConfig } from './enum' import StatementDetail, { StatementDetailConfig } from './statement' +import ImageDetail, { ImageDetailConfig } from './image' import GroupField, { GroupFieldConfig } from './group' import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' @@ -13,6 +14,7 @@ export type DetailFieldConfigs = TextFieldConfig | EnumDetailConfig | StatementDetailConfig | + ImageDetailConfig | GroupFieldConfig | ImportSubformFieldConfig @@ -21,6 +23,7 @@ export type componentType = 'group' | 'detail_enum' | 'statement' | + 'image' | 'import_subform' export default { @@ -28,5 +31,6 @@ export default { text: TextField, import_subform: ImportSubformField, detail_enum: EnumDetail, + image: ImageDetail, statement: StatementDetail } diff --git a/src/index.tsx b/src/index.tsx index c3b11cf..849fd0e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -61,6 +61,7 @@ export { default as DetailStep } from './steps/detail' export { default as DetailGroupField } from './components/detail/group' export { default as DetailEunmField } from './components/detail/enum' export { default as DetailStatementField } from './components/detail/statement' +export { default as DetailImageField } from './components/detail/image' export { default as DetailTextField } from './components/detail/text' export { default as DetailImportSubformField } from './components/detail/importSubform' -- Gitee From 7c0be189f76f9bb31bfba0d488f61075f982548e Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Fri, 21 Jan 2022 20:09:41 +0800 Subject: [PATCH 018/164] =?UTF-8?q?fixed:=E5=A2=9E=E5=BC=BA=E4=BA=86?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E6=93=8D=E4=BD=9C=E6=8C=89=E9=92=AE=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E8=BF=9E=E6=8E=A5=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index b50eefa..ac82304 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -363,14 +363,34 @@ export default class TableStep extends Step { // 提取跳转URL地址,合并URL参数拼接 const targetURL = operation.handle.targetURL || '' - const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) - const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: fragmentIdentifier?.replace('/', '') }, { arrayFormat: 'bracket' }) || '' + const urlParams = this.queryUrlParams(targetURL) + const query = urlParams.paramsResult + const hash = urlParams.hashResult.hash?.replace('#/', '') + const url = targetURL?.split('#')[0]?.split('?')[0] + // const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) + const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: hash }, { arrayFormat: 'bracket' }) || '' this.urlJumpHandler(jumpUrl, operation.handle.target) } } } + /** + * 获取URL中的路由和参数 + * @param url url地址 + */ + queryUrlParams = (url: string) => { + const paramsResult: any = {} + const hashResult: any = {} + const paramReg = /([^?=&#]+)=([^?=&#]+)/g + const hashReg = /#[^?=&#]+/g + // eslint-disable-next-line no-return-assign + url.replace(paramReg, (n, x, y) => paramsResult[x] = y) + // eslint-disable-next-line no-return-assign + url.replace(hashReg, (n) => hashResult.hash = n) + return { paramsResult, hashResult } + } + /** * 链接跳转处理方法 * @param url 跳转地址 -- Gitee From cada06d915791eb2fe7e568d08c53d7c4470364f Mon Sep 17 00:00:00 2001 From: zhenjintao Date: Fri, 21 Jan 2022 22:32:46 +0800 Subject: [PATCH 019/164] =?UTF-8?q?feat:=20group=E3=80=81importSubform?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 12 ++++++++++++ src/components/formFields/common.tsx | 1 + src/components/formFields/form/display.tsx | 5 +++++ src/components/formFields/group/display.tsx | 17 +++++++++++++++-- .../formFields/importSubform/display.tsx | 18 +++++++++++++++++- src/components/formFields/tabs/display.tsx | 3 +++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index f70c3ee..3c124a8 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -20,6 +20,7 @@ import { ColumnsConfig } from '../../../interface' export interface ImportSubformFieldConfig extends DetailFieldConfig { type: 'import_subform', configFrom?: ImportSubformConfigFromData | ImportSubformConfigFromInterface + childColumns?: ColumnsConfig } interface ImportSubformConfigFromData { @@ -216,6 +217,7 @@ export default class ImportSubformField extends DetailField {this.renderComponent({ + columns: config?.columns?.enable ? config.columns : undefined, children: this.state.didMount ? fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { @@ -233,11 +235,21 @@ export default class ImportSubformField extends DetailField | null) => { if (formField) { diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 9539759..f930b1a 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -181,6 +181,7 @@ export class Field extends React.Component< } export interface DisplayProps { + formLayout: 'horizontal' | 'vertical' | 'inline' value: T, record: { [field: string]: any }, data: any[], diff --git a/src/components/formFields/form/display.tsx b/src/components/formFields/form/display.tsx index f6a861a..6cdb1e0 100644 --- a/src/components/formFields/form/display.tsx +++ b/src/components/formFields/form/display.tsx @@ -21,6 +21,7 @@ export interface IFormFieldItem { export interface IFormFieldItemField { index: number label: string + layout: 'horizontal' | 'vertical' | 'inline' fieldType: string children: React.ReactNode } @@ -261,6 +262,7 @@ export default class FormField extends Display | null) => { if (fieldRef) { if (!this.formFieldsList[index]) this.formFieldsList[index] = [] @@ -311,6 +315,7 @@ export default class FormField extends Display { @@ -193,7 +193,9 @@ export default class GroupField extends Display { const { + config, value, + formLayout, record, data, step @@ -202,6 +204,7 @@ export default class GroupField extends Display {this.renderComponent({ + columns: config?.columns?.enable ? config.columns : undefined, children: this.state.didMount ? (this.props.config.fields || []).map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { @@ -232,11 +235,20 @@ export default class GroupField extends Display { const { config, + formLayout, value, record, data, @@ -217,6 +222,7 @@ export default class ImportSubformFieldDisplay extends DetailField {this.renderComponent({ + columns: config?.columns?.enable ? config.columns : undefined, children: this.state.didMount ? fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { @@ -234,11 +240,21 @@ export default class ImportSubformFieldDisplay extends DetailField | null) => { if (formField) { diff --git a/src/components/formFields/tabs/display.tsx b/src/components/formFields/tabs/display.tsx index c7ba0d4..1029f88 100644 --- a/src/components/formFields/tabs/display.tsx +++ b/src/components/formFields/tabs/display.tsx @@ -24,6 +24,7 @@ export interface ITabsFieldItemField { description?: string message?: string extra?: string + layout: 'horizontal' | 'vertical' | 'inline' fieldType: string children: React.ReactNode } @@ -319,6 +320,7 @@ export default class TabsField extends Display extends Display Date: Mon, 24 Jan 2022 14:14:15 +0800 Subject: [PATCH 020/164] =?UTF-8?q?fix:=20paramHelper=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 21 +++--- src/components/formFields/form/index.tsx | 31 ++++---- src/components/formFields/group/index.tsx | 29 ++++---- .../formFields/importSubform/index.tsx | 33 ++++----- src/components/formFields/object/index.tsx | 23 +++--- src/components/formFields/select/common.tsx | 4 +- src/components/formFields/tabs/index.tsx | 25 ++++--- src/steps/detail/index.tsx | 2 +- src/steps/filter/index.tsx | 27 +++---- src/steps/form/index.tsx | 36 +++++----- src/steps/header/index.tsx | 2 +- src/util/condition.ts | 8 +-- src/util/interface.ts | 17 ++--- src/util/param.ts | 8 ++- src/util/statement.ts | 6 +- src/util/value.ts | 71 ++++++++++++++----- 16 files changed, 189 insertions(+), 154 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 195a09c..acd4553 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -96,8 +96,8 @@ export interface FieldProps { onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, path: string, // 组件所在路径以字段拼接展示 - dependentFields: string[] // condition依赖字段存放数组 - onReportFields?:(fields: string[]) => Promise //向上层上报依赖字段 + dependentFields: string[] // param依赖字段存放数组 + onReportFields?:(field: string) => Promise //向父组件上报依赖字段 step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise } @@ -144,7 +144,7 @@ export class Field extends React.Component< config } = this.props if (config.defaultValue !== undefined) { - return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }, this) } return undefined @@ -179,22 +179,20 @@ export class Field extends React.Component< } shouldComponentUpdate(nextProps:FieldProps, nextState: S) { console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); + const dependentFieldsArr = nextProps.dependentFields // console.log('dependentFieldsArr',dependentFieldsArr); let dependentIsChange = false if (dependentFieldsArr && dependentFieldsArr.length) { - for (let i=0;i< dependentFieldsArr.length;i++) { + for (let i=dependentFieldsArr.length;i>=0;i--) { const nextDependentField = get(nextProps.step, dependentFieldsArr[i]) const currentDependentField = get(this.props.step, dependentFieldsArr[i]) - if (dependentFieldsArr[i] === nextProps.path) { // 处于最后一层依赖字段 - if ((nextDependentField || currentDependentField) && (nextDependentField !== currentDependentField)) { - dependentIsChange = true - break - } - } else if (dependentFieldsArr[i].includes(nextProps.path)){ + + if ((nextDependentField || currentDependentField) && nextDependentField !== currentDependentField) { dependentIsChange = true break } + } } @@ -241,7 +239,7 @@ export class Display extends React.Componen config } = this.props if (config.defaultValue !== undefined) { - return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }, this) } return undefined @@ -280,3 +278,4 @@ export class FieldError { this.message = message } } + diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 9bab838..a6ef1a6 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -3,7 +3,7 @@ import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from import getALLComponents from '../' // import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' // import { cloneDeep } from 'lodash' -import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' +import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import { set, setValue , sort, splice, push } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' @@ -189,7 +189,7 @@ export default class FormField extends Field { - const dependentFields_ = this.dependentFields_.concat(fields) - this.props.onReportFields && await this.props.onReportFields(dependentFields_) + handleReportFields = async (field: string) => { + // if (this.dependentFields_.includes(field)) return + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update + this.props.onReportFields && await this.props.onReportFields(field) } + /** * 用于展示子表单组件中的每一子项中的每一个子表单项组件 * @param props @@ -466,6 +466,7 @@ export default class FormField extends Field { + console.log('render--formList'); const { value = [], formLayout, @@ -506,7 +507,7 @@ export default class FormField extends Field 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 })) { + if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, [] ) // this.formFieldsMountedList[index][fieldIndex] = false this.formFieldsMountedList = set(this.formFieldsMountedList, `${[index]}.${fieldIndex}`, false) @@ -528,7 +529,7 @@ export default class FormField extends Field await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(`${fieldIndex}.${formFieldConfig.field}`, this.props.path)} - dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} - onReportFields={async (fields: string[]) => await this.handleReportFields(fields)} + path={getChainPath(`${index}.${formFieldConfig.field}`, this.props.path)} + dependentFields={this.dependentFields_} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) }) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 40e3bdd..388f04a 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' +import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' @@ -48,7 +48,8 @@ export default class GroupField extends Field | null> = [] formFieldsMounted: Array = [] dependentFields_: string[] = [] - + _path: string = '' // 自身字段所在路径 + constructor (props: FieldProps) { super(props) @@ -102,7 +103,7 @@ export default class GroupField extends Field { - const dependentFields_ = this.dependentFields_.concat(fields) - this.props.onReportFields && await this.props.onReportFields(dependentFields_) + handleReportFields = async (field: string) => { + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update + this.props.onReportFields && await this.props.onReportFields(field) } renderComponent = (props: IGroupField) => { @@ -320,7 +319,7 @@ export default class GroupField extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { + if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step }, this)) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -360,7 +359,7 @@ export default class GroupField extends Field await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field, this.props.path)} - dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} - onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} + dependentFields={this.dependentFields_} + onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 51f7c1e..b319daf 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -1,6 +1,6 @@ import React from 'react' // import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' -import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' +import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' @@ -38,7 +38,7 @@ export interface IImportSubformField { interface IImportSubformFieldState { didMount: boolean fields: FieldConfigs[] - formData: { status: 'normal' | 'error' | 'loading', message?: string }[] | any + formData: { status: 'normal' | 'error' | 'loading', message?: string }[] } export default class ImportSubformField extends Field implements IField { @@ -84,7 +84,7 @@ export default class ImportSubformField extends Field { - const dependentFields_ = this.dependentFields_.concat(fields) - this.props.onReportFields && await this.props.onReportFields(dependentFields_) + handleReportFields = async (field: string) => { + // if (this.dependentFields_.includes(field)) return + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update + // this.dependentFields_.push(field) + this.props.onReportFields && await this.props.onReportFields(field) } renderComponent = (props: IImportSubformField) => { @@ -357,7 +357,8 @@ export default class ImportSubformField extends Field { let dataToUnstringfy = data let dataToStringfy = JSON.stringify(data) @@ -389,7 +390,7 @@ export default class ImportSubformField extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { + if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step }, this)) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -428,7 +429,7 @@ export default class ImportSubformField extends Field await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field, this.props.path)} - dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} - onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} + dependentFields={this.dependentFields_} + onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index cd88f6c..35ed558 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -4,7 +4,7 @@ import React from 'react' import ConditionHelper from '../../../util/condition' // import { cloneDeep } from 'lodash' import { set, setValue } from '../../../util/produce' -import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' +import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import StatementHelper from '../../../util/statement' export interface ObjectFieldConfig extends FieldConfig { @@ -152,10 +152,6 @@ export default class ObjectField extends Field extends Field { - const dependentFields_ = this.dependentFields_.concat(fields) - this.props.onReportFields && await this.props.onReportFields(dependentFields_) + handleReportFields = async (field: string) => { + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update + this.props.onReportFields && await this.props.onReportFields(field) } + /** * 用于展示子表单组件 * @param _props @@ -494,9 +493,9 @@ export default class ObjectField extends Field this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => this.props.loadDomain(domain)} - path={getChainPath(formFieldConfig.field, this.props.path)} - dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} - onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} + path={getChainPath(`${key}${formFieldConfig.field}`, this.props.path)} + dependentFields={this.dependentFields_} + onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) }) diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 528b21d..2b8cf78 100644 --- a/src/components/formFields/select/common.tsx +++ b/src/components/formFields/select/common.tsx @@ -37,7 +37,7 @@ export default class SelectField extends Fiel config: EnumerationOptionsConfig | undefined ) => { if (config) { - EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { + EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain }, this)).then((options) => { if (JSON.stringify(this.state.options) !== JSON.stringify(options)) { this.setState({ options @@ -66,7 +66,7 @@ export class SelectDisplay extends Display { if (config) { - EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { + EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain }, this)).then((options) => { if (JSON.stringify(this.state.options) !== JSON.stringify(options)) { this.setState({ options diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index fa16644..2498340 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -4,7 +4,7 @@ import React from 'react' import ConditionHelper from '../../../util/condition' // import { cloneDeep } from 'lodash' import { set, setValue } from '../../../util/produce' -import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../../util/value' +import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import StatementHelper from '../../../util/statement' export type TabsFieldConfig = TabsFieldConfig_Same | TabsFieldConfig_Diff @@ -67,7 +67,7 @@ export default class TabsField extends Field | null>> = [] formFieldsMountedList: Array> = [] dependentFields_: string[] = [] - + constructor (props: FieldProps) { super(props) @@ -168,10 +168,6 @@ export default class TabsField extends Field extends Field { - const dependentFields_ = this.dependentFields_.concat(fields) - this.props.onReportFields && await this.props.onReportFields(dependentFields_) + handleReportFields = async (field: string) => { + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update + this.props.onReportFields && await this.props.onReportFields(field) } + /** * 用于展示子表单组件 * @param _props @@ -454,9 +453,9 @@ export default class TabsField extends Field this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(formFieldConfig.field, this.props.path)} - dependentFields={getDependentFieldsArr(formFieldConfig, this.props)} - onReportFields={async(fields: string[]) => await this.handleReportFields(fields)} + path={getChainPath(`${index}.${formFieldConfig.field}`, this.props.path)} + dependentFields={this.dependentFields_} + onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) })} diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index dcac904..c566bb3 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -145,7 +145,7 @@ export default class DetailStep extends Step { const detailData = cloneDeep(this.state.detailData) if (this.props.config.defaultValue) { - let detailDefault = ParamHelper(this.props.config.defaultValue, { data, step }) + let detailDefault = ParamHelper(this.props.config.defaultValue, { data, step }, this) if (this.props.config.unstringify) { for (const field of this.props.config.unstringify) { const info = getValue(detailDefault, field) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 0998c97..7085808 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -7,7 +7,7 @@ import ParamHelper from '../../util/param' import { get } from 'lodash' import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper from '../../util/condition' -import { getValue, getChainPath, getDependentFieldsArr } from '../../util/value' +import { getValue, getChainPath, updateCommonPrefixItem } from '../../util/value' /** * 表单步骤配置文件格式定义 @@ -115,7 +115,7 @@ export default class FilterStep extends Step { this.formData = [] if (this.props.config.defaultValue) { - const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }) + const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }, this) for (const formFieldIndex in (this.props.config.fields || [])) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const value = (formFieldConfig.field === undefined || formFieldConfig.field === '') ? formDefault : get(formDefault, formFieldConfig.field) @@ -216,7 +216,7 @@ export default class FilterStep extends Step { this.formData = [] if (this.props.config.defaultValue) { - const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }) + const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }, this) for (const formFieldIndex in (this.props.config.fields || [])) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const value = (formFieldConfig.field === undefined || formFieldConfig.field === '') ? formDefault : get(formDefault, formFieldConfig.field) @@ -406,18 +406,13 @@ export default class FilterStep extends Step { } /** - * 上报condition依赖字段名称 + * 上报param依赖字段名称 * @param fields */ - handleReportFields = async (fields: string[]) => { - const dependentFields_ = this.dependentFields_ - for(let i=0;i { + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update } /** @@ -465,7 +460,7 @@ export default class FilterStep extends Step { submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ""), resetText: this.props.config?.resetText?.replace(/(^\s*)|(\s*$)/g, ""), children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { + if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step }, this)) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -521,9 +516,9 @@ export default class FilterStep extends Step { 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)} - path={getChainPath(formFieldIndex, formFieldConfig.field)} + path={getChainPath(formFieldConfig.field)} dependentFields={this.dependentFields_} - onReportFields={async (fields: string[]) => await this.handleReportFields(fields)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 2296e08..aaaaeb3 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -4,14 +4,13 @@ import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' import { ColumnsConfig, ParamConfig } from '../../interface' // import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' -import { getValue, getBoolean, getChainPath, getDependentFieldsArr } from '../../util/value' +import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../util/value' import ParamHelper from '../../util/param' import { get, unset } from 'lodash' import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' import OperationHelper, { OperationConfig } from '../../util/operation' -import { timingSafeEqual } from 'crypto' /** * 表单步骤配置文件格式定义 @@ -228,7 +227,7 @@ export default class FormStep extends Step { // ts对clas this.formData = [] if (this.props.config.defaultValue) { - let formDefault = ParamHelper(this.props.config.defaultValue, { data, step }) + let formDefault = ParamHelper(this.props.config.defaultValue, { data, step }, this) if (this.props.config.unstringify) { for (const field of this.props.config.unstringify) { @@ -303,9 +302,9 @@ export default class FormStep extends Step { // ts对clas this.submitData = {} if (this.props.config.validations) { for (const validation of this.props.config.validations) { - if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.formValue })) { + if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.formValue }, this)) { this.canSubmit = false - const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.formValue }) || '未填写失败文案或失败文案配置异常' + const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.formValue }, this) || '未填写失败文案或失败文案配置异常' this.renderModalComponent({ message }) return } @@ -544,19 +543,14 @@ console.log('step handleValueListAppend', fullPath, value); } } /** - * 上报condition依赖字段名称 + * 上报param依赖字段名称 * @param fields */ - handleReportFields = async (fields: string[]) => { - const dependentFields_ = this.dependentFields_ - for(let i=0;i { + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) + if (typeof update === 'boolean') return + this.dependentFields_ = update + console.log('step依赖', this.dependentFields_); } /** @@ -603,6 +597,8 @@ console.log('step handleValueListAppend', fullPath, value); } render () { + console.log('render--formStep'); + const { data, step, @@ -627,7 +623,7 @@ console.log('step handleValueListAppend', fullPath, value); if (Object.prototype.toString.call(actions) === '[object Array]') { actions_ = [] for (let index = 0, len = actions.length; index < len; index++) { - if (!ConditionHelper(actions[index].condition, { record: formValue, data, step: formValue })) { + if (!ConditionHelper(actions[index].condition, { record: formValue, data, step: formValue }, this)) { continue } if (actions[index].type === 'submit') { @@ -682,7 +678,7 @@ console.log('step handleValueListAppend', fullPath, value); submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 cancelText: this.props.config?.cancelText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue })) { + if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue }, this)) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -726,7 +722,7 @@ console.log('step handleValueListAppend', fullPath, value); : undefined, status, message: formData[formFieldIndex]?.message || '', - extra: StatementHelper(formFieldConfig.extra, { data: this.props.data, step: formValue }), + extra: StatementHelper(formFieldConfig.extra, { data: this.props.data, step: formValue }, this), required: getBoolean(formFieldConfig.required), layout, visitable: display, @@ -758,7 +754,7 @@ console.log('step handleValueListAppend', fullPath, value); loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={formFieldConfig.field} dependentFields={this.dependentFields_} - onReportFields={async (fields: string[]) => await this.handleReportFields(fields)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/steps/header/index.tsx b/src/steps/header/index.tsx index a7ec2d7..671db3d 100644 --- a/src/steps/header/index.tsx +++ b/src/steps/header/index.tsx @@ -243,7 +243,7 @@ export default class HeaderStep extends Step { handleStatisticContent = (config: statisticContentConfig, _position: string) => { return (config.statistics || []).map((statistic, index) => { - const value = statistic.value ? ParamHelper(statistic.value, { data: this.props.data, step: this.props.step }) : undefined + const value = statistic.value ? ParamHelper(statistic.value, { data: this.props.data, step: this.props.step }, this) : undefined switch (statistic.type) { case 'value': return this.renderStatisticComponent({ diff --git a/src/util/condition.ts b/src/util/condition.ts index 633e565..989eec9 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -24,7 +24,7 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; } }): boolean { +export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; } }, _this?: any): boolean { if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { @@ -34,7 +34,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { - const value = ParamHelper(param.data, datas) + const value = ParamHelper(param.data, datas, _this) if (param.field === '') { statementParams = value === undefined ? 'undefined' : JSON.stringify(value) } else { @@ -87,9 +87,9 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - statementParams = ParamHelper(param.data,datas) + statementParams = ParamHelper(param.data,datas, _this) } else { - statementParams = set(statementParams, param.field, ParamHelper(param.data, datas)) + statementParams = set(statementParams, param.field, ParamHelper(param.data, datas, _this)) } } }) diff --git a/src/util/interface.ts b/src/util/interface.ts index 8e1d80b..bdad0fc 100644 --- a/src/util/interface.ts +++ b/src/util/interface.ts @@ -102,7 +102,8 @@ export default class InterfaceHelper { option?: { loadDomain?: (domain: string) => Promise extra_data?: { params?: any, data?: any } - } + }, + _this?: any // 位置要调整 ): Promise { return new Promise(async (resolve, reject) => { // 处理URL @@ -112,9 +113,9 @@ export default class InterfaceHelper { config.urlParams.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - urlParams = ParamHelper(param.data, datas) + urlParams = ParamHelper(param.data, datas, _this) } else { - urlParams = set(urlParams, param.field, ParamHelper(param.data, datas)) + urlParams = set(urlParams, param.field, ParamHelper(param.data, datas, _this)) } } }) @@ -145,9 +146,9 @@ export default class InterfaceHelper { config.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - params = ParamHelper(param.data, datas) + params = ParamHelper(param.data, datas, _this) } else { - params = set(params, param.field, ParamHelper(param.data, datas)) + params = set(params, param.field, ParamHelper(param.data, datas, _this)) } } }) @@ -159,7 +160,7 @@ export default class InterfaceHelper { if (config.data) { config.data.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { - (data as FormData).append(param.field, ParamHelper(param.data, datas)) + (data as FormData).append(param.field, ParamHelper(param.data, datas, _this)) } }) } @@ -173,9 +174,9 @@ export default class InterfaceHelper { config.data.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - data = ParamHelper(param.data, datas) + data = ParamHelper(param.data, datas, _this) } else { - data = set(data, param.field, ParamHelper(param.data, datas)) + data = set(data, param.field, ParamHelper(param.data, datas, _this)) } } }) diff --git a/src/util/param.ts b/src/util/param.ts index 867187b..9f43e02 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -1,11 +1,13 @@ import { get } from "lodash" import qs from "query-string" import { ParamConfig } from "../interface"; +import { getChainPath } from '../util/value' -export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: any } }) { // step--> stepValue +export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: any } }, _this: any) { // step--> stepValue switch (config.source) { case 'record': if (datas.record) { + _this && _this.props.onReportFields && _this.props.onReportFields(getChainPath(config.field, _this._path)) if (config.field === '') { return datas.record } else { @@ -15,6 +17,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj break case 'data': if (datas.step) { + _this && _this.props.onReportFields && _this.props.onReportFields(`${config.field}`) if (config.field === '') { return datas.step } else { @@ -33,6 +36,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj break case 'step': if (datas.data[config.step]) { + _this && _this.props.onReportFields && _this.props.onReportFields(`${config.field}`) if (config.field === '') { return datas.data[config.step] } else { @@ -46,8 +50,10 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj } else { return get(qs.parse(window.location.search, { arrayFormat: 'bracket' }), config.field) } + break case 'static': return config.value + break } return undefined } \ No newline at end of file diff --git a/src/util/statement.ts b/src/util/statement.ts index 73e59c5..4cbcf42 100644 --- a/src/util/statement.ts +++ b/src/util/statement.ts @@ -9,7 +9,7 @@ export interface StatementConfig { params: { field: string, data: ParamConfig }[] } -export default function StatementHelper(config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }}): string { +export default function StatementHelper(config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }}, _this?: any): string { if (config === undefined || config.statement === undefined || config.statement === '') { return '' } else { @@ -19,9 +19,9 @@ export default function StatementHelper(config: StatementConfig | undefined, dat config.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - statementParams = ParamHelper(param.data, datas) + statementParams = ParamHelper(param.data, datas, _this) } else { - statementParams = set(statementParams, param.field, ParamHelper(param.data, datas)) + statementParams = set(statementParams, param.field, ParamHelper(param.data, datas, _this)) } } }) diff --git a/src/util/value.ts b/src/util/value.ts index 766dc5f..5680a83 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -136,23 +136,62 @@ export const getChainPath = (currentPath: string | number = '', sourcePath: stri return finalPath } -/** - * 获取condition依赖字段存放数组 - * @param formFieldConfig - * @returns - */ - export const getDependentFieldsArr = (formFieldConfig: FieldConfig, props: any) => { - const conditionParams = formFieldConfig.condition?.params - if (conditionParams && Array.isArray(conditionParams) && conditionParams.length) { - return conditionParams.map(ite => { - if (ite.data?.source === 'record') { - return ite?.data?.field && `${props.path}.${ite.data.field}` - } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { - return ite?.data?.field && `${ite.data.field}` +// /** 废弃 +// * 获取param依赖字段存放数组 +// * @param formFieldConfig +// * @returns +// */ +// export const getDependentFieldsArr = (formFieldConfig: FieldConfig, props: any) => { +// const conditionParams = formFieldConfig.condition?.params +// if (conditionParams && Array.isArray(conditionParams) && conditionParams.length) { +// return conditionParams.map(ite => { +// if (ite.data?.source === 'record') { +// return ite?.data?.field && `${props.path}.${ite.data.field}` +// } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { +// return ite?.data?.field && `${ite.data.field}` +// } +// return '' +// }).filter(ite=>ite) +// } +// return [] +// } + + +export const getLongestCommonPrefix = (arr: string[]) => { + if (arr.length===0 ||arr[0].length===0){return "";} + for (let i=0,len1=arr[0].length;iite) } - return [] + return arr[0]; } +/** + * + * @param arr 目标数组 + * @param sourceField 来源字段 + * @returns 与来源字段比较共同前缀后更新的数组 | 是否更新并上报 + */ +export const updateCommonPrefixItem = (arr: string[], sourceField: string):string[] | boolean => { + const reg = /[^\.]+(?=\.?)/ + const sourceFieldPrefix = sourceField.match(reg)?.[0] + const commonPrefixItemS = [sourceField] + for(let i=arr.length - 1;i>=0;i--) { + const arrItem = arr[i] + if (sourceField.includes(arrItem)) { + return false + } + const arrItemPrefix = arrItem.match(reg)?.[0] + if (arrItemPrefix && arrItemPrefix === sourceFieldPrefix) { + arr.splice(i, 1) + commonPrefixItemS.push(arrItem) + } + + } + arr.push(getLongestCommonPrefix(commonPrefixItemS).replace(/\.$/, '')) + return arr +} -- Gitee From 38cb9e9a72eba38d8e560a289ca2d9a7e30815a3 Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Mon, 24 Jan 2022 15:38:43 +0800 Subject: [PATCH 021/164] =?UTF-8?q?=E6=8B=89=E5=8F=96=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 62 +++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 72111dc..6fdd48d 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -9,6 +9,8 @@ import CCMS, { CCMSConfig } from '../../main' import { cloneDeep, get, set } from 'lodash' import InterfaceHelper, { InterfaceConfig } from '../../util/interface' import ConditionHelper, { ConditionConfig } from '../../util/condition' +import { StatementConfig } from '../../util/statement' +import marked from 'marked' /** * 表格步骤配置文件格式定义 @@ -32,6 +34,12 @@ export interface TableConfig extends StepConfig { current?: string pageSize?: string total?: string + }, + description?: { + type: 'text' | 'tooltip' | 'modal' + label?: string | undefined + mode: 'plain' | 'markdown' | 'html' + content?: string | undefined } } @@ -98,7 +106,12 @@ export interface ITable { onChange: (page: number, pageSize: number) => void } tableOperations: React.ReactNode | null - multirowOperations: React.ReactNode | null + multirowOperations: React.ReactNode | null, + description?: { + type: string + label: string | undefined + content: React.ReactNode + } } /** @@ -430,7 +443,7 @@ export default class TableStep extends Step { 您当前使用的UI版本没有实现Table组件的OperationGroupItem部分。
} - + renderOperationModal = (props: ITableStepOperationModal) => { const mask = document.createElement('DIV') mask.style.position = 'fixed' @@ -457,13 +470,16 @@ export default class TableStep extends Step { primary, columns, operations, - pagination + pagination, + description }, data, step, onUnmount } = this.props + console.log(this.props) + const { operation: { enable: operationEnable, @@ -481,14 +497,13 @@ export default class TableStep extends Step { if (Object.prototype.toString.call(getDate) !== '[object Array]') { getDate = [] } - + console.log(getDate) const props: ITable = { title: label, primary, data: getDate, columns: (columns || []).filter((column) => column.field !== undefined && column.field !== '').map((column, index) => { const field = column.field.split('.')[0] - return { field, label: column.label, @@ -564,6 +579,43 @@ export default class TableStep extends Step { multirowOperations: null } + if(description) { + if(description.type === 'text') { + props.description = { + type: 'text', + label: description.label, + content: description.content + } + } else if (description.type === 'tooltip') { + props.description = { + type: 'tooltip', + label: description.label, + content: description.content + } + } else { + props.description = { + type: 'modal', + label: description.label, + content: description.content + } + } + } + + if (description && description.content !== undefined) { + const descriptionType = description.mode + switch (descriptionType) { + case 'plain': + props.description && (props.description.content = description.content) + break + case 'markdown': + props.description && (props.description.content =
) + break + case 'html': + props.description && (props.description.content =
) + break + } + } + if (pagination && pagination.mode === 'server') { const paginationCurrent = Number((pagination.current === undefined || pagination.current === '') ? data[step] : get(data[step], pagination.current, 1)) const paginationPageSize = Number((pagination.pageSize === undefined || pagination.pageSize === '') ? data[step] : get(data[step], pagination.pageSize, 10)) -- Gitee From c5d9bc05b358b7438f9c463407195f8a18f7f7c3 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 24 Jan 2022 15:54:06 +0800 Subject: [PATCH 022/164] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 6 +++--- src/components/formFields/form/index.tsx | 2 +- 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 | 5 +---- 8 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index acd4553..56f4020 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -95,9 +95,9 @@ export interface FieldProps { // 事件:修改值 - 列表 - 修改顺序 onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, - path: string, // 组件所在路径以字段拼接展示 - dependentFields: string[] // param依赖字段存放数组 - onReportFields?:(field: string) => Promise //向父组件上报依赖字段 + path: string, // 组件所在路径以字段拼接展示 1.3.0新增 + dependentFields: string[] // 子组件param依赖字段存放数组 1.3.0新增 + onReportFields?:(field: string) => Promise //向父组件上报依赖字段 1.3.0新增 step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index a6ef1a6..4193456 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -422,7 +422,7 @@ export default class FormField extends Field { // if (this.dependentFields_.includes(field)) return diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 388f04a..6de13ea 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -277,7 +277,7 @@ export default class GroupField extends Field { let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index b319daf..31667cc 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -314,7 +314,7 @@ export default class ImportSubformField extends Field { // if (this.dependentFields_.includes(field)) return diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 35ed558..6d081ec 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -358,7 +358,7 @@ export default class ObjectField extends Field { let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 2498340..89c1d00 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -326,7 +326,7 @@ export default class TabsField extends Field { let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 7085808..b7296bb 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -407,7 +407,7 @@ export default class FilterStep extends Step { /** * 上报param依赖字段名称 - * @param fields + * @param field */ handleReportFields = async (field: string) => { let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index aaaaeb3..74a3c15 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -458,7 +458,6 @@ export default class FormStep extends Step { // ts对clas const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` -console.log('step handleValueListAppend', fullPath, value); this.formValue = push(this.formValue, fullPath, value) //向this.formValue的fullPath下的值添加value this.setState({ @@ -544,7 +543,7 @@ console.log('step handleValueListAppend', fullPath, value); } /** * 上报param依赖字段名称 - * @param fields + * @param field */ handleReportFields = async (field: string) => { let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) @@ -597,8 +596,6 @@ console.log('step handleValueListAppend', fullPath, value); } render () { - console.log('render--formStep'); - const { data, step, -- Gitee From 1188c3ec25ad4e87d5b1c2985d4bf88496565fcc Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Tue, 25 Jan 2022 10:38:46 +0800 Subject: [PATCH 023/164] =?UTF-8?q?=E5=88=A0=E9=99=A4console.log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 6fdd48d..b3f9af1 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -478,8 +478,6 @@ export default class TableStep extends Step { onUnmount } = this.props - console.log(this.props) - const { operation: { enable: operationEnable, @@ -497,7 +495,6 @@ export default class TableStep extends Step { if (Object.prototype.toString.call(getDate) !== '[object Array]') { getDate = [] } - console.log(getDate) const props: ITable = { title: label, primary, -- Gitee From d425cd01d1cbf8ced007f08ce3a8b8cde268e089 Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Tue, 25 Jan 2022 11:26:06 +0800 Subject: [PATCH 024/164] =?UTF-8?q?=E4=BF=AE=E6=94=B9description-type?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index b3f9af1..72b09b1 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -108,7 +108,7 @@ export interface ITable { tableOperations: React.ReactNode | null multirowOperations: React.ReactNode | null, description?: { - type: string + type: 'text' | 'tooltip' | 'modal' label: string | undefined content: React.ReactNode } -- Gitee From cbdf549bba4e7b86e6439196647c4c25c31edddb Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Tue, 25 Jan 2022 18:54:20 +0800 Subject: [PATCH 025/164] =?UTF-8?q?=E4=BF=AE=E6=94=B9review=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 51 ++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 72b09b1..bee726d 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -9,9 +9,8 @@ import CCMS, { CCMSConfig } from '../../main' import { cloneDeep, get, set } from 'lodash' import InterfaceHelper, { InterfaceConfig } from '../../util/interface' import ConditionHelper, { ConditionConfig } from '../../util/condition' -import { StatementConfig } from '../../util/statement' +import StatementHelper, { StatementConfig } from '../../util/statement' import marked from 'marked' - /** * 表格步骤配置文件格式定义 * - field: 表格列表数据来源字段 @@ -37,9 +36,10 @@ export interface TableConfig extends StepConfig { }, description?: { type: 'text' | 'tooltip' | 'modal' - label?: string | undefined + label?: StatementConfig mode: 'plain' | 'markdown' | 'html' content?: string | undefined + showIcon: boolean } } @@ -111,6 +111,7 @@ export interface ITable { type: 'text' | 'tooltip' | 'modal' label: string | undefined content: React.ReactNode + showIcon: boolean } } @@ -575,44 +576,44 @@ export default class TableStep extends Step { : null, multirowOperations: null } - if(description) { if(description.type === 'text') { props.description = { type: 'text', - label: description.label, - content: description.content + label: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon } } else if (description.type === 'tooltip') { props.description = { type: 'tooltip', - label: description.label, - content: description.content + label: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon } } else { props.description = { type: 'modal', - label: description.label, - content: description.content + label: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon } } - } - - if (description && description.content !== undefined) { - const descriptionType = description.mode - switch (descriptionType) { - case 'plain': - props.description && (props.description.content = description.content) - break - case 'markdown': - props.description && (props.description.content =
) - break - case 'html': - props.description && (props.description.content =
) - break + if(description.content !== undefined) { + const descriptionType = description.mode + switch (descriptionType) { + case 'plain': + props.description && (props.description.content = description.content) + break + case 'markdown': + props.description && (props.description.content =
) + break + case 'html': + props.description && (props.description.content =
) + break + } } } - if (pagination && pagination.mode === 'server') { const paginationCurrent = Number((pagination.current === undefined || pagination.current === '') ? data[step] : get(data[step], pagination.current, 1)) const paginationPageSize = Number((pagination.pageSize === undefined || pagination.pageSize === '') ? data[step] : get(data[step], pagination.pageSize, 10)) -- Gitee From 8903021c24874f67e7b6ee2830f6b0dc56f3df52 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 26 Jan 2022 15:58:41 +0800 Subject: [PATCH 026/164] =?UTF-8?q?feat:=20=E4=B8=8D=E5=86=8D=E5=BC=95?= =?UTF-8?q?=E7=94=A8ObjectField?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/formFields/index.tsx b/src/components/formFields/index.tsx index e7735a6..4842a89 100644 --- a/src/components/formFields/index.tsx +++ b/src/components/formFields/index.tsx @@ -18,7 +18,7 @@ import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' import GroupField, { GroupFieldConfig } from './group' import AnyField, { AnyFieldConfig } from './any' import SwitchField, { SwitchFieldConfig } from './switch' -import ObjectField, { ObjectFieldConfig } from './object' +// import ObjectField, { ObjectFieldConfig } from './object' import HiddenField from './hidden' import TabsField, { TabsFieldConfig } from './tabs' import MultipleTextField, { MultipleTextFieldConfig } from './multipleText' @@ -64,7 +64,7 @@ export type FieldConfigs = ImportSubformFieldConfig | GroupFieldConfig | AnyFieldConfig | - ObjectFieldConfig | + // ObjectFieldConfig | TabsFieldConfig | MultipleTextFieldConfig | CustomFieldConfig @@ -90,7 +90,7 @@ export type componentType = 'group' | 'any' | 'switch' | - 'object' | + // 'object' | 'tabs' | 'multiple_text'| 'custom' @@ -114,7 +114,7 @@ export default { group: GroupField, any: AnyField, switch: SwitchField, - object: ObjectField, + // object: ObjectField, hidden: HiddenField, tabs: TabsField, multiple_text: MultipleTextField, -- Gitee From 25be20f14c54ab60596b9f4c2fff2c39b81eecc5 Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Wed, 26 Jan 2022 16:33:54 +0800 Subject: [PATCH 027/164] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E7=B1=BB=E5=9E=8Bstatementconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index bee726d..78b0b32 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -38,7 +38,7 @@ export interface TableConfig extends StepConfig { type: 'text' | 'tooltip' | 'modal' label?: StatementConfig mode: 'plain' | 'markdown' | 'html' - content?: string | undefined + content?: StatementConfig showIcon: boolean } } @@ -603,13 +603,13 @@ export default class TableStep extends Step { const descriptionType = description.mode switch (descriptionType) { case 'plain': - props.description && (props.description.content = description.content) + props.description && (props.description.content = StatementHelper(description.content, { data: this.props.data, step: this.props.step })) break case 'markdown': - props.description && (props.description.content =
) + props.description && (props.description.content =
) break case 'html': - props.description && (props.description.content =
) + props.description && (props.description.content =
) break } } -- Gitee From a77672d8d893b7e594bc6476bb5f6e3b5a187cff Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Thu, 27 Jan 2022 16:47:15 +0800 Subject: [PATCH 028/164] =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=A6=E6=83=85=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/detailInfo/index.tsx | 85 ++++++++++++++++++++++ src/components/detail/index.tsx | 11 ++- src/index.tsx | 1 + 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/components/detail/detailInfo/index.tsx diff --git a/src/components/detail/detailInfo/index.tsx b/src/components/detail/detailInfo/index.tsx new file mode 100644 index 0000000..912c664 --- /dev/null +++ b/src/components/detail/detailInfo/index.tsx @@ -0,0 +1,85 @@ +import React from 'react' +import { DetailField, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' +import StatementHelper, { StatementConfig } from '../../../util/statement' +import marked from 'marked' + +export interface InfoDetailConfig extends DetailFieldConfig { + type: 'detail_info' + description?: { + descType: 'text' | 'tooltip' | 'modal' + label?: StatementConfig + mode: 'plain' | 'markdown' | 'html' + content?: StatementConfig + showIcon: boolean + }, +} + +export interface IInfoProps { + description?: { + descType: 'text' | 'tooltip' | 'modal' + label: string | undefined + content: React.ReactNode + showIcon: boolean + } +} + +export default class InfoDetail extends DetailField implements IDetailField { + renderComponent = (props: IInfoProps) => { + return + 您当前使用的UI版本没有实现InfoDetail组件。 + + } + + render = () => { + const props: IInfoProps = {} + const { + config: { + description + } + } = this.props + if(description) { + if(description.descType === 'text') { + props.description = { + descType: 'text', + label: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon + } + } else if (description.descType === 'tooltip') { + props.description = { + descType: 'tooltip', + label: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon + } + } else { + props.description = { + descType: 'modal', + label: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon + } + } + if(description.content !== undefined) { + const descriptionType = description.mode + switch (descriptionType) { + case 'plain': + props.description && (props.description.content = StatementHelper(description.content, { data: this.props.data, step: this.props.step })) + break + case 'markdown': + props.description && (props.description.content =
) + break + case 'html': + props.description && (props.description.content =
) + break + } + } + } + + return ( + + {this.renderComponent(props)} + + ) + } +} diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index 24ae057..a6b7057 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -5,6 +5,7 @@ import StatementDetail, { StatementDetailConfig } from './statement' import GroupField, { GroupFieldConfig } from './group' import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' +import InfoDetail, { InfoDetailConfig } from './detailInfo' /** * 详情步骤内详情项配置文件格式定义 - 枚举 @@ -14,19 +15,23 @@ export type DetailFieldConfigs = EnumDetailConfig | StatementDetailConfig | GroupFieldConfig | - ImportSubformFieldConfig + ImportSubformFieldConfig | + InfoDetailConfig + export type componentType = 'text' | 'group' | 'detail_enum' | 'statement' | - 'import_subform' + 'import_subform' | + 'detail_info' export default { group: GroupField, text: TextField, import_subform: ImportSubformField, detail_enum: EnumDetail, - statement: StatementDetail + statement: StatementDetail, + detail_info: InfoDetail } diff --git a/src/index.tsx b/src/index.tsx index b193a05..297d872 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -58,6 +58,7 @@ export { default as DetailEunmField } from './components/detail/enum' export { default as DetailStatementField } from './components/detail/statement' export { default as DetailTextField } from './components/detail/text' export { default as DetailImportSubformField } from './components/detail/importSubform' +export { default as DetailInfoField } from './components/detail/detailInfo' export { default as HeaderStep } from './steps/header' -- Gitee From f4687894023cd7bb0add0996a69e715799a95de7 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 27 Jan 2022 18:45:31 +0800 Subject: [PATCH 029/164] =?UTF-8?q?feat:=20getfullpath=E6=94=B9=E4=B8=BAge?= =?UTF-8?q?tChainPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 17 ++++---- src/components/formFields/any/index.tsx | 6 +-- src/components/formFields/form/index.tsx | 3 +- src/components/formFields/group/index.tsx | 3 +- .../formFields/importSubform/index.tsx | 19 ++++----- src/components/formFields/object/index.tsx | 2 +- src/components/formFields/tabs/index.tsx | 2 +- src/steps/form/index.tsx | 3 +- src/util/param.ts | 2 +- src/util/value.ts | 40 ++++++++++++------- 10 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 9828bbc..e6d5509 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { getValue } from '../../../util/value' +import { getValue , getChainPath} from '../../../util/value' import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../common' import { Display } from '../../formFields/common' @@ -67,12 +67,7 @@ export default class ImportSubformField extends DetailField { await this.setState({ @@ -89,15 +84,16 @@ export default class ImportSubformField extends DetailField } else { + const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' return ( {this.renderComponent({ @@ -234,7 +231,7 @@ export default class ImportSubformField extends DetailField : ( type === 'number' ? : {}} @@ -137,7 +137,7 @@ export default class AnyField extends Field ) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 4193456..abbf399 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -1,7 +1,6 @@ import React from 'react' import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from '../common' import getALLComponents from '../' -// import { getValue, listItemMove, setValue, getBoolean, getChainPath } from '../../../util/value' // import { cloneDeep } from 'lodash' import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import { set, setValue , sort, splice, push } from '../../../util/produce' @@ -559,7 +558,7 @@ export default class FormField extends Field await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(`${index}.${formFieldConfig.field}`, this.props.path)} + path={getChainPath(this.props.path, `${index}.${formFieldConfig.field}`)} dependentFields={this.dependentFields_} onReportFields={async (field: string) => await this.handleReportFields(field)} /> diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 6de13ea..e3227fc 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -48,7 +48,6 @@ export default class GroupField extends Field | null> = [] formFieldsMounted: Array = [] dependentFields_: string[] = [] - _path: string = '' // 自身字段所在路径 constructor (props: FieldProps) { super(props) @@ -388,7 +387,7 @@ export default class GroupField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(formFieldConfig.field, this.props.path)} + path={getChainPath(this.props.path, formFieldConfig.field)} dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 31667cc..0bafbaa 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -1,5 +1,4 @@ import React from 'react' -// import { setValue, getValue, getBoolean, getChainPath } from '../../../util/value' import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' @@ -65,12 +64,7 @@ export default class ImportSubformField extends Field { await this.setState({ @@ -89,8 +83,9 @@ export default class ImportSubformField extends Field } else { + const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' return ( {this.renderComponent({ @@ -445,7 +442,7 @@ export default class ImportSubformField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(formFieldConfig.field, this.props.path)} + path={getChainPath(this.props.path, formFieldConfig.field)} dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 6d081ec..91520cb 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -493,7 +493,7 @@ export default class ObjectField extends Field this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => this.props.loadDomain(domain)} - path={getChainPath(`${key}${formFieldConfig.field}`, this.props.path)} + path={getChainPath(this.props.path, `${key}${formFieldConfig.field}`)} dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 89c1d00..70fd6e7 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -453,7 +453,7 @@ export default class TabsField extends Field this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(`${index}.${formFieldConfig.field}`, this.props.path)} + path={getChainPath(this.props.path, `${index}.${formFieldConfig.field}`)} dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 74a3c15..ecae8cd 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -3,7 +3,6 @@ import { Field, FieldConfigs, FieldError } from '../../components/formFields/com import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' import { ColumnsConfig, ParamConfig } from '../../interface' -// import { getValue, setValue, listItemMove, getBoolean, getChainPath } from '../../util/value' import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../util/value' import ParamHelper from '../../util/param' import { get, unset } from 'lodash' @@ -749,7 +748,7 @@ export default class FormStep extends Step { // ts对clas 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)} - path={formFieldConfig.field} + path={getChainPath(formFieldConfig.field)} dependentFields={this.dependentFields_} onReportFields={async (field: string) => await this.handleReportFields(field)} /> diff --git a/src/util/param.ts b/src/util/param.ts index 9f43e02..209bee6 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -7,7 +7,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj switch (config.source) { case 'record': if (datas.record) { - _this && _this.props.onReportFields && _this.props.onReportFields(getChainPath(config.field, _this._path)) + _this && _this.props.onReportFields && _this.props.onReportFields(getChainPath(_this.props.path, config.field)) if (config.field === '') { return datas.record } else { diff --git a/src/util/value.ts b/src/util/value.ts index 5680a83..9ad8fd8 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -123,19 +123,28 @@ export const listItemMove = (list: any[], currentIndex: number, sortType: 'up' | return list } -/** - * 组件所在的字符串链式路径 - * @param currentPath - * @param sourcePath - * @returns - */ -export const getChainPath = (currentPath: string | number = '', sourcePath: string | number = '') => { - if (!currentPath && currentPath !== 0) {currentPath = ''} else {currentPath = currentPath.toString()} - if (!sourcePath && sourcePath !== 0) {sourcePath = ''} else {sourcePath = sourcePath.toString()} - const finalPath = (sourcePath +'.'+ currentPath).replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') - return finalPath +// 参数转化为链式路径 +export const getChainPath = (...arg: any[]) => { + // const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' + // const _fullPath = `${withConfigPath}.${field}.${path}.` + const _fullPath = arg.join('.') + const fullPath = _fullPath.replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') + return fullPath } +// /** 废弃 +// * 组件所在的字符串链式路径 +// * @param currentPath +// * @param sourcePath +// * @returns +// */ +// export const getChainPath = (currentPath: string | number = '', sourcePath: string | number = '') => { +// if (!currentPath && currentPath !== 0) {currentPath = ''} else {currentPath = currentPath.toString()} +// if (!sourcePath && sourcePath !== 0) {sourcePath = ''} else {sourcePath = sourcePath.toString()} +// const finalPath = (sourcePath +'.'+ currentPath).replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') +// return finalPath +// } + // /** 废弃 // * 获取param依赖字段存放数组 // * @param formFieldConfig @@ -156,7 +165,9 @@ export const getChainPath = (currentPath: string | number = '', sourcePath: stri // return [] // } - +/** + * 获取一个数组中最长共同前缀 + */ export const getLongestCommonPrefix = (arr: string[]) => { if (arr.length===0 ||arr[0].length===0){return "";} for (let i=0,len1=arr[0].length;i Date: Thu, 27 Jan 2022 22:35:09 +0800 Subject: [PATCH 030/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9SCU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 56f4020..22c84c3 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -197,10 +197,10 @@ export class Field extends React.Component< } /** - * config受value影响变化 ,data提交前不变, 去掉这两项的比较 + * data提交前不变, 去掉这项的比较 * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 * */ - if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value) { + if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { console.log('no update' ); return false; } -- Gitee From 0967226b27e0683e6e8d50f906e9dd83204a3ec8 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 28 Jan 2022 18:56:06 +0800 Subject: [PATCH 031/164] =?UTF-8?q?fix:=20tabs=E3=80=81form=E7=9A=84Helper?= =?UTF-8?q?=E4=B8=ADrecord=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= 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 | 6 +++++- src/components/formFields/tabs/index.tsx | 17 +++++++++++------ src/util/param.ts | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 22c84c3..19098f8 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -200,7 +200,7 @@ export class Field extends React.Component< * data提交前不变, 去掉这项的比较 * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 * */ - if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { + if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value) { console.log('no update' ); return false; } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index abbf399..636b683 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -68,6 +68,7 @@ export default class FormField extends Field | null>> = [] formFieldsMountedList: Array> = [] dependentFields_: string[] = [] + selfPath:string = '' // Tabs和formList需要保存自身路径传给子组件 constructor (props: FieldProps) { super(props) @@ -506,6 +507,9 @@ export default class FormField extends Field await this.handleSort(index, sortType) : undefined, canCollapse, children: (fields || []).map((formFieldConfig, fieldIndex) => { + if (!this.selfPath) { + this.selfPath = getChainPath(this.props.path, index) + } if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, [] ) // this.formFieldsMountedList[index][fieldIndex] = false @@ -528,7 +532,7 @@ export default class FormField extends Field extends Field | null>> = [] formFieldsMountedList: Array> = [] dependentFields_: string[] = [] + selfPath:string = '' // Tabs和formList需要保存自身路径传给子组件 constructor (props: FieldProps) { super(props) @@ -92,7 +93,7 @@ export default class TabsField extends Field extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { + if (!this.selfPath) { + this.selfPath = getChainPath(this.props.path, tab.field) + } + + if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) return null @@ -427,7 +432,7 @@ export default class TabsField extends Field extends Field extends Field this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(this.props.path, `${index}.${formFieldConfig.field}`)} + path={getChainPath(this.props.path, `${tab.field}.${formFieldConfig.field}`)} dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> diff --git a/src/util/param.ts b/src/util/param.ts index 209bee6..f10ea63 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -7,7 +7,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj switch (config.source) { case 'record': if (datas.record) { - _this && _this.props.onReportFields && _this.props.onReportFields(getChainPath(_this.props.path, config.field)) + _this && _this.props.onReportFields && _this.props.onReportFields(getChainPath(_this.selfPath || _this.props.path, config.field)) if (config.field === '') { return datas.record } else { -- Gitee From 457abe7ce9056deaf8398012aecc44be1e4a8114 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 28 Jan 2022 19:11:18 +0800 Subject: [PATCH 032/164] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85helper?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/object/index.tsx | 4 ++-- src/components/formFields/treeSelect/index.tsx | 3 ++- src/components/formFields/upload/index.tsx | 3 ++- src/steps/form/index.tsx | 1 - 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 91520cb..cf28780 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -81,7 +81,7 @@ export default class ObjectField extends Field extends Field await this.handleChangeKey(key, value), onRemove: async () => await this.handleRemove(key), children: (Array.isArray(this.props.config.fields) ? this.props.config.fields : []).map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { + if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step }, this)) { if (!this.formFieldsMountedList[key]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${key}]`, []) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${key}][${formFieldIndex}]`, false) return null diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 9440c97..13d8211 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -113,7 +113,8 @@ export default class TreeSelectField extends Field { this.setState({ interfaceOptionsData: this.formatTree( diff --git a/src/components/formFields/upload/index.tsx b/src/components/formFields/upload/index.tsx index 5b8fc83..29f4372 100644 --- a/src/components/formFields/upload/index.tsx +++ b/src/components/formFields/upload/index.tsx @@ -161,7 +161,8 @@ export default class UploadField extends Field { // ts对clas this.formValue = set(this.formValue, fullPath, value) - console.log('test--->set--', this.formValue, fullPath, value); this.setState(({formValue})=>({ formValue: this.formValue })) -- Gitee From ec6c3a0d989e8fa67b83f80c45d78d5acf64419a Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 28 Jan 2022 22:08:26 +0800 Subject: [PATCH 033/164] =?UTF-8?q?fix:=20tabs=20value=E5=8F=96=E5=80=BC?= =?UTF-8?q?=E6=9C=AA=E9=87=87=E7=94=A8getChainPath=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/tabs/index.tsx | 2 +- src/util/value.ts | 35 ------------------------ 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index a40a559..e6375e0 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -445,7 +445,7 @@ export default class TabsField extends Field { - // const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - // const _fullPath = `${withConfigPath}.${field}.${path}.` const _fullPath = arg.join('.') const fullPath = _fullPath.replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') return fullPath } -// /** 废弃 -// * 组件所在的字符串链式路径 -// * @param currentPath -// * @param sourcePath -// * @returns -// */ -// export const getChainPath = (currentPath: string | number = '', sourcePath: string | number = '') => { -// if (!currentPath && currentPath !== 0) {currentPath = ''} else {currentPath = currentPath.toString()} -// if (!sourcePath && sourcePath !== 0) {sourcePath = ''} else {sourcePath = sourcePath.toString()} -// const finalPath = (sourcePath +'.'+ currentPath).replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') -// return finalPath -// } - -// /** 废弃 -// * 获取param依赖字段存放数组 -// * @param formFieldConfig -// * @returns -// */ -// export const getDependentFieldsArr = (formFieldConfig: FieldConfig, props: any) => { -// const conditionParams = formFieldConfig.condition?.params -// if (conditionParams && Array.isArray(conditionParams) && conditionParams.length) { -// return conditionParams.map(ite => { -// if (ite.data?.source === 'record') { -// return ite?.data?.field && `${props.path}.${ite.data.field}` -// } else if (ite.data?.source === 'data' || ite.data?.source === 'step') { -// return ite?.data?.field && `${ite.data.field}` -// } -// return '' -// }).filter(ite=>ite) -// } -// return [] -// } - /** * 获取一个数组中最长共同前缀 */ -- Gitee From d075d31ab498f77943949a5330d908d76470206b Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Sat, 29 Jan 2022 09:05:25 +0800 Subject: [PATCH 034/164] =?UTF-8?q?fix:=20=E5=8E=86=E5=8F=B2=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=ADstatementHelper=E4=B8=ADrecord=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 2 +- src/components/formFields/group/index.tsx | 2 +- src/components/formFields/importSubform/index.tsx | 2 +- src/util/produce.tsx | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 19098f8..22c84c3 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -200,7 +200,7 @@ export class Field extends React.Component< * data提交前不变, 去掉这项的比较 * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 * */ - if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value) { + if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { console.log('no update' ); return false; } diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index e3227fc..97c5a08 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -358,7 +358,7 @@ export default class GroupField extends Field Date: Sat, 29 Jan 2022 09:10:14 +0800 Subject: [PATCH 035/164] =?UTF-8?q?docs:=20=20immer=E3=80=81=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=AD=97=E6=AE=B5=E4=B8=8A=E6=8A=A5=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/readme.md | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/components/formFields/readme.md b/src/components/formFields/readme.md index e69de29..565e722 100644 --- a/src/components/formFields/readme.md +++ b/src/components/formFields/readme.md @@ -0,0 +1,67 @@ +# immer + +Immer是一个简单易用、体量小巧、设计巧妙的immutable 库,以最小的成本实现了js的不可变数据结构。 + +Js的对象是引用类型的,在使用过程中常常会不经意的修改。为了解决这个问题,除了可以使用深度拷贝的方法(但成本高,影响性能),还可以使用一些不可变数据结构的库,Immer就是其中的佼佼者。 +immer基于copy-on-write机制——在当前的状态数据上复制出一份临时的草稿,然后对这份草稿修改,最后生成新的状态数据。借力于ES6的Proxy,跟响应式的自动跟踪是一样的。 +https://immerjs.github.io/immer/api + +# immer写法 + +```js +import produce from "immer" + +this.state = { + members: [{name: 'user', age: 18}] +} + +// 一般写法 +this.setState(state=>{ + return produce(state,draft=>{ + draft.members[0].age++; + }) +}) +// 高阶写法 +this.setState(state=>{ + return produce(draft=>{ + draft.members[0].age++; + })(state) +}) +// 简洁写法 +this.setState(produce(draft => { + draft.members[0].age++; +})) +``` +# immer拓展 +1. 返回值问题 +以高阶函数写法为例 +语法:produce(recipe: (draftState) => void | draftState, ?PatchListener)(currentState): nextState +recipe 是否有返回值,nextState 的生成过程是不同的: +- recipe 没有返回值时:nextState是根据recipe 函数内的 draftState生成的; +- recipe有返回值时:nextState是根据 recipe 函数的返回值生成的 + +了解了这些,方便在开发中更加灵活地运用immer +2. Auto freezing(自动冻结) +Immer 会自动冻结使用 produce 修改过的状态树,这样可以防止在变更函数外部修改状态树。这个特性会带来性能影响,所以需要在生产环境中关闭。可以使用 setAutoFreeze(true / false) 打开或者关闭。在开发环境中建议打开,可以避免不可预测的状态树更改 +https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze + +# immer结合shouldComponentUpdate做了哪些事? + SCU的对于引用类型对象的比较,如果通过比较它们的值往往很耗费性能,有了数据结构共享,我们可以通过比较复杂对象的每一个节点的指针指向是否相同,大大节省性能损耗 + +# 项目中数据依赖字段上报规则及注意record(当前记录)注意事项 +1. 每一个组件在handleMount以后知道它们的this.props.path和自身的field路径,以path字段向下传递给子组件,我们在paramHelper里面对应record里的依赖项的处理是,拿到父级的路径和record依赖的字段(举例为DepField),通过getChainPath(this.props.path, DepField)拿到完整的链式路径,onReportFields上报给父组件有哪些依赖项,参见下: + +path=this.props.path+field ----传递子组件---> path=this.props.path+field +父组件 <----onReportFields--- getChainPath(this.props.path, DepField) + +2. 正常来说,父组件的value就是子组件的record, 特殊的是tabs和form两个组件对应分别多了tab.field和index,这里通过Helper传递record时,取值分别对应下探到tab.field和index。 +示例: + +```js +// import_subform和group用法: +ConditionHelper(formFieldConfig.condition, { record: this.props.value,...}) +ConditionHelper(formFieldConfig.condition, { record: this.props.value,...}) +// tabs和form用法: +ConditionHelper(formFieldConfig.condition, { record: this.props.value[tab.field],...}) +ConditionHelper(formFieldConfig.condition, { record: this.props.value[index],...}) +``` \ No newline at end of file -- Gitee From e1a525d0257c6925dc874edd006fe0ff63a08123 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Sat, 29 Jan 2022 09:33:02 +0800 Subject: [PATCH 036/164] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 4 ++-- src/components/formFields/form/index.tsx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 22c84c3..ae766a2 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -178,7 +178,7 @@ export class Field extends React.Component< } shouldComponentUpdate(nextProps:FieldProps, nextState: S) { - console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); + // console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); const dependentFieldsArr = nextProps.dependentFields // console.log('dependentFieldsArr',dependentFieldsArr); @@ -201,7 +201,7 @@ export class Field extends React.Component< * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 * */ if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { - console.log('no update' ); + // console.log('no update' ); return false; } return true; diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 636b683..21e8bd2 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -466,7 +466,6 @@ export default class FormField extends Field { - console.log('render--formList'); const { value = [], formLayout, -- Gitee From 8fab4f8e8b5628db01c9fe5ea782d22e605f11f0 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 9 Feb 2022 15:34:40 +0800 Subject: [PATCH 037/164] =?UTF-8?q?fix:=20=E4=BB=A3=E7=A0=81cherry-pick?= =?UTF-8?q?=E5=90=8E=E4=BF=AE=E5=A4=8DwithConfigPath=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 12 +++++++---- .../formFields/importSubform/index.tsx | 21 ++++++++++++------- src/steps/form/index.tsx | 5 ----- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index e6d5509..a2e1574 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -101,33 +101,37 @@ export default class ImportSubformField extends DetailField { + const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueSet(fullPath, value, true) } } handleValueUnset = async (formFieldIndex: number, path: string) => { + const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueUnset(fullPath, true) } } handleValueListAppend = async (formFieldIndex: number, path: string, value: any) => { + const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListAppend(fullPath, value, true) } } handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number) => { + const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListSplice(fullPath, index, count, true) } } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 206ea4c..f1fbd81 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -153,16 +153,17 @@ export default class ImportSubformField extends Field { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueSet(fullPath, value, true) let formData = this.state.formData @@ -235,7 +237,8 @@ export default class ImportSubformField extends Field { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueUnset(fullPath, true) let formData = this.state.formData @@ -254,7 +257,8 @@ export default class ImportSubformField extends Field { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListAppend(fullPath, value, true) let formData = this.state.formData @@ -273,7 +277,8 @@ export default class ImportSubformField extends Field { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListSplice(fullPath, index, count, true) let formData = this.state.formData @@ -292,7 +297,8 @@ export default class ImportSubformField extends Field { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = this.getFullpath(formFieldConfig.field, path) + const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' + const fullPath = getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListSort(fullPath, index, sortType, true) let formData = this.state.formData @@ -317,7 +323,6 @@ export default class ImportSubformField extends Field { // ts对clas if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - if(this.props.handleFormValue) { - this.props.handleFormValue({path: fullPath, value}) - } - - this.formValue = set(this.formValue, fullPath, value) this.setState(({formValue})=>({ formValue: this.formValue -- Gitee From 956c2c2c0593d627c240c81ab691ca869f04a5fa Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 9 Feb 2022 18:08:20 +0800 Subject: [PATCH 038/164] =?UTF-8?q?fix:=20handleReportFields=E6=94=BE?= =?UTF-8?q?=E5=88=B0formfield=E7=9A=84common?= 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 | 17 +++++++++++++++-- src/components/formFields/form/index.tsx | 14 +------------- src/components/formFields/group/index.tsx | 13 +------------ .../formFields/importSubform/index.tsx | 13 ------------- src/components/formFields/object/index.tsx | 13 +------------ src/components/formFields/tabs/index.tsx | 12 ------------ src/steps/filter/index.tsx | 1 - src/steps/form/index.tsx | 3 +-- src/util/param.ts | 11 +++++++---- 10 files changed, 26 insertions(+), 74 deletions(-) diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index 37a3744..f6c28c3 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -99,7 +99,6 @@ export default class AnyField extends Field : ( type === 'number' ? {}} @@ -119,7 +118,6 @@ export default class AnyField extends Field : {}} form={this.props.form} @@ -138,7 +136,6 @@ export default class AnyField extends Field ) })} diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index ae766a2..e162c1c 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -3,6 +3,7 @@ import { ColumnsConfig, ParamConfig } from '../../interface' import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' +import { updateCommonPrefixItem } from '../../util/value' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' import { isEqual, get } from 'lodash' @@ -96,7 +97,6 @@ export interface FieldProps { onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, path: string, // 组件所在路径以字段拼接展示 1.3.0新增 - dependentFields: string[] // 子组件param依赖字段存放数组 1.3.0新增 onReportFields?:(field: string) => Promise //向父组件上报依赖字段 1.3.0新增 step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise @@ -132,6 +132,7 @@ export interface FieldInterface { * - S: 表单项的扩展状态 */ export class Field extends React.Component, S> implements IField { + dependentFields: string[] = [] // 组件param依赖字段存放数组 1.3.0新增 static defaultProps = { config: {} }; @@ -172,6 +173,18 @@ export class Field extends React.Component< didMount: () => Promise = async () => { } +/** + * 上报param依赖字段名称 + * @param field + */ + handleReportFields: (field: string) => void = async (field) => { + // if (this.dependentFields.includes(field)) return + let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields, field) + if (typeof update === 'boolean') return + this.dependentFields = update + this.props.onReportFields && await this.props.onReportFields(field) + } + renderComponent = (props: E) => { return 当前UI库未实现该表单类型 @@ -180,7 +193,7 @@ export class Field extends React.Component< shouldComponentUpdate(nextProps:FieldProps, nextState: S) { // console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); - const dependentFieldsArr = nextProps.dependentFields + const dependentFieldsArr = this.dependentFields // console.log('dependentFieldsArr',dependentFieldsArr); let dependentIsChange = false if (dependentFieldsArr && dependentFieldsArr.length) { diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 21e8bd2..be27d88 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -67,7 +67,6 @@ export default class FormField extends Field | null>> = [] formFieldsMountedList: Array> = [] - dependentFields_: string[] = [] selfPath:string = '' // Tabs和formList需要保存自身路径传给子组件 constructor (props: FieldProps) { @@ -420,17 +419,7 @@ export default class FormField extends Field { - // if (this.dependentFields_.includes(field)) return - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - this.props.onReportFields && await this.props.onReportFields(field) - } + /** * 用于展示子表单组件中的每一子项中的每一个子表单项组件 @@ -562,7 +551,6 @@ export default class FormField extends Field await this.props.loadDomain(domain)} path={getChainPath(this.props.path, `${index}.${formFieldConfig.field}`)} - dependentFields={this.dependentFields_} onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 97c5a08..ec804d3 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -47,7 +47,6 @@ export default class GroupField extends Field | null> = [] formFieldsMounted: Array = [] - dependentFields_: string[] = [] constructor (props: FieldProps) { super(props) @@ -274,16 +273,7 @@ export default class GroupField extends Field { - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - this.props.onReportFields && await this.props.onReportFields(field) - } + renderComponent = (props: IGroupField) => { return @@ -388,7 +378,6 @@ export default class GroupField extends Field await this.props.loadDomain(domain)} path={getChainPath(this.props.path, formFieldConfig.field)} - dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index f1fbd81..986e055 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -50,7 +50,6 @@ export default class ImportSubformField extends Field | null> = [] formFieldsMounted: Array = [] - dependentFields_: string[] = [] interfaceHelper = new InterfaceHelper() @@ -314,17 +313,6 @@ export default class ImportSubformField extends Field { - // if (this.dependentFields_.includes(field)) return - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - this.props.onReportFields && await this.props.onReportFields(field) - } renderComponent = (props: IImportSubformField) => { return @@ -462,7 +450,6 @@ export default class ImportSubformField extends Field await this.props.loadDomain(domain)} path={getChainPath(this.props.path, formFieldConfig.field)} - dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index cf28780..2e737fc 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -54,7 +54,6 @@ export default class ObjectField extends Field | null> } = {} formFieldsMountedList: { [key: string]: Array } = {} - dependentFields_: string[] = [] constructor (props: FieldProps) { super(props) @@ -356,16 +355,7 @@ export default class ObjectField extends Field { - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - this.props.onReportFields && await this.props.onReportFields(field) - } + /** @@ -494,7 +484,6 @@ export default class ObjectField extends Field this.props.loadDomain(domain)} path={getChainPath(this.props.path, `${key}${formFieldConfig.field}`)} - dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index e6375e0..753da54 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -66,7 +66,6 @@ export default class TabsField extends Field | null>> = [] formFieldsMountedList: Array> = [] - dependentFields_: string[] = [] selfPath:string = '' // Tabs和formList需要保存自身路径传给子组件 constructor (props: FieldProps) { @@ -325,16 +324,6 @@ export default class TabsField extends Field { - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - this.props.onReportFields && await this.props.onReportFields(field) - } /** @@ -459,7 +448,6 @@ export default class TabsField extends Field await this.props.loadDomain(domain)} path={getChainPath(this.props.path, `${tab.field}.${formFieldConfig.field}`)} - dependentFields={this.dependentFields_} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index b7296bb..a1aded3 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -517,7 +517,6 @@ export default class FilterStep extends Step { baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field)} - dependentFields={this.dependentFields_} onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 1e8e7d7..1e7612a 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -542,7 +542,7 @@ export default class FormStep extends Step { // ts对clas let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) if (typeof update === 'boolean') return this.dependentFields_ = update - console.log('step依赖', this.dependentFields_); + // console.log('step依赖', this.dependentFields_); } /** @@ -743,7 +743,6 @@ export default class FormStep extends Step { // ts对clas baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field)} - dependentFields={this.dependentFields_} onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/util/param.ts b/src/util/param.ts index f10ea63..c9fc1d3 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -1,4 +1,4 @@ -import { get } from "lodash" +import _, { get } from "lodash" import qs from "query-string" import { ParamConfig } from "../interface"; import { getChainPath } from '../util/value' @@ -7,7 +7,10 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj switch (config.source) { case 'record': if (datas.record) { - _this && _this.props.onReportFields && _this.props.onReportFields(getChainPath(_this.selfPath || _this.props.path, config.field)) + if (_this) { + const fullPath = getChainPath(_this.selfPath || _this.props.path, config.field) + _this.handleReportFields(fullPath) + } if (config.field === '') { return datas.record } else { @@ -17,7 +20,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj break case 'data': if (datas.step) { - _this && _this.props.onReportFields && _this.props.onReportFields(`${config.field}`) + _this && _this.handleReportFields(`${config.field}`) if (config.field === '') { return datas.step } else { @@ -36,7 +39,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj break case 'step': if (datas.data[config.step]) { - _this && _this.props.onReportFields && _this.props.onReportFields(`${config.field}`) + _this && _this.handleReportFields(`${config.field}`) if (config.field === '') { return datas.data[config.step] } else { -- Gitee From cd00d1ba23981a0574559276dec6c5c0bb5800b0 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 9 Feb 2022 20:09:51 +0800 Subject: [PATCH 039/164] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4step=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=ADhandleReportFields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/filter/index.tsx | 11 ---------- src/steps/form/index.tsx | 43 ++++++++++++++------------------------ 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index a1aded3..07e9094 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -405,16 +405,6 @@ export default class FilterStep extends Step { } } - /** - * 上报param依赖字段名称 - * @param field - */ - handleReportFields = async (field: string) => { - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - } - /** * 表单步骤组件 - UI渲染方法 * 各UI库需重写该方法 @@ -517,7 +507,6 @@ export default class FilterStep extends Step { baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field)} - onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 1e7612a..1092ece 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -199,7 +199,7 @@ export default class FormStep extends Step { // ts对clas * 初始化表单的值 * @param props */ - constructor (props: StepProps) { + constructor(props: StepProps) { super(props) this.state = { ready: false, @@ -242,7 +242,7 @@ export default class FormStep extends Step { // ts对clas for (const formFieldIndex in formFieldsConfig) { const formFieldConfig = formFieldsConfig[formFieldIndex] const value = getValue(formDefault, formFieldConfig.field) - + this.formValue = setValue(this.formValue, formFieldConfig.field, value) this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } @@ -274,7 +274,7 @@ export default class FormStep extends Step { // ts对clas } value = await formField.set(value) this.formValue = setValue(this.formValue, formFieldConfig.field, value) - + if (value !== undefined) { const validation = await formField.validate(value) if (validation === true) { @@ -397,9 +397,9 @@ export default class FormStep extends Step { // ts对clas const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - + this.formValue = set(this.formValue, fullPath, value) - this.setState(({formValue})=>({ + this.setState(({ formValue }) => ({ formValue: this.formValue })) @@ -452,7 +452,7 @@ export default class FormStep extends Step { // ts对clas if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - this.formValue = push(this.formValue, fullPath, value) //向this.formValue的fullPath下的值添加value + this.formValue = push(this.formValue, fullPath, value) // 向this.formValue的fullPath下的值添加value this.setState({ formValue: this.formValue }) @@ -534,16 +534,6 @@ export default class FormStep extends Step { // ts对clas } } } -/** - * 上报param依赖字段名称 - * @param field - */ - handleReportFields = async (field: string) => { - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields_, field) - if (typeof update === 'boolean') return - this.dependentFields_ = update - // console.log('step依赖', this.dependentFields_); - } /** * 表单步骤组件 - UI渲染方法 @@ -588,7 +578,7 @@ export default class FormStep extends Step { // ts对clas }) } - render () { + render() { const { data, step, @@ -654,7 +644,7 @@ export default class FormStep extends Step { // ts对clas } } } - + if (ready) { return ( @@ -687,7 +677,7 @@ export default class FormStep extends Step { // ts对clas // 隐藏项同时打标录入数据并清空填写项 if (!hidden) { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } const FormField = this.getALLComponents(formFieldConfig.type) || Field @@ -697,18 +687,18 @@ export default class FormStep extends Step { // ts对clas if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { status = 'normal' } - + const renderData = { key: formFieldIndex, label: formFieldConfig.label, columns: columns?.enable ? { - type: formFieldConfig.columns?.type || columns?.type || 'span', - value: formFieldConfig.columns?.value || columns?.value || 1, - wrap: formFieldConfig.columns?.wrap || columns?.wrap || false, - gap: columns?.gap || 0, - rowGap: columns?.rowGap || 0 - } + type: formFieldConfig.columns?.type || columns?.type || 'span', + value: formFieldConfig.columns?.value || columns?.value || 1, + wrap: formFieldConfig.columns?.wrap || columns?.wrap || false, + gap: columns?.gap || 0, + rowGap: columns?.rowGap || 0 + } : undefined, status, message: formData[formFieldIndex]?.message || '', @@ -743,7 +733,6 @@ export default class FormStep extends Step { // ts对clas baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} path={getChainPath(formFieldConfig.field)} - onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) } -- Gitee From c02570723beffd5e3dfad75aec17d6708721826d Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Feb 2022 00:56:28 +0800 Subject: [PATCH 040/164] =?UTF-8?q?fix:=20path=E6=94=B9=E4=B8=BAcontainerP?= =?UTF-8?q?ath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/any/index.tsx | 6 +- src/components/formFields/common.tsx | 59 +++++++++---------- src/components/formFields/form/index.tsx | 10 +--- src/components/formFields/group/index.tsx | 2 +- .../formFields/importSubform/index.tsx | 2 +- src/components/formFields/object/index.tsx | 2 +- src/components/formFields/readme.md | 16 ++--- src/components/formFields/tabs/index.tsx | 7 +-- src/steps/detail/index.tsx | 2 +- src/steps/filter/index.tsx | 8 +-- src/steps/form/index.tsx | 14 ++--- src/steps/header/index.tsx | 2 +- src/util/param.ts | 14 ++--- 13 files changed, 66 insertions(+), 78 deletions(-) diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index f6c28c3..566caf9 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -98,7 +98,7 @@ export default class AnyField extends Field : ( type === 'number' ? {}} @@ -117,7 +117,7 @@ export default class AnyField extends Field : {}} form={this.props.form} @@ -135,7 +135,7 @@ export default class AnyField extends Field ) })} diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index e162c1c..01f5d11 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -96,8 +96,8 @@ export interface FieldProps { // 事件:修改值 - 列表 - 修改顺序 onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => Promise baseRoute: string, - path: string, // 组件所在路径以字段拼接展示 1.3.0新增 - onReportFields?:(field: string) => Promise //向父组件上报依赖字段 1.3.0新增 + containerPath: string, // 容器组件所在路径以字段拼接展示 1.3.0新增 + onReportFields?: (field: string) => Promise // 向父组件上报依赖字段 1.3.0新增 step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise } @@ -140,7 +140,7 @@ export class Field extends React.Component< /** * 获取默认值 */ - defaultValue = async () => { + async defaultValue (this: any) { const { config } = this.props @@ -173,31 +173,32 @@ export class Field extends React.Component< didMount: () => Promise = async () => { } -/** - * 上报param依赖字段名称 - * @param field - */ - handleReportFields: (field: string) => void = async (field) => { - // if (this.dependentFields.includes(field)) return - let update: string[] | boolean = updateCommonPrefixItem(this.dependentFields, field) - if (typeof update === 'boolean') return - this.dependentFields = update - this.props.onReportFields && await this.props.onReportFields(field) - } + /** + * 上报param依赖字段名称 + * @param field + */ + handleReportFields: (field: string) => void = async (field) => { + // if (this.dependentFields.includes(field)) return + const update: string[] | boolean = updateCommonPrefixItem(this.dependentFields, field) + if (typeof update === 'boolean') return + this.dependentFields = update + this.props.onReportFields && await this.props.onReportFields(field) + } renderComponent = (props: E) => { return 当前UI库未实现该表单类型 } - shouldComponentUpdate(nextProps:FieldProps, nextState: S) { + + shouldComponentUpdate (nextProps: FieldProps, nextState: S) { // console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); - + const dependentFieldsArr = this.dependentFields // console.log('dependentFieldsArr',dependentFieldsArr); let dependentIsChange = false if (dependentFieldsArr && dependentFieldsArr.length) { - for (let i=dependentFieldsArr.length;i>=0;i--) { + for (let i = dependentFieldsArr.length; i >= 0; i--) { const nextDependentField = get(nextProps.step, dependentFieldsArr[i]) const currentDependentField = get(this.props.step, dependentFieldsArr[i]) @@ -205,20 +206,19 @@ export class Field extends React.Component< dependentIsChange = true break } - } } - -/** - * data提交前不变, 去掉这项的比较 - * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 - * */ - if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { - // console.log('no update' ); - return false; + + /** + * data提交前不变, 去掉这项的比较 + * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 + * */ + if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { + // console.log('no update' ); + return false + } + return true } - return true; -} render = () => { return ( @@ -252,7 +252,7 @@ export class Display extends React.Componen config } = this.props if (config.defaultValue !== undefined) { - return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }, this) + return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) } return undefined @@ -291,4 +291,3 @@ export class FieldError { this.message = message } } - diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index be27d88..e95af8e 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -67,7 +67,6 @@ export default class FormField extends Field | null>> = [] formFieldsMountedList: Array> = [] - selfPath:string = '' // Tabs和formList需要保存自身路径传给子组件 constructor (props: FieldProps) { super(props) @@ -280,13 +279,13 @@ export default class FormField extends Field { var list = this.state.formDataList - let formDataList = sort(list, '', index, sortType) + const formDataList = sort(list, '', index, sortType) this.setState({ formDataList: formDataList }) @@ -495,9 +494,6 @@ export default class FormField extends Field await this.handleSort(index, sortType) : undefined, canCollapse, children: (fields || []).map((formFieldConfig, fieldIndex) => { - if (!this.selfPath) { - this.selfPath = getChainPath(this.props.path, index) - } if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, [] ) // this.formFieldsMountedList[index][fieldIndex] = false @@ -550,7 +546,7 @@ export default class FormField extends Field await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(this.props.path, `${index}.${formFieldConfig.field}`)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field, index)} onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index ec804d3..a2be717 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -377,7 +377,7 @@ export default class GroupField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(this.props.path, formFieldConfig.field)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field)} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 986e055..c296d83 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -449,7 +449,7 @@ export default class ImportSubformField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(this.props.path, formFieldConfig.field)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field)} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 2e737fc..1ee93c8 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -483,7 +483,7 @@ export default class ObjectField extends Field this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => this.props.loadDomain(domain)} - path={getChainPath(this.props.path, `${key}${formFieldConfig.field}`)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field, key)} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/components/formFields/readme.md b/src/components/formFields/readme.md index 565e722..d69849c 100644 --- a/src/components/formFields/readme.md +++ b/src/components/formFields/readme.md @@ -1,4 +1,4 @@ -# immer +#### immer Immer是一个简单易用、体量小巧、设计巧妙的immutable 库,以最小的成本实现了js的不可变数据结构。 @@ -6,7 +6,7 @@ Js的对象是引用类型的,在使用过程中常常会不经意的修改。 immer基于copy-on-write机制——在当前的状态数据上复制出一份临时的草稿,然后对这份草稿修改,最后生成新的状态数据。借力于ES6的Proxy,跟响应式的自动跟踪是一样的。 https://immerjs.github.io/immer/api -# immer写法 +#### immer写法 ```js import produce from "immer" @@ -32,7 +32,7 @@ this.setState(produce(draft => { draft.members[0].age++; })) ``` -# immer拓展 +#### immer拓展 1. 返回值问题 以高阶函数写法为例 语法:produce(recipe: (draftState) => void | draftState, ?PatchListener)(currentState): nextState @@ -45,14 +45,14 @@ recipe 是否有返回值,nextState 的生成过程是不同的: Immer 会自动冻结使用 produce 修改过的状态树,这样可以防止在变更函数外部修改状态树。这个特性会带来性能影响,所以需要在生产环境中关闭。可以使用 setAutoFreeze(true / false) 打开或者关闭。在开发环境中建议打开,可以避免不可预测的状态树更改 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze -# immer结合shouldComponentUpdate做了哪些事? +#### immer结合shouldComponentUpdate做了哪些事? SCU的对于引用类型对象的比较,如果通过比较它们的值往往很耗费性能,有了数据结构共享,我们可以通过比较复杂对象的每一个节点的指针指向是否相同,大大节省性能损耗 -# 项目中数据依赖字段上报规则及注意record(当前记录)注意事项 -1. 每一个组件在handleMount以后知道它们的this.props.path和自身的field路径,以path字段向下传递给子组件,我们在paramHelper里面对应record里的依赖项的处理是,拿到父级的路径和record依赖的字段(举例为DepField),通过getChainPath(this.props.path, DepField)拿到完整的链式路径,onReportFields上报给父组件有哪些依赖项,参见下: +#### 项目中数据依赖字段上报规则及注意record(当前记录)注意事项 +1. 每一个组件在handleMount以后知道它们的this.props.containerPath和自身的field路径,以containerPath字段向下传递给子组件,我们在paramHelper里面对应record里的依赖项的处理是,拿到父级的路径和record依赖的字段(举例为DepField),通过getChainPath(this.props.containerPath, DepField)拿到完整的链式路径,onReportFields上报给父组件有哪些依赖项,参见下: -path=this.props.path+field ----传递子组件---> path=this.props.path+field -父组件 <----onReportFields--- getChainPath(this.props.path, DepField) +containerPath=this.props.containerPath+field ----传递子组件---> containerPath=this.props.containerPath+field +父组件 <----onReportFields--- getChainPath(this.props.containerPath, DepField) 2. 正常来说,父组件的value就是子组件的record, 特殊的是tabs和form两个组件对应分别多了tab.field和index,这里通过Helper传递record时,取值分别对应下探到tab.field和index。 示例: diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 753da54..b8c0c81 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -66,7 +66,6 @@ export default class TabsField extends Field | null>> = [] formFieldsMountedList: Array> = [] - selfPath:string = '' // Tabs和formList需要保存自身路径传给子组件 constructor (props: FieldProps) { super(props) @@ -381,10 +380,6 @@ export default class TabsField extends Field { - if (!this.selfPath) { - this.selfPath = getChainPath(this.props.path, tab.field) - } - if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) @@ -447,7 +442,7 @@ export default class TabsField extends Field this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - path={getChainPath(this.props.path, `${tab.field}.${formFieldConfig.field}`)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field, tab.field)} onReportFields={async(field: string) => await this.handleReportFields(field)} /> ) diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index c566bb3..dcac904 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -145,7 +145,7 @@ export default class DetailStep extends Step { const detailData = cloneDeep(this.state.detailData) if (this.props.config.defaultValue) { - let detailDefault = ParamHelper(this.props.config.defaultValue, { data, step }, this) + let detailDefault = ParamHelper(this.props.config.defaultValue, { data, step }) if (this.props.config.unstringify) { for (const field of this.props.config.unstringify) { const info = getValue(detailDefault, field) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 07e9094..a6704ec 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -115,7 +115,7 @@ export default class FilterStep extends Step { this.formData = [] if (this.props.config.defaultValue) { - const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }, this) + const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }) for (const formFieldIndex in (this.props.config.fields || [])) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const value = (formFieldConfig.field === undefined || formFieldConfig.field === '') ? formDefault : get(formDefault, formFieldConfig.field) @@ -216,7 +216,7 @@ export default class FilterStep extends Step { this.formData = [] if (this.props.config.defaultValue) { - const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }, this) + const formDefault = ParamHelper(this.props.config.defaultValue, { data: this.props.data, step: this.props.step }) for (const formFieldIndex in (this.props.config.fields || [])) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] const value = (formFieldConfig.field === undefined || formFieldConfig.field === '') ? formDefault : get(formDefault, formFieldConfig.field) @@ -450,7 +450,7 @@ export default class FilterStep extends Step { submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ""), resetText: this.props.config?.resetText?.replace(/(^\s*)|(\s*$)/g, ""), children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -506,7 +506,7 @@ export default class FilterStep extends Step { 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)} - path={getChainPath(formFieldConfig.field)} + containerPath={''} /> ) } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 1092ece..cca1d8a 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -226,7 +226,7 @@ export default class FormStep extends Step { // ts对clas this.formData = [] if (this.props.config.defaultValue) { - let formDefault = ParamHelper(this.props.config.defaultValue, { data, step }, this) + let formDefault = ParamHelper(this.props.config.defaultValue, { data, step }) if (this.props.config.unstringify) { for (const field of this.props.config.unstringify) { @@ -301,9 +301,9 @@ export default class FormStep extends Step { // ts对clas this.submitData = {} if (this.props.config.validations) { for (const validation of this.props.config.validations) { - if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.formValue }, this)) { + if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.formValue })) { this.canSubmit = false - const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.formValue }, this) || '未填写失败文案或失败文案配置异常' + const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.formValue }) || '未填写失败文案或失败文案配置异常' this.renderModalComponent({ message }) return } @@ -603,7 +603,7 @@ export default class FormStep extends Step { // ts对clas if (Object.prototype.toString.call(actions) === '[object Array]') { actions_ = [] for (let index = 0, len = actions.length; index < len; index++) { - if (!ConditionHelper(actions[index].condition, { record: formValue, data, step: formValue }, this)) { + if (!ConditionHelper(actions[index].condition, { record: formValue, data, step: formValue })) { continue } if (actions[index].type === 'submit') { @@ -658,7 +658,7 @@ export default class FormStep extends Step { // ts对clas submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 cancelText: this.props.config?.cancelText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step: formValue })) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -702,7 +702,7 @@ export default class FormStep extends Step { // ts对clas : undefined, status, message: formData[formFieldIndex]?.message || '', - extra: StatementHelper(formFieldConfig.extra, { data: this.props.data, step: formValue }, this), + extra: StatementHelper(formFieldConfig.extra, { data: this.props.data, step: formValue }), required: getBoolean(formFieldConfig.required), layout, visitable: display, @@ -732,7 +732,7 @@ export default class FormStep extends Step { // ts对clas 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)} - path={getChainPath(formFieldConfig.field)} + containerPath={''} /> ) } diff --git a/src/steps/header/index.tsx b/src/steps/header/index.tsx index 671db3d..a7ec2d7 100644 --- a/src/steps/header/index.tsx +++ b/src/steps/header/index.tsx @@ -243,7 +243,7 @@ export default class HeaderStep extends Step { handleStatisticContent = (config: statisticContentConfig, _position: string) => { return (config.statistics || []).map((statistic, index) => { - const value = statistic.value ? ParamHelper(statistic.value, { data: this.props.data, step: this.props.step }, this) : undefined + const value = statistic.value ? ParamHelper(statistic.value, { data: this.props.data, step: this.props.step }) : undefined switch (statistic.type) { case 'value': return this.renderStatisticComponent({ diff --git a/src/util/param.ts b/src/util/param.ts index c9fc1d3..a02d243 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -2,15 +2,13 @@ import _, { get } from "lodash" import qs from "query-string" import { ParamConfig } from "../interface"; import { getChainPath } from '../util/value' +import { Field , FieldConfig } from '../components/formFields/common' -export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: any } }, _this: any) { // step--> stepValue +export default function ParamHelper (config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: unknown } }, _this?: Field) { // step--> stepValue switch (config.source) { case 'record': if (datas.record) { - if (_this) { - const fullPath = getChainPath(_this.selfPath || _this.props.path, config.field) - _this.handleReportFields(fullPath) - } + _this && _this.handleReportFields && _this.handleReportFields(getChainPath(_this.props.containerPath, config.field)) if (config.field === '') { return datas.record } else { @@ -20,11 +18,11 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj break case 'data': if (datas.step) { - _this && _this.handleReportFields(`${config.field}`) + _this && _this.handleReportFields && _this.handleReportFields(`${config.field}`) if (config.field === '') { return datas.step } else { - return get(datas.step, config.field) //return get(step, config.field) + return get(datas.step, config.field) // return get(step, config.field) } } break @@ -39,7 +37,7 @@ export default function ParamHelper ( config: ParamConfig, datas: { record?: obj break case 'step': if (datas.data[config.step]) { - _this && _this.handleReportFields(`${config.field}`) + _this && _this.handleReportFields && _this.handleReportFields(`${config.field}`) if (config.field === '') { return datas.data[config.step] } else { -- Gitee From 3711a6d9aff74e870b19a04ee6694f65f3d6c132 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Feb 2022 00:58:32 +0800 Subject: [PATCH 041/164] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=80?= =?UTF-8?q?=E9=95=BF=E5=85=B1=E5=90=8C=E5=89=8D=E7=BC=80=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/value.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/util/value.ts b/src/util/value.ts index c447f91..86903cb 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -130,6 +130,22 @@ export const getChainPath = (...arg: any[]) => { return fullPath } +/** + * + * @param source 来源字符串 + * @param find 目标字符串 + * @returns 返回目标字符串出现在来源字符串中所有索引 + */ + function indexes(source: string, find: string) { + var result = [] + for (let i = 0; i < source.length; ++i) { + if (source.substring(i, i + find.length) == find) { + result.push(i) + } + } + return result +} + /** * 获取一个数组中最长共同前缀 */ @@ -139,13 +155,24 @@ export const getLongestCommonPrefix = (arr: string[]) => { let c=arr[0].charAt(i); for (let j=1,len2=arr.length;j Date: Thu, 10 Feb 2022 11:08:43 +0800 Subject: [PATCH 042/164] =?UTF-8?q?fix:=20=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 23 +++--- src/components/formFields/group/index.tsx | 5 +- .../formFields/importSubform/index.tsx | 11 +-- src/components/formFields/object/index.tsx | 6 +- src/components/formFields/tabs/index.tsx | 15 ++-- src/steps/common.tsx | 2 +- src/steps/detail/index.tsx | 3 +- src/steps/filter/index.tsx | 7 +- src/steps/form/index.tsx | 22 +++--- src/steps/header/index.tsx | 18 ++--- src/util/condition.ts | 12 ++- src/util/enumeration.ts | 4 +- src/util/interface.ts | 30 ++++---- src/util/operation.tsx | 19 +++-- src/util/param.ts | 10 +-- src/util/produce.tsx | 57 +++++++------- src/util/statement.ts | 13 ++-- src/util/value.ts | 76 +++++++++---------- 18 files changed, 151 insertions(+), 182 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index e95af8e..7bc2146 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -220,7 +220,7 @@ export default class FormField extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step }, this)) { - if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, [] ) + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, []) // this.formFieldsMountedList[index][fieldIndex] = false this.formFieldsMountedList = set(this.formFieldsMountedList, `${[index]}.${fieldIndex}`, false) return null @@ -547,7 +544,7 @@ export default class FormField extends Field await this.props.loadDomain(domain)} containerPath={getChainPath(this.props.containerPath, this.props.config.field, index)} - onReportFields={async (field: string) => await this.handleReportFields(field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) }) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index a2be717..5737063 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -124,7 +124,6 @@ export default class GroupField extends Field { return 您当前使用的UI版本没有实现GroupField组件。 @@ -378,7 +375,7 @@ export default class GroupField extends Field await this.props.loadDomain(domain)} containerPath={getChainPath(this.props.containerPath, this.props.config.field)} - onReportFields={async(field: string) => await this.handleReportFields(field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index c296d83..986204a 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -1,11 +1,10 @@ import React from 'react' -import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' +import { getValue, getBoolean, getChainPath } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' -import { concat, uniq } from 'lodash' -import { set, setValue, push } from '../../../util/produce' +import { set, setValue } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import StatementHelper from '../../../util/statement' @@ -50,7 +49,6 @@ export default class ImportSubformField extends Field | null> = [] formFieldsMounted: Array = [] - interfaceHelper = new InterfaceHelper() constructor (props: FieldProps) { @@ -63,8 +61,6 @@ export default class ImportSubformField extends Field { await this.setState({ didMount: true @@ -313,7 +309,6 @@ export default class ImportSubformField extends Field { return 您当前使用的UI版本没有实现ImportSubformField组件。 @@ -450,7 +445,7 @@ export default class ImportSubformField extends Field await this.props.loadDomain(domain)} containerPath={getChainPath(this.props.containerPath, this.props.config.field)} - onReportFields={async(field: string) => await this.handleReportFields(field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) } diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 1ee93c8..99e1c92 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -165,13 +165,13 @@ export default class ObjectField extends Field { - if (!formDataList[key]) formDataList= set(formDataList, `[${key}]`, []) + if (!formDataList[key]) formDataList = set(formDataList, `[${key}]`, []) formDataList = set(formDataList, `[${key}][${formFieldIndex}]`, { status: 'normal' }) return { formDataList: formDataList } }) } else { await this.setState(({ formDataList }) => { - if (!formDataList[key]) formDataList= set(formDataList, `[${key}]`, []) + if (!formDataList[key]) formDataList = set(formDataList, `[${key}]`, []) formDataList = set(formDataList, `[${key}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) return { formDataList: formDataList } }) @@ -484,7 +484,7 @@ export default class ObjectField extends Field this.props.loadDomain(domain)} containerPath={getChainPath(this.props.containerPath, this.props.config.field, key)} - onReportFields={async(field: string) => await this.handleReportFields(field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) }) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index b8c0c81..6bb7967 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -2,9 +2,8 @@ import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from import getALLComponents from '../' import React from 'react' import ConditionHelper from '../../../util/condition' -import { get } from 'lodash' import { set, setValue } from '../../../util/produce' -import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' +import { getValue, getBoolean, getChainPath } from '../../../util/value' import StatementHelper from '../../../util/statement' export type TabsFieldConfig = TabsFieldConfig_Same | TabsFieldConfig_Diff @@ -218,7 +217,7 @@ export default class TabsField extends Field extends Field extends Field extends Field extends Field extends Field await this.props.loadDomain(domain)} containerPath={getChainPath(this.props.containerPath, this.props.config.field, tab.field)} - onReportFields={async(field: string) => await this.handleReportFields(field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} /> ) })} diff --git a/src/steps/common.tsx b/src/steps/common.tsx index c76cbec..ecd4181 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -40,7 +40,7 @@ export interface StepProps { /** * 页面步骤基类 */ - export default class Step extends React.Component, S> { +export default class Step extends React.Component, S> { static defaultProps = { config: { } diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index dcac904..179273f 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -389,8 +389,7 @@ export default class DetailStep extends Step { const { ready, - detailValue, - detailData + detailValue } = this.state if (ready) { diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index a6704ec..bb6e103 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -7,7 +7,7 @@ import ParamHelper from '../../util/param' import { get } from 'lodash' import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper from '../../util/condition' -import { getValue, getChainPath, updateCommonPrefixItem } from '../../util/value' +import { getValue } from '../../util/value' /** * 表单步骤配置文件格式定义 @@ -380,6 +380,7 @@ export default class FilterStep extends Step { }) } } + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { @@ -447,8 +448,8 @@ export default class FilterStep extends Step { {this.renderComponent({ onSubmit: this.props.config?.hiddenSubmit ? undefined : async () => this.handleSubmit(), onReset: this.props.config?.hiddenReset ? undefined : async () => this.handleReset(), - submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ""), - resetText: this.props.config?.resetText?.replace(/(^\s*)|(\s*$)/g, ""), + submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ''), + resetText: this.props.config?.resetText?.replace(/(^\s*)|(\s*$)/g, ''), children: fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index cca1d8a..79114bf 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -3,9 +3,8 @@ import { Field, FieldConfigs, FieldError } from '../../components/formFields/com import Step, { StepConfig, StepProps } from '../common' import getALLComponents from '../../components/formFields' import { ColumnsConfig, ParamConfig } from '../../interface' -import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../util/value' +import { getValue, getBoolean } from '../../util/value' import ParamHelper from '../../util/param' -import { get, unset } from 'lodash' import { push, splice, sort, set, setValue } from '../../util/produce' import ConditionHelper, { ConditionConfig } from '../../util/condition' import StatementHelper, { StatementConfig } from '../../util/statement' @@ -184,7 +183,6 @@ export default class FormStep extends Step { // ts对clas getALLComponents = (type: any): typeof Field => getALLComponents[type] OperationHelper = OperationHelper - // 各表单项所使用的UI组件的实例 formFields: Array | null> = [] formFieldsMounted: Array = [] @@ -199,7 +197,7 @@ export default class FormStep extends Step { // ts对clas * 初始化表单的值 * @param props */ - constructor(props: StepProps) { + constructor (props: StepProps) { super(props) this.state = { ready: false, @@ -578,10 +576,9 @@ export default class FormStep extends Step { // ts对clas }) } - render() { + render () { const { data, - step, config: { columns, // layout = 'horizontal', @@ -693,12 +690,12 @@ export default class FormStep extends Step { // ts对clas label: formFieldConfig.label, columns: columns?.enable ? { - type: formFieldConfig.columns?.type || columns?.type || 'span', - value: formFieldConfig.columns?.value || columns?.value || 1, - wrap: formFieldConfig.columns?.wrap || columns?.wrap || false, - gap: columns?.gap || 0, - rowGap: columns?.rowGap || 0 - } + type: formFieldConfig.columns?.type || columns?.type || 'span', + value: formFieldConfig.columns?.value || columns?.value || 1, + wrap: formFieldConfig.columns?.wrap || columns?.wrap || false, + gap: columns?.gap || 0, + rowGap: columns?.rowGap || 0 + } : undefined, status, message: formData[formFieldIndex]?.message || '', @@ -751,4 +748,3 @@ export default class FormStep extends Step { // ts对clas } } } - diff --git a/src/steps/header/index.tsx b/src/steps/header/index.tsx index a7ec2d7..2b8b574 100644 --- a/src/steps/header/index.tsx +++ b/src/steps/header/index.tsx @@ -75,7 +75,6 @@ export interface statisticContentConfig extends basicContentConfig { statistics?: (valueStatisticConfig | enumerationStatisticConfig)[] } - interface basicStatisticConfig { label?: string value?: ParamConfig @@ -337,20 +336,19 @@ export default class HeaderStep extends Step { switch (mainContent.type) { case 'plain': props.mainContent = this.handlePlainContent(mainContent, 'main') - break; + break case 'markdown': props.mainContent = this.handleMarkdownContent(mainContent, 'main') - break; + break case 'html': props.mainContent = this.handleHTMLContent(mainContent, 'main') - break; + break case 'detail': props.mainContent = this.handleDetailContent(mainContent, 'main') - break; + break case 'statistic': props.mainContent = this.handleStatisticContent(mainContent, 'main') - default: - break; + break } } @@ -359,12 +357,12 @@ export default class HeaderStep extends Step { switch (extraContent.type) { case 'statistic': props.extraContent = this.handleStatisticContent(extraContent, 'extra') - break; + break case 'image': props.extraContent = this.handleImageContent(extraContent, 'extra') - break; + break default: - break; + break } } diff --git a/src/util/condition.ts b/src/util/condition.ts index 989eec9..d42ef17 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,8 +1,7 @@ -// import { set, cloneDeep, template } from "lodash" -import { template } from "lodash" +import { template } from 'lodash' import { set } from '../util/produce' -import { ParamConfig } from "../interface"; -import ParamHelper from "./param"; +import { ParamConfig } from '../interface' +import ParamHelper from './param' export interface ConditionConfig { /** @@ -24,7 +23,7 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; } }, _this?: any): boolean { +export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; } }, _this?: any): boolean { if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { @@ -87,14 +86,13 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { if (param.field === '') { - statementParams = ParamHelper(param.data,datas, _this) + statementParams = ParamHelper(param.data, datas, _this) } else { statementParams = set(statementParams, param.field, ParamHelper(param.data, datas, _this)) } } }) } - try { const statement = statementTemplate(statementParams) try { diff --git a/src/util/enumeration.ts b/src/util/enumeration.ts index 0b3c41d..67b0c3d 100644 --- a/src/util/enumeration.ts +++ b/src/util/enumeration.ts @@ -1,5 +1,5 @@ -import { InterfaceConfig } from "./interface"; -import { getValue } from "./value"; +import { InterfaceConfig } from './interface' +import { getValue } from './value' export type EnumerationOptionsConfig = ManualEnumerationOptionsConfig | InterfaceEnumerationOptionsConfig diff --git a/src/util/interface.ts b/src/util/interface.ts index bdad0fc..308a05c 100644 --- a/src/util/interface.ts +++ b/src/util/interface.ts @@ -2,9 +2,9 @@ import { isEqual, template, get, merge } from "lodash" import { set } from '../util/produce' import axios, { AxiosRequestConfig } from 'axios' -import { ParamConfig } from "../interface"; -import ParamHelper from "./param"; -import { getValue } from "./value"; +import { ParamConfig } from '../interface' +import ParamHelper from './param' +import { getValue } from './value' export interface InterfaceConfig { domain?: string @@ -22,12 +22,12 @@ export interface InterfaceConfig { enable?: boolean, field?: string, value?: any, - success?: { type: 'none' } | - { type: 'modal', content?: { type: 'static', content?: string } | - { type: 'field', field?: string }}, - fail?: { type: 'none' } | + success?: { type: 'none' } | + { type: 'modal', content?: { type: 'static', content?: string } | + { type: 'field', field?: string }}, + fail?: { type: 'none' } | { type: 'modal', content?: {type: 'static', content?: string } | - {type: 'field', field?: string }} + {type: 'field', field?: string }} } response?: { @@ -185,12 +185,12 @@ export default class InterfaceHelper { merge(data, option.extra_data.data) } } - + // 缓存判断 if (config.cache && config.cache.global && Object.keys(InterfaceHelper.cache).includes(config.cache.global)) { resolve(InterfaceHelper.cache[config.cache.global]) } else if ( - (!config.cache || !config.cache.disabled) && + (!config.cache || !config.cache.disabled) && isEqual(this._config, config) && isEqual(this._url, url) && isEqual(this._params, params) && @@ -202,7 +202,7 @@ export default class InterfaceHelper { this._url = url this._params = params this._data = data - + const request: AxiosRequestConfig = { url, method: config.method || 'GET', @@ -213,10 +213,10 @@ export default class InterfaceHelper { if (config.method === 'POST') { request.data = data } - + try { const response = await axios(request).then((response) => response.data) - + if (config.condition && config.condition.enable) { if (get(response, config.condition.field || '') === config.condition.value) { if (config.condition.success) { @@ -246,7 +246,7 @@ export default class InterfaceHelper { return } } - + if (config.response) { if (Array.isArray(config.response)) { let content = {} @@ -287,4 +287,4 @@ export default class InterfaceHelper { } }) } -} \ No newline at end of file +} diff --git a/src/util/operation.tsx b/src/util/operation.tsx index 05a63ff..aa3c6c9 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -1,10 +1,10 @@ -import React from 'react'; -import queryString from 'query-string'; +import React from 'react' +import queryString from 'query-string' // import { set } from "lodash"; import { set } from '../util/produce' -import { ParamConfig } from "../interface"; -import { CCMSConfig, CCMSProps } from "../main"; -import { getParam } from "./value"; +import { ParamConfig } from '../interface' +import { CCMSConfig, CCMSProps } from '../main' +import { getParam } from './value' export type OperationConfig = CCMSOperationConfig @@ -51,7 +51,7 @@ interface CCMSInvisibleOperationConfig extends _CCMSOperationConfig { type CCMSOperationConfig = CCMSPopupOperationConfig | CCMSRedirectOperationConfig | CCMSWindowOperationConfig | CCMSInvisibleOperationConfig interface OperationHelperProps { - config?: OperationConfig, + config?: OperationConfig, datas: { record?: object, data: object[], step: { [field: string]: any; } }, checkPageAuth: (pageID: any) => Promise, loadPageURL: (pageID: any) => Promise, @@ -78,7 +78,7 @@ export default class OperationHelper extends React.Component 您当前使用的UI版本没有实现OpertionHelper组件。 @@ -108,7 +108,7 @@ export default class OperationHelper extends React.Component) { // step--> stepValue switch (config.source) { @@ -57,4 +57,4 @@ export default function ParamHelper (config: ParamConfig, datas: { record?: obje break } return undefined -} \ No newline at end of file +} diff --git a/src/util/produce.tsx b/src/util/produce.tsx index 68afdeb..2d97d10 100644 --- a/src/util/produce.tsx +++ b/src/util/produce.tsx @@ -1,8 +1,7 @@ -import produce, { setAutoFreeze, original } from 'immer' +import produce, { setAutoFreeze } from 'immer' import lodash from 'lodash' import { listItemMove } from '../util/value' -type OperationType = 'set' | 'push' | 'splice' /** * setAutoFreeze @@ -12,18 +11,17 @@ type OperationType = 'set' | 'push' | 'splice' */ setAutoFreeze(false) - /** * 对应loadsh 的set - * @param current - * @param path - * @param value - * @returns + * @param current + * @param path + * @param value + * @returns */ -export function set (current: any, path?: string, value?: any) { - let target = produce(current, (draft: any) => { +export function set(current: any, path?: string, value?: any) { + const target = produce(current, (draft: any) => { if (path) { - if (arguments.length == 2) { // 移除对象路径的属性 参数改动时同步修改这块 + if (arguments.length === 2) { // 移除对象路径的属性 参数改动时同步修改这块 lodash.unset(draft, path) } else { return lodash.set(draft, path, value) @@ -35,14 +33,14 @@ export function set (current: any, path?: string, value?: any) { } /** * current指定路径下的数组添加元素 - * @param current - * @param path - * @param value - * @returns + * @param current + * @param path + * @param value + * @returns */ export const push = (current: any, path: string = '', value?: any) => { const target = produce(current, (draft: any) => { - let list = lodash.get(draft, path) + const list = lodash.get(draft, path) if (!Array.isArray(list)) { // 如果指定路径下不是数组类型 var tempArr = [] tempArr.push(value) @@ -56,13 +54,13 @@ export const push = (current: any, path: string = '', value?: any) => { /** * current指定路径下的数组删除元素 - * @param current - * @param path - * @param index - * @param count - * @returns + * @param current + * @param path + * @param index + * @param count + * @returns */ -export const splice = (current: any, path: string='', index: number, count: number) => { +export const splice = (current: any, path: string = '', index: number, count: number) => { const target = produce(current, (draft: any) => { const list = lodash.get(draft, path, []) list.splice(index, count) @@ -73,12 +71,12 @@ export const splice = (current: any, path: string='', index: number, count: numb /** * current指定路径下数组排序 * @param current - * @param path - * @param index - * @param sortType - * @returns + * @param path + * @param index + * @param sortType + * @returns */ -export const sort = (current: any, path: string='', index: number, sortType: 'up' | 'down') => { +export const sort = (current: any, path: string = '', index: number, sortType: 'up' | 'down') => { const target = produce(current, (draft: any) => { const list = lodash.get(draft, path, []) listItemMove(list, index, sortType) @@ -86,12 +84,11 @@ export const sort = (current: any, path: string='', index: number, sortType: 'up return target } - /** * lodash 递归合并来源对象的自身和继承的可枚举属性到目标对象 * @param a 目标对象 * @param b 来源对象 - * @returns + * @returns */ const merge = (a: any, b: any): any => { return lodash.assignInWith(a, b, (a, b) => { @@ -109,7 +106,7 @@ const merge = (a: any, b: any): any => { } export const setValue = (obj: any, path: string = '', value: any) => { - let target = produce(obj, (draft: any) => { + const target = produce(obj, (draft: any) => { if (path === '') { if (Object.prototype.toString.call(value) === '[object Object]') { draft = merge(draft, value) @@ -126,4 +123,4 @@ export const setValue = (obj: any, path: string = '', value: any) => { } }) return target -} \ No newline at end of file +} diff --git a/src/util/statement.ts b/src/util/statement.ts index 4cbcf42..fd7c9fa 100644 --- a/src/util/statement.ts +++ b/src/util/statement.ts @@ -1,15 +1,14 @@ -// import { set, cloneDeep, template } from "lodash" -import { template } from "lodash" +import { template } from 'lodash' import { set } from '../util/produce' -import { ParamConfig } from "../interface"; -import ParamHelper from "./param"; +import { ParamConfig } from '../interface' +import ParamHelper from './param' export interface StatementConfig { statement: string params: { field: string, data: ParamConfig }[] } -export default function StatementHelper(config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }}, _this?: any): string { +export default function StatementHelper (config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }}, _this?: any): string { if (config === undefined || config.statement === undefined || config.statement === '') { return '' } else { @@ -26,7 +25,7 @@ export default function StatementHelper(config: StatementConfig | undefined, dat } }) } - + try { const statement = statementTemplate(statementParams) return statement @@ -35,4 +34,4 @@ export default function StatementHelper(config: StatementConfig | undefined, dat return '' } } -} \ No newline at end of file +} diff --git a/src/util/value.ts b/src/util/value.ts index 86903cb..c21ce55 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -1,7 +1,6 @@ import queryString from 'query-string' import { ParamConfig } from '../interface' import { set, get, isArray, assignInWith, isObject, isUndefined } from 'lodash' -import { FieldConfig } from '../components/formFields/common' export const getValue = (obj: any, path: string = '', defaultValue: any = undefined) => { if (path === undefined) { @@ -115,31 +114,30 @@ export const listItemMove = (list: any[], currentIndex: number, sortType: 'up' | switch (sortType) { case 'up': currentIndex !== 0 && (list[currentIndex] = list.splice(currentIndex - 1, 1, list[currentIndex])[0]) - break; + break case 'down': currentIndex < list.length - 1 && (list[currentIndex] = list.splice(currentIndex + 1, 1, list[currentIndex])[0]) - break; + break } return list } // 参数转化为链式路径 export const getChainPath = (...arg: any[]) => { - const _fullPath = arg.join('.') + const _fullPath = arg.join('.') const fullPath = _fullPath.replace(/(^\.*)|(\.*$)|(\.){2,}/g, '$3') return fullPath } /** - * * @param source 来源字符串 * @param find 目标字符串 * @returns 返回目标字符串出现在来源字符串中所有索引 */ - function indexes(source: string, find: string) { - var result = [] +function indexes (source: string, find: string) { + const result = [] for (let i = 0; i < source.length; ++i) { - if (source.substring(i, i + find.length) == find) { + if (source.substring(i, i + find.length) === find) { result.push(i) } } @@ -150,52 +148,48 @@ export const getChainPath = (...arg: any[]) => { * 获取一个数组中最长共同前缀 */ export const getLongestCommonPrefix = (arr: string[]) => { - if (arr.length===0 ||arr[0].length===0){return "";} - for (let i=0,len1=arr[0].length;i { - const reg = /[^\.]+(?=\.?)/ +export const updateCommonPrefixItem = (arr: string[], sourceField: string): string[] | boolean => { + const reg = /[^\\.]+(?=\.?)/ const sourceFieldPrefix = sourceField.match(reg)?.[0] const commonPrefixItemS = [sourceField] - for(let i=arr.length - 1;i>=0;i--) { - const arrItem = arr[i] - if (sourceField.includes(arrItem)) { - return false - } - const arrItemPrefix = arrItem.match(reg)?.[0] - if (arrItemPrefix && arrItemPrefix === sourceFieldPrefix) { - arr.splice(i, 1) - commonPrefixItemS.push(arrItem) - } - + for (let i = arr.length - 1; i >= 0; i--) { + const arrItem = arr[i] + if (sourceField.includes(arrItem)) { + return false } - + const arrItemPrefix = arrItem.match(reg)?.[0] + if (arrItemPrefix && arrItemPrefix === sourceFieldPrefix) { + arr.splice(i, 1) + commonPrefixItemS.push(arrItem) + } + } + arr.push(getLongestCommonPrefix(commonPrefixItemS)) return arr } -- Gitee From c86083aea366635d49fb358d942c242310c8ade6 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Feb 2022 11:51:14 +0800 Subject: [PATCH 043/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9paramHelper=20?= =?UTF-8?q?TS=E6=8A=A5=E9=94=99?= 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 | 4 ++-- src/components/formFields/group/index.tsx | 2 +- src/components/formFields/tabs/index.tsx | 4 +--- src/util/param.ts | 8 ++++---- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 01f5d11..a856135 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -140,7 +140,7 @@ export class Field extends React.Component< /** * 获取默认值 */ - async defaultValue (this: any) { + defaultValue : () => Promise = async () => { const { config } = this.props diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 7bc2146..c67dcbb 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -2,8 +2,8 @@ import React from 'react' import { Field, FieldConfig, FieldConfigs, FieldError, FieldProps, IField } from '../common' import getALLComponents from '../' // import { cloneDeep } from 'lodash' -import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' -import { set, setValue , sort, splice, push } from '../../../util/produce' +import { getValue, getBoolean, getChainPath } from '../../../util/value' +import { set, setValue, sort, splice } from '../../../util/produce' import ConditionHelper from '../../../util/condition' import StatementHelper from '../../../util/statement' diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 5737063..c74bccc 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { getValue, getBoolean, getChainPath, updateCommonPrefixItem } from '../../../util/value' +import { getValue, getBoolean, getChainPath } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' import getALLComponents, { FieldConfigs } from '../' import { IFormItem } from '../../../steps/form' diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 6bb7967..e4b8aaf 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -183,7 +183,7 @@ export default class TabsField extends Field { if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) - formDataList= set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'normal' }) + formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'normal' }) return { formDataList: formDataList } }) } else { @@ -322,8 +322,6 @@ export default class TabsField extends Field) { // step--> stepValue +export default function ParamHelper (config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: unknown } }, _this?: Field) { // 1.3.0新增 step由索引变为formValue switch (config.source) { case 'record': if (datas.record) { @@ -22,7 +22,7 @@ export default function ParamHelper (config: ParamConfig, datas: { record?: obje if (config.field === '') { return datas.step } else { - return get(datas.step, config.field) // return get(step, config.field) + return get(datas.step, config.field) } } break -- Gitee From 80ea69b33eb52ecc0273ef084cabbdfa3436b1a4 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Feb 2022 15:16:32 +0800 Subject: [PATCH 044/164] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0extraContaine?= =?UTF-8?q?rPath=E5=A4=84=E7=90=86=E8=A1=A8=E5=8D=95=E9=A1=B9=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=9C=A8=E5=AE=B9=E5=99=A8=E7=BB=84=E4=BB=B6=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8A=E5=B1=82=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 8 ++++---- src/components/formFields/group/index.tsx | 8 ++++---- src/components/formFields/importSubform/index.tsx | 6 +++--- src/components/formFields/tabs/index.tsx | 6 +++--- src/util/condition.ts | 2 +- src/util/interface.ts | 2 +- src/util/param.ts | 7 +++++-- src/util/statement.ts | 2 +- 8 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index c67dcbb..c2bf259 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -187,7 +187,7 @@ export default class FormField extends Field { - var list = this.state.formDataList + const list = this.state.formDataList const formDataList = sort(list, '', index, sortType) this.setState({ formDataList: formDataList @@ -491,7 +491,7 @@ export default class FormField extends Field 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 }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step, extraContainerPath: this.props.config.field }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, []) // this.formFieldsMountedList[index][fieldIndex] = false this.formFieldsMountedList = set(this.formFieldsMountedList, `${[index]}.${fieldIndex}`, false) @@ -513,7 +513,7 @@ export default class FormField extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step, extraContainerPath: this.props.config.field }, this)) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -345,7 +345,7 @@ export default class GroupField extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step, extraContainerPath: this.props.config.field }, this)) { this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) return null } @@ -414,7 +414,7 @@ export default class ImportSubformField extends Field extends Field extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: this.props.config.field }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) return null @@ -413,7 +413,7 @@ export default class TabsField extends Field Promise extra_data?: { params?: any, data?: any } diff --git a/src/util/param.ts b/src/util/param.ts index 03ab1e1..1d041c2 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -4,11 +4,14 @@ import { ParamConfig } from '../interface' import { getChainPath } from '../util/value' import { Field } from '../components/formFields/common' -export default function ParamHelper (config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: unknown } }, _this?: Field) { // 1.3.0新增 step由索引变为formValue +export default function ParamHelper (config: ParamConfig, datas: { record?: object, data: object[], step: { [field: string]: unknown }, extraContainerPath?: string }, _this?: Field) { // 1.3.0新增 step由索引变为formValue switch (config.source) { case 'record': if (datas.record) { - _this && _this.handleReportFields && _this.handleReportFields(getChainPath(_this.props.containerPath, config.field)) + if (_this) { + const fullPath = datas.extraContainerPath ? getChainPath(_this.props.containerPath, datas.extraContainerPath, config.field) : getChainPath(_this.props.containerPath, config.field) + _this.handleReportFields && _this.handleReportFields(getChainPath(fullPath)) + } if (config.field === '') { return datas.record } else { diff --git a/src/util/statement.ts b/src/util/statement.ts index fd7c9fa..6ee50ac 100644 --- a/src/util/statement.ts +++ b/src/util/statement.ts @@ -8,7 +8,7 @@ export interface StatementConfig { params: { field: string, data: ParamConfig }[] } -export default function StatementHelper (config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }}, _this?: any): string { +export default function StatementHelper (config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }, extraContainerPath?: string }, _this?: any): string { if (config === undefined || config.statement === undefined || config.statement === '') { return '' } else { -- Gitee From 740130bae12c2be8eed1eaf791e42cc74706ab99 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Feb 2022 15:52:57 +0800 Subject: [PATCH 045/164] =?UTF-8?q?fix:=20subform=E3=80=81group=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E9=A1=B9record=E5=8F=96=E5=80=BCvalue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/importSubform/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 3fdb533..0217651 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -431,7 +431,7 @@ export default class ImportSubformField extends Field Date: Thu, 10 Feb 2022 16:40:10 +0800 Subject: [PATCH 046/164] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84tab=E5=92=8Cfo?= =?UTF-8?q?rm=E7=9A=84extraContainerPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 3 +-- src/components/formFields/form/index.tsx | 6 +++--- src/components/formFields/tabs/index.tsx | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index a856135..42b527c 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -140,7 +140,7 @@ export class Field extends React.Component< /** * 获取默认值 */ - defaultValue : () => Promise = async () => { + defaultValue : () => Promise = async () => { const { config } = this.props @@ -178,7 +178,6 @@ export class Field extends React.Component< * @param field */ handleReportFields: (field: string) => void = async (field) => { - // if (this.dependentFields.includes(field)) return const update: string[] | boolean = updateCommonPrefixItem(this.dependentFields, field) if (typeof update === 'boolean') return this.dependentFields = update diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index c2bf259..ec0a425 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -187,7 +187,7 @@ export default class FormField extends Field 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, extraContainerPath: this.props.config.field }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: itemValue, data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, index) }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, []) // this.formFieldsMountedList[index][fieldIndex] = false this.formFieldsMountedList = set(this.formFieldsMountedList, `${[index]}.${fieldIndex}`, false) @@ -513,7 +513,7 @@ export default class FormField extends Field extends Field extends Field { - if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: this.props.config.field }, this)) { + if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, tab.field) }, this)) { if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) return null @@ -413,7 +413,7 @@ export default class TabsField extends Field Date: Thu, 10 Feb 2022 17:48:45 +0800 Subject: [PATCH 047/164] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=E5=87=BA?= =?UTF-8?q?handleValueCallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 221 ++++++-------- src/components/formFields/group/index.tsx | 84 ++---- .../formFields/importSubform/index.tsx | 82 ++---- src/components/formFields/tabs/index.tsx | 278 ++++++++---------- 4 files changed, 254 insertions(+), 411 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index ec0a425..dbc4b0b 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -168,7 +168,7 @@ export default class FormField extends Field { + let formDataList = this.state.formDataList + if (validation === true) { + formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'normal' }) + } else { + formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) + } + + this.setState({ + formDataList + }) + } + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { @@ -329,16 +345,7 @@ export default class FormField extends Field { return - {this.renderItemComponent({ - index, - isLastIndex: value.length - 1 === index, - title: primaryField !== undefined ? getValue(itemValue, primaryField, '').toString() : index.toString(), - removeText: removeText === undefined - ? `删除 ${label}` - : removeText, - onRemove: canRemove ? async () => await this.handleRemove(index) : 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, extraContainerPath: getChainPath(this.props.config.field, index) }, this)) { - if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, []) - // this.formFieldsMountedList[index][fieldIndex] = false - this.formFieldsMountedList = set(this.formFieldsMountedList, `${[index]}.${fieldIndex}`, false) - return null - } - const FormField = this.getALLComponents(formFieldConfig.type) || Field - - let status = ((this.state.formDataList[index] || [])[fieldIndex] || {}).status || 'normal' - - if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { - status = 'normal' - } - // 渲染表单项容器 - return ( -
- { - this.renderItemFieldComponent({ - index: fieldIndex, - label: formFieldConfig.label, - status, - message: ((this.state.formDataList[index] || [])[fieldIndex] || {}).message || '', - extra: StatementHelper(formFieldConfig.extra, { record: itemValue, data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, index) }, this), - required: getBoolean(formFieldConfig.required), - layout: formLayout, - fieldType: formFieldConfig.type, - children: ( - | null) => { - if (fieldRef) { - if (!this.formFieldsList[index]) this.formFieldsList = set(this.formFieldsList, `[${index}]`, []) - // this.formFieldsList[index][fieldIndex] = fieldRef - this.formFieldsList = set(this.formFieldsList, `[${index}][${fieldIndex}]`, fieldRef) - this.handleMount(index, fieldIndex) - } - }} - form={this.props.form} - formLayout={formLayout} - value={getValue(value[index], formFieldConfig.field)} - record={value[index]} - step={this.props.step} - data={data} - // step={step} - config={formFieldConfig} - onChange={(value: any) => 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)} - baseRoute={this.props.baseRoute} - loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - containerPath={getChainPath(this.props.containerPath, this.props.config.field, index)} - onReportFields={async (field: string) => await this.handleReportFields(field)} - /> - ) - }) - } -
- ) - }) + {this.renderItemComponent({ + index, + isLastIndex: value.length - 1 === index, + title: primaryField !== undefined ? getValue(itemValue, primaryField, '').toString() : index.toString(), + removeText: removeText === undefined + ? `删除 ${label}` + : removeText, + onRemove: canRemove ? async () => await this.handleRemove(index) : 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, extraContainerPath: getChainPath(this.props.config.field, index) }, this)) { + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `${index}`, []) + // this.formFieldsMountedList[index][fieldIndex] = false + this.formFieldsMountedList = set(this.formFieldsMountedList, `${[index]}.${fieldIndex}`, false) + return null + } + const FormField = this.getALLComponents(formFieldConfig.type) || Field + + let status = ((this.state.formDataList[index] || [])[fieldIndex] || {}).status || 'normal' + + if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { + status = 'normal' + } + // 渲染表单项容器 + return ( +
+ { + this.renderItemFieldComponent({ + index: fieldIndex, + label: formFieldConfig.label, + status, + message: ((this.state.formDataList[index] || [])[fieldIndex] || {}).message || '', + extra: StatementHelper(formFieldConfig.extra, { record: itemValue, data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, index) }, this), + required: getBoolean(formFieldConfig.required), + layout: formLayout, + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (fieldRef) { + if (!this.formFieldsList[index]) this.formFieldsList = set(this.formFieldsList, `[${index}]`, []) + // this.formFieldsList[index][fieldIndex] = fieldRef + this.formFieldsList = set(this.formFieldsList, `[${index}][${fieldIndex}]`, fieldRef) + this.handleMount(index, fieldIndex) + } + }} + form={this.props.form} + formLayout={formLayout} + value={getValue(value[index], formFieldConfig.field)} + record={value[index]} + step={this.props.step} + data={data} + // step={step} + config={formFieldConfig} + onChange={(value: any) => 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field, index)} + onReportFields={async (field: string) => await this.handleReportFields(field)} + /> + ) + }) + } +
+ ) }) - } -
+ }) + } +
} ) : [] diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 3d2cc03..69ff1bf 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -136,17 +136,7 @@ export default class GroupField extends Field { - formData = set(formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) - return { formData: formData } - }) - } else { - await this.setState(({ formData }) => { - formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) - return { formData: formData } - }) - } + this.handleValueCallback(formFieldIndex, validation) } await formField.didMount() } @@ -182,21 +172,28 @@ export default class GroupField extends Field { + let formData = this.state.formData + if (validation === true) { + formData = set(formData, `[${formFieldIndex}]`, { status: 'normal' }) + } else { + formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) + } + + await this.setState({ + formData + }) + } + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` await this.props.onValueSet(fullPath, value, true) - let formData = this.state.formData - if (validation === true) { - formData = set(formData, `[${formFieldIndex}]`, { status: 'normal' }) - } else { - formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) - } - - this.setState({ - formData - }) + this.handleValueCallback(formFieldIndex, validation) } } @@ -205,16 +202,7 @@ export default class GroupField extends Field { - formData = set(formData, `[${formFieldIndex}]`, { status: 'normal' }) - return { formData: formData } - }) - } else { - await this.setState(({ formData }) => { - formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) - return { formData: formData } - }) - } + this.handleValueCallback(formFieldIndex, validation) } await formField.didMount() } @@ -209,6 +199,21 @@ export default class ImportSubformField extends Field { + let formData = this.state.formData + if (validation === true) { + formData = set(formData, `[${formFieldIndex}]`, { status: 'normal' }) + } else { + formData = set(formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message }) + } + await this.setState({ + formData + }) + } + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { @@ -216,16 +221,7 @@ export default class ImportSubformField extends Field extends Field { - if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) - formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'normal' }) - return { formDataList: formDataList } - }) - } else { - await this.setState(({ formDataList }) => { - if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) - formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) - return { formDataList: formDataList } - }) - } + this.handleValueCallback(index, formFieldIndex, validation) } await formField.didMount() } @@ -202,6 +190,23 @@ export default class TabsField extends Field { } + /** + * 处理set、unset、append、splice、sort后的操作 + */ + handleValueCallback = async (index: number, formFieldIndex: number, validation: true | FieldError[]) => { + let formDataList = this.state.formDataList + // if (!formDataList[index]) formDataList = set(formDataList, `[${index}]`, []) + if (validation === true) { + formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'normal' }) + } else { + formDataList = set(formDataList, `[${index}][${formFieldIndex}]`, { status: 'error', message: validation[0].message }) + } + + this.setState({ + formDataList + }) + } + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { const tab = (this.props.config.tabs || [])[index] @@ -212,17 +217,7 @@ export default class TabsField extends Field extends Field extends Field extends Field extends Field extends Field { - return + renderItemComponent = (props: ITabsFieldItem) => { + return 您当前使用的UI版本没有实现FormField组件的renderItemComponent方法。 - } + } - /** - * 用于展示子表单组件中的每一子项中的每一个子表单项组件 - * @param props - * @returns - */ - renderItemFieldComponent = (props: ITabsFieldItemField) => { - return + /** + * 用于展示子表单组件中的每一子项中的每一个子表单项组件 + * @param props + * @returns + */ + renderItemFieldComponent = (props: ITabsFieldItemField) => { + return 您当前使用的UI版本没有实现FormField组件的renderItemFieldComponent方法。 - } + } render = () => { const { - value = {}, - config: { - label - } + value = {} } = this.props return ( @@ -372,86 +324,86 @@ export default class TabsField extends Field { const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) return ( - - {this.renderItemComponent({ - key: index.toString(), - label: tab.label, - children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, tab.field) }, this)) { - if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) - this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) - return null - } - let hidden: boolean = true - let display: boolean = true - - if (formFieldConfig.type === 'hidden') { - hidden = true - display = false - } - - if (formFieldConfig.display === 'none') { - hidden = true - display = false - } - - const FormField = this.getALLComponents(formFieldConfig.type) || Field - - let status = ((this.state.formDataList[index] || [])[formFieldIndex] || {}).status || 'normal' - - if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { - status = 'normal' - } - - // 渲染表单项容器 - if (hidden) { - return ( -
- {this.renderItemFieldComponent({ - index: formFieldIndex, - label: formFieldConfig.label, - status, - message: ((this.state.formDataList[index] || [])[formFieldIndex] || {}).message || '', - required: getBoolean(formFieldConfig.required), - extra: StatementHelper(formFieldConfig.extra, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, tab.field) }, this), - layout: this.props.formLayout, - fieldType: formFieldConfig.type, - children: ( - | null) => { - if (!this.formFieldsList[index]) this.formFieldsList = set(this.formFieldsList, `[${index}]`, []) - this.formFieldsList = set(this.formFieldsList, `[${index}][${formFieldIndex}]`, formField) - this.handleMount(index, formFieldIndex) - }} - form={this.props.form} - formLayout={this.props.formLayout} - value={getValue(value, getChainPath(tab.field, formFieldConfig.field))} - record={getValue(value, tab.field)} - data={this.props.data} - step={this.props.step} - config={formFieldConfig} - onChange={(value: any) => 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)} - baseRoute={this.props.baseRoute} - loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - containerPath={getChainPath(this.props.containerPath, this.props.config.field, tab.field)} - onReportFields={async (field: string) => await this.handleReportFields(field)} - /> - ) - })} -
- ) - } else { - return - } - }) - })} - + + {this.renderItemComponent({ + key: index.toString(), + label: tab.label, + children: fields.map((formFieldConfig, formFieldIndex) => { + if (!ConditionHelper(formFieldConfig.condition, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, tab.field) }, this)) { + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}]`, []) + this.formFieldsMountedList = set(this.formFieldsMountedList, `[${index}][${formFieldIndex}]`, false) + return null + } + let hidden: boolean = true + let display: boolean = true + + if (formFieldConfig.type === 'hidden') { + hidden = true + display = false + } + + if (formFieldConfig.display === 'none') { + hidden = true + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Field + + let status = ((this.state.formDataList[index] || [])[formFieldIndex] || {}).status || 'normal' + + if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { + status = 'normal' + } + + // 渲染表单项容器 + if (hidden) { + return ( +
+ {this.renderItemFieldComponent({ + index: formFieldIndex, + label: formFieldConfig.label, + status, + message: ((this.state.formDataList[index] || [])[formFieldIndex] || {}).message || '', + required: getBoolean(formFieldConfig.required), + extra: StatementHelper(formFieldConfig.extra, { record: getValue(value, tab.field), data: this.props.data, step: this.props.step, extraContainerPath: getChainPath(this.props.config.field, tab.field) }, this), + layout: this.props.formLayout, + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (!this.formFieldsList[index]) this.formFieldsList = set(this.formFieldsList, `[${index}]`, []) + this.formFieldsList = set(this.formFieldsList, `[${index}][${formFieldIndex}]`, formField) + this.handleMount(index, formFieldIndex) + }} + form={this.props.form} + formLayout={this.props.formLayout} + value={getValue(value, getChainPath(tab.field, formFieldConfig.field))} + record={getValue(value, tab.field)} + data={this.props.data} + step={this.props.step} + config={formFieldConfig} + onChange={(value: any) => 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field, tab.field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} + /> + ) + })} +
+ ) + } else { + return + } + }) + })} + ) }) : [] -- Gitee From a796efa05e854eddada9bd50314329941c0bf147 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Feb 2022 18:24:13 +0800 Subject: [PATCH 048/164] =?UTF-8?q?style:=20any=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/any/index.tsx | 121 +++++++++--------- .../formFields/importSubform/index.tsx | 1 - 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index 566caf9..996a04c 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -30,8 +30,7 @@ export default class AnyField extends Field { const { - value, - onChange + value } = this.props if (type === 'null') { this.props.onValueSet('', null, true) @@ -81,63 +80,67 @@ export default class AnyField extends Field this.handleChangeType(type) }), - valueContent: type === 'string' ? {}} - form={this.props.form} - formLayout={'horizontal'} - value={typeof value === 'string' ? value : ''} - record={record} - data={_.cloneDeep(data)} - step={step} - config={{ type: 'text', field: '', label: '' }} - onChange={async (value: string) => { await onChange(value) }} - onValueSet={this.props.onValueSet} - onValueUnset={this.props.onValueUnset} - onValueListAppend={this.props.onValueListAppend} - onValueListSplice={this.props.onValueListSplice} - onValueListSort={this.props.onValueListSort} - baseRoute={this.props.baseRoute} - loadDomain={this.props.loadDomain} - containerPath={getChainPath(this.props.containerPath, '')} - /> : ( - type === 'number' ? {}} - form={this.props.form} - formLayout={'horizontal'} - record={record} - value={typeof value === 'number' ? value : ''} - data={_.cloneDeep(data)} - step={step} - config={{ type: 'number', field: '', label: '' }} - onChange={async (value) => { await onChange(Number(value)) }} - onValueSet={async (path, value, validation) => await this.props.onValueSet(path, Number(value), validation)} - onValueUnset={this.props.onValueUnset} - onValueListAppend={this.props.onValueListAppend} - onValueListSplice={this.props.onValueListSplice} - onValueListSort={this.props.onValueListSort} - baseRoute={this.props.baseRoute} - loadDomain={this.props.loadDomain} - containerPath={getChainPath(this.props.containerPath, '')} - /> : {}} - form={this.props.form} - formLayout={'horizontal'} - record={record} - value={typeof value === 'boolean' ? value : false} - data={_.cloneDeep(data)} - step={step} - config={{ type: 'switch', field: '', label: '' }} - onChange={async (value) => { await onChange(Boolean(value)) }} - onValueSet={this.props.onValueSet} - onValueUnset={this.props.onValueUnset} - onValueListAppend={this.props.onValueListAppend} - onValueListSplice={this.props.onValueListSplice} - onValueListSort={this.props.onValueListSort} - baseRoute={this.props.baseRoute} - loadDomain={this.props.loadDomain} - containerPath={getChainPath(this.props.containerPath, '')} - /> - ) + valueContent: + type === 'string' + ? {}} + form={this.props.form} + formLayout={'horizontal'} + value={typeof value === 'string' ? value : ''} + record={record} + data={_.cloneDeep(data)} + step={step} + config={{ type: 'text', field: '', label: '' }} + onChange={async (value: string) => { await onChange(value) }} + onValueSet={this.props.onValueSet} + onValueUnset={this.props.onValueUnset} + onValueListAppend={this.props.onValueListAppend} + onValueListSplice={this.props.onValueListSplice} + onValueListSort={this.props.onValueListSort} + baseRoute={this.props.baseRoute} + loadDomain={this.props.loadDomain} + containerPath={getChainPath(this.props.containerPath, '')} + /> + : ( + type === 'number' + ? {}} + form={this.props.form} + formLayout={'horizontal'} + record={record} + value={typeof value === 'number' ? value : ''} + data={_.cloneDeep(data)} + step={step} + config={{ type: 'number', field: '', label: '' }} + onChange={async (value) => { await onChange(Number(value)) }} + onValueSet={async (path, value, validation) => await this.props.onValueSet(path, Number(value), validation)} + onValueUnset={this.props.onValueUnset} + onValueListAppend={this.props.onValueListAppend} + onValueListSplice={this.props.onValueListSplice} + onValueListSort={this.props.onValueListSort} + baseRoute={this.props.baseRoute} + loadDomain={this.props.loadDomain} + containerPath={getChainPath(this.props.containerPath, '')} + /> + : {}} + form={this.props.form} + formLayout={'horizontal'} + record={record} + value={typeof value === 'boolean' ? value : false} + data={_.cloneDeep(data)} + step={step} + config={{ type: 'switch', field: '', label: '' }} + onChange={async (value) => { await onChange(Boolean(value)) }} + onValueSet={this.props.onValueSet} + onValueUnset={this.props.onValueUnset} + onValueListAppend={this.props.onValueListAppend} + onValueListSplice={this.props.onValueListSplice} + onValueListSort={this.props.onValueListSort} + baseRoute={this.props.baseRoute} + loadDomain={this.props.loadDomain} + containerPath={getChainPath(this.props.containerPath, '')} + />) })}
) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 0c846ff..d60bd69 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -291,7 +291,6 @@ export default class ImportSubformField extends Field Date: Fri, 11 Feb 2022 19:26:10 +0800 Subject: [PATCH 049/164] build: use rollup --- .babelrc | 24 ++++++++++++ .eslintrc | 31 +++++++++++++++ .eslintrc.js | 27 ------------- .fatherrc.js | 21 ----------- package.json | 98 ++++++++++++++++++++++++------------------------ rollup.config.js | 41 ++++++++++++++++++++ tsconfig.json | 34 ++++++++++------- 7 files changed, 164 insertions(+), 112 deletions(-) create mode 100644 .babelrc create mode 100644 .eslintrc delete mode 100644 .eslintrc.js delete mode 100644 .fatherrc.js create mode 100644 rollup.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..0792683 --- /dev/null +++ b/.babelrc @@ -0,0 +1,24 @@ +{ + "sourceMaps": true, + "presets": [ + [ + "@babel/preset-typescript", + { + "isTSX": true, + "allExtensions": true + } + ], + "@babel/preset-react", + [ + "@babel/preset-env", + { + "targets": { + "node": "10.13.0" + }, + // "modules": false + //将 ES6 module 转换为其他模块规范,可选 "adm" | "umd" | "systemjs" | "commonjs" | "cjs" | false,默认为 false + // 否则 Babel 会在 Rollup 有机会做处理之前,将我们的模块转成 CommonJS ,导致 Rollup 的一些处理失败。 + } + ] + ] +} \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..e88f05d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,31 @@ +{ + "env": { + "browser": true, + "es2021": true, + "jest": true, + "node": true, + "commonjs": true, + "es6": true + }, + "parser": "@typescript-eslint/parser", + "plugins": [ + "react", + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "standard" + ], + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "rules": { + "no-use-before-define": "off", + "react/display-name": 0 + } +} \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 797152f..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,27 +0,0 @@ -module.exports = { - env: { - browser: true, - es2021: true, - jest: true - }, - extends: [ - 'plugin:react/recommended', - 'standard' - ], - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaFeatures: { - jsx: true - }, - ecmaVersion: 12, - sourceType: 'module' - }, - plugins: [ - 'react', - '@typescript-eslint' - ], - rules: { - 'no-use-before-define': 'off', - 'react/display-name': 0 - } -} diff --git a/.fatherrc.js b/.fatherrc.js deleted file mode 100644 index c9b7c09..0000000 --- a/.fatherrc.js +++ /dev/null @@ -1,21 +0,0 @@ -export default { - entry: 'src/index.tsx', - esm: "rollup", - cjs: { - type: "babel", - lazy: true - }, - cssModules: true, - injectCSS: true, - lessInBabelMode: true, - doc: { - typescript: true - }, - extraBabelPlugins: [ - ['babel-plugin-import', { - libraryName: 'antd', - libraryDirectory: 'es', - style: true, - }], - ] -} \ No newline at end of file diff --git a/package.json b/package.json index 91472ce..27772ca 100644 --- a/package.json +++ b/package.json @@ -10,76 +10,74 @@ "dist" ], "scripts": { - "build": "father build", - "dev": "father doc dev", - "lint-init": "eslint --init", - "lint": "eslint src --ext .ts", + "dev": "npm-watch build", + "build": "npm run clear && npm run build:rollup && npm run build:babel", + "build:rollup": "rollup -c", + "build:babel": "babel src -d lib -s -x '.ts,.tsx'", + "clear": "rm -rf dist && rm -rf lib", "test": "jest", - "test:u": "npm test -- -u" + "test:u": "npm test -- -u", + "lint": "eslint src/** --fix" }, + "keywords": [ + "ccms" + ], "author": "niuweb", "license": "MIT", + "dependencies": { + "@types/react": "^16.9.46", + "@types/react-router-dom": "^5.1.5", + "axios": "^0.20.0", + "lodash": "^4.17.21", + "marked": "^1.2.5", + "moment": "^2.29.0", + "qiankun": "^2.5.1", + "query-string": "^6.13.8", + "rc-table": "^7.9.10", + "react-loadable": "^5.5.0" + }, "devDependencies": { - "@babel/core": "^7.11.4", + "@babel/cli": "^7.16.8", + "@babel/core": "^7.16.12", "@babel/plugin-proposal-class-properties": "^7.10.4", "@babel/plugin-proposal-decorators": "^7.10.5", "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-transform-runtime": "^7.11.0", - "@babel/preset-env": "^7.11.0", - "@babel/preset-react": "^7.10.4", + "@babel/preset-env": "^7.16.11", + "@babel/preset-react": "^7.16.7", + "@babel/preset-typescript": "^7.16.7", + "@rollup/plugin-babel": "^5.3.0", + "@rollup/plugin-commonjs": "^21.0.1", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.1.3", "@testing-library/react": "^11.0.4", - "@types/jest": "^26.0.14", - "@types/lodash": "^4.14.172", + "@types/jest": "^27.4.0", + "@types/lodash": "^4.14.178", "@types/marked": "^1.2.0", "@types/node": "^14.11.2", "@types/react-dom": "^16.9.8", "@types/react-loadable": "^5.5.3", "@types/react-test-renderer": "^16.9.3", - "@typescript-eslint/eslint-plugin": "^4.12.0", - "@typescript-eslint/parser": "^4.12.0", + "@typescript-eslint/eslint-plugin": "^5.10.1", + "@typescript-eslint/parser": "^5.10.1", "awesome-typescript-loader": "^5.2.1", "babel-jest": "^26.3.0", - "babel-loader": "^8.1.0", "babel-plugin-import": "^1.13.0", - "css-loader": "^4.3.0", - "eslint": "^7.17.0", - "eslint-config-standard": "^16.0.2", - "eslint-plugin-import": "^2.22.1", + "eslint": "^7.32.0", + "eslint-config-standard": "^16.0.3", + "eslint-plugin-import": "^2.25.4", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^4.2.1", - "eslint-plugin-react": "^7.22.0", - "express": "^4.17.1", - "father": "^2.29.11", - "html-webpack-plugin": "^4.5.0", - "identity-obj-proxy": "^3.0.0", - "jest": "^26.4.2", - "less": "^3.12.2", - "less-loader": "^7.0.1", - "loadsh": "0.0.4", - "react-docgen": "^5.3.1", - "react-scripts": "^4.0.1", - "react-test-renderer": "^16.13.1", - "style-loader": "^1.2.1", - "ts-jest": "^26.4.0", - "typedoc": "^0.19.2", - "typescript": "^4.0.2", - "webpack": "^4.44.2", - "webpack-bundle-analyzer": "^3.9.0", - "webpack-cli": "^3.3.12", - "webpack-dev-server": "^3.11.0", - "webpack-merge": "^5.1.4" - }, - "dependencies": { - "@types/react": "^16.9.46", - "@types/react-router-dom": "^5.1.5", - "axios": "^0.20.0", + "eslint-plugin-promise": "^4.3.1", + "eslint-plugin-react": "^7.28.0", + "execa": "^4.1.0", + "jest": "^27.4.7", "lodash": "^4.17.21", - "marked": "^1.2.5", - "moment": "^2.29.0", - "qiankun": "^2.5.1", - "query-string": "^6.13.8", - "rc-table": "^7.9.10", - "react-loadable": "^5.5.0" + "npm-watch": "^0.11.0", + "rollup": "^2.66.0", + "rollup-plugin-eslint": "^7.0.0", + "rollup-plugin-typescript2": "^0.31.1", + "ts-jest": "^27.1.3", + "typescript": "^4.5.5" }, "peerDependencies": { "react": "^16.13.1", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..b2a1bc4 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,41 @@ +import path from 'path' +import ts from 'rollup-plugin-typescript2' +import { nodeResolve } from '@rollup/plugin-node-resolve' +import { babel } from '@rollup/plugin-babel' +import commonjs from '@rollup/plugin-commonjs' +import { eslint } from 'rollup-plugin-eslint' +import json from '@rollup/plugin-json' + +export default { + input: 'src/index.tsx', + output: [ + { + format: 'esm', + file: path.resolve('dist/index.esm.js'), // 输出的文件路径 + sourcemap: true + } + ], + plugins: [ + json(), + // eslint({ + // throwOnError: true, + // exclude: ['node_modules/**', 'es/**', 'dist/**'] + // }), + ts({ + tsconfig: path.resolve(__dirname, 'tsconfig.json') + }), + babel({ + babelHelpers: 'runtime', + exclude: 'node_modules/**' // 只编译我们的源代码 + }), + commonjs(), + nodeResolve({ + extensions: ['.js', '.ts', '.tsx'] + }) + ], + external: ['react', 'react-dom'], + // external: id => /lodash/.test(id), // lodash 现在将被视为外部的(externals),不会与你的库打包在一起 + watch: { + include: 'src/**' + } +} diff --git a/tsconfig.json b/tsconfig.json index 95deb7c..8123d1b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,32 +1,38 @@ { "compilerOptions": { - "target": "es6", - "module": "esnext", - "jsx": "react", - "sourceMap": true, - "outDir": "./lib/", + "target": "ES6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "allowJs": true, /* Allow javascript files to be compiled. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + "outDir": "./lib/", //输出编译后的文件 /* Redirect output structure to the directory. */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "esModuleInterop": true, /* 通过为所有导入创建命名空间对象,启用 CommonJS 和 ES 模块之间的发射互操作性 Implies 'allowSyntheticDefaultImports'. */ + "declaration": true, // 生成定义文件 /* Generates corresponding '.d.ts' file. */ + "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declarationDir": "./ts/types", // 定义文件输出目录 + // "declarationMap": true, // 生成定义sourceMap /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "removeComments": true, // 删除注释 + // "noUnusedLocals": true, // 未使用变量报错 /* Report errors on unused locals. */ + "strict": true, - "esModuleInterop": true, - "lib": [ + "lib": [ // // 指定要包含在编译中的库文件导入库类型定义 "dom", "dom.iterable", "esnext" ], - "allowJs": true, - "skipLibCheck": true, + "skipLibCheck": true, // Skip type checking of declaration files. "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, // /* Disallow inconsistently-cased references to the same file. */ "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "noImplicitAny": true, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, - "types": [ + "types": [ // // 导入指定类型包 "node", "jest" ], - "experimentalDecorators": true + "experimentalDecorators": true, } -} \ No newline at end of file +} -- Gitee From 3534866f07c8310ada03aac622d6c17f31211e5d Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 11 Feb 2022 23:28:25 +0800 Subject: [PATCH 050/164] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E5=89=8D=E7=BC=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/value.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/util/value.ts b/src/util/value.ts index c21ce55..c7dd643 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -146,23 +146,24 @@ function indexes (source: string, find: string) { /** * 获取一个数组中最长共同前缀 + *@param arr 入参数组的元素是二级及以上路径,为节省性能,该方法没有适配处理多个一级路径的共同前缀,一级路径没有共同前缀 + * + * eg: 根据项目使用场景,如['81.mode', '81.me.1', '81.my.1', '81.m']的共同前缀为81,不可以是81.m */ export const getLongestCommonPrefix = (arr: string[]) => { if (arr.length === 0 || arr[0].length === 0) { return '' } for (let i = 0, len1 = arr[0].length; i < len1; i++) { const c = arr[0].charAt(i) for (let j = 1, len2 = arr.length; j < len2; j++) { - if (i === arr[j].length || arr[j].charAt(i) !== c) { + if (i === arr[j].length || arr[j].charAt(i) !== c || (i === len1 - 1 && arr[j].length > len1 && arr[j].charAt(len1) !== '.')) { const _indexes = indexes(arr[0], '.') const res = arr[0].substring(0, i).replace(/\.+$/, '') // 去掉尾部'.' - if (_indexes.length) { - for (let n = 0; n < _indexes.length; n++) { - if (res.length === _indexes[n]) { - return res - } + for (let n = 0; n < _indexes.length; n++) { + if (res.length === _indexes[n]) { + return res } - return res.replace(/\.+[^\\.]+$/, '') } + return res.replace(/\.+[^\\.]+$/, '') } } } @@ -173,6 +174,8 @@ export const getLongestCommonPrefix = (arr: string[]) => { * @param arr 目标数组 * @param sourceField 来源字段 * @returns 与来源字段比较共同前缀后更新的数组 | 是否更新并上报 + * + * eg: ['a.0', 'b']不会插入'a.0.c',会插入'a'替换'a.0',原数组改变为['a', 'b'] */ export const updateCommonPrefixItem = (arr: string[], sourceField: string): string[] | boolean => { const reg = /[^\\.]+(?=\.?)/ @@ -180,7 +183,9 @@ export const updateCommonPrefixItem = (arr: string[], sourceField: string): stri const commonPrefixItemS = [sourceField] for (let i = arr.length - 1; i >= 0; i--) { const arrItem = arr[i] - if (sourceField.includes(arrItem)) { + // const sourceFieldLevels = indexes(sourceField, '.').length + // const arrItemLevels = indexes(arrItem, '.').length + if (sourceField === arrItem) { return false } const arrItemPrefix = arrItem.match(reg)?.[0] -- Gitee From 55fa750ed4453297fc61db8a5420fb4db254d658 Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Mon, 14 Feb 2022 18:15:32 +0800 Subject: [PATCH 051/164] =?UTF-8?q?=E9=A2=9C=E8=89=B2=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/detailColor/index.tsx | 45 +++++++++++++++++++++ src/components/detail/index.tsx | 7 +++- src/index.tsx | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/components/detail/detailColor/index.tsx diff --git a/src/components/detail/detailColor/index.tsx b/src/components/detail/detailColor/index.tsx new file mode 100644 index 0000000..5d2173d --- /dev/null +++ b/src/components/detail/detailColor/index.tsx @@ -0,0 +1,45 @@ +import React from 'react' +import { DetailField, DetailFieldConfig, IDetailField } from '../common' + +export interface ColorDetailConfig extends DetailFieldConfig { + type: 'color' +} + +export interface IColorProps { + value: string +} + +export default class InfoDetail extends DetailField implements IDetailField { + renderComponent = (props: IColorProps) => { + return + 您当前使用的UI版本没有实现colorDetail组件。 + + } + + getValue = () => { + const { + value, + config: { + defaultValue + } + } = this.props + + if (value === undefined || value === null || value === '') { + return defaultValue !== undefined ? defaultValue : '' + } + return value + } + + render = () => { + const value = this.getValue() + console.log(value, 'color value ') + + return ( + + {this.renderComponent({ + value + })} + + ) + } +} diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index a6b7057..2c2fffb 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -6,6 +6,7 @@ import StatementDetail, { StatementDetailConfig } from './statement' import GroupField, { GroupFieldConfig } from './group' import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' import InfoDetail, { InfoDetailConfig } from './detailInfo' +import ColorDetail, { ColorDetailConfig } from './detailColor' /** * 详情步骤内详情项配置文件格式定义 - 枚举 @@ -25,7 +26,8 @@ export type componentType = 'detail_enum' | 'statement' | 'import_subform' | - 'detail_info' + 'detail_info' | + 'detail_color' export default { group: GroupField, @@ -33,5 +35,6 @@ export default { import_subform: ImportSubformField, detail_enum: EnumDetail, statement: StatementDetail, - detail_info: InfoDetail + detail_info: InfoDetail, + detail_color: ColorDetail } diff --git a/src/index.tsx b/src/index.tsx index 297d872..af50ce4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -59,6 +59,7 @@ export { default as DetailStatementField } from './components/detail/statement' export { default as DetailTextField } from './components/detail/text' export { default as DetailImportSubformField } from './components/detail/importSubform' export { default as DetailInfoField } from './components/detail/detailInfo' +export { default as DetailColorField } from './components/detail/detailColor' export { default as HeaderStep } from './steps/header' -- Gitee From 817f6e7c19145eedf20b92954874192f998051f3 Mon Sep 17 00:00:00 2001 From: zhenjintao Date: Tue, 15 Feb 2022 10:57:16 +0800 Subject: [PATCH 052/164] feat: eslint --- .eslintrc | 42 ++++++++++++++++++++++++++++++++---------- .prettierrc | 5 +++++ package.json | 14 ++++++++++++-- 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index e88f05d..4ba6db6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,22 +1,25 @@ { + // 为我们提供运行环境,一个环境定义了一组预定义的全局变量 "env": { "browser": true, "es2021": true, "jest": true, "node": true, - "commonjs": true, - "es6": true + "commonjs": true }, - "parser": "@typescript-eslint/parser", - "plugins": [ - "react", - "@typescript-eslint" - ], + // 一个配置文件可以被基础配置中的已启用的规则继承。 "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "standard" + "airbnb", + "prettier", + "plugin:compat/recommended", + "plugin:jest/recommended", + "plugin:react/recommended", + "plugin:import/typescript", + "plugin:@typescript-eslint/recommended" ], + // ESLint 默认使用Espree作为其解析器,你可以在配置文件中指定一个不同的解析器 + "parser": "@typescript-eslint/parser", + // 配置解析器支持的语法 "parserOptions": { "ecmaFeatures": { "jsx": true @@ -24,8 +27,27 @@ "ecmaVersion": 12, "sourceType": "module" }, + // ESLint 支持使用第三方插件。在使用插件之前,你必须使用 npm 安装它。 + // 在配置文件里配置插件时,可以使用 plugins 关键字来存放插件名字的列表。插件名称可以省略 eslint-plugin- 前缀 + "plugins": [ + "react", + "babel", + "jest", + "react-hooks", + "@typescript-eslint" + ], + // ESLint 附带有大量的规则。你可以使用注释或配置文件修改你项目中要使用的规则。要改变一个规则设置,你必须将规则 ID 设置为下列值之一: + // "off" 或 0 - 关闭规则 + // "warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出) + // "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出) "rules": { "no-use-before-define": "off", "react/display-name": 0 + }, + // 指定react版本为安装的版本 + "settings": { + "react": { + "version": "16.13.1" + } } } \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..122cf16 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "printWidth": 120, + "tabWidth": 2 +} \ No newline at end of file diff --git a/package.json b/package.json index 27772ca..77bd680 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "clear": "rm -rf dist && rm -rf lib", "test": "jest", "test:u": "npm test -- -u", - "lint": "eslint src/** --fix" + "lint": "eslint src/** --fix", + "prettier": "prettier -c --write **/*" }, "keywords": [ "ccms" @@ -64,15 +65,24 @@ "babel-jest": "^26.3.0", "babel-plugin-import": "^1.13.0", "eslint": "^7.32.0", - "eslint-config-standard": "^16.0.3", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-babel": "^5.3.1", + "eslint-plugin-compat": "^4.0.1", "eslint-plugin-import": "^2.25.4", + "eslint-plugin-jest": "^26.0.0", + "eslint-plugin-jsx-a11y": "^6.5.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^4.3.1", "eslint-plugin-react": "^7.28.0", + "eslint-plugin-react-hooks": "^4.3.0", "execa": "^4.1.0", + "husky": "^7.0.4", "jest": "^27.4.7", + "lint-staged": "^12.3.3", "lodash": "^4.17.21", "npm-watch": "^0.11.0", + "prettier": "^2.5.1", "rollup": "^2.66.0", "rollup-plugin-eslint": "^7.0.0", "rollup-plugin-typescript2": "^0.31.1", -- Gitee From d1acea5d9897f8fdded0fd2e8b63c2fb6dbc2038 Mon Sep 17 00:00:00 2001 From: zhenjintao Date: Tue, 15 Feb 2022 17:30:08 +0800 Subject: [PATCH 053/164] feat: commitlint --- .commitlintrc.js | 32 +++++++++++++++++++++++++++++++ .editorconfig | 9 +++++++++ .eslintrc | 5 +++-- .prettierrc | 8 ++++---- package.json | 31 +++++++++++++++++++++++++++--- src/util/param.ts | 48 ++++++++++++++++++++++------------------------- 6 files changed, 98 insertions(+), 35 deletions(-) create mode 100644 .commitlintrc.js create mode 100644 .editorconfig diff --git a/.commitlintrc.js b/.commitlintrc.js new file mode 100644 index 0000000..1449c0f --- /dev/null +++ b/.commitlintrc.js @@ -0,0 +1,32 @@ +/** + * @file commitlint 配置 + * commit message: (注意冒号后面有空格) + * + */ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'type-enum': [ + 2, + 'always', + [ + 'init', // 初始提交 + 'feat', // 新功能(feature) + 'perf', // 优化 + 'fix', // 修补bug + 'docs', // 文档(documentation) + 'style', // 格式(不影响代码运行的变动) + 'refactor', // 重构(即不是新增功能,也不是修改bug的代码变动) + 'build', // 编译构建 + 'test', // 增加测试 + 'revert', // 回滚 + 'config', // 构建过程或辅助工具的变动 + 'chore', // 其他改动 + ], + ], + 'type-empty': [2, 'never'], // 提交不符合规范时,也可以提交,但是会有警告 + 'subject-empty': [2, 'never'], // 提交不符合规范时,也可以提交,但是会有警告 + 'subject-full-stop': [0, 'never'], + 'subject-case': [0, 'never'], + }, +}; diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc b/.eslintrc index 4ba6db6..04b963d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,7 +42,8 @@ // "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出) "rules": { "no-use-before-define": "off", - "react/display-name": 0 + "react/display-name": 0, + "import/extensions": 0 }, // 指定react版本为安装的版本 "settings": { @@ -50,4 +51,4 @@ "version": "16.13.1" } } -} \ No newline at end of file +} diff --git a/.prettierrc b/.prettierrc index 122cf16..d0ed5e8 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "singleQuote": true, - "printWidth": 120, - "tabWidth": 2 -} \ No newline at end of file + "singleQuote": true, + "printWidth": 120, + "tabWidth": 2 +} diff --git a/package.json b/package.json index 77bd680..07f6e2c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,28 @@ "test": "jest", "test:u": "npm test -- -u", "lint": "eslint src/** --fix", - "prettier": "prettier -c --write **/*" + "prettier": "prettier -c --write **/*", + "commit": "git-cz" + }, + "husky": { + "hooks": { + "commit-msg": "commitlint --env HUSKY_GIT_PARAMS", + "pre-commit": "lint-staged" + } + }, + "lint-staged": { + "src/*.{js, jsx, ts, tsx}": [ + "npm run prettier", + "npm run lint" + ], + "src/*.{css,scss,less,json,html,md,markdown}": [ + "npm run prettier" + ] + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } }, "keywords": [ "ccms" @@ -38,6 +59,9 @@ "react-loadable": "^5.5.0" }, "devDependencies": { + "@commitlint/cli": "^9.0.1", + "@commitlint/config-conventional": "^9.0.1", + "commitizen": "^4.2.4", "@babel/cli": "^7.16.8", "@babel/core": "^7.16.12", "@babel/plugin-proposal-class-properties": "^7.10.4", @@ -77,9 +101,10 @@ "eslint-plugin-react": "^7.28.0", "eslint-plugin-react-hooks": "^4.3.0", "execa": "^4.1.0", - "husky": "^7.0.4", + "husky": "^4.2.5", + "cz-conventional-changelog": "^3.3.0", "jest": "^27.4.7", - "lint-staged": "^12.3.3", + "lint-staged": "^10.2.11", "lodash": "^4.17.21", "npm-watch": "^0.11.0", "prettier": "^2.5.1", diff --git a/src/util/param.ts b/src/util/param.ts index 0742e6b..f86401f 100644 --- a/src/util/param.ts +++ b/src/util/param.ts @@ -1,53 +1,49 @@ -import { get, set } from "lodash" -import qs from "query-string" -import { ParamConfig } from "../interface"; +import { get, set } from 'lodash'; +import qs from 'query-string'; +import { ParamConfig } from '../interface'; -export default function ParamHelper ( config: ParamConfig, datas: { record?: object, data: object[], step: number }) { +export default function ParamHelper(config: ParamConfig, datas: { record?: object; data: object[]; step: number }) { switch (config.source) { case 'record': if (datas.record) { if (config.field === '') { - return datas.record - } else { - return get(datas.record, config.field) + return datas.record; } + return get(datas.record, config.field); } - break + break; case 'data': if (datas.data[datas.step]) { if (config.field === '') { - return datas.data[datas.step] - } else { - return get(datas.data[datas.step], config.field) + return datas.data[datas.step]; } + return get(datas.data[datas.step], config.field); } - break + break; case 'source': if (datas.data[0]) { if (config.field === '') { - return datas.data[0] - } else { - return get(datas.data[0], config.field) + return datas.data[0]; } + return get(datas.data[0], config.field); } - break + break; case 'step': if (datas.data[config.step]) { if (config.field === '') { - return datas.data[config.step] - } else { - return get(datas.data[config.step], config.field) + return datas.data[config.step]; } + return get(datas.data[config.step], config.field); } - break + break; case 'url': if (config.field === '') { - return qs.parse(window.location.search, { arrayFormat: 'bracket' }) - } else { - return get(qs.parse(window.location.search, { arrayFormat: 'bracket' }), config.field) + return qs.parse(window.location.search, { arrayFormat: 'bracket' }); } + return get(qs.parse(window.location.search, { arrayFormat: 'bracket' }), config.field); + case 'static': - return config.value + return config.value; } - return undefined -} \ No newline at end of file + return undefined; +} -- Gitee From 5871d8bb7efc4603b1eae0a2d7b04c84ec73f1a3 Mon Sep 17 00:00:00 2001 From: zhenjintao Date: Thu, 17 Feb 2022 21:49:54 +0800 Subject: [PATCH 054/164] feat: commitlint --- .commitlintrc.js | 1 - package.json | 23 ++++++++++++----------- rollup.config.js | 36 +++++++++++++++++++----------------- tsconfig.json | 19 +++++++++---------- 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/.commitlintrc.js b/.commitlintrc.js index 1449c0f..ccc051b 100644 --- a/.commitlintrc.js +++ b/.commitlintrc.js @@ -20,7 +20,6 @@ module.exports = { 'build', // 编译构建 'test', // 增加测试 'revert', // 回滚 - 'config', // 构建过程或辅助工具的变动 'chore', // 其他改动 ], ], diff --git a/package.json b/package.json index 07f6e2c..97bba4d 100644 --- a/package.json +++ b/package.json @@ -49,19 +49,10 @@ "dependencies": { "@types/react": "^16.9.46", "@types/react-router-dom": "^5.1.5", - "axios": "^0.20.0", - "lodash": "^4.17.21", - "marked": "^1.2.5", - "moment": "^2.29.0", - "qiankun": "^2.5.1", - "query-string": "^6.13.8", "rc-table": "^7.9.10", "react-loadable": "^5.5.0" }, "devDependencies": { - "@commitlint/cli": "^9.0.1", - "@commitlint/config-conventional": "^9.0.1", - "commitizen": "^4.2.4", "@babel/cli": "^7.16.8", "@babel/core": "^7.16.12", "@babel/plugin-proposal-class-properties": "^7.10.4", @@ -71,6 +62,8 @@ "@babel/preset-env": "^7.16.11", "@babel/preset-react": "^7.16.7", "@babel/preset-typescript": "^7.16.7", + "@commitlint/cli": "^9.0.1", + "@commitlint/config-conventional": "^9.0.1", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-json": "^4.1.0", @@ -88,6 +81,8 @@ "awesome-typescript-loader": "^5.2.1", "babel-jest": "^26.3.0", "babel-plugin-import": "^1.13.0", + "commitizen": "^4.2.4", + "cz-conventional-changelog": "^3.3.0", "eslint": "^7.32.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.3.0", @@ -102,7 +97,6 @@ "eslint-plugin-react-hooks": "^4.3.0", "execa": "^4.1.0", "husky": "^4.2.5", - "cz-conventional-changelog": "^3.3.0", "jest": "^27.4.7", "lint-staged": "^10.2.11", "lodash": "^4.17.21", @@ -110,12 +104,19 @@ "prettier": "^2.5.1", "rollup": "^2.66.0", "rollup-plugin-eslint": "^7.0.0", + "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.31.1", "ts-jest": "^27.1.3", "typescript": "^4.5.5" }, "peerDependencies": { + "axios": "^0.20.0", + "lodash": "^4.17.21", + "marked": "^1.2.5", "react": "^16.13.1", - "react-dom": "^16.13.1" + "react-dom": "^16.13.1", + "query-string": "^6.13.8", + "moment": "^2.29.0", + "qiankun": "^2.5.1" } } diff --git a/rollup.config.js b/rollup.config.js index b2a1bc4..523ba5a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,10 +1,11 @@ -import path from 'path' -import ts from 'rollup-plugin-typescript2' -import { nodeResolve } from '@rollup/plugin-node-resolve' -import { babel } from '@rollup/plugin-babel' -import commonjs from '@rollup/plugin-commonjs' -import { eslint } from 'rollup-plugin-eslint' -import json from '@rollup/plugin-json' +import path from 'path'; +import ts from 'rollup-plugin-typescript2'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import { babel } from '@rollup/plugin-babel'; +import commonjs from '@rollup/plugin-commonjs'; +import { eslint } from 'rollup-plugin-eslint'; +import json from '@rollup/plugin-json'; +import { terser } from 'rollup-plugin-terser'; export default { input: 'src/index.tsx', @@ -12,8 +13,8 @@ export default { { format: 'esm', file: path.resolve('dist/index.esm.js'), // 输出的文件路径 - sourcemap: true - } + // sourcemap: true, + }, ], plugins: [ json(), @@ -22,20 +23,21 @@ export default { // exclude: ['node_modules/**', 'es/**', 'dist/**'] // }), ts({ - tsconfig: path.resolve(__dirname, 'tsconfig.json') + tsconfig: path.resolve(__dirname, 'tsconfig.json'), }), babel({ babelHelpers: 'runtime', - exclude: 'node_modules/**' // 只编译我们的源代码 + exclude: 'node_modules/**', // 只编译我们的源代码 }), commonjs(), nodeResolve({ - extensions: ['.js', '.ts', '.tsx'] - }) + extensions: ['.js', '.ts', '.tsx'], + }), + terser(), ], - external: ['react', 'react-dom'], + external: ['react', 'react-dom', 'marked', 'lodash', 'axios', 'query-string', 'moment', 'qiankun'], // external: id => /lodash/.test(id), // lodash 现在将被视为外部的(externals),不会与你的库打包在一起 watch: { - include: 'src/**' - } -} + include: 'src/**', + }, +}; diff --git a/tsconfig.json b/tsconfig.json index 8123d1b..1e93bd0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,18 @@ { "compilerOptions": { - "target": "ES6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - "sourceMap": true, /* Generates corresponding '.map' file. */ - "outDir": "./lib/", //输出编译后的文件 /* Redirect output structure to the directory. */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - "esModuleInterop": true, /* 通过为所有导入创建命名空间对象,启用 CommonJS 和 ES 模块之间的发射互操作性 Implies 'allowSyntheticDefaultImports'. */ - "declaration": true, // 生成定义文件 /* Generates corresponding '.d.ts' file. */ - "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "target": "ES6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "allowJs": true, /* Allow javascript files to be compiled. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + "outDir": "./lib/", //输出编译后的文件 /* Redirect output structure to the directory. */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "esModuleInterop": true, /* 通过为所有导入创建命名空间对象,启用 CommonJS 和 ES 模块之间的发射互操作性 Implies 'allowSyntheticDefaultImports'. */ + "declaration": true, // 生成定义文件 /* Generates corresponding '.d.ts' file. */ + "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "declarationDir": "./ts/types", // 定义文件输出目录 // "declarationMap": true, // 生成定义sourceMap /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "removeComments": true, // 删除注释 // "noUnusedLocals": true, // 未使用变量报错 /* Report errors on unused locals. */ - "strict": true, "lib": [ // // 指定要包含在编译中的库文件导入库类型定义 "dom", -- Gitee From 6a2a9eb30ae956b04866f35626fa0098ca79be59 Mon Sep 17 00:00:00 2001 From: xbaoshu Date: Mon, 21 Feb 2022 02:23:26 +0000 Subject: [PATCH 055/164] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=93=8D=E4=BD=9C=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E9=93=BE=E6=8E=A5=20*=20fixed:?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E4=BA=86=E8=A1=A8=E6=A0=BC=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=AC=AC=E4=B8=89=E6=96=B9=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=20*=20feat:=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=A1=A8=E6=A0=BC=E6=93=8D=E4=BD=9C=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E7=AC=AC=E4=B8=89=E6=96=B9=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=20*=20Merge=20branch=20'v1.2.2'=20into=20dev-xc=20*=20Merge=20?= =?UTF-8?q?branch=20'v1.2.1'=20into=20dev-xc=20*=20merge:=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6v1.2.1=E5=88=86=E6=94=AF=20*=20change:=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=A0=87=E5=87=86=E5=8C=96=20*=20Merge=20branch=20'v1?= =?UTF-8?q?.2.1'=20into=20dev-xc=20*=20fixed:=E4=BF=AE=E5=A4=8D=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E8=AF=AD=E5=8F=A5=E5=85=A5=E5=8F=82?= =?UTF-8?q?=E4=B8=BAunderfind=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 67 +++++++++++++++++++++++- src/util/condition.ts | 106 +++++++++++++++----------------------- 2 files changed, 107 insertions(+), 66 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 72111dc..ac82304 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -54,7 +54,7 @@ export interface TableOperationConfig { level?: 'normal' | 'primary' | 'danger' check?: { enable: false } | TableOperationCheckConfig confirm?: { enable: false } | TableOperationConfirmConfig - handle: TableCCMSOperationConfig + handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig } @@ -69,6 +69,15 @@ export interface TableCCMSOperationConfig { debug?: boolean } +export interface TableLinkOperationConfig { + type: 'link' + target: '_blank' | '_self' + targetURL: string + params?: { field: string, data: ParamConfig }[] + callback?: boolean + debug?: boolean +} + interface TableOperationCheckConfig { enable: true interface: InterfaceConfig @@ -338,6 +347,62 @@ export default class TableStep extends Step { window.open(`${targetURL}${targetKey}`) } } + + // 当按钮的响应类型是第三方链接时 + if (operation.handle.type === 'link') { + const params = {} + if (operation.handle.params !== undefined) { + for (const { field, data: dataConfig } of operation.handle.params) { + const value = getParam(dataConfig, { record, data, step }) + set(params, field, value) + } + + if (operation.handle.debug) { + console.log('CCMS debug: operation - operation.handle.type === link', params) + } + + // 提取跳转URL地址,合并URL参数拼接 + const targetURL = operation.handle.targetURL || '' + const urlParams = this.queryUrlParams(targetURL) + const query = urlParams.paramsResult + const hash = urlParams.hashResult.hash?.replace('#/', '') + const url = targetURL?.split('#')[0]?.split('?')[0] + // const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) + const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: hash }, { arrayFormat: 'bracket' }) || '' + + this.urlJumpHandler(jumpUrl, operation.handle.target) + } + } + } + + /** + * 获取URL中的路由和参数 + * @param url url地址 + */ + queryUrlParams = (url: string) => { + const paramsResult: any = {} + const hashResult: any = {} + const paramReg = /([^?=&#]+)=([^?=&#]+)/g + const hashReg = /#[^?=&#]+/g + // eslint-disable-next-line no-return-assign + url.replace(paramReg, (n, x, y) => paramsResult[x] = y) + // eslint-disable-next-line no-return-assign + url.replace(hashReg, (n) => hashResult.hash = n) + return { paramsResult, hashResult } + } + + /** + * 链接跳转处理方法 + * @param url 跳转地址 + * @param target 跳转方式 + */ + urlJumpHandler = (url: string, target: string) => { + const a = document.createElement('a') + document.body.appendChild(a) + a.href = url + a.target = target + a.click() + document.body.removeChild(a) } /** diff --git a/src/util/condition.ts b/src/util/condition.ts index 7d7542b..a8358a6 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,6 +1,6 @@ -import { set, cloneDeep, template } from "lodash" -import { ParamConfig } from "../interface"; -import ParamHelper from "./param"; +import { set, cloneDeep, template } from 'lodash' +import { ParamConfig } from '../interface' +import ParamHelper from './param' export interface ConditionConfig { /** @@ -22,13 +22,17 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { +export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { + // 条件语句模版 + let conditionTemplate = '' + // 条件语句模版入参 + let statementParams = {} + if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { if (condition.template) { - const statementTemplate = template(condition.template) - let statementParams = {} + conditionTemplate = condition.template if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -41,46 +45,15 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } }) } - - try { - const statement = statementTemplate(statementParams) - try { - const result = eval(statement) - if (result) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => true') - } - return true - } else { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => false') - } - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.template + '` => `' + statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.template, statement) - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.template + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.template) - return false - } } else { // 用于兼容旧版本中的通配符 // V2新增逻辑段 - 开始 // const statementTemplate = template(condition.statement) // V2新增逻辑段 - 结束 // V2移除逻辑段 - 开始 - const statementPolyfill = condition.statement?.replace(/([^\$])\{/g, '$1${') - const statementTemplate = template(statementPolyfill) + conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || '' // V2移除逻辑段 - 结束 - let statementParams = {} + if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -92,36 +65,39 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } }) } - + } + + return execConditionHandler(condition, conditionTemplate, statementParams) + } +} + +// 执行条件语句,返回结果 +const execConditionHandler = (condition: ConditionConfig | undefined, conditionTemplate: string, statementParams: object): boolean => { + try { + if (Object.values(statementParams).some((param) => param === undefined)) { + if (condition?.debug) { + console.info(`CCMS debug: condition ${conditionTemplate} => false`) + } + return false + } else { + const statement = template(conditionTemplate)(statementParams) + try { - const statement = statementTemplate(statementParams) - try { - const result = eval(statement) - if (result) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => true') - } - return true - } else { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => false') - } - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.statement + '` => `' + statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.statement, statement) - return false + const result = eval(statement) + if (condition?.debug) { + console.info(`CCMS debug: condition ${statement} => ${result}`) } + return result } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.statement) + console.error('表单项展示条件语句执行错误。', conditionTemplate, statement) return false } } + } catch (e) { + if (condition?.debug) { + console.info('CCMS debug: condition - `' + conditionTemplate + '` => error') + } + console.error('表单项展示条件语句执行错误。', conditionTemplate) + return false } -} \ No newline at end of file +} -- Gitee From 7520577fa5ea4721ad2355396e400cacd7853c16 Mon Sep 17 00:00:00 2001 From: zjt Date: Mon, 21 Feb 2022 14:38:47 +0800 Subject: [PATCH 056/164] chore: package.json --- package.json | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 97bba4d..00c1bd6 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,12 @@ "dependencies": { "@types/react": "^16.9.46", "@types/react-router-dom": "^5.1.5", + "axios": "^0.20.0", + "lodash": "^4.17.21", + "marked": "^1.2.5", + "moment": "^2.29.0", + "qiankun": "^2.5.1", + "query-string": "^6.13.8", "rc-table": "^7.9.10", "react-loadable": "^5.5.0" }, @@ -99,7 +105,6 @@ "husky": "^4.2.5", "jest": "^27.4.7", "lint-staged": "^10.2.11", - "lodash": "^4.17.21", "npm-watch": "^0.11.0", "prettier": "^2.5.1", "rollup": "^2.66.0", @@ -110,13 +115,7 @@ "typescript": "^4.5.5" }, "peerDependencies": { - "axios": "^0.20.0", - "lodash": "^4.17.21", - "marked": "^1.2.5", "react": "^16.13.1", - "react-dom": "^16.13.1", - "query-string": "^6.13.8", - "moment": "^2.29.0", - "qiankun": "^2.5.1" + "react-dom": "^16.13.1" } } -- Gitee From 7fc1598ca4c4a03e0c4ef8ff5589ba61e720f27f Mon Sep 17 00:00:00 2001 From: wangailin Date: Mon, 21 Feb 2022 14:40:10 +0800 Subject: [PATCH 057/164] feat: version 1.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 91472ce..b1fc05e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccms", - "version": "1.2.0", + "version": "1.2.4", "description": "ConfigableCMS", "main": "lib/index.js", "module": "dist/index.js", -- Gitee From e62ca5f404bbdc4188c10eabce8145e5b81aa9a0 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 22 Feb 2022 00:02:44 +0800 Subject: [PATCH 058/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9this=E7=9A=84t?= =?UTF-8?q?s=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/condition.ts | 3 ++- src/util/interface.ts | 3 ++- src/util/statement.ts | 3 ++- src/util/value.ts | 2 -- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/condition.ts b/src/util/condition.ts index cf48fbd..6a2331b 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -2,6 +2,7 @@ import { template } from 'lodash' import { set } from '../util/produce' import { ParamConfig } from '../interface' import ParamHelper from './param' +import { Field } from '../components/formFields/common' export interface ConditionConfig { /** @@ -23,7 +24,7 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }, extraContainerPath?: string }, _this?: any): boolean { +export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }, extraContainerPath?: string }, _this?: Field): boolean { if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { diff --git a/src/util/interface.ts b/src/util/interface.ts index 0971d88..3b0c9fd 100644 --- a/src/util/interface.ts +++ b/src/util/interface.ts @@ -5,6 +5,7 @@ import axios, { AxiosRequestConfig } from 'axios' import { ParamConfig } from '../interface' import ParamHelper from './param' import { getValue } from './value' +import { Field } from '../components/formFields/common' export interface InterfaceConfig { domain?: string @@ -103,7 +104,7 @@ export default class InterfaceHelper { loadDomain?: (domain: string) => Promise extra_data?: { params?: any, data?: any } }, - _this?: any // 位置要调整 + _this?: Field ): Promise { return new Promise(async (resolve, reject) => { // 处理URL diff --git a/src/util/statement.ts b/src/util/statement.ts index 6ee50ac..9329a8a 100644 --- a/src/util/statement.ts +++ b/src/util/statement.ts @@ -2,13 +2,14 @@ import { template } from 'lodash' import { set } from '../util/produce' import { ParamConfig } from '../interface' import ParamHelper from './param' +import { Field } from '../components/formFields/common' export interface StatementConfig { statement: string params: { field: string, data: ParamConfig }[] } -export default function StatementHelper (config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }, extraContainerPath?: string }, _this?: any): string { +export default function StatementHelper (config: StatementConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any; }, extraContainerPath?: string }, _this?: Field): string { if (config === undefined || config.statement === undefined || config.statement === '') { return '' } else { diff --git a/src/util/value.ts b/src/util/value.ts index c7dd643..a94db1d 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -183,8 +183,6 @@ export const updateCommonPrefixItem = (arr: string[], sourceField: string): stri const commonPrefixItemS = [sourceField] for (let i = arr.length - 1; i >= 0; i--) { const arrItem = arr[i] - // const sourceFieldLevels = indexes(sourceField, '.').length - // const arrItemLevels = indexes(arrItem, '.').length if (sourceField === arrItem) { return false } -- Gitee From 81266e86e464e12b1cb4bc3c39e032d97703ce51 Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Wed, 23 Feb 2022 12:43:07 +0800 Subject: [PATCH 059/164] =?UTF-8?q?fixed:=E4=BF=AE=E5=A4=8D=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E7=AC=AC=E4=B8=89=E6=96=B9=E9=93=BE=E6=8E=A5=E7=9A=84?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 49 +++++++-------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index ac82304..a3a5dbd 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -361,50 +361,19 @@ export default class TableStep extends Step { console.log('CCMS debug: operation - operation.handle.type === link', params) } - // 提取跳转URL地址,合并URL参数拼接 - const targetURL = operation.handle.targetURL || '' - const urlParams = this.queryUrlParams(targetURL) - const query = urlParams.paramsResult - const hash = urlParams.hashResult.hash?.replace('#/', '') - const url = targetURL?.split('#')[0]?.split('?')[0] - // const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) - const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: hash }, { arrayFormat: 'bracket' }) || '' - - this.urlJumpHandler(jumpUrl, operation.handle.target) + const targetURL = operation.handle.targetURL + const { query } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket' }) + const targetKey = queryString.stringifyUrl({ url: '', query: { ...query, ...params } }, { arrayFormat: 'bracket' }) || '' + const jumpUrl = `${targetURL}${targetKey}` + if (operation.handle.target === '_blank') { + window.open(jumpUrl) + } else { + window.location.href = jumpUrl + } } } } - /** - * 获取URL中的路由和参数 - * @param url url地址 - */ - queryUrlParams = (url: string) => { - const paramsResult: any = {} - const hashResult: any = {} - const paramReg = /([^?=&#]+)=([^?=&#]+)/g - const hashReg = /#[^?=&#]+/g - // eslint-disable-next-line no-return-assign - url.replace(paramReg, (n, x, y) => paramsResult[x] = y) - // eslint-disable-next-line no-return-assign - url.replace(hashReg, (n) => hashResult.hash = n) - return { paramsResult, hashResult } - } - - /** - * 链接跳转处理方法 - * @param url 跳转地址 - * @param target 跳转方式 - */ - urlJumpHandler = (url: string, target: string) => { - const a = document.createElement('a') - document.body.appendChild(a) - a.href = url - a.target = target - a.click() - document.body.removeChild(a) - } - /** * 渲染 操作二次确认弹窗 * @param props -- Gitee From 77c6aa3b4f09a9944d7f0f45c0ac423b7bc805b3 Mon Sep 17 00:00:00 2001 From: wangailin Date: Wed, 23 Feb 2022 16:07:56 +0800 Subject: [PATCH 060/164] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E9=9A=90=E8=97=8F=E9=A1=B9=E6=8F=90=E4=BA=A4=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=9B=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=A1=A8=E5=8D=95=E9=A1=B9=E6=A0=A1=E9=AA=8C=E7=9A=84?= =?UTF-8?q?=E6=96=87=E6=A1=88=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 8 +++++++- src/components/formFields/group/index.tsx | 12 ++++++++++-- src/components/formFields/tabs/index.tsx | 10 +++++++--- src/steps/form/index.tsx | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d95ddea..94d287f 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -127,6 +127,7 @@ export default class FormField extends Field = [] const formDataList = cloneDeep(this.state.formDataList) @@ -143,6 +144,10 @@ export default class FormField extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + errors.push(new FieldError(`${this.props.config.label || ''} ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}`)) } return errors.length ? errors : true @@ -494,6 +499,7 @@ export default class FormField extends Field = [] const formData = cloneDeep(this.state.formData) for (const fieldIndex in (this.props.config.fields || [])) { const formItem = this.formFields[fieldIndex] + const formConfig = this.props.config.fields?.[fieldIndex] if (formItem !== null && formItem !== undefined) { const validation = await formItem.validate(getValue(value, (this.props.config.fields || [])[fieldIndex].field)) - if (validation === true || this.formFieldsMounted[fieldIndex] === false) { + if (validation === true) { formData[fieldIndex] = { status: 'normal' } } else { childrenError++ formData[fieldIndex] = { status: 'error', message: validation[0].message } + childrenErrorMsg.push({ + name: formConfig?.label, + msg: validation[0].message + }) + console.log(formData[fieldIndex], 'group') } } } @@ -88,7 +95,7 @@ export default class GroupField extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + errors.push(new FieldError(`${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。`)) } return errors.length ? errors : true @@ -307,6 +314,7 @@ export default class GroupField extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { this.formFieldsMounted[formFieldIndex] = false + this.formFields[formFieldIndex] = null return null } let hidden: boolean = true diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index a32b115..51e252a 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -113,6 +113,7 @@ export default class TabsField extends Field = [] const formDataList = cloneDeep(this.state.formDataList) @@ -127,12 +128,15 @@ export default class TabsField extends Field extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + errors.push(new FieldError(`${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。`)) } return errors.length ? errors : true @@ -380,6 +383,7 @@ export default class TabsField extends Field { if (formField && formFieldConfig) { const value = await formField.get() const validation = await formField.validate(value) - if (validation !== true) { console.warn('表单项中存在问题', value, formFieldConfig) this.formData[formFieldIndex] = { status: 'error', message: validation[0].message, name: formFieldConfig.label } @@ -661,6 +660,7 @@ export default class FormStep extends Step { children: fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { this.formFieldsMounted[formFieldIndex] = false + this.formFields[formFieldIndex] = null return null } let hidden: boolean = true -- Gitee From 7fdd246c933ebbe859615ff3a80639179920d9c6 Mon Sep 17 00:00:00 2001 From: wangailin Date: Wed, 23 Feb 2022 16:09:45 +0800 Subject: [PATCH 061/164] =?UTF-8?q?feat:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=9B=20=E8=A1=A8=E6=A0=BC=E5=A2=9E=E5=8A=A0=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 2 + src/components/detail/custom/index.tsx | 95 ++++++++++++++++++++++++++ src/components/detail/group/index.tsx | 1 + src/components/detail/index.tsx | 11 +-- src/index.tsx | 1 + src/steps/detail/index.tsx | 1 + src/steps/table/index.tsx | 6 ++ 7 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 src/components/detail/custom/index.tsx diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 57902c1..adcf97c 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -76,6 +76,8 @@ export interface DetailFieldProps { data: any[], step: number, config: C + // 挂载引用 + detail?: React.ReactNode // TODO 待删除 onChange: (value: T) => Promise // 事件:设置值 diff --git a/src/components/detail/custom/index.tsx b/src/components/detail/custom/index.tsx new file mode 100644 index 0000000..19a582f --- /dev/null +++ b/src/components/detail/custom/index.tsx @@ -0,0 +1,95 @@ +import React, { RefObject } from 'react' +import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../common' +import { loadMicroApp, MicroApp } from 'qiankun' +import moment from 'moment' +import { cloneDeep } from 'lodash' + +export interface CustomDetailConfig extends DetailFieldConfig { + type: 'custom' + entry: string +} + +export default class CustomDtail extends DetailField implements IDetailField { + identifier: string = '' + entry: string = '' + container: RefObject = React.createRef() + customField: MicroApp | null = null + _get: () => Promise = async () => this.props.value + + componentDidMount () { + this.loadCustomField(this.props.config.entry) + } + + getSnapshotBeforeUpdate () { + const snapshot: string[] = [] + if (this.entry !== this.props.config.entry) { + snapshot.push('entry') + } + return snapshot + } + + get = async (): Promise => { + return await this._get() + } + + bindGet = async (get: () => Promise): Promise => { + this._get = get + } + + componentDidUpdate (_: DetailFieldProps, __: {}, snapshot: string[]) { + if (snapshot.includes('entry')) { + this.loadCustomField(this.props.config.entry) + } else { + if (this.customField && this.customField.update) { + this.customField.update({ + value: this.props.value, + record: this.props.record, + data: cloneDeep(this.props.data), + step: this.props.step, + config: this.props.config, + detail: this.props.detail, + onChange: this.props.onChange, + onValueSet: this.props.onValueSet, + onValueUnset: this.props.onValueUnset, + onValueListAppend: this.props.onValueListAppend, + onValueListSplice: this.props.onValueListSplice, + base: this.props.baseRoute, + loadDomain: this.props.loadDomain + }) + } + } + } + + loadCustomField = (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.customField = 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, + detail: this.props.detail, + onChange: this.props.onChange, + onValueSet: this.props.onValueSet, + onValueUnset: this.props.onValueUnset, + onValueListAppend: this.props.onValueListAppend, + onValueListSplice: this.props.onValueListSplice, + base: this.props.baseRoute, + loadDomain: this.props.loadDomain + } + }) + } + } + + render = () => { + return ( +
+ ) + } +} diff --git a/src/components/detail/group/index.tsx b/src/components/detail/group/index.tsx index 1dd5220..6d0dcf1 100644 --- a/src/components/detail/group/index.tsx +++ b/src/components/detail/group/index.tsx @@ -274,6 +274,7 @@ export default class GroupField extends DetailField { await this.handleChange(detailFieldIndex, value) }} onValueSet={async (path, value, validation) => this.handleValueSet(detailFieldIndex, path, value, validation)} onValueUnset={async (path, validation) => this.handleValueUnset(detailFieldIndex, path, validation)} diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index 24ae057..0d661f1 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -2,7 +2,7 @@ import TextField, { TextFieldConfig } from './text' import EnumDetail, { EnumDetailConfig } from './enum' import StatementDetail, { StatementDetailConfig } from './statement' - +import CustomDetail, { CustomDetailConfig } from './custom' import GroupField, { GroupFieldConfig } from './group' import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' @@ -14,19 +14,22 @@ export type DetailFieldConfigs = EnumDetailConfig | StatementDetailConfig | GroupFieldConfig | - ImportSubformFieldConfig + ImportSubformFieldConfig | + CustomDetailConfig export type componentType = 'text' | 'group' | 'detail_enum' | 'statement' | - 'import_subform' + 'import_subform' | + 'custom' export default { group: GroupField, text: TextField, import_subform: ImportSubformField, detail_enum: EnumDetail, - statement: StatementDetail + statement: StatementDetail, + custom: CustomDetail } diff --git a/src/index.tsx b/src/index.tsx index b193a05..5e8ec9d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -58,6 +58,7 @@ export { default as DetailEunmField } from './components/detail/enum' export { default as DetailStatementField } from './components/detail/statement' export { default as DetailTextField } from './components/detail/text' export { default as DetailImportSubformField } from './components/detail/importSubform' +export { default as CustomDetail } from './components/detail/custom' export { default as HeaderStep } from './steps/header' diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index 0ff404c..3823d28 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -456,6 +456,7 @@ export default class DetailStep extends Step { value={detailFieldConfig.field !== undefined ? getValue(detailValue, detailFieldConfig.field) || detailFieldConfig.defaultValue : undefined} record={detailValue} data={cloneDeep(data)} + detail={this} step={step} config={detailFieldConfig} onChange={async (value: any) => { await this.handleChange(detailFieldIndex, value) }} diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 66a364d..5df516f 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -51,6 +51,7 @@ export interface TableOperationGroupConfig { label?: string level?: 'normal' | 'primary' | 'danger' operations: Array + align: 'left' | 'right' } /** @@ -64,6 +65,7 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig + align: 'left' | 'right' } export interface TableCCMSOperationConfig { @@ -154,6 +156,7 @@ export interface ITableStepTableOperation { export interface ITableStepRowOperationButton { label: string level: 'normal' | 'primary' | 'danger' + align: 'left' | 'right' disabled?: boolean onClick: () => Promise } @@ -164,6 +167,7 @@ export interface ITableStepRowOperationButton { export interface ITableStepRowOperationGroup { label?: string children: React.ReactNode[] + align: 'left' | 'right' } /** @@ -732,6 +736,7 @@ export default class TableStep extends Step { : this.renderRowOperationButtonComponent({ label: operation.label, level: operation.level || 'normal', + align: operation.align, onClick: async () => { await this.handleRowOperation(operation, record) } })}
@@ -741,6 +746,7 @@ export default class TableStep extends Step { {this.renderRowOperationGroupComponent({ label: operation.label, + align: operation.align, children: (operation.operations || []).map((operation) => { if (!ConditionHelper(operation.condition, { record, data, step })) { return null -- Gitee From 6c3284b1fa1c4522372da30f49db4db4bad4a776 Mon Sep 17 00:00:00 2001 From: wangailin Date: Wed, 23 Feb 2022 16:58:26 +0800 Subject: [PATCH 062/164] =?UTF-8?q?feat:=20=E7=BD=AE=E7=A9=BA=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=89=8D=E7=BD=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 2 +- src/components/formFields/group/index.tsx | 2 +- src/components/formFields/tabs/index.tsx | 2 +- src/steps/form/index.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 94d287f..111ac3c 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -499,7 +499,7 @@ export default class FormField extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { this.formFieldsMounted[formFieldIndex] = false - this.formFields[formFieldIndex] = null + this.formFields && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 51e252a..0ed46c2 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -383,7 +383,7 @@ export default class TabsField extends Field { children: fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { this.formFieldsMounted[formFieldIndex] = false - this.formFields[formFieldIndex] = null + this.formFields && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true -- Gitee From 8691169638644f26e173068872e16f1b0a13c9e5 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 23 Feb 2022 22:16:26 +0800 Subject: [PATCH 063/164] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85treeSelect?= =?UTF-8?q?=E5=92=8Cselect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/common.tsx | 60 ++++++- .../formFields/select/multiple/index.tsx | 8 +- .../formFields/treeSelect/index.tsx | 162 +++++++++++++----- src/interface.ts | 89 +++++----- 4 files changed, 232 insertions(+), 87 deletions(-) diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 528b21d..2779ab8 100644 --- a/src/components/formFields/select/common.tsx +++ b/src/components/formFields/select/common.tsx @@ -1,7 +1,29 @@ import { ReactNode } from 'react' -import EnumerationHelper, { EnumerationOptionsConfig } from '../../../util/enumeration' +import EnumerationHelper, { EnumerationOptionsConfig, InterfaceEnumerationOptionsKVConfig, InterfaceEnumerationOptionsListConfig } from '../../../util/enumeration' import InterfaceHelper from '../../../util/interface' import { Field, FieldConfig, FieldProps, IField, Display, DisplayProps } from '../common' +import { + RecordParamConfig, + DataParamConfig, + StepParamConfig, + SourceParamConfig +} from '../../../interface' +import ParamHelper from '../../../util/param' +import { getValue } from '../../../util/value' + +type OptionsConfigDefaultValue = + | RecordParamConfig + | DataParamConfig + | StepParamConfig + | SourceParamConfig; + +interface AutomaticEnumerationOptionsConfig { + from: 'automatic'; + defaultValue?: OptionsConfigDefaultValue; + format?: + | InterfaceEnumerationOptionsKVConfig + | InterfaceEnumerationOptionsListConfig; +} export interface SelectFieldConfig extends FieldConfig { options?: EnumerationOptionsConfig @@ -25,7 +47,7 @@ interface SelectSingleFieldState { export default class SelectField extends Field implements IField { interfaceHelper = new InterfaceHelper() - constructor (props: FieldProps) { + constructor(props: FieldProps) { super(props) this.state = { @@ -33,10 +55,40 @@ export default class SelectField extends Fiel } } + optionsAutomaticValue = (defaultValue: OptionsConfigDefaultValue) => { + if (defaultValue !== undefined) { + return ParamHelper(defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + } + return undefined + } + options = ( - config: EnumerationOptionsConfig | undefined + config: EnumerationOptionsConfig | undefined | AutomaticEnumerationOptionsConfig ) => { if (config) { + if (config.from === 'automatic') { + if (config.defaultValue && config.defaultValue.source && config.defaultValue.field) { + const data = this.optionsAutomaticValue(config.defaultValue) + if (config.format) { + if (config.format.type === 'kv') { + return Object.keys(data).map((key) => ({ + value: key, + label: data[key] + })) + } else if (config.format.type === 'list') { + if (Array.isArray(data)) { + return data.map((item: any) => { + return { + value: getValue(item, (config.format as InterfaceEnumerationOptionsListConfig).keyField), + label: getValue(item, (config.format as InterfaceEnumerationOptionsListConfig).labelField) + } + }) + } + } + } + } + return [] + } EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { if (JSON.stringify(this.state.options) !== JSON.stringify(options)) { this.setState({ @@ -54,7 +106,7 @@ export default class SelectField extends Fiel export class SelectDisplay extends Display { interfaceHelper = new InterfaceHelper() - constructor (props: DisplayProps) { + constructor(props: DisplayProps) { super(props) this.state = { diff --git a/src/components/formFields/select/multiple/index.tsx b/src/components/formFields/select/multiple/index.tsx index d2dd263..0d84ff1 100644 --- a/src/components/formFields/select/multiple/index.tsx +++ b/src/components/formFields/select/multiple/index.tsx @@ -114,7 +114,13 @@ export default class SelectMultipleField extends SelectField { await this.props.onValueSet('', value, await this.validate(value)) }, + onChange: async (value: string | Array | undefined) => { + let useV = value + if (Array.isArray(useV) && multiple !== true && multiple?.type === 'split') { + useV = useV.join(multiple.split || ',') + } + return await this.props.onValueSet('', useV, await this.validate(useV)) + }, onClear: this.props.config.canClear ? async () => { await this.props.onValueSet('', undefined, await this.validate(undefined)) } : undefined, disabled: getBoolean(disabled), readonly: getBoolean(readonly), diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 6d3973a..6546deb 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -2,20 +2,42 @@ import React, { ReactNode } from 'react' import { get } from 'lodash' import { Field, FieldConfig, IField, FieldError, FieldProps } from '../common' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' +import ParamHelper from '../../../util/param' +import { RecordParamConfig, DataParamConfig, StepParamConfig, SourceParamConfig } from '../../../interface' +type OptionsConfigDefaultValue = RecordParamConfig | DataParamConfig | StepParamConfig | SourceParamConfig export interface TreeSelectFieldConfig extends FieldConfig { type: 'tree_select' - treeData?: ManualOptionsConfig | InterfaceOptionsConfig + mode?: 'tree' | 'table' + multiple?: true | TreeSelectMultipleArrayConfig | TreeSelectMultipleSplitConfig, + titleColumn: string, + treeData?: ManualOptionsConfig | InterfaceOptionsConfig | DefaultOptionsConfig +} + +interface TreeSelectMultipleArrayConfig { + type: 'array' +} + +interface TreeSelectMultipleSplitConfig { + type: 'split', + split?: string +} +export interface DefaultOptionsConfig { + from: 'automatic' + defaultValue?: OptionsConfigDefaultValue, + format?: InterfaceOptionsListConfig } export interface ManualOptionsConfig { from: 'manual' defaultIndex?: string | number - data?: Array<{ - value: string | number - title: string - [extra: string]: any - }> + data?: treeTableDataConfig[] +} + +export interface treeTableDataConfig { + value: any + title: string + children: treeTableDataConfig[] } export interface InterfaceOptionsConfig { @@ -36,36 +58,32 @@ export interface InterfaceOptionsListConfig { } export interface ISelectFieldOption { - value: string | number, - title: ReactNode, + key: any + value: any + title: ReactNode children?: Array } -interface treeData { - value: any, - title: string, - children?: treeData[] -} - -interface SelectSingleFieldState { - interfaceOptionsData: treeData[] +interface TreeSelectFieldState { + interfaceOptionsData: ISelectFieldOption[] } export interface ITreeSelectField { - value?: string, + value?: any, treeData: Array - onChange: (value: string) => Promise + titleColumn?: string + onChange: (value: any) => Promise } -export default class TreeSelectField extends Field implements IField { +export default class TreeSelectField extends Field | undefined> { interfaceHelper = new InterfaceHelper() interfaceOptionsConfig: string = '' - state: SelectSingleFieldState = { + state: TreeSelectFieldState = { interfaceOptionsData: [] } - constructor (props: FieldProps) { + constructor(props: FieldProps | undefined>) { super(props) this.state = { @@ -73,17 +91,26 @@ export default class TreeSelectField extends Field { + if (defaultValue !== undefined) { + return ParamHelper(defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + } + return undefined + } + formatTree = (treeList: any, value: string, title: string, children: string) => { - const rsMenu: treeData[] = [] + const rsMenu: ISelectFieldOption[] = [] treeList.forEach((val: any) => { - const theMenu: treeData = { + const theMenu: ISelectFieldOption = { title: '', - value: null + value: null, + key: null } theMenu.title = get(val, title) theMenu.value = get(val, value) + theMenu.key = get(val, value) if (get(val, children)) { theMenu.children = this.formatTree(get(val, children), value, title, children) @@ -95,7 +122,7 @@ export default class TreeSelectField extends Field { if (config) { - if (config.from === 'manual') { + if (config.from === 'automatic') { + if (config.defaultValue && config.defaultValue.source && config.defaultValue.field) { + const data = this.optionsAutomaticValue(config.defaultValue) + if (Array.isArray(data)) { + return this.formatTree( + data, + config.format?.keyField || 'value', + config.format?.titleField || 'title', + config.format?.childrenField || 'children' + ) + } + } + } else if (config.from === 'manual') { if (config.data) { return this.formatTree(config.data, 'value', 'title', 'children') } @@ -151,7 +190,7 @@ export default class TreeSelectField extends Field => { + validate = async (_value: string | Array | undefined): Promise => { const { config: { required @@ -169,11 +208,20 @@ export default class TreeSelectField extends Field { + renderTreeComponent = (props: ITreeSelectField) => { return - 您当前使用的UI版本没有实现TreeSelectSingleField组件的SelectSingle模式。 + 您当前使用的UI版本没有实现TreeSelectField组件的tree模式。
- + +
+
+ } + + renderTableComponent = (props: ITreeSelectField) => { + return + 您当前使用的UI版本没有实现TreeSelectField组件的table模式。 +
+
} @@ -182,24 +230,54 @@ export default class TreeSelectField extends Field - {this.renderComponent({ - value, - treeData: this.state.interfaceOptionsData, - onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) - })} -
- ) + const temp = this.options(optionsConfig, { record, data, step }) + const props: ITreeSelectField = { + value: undefined, + treeData: this.state.interfaceOptionsData, + onChange: async (value: string | Array | undefined) => { + let useV = value + if (Array.isArray(useV) && multiple !== true && multiple?.type === 'split') { + useV = useV.join(multiple.split || ',') + } + return await this.props.onValueSet('', useV, await this.validate(useV)) + } + } + if (optionsConfig && (optionsConfig.from === 'manual' || optionsConfig.from === 'automatic')) { + props.treeData = temp + } + if (multiple === true || multiple?.type === 'array') { + if (Array.isArray(value)) { + props.value = (value as Array) + } else if (value !== undefined) { + props.value = undefined + console.warn('数组类型的树形选框的值需要是字符串或数值的数组。') + } + } else if (multiple?.type === 'split') { + if (typeof value === 'string') { + props.value = String(value).split(multiple.split || ',') + } else if (value !== undefined) { + props.value = undefined + console.warn('字符串分隔类型的树形选框的值需要是字符串。') + } + } else { + props.value = Array.isArray(value) ? value : undefined + } + + if (mode === 'table') { + props.titleColumn = titleColumn + return this.renderTableComponent(props) + } else { + return this.renderTreeComponent(props) + } } } diff --git a/src/interface.ts b/src/interface.ts index 1f55966..60a20c5 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -7,75 +7,84 @@ * - content: 内容 */ export interface RichStringConfig { - type: 'plain' | 'markdown' | 'html' - content: string + type: 'plain' | 'markdown' | 'html'; + content: string; } -export type ParamConfig = RecordParamConfig | DataParamConfig | StepParamConfig | SourceParamConfig | URLParamConfig | QueryParamConfig | HashParamConfig | InterfaceParamConfig | StaticParamConfig +export type ParamConfig = + | RecordParamConfig + | DataParamConfig + | StepParamConfig + | SourceParamConfig + | URLParamConfig + | QueryParamConfig + | HashParamConfig + | InterfaceParamConfig + | StaticParamConfig; -interface RecordParamConfig { - source: 'record' - field: string +export interface RecordParamConfig { + source: 'record'; + field: string; } -interface DataParamConfig { - source: 'data' - field: string +export interface DataParamConfig { + source: 'data'; + field: string; } -interface StepParamConfig { - source: 'step' - step: number - field: string +export interface StepParamConfig { + source: 'step'; + step: number; + field: string; } -interface SourceParamConfig { - source: 'source', - field: string +export interface SourceParamConfig { + source: 'source'; + field: string; } interface URLParamConfig { - source: 'url', - field: string + source: 'url'; + field: string; } interface QueryParamConfig { - source: 'query', - filed: any + source: 'query'; + filed: any; } interface HashParamConfig { - source: 'hash', - filed: any + source: 'hash'; + filed: any; } interface InterfaceParamConfig { - source: 'interface', + source: 'interface'; // api: { // url: string, // method: 'POST', // contentType: 'json', // withCredentials: true // }, - api: object, - apiResponse: string + api: object; + apiResponse: string; } interface StaticParamConfig { - source: 'static', - value: any + source: 'static'; + value: any; } /** * 表单/详情分栏配置定义 -* - * type: 分栏类型 -* - * - * span: 固定分栏 -* - * - * width: 宽度分栏 -* - * value: 分栏相关配置值 -* - * wrap: 分栏后是否换行 -* - * gap: 分栏边距 -*/ + * - * type: 分栏类型 + * - * - * span: 固定分栏 + * - * - * width: 宽度分栏 + * - * value: 分栏相关配置值 + * - * wrap: 分栏后是否换行 + * - * gap: 分栏边距 + */ export interface ColumnsConfig { - enable?: boolean - type?: 'span' | 'width' - value?: number | string, - wrap?: boolean - gap?: number | string - rowGap?: number | string + enable?: boolean; + type?: 'span' | 'width'; + value?: number | string; + wrap?: boolean; + gap?: number | string; + rowGap?: number | string; } -- Gitee From 23d2ec3ad3b30c2a549bb6e41ace5243472402f5 Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 24 Feb 2022 10:54:10 +0800 Subject: [PATCH 064/164] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/enumeration.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/enumeration.ts b/src/util/enumeration.ts index 0b3c41d..f56f413 100644 --- a/src/util/enumeration.ts +++ b/src/util/enumeration.ts @@ -1,5 +1,5 @@ -import { InterfaceConfig } from "./interface"; -import { getValue } from "./value"; +import { InterfaceConfig } from './interface' +import { getValue } from './value' export type EnumerationOptionsConfig = ManualEnumerationOptionsConfig | InterfaceEnumerationOptionsConfig @@ -18,11 +18,11 @@ interface InterfaceEnumerationOptionsConfig { format?: InterfaceEnumerationOptionsKVConfig | InterfaceEnumerationOptionsListConfig } -interface InterfaceEnumerationOptionsKVConfig { +export interface InterfaceEnumerationOptionsKVConfig { type: 'kv' } -interface InterfaceEnumerationOptionsListConfig { +export interface InterfaceEnumerationOptionsListConfig { type: 'list' keyField: string labelField: string @@ -74,4 +74,4 @@ export default class EnumerationHelper { } return await EnumerationHelper._instance.options(config, interfaceRequire) } -} \ No newline at end of file +} -- Gitee From f597cd1d664e2317b9f4ea9b0e1fcf47e77c343a Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 24 Feb 2022 21:07:23 +0800 Subject: [PATCH 065/164] =?UTF-8?q?peat:=20=E4=BF=AE=E6=94=B9=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=90=8D&=E5=85=BC=E5=AE=B9mini?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/common.tsx | 12 +++--- .../formFields/treeSelect/index.tsx | 42 ++++++++++++++----- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 2779ab8..550175d 100644 --- a/src/components/formFields/select/common.tsx +++ b/src/components/formFields/select/common.tsx @@ -19,7 +19,7 @@ type OptionsConfigDefaultValue = interface AutomaticEnumerationOptionsConfig { from: 'automatic'; - defaultValue?: OptionsConfigDefaultValue; + sourceConfig?: OptionsConfigDefaultValue; format?: | InterfaceEnumerationOptionsKVConfig | InterfaceEnumerationOptionsListConfig; @@ -55,9 +55,9 @@ export default class SelectField extends Fiel } } - optionsAutomaticValue = (defaultValue: OptionsConfigDefaultValue) => { - if (defaultValue !== undefined) { - return ParamHelper(defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + optionsAutomaticValue = (sourceConfig: OptionsConfigDefaultValue) => { + if (sourceConfig !== undefined) { + return ParamHelper(sourceConfig, { record: this.props.record, data: this.props.data, step: this.props.step }) } return undefined } @@ -67,8 +67,8 @@ export default class SelectField extends Fiel ) => { if (config) { if (config.from === 'automatic') { - if (config.defaultValue && config.defaultValue.source && config.defaultValue.field) { - const data = this.optionsAutomaticValue(config.defaultValue) + if (config.sourceConfig && config.sourceConfig.source && config.sourceConfig.field) { + const data = this.optionsAutomaticValue(config.sourceConfig) if (config.format) { if (config.format.type === 'kv') { return Object.keys(data).map((key) => ({ diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 6546deb..405d701 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -10,8 +10,8 @@ export interface TreeSelectFieldConfig extends FieldConfig { type: 'tree_select' mode?: 'tree' | 'table' multiple?: true | TreeSelectMultipleArrayConfig | TreeSelectMultipleSplitConfig, - titleColumn: string, - treeData?: ManualOptionsConfig | InterfaceOptionsConfig | DefaultOptionsConfig + titleColumn?: string, + treeData?: ManualOptionsConfig | InterfaceOptionsConfig | AutomaticOptionsConfig } interface TreeSelectMultipleArrayConfig { @@ -22,9 +22,9 @@ interface TreeSelectMultipleSplitConfig { type: 'split', split?: string } -export interface DefaultOptionsConfig { +export interface AutomaticOptionsConfig { from: 'automatic' - defaultValue?: OptionsConfigDefaultValue, + sourceConfig?: OptionsConfigDefaultValue, format?: InterfaceOptionsListConfig } @@ -91,9 +91,9 @@ export default class TreeSelectField extends Field { - if (defaultValue !== undefined) { - return ParamHelper(defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + optionsAutomatic = (sourceConfig: OptionsConfigDefaultValue) => { + if (sourceConfig !== undefined) { + return ParamHelper(sourceConfig, { record: this.props.record, data: this.props.data, step: this.props.step }) } return undefined } @@ -122,7 +122,7 @@ export default class TreeSelectField extends Field { if (config) { if (config.from === 'automatic') { - if (config.defaultValue && config.defaultValue.source && config.defaultValue.field) { - const data = this.optionsAutomaticValue(config.defaultValue) + if (config.sourceConfig && config.sourceConfig.source && config.sourceConfig.field) { + const data = this.optionsAutomatic(config.sourceConfig) if (Array.isArray(data)) { return this.formatTree( data, @@ -208,6 +208,15 @@ export default class TreeSelectField extends Field { + return + 您当前使用的UI版本没有实现TreeSelectSingleField组件的SelectSingle模式。 +
+ +
+
+ } + renderTreeComponent = (props: ITreeSelectField) => { return 您当前使用的UI版本没有实现TreeSelectField组件的tree模式。 @@ -255,6 +264,7 @@ export default class TreeSelectField extends Field) @@ -276,8 +286,18 @@ export default class TreeSelectField extends Field + {this.renderComponent({ + value, + treeData: this.state.interfaceOptionsData, + onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) + })} + + ) } } } -- Gitee From 0501370816a331b77266d761247cf1fc19ab05b2 Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 25 Feb 2022 10:53:05 +0800 Subject: [PATCH 066/164] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/treeSelect/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 405d701..33433a2 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -264,7 +264,6 @@ export default class TreeSelectField extends Field) -- Gitee From 3c1ebc2fea83b79c67b0691479141a7f03cf21a1 Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 25 Feb 2022 15:31:45 +0800 Subject: [PATCH 067/164] =?UTF-8?q?fix:=20select=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E5=80=BC=E4=B8=BA=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/formFields/select/multiple/index.tsx | 2 +- src/components/formFields/treeSelect/index.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b1fc05e..a420bb7 100644 --- a/package.json +++ b/package.json @@ -85,4 +85,4 @@ "react": "^16.13.1", "react-dom": "^16.13.1" } -} +} \ No newline at end of file diff --git a/src/components/formFields/select/multiple/index.tsx b/src/components/formFields/select/multiple/index.tsx index 0d84ff1..9254fde 100644 --- a/src/components/formFields/select/multiple/index.tsx +++ b/src/components/formFields/select/multiple/index.tsx @@ -135,7 +135,7 @@ export default class SelectMultipleField extends SelectField Date: Fri, 25 Feb 2022 18:35:50 +0800 Subject: [PATCH 068/164] =?UTF-8?q?feat:=20=E5=AD=97=E7=AC=A6=E5=88=86?= =?UTF-8?q?=E9=9A=94=E5=A2=9E=E5=8A=A0=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formFields/select/multiple/index.tsx | 10 ++++--- .../formFields/treeSelect/index.tsx | 6 +++-- src/util/value.ts | 26 +++++++++++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/components/formFields/select/multiple/index.tsx b/src/components/formFields/select/multiple/index.tsx index 9254fde..262c998 100644 --- a/src/components/formFields/select/multiple/index.tsx +++ b/src/components/formFields/select/multiple/index.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { getBoolean } from '../../../../util/value' +import { getBoolean, transformValueType } from '../../../../util/value' import { FieldError } from '../../common' import SelectField, { ISelectFieldOption, SelectFieldConfig } from '../common' @@ -17,7 +17,8 @@ interface SelectMultipleArrayConfig { interface SelectMultipleSplitConfig { type: 'split', - split?: string + split?: string, + valueType?: string } export interface ISelectMultipleField { @@ -136,7 +137,7 @@ export default class SelectMultipleField extends SelectField option.value) props.value.filter((v) => { - if (props.options.map((option) => option.value).includes(v.toString())) { + if (values.includes(v)) { return true } else { console.warn(`选择框的当前值中${v}不在选项中。`) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 21b5be9..9ed3fa9 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -4,6 +4,7 @@ import { Field, FieldConfig, IField, FieldError, FieldProps } from '../common' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import ParamHelper from '../../../util/param' import { RecordParamConfig, DataParamConfig, StepParamConfig, SourceParamConfig } from '../../../interface' +import { transformValueType } from '../../../util/value' type OptionsConfigDefaultValue = RecordParamConfig | DataParamConfig | StepParamConfig | SourceParamConfig export interface TreeSelectFieldConfig extends FieldConfig { @@ -20,7 +21,8 @@ interface TreeSelectMultipleArrayConfig { interface TreeSelectMultipleSplitConfig { type: 'split', - split?: string + split?: string, + valueType?: string } export interface AutomaticOptionsConfig { from: 'automatic' @@ -273,7 +275,7 @@ export default class TreeSelectField extends Field { + switch (type) { + case 'string': + return list.map(v => String(v)) + + case 'number': + return list.map(v => +v) + + case 'boolean': + return list.map(v => Boolean(v)) + + default: + return list + } +} -- Gitee From 13054ae60ab6e6965191b7c0e23a3e31074cbdb0 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 2 Mar 2022 10:42:25 +0800 Subject: [PATCH 069/164] 1.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 00c1bd6..9d3a91d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccms", - "version": "1.2.0", + "version": "1.2.1", "description": "ConfigableCMS", "main": "lib/index.js", "module": "dist/index.js", -- Gitee From 07bf310402465db2a7ca3bd5f7ef7e702439c122 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 2 Mar 2022 10:42:28 +0800 Subject: [PATCH 070/164] 1.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d3a91d..3111d61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccms", - "version": "1.2.1", + "version": "1.2.2", "description": "ConfigableCMS", "main": "lib/index.js", "module": "dist/index.js", -- Gitee From 6e99401ada937dc7868c55e1455901af59f0d3bc Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 2 Mar 2022 10:45:23 +0800 Subject: [PATCH 071/164] 1.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3111d61..3a68709 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccms", - "version": "1.2.2", + "version": "1.2.3", "description": "ConfigableCMS", "main": "lib/index.js", "module": "dist/index.js", -- Gitee From 0deb94fa53ebb9aca7a17c6844b58c29dd7b1d6d Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 2 Mar 2022 17:58:13 +0800 Subject: [PATCH 072/164] docs: commit&eslint --- .commitlintrc.js | 26 ++++++++++++++------------ .cz-config.js | 30 ++++++++++++++++++++++++++++++ .eslintrc | 48 ++++++++++++++++++++++-------------------------- .prettierrc | 5 ++++- package.json | 9 ++++++--- rollup.config.js | 19 +++++++++---------- tsconfig.json | 41 +++++++++++++++-------------------------- 7 files changed, 100 insertions(+), 78 deletions(-) create mode 100644 .cz-config.js diff --git a/.commitlintrc.js b/.commitlintrc.js index ccc051b..72120c1 100644 --- a/.commitlintrc.js +++ b/.commitlintrc.js @@ -1,7 +1,9 @@ /** * @file commitlint 配置 - * commit message: (注意冒号后面有空格) - * + * commit message: (): (注意冒号后面有空格) + * type 标识commit类别 + * scope 标识commit影响范围 + * subject 本次修改的简单描述 */ module.exports = { extends: ['@commitlint/config-conventional'], @@ -14,18 +16,18 @@ module.exports = { 'feat', // 新功能(feature) 'perf', // 优化 'fix', // 修补bug - 'docs', // 文档(documentation) - 'style', // 格式(不影响代码运行的变动) - 'refactor', // 重构(即不是新增功能,也不是修改bug的代码变动) + 'docs', // 文档 + 'style', // 格式 + 'refactor', // 重构 'build', // 编译构建 'test', // 增加测试 'revert', // 回滚 - 'chore', // 其他改动 - ], + 'chore' // 其他改动 + ] ], - 'type-empty': [2, 'never'], // 提交不符合规范时,也可以提交,但是会有警告 - 'subject-empty': [2, 'never'], // 提交不符合规范时,也可以提交,但是会有警告 + 'type-empty': [2, 'never'], + 'subject-empty': [2, 'never'], 'subject-full-stop': [0, 'never'], - 'subject-case': [0, 'never'], - }, -}; + 'subject-case': [0, 'never'] + } +} diff --git a/.cz-config.js b/.cz-config.js new file mode 100644 index 0000000..ac77282 --- /dev/null +++ b/.cz-config.js @@ -0,0 +1,30 @@ +'use strict' +module.exports = { + types: [ + { value: 'init', name: '初始化' }, + { value: 'feat', name: '新增: 新功能' }, + { value: 'fix', name: '修复: 修复一个Bug' }, + { value: 'docs', name: '文档: 变更的只有文档' }, + { value: 'style', name: '格式: 空格, 分号等格式修复' }, + { value: 'refactor', name: '重构: 代码重构,注意和特性、修复区分开' }, + { value: 'perf', name: '性能: 提升性能' }, + { value: 'test', name: '测试: 添加一个测试' }, + { value: 'build', name: '工具: 开发工具变动(构建、脚手架工具等)' }, + { value: 'revert', name: '回滚: 代码回退' }, + { value: 'chore', name: '其他' } + ], + scopes: [{ name: 'javascript' }, { name: 'typescript' }, { name: 'React' }, { name: 'node' }], + messages: { + type: '选择一种你的提交类型:', + scope: '选择一个scope (可选):', + customScope: 'Denote the SCOPE of this change:', + subject: '短说明:\n', + body: '长说明,使用"|"换行(可选):\n', + breaking: '非兼容性说明 (可选):\n', + footer: '关联关闭的issue,例如:#31, #34(可选):\n', + confirmCommit: '确定提交说明?(yes/no)' + }, + allowCustomScopes: true, + allowBreakingChanges: ['特性', '修复'], + subjectLimit: 100 +} diff --git a/.eslintrc b/.eslintrc index 04b963d..23b421f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,4 @@ { - // 为我们提供运行环境,一个环境定义了一组预定义的全局变量 "env": { "browser": true, "es2021": true, @@ -7,19 +6,17 @@ "node": true, "commonjs": true }, - // 一个配置文件可以被基础配置中的已启用的规则继承。 "extends": [ "airbnb", - "prettier", "plugin:compat/recommended", "plugin:jest/recommended", "plugin:react/recommended", "plugin:import/typescript", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "prettier", + "plugin:prettier/recommended" ], - // ESLint 默认使用Espree作为其解析器,你可以在配置文件中指定一个不同的解析器 "parser": "@typescript-eslint/parser", - // 配置解析器支持的语法 "parserOptions": { "ecmaFeatures": { "jsx": true @@ -27,28 +24,27 @@ "ecmaVersion": 12, "sourceType": "module" }, - // ESLint 支持使用第三方插件。在使用插件之前,你必须使用 npm 安装它。 - // 在配置文件里配置插件时,可以使用 plugins 关键字来存放插件名字的列表。插件名称可以省略 eslint-plugin- 前缀 - "plugins": [ - "react", - "babel", - "jest", - "react-hooks", - "@typescript-eslint" - ], - // ESLint 附带有大量的规则。你可以使用注释或配置文件修改你项目中要使用的规则。要改变一个规则设置,你必须将规则 ID 设置为下列值之一: - // "off" 或 0 - 关闭规则 - // "warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出) - // "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出) - "rules": { - "no-use-before-define": "off", - "react/display-name": 0, - "import/extensions": 0 - }, - // 指定react版本为安装的版本 + "plugins": ["react", "babel", "jest", "react-hooks", "@typescript-eslint"], "settings": { "react": { "version": "16.13.1" - } + }, + "polyfills": ["Promise"] + }, + "rules": { + "prettier/prettier": "error", + "arrow-body-style": "off", + "prefer-arrow-callback": "off", + "no-use-before-define": "off", + "react/display-name": 0, + "import/extensions": 0, + "comma-dangle": ["error", "never"], + "space-before-function-paren": [0, "always"], + "react/jsx-filename-extension": [ + 2, + { + "extensions": [".js", ".jsx", ".ts", ".tsx"] + } + ] } } diff --git a/.prettierrc b/.prettierrc index d0ed5e8..51fdad2 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,8 @@ { "singleQuote": true, "printWidth": 120, - "tabWidth": 2 + "useTabs": false, + "tabWidth": 2, + "semi": false, + "trailingComma": "none" } diff --git a/package.json b/package.json index 3a68709..723ebea 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "config": { "commitizen": { - "path": "./node_modules/cz-conventional-changelog" + "path": "./node_modules/cz-customizable" } }, "keywords": [ @@ -56,7 +56,8 @@ "qiankun": "^2.5.1", "query-string": "^6.13.8", "rc-table": "^7.9.10", - "react-loadable": "^5.5.0" + "react-loadable": "^5.5.0", + "tslib": "^2.3.1" }, "devDependencies": { "@babel/cli": "^7.16.8", @@ -88,7 +89,8 @@ "babel-jest": "^26.3.0", "babel-plugin-import": "^1.13.0", "commitizen": "^4.2.4", - "cz-conventional-changelog": "^3.3.0", + "commitlint-config-cz": "^0.13.2", + "cz-customizable": "^6.3.0", "eslint": "^7.32.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.3.0", @@ -98,6 +100,7 @@ "eslint-plugin-jest": "^26.0.0", "eslint-plugin-jsx-a11y": "^6.5.1", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^4.3.1", "eslint-plugin-react": "^7.28.0", "eslint-plugin-react-hooks": "^4.3.0", diff --git a/rollup.config.js b/rollup.config.js index 523ba5a..6b20707 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -12,9 +12,8 @@ export default { output: [ { format: 'esm', - file: path.resolve('dist/index.esm.js'), // 输出的文件路径 - // sourcemap: true, - }, + file: path.resolve('dist/index.esm.js') + } ], plugins: [ json(), @@ -23,21 +22,21 @@ export default { // exclude: ['node_modules/**', 'es/**', 'dist/**'] // }), ts({ - tsconfig: path.resolve(__dirname, 'tsconfig.json'), + tsconfig: path.resolve(__dirname, 'tsconfig.json') }), babel({ babelHelpers: 'runtime', - exclude: 'node_modules/**', // 只编译我们的源代码 + exclude: 'node_modules/**' }), + commonjs(), nodeResolve({ - extensions: ['.js', '.ts', '.tsx'], + extensions: ['.js', '.ts', '.tsx'] }), - terser(), + terser() ], external: ['react', 'react-dom', 'marked', 'lodash', 'axios', 'query-string', 'moment', 'qiankun'], - // external: id => /lodash/.test(id), // lodash 现在将被视为外部的(externals),不会与你的库打包在一起 watch: { - include: 'src/**', - }, + include: 'src/**' + } }; diff --git a/tsconfig.json b/tsconfig.json index 1e93bd0..8231895 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,37 +1,26 @@ { "compilerOptions": { - "target": "ES6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - "sourceMap": true, /* Generates corresponding '.map' file. */ - "outDir": "./lib/", //输出编译后的文件 /* Redirect output structure to the directory. */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - "esModuleInterop": true, /* 通过为所有导入创建命名空间对象,启用 CommonJS 和 ES 模块之间的发射互操作性 Implies 'allowSyntheticDefaultImports'. */ - "declaration": true, // 生成定义文件 /* Generates corresponding '.d.ts' file. */ - "jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declarationDir": "./ts/types", // 定义文件输出目录 - // "declarationMap": true, // 生成定义sourceMap /* Generates a sourcemap for each corresponding '.d.ts' file. */ - // "removeComments": true, // 删除注释 - // "noUnusedLocals": true, // 未使用变量报错 /* Report errors on unused locals. */ + "target": "ES6", + "module": "ESNext", + "allowJs": true, + "sourceMap": true, + "outDir": "./lib/", + "moduleResolution": "node", + "esModuleInterop": true, + "declaration": true, + "jsx": "react", "strict": true, - "lib": [ // // 指定要包含在编译中的库文件导入库类型定义 - "dom", - "dom.iterable", - "esnext" - ], - "skipLibCheck": true, // Skip type checking of declaration files. + "lib": ["dom", "dom.iterable", "esnext"], + "skipLibCheck": true, "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true, // /* Disallow inconsistently-cased references to the same file. */ + "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, - "noImplicitAny": true, + "noImplicitAny": false, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, - "types": [ // // 导入指定类型包 - "node", - "jest" - ], - "experimentalDecorators": true, + "types": ["node", "jest"], + "experimentalDecorators": true } } -- Gitee From 4cd8f0218b4e7f902ec4d443648853478ec39388 Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 3 Mar 2022 10:43:07 +0800 Subject: [PATCH 073/164] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=A7=84?= =?UTF-8?q?=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .babelrc | 7 ++----- .eslintrc | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.babelrc b/.babelrc index 0792683..5e1194f 100644 --- a/.babelrc +++ b/.babelrc @@ -14,11 +14,8 @@ { "targets": { "node": "10.13.0" - }, - // "modules": false - //将 ES6 module 转换为其他模块规范,可选 "adm" | "umd" | "systemjs" | "commonjs" | "cjs" | false,默认为 false - // 否则 Babel 会在 Rollup 有机会做处理之前,将我们的模块转成 CommonJS ,导致 Rollup 的一些处理失败。 + } } ] ] -} \ No newline at end of file +} diff --git a/.eslintrc b/.eslintrc index 23b421f..fc8dbf2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,6 @@ "plugin:react/recommended", "plugin:import/typescript", "plugin:@typescript-eslint/recommended", - "prettier", "plugin:prettier/recommended" ], "parser": "@typescript-eslint/parser", @@ -32,9 +31,7 @@ "polyfills": ["Promise"] }, "rules": { - "prettier/prettier": "error", - "arrow-body-style": "off", - "prefer-arrow-callback": "off", + "react/jsx-props-no-spreading": 0, "no-use-before-define": "off", "react/display-name": 0, "import/extensions": 0, -- Gitee From b3cc54715a59f729aedb908ba245be9c2708725f Mon Sep 17 00:00:00 2001 From: wangailin Date: Wed, 9 Mar 2022 17:49:48 +0800 Subject: [PATCH 074/164] feat: package version update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f8968d7..b1fc05e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccms", - "version": "1.2.2", + "version": "1.2.4", "description": "ConfigableCMS", "main": "lib/index.js", "module": "dist/index.js", -- Gitee From 9347a0393e6f62c81ed35b7bab3e272a2d01c934 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 10 Mar 2022 11:18:45 +0800 Subject: [PATCH 075/164] =?UTF-8?q?feat:=20[form]=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=A1=A8=E5=8D=95=E9=A1=B9=E7=82=B9=E5=87=BB=E5=89=8D?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C[table]=E4=BF=AE=E5=A4=8D=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6=E6=9C=AA=E7=94=9F=E6=95=88,=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/form/index.tsx | 14 +++++++++++-- src/steps/table/index.tsx | 44 +++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 5be24f0..27debc8 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -79,6 +79,7 @@ export interface ActionConfig { type: 'submit' | 'cancel' | 'ccms', label: string, mode: 'normal' | 'primary' | 'link', + submitValidate: boolean condition?: ConditionConfig handle?: OperationConfig callback?: { @@ -620,6 +621,7 @@ export default class FormStep extends Step { onClick: () => this.handleCancel() })) } else { + const submitValidate = actions[index].submitValidate const OperationHelperWrapper = { this.renderButtonComponent({ label: actions[index].label || '', mode: actions[index].mode, - onClick + onClick: submitValidate + ? async () => { + await this.handleValidations() + console.info('表单参数信息', this.submitData, this.state.formValue, this.formData) + if (this.canSubmit) { + onClick() + } + } + : onClick }) )} @@ -645,7 +655,7 @@ export default class FormStep extends Step { } } } - + if (ready) { return ( diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index a3a5dbd..44071b1 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -62,7 +62,9 @@ export interface TableCCMSOperationConfig { type: 'ccms' page: any target: 'current' | 'page' | 'open' | 'handle' + historyTpye?: 'replace' targetURL: string + width: string data: { [key: string]: ParamConfig } params?: { field: string, data: ParamConfig }[] callback?: boolean @@ -98,6 +100,7 @@ interface TableOperationConfirmConfig { export interface ITable { title: string | null primary: string + width: string data: { [field: string]: any }[] columns: ITableColumn[] pagination?: { @@ -213,6 +216,7 @@ interface TableState { operation: { enable: boolean target: 'current' | 'handle' + width: string title: string visible: boolean config: CCMSConfig @@ -245,6 +249,7 @@ export default class TableStep extends Step { enable: false, target: 'current', title: '', + width: '400px', visible: false, config: {}, data: {}, @@ -322,6 +327,7 @@ export default class TableStep extends Step { operation: { enable: true, target: operation.handle.target, + width: operation.handle.width, title: operation.label, visible: true, config: operationConfig, @@ -337,7 +343,11 @@ export default class TableStep extends Step { if (this.props.handlePageRedirect) { this.props.handlePageRedirect(`${targetURL}${targetKey}`) } else { - window.location.href = `${targetURL}${targetKey}` + if (operation.handle.historyTpye === 'replace') { + window.location.replace(`${targetURL}${targetKey}`) + } else { + window.location.href = `${targetURL}${targetKey}` + } } } else if (operation.handle.target === 'open') { const sourceURL = await this.props.loadPageFrameURL(operation.handle.page) @@ -502,6 +512,7 @@ export default class TableStep extends Step { operation: { enable: operationEnable, target: operationTarget, + width: operationWidth, title: operationTitle, visible: operationVisible, config: operationConfig, @@ -518,6 +529,7 @@ export default class TableStep extends Step { const props: ITable = { title: label, + width, primary, data: getDate, columns: (columns || []).filter((column) => column.field !== undefined && column.field !== '').map((column, index) => { @@ -702,11 +714,11 @@ export default class TableStep extends Step { {operationEnable && ( operationTarget === 'current' ? ( - this.renderOperationModal({ - title: operationTitle, - width, - visible: operationVisible, - children: ( + this.renderOperationModal({ + title: operationTitle, + width: operationWidth, + visible: operationVisible, + children: ( { } }} /> - ), - onClose: () => { - const { operation } = this.state - operation.enable = false - operation.visible = false - this.setState({ operation }) - } - }) - ) + ), + onClose: () => { + const { operation } = this.state + operation.enable = false + operation.visible = false + this.setState({ operation }) + } + }) + ) : ( { } }} /> - ) + ) )} ) -- Gitee From c5681445505fb96effd9656b356315459fd221cb Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 10 Mar 2022 11:57:24 +0800 Subject: [PATCH 076/164] =?UTF-8?q?feat:=20=E8=A1=A8=E6=A0=BC=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=A2=9E=E5=8A=A0=E4=B8=BA=E4=B8=89=E7=A7=8D=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E3=80=81=E6=8C=89=E9=92=AE=E7=BB=84=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E6=8E=A5=E6=8C=89=E9=92=AE,=E6=B7=BB=E5=8A=A0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=8F=9C=E5=8D=95=E5=B7=A6=E5=8F=B3=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E9=85=8D=E7=BD=AE,=E8=A1=A8=E6=A0=BC=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=A0=8F=E4=BD=8D=E7=BD=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 250 +++++++++++++++++++++++++++----------- 1 file changed, 181 insertions(+), 69 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index a3a5dbd..2409bc1 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -22,10 +22,12 @@ export interface TableConfig extends StepConfig { label: string primary: string columns: ColumnConfigs[] + rowOperationsPosition: 'left' operations?: { - tableOperations?: Array - rowOperations?: Array - multirowOperations?: Array + tableOperations?: Array + leftTableOperations?: Array + rowOperations?: Array + multirowOperations?: Array } pagination?: { mode: 'none' | 'client' | 'server' @@ -35,6 +37,11 @@ export interface TableConfig extends StepConfig { } } +/** + * 表格步骤-菜单配置 + */ +export type TableOperationsType = TableOperationConfig | TableOperationGroupConfig | TableOperationDropdownConfig + /** * 表格步骤-操作配置文件格式 */ @@ -43,6 +50,18 @@ export interface TableOperationGroupConfig { label?: string level?: 'normal' | 'primary' | 'danger' operations: Array + align: 'left' | 'right' +} + +/** + * 表格步骤-操作配置文件下拉菜单 + */ +export interface TableOperationDropdownConfig { + type: 'dropdown' + label?: string + level?: 'normal' | 'primary' | 'danger' + operations: Array + align: 'left' | 'right' } /** @@ -56,6 +75,7 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig + align: 'left' | 'right' } export interface TableCCMSOperationConfig { @@ -107,6 +127,7 @@ export interface ITable { onChange: (page: number, pageSize: number) => void } tableOperations: React.ReactNode | null + leftTableOperations: React.ReactNode | null multirowOperations: React.ReactNode | null } @@ -140,6 +161,7 @@ export interface ITableStepTableOperation { export interface ITableStepRowOperationButton { label: string level: 'normal' | 'primary' | 'danger' + align: 'left' | 'right' disabled?: boolean onClick: () => Promise } @@ -150,6 +172,7 @@ export interface ITableStepRowOperationButton { export interface ITableStepRowOperationGroup { label?: string children: React.ReactNode[] + align: 'left' | 'right' } /** @@ -237,7 +260,7 @@ export default class TableStep extends Step { /* 服务端分页情况下页码溢出标识:页码溢出时退回重新请求,此标识符用于防止死循环判断 */ pageOverflow: boolean = false - constructor(props: StepProps) { + constructor (props: StepProps) { super(props) this.state = { @@ -441,6 +464,18 @@ export default class TableStep extends Step {
} + renderRowOperationDropdownComponent = (props: ITableStepRowOperationGroup) => { + return + 您当前使用的UI版本没有实现Table组件的OperationDropdown部分。 + + } + + renderRowOperationDropdownItemComponent = (props: ITableStepRowOperationGroupItem) => { + return + 您当前使用的UI版本没有实现Table组件的OperationDropdownItem部分。 + + } + renderTableOperationComponent = (props: ITableStepTableOperation) => { return 您当前使用的UI版本没有实现Table组件的OperationButton部分。 @@ -465,6 +500,18 @@ export default class TableStep extends Step { } + renderTableOperationDropdownComponent = (props: ITableStepTableOperationGroup) => { + return + 您当前使用的UI版本没有实现Table组件的OperationDropdown部分。 + + } + + renderTableOperationDropdownItemComponent = (props: ITableStepTableOperationGroupItem) => { + return + 您当前使用的UI版本没有实现Table组件的OperationDropdownItem部分。 + + } + renderOperationModal = (props: ITableStepOperationModal) => { const mask = document.createElement('DIV') mask.style.position = 'fixed' @@ -482,11 +529,85 @@ export default class TableStep extends Step { document.body.appendChild(mask) } - render() { + tableOperations = (tabOperations: Array, getDate: Array<{}>) => { + const { + pageAuth + } = this.state + return tabOperations.length > 0 + ? this.renderTableOperationComponent({ + children: tabOperations.map((operation: TableOperationsType, index: number) => { + if (operation.type === 'button') { + let hidden = false + if (operation.handle && operation.handle.type === 'ccms') { + hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] + operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) + } + + return hidden + ? + : + {this.renderTableOperationButtonComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { + await this.handleRowOperation(operation, getDate) + } + })} + + } else if (operation.type === 'group') { + return + {this.renderTableOperationGroupComponent({ + label: operation.label, + children: (operation.operations || []).map((operation) => { + let hidden = false + if (operation.handle && operation.handle.type === 'ccms') { + hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] + operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) + } + return hidden + ? null + : this.renderTableOperationGroupItemComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { await this.handleRowOperation(operation, getDate) } + }) + }) + })} + + } else if (operation.type === 'dropdown') { + return + {this.renderTableOperationDropdownComponent({ + label: operation.label, + children: (operation.operations || []).map((operation) => { + let hidden = false + if (operation.handle && operation.handle.type === 'ccms') { + hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] + operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) + } + return hidden + ? null + : this.renderTableOperationDropdownItemComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { await this.handleRowOperation(operation, getDate) } + }) + }) + })} + + } else { + return + } + }) + }) + : null + } + + render () { const { config: { field, label, + rowOperationsPosition, width, primary, columns, @@ -548,53 +669,8 @@ export default class TableStep extends Step { } } }), - tableOperations: operations && operations.tableOperations - ? this.renderTableOperationComponent({ - children: operations.tableOperations.map((operation, index) => { - if (operation.type === 'button') { - let hidden = false - if (operation.handle && operation.handle.type === 'ccms') { - hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] - operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) - } - - return hidden - ? - : - {this.renderTableOperationButtonComponent({ - label: operation.label, - level: operation.level || 'normal', - onClick: async () => { - await this.handleRowOperation(operation, getDate) - } - })} - - } else if (operation.type === 'group') { - return - {this.renderTableOperationGroupComponent({ - label: operation.label, - children: (operation.operations || []).map((operation) => { - let hidden = false - if (operation.handle && operation.handle.type === 'ccms') { - hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] - operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) - } - return hidden - ? null - : this.renderTableOperationGroupItemComponent({ - label: operation.label, - level: operation.level || 'normal', - onClick: async () => { await this.handleRowOperation(operation, getDate) } - }) - }) - })} - - } else { - return - } - }) - }) - : null, + tableOperations: this.tableOperations(operations?.tableOperations || [], getDate), + leftTableOperations: this.tableOperations(operations?.leftTableOperations || [], getDate), multirowOperations: null } @@ -625,7 +701,7 @@ export default class TableStep extends Step { } if (operations && operations.rowOperations && operations.rowOperations.length > 0) { - props.columns.push({ + const rowOperationData: ITableColumn = { field: 'ccms-table-rowOperation', label: '操作', align: 'left', @@ -651,6 +727,7 @@ export default class TableStep extends Step { : this.renderRowOperationButtonComponent({ label: operation.label, level: operation.level || 'normal', + align: operation.align, onClick: async () => { await this.handleRowOperation(operation, record) } })} @@ -660,6 +737,7 @@ export default class TableStep extends Step { {this.renderRowOperationGroupComponent({ label: operation.label, + align: operation.align, children: (operation.operations || []).map((operation) => { if (!ConditionHelper(operation.condition, { record, data, step })) { return null @@ -682,6 +760,34 @@ export default class TableStep extends Step { })} ) + } else if (operation.type === 'dropdown') { + return ( + + {this.renderRowOperationDropdownComponent({ + label: operation.label, + align: operation.align, + children: (operation.operations || []).map((operation) => { + if (!ConditionHelper(operation.condition, { record, data, step })) { + return null + } + + let hidden = false + if (operation.handle && operation.handle.type === 'ccms') { + hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] + operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) + } + + return hidden + ? null + : this.renderRowOperationDropdownItemComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { await this.handleRowOperation(operation, record) } + }) + }) + })} + + ) } else { return } @@ -691,7 +797,13 @@ export default class TableStep extends Step { return } } - }) + } + + if (rowOperationsPosition === 'left') { + props.columns.unshift(rowOperationData) + } else { + props.columns.push(rowOperationData) + } } const CCMS = this.CCMS @@ -702,11 +814,11 @@ export default class TableStep extends Step { {operationEnable && ( operationTarget === 'current' ? ( - this.renderOperationModal({ - title: operationTitle, - width, - visible: operationVisible, - children: ( + this.renderOperationModal({ + title: operationTitle, + width, + visible: operationVisible, + children: ( { } }} /> - ), - onClose: () => { - const { operation } = this.state - operation.enable = false - operation.visible = false - this.setState({ operation }) - } - }) - ) + ), + onClose: () => { + const { operation } = this.state + operation.enable = false + operation.visible = false + this.setState({ operation }) + } + }) + ) : ( { } }} /> - ) + ) )} ) -- Gitee From eb37a17ac88e43502d607fc5722e75f739e91b06 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 10 Mar 2022 14:35:32 +0800 Subject: [PATCH 077/164] =?UTF-8?q?fix:=20=E4=BB=A3=E7=A0=81=E8=AF=84?= =?UTF-8?q?=E5=AE=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 1de5f0b..9db55f2 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -164,7 +164,6 @@ export interface ITableStepTableOperation { export interface ITableStepRowOperationButton { label: string level: 'normal' | 'primary' | 'danger' - align: 'left' | 'right' disabled?: boolean onClick: () => Promise } @@ -175,7 +174,6 @@ export interface ITableStepRowOperationButton { export interface ITableStepRowOperationGroup { label?: string children: React.ReactNode[] - align: 'left' | 'right' } /** @@ -539,13 +537,13 @@ export default class TableStep extends Step { document.body.appendChild(mask) } - tableOperations = (tabOperations: Array, getDate: Array<{}>) => { + tableOperations = (tableOperationsList: Array, getDate: Array<{}>) => { const { pageAuth } = this.state - return tabOperations.length > 0 + return tableOperationsList.length > 0 ? this.renderTableOperationComponent({ - children: tabOperations.map((operation: TableOperationsType, index: number) => { + children: tableOperationsList.map((operation: TableOperationsType, index: number) => { if (operation.type === 'button') { let hidden = false if (operation.handle && operation.handle.type === 'ccms') { @@ -739,7 +737,6 @@ export default class TableStep extends Step { : this.renderRowOperationButtonComponent({ label: operation.label, level: operation.level || 'normal', - align: operation.align, onClick: async () => { await this.handleRowOperation(operation, record) } })} @@ -749,7 +746,6 @@ export default class TableStep extends Step { {this.renderRowOperationGroupComponent({ label: operation.label, - align: operation.align, children: (operation.operations || []).map((operation) => { if (!ConditionHelper(operation.condition, { record, data, step })) { return null @@ -777,7 +773,6 @@ export default class TableStep extends Step { {this.renderRowOperationDropdownComponent({ label: operation.label, - align: operation.align, children: (operation.operations || []).map((operation) => { if (!ConditionHelper(operation.condition, { record, data, step })) { return null -- Gitee From 7316aeabcc415aaf2249c46c8b2a920fc0f0eaf1 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 10 Mar 2022 14:43:53 +0800 Subject: [PATCH 078/164] =?UTF-8?q?fix:=20=E6=8C=89=E9=92=AE=E4=B8=8E?= =?UTF-8?q?=E5=85=B6=E5=AE=83=E7=B1=BB=E5=9E=8B=E7=BB=9F=E4=B8=80=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91=E7=BC=96=E5=86=99=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 9db55f2..d34334e 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -551,17 +551,19 @@ export default class TableStep extends Step { operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) } - return hidden - ? - : - {this.renderTableOperationButtonComponent({ - label: operation.label, - level: operation.level || 'normal', - onClick: async () => { - await this.handleRowOperation(operation, getDate) - } - })} - + return + { + hidden + ? null + : this.renderTableOperationButtonComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { + await this.handleRowOperation(operation, getDate) + } + }) + } + } else if (operation.type === 'group') { return {this.renderTableOperationGroupComponent({ -- Gitee From b422e64eed681ea6acdaa51cd64899fabf3ede31 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 10 Mar 2022 14:47:30 +0800 Subject: [PATCH 079/164] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index d34334e..67b8df0 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -50,7 +50,6 @@ export interface TableOperationGroupConfig { label?: string level?: 'normal' | 'primary' | 'danger' operations: Array - align: 'left' | 'right' } /** @@ -61,7 +60,6 @@ export interface TableOperationDropdownConfig { label?: string level?: 'normal' | 'primary' | 'danger' operations: Array - align: 'left' | 'right' } /** -- Gitee From 9c141d3d86f498ae15b0538e389543fc85c4fc39 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 10 Mar 2022 17:23:55 +0800 Subject: [PATCH 080/164] =?UTF-8?q?feat:=20=E5=AD=90=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E9=A1=B9=E6=9C=AA=E5=A1=AB=E5=86=99=E9=A1=B9=E5=85=B7=E4=BD=93?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E5=86=85=E5=AE=B9=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=EF=BC=8C=E5=AD=90=E8=A1=A8=E5=8D=95=E9=A1=B9=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E9=A1=B9=E4=B8=8D=E5=81=9A=E8=A1=A8=E5=8D=95=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/index.tsx | 9 ++++++++- src/components/formFields/group/index.tsx | 12 ++++++++++-- src/components/formFields/importSubform/index.tsx | 10 +++++++++- src/components/formFields/tabs/index.tsx | 9 ++++++++- src/steps/form/index.tsx | 1 + 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d95ddea..778cdcf 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -127,6 +127,7 @@ export default class FormField extends Field = [] const formDataList = cloneDeep(this.state.formDataList) @@ -143,6 +144,10 @@ export default class FormField extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + const errTips = `${this.props.config.label || ''} ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}` + errors.push(new FieldError(errTips)) } return errors.length ? errors : true @@ -494,6 +500,7 @@ export default class FormField extends Field = [] const formData = cloneDeep(this.state.formData) for (const fieldIndex in (this.props.config.fields || [])) { const formItem = this.formFields[fieldIndex] + const formConfig = this.props.config.fields?.[fieldIndex] if (formItem !== null && formItem !== undefined) { const validation = await formItem.validate(getValue(value, (this.props.config.fields || [])[fieldIndex].field)) - if (validation === true || this.formFieldsMounted[fieldIndex] === false) { + if (validation === true) { formData[fieldIndex] = { status: 'normal' } } else { childrenError++ formData[fieldIndex] = { status: 'error', message: validation[0].message } + childrenErrorMsg.push({ + name: formConfig?.label, + msg: validation[0].message + }) } } } @@ -88,7 +94,8 @@ export default class GroupField extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + const errTips = `${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + errors.push(new FieldError(errTips)) } return errors.length ? errors : true @@ -307,6 +314,7 @@ export default class GroupField extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { this.formFieldsMounted[formFieldIndex] = false + this.formFields && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 5735eb9..23f933d 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -116,11 +116,13 @@ export default class ImportSubformField extends Field = [] const formData = cloneDeep(this.state.formData) for (const fieldIndex in (this.state.fields || [])) { const formItem = this.formFields[fieldIndex] + const formConfig = this.state.fields?.[fieldIndex] if (formItem !== null && formItem !== undefined) { const validation = await formItem.validate(getValue(value, this.getFullpath((this.state.fields || [])[fieldIndex].field))) @@ -129,6 +131,10 @@ export default class ImportSubformField extends Field 0) { - errors.push(new FieldError('子项中存在错误')) + const errTips = `${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + errors.push(new FieldError(errTips)) } return errors.length ? errors : true @@ -375,6 +382,7 @@ export default class ImportSubformField extends Field { if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { this.formFieldsMounted[formFieldIndex] = false + this.formFields && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index a32b115..9167351 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -113,6 +113,7 @@ export default class TabsField extends Field = [] const formDataList = cloneDeep(this.state.formDataList) @@ -133,6 +134,10 @@ export default class TabsField extends Field extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + const errTips = `${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + errors.push(new FieldError(errTips)) } return errors.length ? errors : true @@ -380,6 +386,7 @@ export default class TabsField extends Field { children: fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: formValue, data, step })) { this.formFieldsMounted[formFieldIndex] = false + this.formFields && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true -- Gitee From 0fb5f511d0974a8f5a0051569e24eb906f45c50b Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 11 Mar 2022 15:38:04 +0800 Subject: [PATCH 081/164] =?UTF-8?q?feat:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/image/index.tsx | 68 +++++++++++++++++++++++++++ src/components/detail/index.tsx | 4 ++ src/index.tsx | 1 + 3 files changed, 73 insertions(+) create mode 100644 src/components/detail/image/index.tsx diff --git a/src/components/detail/image/index.tsx b/src/components/detail/image/index.tsx new file mode 100644 index 0000000..9bc21f1 --- /dev/null +++ b/src/components/detail/image/index.tsx @@ -0,0 +1,68 @@ +import React from 'react' +import { DetailField, DetailFieldConfig, IDetailField } from '../common' + +/** + * 详情项图片组件 格式定义 + * - type: 图片类型 + * - height: 图片高度 + * - width: 图片宽度 + * - preview: 点击预览 + */ +export interface ImageDetailConfig extends DetailFieldConfig { + type: 'Image', + height?: string | number + width?: string | number + preview?: boolean +} + +export interface IImageDetail { + value: string + height: string | number + width: string | number + preview?: boolean +} + +export default class ImageDetail extends DetailField implements IDetailField { + renderComponent = (props: IImageDetail) => { + return + 您当前使用的UI版本没有实现Image组件。 +
+
+
+ } + + getValue = () => { + const { + value, + config: { + defaultValue + } + } = this.props + if (value === undefined || value === null || value === '') { + return defaultValue !== undefined ? defaultValue : '' + } + return value + } + + render = () => { + const { + config: { + height, + width, + preview + } + } = this.props + const props: any = { + height, + width, + preview, + value: this.getValue() + } + + return ( + + {this.renderComponent(props)} + + ) + } +} diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index 24ae057..a88014b 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -2,6 +2,7 @@ import TextField, { TextFieldConfig } from './text' import EnumDetail, { EnumDetailConfig } from './enum' import StatementDetail, { StatementDetailConfig } from './statement' +import ImageDetail, { ImageDetailConfig } from './image' import GroupField, { GroupFieldConfig } from './group' import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' @@ -13,6 +14,7 @@ export type DetailFieldConfigs = TextFieldConfig | EnumDetailConfig | StatementDetailConfig | + ImageDetailConfig | GroupFieldConfig | ImportSubformFieldConfig @@ -21,6 +23,7 @@ export type componentType = 'group' | 'detail_enum' | 'statement' | + 'image' | 'import_subform' export default { @@ -28,5 +31,6 @@ export default { text: TextField, import_subform: ImportSubformField, detail_enum: EnumDetail, + image: ImageDetail, statement: StatementDetail } diff --git a/src/index.tsx b/src/index.tsx index b193a05..f91a5da 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -56,6 +56,7 @@ export { default as DetailStep } from './steps/detail' export { default as DetailGroupField } from './components/detail/group' export { default as DetailEunmField } from './components/detail/enum' export { default as DetailStatementField } from './components/detail/statement' +export { default as DetailImageField } from './components/detail/image' export { default as DetailTextField } from './components/detail/text' export { default as DetailImportSubformField } from './components/detail/importSubform' -- Gitee From 72d8b98f62fc2c600298f9163461064ff217d735 Mon Sep 17 00:00:00 2001 From: wangailin Date: Mon, 14 Mar 2022 15:27:14 +0800 Subject: [PATCH 082/164] =?UTF-8?q?fixed:=20=E5=AD=90=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E9=A1=B5=E9=9D=A2=E6=97=B6=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 44071b1..044dc70 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -750,6 +750,9 @@ export default class TableStep extends Step { const { operation } = this.state operation.enable = false operation.visible = false + if ((operationCallback && operationCallback === true) || Boolean(operationCallback)) { + onUnmount(true) + } this.setState({ operation }) } }) -- Gitee From 45043c11f6e97b60309d957afda7cc7fc19b6663 Mon Sep 17 00:00:00 2001 From: wangailin Date: Tue, 15 Mar 2022 15:26:19 +0800 Subject: [PATCH 083/164] =?UTF-8?q?feat:=20=E5=85=B3=E9=97=AD=E5=92=8C?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=97=B6=E5=8D=95=E7=8B=AC=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E8=BF=94=E5=9B=9E=EF=BC=9B=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=85=B3=E9=97=AD=E5=BC=B9=E7=AA=97=E6=97=B6?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 044dc70..f84fa03 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -517,7 +517,8 @@ export default class TableStep extends Step { visible: operationVisible, config: operationConfig, data: operationData, - callback: operationCallback + callback: operationCallback, + cancelCallback: cancelCallback }, pageAuth } = this.state @@ -750,7 +751,7 @@ export default class TableStep extends Step { const { operation } = this.state operation.enable = false operation.visible = false - if ((operationCallback && operationCallback === true) || Boolean(operationCallback)) { + if ((cancelCallback && cancelCallback === true) || Boolean(cancelCallback)) { onUnmount(true) } this.setState({ operation }) -- Gitee From d325ffb6f6d31124a50b7428f8b8dc4be2b500c4 Mon Sep 17 00:00:00 2001 From: wangailin Date: Tue, 15 Mar 2022 15:28:45 +0800 Subject: [PATCH 084/164] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=92=8C=E5=8F=96=E6=B6=88=E6=97=B6=E7=9A=84=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index f84fa03..3a06aa1 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -68,6 +68,7 @@ export interface TableCCMSOperationConfig { data: { [key: string]: ParamConfig } params?: { field: string, data: ParamConfig }[] callback?: boolean + cancelCallback?: boolean debug?: boolean } @@ -222,6 +223,8 @@ interface TableState { config: CCMSConfig data: any callback?: boolean + cancelCallback?: boolean + } pageAuth: { [page: string]: boolean } } @@ -241,7 +244,7 @@ export default class TableStep extends Step { /* 服务端分页情况下页码溢出标识:页码溢出时退回重新请求,此标识符用于防止死循环判断 */ pageOverflow: boolean = false - constructor(props: StepProps) { + constructor (props: StepProps) { super(props) this.state = { @@ -253,7 +256,8 @@ export default class TableStep extends Step { visible: false, config: {}, data: {}, - callback: false + callback: false, + cancelCallback: false }, pageAuth: {} } @@ -492,7 +496,7 @@ export default class TableStep extends Step { document.body.appendChild(mask) } - render() { + render () { const { config: { field, @@ -518,7 +522,7 @@ export default class TableStep extends Step { config: operationConfig, data: operationData, callback: operationCallback, - cancelCallback: cancelCallback + cancelCallback: operationCancelCallback }, pageAuth } = this.state @@ -751,7 +755,7 @@ export default class TableStep extends Step { const { operation } = this.state operation.enable = false operation.visible = false - if ((cancelCallback && cancelCallback === true) || Boolean(cancelCallback)) { + if ((operationCancelCallback && operationCancelCallback === true) || Boolean(operationCancelCallback)) { onUnmount(true) } this.setState({ operation }) -- Gitee From 3bd87e7a4ab4f8b82c2eefb1f3ce76a43bb48889 Mon Sep 17 00:00:00 2001 From: wangailin Date: Tue, 15 Mar 2022 15:56:28 +0800 Subject: [PATCH 085/164] =?UTF-8?q?feat:=20=E4=BF=9D=E5=AD=98=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/steps/table/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 3a06aa1..27c7a55 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -336,7 +336,8 @@ export default class TableStep extends Step { visible: true, config: operationConfig, data: params, - callback: operation.handle.callback + callback: operation.handle.callback, + cancelCallback: operation.handle.cancelCallback } }) } else if (operation.handle.target === 'page') { -- Gitee From 35227bf0588ec0939f1e017c4b968332063aec32 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 15 Mar 2022 17:31:24 +0800 Subject: [PATCH 086/164] =?UTF-8?q?fix:=20Display=E4=BC=A0=E5=85=A5this?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/common.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 2b8cf78..2141c97 100644 --- a/src/components/formFields/select/common.tsx +++ b/src/components/formFields/select/common.tsx @@ -66,7 +66,7 @@ export class SelectDisplay extends Display { if (config) { - EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain }, this)).then((options) => { + EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { if (JSON.stringify(this.state.options) !== JSON.stringify(options)) { this.setState({ options -- Gitee From 2def59c63be98be109bc09866bc609289ddea37b Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 17 Mar 2022 17:56:38 +0800 Subject: [PATCH 087/164] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 27c7a55..4b17cbe 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -68,7 +68,7 @@ export interface TableCCMSOperationConfig { data: { [key: string]: ParamConfig } params?: { field: string, data: ParamConfig }[] callback?: boolean - cancelCallback?: boolean + closeCallback?: boolean debug?: boolean } @@ -223,7 +223,7 @@ interface TableState { config: CCMSConfig data: any callback?: boolean - cancelCallback?: boolean + closeCallback?: boolean } pageAuth: { [page: string]: boolean } @@ -257,7 +257,7 @@ export default class TableStep extends Step { config: {}, data: {}, callback: false, - cancelCallback: false + closeCallback: false }, pageAuth: {} } @@ -337,7 +337,7 @@ export default class TableStep extends Step { config: operationConfig, data: params, callback: operation.handle.callback, - cancelCallback: operation.handle.cancelCallback + closeCallback: operation.handle.closeCallback } }) } else if (operation.handle.target === 'page') { @@ -523,7 +523,7 @@ export default class TableStep extends Step { config: operationConfig, data: operationData, callback: operationCallback, - cancelCallback: operationCancelCallback + closeCallback: operationcloseCallback }, pageAuth } = this.state @@ -756,7 +756,7 @@ export default class TableStep extends Step { const { operation } = this.state operation.enable = false operation.visible = false - if ((operationCancelCallback && operationCancelCallback === true) || Boolean(operationCancelCallback)) { + if ((operationcloseCallback && operationcloseCallback === true) || Boolean(operationcloseCallback)) { onUnmount(true) } this.setState({ operation }) -- Gitee From 8faf8396049fbc8ae0fe32666070a2d45e018118 Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Thu, 17 Mar 2022 18:22:33 +0800 Subject: [PATCH 088/164] =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/detailInfo/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/detail/detailInfo/index.tsx b/src/components/detail/detailInfo/index.tsx index 912c664..939662f 100644 --- a/src/components/detail/detailInfo/index.tsx +++ b/src/components/detail/detailInfo/index.tsx @@ -75,7 +75,7 @@ export default class InfoDetail extends DetailField {this.renderComponent(props)} -- Gitee From c7a2db3e29e3db86541063d60d98cd1760e896f4 Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Fri, 18 Mar 2022 14:53:33 +0800 Subject: [PATCH 089/164] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/detailColor/index.tsx | 1 - src/components/detail/index.tsx | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/detail/detailColor/index.tsx b/src/components/detail/detailColor/index.tsx index 5d2173d..d498ce1 100644 --- a/src/components/detail/detailColor/index.tsx +++ b/src/components/detail/detailColor/index.tsx @@ -32,7 +32,6 @@ export default class InfoDetail extends DetailField { const value = this.getValue() - console.log(value, 'color value ') return ( diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index 2c2fffb..d67c1e3 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -17,7 +17,8 @@ export type DetailFieldConfigs = StatementDetailConfig | GroupFieldConfig | ImportSubformFieldConfig | - InfoDetailConfig + InfoDetailConfig | + ColorDetailConfig export type componentType = -- Gitee From e3147b46e3671524227faa295b125c167189af68 Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 18 Mar 2022 16:34:22 +0800 Subject: [PATCH 090/164] =?UTF-8?q?feat:=20=E8=A1=A8=E6=A0=BC=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=A0=8F=E5=86=85=E5=85=BC=E5=AE=B9=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E4=B8=8B=E6=8B=89=E4=B8=BAgroup=E9=A1=B9=EF=BC=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=94=B9=E4=B8=BAdropdown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 67b8df0..001f657 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -741,34 +741,7 @@ export default class TableStep extends Step { })} ) - } else if (operation.type === 'group') { - return ( - - {this.renderRowOperationGroupComponent({ - label: operation.label, - children: (operation.operations || []).map((operation) => { - if (!ConditionHelper(operation.condition, { record, data, step })) { - return null - } - - let hidden = false - if (operation.handle && operation.handle.type === 'ccms') { - hidden = operation.handle.page === undefined || !pageAuth[operation.handle.page.toString()] - operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) - } - - return hidden - ? null - : this.renderRowOperationGroupItemComponent({ - label: operation.label, - level: operation.level || 'normal', - onClick: async () => { await this.handleRowOperation(operation, record) } - }) - }) - })} - - ) - } else if (operation.type === 'dropdown') { + } else if (operation.type === 'group' || operation.type === 'dropdown') { return ( {this.renderRowOperationDropdownComponent({ -- Gitee From 2f7198b0397645bdc511bba452b2404eb08439e5 Mon Sep 17 00:00:00 2001 From: wangailin Date: Mon, 28 Mar 2022 14:48:16 +0800 Subject: [PATCH 091/164] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 001f657..9846349 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -73,7 +73,6 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig - align: 'left' | 'right' } export interface TableCCMSOperationConfig { -- Gitee From adc4b8e2ea9f334fc1998c42568367497b1599a7 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 31 Mar 2022 23:00:12 +0800 Subject: [PATCH 092/164] =?UTF-8?q?feat:=20=E5=A2=9EloadPageList=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.tsx | 4 ++++ src/steps/common.tsx | 2 ++ src/steps/form/index.tsx | 1 + src/steps/header/index.tsx | 2 ++ src/steps/table/index.tsx | 2 ++ src/util/operation.tsx | 5 +++++ 6 files changed, 16 insertions(+) diff --git a/src/main.tsx b/src/main.tsx index d580507..c8d852f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -3,6 +3,7 @@ import marked from 'marked' import Step, { StepProps } from './steps/common' import StepComponents, { StepConfigs } from './steps' import { RichStringConfig } from './interface' +import { ISelectFieldOption } from './components/formFields/treeSelect' /** * 页面配置文件格式定义 @@ -46,6 +47,7 @@ export interface CCMSProps { loadPageURL: (pageID: any) => Promise loadPageFrameURL: (pageID: any) => Promise loadPageConfig: (pageID: any) => Promise + loadPageList: () => Promise> loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string) => void callback: (success: boolean) => void @@ -233,6 +235,7 @@ export default class CCMS extends React.Component { loadPageURL, loadPageFrameURL, loadPageConfig, + loadPageList, loadDomain, handlePageRedirect } = this.props @@ -275,6 +278,7 @@ export default class CCMS extends React.Component { loadPageURL, loadPageFrameURL, loadPageConfig, + loadPageList, loadDomain, handlePageRedirect } diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 88da0fd..1641d1a 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -1,5 +1,6 @@ import React from 'react' import { CCMSConfig } from '../main' +import { ISelectFieldOption } from '../components/formFields/treeSelect' /** * 页面流转步骤基类配置定义 @@ -30,6 +31,7 @@ export interface StepProps { loadPageURL: (pageID: any) => Promise loadPageFrameURL: (pageID: any) => Promise loadPageConfig: (pageID: any) => Promise + loadPageList: () => Promise> baseRoute: string loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string) => void diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 27debc8..ae0b0be 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -630,6 +630,7 @@ export default class FormStep extends Step { loadPageURL={this.props.loadPageURL} loadPageFrameURL={this.props.loadPageFrameURL} loadPageConfig={this.props.loadPageConfig} + loadPageList={this.props.loadPageList} baseRoute={this.props.baseRoute} loadDomain={this.props.loadDomain} handlePageRedirect={this.props.handlePageRedirect} diff --git a/src/steps/header/index.tsx b/src/steps/header/index.tsx index a7ec2d7..cbbfe82 100644 --- a/src/steps/header/index.tsx +++ b/src/steps/header/index.tsx @@ -235,6 +235,7 @@ export default class HeaderStep extends Step { loadPageURL={this.props.loadPageURL} loadPageFrameURL={this.props.loadPageFrameURL} loadPageConfig={this.props.loadPageConfig} + loadPageList={this.props.loadPageList} loadDomain={this.props.loadDomain} handlePageRedirect={this.props.handlePageRedirect} /> @@ -303,6 +304,7 @@ export default class HeaderStep extends Step { loadPageURL={this.props.loadPageURL} loadPageFrameURL={this.props.loadPageFrameURL} loadPageConfig={this.props.loadPageConfig} + loadPageList={this.props.loadPageList} baseRoute={this.props.baseRoute} loadDomain={this.props.loadDomain} handlePageRedirect={this.props.handlePageRedirect} diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 8a751a0..765f26e 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -861,6 +861,7 @@ export default class TableStep extends Step { loadPageURL={this.props.loadPageURL} loadPageFrameURL={this.props.loadPageFrameURL} loadPageConfig={this.props.loadPageConfig} + loadPageList={this.props.loadPageList} loadDomain={this.props.loadDomain} handlePageRedirect={this.props.handlePageRedirect} onMount={() => { @@ -900,6 +901,7 @@ export default class TableStep extends Step { loadPageURL={this.props.loadPageURL} loadPageFrameURL={this.props.loadPageFrameURL} loadPageConfig={this.props.loadPageConfig} + loadPageList={this.props.loadPageList} loadDomain={this.props.loadDomain} handlePageRedirect={this.props.handlePageRedirect} onMount={() => { diff --git a/src/util/operation.tsx b/src/util/operation.tsx index 3f9f3b9..893f948 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -4,6 +4,7 @@ import { set } from "lodash"; import { ParamConfig } from "../interface"; import { CCMSConfig, CCMSProps } from "../main"; import { getParam } from "./value"; +import { ISelectFieldOption } from '../components/formFields/treeSelect' export type OperationConfig = CCMSOperationConfig @@ -56,6 +57,7 @@ interface OperationHelperProps { loadPageURL: (pageID: any) => Promise, loadPageFrameURL: (pageID: any) => Promise, loadPageConfig: (pageID: any) => Promise, + loadPageList: () => Promise>, baseRoute: string, loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string) => void @@ -96,6 +98,7 @@ export default class OperationHelper extends React.Component { @@ -152,6 +155,7 @@ export default class OperationHelper extends React.Component { @@ -180,6 +184,7 @@ export default class OperationHelper extends React.Component { -- Gitee From e5e19e88722a70e533ec67c19468172cca749fed Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Fri, 1 Apr 2022 11:32:25 +0800 Subject: [PATCH 093/164] =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 8a751a0..0d3a11f 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -81,6 +81,7 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig + modalWidth?: string } export interface TableCCMSOperationConfig { @@ -243,6 +244,7 @@ export interface ITableStepOperationModal { width: string children: React.ReactNode onClose: () => void + modalWidth?: string } interface TableState { @@ -252,6 +254,7 @@ interface TableState { width: string title: string visible: boolean + modalWidth?: string config: CCMSConfig data: any callback?: boolean @@ -289,6 +292,7 @@ export default class TableStep extends Step { config: {}, data: {}, callback: false, + modalWidth: '40', closeCallback: false }, pageAuth: {} @@ -366,6 +370,7 @@ export default class TableStep extends Step { width: operation.handle.width, title: operation.label, visible: true, + modalWidth: operation.modalWidth, config: operationConfig, data: params, callback: operation.handle.callback, @@ -655,7 +660,8 @@ export default class TableStep extends Step { config: operationConfig, data: operationData, callback: operationCallback, - closeCallback: operationcloseCallback + closeCallback: operationcloseCallback, + modalWidth: operationModalWidth, }, pageAuth } = this.state @@ -852,6 +858,7 @@ export default class TableStep extends Step { title: operationTitle, width: operationWidth, visible: operationVisible, + modalWidth: operationModalWidth, children: ( Date: Fri, 1 Apr 2022 14:37:08 +0800 Subject: [PATCH 094/164] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=AF=94=E4=BE=8B=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 0d3a11f..be4691f 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -81,7 +81,7 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig - modalWidth?: string + modalWidthRatio?: string } export interface TableCCMSOperationConfig { @@ -244,7 +244,7 @@ export interface ITableStepOperationModal { width: string children: React.ReactNode onClose: () => void - modalWidth?: string + modalWidthRatio?: string } interface TableState { @@ -254,7 +254,7 @@ interface TableState { width: string title: string visible: boolean - modalWidth?: string + modalWidthRatio?: string config: CCMSConfig data: any callback?: boolean @@ -292,7 +292,7 @@ export default class TableStep extends Step { config: {}, data: {}, callback: false, - modalWidth: '40', + modalWidthRatio: '40', closeCallback: false }, pageAuth: {} @@ -370,7 +370,7 @@ export default class TableStep extends Step { width: operation.handle.width, title: operation.label, visible: true, - modalWidth: operation.modalWidth, + modalWidthRatio: operation.modalWidthRatio, config: operationConfig, data: params, callback: operation.handle.callback, @@ -661,7 +661,7 @@ export default class TableStep extends Step { data: operationData, callback: operationCallback, closeCallback: operationcloseCallback, - modalWidth: operationModalWidth, + modalWidthRatio: operationModalWidthRatio, }, pageAuth } = this.state @@ -858,7 +858,7 @@ export default class TableStep extends Step { title: operationTitle, width: operationWidth, visible: operationVisible, - modalWidth: operationModalWidth, + modalWidthRatio: operationModalWidthRatio, children: ( Date: Fri, 1 Apr 2022 14:54:47 +0800 Subject: [PATCH 095/164] =?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index be4691f..57727d9 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -82,6 +82,7 @@ export interface TableOperationConfig { handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig modalWidthRatio?: string + modalWidth?: number } export interface TableCCMSOperationConfig { @@ -245,6 +246,7 @@ export interface ITableStepOperationModal { children: React.ReactNode onClose: () => void modalWidthRatio?: string + modalWidth?: number } interface TableState { @@ -255,6 +257,7 @@ interface TableState { title: string visible: boolean modalWidthRatio?: string + modalWidth?: number config: CCMSConfig data: any callback?: boolean @@ -293,6 +296,7 @@ export default class TableStep extends Step { data: {}, callback: false, modalWidthRatio: '40', + modalWidth: 400, closeCallback: false }, pageAuth: {} @@ -371,6 +375,7 @@ export default class TableStep extends Step { title: operation.label, visible: true, modalWidthRatio: operation.modalWidthRatio, + modalWidth: operation.modalWidth, config: operationConfig, data: params, callback: operation.handle.callback, @@ -662,6 +667,7 @@ export default class TableStep extends Step { callback: operationCallback, closeCallback: operationcloseCallback, modalWidthRatio: operationModalWidthRatio, + modalWidth: operationModalWidth, }, pageAuth } = this.state @@ -859,6 +865,7 @@ export default class TableStep extends Step { width: operationWidth, visible: operationVisible, modalWidthRatio: operationModalWidthRatio, + modalWidth: operationModalWidth, children: ( Date: Wed, 23 Feb 2022 16:09:44 +0800 Subject: [PATCH 096/164] =?UTF-8?q?feat:=20=E9=85=8D=E5=90=88upload?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=8D=E6=8B=BC=E5=90=88=E8=B7=AF=E5=BE=84?= =?UTF-8?q?noPathCombination=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 8 +- src/components/detail/enum/index.tsx | 3 +- src/components/detail/group/index.tsx | 99 ++++------------- src/components/detail/importSubform/index.tsx | 34 +++--- src/components/formFields/common.tsx | 20 ++-- src/components/formFields/form/index.tsx | 30 +++--- src/components/formFields/group/index.tsx | 30 +++--- .../formFields/importSubform/index.tsx | 30 +++--- src/components/formFields/object/index.tsx | 30 +++--- src/components/formFields/tabs/index.tsx | 30 +++--- src/components/formFields/upload/index.tsx | 8 +- src/steps/detail/index.tsx | 100 +++--------------- src/steps/filter/index.tsx | 31 +++--- src/steps/form/index.tsx | 30 +++--- 14 files changed, 179 insertions(+), 304 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 57902c1..9afe693 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -79,13 +79,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?: true }) => Promise // // 事件:置空值 - onValueUnset: (path: string, validation: true | DetailFieldError[]) => Promise + onValueUnset: (path: string, options?: { noPathCombination?: true }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | DetailFieldError[]) => Promise + onValueListAppend: (path: string, value: any, options?: { noPathCombination?: true }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | DetailFieldError[]) => Promise + onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: true }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/detail/enum/index.tsx b/src/components/detail/enum/index.tsx index c79b2cf..d30c108 100644 --- a/src/components/detail/enum/index.tsx +++ b/src/components/detail/enum/index.tsx @@ -1,6 +1,5 @@ -import { config } from 'process' import React from 'react' -import { DetailField, DetailFieldConfig, DetailFieldError, DetailFieldProps, IDetailField } from '../common' +import { DetailField, DetailFieldConfig, IDetailField } from '../common' export interface EnumDetailConfig extends DetailFieldConfig { type: 'detail_enum' diff --git a/src/components/detail/group/index.tsx b/src/components/detail/group/index.tsx index 1dd5220..07c8b7e 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' @@ -19,7 +19,6 @@ export interface IGroupField { } interface IGroupFieldState { - detailData: { status: 'normal' | 'error' | 'loading', message?: string }[] } export default class GroupField extends DetailField implements IDetailField { @@ -32,9 +31,7 @@ export default class GroupField extends DetailField) { super(props) - this.state = { - detailData: [] - } + this.state = {} } get = async () => { @@ -67,22 +64,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() } } @@ -117,79 +98,35 @@ export default class GroupField extends DetailField { + handleValueSet = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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) } } @@ -275,10 +212,10 @@ export default class GroupField extends DetailField { await this.handleChange(detailFieldIndex, value) }} - onValueSet={async (path, value, validation) => this.handleValueSet(detailFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => this.handleValueUnset(detailFieldIndex, path, validation)} - onValueListAppend={async (path, value, validation) => this.handleValueListAppend(detailFieldIndex, path, value, validation)} - onValueListSplice={async (path, index, count, validation) => this.handleValueListSplice(detailFieldIndex, path, index, count, validation)} + onValueSet={async (path, value, options) => this.handleValueSet(detailFieldIndex, path, value, options)} + onValueUnset={async (path, options) => this.handleValueUnset(detailFieldIndex, path, options)} + onValueListAppend={async (path, value, options) => this.handleValueListAppend(detailFieldIndex, path, value, options)} + onValueListSplice={async (path, index, count, options) => this.handleValueListSplice(detailFieldIndex, path, index, count, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 9828bbc..33383b1 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -97,42 +97,42 @@ export default class ImportSubformField extends DetailField { + handleValueSet = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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) } } @@ -239,10 +239,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/common.tsx b/src/components/formFields/common.tsx index 9539759..412bb04 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?: true }) => Promise // 事件:置空值 - onValueUnset: (path: string, validation: true | FieldError[]) => Promise + onValueUnset: (path: string, validation: true | FieldError[], options?: { noPathCombination?: true }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | FieldError[]) => Promise + onValueListAppend: (path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[]) => Promise + onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: true }) => 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?: true }) => 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?: true }) => Promise // 事件:置空值 - onValueUnset: (path: string, validation: true | FieldError[]) => Promise + onValueUnset: (path: string, options?: { noPathCombination?: true }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | FieldError[]) => Promise + onValueListAppend: (path: string, value: any, options?: { noPathCombination?: true }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[]) => Promise + onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: true }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d95ddea..558b6b0 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -322,10 +322,10 @@ export default class FormField extends Field { + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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 22347f7..5548b9b 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -182,10 +182,10 @@ export default class GroupField extends Field { + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +200,10 @@ export default class GroupField extends Field { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +218,10 @@ export default class GroupField extends Field { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +236,10 @@ export default class GroupField extends Field { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +254,10 @@ export default class GroupField extends Field { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +367,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 5735eb9..5210cca 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -214,10 +214,10 @@ export default class ImportSubformField extends Field { + handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +233,10 @@ export default class ImportSubformField extends Field { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +252,10 @@ export default class ImportSubformField extends Field { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +271,10 @@ export default class ImportSubformField extends Field { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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 +290,10 @@ export default class ImportSubformField extends Field { + handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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) @@ -434,11 +434,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/object/index.tsx b/src/components/formFields/object/index.tsx index b0de063..12bb936 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -259,10 +259,10 @@ export default class ObjectField extends Field { + handleValueSet = async (key: string, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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 a32b115..b68ac0c 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -202,13 +202,13 @@ export default class TabsField 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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 5b8fc83..295ec68 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 { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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) { @@ -459,10 +393,10 @@ export default class DetailStep extends Step { step={step} config={detailFieldConfig} 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 3f1bd37..4169148 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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?: true }) => { 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 5be24f0..9c32198 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -390,10 +390,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?: true }) => { 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({ @@ -417,10 +417,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?: true }) => { 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({ @@ -442,10 +442,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?: true }) => { 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 = [] @@ -470,10 +470,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?: true }) => { 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) @@ -497,10 +497,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?: true }) => { 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) @@ -725,11 +725,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)} /> -- Gitee From 30837ea8e87d256ffcf5c7735606d927a09d444c Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 24 Feb 2022 12:57:11 +0800 Subject: [PATCH 097/164] =?UTF-8?q?feat:=20=E5=8A=A8=E6=80=81=E5=AD=90?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=94=AF=E6=8C=81=E4=B8=A4=E7=A7=8D=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 9 ++- .../formFields/importSubform/index.tsx | 80 ++++++++++++++----- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 33383b1..6455f04 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', diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 5210cca..0883417 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[] @@ -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 ( -- Gitee From 1a9e6a1b673f9f7bd8d43069edf73abb1d336d63 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 28 Feb 2022 18:30:14 +0800 Subject: [PATCH 098/164] =?UTF-8?q?feat:=20code=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 2 +- src/components/formFields/code/index.tsx | 88 +++++++++++++++++++ src/components/formFields/index.tsx | 10 ++- src/index.tsx | 1 + 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/components/formFields/code/index.tsx diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 6455f04..5021932 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -45,7 +45,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] diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx new file mode 100644 index 0000000..545c506 --- /dev/null +++ b/src/components/formFields/code/index.tsx @@ -0,0 +1,88 @@ +import React 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: 'light' | 'vs-dark' + fullScreen: boolean +} + +export interface ICodeField { + codeType: 'xml' | 'json' | 'javascript' | 'java' + height: number + theme: 'light' | 'vs-dark' + value: string + fullScreen: boolean + onChange: (value: string) => Promise +} + +export default class CodeField extends Field implements IField { + 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 + } + + renderComponent = (props: ICodeField) => { + return + 您当前使用的UI版本没有实现CodeField组件。 +
+ +
+
+ } + + render = () => { + const { + value, + config: { + theme, + fullScreen, + height, + codeType + } + } = this.props + + return ( + + { this.renderComponent({ + codeType, + value, + theme, + fullScreen, + height, + onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) + })} + + ) + } +} diff --git a/src/components/formFields/index.tsx b/src/components/formFields/index.tsx index e7735a6..4419556 100644 --- a/src/components/formFields/index.tsx +++ b/src/components/formFields/index.tsx @@ -23,6 +23,7 @@ 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 TextDisplay from './text/display' import RadioDisplay from './radio/display' @@ -67,7 +68,8 @@ export type FieldConfigs = ObjectFieldConfig | TabsFieldConfig | MultipleTextFieldConfig | - CustomFieldConfig + CustomFieldConfig | + CodeFieldConfig export type componentType = 'text' | @@ -93,7 +95,8 @@ export type componentType = 'object' | 'tabs' | 'multiple_text'| - 'custom' + 'custom' | + 'code' export default { text: TextField, @@ -118,7 +121,8 @@ export default { hidden: HiddenField, tabs: TabsField, multiple_text: MultipleTextField, - custom: CustomField + custom: CustomField, + code: CodeField } export const display = { diff --git a/src/index.tsx b/src/index.tsx index b193a05..47f4345 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -26,6 +26,7 @@ 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 TextDisplay } from './components/formFields/text/display' export { default as LongTextDisplay } from './components/formFields/longtext/display' -- Gitee From e7d5f5a7ddeee65e0fdb8ba4e4604f1ea0132c3f Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 1 Mar 2022 18:31:34 +0800 Subject: [PATCH 099/164] =?UTF-8?q?refactor:=20code=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E4=BA=A4=E4=BA=92=E9=80=BB=E8=BE=91=E6=94=BE=E5=88=B0?= =?UTF-8?q?renderContainer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/code/index.tsx | 86 +++++++++++++++++++++--- 1 file changed, 75 insertions(+), 11 deletions(-) diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx index 545c506..dfac081 100644 --- a/src/components/formFields/code/index.tsx +++ b/src/components/formFields/code/index.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { KeyboardEvent } from 'react' import { Field, FieldConfig, FieldError, IField } from '../common' import { getBoolean } from '../../../util/value' @@ -7,26 +7,51 @@ import { getBoolean } from '../../../util/value' * - codeType: 语言类型 * - height: 代码编辑器高度 * - theme: 编辑器主题风格 - * - fullScreen: 是否全屏 + * - fullScreen: 是否支持全屏 */ export interface CodeFieldConfig extends FieldConfig { type: 'code' codeType: 'xml' | 'json' | 'javascript' | 'java' height: number - theme: 'light' | 'vs-dark' + theme: 'white' | 'black' fullScreen: boolean } export interface ICodeField { codeType: 'xml' | 'json' | 'javascript' | 'java' + fullScreenStatus: boolean height: number - theme: 'light' | 'vs-dark' + theme: 'white' | 'black' value: string - fullScreen: boolean 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: (value: string) => Promise + exitFull: (value: string) => Promise +} +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 @@ -52,6 +77,35 @@ export default class CodeField extends Field { + 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: any) => { + return + 您当前使用的UI版本没有实现CodeField的container组件。 +
+ +
+
+ } + renderComponent = (props: ICodeField) => { return 您当前使用的UI版本没有实现CodeField组件。 @@ -71,16 +125,26 @@ export default class CodeField extends Field - { this.renderComponent({ - codeType, - value, - theme, + {this.renderContainer({ + fullScreenStatus, fullScreen, - height, - onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) + 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)) + }) })} ) -- Gitee From ef7adf00563d23c4ce70d4662c731cb0dc5d1c28 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 2 Mar 2022 10:37:37 +0800 Subject: [PATCH 100/164] =?UTF-8?q?fix:=20code=E7=BC=96=E8=BE=91=E5=99=A8e?= =?UTF-8?q?nterFull=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/code/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx index dfac081..731af17 100644 --- a/src/components/formFields/code/index.tsx +++ b/src/components/formFields/code/index.tsx @@ -41,8 +41,8 @@ export interface ICodeFieldContainer { children: React.ReactNode onResetValue: (value: string) => Promise keydownCallback: (value: KeyboardEvent) => Promise - enterFull: (value: string) => Promise - exitFull: (value: string) => Promise + enterFull: () => void + exitFull: () => void } interface State { fullScreenStatus: boolean // 编辑器是不是处于全屏状态 -- Gitee From 839339fa1065198e57106d4f9d1981127a5203d7 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 2 Mar 2022 22:39:05 +0800 Subject: [PATCH 101/164] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E9=A1=B9=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tableColumns/common.tsx | 4 ++ src/components/tableColumns/custom/index.tsx | 76 ++++++++++++++++++++ src/components/tableColumns/index.tsx | 6 +- src/index.tsx | 1 + src/steps/table/index.tsx | 7 +- 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/components/tableColumns/custom/index.tsx diff --git a/src/components/tableColumns/common.tsx b/src/components/tableColumns/common.tsx index a613f19..3c09f86 100644 --- a/src/components/tableColumns/common.tsx +++ b/src/components/tableColumns/common.tsx @@ -30,6 +30,10 @@ export interface ColumnProps { data: any[], step: number, config: T + // 挂载引用 + column?: React.ReactNode + baseRoute: string + loadDomain: (domain: string) => Promise } interface ColumnState { diff --git a/src/components/tableColumns/custom/index.tsx b/src/components/tableColumns/custom/index.tsx new file mode 100644 index 0000000..15f1d54 --- /dev/null +++ b/src/components/tableColumns/custom/index.tsx @@ -0,0 +1,76 @@ +import React, { RefObject } from 'react' +import Column, { ColumnConfig, ColumnProps, IColumn } from '../common' +import { loadMicroApp, MicroApp } from 'qiankun' +import moment from 'moment' +import { cloneDeep } from 'lodash' + +export interface CustomColumnConfig extends ColumnConfig { + type: 'custom' + entry: string +} + +export default class CustomColumn extends Column 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, + column: this.props.column, + 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, + column: this.props.column, + 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 aa8159b..ff52f94 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 47f4345..1d220f3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -51,6 +51,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/table/index.tsx b/src/steps/table/index.tsx index ac82304..2f8c8a3 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' @@ -227,7 +228,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() /** * 页面权限获取状态 @@ -568,11 +569,15 @@ export default class TableStep extends Step { const addfix = ['multirowText'].some((val) => val !== column.field) return {}} record={record} value={value} data={data} step={step} config={column} + column={this} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> } -- Gitee From 296f077fc62a14bfc2c4a8583fcc1eb25db53260 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 7 Mar 2022 16:11:50 +0800 Subject: [PATCH 102/164] =?UTF-8?q?feat:=20diffCode=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/code/index.tsx | 4 +- src/components/formFields/diffCode/index.tsx | 147 +++++++++++++++++++ src/components/formFields/index.tsx | 10 +- src/index.tsx | 1 + 4 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 src/components/formFields/diffCode/index.tsx diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx index 731af17..69aabb9 100644 --- a/src/components/formFields/code/index.tsx +++ b/src/components/formFields/code/index.tsx @@ -97,11 +97,11 @@ export default class CodeField extends Field { + renderContainer = (props: ICodeFieldContainer) => { return 您当前使用的UI版本没有实现CodeField的container组件。
- +
} diff --git a/src/components/formFields/diffCode/index.tsx b/src/components/formFields/diffCode/index.tsx new file mode 100644 index 0000000..3649f88 --- /dev/null +++ b/src/components/formFields/diffCode/index.tsx @@ -0,0 +1,147 @@ +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 () => { + if (this.props.config.disabled) return '' + 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/index.tsx b/src/components/formFields/index.tsx index 4419556..d7e9013 100644 --- a/src/components/formFields/index.tsx +++ b/src/components/formFields/index.tsx @@ -24,6 +24,7 @@ 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' @@ -69,7 +70,8 @@ export type FieldConfigs = TabsFieldConfig | MultipleTextFieldConfig | CustomFieldConfig | - CodeFieldConfig + CodeFieldConfig | + DiffCodeFieldConfig export type componentType = 'text' | @@ -96,7 +98,8 @@ export type componentType = 'tabs' | 'multiple_text'| 'custom' | - 'code' + 'code' | + 'diffcode' export default { text: TextField, @@ -122,7 +125,8 @@ export default { tabs: TabsField, multiple_text: MultipleTextField, custom: CustomField, - code: CodeField + code: CodeField, + diffcode: DiffCodeField } export const display = { diff --git a/src/index.tsx b/src/index.tsx index 1d220f3..78ca26a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -27,6 +27,7 @@ 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' -- Gitee From f7f00aeaf2d98e36a989bfabef8ad02dd0518174 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 7 Mar 2022 17:57:52 +0800 Subject: [PATCH 103/164] =?UTF-8?q?feat:=20=E8=A1=A8=E5=8D=95=E9=A1=B9?= =?UTF-8?q?=E9=85=8D=E7=BD=AEdisable=E4=B8=8D=E4=BC=9A=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E5=88=B0submitData?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/diffCode/index.tsx | 1 - src/components/formFields/form/index.tsx | 4 ++-- src/components/formFields/group/index.tsx | 5 +++-- src/components/formFields/importSubform/index.tsx | 4 ++-- src/components/formFields/tabs/index.tsx | 4 ++-- src/steps/form/index.tsx | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/formFields/diffCode/index.tsx b/src/components/formFields/diffCode/index.tsx index 3649f88..eea5d6f 100644 --- a/src/components/formFields/diffCode/index.tsx +++ b/src/components/formFields/diffCode/index.tsx @@ -59,7 +59,6 @@ export default class DiffCodeField extends Field Promise = async () => { - if (this.props.config.disabled) return '' return {} } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 558b6b0..f953e20 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 extends Field extends Field { 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) -- Gitee From b19be67318a3a2489124b71d29cc34ad6aeb3752 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Mar 2022 11:32:09 +0800 Subject: [PATCH 104/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9noPathCombinat?= =?UTF-8?q?ion=E7=9A=84=E7=B1=BB=E5=9E=8B=E4=B8=BAboolean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 8 ++++---- src/components/detail/group/index.tsx | 8 ++++---- src/components/detail/importSubform/index.tsx | 8 ++++---- src/components/formFields/common.tsx | 18 +++++++++--------- src/components/formFields/form/index.tsx | 10 +++++----- src/components/formFields/group/index.tsx | 10 +++++----- .../formFields/importSubform/index.tsx | 10 +++++----- src/components/formFields/object/index.tsx | 14 +++++++------- src/components/formFields/tabs/index.tsx | 10 +++++----- src/components/formFields/upload/index.tsx | 2 +- src/steps/detail/index.tsx | 8 ++++---- src/steps/filter/index.tsx | 10 +++++----- src/steps/form/index.tsx | 10 +++++----- 13 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 9afe693..3107ab8 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -79,13 +79,13 @@ export interface DetailFieldProps { // TODO 待删除 onChange: (value: T) => Promise // 事件:设置值 - onValueSet: (path: string, value: T, options?: { noPathCombination?: true }) => Promise + onValueSet: (path: string, value: T, options?: { noPathCombination?: boolean }) => Promise // // 事件:置空值 - onValueUnset: (path: string, options?: { noPathCombination?: true }) => Promise + onValueUnset: (path: string, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, options?: { noPathCombination?: true }) => Promise + onValueListAppend: (path: string, value: any, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: true }) => Promise + onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/detail/group/index.tsx b/src/components/detail/group/index.tsx index 07c8b7e..dbc057f 100644 --- a/src/components/detail/group/index.tsx +++ b/src/components/detail/group/index.tsx @@ -98,7 +98,7 @@ 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 = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) @@ -106,7 +106,7 @@ export default class GroupField extends DetailField { + handleValueUnset = async (detailFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) @@ -114,7 +114,7 @@ export default class GroupField extends DetailField { + handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) @@ -122,7 +122,7 @@ export default class GroupField extends DetailField { + handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 5021932..dcf1f45 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -105,7 +105,7 @@ export default class DetailImportSubformField extends DetailField { + handleValueSet = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -113,7 +113,7 @@ export default class DetailImportSubformField extends DetailField { + handleValueUnset = async (formFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -121,7 +121,7 @@ export default class DetailImportSubformField extends DetailField { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -129,7 +129,7 @@ export default class DetailImportSubformField extends DetailField { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 412bb04..cf36a02 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -84,15 +84,15 @@ export interface FieldProps { // TODO 待删除 onChange: (value: T) => Promise // 事件:设置值 noPathCombination:为true时不做路径拼接 - onValueSet: (path: string, value: T, validation: true | FieldError[], options?: { noPathCombination?: true }) => Promise + onValueSet: (path: string, value: T, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:置空值 - onValueUnset: (path: string, validation: true | FieldError[], options?: { noPathCombination?: true }) => Promise + onValueUnset: (path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => Promise + onValueListAppend: (path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: true }) => 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[], options?: { noPathCombination?: true }) => 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, options?: { noPathCombination?: true }) => Promise + onValueSet: (path: string, value: T, options?: { noPathCombination?: boolean }) => Promise // 事件:置空值 - onValueUnset: (path: string, options?: { noPathCombination?: true }) => Promise + onValueUnset: (path: string, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 追加 - onValueListAppend: (path: string, value: any, options?: { noPathCombination?: true }) => Promise + onValueListAppend: (path: string, value: any, options?: { noPathCombination?: boolean }) => Promise // 事件:修改值 - 列表 - 删除 - onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: true }) => Promise + onValueListSplice: (path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index f953e20..2c738f1 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -322,7 +322,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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -341,7 +341,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -360,7 +360,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -379,7 +379,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -398,7 +398,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index e6f992f..7bec8a1 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -183,7 +183,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -201,7 +201,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -219,7 +219,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -237,7 +237,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -255,7 +255,7 @@ 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 = options && options.noPathCombination ? path : (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 fda69c4..5863faf 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -229,7 +229,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 = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -248,7 +248,7 @@ 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 = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -267,7 +267,7 @@ 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 = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -286,7 +286,7 @@ 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 = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) @@ -305,7 +305,7 @@ 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 = options && options.noPathCombination ? path : this.getFullpath(formFieldConfig.field, path) diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index 12bb936..e3ddba5 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -278,7 +278,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -297,7 +297,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -316,7 +316,7 @@ 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -335,7 +335,7 @@ 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 = options && options.noPathCombination ? path : (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 aad3781..6525e9b 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -202,7 +202,7 @@ export default class TabsField extends Field { } - handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 || []) @@ -226,7 +226,7 @@ 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 || []) @@ -250,7 +250,7 @@ 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 || []) @@ -274,7 +274,7 @@ 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 || []) @@ -298,7 +298,7 @@ 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 || []) diff --git a/src/components/formFields/upload/index.tsx b/src/components/formFields/upload/index.tsx index 295ec68..0013ca1 100644 --- a/src/components/formFields/upload/index.tsx +++ b/src/components/formFields/upload/index.tsx @@ -165,7 +165,7 @@ export default class UploadField extends Field { } } - handleValueSet = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: true }) => { + handleValueSet = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) @@ -237,7 +237,7 @@ export default class DetailStep extends Step { } } - handleValueUnset = async (detailFieldIndex: number, path: string, options?: { noPathCombination?: true }) => { + handleValueUnset = async (detailFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) @@ -252,7 +252,7 @@ export default class DetailStep extends Step { } } - handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: true }) => { + handleValueListAppend = async (detailFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) @@ -269,7 +269,7 @@ export default class DetailStep extends Step { } } - handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: true }) => { + handleValueListSplice = async (detailFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const detailFieldConfig = (this.props.config.fields || [])[detailFieldIndex] if (detailFieldConfig) { const fullPath = options && options.noPathCombination ? path : (detailFieldConfig.field === '' || path === '' ? `${detailFieldConfig.field}${path}` : `${detailFieldConfig.field}.${path}`) diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 4169148..8d828f6 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -278,7 +278,7 @@ export default class FilterStep extends Step { } } - handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -303,7 +303,7 @@ export default class FilterStep extends Step { } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -328,7 +328,7 @@ export default class FilterStep extends Step { } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -355,7 +355,7 @@ export default class FilterStep extends Step { } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -382,7 +382,7 @@ export default class FilterStep extends Step { } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 3257f66..9a4e7e4 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -390,7 +390,7 @@ export default class FormStep extends Step { } } - handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -417,7 +417,7 @@ export default class FormStep extends Step { } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -442,7 +442,7 @@ export default class FormStep extends Step { } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -470,7 +470,7 @@ export default class FormStep extends Step { } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) @@ -497,7 +497,7 @@ export default class FormStep extends Step { } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: true }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) -- Gitee From 3cd98841809af6c9b9530a5792249f96bf5140f9 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 10 Mar 2022 18:05:52 +0800 Subject: [PATCH 105/164] =?UTF-8?q?fix:=20=E7=BC=96=E8=BE=91=E5=99=A8ESC?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E5=AF=BC=E8=87=B4antd=20modal?= =?UTF-8?q?=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/code/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx index 69aabb9..09d8f27 100644 --- a/src/components/formFields/code/index.tsx +++ b/src/components/formFields/code/index.tsx @@ -78,6 +78,7 @@ export default class CodeField extends Field { + e.stopPropagation() const keyCode = e.keyCode || e.which || e.charCode const ctrlKey = e.ctrlKey || e.metaKey if (this.props.config.fullScreen) { -- Gitee From 1181016a51e9b1060bff3f4c164ba7df54e2b9e7 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 13 Apr 2022 10:34:45 +0800 Subject: [PATCH 106/164] =?UTF-8?q?fix:=20await=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?react=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/single/index.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/formFields/select/single/index.tsx b/src/components/formFields/select/single/index.tsx index 3eada97..7299ab4 100644 --- a/src/components/formFields/select/single/index.tsx +++ b/src/components/formFields/select/single/index.tsx @@ -144,11 +144,9 @@ export default class SelectSingleField extends SelectField { - const value = props.options[defaultSelect === true ? 0 : defaultSelect].value - props.value = value - this.props.onValueSet('', value, await this.validate(value)) - })() + const value = props.options[defaultSelect === true ? 0 : defaultSelect].value + props.value = value + this.props.onValueSet('', value, true) } } -- Gitee From 86cb6baba2904cac2af24e48f2c3ec8595bdf360 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 13 Apr 2022 12:16:55 +0800 Subject: [PATCH 107/164] =?UTF-8?q?feat:=20=E6=96=87=E6=9C=AC=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=E6=94=AF=E6=8C=81=E9=A1=B5=E9=9D=A2=E4=BC=A0?= =?UTF-8?q?=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 10 ++++- src/components/detail/detailColor/index.tsx | 33 +++++++++++++--- src/components/detail/text/index.tsx | 42 +++++++++++++++++---- 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 57902c1..c095ba3 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -24,7 +24,7 @@ export interface DetailFieldConfig { columns?: ColumnsConfig childColumns?: ColumnsConfig display?: 'none' - defaultValue?: string, + defaultValue?: ParamConfig, condition?: DetailFieldConditionConfig layout?: 'horizontal' | 'vertical' styles?: object @@ -132,7 +132,13 @@ export class DetailField extends Reac config } = this.props - return config.defaultValue + if (typeof config.defaultValue === 'string') { + return config.defaultValue + } + if (config.defaultValue !== undefined) { + return ParamHelper(config.defaultValue, { record: this.props.record, data: this.props.data, step: this.props.step }) + } + return undefined } set: (value: T) => Promise = async (value) => { diff --git a/src/components/detail/detailColor/index.tsx b/src/components/detail/detailColor/index.tsx index d498ce1..f5b3c3e 100644 --- a/src/components/detail/detailColor/index.tsx +++ b/src/components/detail/detailColor/index.tsx @@ -10,13 +10,26 @@ export interface IColorProps { } export default class InfoDetail extends DetailField implements IDetailField { + reset: () => Promise = async () => { + const defaults = await this.defaultValue() + return (defaults === undefined) ? '' : defaults + } + + state = { + value: '' + } + renderComponent = (props: IColorProps) => { return 您当前使用的UI版本没有实现colorDetail组件。 } - getValue = () => { + componentDidMount() { + this.getValue() + } + + getValue = async () => { const { value, config: { @@ -24,14 +37,24 @@ export default class InfoDetail extends DetailField { - const value = this.getValue() + const { value } = this.state return ( diff --git a/src/components/detail/text/index.tsx b/src/components/detail/text/index.tsx index 6338ad6..d621a0a 100644 --- a/src/components/detail/text/index.tsx +++ b/src/components/detail/text/index.tsx @@ -1,6 +1,6 @@ import React from 'react' import { getBoolean } from '../../../util/value' -import { DetailField, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' +import { DetailField, DetailFieldProps, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' export interface TextFieldConfig extends DetailFieldConfig { type: 'text' @@ -11,6 +11,19 @@ export interface ITextField { } export default class TextField extends DetailField implements IDetailField { + reset: () => Promise = async () => { + const defaults = await this.defaultValue() + return (defaults === undefined) ? '' : defaults + } + + state = { + value: '' + } + + constructor(props: DetailFieldProps) { + super(props) + } + renderComponent = (props: ITextField) => { return 您当前使用的UI版本没有实现Text组件。 @@ -19,7 +32,11 @@ export default class TextField extends DetailField } - getValue = () => { + componentDidMount() { + this.getValue() + } + + getValue = async () => { const { value, config: { @@ -27,16 +44,25 @@ export default class TextField extends DetailField { - const value = this.getValue() - console.log(value, 'text value ') - + // console.log(value, 'text value ') + const { value } = this.state return ( {this.renderComponent({ -- Gitee From 81bfa51a199c399a5875667c5587721d0d020c74 Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 8 Apr 2022 17:11:07 +0800 Subject: [PATCH 108/164] =?UTF-8?q?feat:=20=E6=96=87=E6=9C=AC=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=95=B0=E7=BB=84=E5=92=8C=E6=95=B0=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/enum/index.tsx | 2 +- src/components/detail/text/index.tsx | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/detail/enum/index.tsx b/src/components/detail/enum/index.tsx index c79b2cf..658ff32 100644 --- a/src/components/detail/enum/index.tsx +++ b/src/components/detail/enum/index.tsx @@ -35,7 +35,7 @@ export interface IEnumProps { export default class EnumDetail extends DetailField implements IDetailField { reset: () => Promise = async () => { const defaults = await this.defaultValue() - return (defaults === undefined) ? '' : defaults + return (defaults === undefined) ? '/' : defaults } renderComponent = (props: IEnumProps) => { diff --git a/src/components/detail/text/index.tsx b/src/components/detail/text/index.tsx index d621a0a..6a424af 100644 --- a/src/components/detail/text/index.tsx +++ b/src/components/detail/text/index.tsx @@ -13,7 +13,7 @@ export interface ITextField { export default class TextField extends DetailField implements IDetailField { reset: () => Promise = async () => { const defaults = await this.defaultValue() - return (defaults === undefined) ? '' : defaults + return (defaults === undefined) ? '/' : defaults } state = { @@ -43,11 +43,20 @@ export default class TextField extends DetailField).join(',') + }) + } else { + return this.setState({ + value: '/' + }) + } } if (typeof defaultValue === 'string') { this.setState({ -- Gitee From 6a56a343bab500a5565faa3c4fc0b3b21b387343 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 13 Apr 2022 14:29:08 +0800 Subject: [PATCH 109/164] =?UTF-8?q?perf:=20=E5=8E=BB=E6=8E=89log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/text/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/detail/text/index.tsx b/src/components/detail/text/index.tsx index 6a424af..15192b8 100644 --- a/src/components/detail/text/index.tsx +++ b/src/components/detail/text/index.tsx @@ -70,7 +70,6 @@ export default class TextField extends DetailField { - // console.log(value, 'text value ') const { value } = this.state return ( -- Gitee From 98628032c4f370ab162fd2fce0027c1493943550 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 6 Apr 2022 16:27:55 +0800 Subject: [PATCH 110/164] =?UTF-8?q?feat:=20=E8=AF=A6=E6=83=85=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=E4=B8=8B=E5=8F=91?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/enum/index.tsx | 129 +++++++++++++++++++++++---- src/components/detail/text/index.tsx | 2 +- 2 files changed, 115 insertions(+), 16 deletions(-) diff --git a/src/components/detail/enum/index.tsx b/src/components/detail/enum/index.tsx index 658ff32..9ebfa19 100644 --- a/src/components/detail/enum/index.tsx +++ b/src/components/detail/enum/index.tsx @@ -1,11 +1,13 @@ import { config } from 'process' import React from 'react' -import { DetailField, DetailFieldConfig, DetailFieldError, DetailFieldProps, IDetailField } from '../common' +import { DetailField, DetailFieldProps, DetailFieldConfig, IDetailField } from '../common' +import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' +import { getValue } from '../../../util/value' export interface EnumDetailConfig extends DetailFieldConfig { type: 'detail_enum' multiple: boolean | ArrayMultipleConfig | SplitMultipleConfig - options: ManualOptionsConfig + options: ManualOptionsConfig | InterfaceOptionsConfig } interface ArrayMultipleConfig { @@ -28,24 +30,53 @@ interface ManualOptionsConfig { getValue?: string } +export interface InterfaceOptionsConfig { + from: 'interface' + interface?: InterfaceConfig + format?: InterfaceOptionsListConfig | InterfaceOptionKVConfig +} + +export interface InterfaceOptionKVConfig { + type: 'kv' +} +export interface InterfaceOptionsListConfig { + type: 'list' + keyField: string + labelField: string +} + + export interface IEnumProps { value?: string | string[] } export default class EnumDetail extends DetailField implements IDetailField { + interfaceHelper = new InterfaceHelper() + reset: () => Promise = async () => { const defaults = await this.defaultValue() return (defaults === undefined) ? '/' : defaults } + state = { + value: '' + } + + constructor(props: DetailFieldProps) { + super(props) + } + renderComponent = (props: IEnumProps) => { return 您当前使用的UI版本没有实现EnumDetail组件。 } - - getValue = () => { + componentDidMount() { + this.getValue() + } + + getValue = async () => { const { value, config: { @@ -55,7 +86,17 @@ export default class EnumDetail extends DetailField option.value === value) - return option ? option.label : value.toString() + this.setState({ + value: option ? option.label : value.toString() + }) } else if (multiple === true || multiple.type) { if (Array.isArray(theValue)) { - return theValue.map((item) => { - const option = options.data.find((option) => { - return option.value === Number(item) - }) - return option ? option.label : item.toString() - }).join(',') + this.setState({ + value: theValue.map((item) => { + const option = options.data.find((option) => { + return option.value === Number(item) + }) + return option ? option.label : item.toString() + }).join(',') + }) } else { - return '-' + this.setState({ + value: '-' + }) } } + } else { + this.setState({ + value: value + }) + } + } else if (options && options.from === 'interface') { + if (options.interface) { + this.interfaceHelper.request( + options.interface, + {}, + { record: this.props.record, data: this.props.data, step: this.props.step }, + { loadDomain: this.props.loadDomain } + ).then((data) => { + + if (options.format) { + type OptionItem = { value: string, label: string } + let tempOptions: Array = [] + if (options.format.type === 'kv') { + tempOptions = Object.keys(data).map((key) => ({ + value: key, + label: data[key] + })) + this.setState({ + value: theValue.map((item: OptionItem) => { + const option = tempOptions.find((option) => { + return option.value === String(item) + }) + return option ? option.label : item.toString() + }).join(',') + }) + } else if (options.format.type === 'list') { + tempOptions = data.map((item: any) => { + if (options.format && options.format.type === 'list') { + return ({ + value: getValue(item, options.format.keyField), + label: getValue(item, options.format.labelField) + }) + } + }) + this.setState({ + value: theValue.map((item: OptionItem) => { + const option = tempOptions.find((option) => { + return option.value === String(item) + }) + return option ? option.label : item.toString() + }).join(',') + }) + } + } + }) } else { return value } - } else { + } + else { return value } } render = () => { - const value = this.getValue() + // const value = this.getValue() + const { value } = this.state return ( {this.renderComponent({ diff --git a/src/components/detail/text/index.tsx b/src/components/detail/text/index.tsx index 15192b8..a3de7db 100644 --- a/src/components/detail/text/index.tsx +++ b/src/components/detail/text/index.tsx @@ -7,7 +7,7 @@ export interface TextFieldConfig extends DetailFieldConfig { } export interface ITextField { - value: string + value: string | Array } export default class TextField extends DetailField implements IDetailField { -- Gitee From 230c1807f3654b606e2ada9b3fff733130b75760 Mon Sep 17 00:00:00 2001 From: zjt Date: Tue, 15 Mar 2022 16:31:50 +0800 Subject: [PATCH 111/164] =?UTF-8?q?feat:=20=E8=AF=A6=E6=83=85=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 8 + src/components/detail/index.tsx | 37 +- .../detail/table/common/columnStyle.tsx | 20 + src/components/detail/table/index.tsx | 770 ++++++++++++++++++ src/index.tsx | 1 + src/steps/detail/index.tsx | 18 +- 6 files changed, 831 insertions(+), 23 deletions(-) create mode 100644 src/components/detail/table/common/columnStyle.tsx create mode 100644 src/components/detail/table/index.tsx diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index c095ba3..69560e3 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -3,6 +3,8 @@ import { ColumnsConfig, ParamConfig } from '../../interface' import { DetailFieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' +import { CCMSConfig } from '../../main' + /** * 详情页表单项基类配置文件格式定义 * - field: 表单项字段名 @@ -88,6 +90,12 @@ export interface DetailFieldProps { onValueListSplice: (path: string, index: number, count: number, validation: true | DetailFieldError[]) => Promise baseRoute: string, loadDomain: (domain: string) => Promise + loadPageConfig?: (pageID: any) => Promise + handlePageRedirect?: (path: string) => void + checkPageAuth?: (pageID: any) => Promise + onUnmount?: (reload?: boolean, data?: any) => Promise + loadPageURL?: (pageID: any) => Promise + loadPageFrameURL?: (pageID: any) => Promise } /** diff --git a/src/components/detail/index.tsx b/src/components/detail/index.tsx index d67c1e3..f590834 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -1,4 +1,3 @@ - import TextField, { TextFieldConfig } from './text' import EnumDetail, { EnumDetailConfig } from './enum' import StatementDetail, { StatementDetailConfig } from './statement' @@ -7,28 +6,31 @@ import GroupField, { GroupFieldConfig } from './group' import ImportSubformField, { ImportSubformFieldConfig } from './importSubform' import InfoDetail, { InfoDetailConfig } from './detailInfo' import ColorDetail, { ColorDetailConfig } from './detailColor' +import TableField, { TableFieldConfig } from './table' /** * 详情步骤内详情项配置文件格式定义 - 枚举 */ export type DetailFieldConfigs = - TextFieldConfig | - EnumDetailConfig | - StatementDetailConfig | - GroupFieldConfig | - ImportSubformFieldConfig | - InfoDetailConfig | - ColorDetailConfig - + TextFieldConfig | + EnumDetailConfig | + StatementDetailConfig | + GroupFieldConfig | + ImportSubformFieldConfig | + InfoDetailConfig | + ColorDetailConfig | + TableFieldConfig export type componentType = - 'text' | - 'group' | - 'detail_enum' | - 'statement' | - 'import_subform' | - 'detail_info' | - 'detail_color' + 'text' | + 'group' | + 'detail_enum' | + 'statement' | + 'import_subform' | + 'detail_info' | + 'detail_color' | + 'table' + export default { group: GroupField, @@ -37,5 +39,6 @@ export default { detail_enum: EnumDetail, statement: StatementDetail, detail_info: InfoDetail, - detail_color: ColorDetail + detail_color: ColorDetail, + table: TableField } diff --git a/src/components/detail/table/common/columnStyle.tsx b/src/components/detail/table/common/columnStyle.tsx new file mode 100644 index 0000000..a0d9e22 --- /dev/null +++ b/src/components/detail/table/common/columnStyle.tsx @@ -0,0 +1,20 @@ +import React, { Component } from 'react' + +type Props = { + style: any + addfix: boolean +}; + +export default class ColumnStyleComponent extends Component { + render () { + const { style, addfix = true } = this.props + const reSetStyle = Object.assign({}, { fontSize: style?.fontSize, color: style?.color }, style?.customStyle) + return addfix + ?
+ {style?.prefix || ''}{this.props.children}{style?.postfix || ''} +
+ :
+ {this.props.children} +
+ } +} diff --git a/src/components/detail/table/index.tsx b/src/components/detail/table/index.tsx new file mode 100644 index 0000000..17b409d --- /dev/null +++ b/src/components/detail/table/index.tsx @@ -0,0 +1,770 @@ +import React from 'react' +import queryString from 'query-string' +import { getParam, getParamText, getValue } from '../../../util/value' +import { getBoolean } from '../../../util/value' +import Step, { StepConfig, StepProps } from '../../../steps/common' +import { DetailField, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' +import getALLComponents, { ColumnConfigs } from '../../tableColumns' +import CCMS, { CCMSConfig } from '../../../main' +import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' +import ConditionHelper, { ConditionConfig } from '../../../util/condition' +import { ParamConfig } from '../../../interface' +import { DetailFieldProps } from '../common' +import { cloneDeep, get, set } from 'lodash' +import ColumnStyleComponent from './common/columnStyle' + + +export interface TableFieldConfig extends DetailFieldConfig { + type: 'table' + field: string + label: string + primary: string + tableColumns: ColumnConfigs[] + operations?: { + rowOperations?: Array + } + pagination?: { + mode: 'none' | 'client' | 'server' + current?: string + pageSize?: string + total?: string + } +} + +/** + * 表格步骤-操作配置文件格式 + */ +export interface TableOperationGroupConfig { + type: 'group' + label?: string + level?: 'normal' | 'primary' | 'danger' + operations: Array +} + +/** + * 表格步骤-操作配置文件格式 + */ +export interface TableOperationConfig { + type: 'button' + label: string + level?: 'normal' | 'primary' | 'danger' + check?: { enable: false } | TableOperationCheckConfig + confirm?: { enable: false } | TableOperationConfirmConfig + handle: TableCCMSOperationConfig | TableLinkOperationConfig + condition?: ConditionConfig +} + +export interface TableCCMSOperationConfig { + type: 'ccms' + page: any + target: 'current' | 'page' | 'open' | 'handle' + targetURL: string + data: { [key: string]: ParamConfig } + params?: { field: string, data: ParamConfig }[] + callback?: boolean + debug?: boolean +} + +export interface TableLinkOperationConfig { + type: 'link' + target: '_blank' | '_self' + targetURL: string + params?: { field: string, data: ParamConfig }[] + callback?: boolean + debug?: boolean +} + +interface TableOperationCheckConfig { + enable: true + interface: InterfaceConfig +} + +interface TableOperationConfirmConfig { + enable: true + titleText: string + titleParams?: Array<{ field: string, data: ParamConfig }> + okText: string + cancelText: string +} + +/** + * 表格步骤组件 - 列 - UI渲染方法 - 入参 + */ +export interface ITableColumn { + field: string + label: string + align: 'left' | 'center' | 'right' + render: (value: any, record: { [type: string]: any }, index: number) => React.ReactNode +} + +/** + * 表格步骤组件 - 操作 - UI渲染方法 - 入参 + */ +export interface ITableStepRowOperation { + children: (React.ReactNode | undefined)[] +} + +/** + * 表格步骤组件 - 操作 - UI渲染方法 - 入参 + */ +export interface ITableStepTableOperation { + children: (React.ReactNode | undefined)[] +} + +/** + * 表格步骤组件 - 操作按钮 - UI渲染方法 - 入参 + */ +export interface ITableStepRowOperationButton { + label: string + level: 'normal' | 'primary' | 'danger' + disabled?: boolean + onClick: () => Promise +} + +/** + * 表格步骤组件 - 操作按钮组 - UI渲染方法 - 入参 + */ +export interface ITableStepRowOperationGroup { + label?: string + children: React.ReactNode[] +} + +/** + * 表格步骤组件 - 操作按钮组元素 - UI渲染方法 - 入参 + */ +export interface ITableStepRowOperationGroupItem { + label: string + level: 'normal' | 'primary' | 'danger' + disabled?: boolean + onClick: () => Promise +} + +/** + * 表格步骤组件 - 操作按钮 - UI渲染方法 - 入参 + */ +export interface ITableStepTableOperationButton { + label: string + level: 'normal' | 'primary' | 'danger' + disabled?: boolean + onClick: () => Promise +} + +/** + * 表格步骤组件 - 操作按钮组 - UI渲染方法 - 入参 + */ +export interface ITableStepTableOperationGroup { + label?: string + children: React.ReactNode[] +} + +/** + * 表格步骤组件 - 操作按钮组元素 - UI渲染方法 - 入参 + */ +export interface ITableStepTableOperationGroupItem { + label: string + level: 'normal' | 'primary' | 'danger' + disabled?: boolean + onClick: () => Promise +} + +/** + * 表格步骤组件 - 操作 - 二次确认 - UI渲染方法 - 入参 + */ +export interface ITableStepOperationConfirm { + title: string + okText: string + cancelText: string + onOk: () => void + onCancel: () => void +} + +export interface ITableStepOperationModal { + title: string + visible: boolean + width: string + children: React.ReactNode + onClose: () => void +} + +interface TableState { + operation: { + enable: boolean + target: 'current' | 'handle' + title: string + visible: boolean + config: CCMSConfig + data: any + callback?: boolean + } + pageAuth: { [page: string]: boolean } +} + +/** + * 表格步骤组件 - UI渲染方法 - 入参 + * - data: 数据 + */ +export interface ITableField { + title: string | null + primary: string + data: { [field: string]: any }[] + tableColumns: ITableColumn[] + pagination?: { + current: number + pageSize: number + total: number + onChange: (page: number, pageSize: number) => void + } + // tableOperations: React.ReactNode | null + // multirowOperations: React.ReactNode | null, + description?: { + type: 'text' | 'tooltip' | 'modal' + label: string | undefined + content: React.ReactNode + showIcon: boolean + } +} + +export default class TableField extends DetailField implements IDetailField { + state: TableState + CCMS = CCMS + getALLComponents = (type: any) => getALLComponents[type] + interfaceHelper = new InterfaceHelper() + /** + * 页面权限获取状态 + * fulfilled |pending + */ + pageAuth: { [page: string]: boolean } = {} + /* 服务端分页情况下页码溢出标识:页码溢出时退回重新请求,此标识符用于防止死循环判断 */ + pageOverflow: boolean = false + + constructor(props: DetailFieldProps) { + super(props) + + this.state = { + operation: { + enable: false, + target: 'current', + title: '', + visible: false, + config: {}, + data: {}, + callback: false + }, + pageAuth: {} + } + } + + /** + * 执行操作 + * @param operation + * @param record + * @returns + */ + handleRowOperation = async (operation: TableOperationConfig, record: { [field: string]: any }) => { + const { + data, + step + } = this.props + if (operation.check && operation.check.enable) { + const checkResult = await this.interfaceHelper.request( + operation.check.interface, + {}, + { record, data, step }, + { loadDomain: this.props.loadDomain } + ) + if (!checkResult) { + return false + } + } + + if (operation.confirm && operation.confirm.enable) { + const title = operation.confirm.titleParams ? (await getParamText(operation.confirm.titleText, operation.confirm.titleParams, { record, data, step })) : operation.confirm.titleText + const showConfirm = () => { + return new Promise((resolve, reject) => { + if (operation.confirm && operation.confirm.enable) { + this.renderOperationConfirm({ + title, + okText: operation.confirm.okText, + cancelText: operation.confirm.cancelText, + onOk: () => { resolve(true) }, + onCancel: () => { reject(new Error('用户取消')) } + }) + } + }) + } + try { + await showConfirm() + } catch (e) { + return false + } + } + + if (operation.handle.type === 'ccms') { + const params = {} + if (operation.handle.params === undefined) { + for (const [field, param] of Object.entries(operation.handle.data || {})) { + const value = getParam(param, { record, data, step }) + set(params, field, value) + } + } else { + for (const { field, data: dataConfig } of operation.handle.params) { + const value = getParam(dataConfig, { record, data, step }) + set(params, field, value) + } + } + if (operation.handle.debug) { + console.log('CCMS debug: operation - params', params) + } + if (operation.handle.target === 'current' || operation.handle.target === 'handle') { + if (this.props.loadPageConfig) { + const operationConfig = await this.props.loadPageConfig(operation.handle.page) + + this.setState({ + operation: { + enable: true, + target: operation.handle.target, + title: operation.label, + visible: true, + config: operationConfig, + data: params, + callback: operation.handle.callback + } + }) + } + } else if (operation.handle.target === 'page') { + if (this.props.loadPageURL) { + const sourceURL = await this.props.loadPageURL(operation.handle.page) + const { url, query } = queryString.parseUrl(sourceURL, { arrayFormat: 'bracket' }) + const targetURL = operation.handle.targetURL || '' + const targetKey = queryString.stringifyUrl({ url, query: { ...query, ...params } }, { arrayFormat: 'bracket' }) || '' + if (this.props.handlePageRedirect) { + this.props.handlePageRedirect(`${targetURL}${targetKey}`) + } else { + window.location.href = `${targetURL}${targetKey}` + } + } + } else if (operation.handle.target === 'open') { + if (this.props.loadPageFrameURL) { + const sourceURL = await this.props.loadPageFrameURL(operation.handle.page) + const { url, query } = queryString.parseUrl(sourceURL, { arrayFormat: 'bracket' }) + const targetURL = operation.handle.targetURL || '' + const targetKey = queryString.stringifyUrl({ url, query: { ...query, ...params } }, { arrayFormat: 'bracket' }) || '' + window.open(`${targetURL}${targetKey}`) + } + } + } + + // 当按钮的响应类型是第三方链接时 + if (operation.handle.type === 'link') { + const params = {} + if (operation.handle.params !== undefined) { + for (const { field, data: dataConfig } of operation.handle.params) { + const value = getParam(dataConfig, { record, data, step }) + set(params, field, value) + } + + if (operation.handle.debug) { + console.log('CCMS debug: operation - operation.handle.type === link', params) + } + + // 提取跳转URL地址,合并URL参数拼接 + const targetURL = operation.handle.targetURL || '' + const urlParams = this.queryUrlParams(targetURL) + const query = urlParams.paramsResult + const hash = urlParams.hashResult.hash?.replace('#/', '') + const url = targetURL?.split('#')[0]?.split('?')[0] + // const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) + const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: hash }, { arrayFormat: 'bracket' }) || '' + + this.urlJumpHandler(jumpUrl, operation.handle.target) + } + } + } + + /** + * 获取URL中的路由和参数 + * @param url url地址 + */ + queryUrlParams = (url: string) => { + const paramsResult: any = {} + const hashResult: any = {} + const paramReg = /([^?=&#]+)=([^?=&#]+)/g + const hashReg = /#[^?=&#]+/g + // eslint-disable-next-line no-return-assign + url.replace(paramReg, (n, x, y) => paramsResult[x] = y) + // eslint-disable-next-line no-return-assign + url.replace(hashReg, (n) => hashResult.hash = n) + return { paramsResult, hashResult } + } + + /** + * 链接跳转处理方法 + * @param url 跳转地址 + * @param target 跳转方式 + */ + urlJumpHandler = (url: string, target: string) => { + const a = document.createElement('a') + document.body.appendChild(a) + a.href = url + a.target = target + a.click() + document.body.removeChild(a) + } + + /** + * 渲染 操作二次确认弹窗 + * @param props + */ + renderOperationConfirm = (props: ITableStepOperationConfirm) => { + const mask = document.createElement('DIV') + mask.style.position = 'fixed' + mask.style.left = '0px' + mask.style.top = '0px' + mask.style.width = '100%' + mask.style.height = '100%' + mask.style.backgroundColor = 'white' + mask.innerText = '您当前使用的UI版本没有实现Table的OperationConfirm组件。' + mask.onclick = () => { + mask.remove() + props.onOk() + } + + document.body.appendChild(mask) + } + + checkPageAuth = (page: string) => { + if (!this.pageAuth[page]) { + this.pageAuth[page] = true + this.props.checkPageAuth && this.props.checkPageAuth(page).then((auth) => { + const pageAuth = cloneDeep(this.state.pageAuth) + pageAuth[page] = auth + this.setState({ pageAuth }) + }) + } + } + + + /** + * 渲染 表格 + * @param props + * @returns + */ + renderComponent = (props: ITableField) => { + return + 您当前使用的UI版本没有实现Table组件。 +
+
+
+ } + + renderRowOperationComponent = (props: ITableStepRowOperation) => { + return + 您当前使用的UI版本没有实现Table组件的OperationButton部分。 + + } + + renderRowOperationButtonComponent = (props: ITableStepRowOperationButton) => { + return + 您当前使用的UI版本没有实现Table组件的OperationButton部分。 + + } + + renderRowOperationGroupComponent = (props: ITableStepRowOperationGroup) => { + return + 您当前使用的UI版本没有实现Table组件的OperationGroup部分。 + + } + + renderRowOperationGroupItemComponent = (props: ITableStepRowOperationGroupItem) => { + return + 您当前使用的UI版本没有实现Table组件的OperationGroupItem部分。 + + } + + renderTableOperationComponent = (props: ITableStepTableOperation) => { + return + 您当前使用的UI版本没有实现Table组件的OperationButton部分。 + + } + + renderTableOperationButtonComponent = (props: ITableStepTableOperationButton) => { + return + 您当前使用的UI版本没有实现Table组件的OperationButton部分。 + + } + + renderTableOperationGroupComponent = (props: ITableStepTableOperationGroup) => { + return + 您当前使用的UI版本没有实现Table组件的OperationGroup部分。 + + } + + renderTableOperationGroupItemComponent = (props: ITableStepTableOperationGroupItem) => { + return + 您当前使用的UI版本没有实现Table组件的OperationGroupItem部分。 + + } + + renderOperationModal = (props: ITableStepOperationModal) => { + const mask = document.createElement('DIV') + mask.style.position = 'fixed' + mask.style.left = '0px' + mask.style.top = '0px' + mask.style.width = props.width || '100%' + mask.style.height = '100%' + mask.style.backgroundColor = 'white' + mask.innerText = '您当前使用的UI版本没有实现Table的OperationModal组件。' + mask.onclick = () => { + mask.remove() + props.onClose() + } + + document.body.appendChild(mask) + } + + + render = () => { + const { + config: { + field, + label, + // width, + primary, + tableColumns, + operations, + pagination, + // description + }, + data, + step, + onUnmount, + value + } = this.props + + const { + operation: { + enable: operationEnable, + target: operationTarget, + title: operationTitle, + visible: operationVisible, + config: operationConfig, + data: operationData, + callback: operationCallback + }, + pageAuth + } = this.state + + // let getDate = field ? getValue(data[step], field) : data[step] + let getDate = value || [] + if (Object.prototype.toString.call(getDate) !== '[object Array]') { + getDate = [] + } + const props: ITableField = { + title: label, + primary, + data: getDate as { [field: string]: any; }[], + tableColumns: (tableColumns || []).filter((column) => column.field !== undefined && column.field !== '').map((column, index) => { + const field = column.field.split('.')[0] + return { + field, + label: column.label, + align: column.align, + render: (value: any, record: { [field: string]: any }) => { + if (value && Object.prototype.toString.call(value) === '[object Object]') { + value = getValue(value, column.field.replace(field, '').slice(1)) + } + + const Column = this.getALLComponents(column.type) + if (Column) { + const addfix = ['multirowText'].some((val) => val !== column.field) + return + + + } + } + } + }) + } + if (pagination && pagination.mode === 'server') { + const paginationCurrent = Number((pagination.current === undefined || pagination.current === '') ? data[step] : get(data[step], pagination.current, 1)) + const paginationPageSize = Number((pagination.pageSize === undefined || pagination.pageSize === '') ? data[step] : get(data[step], pagination.pageSize, 10)) + const paginationTotal = Number((pagination.total === undefined || pagination.total === '') ? data[step] : get(data[step], pagination.total, 0)) + + props.pagination = { + current: Number.isNaN(paginationCurrent) ? 1 : paginationCurrent, + pageSize: Number.isNaN(paginationPageSize) ? 10 : paginationPageSize, + total: Number.isNaN(paginationTotal) ? 0 : paginationTotal, + onChange: (page, pageSize) => { + this.props.onUnmount && this.props.onUnmount(true, { + [pagination.current || '']: page, + [pagination.pageSize || '']: pageSize + }) + } + } + + if (!this.pageOverflow && props.pagination.current > 1 && (props.pagination.current - 1) * props.pagination.pageSize >= props.pagination.total) { + this.pageOverflow = true + this.props.onUnmount && this.props.onUnmount(true, { + [pagination.current || '']: 1, + [pagination.pageSize || '']: props.pagination.pageSize + }) + } + } + + if (operations && operations.rowOperations && operations.rowOperations.length > 0) { + props.tableColumns.push({ + field: 'ccms-table-rowOperation', + label: '操作', + align: 'left', + render: (_value: any, record: { [field: string]: any }) => { + if (operations.rowOperations) { + return this.renderRowOperationComponent({ + children: (operations.rowOperations || []).map((operation, index) => { + if (operation.type === 'button') { + if (!ConditionHelper(operation.condition, { record, data, step })) { + return null + } + + let hidden = false + if (operation.handle && operation.handle.type === 'ccms') { + hidden = operation.handle.page === undefined || !false + operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) + } + + return ( + + {hidden + ? null + : this.renderRowOperationButtonComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { await this.handleRowOperation(operation, record) } + })} + + ) + } else if (operation.type === 'group') { + return ( + + {this.renderRowOperationGroupComponent({ + label: operation.label, + children: (operation.operations || []).map((operation) => { + if (!ConditionHelper(operation.condition, { record, data, step })) { + return null + } + + let hidden = false + if (operation.handle && operation.handle.type === 'ccms') { + hidden = operation.handle.page === undefined || !false + operation.handle.page !== undefined && this.checkPageAuth(operation.handle.page.toString()) + } + + return hidden + ? null + : this.renderRowOperationGroupItemComponent({ + label: operation.label, + level: operation.level || 'normal', + onClick: async () => { await this.handleRowOperation(operation, record) } + }) + }) + })} + + ) + } else { + return + } + }) + }) + } else { + return + } + } + }) + } + + const CCMS = this.CCMS + console.log('props:', props); + return ( + + {this.renderComponent(props)} + {operationEnable && ( + operationTarget === 'current' + ? ( + this.renderOperationModal({ + title: operationTitle, + width: '500', + visible: operationVisible, + children: ( + Promise} + loadPageURL={this.props.loadPageURL as (pageID: any) => Promise} + loadPageFrameURL={this.props.loadPageFrameURL as (pageID: any) => Promise} + loadPageConfig={this.props.loadPageConfig as (pageID: any) => Promise} + loadDomain={this.props.loadDomain} + handlePageRedirect={this.props.handlePageRedirect} + onMount={() => { + const { operation } = this.state + operation.visible = true + this.setState({ operation }) + }} + callback={() => { + const { operation } = this.state + operation.enable = false + operation.visible = false + this.setState({ operation }) + + if ((operationCallback && operationCallback === true) || Boolean(operationCallback)) { + onUnmount && onUnmount(true) + } + }} + /> + ), + onClose: () => { + const { operation } = this.state + operation.enable = false + operation.visible = false + this.setState({ operation }) + } + }) + ) + : ( + true} + loadPageURL={this.props.loadPageURL as (pageID: any) => Promise} + loadPageFrameURL={this.props.loadPageFrameURL as (pageID: any) => Promise} + loadPageConfig={this.props.loadPageConfig as (pageID: any) => Promise} + loadDomain={this.props.loadDomain} + handlePageRedirect={this.props.handlePageRedirect} + onMount={() => { + const { operation } = this.state + operation.visible = true + this.setState({ operation }) + }} + callback={() => { + const { operation } = this.state + operation.enable = false + operation.visible = false + this.setState({ operation }) + + if ((operationCallback && operationCallback === true) || Boolean(operationCallback)) { + onUnmount && onUnmount(true) + } + }} + /> + ) + )} + + ) + } +} diff --git a/src/index.tsx b/src/index.tsx index af50ce4..93425aa 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -60,6 +60,7 @@ export { default as DetailTextField } from './components/detail/text' export { default as DetailImportSubformField } from './components/detail/importSubform' export { default as DetailInfoField } from './components/detail/detailInfo' export { default as DetailColorField } from './components/detail/detailColor' +export { default as DetailTableField } from './components/detail/table' export { default as HeaderStep } from './steps/header' diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index e877424..8733659 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -434,12 +434,12 @@ export default class DetailStep extends Step { // message: detailFieldConfig.field !== undefined ? getValue(detailData, detailFieldConfig.field, {}).message || '' : '', columns: config.columns?.enable ? { - type: detailFieldConfig.columns?.type || config.columns?.type || 'span', - value: detailFieldConfig.columns?.value || config.columns?.value || 1, - wrap: detailFieldConfig.columns?.wrap || config.columns?.wrap || false, - gap: detailFieldConfig.columns?.gap || config.columns?.gap || 0, - rowGap: detailFieldConfig.columns?.rowGap || config.columns?.rowGap || 0 - } + type: detailFieldConfig.columns?.type || config.columns?.type || 'span', + value: detailFieldConfig.columns?.value || config.columns?.value || 1, + wrap: detailFieldConfig.columns?.wrap || config.columns?.wrap || false, + gap: detailFieldConfig.columns?.gap || config.columns?.gap || 0, + rowGap: detailFieldConfig.columns?.rowGap || config.columns?.rowGap || 0 + } : undefined, layout, styles: detailFieldConfig.styles || {}, @@ -447,6 +447,12 @@ export default class DetailStep extends Step { fieldType: detailFieldConfig.type, children: ( this.props.handlePageRedirect} key={detailFieldIndex} ref={(detailField: DetailField | null) => { if (detailFieldIndex !== null) { -- Gitee From 7174325d60b06967f99b53cb2fa58c1adf44150b Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 30 Mar 2022 10:23:55 +0800 Subject: [PATCH 112/164] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 12 +- src/components/detail/group/index.tsx | 65 +++++---- src/components/detail/table/index.tsx | 191 +++++++++++++++----------- 3 files changed, 156 insertions(+), 112 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 69560e3..ac8a055 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -90,12 +90,12 @@ export interface DetailFieldProps { onValueListSplice: (path: string, index: number, count: number, validation: true | DetailFieldError[]) => Promise baseRoute: string, loadDomain: (domain: string) => Promise - loadPageConfig?: (pageID: any) => Promise - handlePageRedirect?: (path: string) => void - checkPageAuth?: (pageID: any) => Promise - onUnmount?: (reload?: boolean, data?: any) => Promise - loadPageURL?: (pageID: any) => Promise - loadPageFrameURL?: (pageID: any) => Promise + loadPageConfig: (pageID: any) => Promise + handlePageRedirect: (path: string) => void + checkPageAuth: (pageID: any) => Promise + onUnmount: (reload?: boolean, data?: any) => Promise + loadPageURL: (pageID: any) => Promise + loadPageFrameURL: (pageID: any) => Promise } /** diff --git a/src/components/detail/group/index.tsx b/src/components/detail/group/index.tsx index c7dd58d..3bbf31a 100644 --- a/src/components/detail/group/index.tsx +++ b/src/components/detail/group/index.tsx @@ -30,7 +30,7 @@ export default class GroupField extends DetailField | null> = [] detailFieldsMounted: Array = [] - constructor (props: DetailFieldProps) { + constructor(props: DetailFieldProps) { super(props) this.state = { @@ -250,40 +250,47 @@ export default class GroupField extends DetailField | null) => { - if (detailFieldIndex !== null) { - this.detailFields[detailFieldIndex] = detailField - this.handleMount(detailFieldIndex) - } - }} - formLayout={formLayout} - value={getValue(value, detailFieldConfig.field)} - record={record} - data={cloneDeep(data)} - step={step} - config={detailFieldConfig} - onChange={async (value: any) => { await this.handleChange(detailFieldIndex, value) }} - onValueSet={async (path, value, validation) => this.handleValueSet(detailFieldIndex, path, value, validation)} - onValueUnset={async (path, validation) => this.handleValueUnset(detailFieldIndex, path, validation)} - onValueListAppend={async (path, value, validation) => this.handleValueListAppend(detailFieldIndex, path, value, validation)} - onValueListSplice={async (path, index, count, validation) => this.handleValueListSplice(detailFieldIndex, path, index, count, validation)} - baseRoute={this.props.baseRoute} - loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - /> + | null) => { + if (detailFieldIndex !== null) { + this.detailFields[detailFieldIndex] = detailField + this.handleMount(detailFieldIndex) + } + }} + formLayout={formLayout} + value={getValue(value, detailFieldConfig.field)} + record={record} + data={cloneDeep(data)} + step={step} + config={detailFieldConfig} + detail={this.props.detail} + onChange={async (value: any) => { await this.handleChange(detailFieldIndex, value) }} + onValueSet={async (path, value, options) => this.handleValueSet(detailFieldIndex, path, value, options)} + onValueUnset={async (path, options) => this.handleValueUnset(detailFieldIndex, path, options)} + onValueListAppend={async (path, value, options) => this.handleValueListAppend(detailFieldIndex, path, value, options)} + onValueListSplice={async (path, index, count, options) => this.handleValueListSplice(detailFieldIndex, path, index, count, options)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + /> ) } // 渲染表单项容器 diff --git a/src/components/detail/table/index.tsx b/src/components/detail/table/index.tsx index 17b409d..3a31698 100644 --- a/src/components/detail/table/index.tsx +++ b/src/components/detail/table/index.tsx @@ -2,7 +2,6 @@ import React from 'react' import queryString from 'query-string' import { getParam, getParamText, getValue } from '../../../util/value' import { getBoolean } from '../../../util/value' -import Step, { StepConfig, StepProps } from '../../../steps/common' import { DetailField, DetailFieldConfig, DetailFieldError, IDetailField } from '../common' import getALLComponents, { ColumnConfigs } from '../../tableColumns' import CCMS, { CCMSConfig } from '../../../main' @@ -12,6 +11,7 @@ import { ParamConfig } from '../../../interface' import { DetailFieldProps } from '../common' import { cloneDeep, get, set } from 'lodash' import ColumnStyleComponent from './common/columnStyle' +import Column from '../../tableColumns/common' export interface TableFieldConfig extends DetailFieldConfig { @@ -21,7 +21,7 @@ export interface TableFieldConfig extends DetailFieldConfig { primary: string tableColumns: ColumnConfigs[] operations?: { - rowOperations?: Array + rowOperations?: Array } pagination?: { mode: 'none' | 'client' | 'server' @@ -31,6 +31,12 @@ export interface TableFieldConfig extends DetailFieldConfig { } } + +/** + * 表格步骤-菜单配置 + */ +export type TableOperationsType = TableOperationConfig | TableOperationGroupConfig | TableOperationDropdownConfig + /** * 表格步骤-操作配置文件格式 */ @@ -41,6 +47,16 @@ export interface TableOperationGroupConfig { operations: Array } +/** + * 表格步骤-操作配置文件下拉菜单 + */ +export interface TableOperationDropdownConfig { + type: 'dropdown' + label?: string + level?: 'normal' | 'primary' | 'danger' + operations: Array +} + /** * 表格步骤-操作配置文件格式 */ @@ -100,21 +116,21 @@ export interface ITableColumn { /** * 表格步骤组件 - 操作 - UI渲染方法 - 入参 */ -export interface ITableStepRowOperation { +export interface ITableDetailRowOperation { children: (React.ReactNode | undefined)[] } /** * 表格步骤组件 - 操作 - UI渲染方法 - 入参 */ -export interface ITableStepTableOperation { +export interface ITableDetailTableOperation { children: (React.ReactNode | undefined)[] } /** * 表格步骤组件 - 操作按钮 - UI渲染方法 - 入参 */ -export interface ITableStepRowOperationButton { +export interface ITableDetailRowOperationButton { label: string level: 'normal' | 'primary' | 'danger' disabled?: boolean @@ -124,7 +140,7 @@ export interface ITableStepRowOperationButton { /** * 表格步骤组件 - 操作按钮组 - UI渲染方法 - 入参 */ -export interface ITableStepRowOperationGroup { +export interface ITableDetailRowOperationGroup { label?: string children: React.ReactNode[] } @@ -132,7 +148,7 @@ export interface ITableStepRowOperationGroup { /** * 表格步骤组件 - 操作按钮组元素 - UI渲染方法 - 入参 */ -export interface ITableStepRowOperationGroupItem { +export interface ITableDetailRowOperationGroupItem { label: string level: 'normal' | 'primary' | 'danger' disabled?: boolean @@ -142,7 +158,7 @@ export interface ITableStepRowOperationGroupItem { /** * 表格步骤组件 - 操作按钮 - UI渲染方法 - 入参 */ -export interface ITableStepTableOperationButton { +export interface ITableDetailTableOperationButton { label: string level: 'normal' | 'primary' | 'danger' disabled?: boolean @@ -152,7 +168,7 @@ export interface ITableStepTableOperationButton { /** * 表格步骤组件 - 操作按钮组 - UI渲染方法 - 入参 */ -export interface ITableStepTableOperationGroup { +export interface ITableDetailTableOperationGroup { label?: string children: React.ReactNode[] } @@ -160,7 +176,7 @@ export interface ITableStepTableOperationGroup { /** * 表格步骤组件 - 操作按钮组元素 - UI渲染方法 - 入参 */ -export interface ITableStepTableOperationGroupItem { +export interface ITableDetailTableOperationGroupItem { label: string level: 'normal' | 'primary' | 'danger' disabled?: boolean @@ -170,7 +186,7 @@ export interface ITableStepTableOperationGroupItem { /** * 表格步骤组件 - 操作 - 二次确认 - UI渲染方法 - 入参 */ -export interface ITableStepOperationConfirm { +export interface ITableDetailOperationConfirm { title: string okText: string cancelText: string @@ -178,7 +194,7 @@ export interface ITableStepOperationConfirm { onCancel: () => void } -export interface ITableStepOperationModal { +export interface ITableDetailOperationModal { title: string visible: boolean width: string @@ -224,10 +240,9 @@ export interface ITableField { } } -export default class TableField extends DetailField implements IDetailField { - state: TableState +export default class TableField extends DetailField implements IDetailField { CCMS = CCMS - getALLComponents = (type: any) => getALLComponents[type] + getALLComponents = (type: any): typeof Column => getALLComponents[type] interfaceHelper = new InterfaceHelper() /** * 页面权限获取状态 @@ -315,42 +330,38 @@ export default class TableField extends DetailField { + renderOperationConfirm = (props: ITableDetailOperationConfirm) => { const mask = document.createElement('DIV') mask.style.position = 'fixed' mask.style.left = '0px' @@ -435,6 +446,7 @@ export default class TableField extends DetailField { if (!this.pageAuth[page]) { this.pageAuth[page] = true + this.props.checkPageAuth && this.props.checkPageAuth(page).then((auth) => { const pageAuth = cloneDeep(this.state.pageAuth) pageAuth[page] = auth @@ -457,55 +469,43 @@ export default class TableField extends DetailField } - renderRowOperationComponent = (props: ITableStepRowOperation) => { + renderRowOperationComponent = (props: ITableDetailRowOperation) => { return 您当前使用的UI版本没有实现Table组件的OperationButton部分。 } - renderRowOperationButtonComponent = (props: ITableStepRowOperationButton) => { + renderRowOperationButtonComponent = (props: ITableDetailRowOperationButton) => { return 您当前使用的UI版本没有实现Table组件的OperationButton部分。 } - renderRowOperationGroupComponent = (props: ITableStepRowOperationGroup) => { + renderRowOperationGroupComponent = (props: ITableDetailRowOperationGroup) => { return 您当前使用的UI版本没有实现Table组件的OperationGroup部分。 } - renderRowOperationGroupItemComponent = (props: ITableStepRowOperationGroupItem) => { + renderRowOperationGroupItemComponent = (props: ITableDetailRowOperationGroupItem) => { return 您当前使用的UI版本没有实现Table组件的OperationGroupItem部分。 } - renderTableOperationComponent = (props: ITableStepTableOperation) => { + renderRowOperationDropdownComponent = (props: ITableDetailRowOperationGroup) => { return - 您当前使用的UI版本没有实现Table组件的OperationButton部分。 + 您当前使用的UI版本没有实现Table组件的OperationDropdown部分。 } - renderTableOperationButtonComponent = (props: ITableStepTableOperationButton) => { + renderRowOperationDropdownItemComponent = (props: ITableDetailRowOperationGroupItem) => { return - 您当前使用的UI版本没有实现Table组件的OperationButton部分。 + 您当前使用的UI版本没有实现Table组件的OperationDropdownItem部分。 } - renderTableOperationGroupComponent = (props: ITableStepTableOperationGroup) => { - return - 您当前使用的UI版本没有实现Table组件的OperationGroup部分。 - - } - - renderTableOperationGroupItemComponent = (props: ITableStepTableOperationGroupItem) => { - return - 您当前使用的UI版本没有实现Table组件的OperationGroupItem部分。 - - } - - renderOperationModal = (props: ITableStepOperationModal) => { + renderOperationModal = (props: ITableDetailOperationModal) => { const mask = document.createElement('DIV') mask.style.position = 'fixed' mask.style.left = '0px' @@ -559,10 +559,11 @@ export default class TableField extends DetailField column.field !== undefined && column.field !== '').map((column, index) => { const field = column.field.split('.')[0] return { @@ -579,11 +580,15 @@ export default class TableField extends DetailField val !== column.field) return { }} record={record} value={value} data={data} step={step} config={column} + column={this} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> } @@ -632,11 +637,12 @@ export default class TableField extends DetailField
) -- Gitee From 04826ceca4c65d55b95fb2657327637eaf805945 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 13 Apr 2022 18:22:14 +0800 Subject: [PATCH 120/164] =?UTF-8?q?perf:=20=E7=BB=9F=E4=B8=80=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/table/index.tsx | 2 +- src/components/tableColumns/common.tsx | 2 +- src/steps/table/index.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/detail/table/index.tsx b/src/components/detail/table/index.tsx index d4a5f34..3c51752 100644 --- a/src/components/detail/table/index.tsx +++ b/src/components/detail/table/index.tsx @@ -546,7 +546,7 @@ export default class TableField extends DetailField await this.props.loadDomain(domain)} /> diff --git a/src/components/tableColumns/common.tsx b/src/components/tableColumns/common.tsx index 5c54728..d48a2c8 100644 --- a/src/components/tableColumns/common.tsx +++ b/src/components/tableColumns/common.tsx @@ -31,7 +31,7 @@ export interface ColumnProps { step: number, config: T, // 挂载引用 - column?: React.ReactNode + table?: React.ReactNode baseRoute: string loadDomain: (domain: string) => Promise } diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index f4b88d0..9f31459 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -691,7 +691,7 @@ export default class TableStep extends Step { data={data} step={step} config={column} - column={this} + table={this} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> -- Gitee From 91b3461baa4ea76ebaf55762a25d197a3ca9f92a Mon Sep 17 00:00:00 2001 From: wangailin Date: Wed, 13 Apr 2022 18:40:12 +0800 Subject: [PATCH 121/164] =?UTF-8?q?feat:=20=E5=88=97=E8=A1=A8=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=B7=BB=E5=8A=A0URL=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tableColumns/text/index.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/tableColumns/text/index.tsx b/src/components/tableColumns/text/index.tsx index 639f6fc..e82a169 100644 --- a/src/components/tableColumns/text/index.tsx +++ b/src/components/tableColumns/text/index.tsx @@ -3,10 +3,13 @@ import Column, { ColumnConfig } from '../common' export interface TextColumnConfig extends ColumnConfig { type: 'text' + // 临时方案 后续优化 + linkUrl: boolean } export interface ITextColumn { value: string + linkUrl: boolean } export default class TextColumn extends Column { @@ -31,11 +34,17 @@ export default class TextColumn extends Column { } render = () => { + const { + config: { + linkUrl + } + } = this.props + const value = this.getValue() return ( - {this.renderComponent({ value })} + {this.renderComponent({ value, linkUrl })} ) } -- Gitee From da0bc74b422a83be22749186e5aedceef95a4695 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 14 Apr 2022 09:44:34 +0800 Subject: [PATCH 122/164] =?UTF-8?q?feat:=20=E8=A1=A8=E6=A0=BC=E9=A1=B9?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=96=B0=E5=A2=9E=E5=A4=9A=E8=A1=8C=E7=9C=81?= =?UTF-8?q?=E7=95=A5=E4=B8=8E=E6=9F=A5=E7=9C=8B=E6=9B=B4=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tableColumns/text/index.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/tableColumns/text/index.tsx b/src/components/tableColumns/text/index.tsx index e82a169..4a2f8bf 100644 --- a/src/components/tableColumns/text/index.tsx +++ b/src/components/tableColumns/text/index.tsx @@ -1,15 +1,26 @@ import React from 'react' import Column, { ColumnConfig } from '../common' +/** + * 表格文本配置项 + * - type: 文本类型 + * - linkUrl: 可跳转文本超链接,临时方案,后续优化。 + * - showLines: 显示行数多行省略 + * - showMore: 查看更多 showLines 大于1时显示 + */ export interface TextColumnConfig extends ColumnConfig { type: 'text' // 临时方案 后续优化 linkUrl: boolean + showLines?: number + showMore?: boolean } export interface ITextColumn { value: string linkUrl: boolean + showLines?: number + showMore?: boolean } export default class TextColumn extends Column { @@ -36,7 +47,9 @@ export default class TextColumn extends Column { render = () => { const { config: { - linkUrl + linkUrl, + showLines, + showMore } } = this.props @@ -44,7 +57,7 @@ export default class TextColumn extends Column { return ( - {this.renderComponent({ value, linkUrl })} + {this.renderComponent({ value, linkUrl, showLines, showMore })} ) } -- Gitee From 83ba7a7d6f670f05bc5038dcd7d23da31cc629eb Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 14 Apr 2022 11:12:13 +0800 Subject: [PATCH 123/164] =?UTF-8?q?fix:=20column=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=B8=BAtable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tableColumns/custom/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/tableColumns/custom/index.tsx b/src/components/tableColumns/custom/index.tsx index 15f1d54..dbfff51 100644 --- a/src/components/tableColumns/custom/index.tsx +++ b/src/components/tableColumns/custom/index.tsx @@ -38,7 +38,7 @@ export default class CustomColumn extends Column im data: cloneDeep(this.props.data), step: this.props.step, config: this.props.config, - column: this.props.column, + table: this.props.table, base: this.props.baseRoute, loadDomain: this.props.loadDomain }) @@ -60,7 +60,7 @@ export default class CustomColumn extends Column im data: cloneDeep(this.props.data), step: this.props.step, config: this.props.config, - column: this.props.column, + table: this.props.table, base: this.props.baseRoute, loadDomain: this.props.loadDomain } -- Gitee From 29e052f002b58dd37a26a1ce7f530702f049bb8b Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 14 Apr 2022 14:54:10 +0800 Subject: [PATCH 124/164] =?UTF-8?q?perf:=20=E8=A1=A5=E5=85=85=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/multiple/index.tsx | 2 +- src/util/value.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/formFields/select/multiple/index.tsx b/src/components/formFields/select/multiple/index.tsx index 262c998..ad0aca9 100644 --- a/src/components/formFields/select/multiple/index.tsx +++ b/src/components/formFields/select/multiple/index.tsx @@ -18,7 +18,7 @@ interface SelectMultipleArrayConfig { interface SelectMultipleSplitConfig { type: 'split', split?: string, - valueType?: string + valueType?: 'string' | 'number' | 'boolean' | undefined } export interface ISelectMultipleField { diff --git a/src/util/value.ts b/src/util/value.ts index d45ae5c..10cd4dd 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -128,7 +128,7 @@ export const listItemMove = (list: any[], currentIndex: number, sortType: 'up' | * @param type 值类型 * @returns value数组 */ -export const transformValueType = (list: any[], type: string | undefined) => { +export const transformValueType = (list: any[], type: 'string' | 'number' | 'boolean' | undefined) => { switch (type) { case 'string': return list.map(v => String(v)) -- Gitee From 1dada1a3d1650a2fb4de1b2617e8931b74c49299 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 14 Apr 2022 15:01:01 +0800 Subject: [PATCH 125/164] =?UTF-8?q?feat:=20=E5=8E=BB=E6=8E=89=E5=AD=90?= =?UTF-8?q?=E9=A1=B9=E4=B8=AD=E5=AD=98=E5=9C=A8=E9=94=99=E8=AF=AF=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E7=BB=9F=E4=B8=80=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index e97cb98..5fa6f47 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -94,7 +94,7 @@ export default class GroupField extends Field 0) { - const errTips = `${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + const errTips = `${this.props.config.label || ''}子项中存在错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` errors.push(new FieldError(errTips)) } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 23f933d..cdecd33 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -144,7 +144,7 @@ export default class ImportSubformField extends Field 0) { - const errTips = `${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + const errTips = `${this.props.config.label || ''}子项中错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` errors.push(new FieldError(errTips)) } diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index b0de063..0b2e8fd 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -130,7 +130,7 @@ export default class ObjectField extends Field 0) { - errors.push(new FieldError(`子项中存在${childrenError}个错误。`)) + errors.push(new FieldError('子项中存在错误。')) } return errors.length ? errors : true diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 9167351..36ab708 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -148,7 +148,7 @@ export default class TabsField extends Field 0) { - const errTips = `${this.props.config.label || ''}子项中存在${childrenError}个错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + const errTips = `${this.props.config.label || ''}子项中存在错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}` errors.push(new FieldError(errTips)) } -- Gitee From 9e08faa1014a1b28a0f9af612e34d5ec2e3ad9f6 Mon Sep 17 00:00:00 2001 From: wangailin Date: Thu, 14 Apr 2022 15:15:13 +0800 Subject: [PATCH 126/164] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0image=E7=9A=84?= =?UTF-8?q?type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/image/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/detail/image/index.tsx b/src/components/detail/image/index.tsx index 9bc21f1..2783cb1 100644 --- a/src/components/detail/image/index.tsx +++ b/src/components/detail/image/index.tsx @@ -9,7 +9,7 @@ import { DetailField, DetailFieldConfig, IDetailField } from '../common' * - preview: 点击预览 */ export interface ImageDetailConfig extends DetailFieldConfig { - type: 'Image', + type: 'image', height?: string | number width?: string | number preview?: boolean -- Gitee From ff1e641ff3bee5c7163082168e945cf558d67add Mon Sep 17 00:00:00 2001 From: "ext.pangzhaoqun1" Date: Thu, 14 Apr 2022 16:03:25 +0800 Subject: [PATCH 127/164] 1 --- src/steps/table/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 57727d9..bf47581 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -83,6 +83,8 @@ export interface TableOperationConfig { condition?: ConditionConfig modalWidthRatio?: string modalWidth?: number + // modalWidthMode? : 'none' | 'percentage' | 'pixel' + // modalWidthValue? : string } export interface TableCCMSOperationConfig { -- Gitee From b1ebc67d4eaacdece8019fdef47d51c191416e8c Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 14 Apr 2022 16:26:18 +0800 Subject: [PATCH 128/164] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=90=8D=E5=92=8C=E8=A1=A5=E5=85=85=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/common.tsx | 29 ++++++------------- .../formFields/treeSelect/index.tsx | 18 ++++++------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 550175d..2a621ec 100644 --- a/src/components/formFields/select/common.tsx +++ b/src/components/formFields/select/common.tsx @@ -2,24 +2,13 @@ import { ReactNode } from 'react' import EnumerationHelper, { EnumerationOptionsConfig, InterfaceEnumerationOptionsKVConfig, InterfaceEnumerationOptionsListConfig } from '../../../util/enumeration' import InterfaceHelper from '../../../util/interface' import { Field, FieldConfig, FieldProps, IField, Display, DisplayProps } from '../common' -import { - RecordParamConfig, - DataParamConfig, - StepParamConfig, - SourceParamConfig -} from '../../../interface' +import { ParamConfig } from '../../../interface' import ParamHelper from '../../../util/param' import { getValue } from '../../../util/value' -type OptionsConfigDefaultValue = - | RecordParamConfig - | DataParamConfig - | StepParamConfig - | SourceParamConfig; - -interface AutomaticEnumerationOptionsConfig { - from: 'automatic'; - sourceConfig?: OptionsConfigDefaultValue; +interface DataEnumerationOptionsConfig { + from: 'data'; + sourceConfig?: ParamConfig; format?: | InterfaceEnumerationOptionsKVConfig | InterfaceEnumerationOptionsListConfig; @@ -55,7 +44,7 @@ export default class SelectField extends Fiel } } - optionsAutomaticValue = (sourceConfig: OptionsConfigDefaultValue) => { + optionsDataValue = (sourceConfig: ParamConfig) => { if (sourceConfig !== undefined) { return ParamHelper(sourceConfig, { record: this.props.record, data: this.props.data, step: this.props.step }) } @@ -63,12 +52,12 @@ export default class SelectField extends Fiel } options = ( - config: EnumerationOptionsConfig | undefined | AutomaticEnumerationOptionsConfig + config: EnumerationOptionsConfig | undefined | DataEnumerationOptionsConfig ) => { if (config) { - if (config.from === 'automatic') { - if (config.sourceConfig && config.sourceConfig.source && config.sourceConfig.field) { - const data = this.optionsAutomaticValue(config.sourceConfig) + if (config.from === 'data') { + if (config.sourceConfig && config.sourceConfig.source) { + const data = this.optionsDataValue(config.sourceConfig) if (config.format) { if (config.format.type === 'kv') { return Object.keys(data).map((key) => ({ diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 9ed3fa9..6095c81 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -12,7 +12,7 @@ export interface TreeSelectFieldConfig extends FieldConfig { mode?: 'tree' | 'table' multiple?: true | TreeSelectMultipleArrayConfig | TreeSelectMultipleSplitConfig, titleColumn?: string, - treeData?: ManualOptionsConfig | InterfaceOptionsConfig | AutomaticOptionsConfig + treeData?: ManualOptionsConfig | InterfaceOptionsConfig | DataOptionsConfig } interface TreeSelectMultipleArrayConfig { @@ -22,10 +22,10 @@ interface TreeSelectMultipleArrayConfig { interface TreeSelectMultipleSplitConfig { type: 'split', split?: string, - valueType?: string + valueType?: 'string' | 'number' | 'boolean' | undefined } -export interface AutomaticOptionsConfig { - from: 'automatic' +export interface DataOptionsConfig { + from: 'data' sourceConfig?: OptionsConfigDefaultValue, format?: InterfaceOptionsListConfig } @@ -93,7 +93,7 @@ export default class TreeSelectField extends Field { + optionsData = (sourceConfig: OptionsConfigDefaultValue) => { if (sourceConfig !== undefined) { return ParamHelper(sourceConfig, { record: this.props.record, data: this.props.data, step: this.props.step }) } @@ -124,7 +124,7 @@ export default class TreeSelectField extends Field { if (config) { - if (config.from === 'automatic') { + if (config.from === 'data') { if (config.sourceConfig && config.sourceConfig.source && config.sourceConfig.field) { - const data = this.optionsAutomatic(config.sourceConfig) + const data = this.optionsData(config.sourceConfig) if (Array.isArray(data)) { return this.formatTree( data, @@ -263,7 +263,7 @@ export default class TreeSelectField extends Field Date: Thu, 14 Apr 2022 17:11:29 +0800 Subject: [PATCH 129/164] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=AF=94=E4=BE=8B=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index bf47581..fe14b7b 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -81,10 +81,8 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig - modalWidthRatio?: string - modalWidth?: number - // modalWidthMode? : 'none' | 'percentage' | 'pixel' - // modalWidthValue? : string + modalWidthMode?: 'none' | 'percentage' | 'pixel' + modalWidthValue?: string | number } export interface TableCCMSOperationConfig { @@ -247,8 +245,8 @@ export interface ITableStepOperationModal { width: string children: React.ReactNode onClose: () => void - modalWidthRatio?: string - modalWidth?: number + modalWidthMode?: 'none' | 'percentage' | 'pixel' + modalWidthValue?: string | number } interface TableState { @@ -258,8 +256,8 @@ interface TableState { width: string title: string visible: boolean - modalWidthRatio?: string - modalWidth?: number + modalWidthMode?: 'none' | 'percentage' | 'pixel' + modalWidthValue?: string | number config: CCMSConfig data: any callback?: boolean @@ -297,8 +295,8 @@ export default class TableStep extends Step { config: {}, data: {}, callback: false, - modalWidthRatio: '40', - modalWidth: 400, + modalWidthMode: 'none', + modalWidthValue: '', closeCallback: false }, pageAuth: {} @@ -376,8 +374,8 @@ export default class TableStep extends Step { width: operation.handle.width, title: operation.label, visible: true, - modalWidthRatio: operation.modalWidthRatio, - modalWidth: operation.modalWidth, + modalWidthMode: operation.modalWidthMode, + modalWidthValue: operation.modalWidthValue, config: operationConfig, data: params, callback: operation.handle.callback, @@ -668,8 +666,8 @@ export default class TableStep extends Step { data: operationData, callback: operationCallback, closeCallback: operationcloseCallback, - modalWidthRatio: operationModalWidthRatio, - modalWidth: operationModalWidth, + modalWidthMode: operationModalWidthMode, + modalWidthValue: operationModalWidthValue }, pageAuth } = this.state @@ -866,8 +864,8 @@ export default class TableStep extends Step { title: operationTitle, width: operationWidth, visible: operationVisible, - modalWidthRatio: operationModalWidthRatio, - modalWidth: operationModalWidth, + modalWidthMode: operationModalWidthMode, + modalWidthValue: operationModalWidthValue, children: ( Date: Thu, 14 Apr 2022 17:21:13 +0800 Subject: [PATCH 130/164] =?UTF-8?q?perf:=20=E5=B7=B2=E9=80=89=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E6=88=90=E5=88=B0EnumerationHelper=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/select/common.tsx | 55 +++++---------------- src/steps/header/index.tsx | 14 ++++-- src/util/enumeration.ts | 55 +++++++++++++++++++-- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 2a621ec..039461a 100644 --- a/src/components/formFields/select/common.tsx +++ b/src/components/formFields/select/common.tsx @@ -2,17 +2,6 @@ import { ReactNode } from 'react' import EnumerationHelper, { EnumerationOptionsConfig, InterfaceEnumerationOptionsKVConfig, InterfaceEnumerationOptionsListConfig } from '../../../util/enumeration' import InterfaceHelper from '../../../util/interface' import { Field, FieldConfig, FieldProps, IField, Display, DisplayProps } from '../common' -import { ParamConfig } from '../../../interface' -import ParamHelper from '../../../util/param' -import { getValue } from '../../../util/value' - -interface DataEnumerationOptionsConfig { - from: 'data'; - sourceConfig?: ParamConfig; - format?: - | InterfaceEnumerationOptionsKVConfig - | InterfaceEnumerationOptionsListConfig; -} export interface SelectFieldConfig extends FieldConfig { options?: EnumerationOptionsConfig @@ -44,41 +33,15 @@ export default class SelectField extends Fiel } } - optionsDataValue = (sourceConfig: ParamConfig) => { - if (sourceConfig !== undefined) { - return ParamHelper(sourceConfig, { record: this.props.record, data: this.props.data, step: this.props.step }) - } - return undefined - } - options = ( - config: EnumerationOptionsConfig | undefined | DataEnumerationOptionsConfig + config: EnumerationOptionsConfig | undefined ) => { if (config) { - if (config.from === 'data') { - if (config.sourceConfig && config.sourceConfig.source) { - const data = this.optionsDataValue(config.sourceConfig) - if (config.format) { - if (config.format.type === 'kv') { - return Object.keys(data).map((key) => ({ - value: key, - label: data[key] - })) - } else if (config.format.type === 'list') { - if (Array.isArray(data)) { - return data.map((item: any) => { - return { - value: getValue(item, (config.format as InterfaceEnumerationOptionsListConfig).keyField), - label: getValue(item, (config.format as InterfaceEnumerationOptionsListConfig).labelField) - } - }) - } - } - } - } - return [] - } - EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { + EnumerationHelper.options( + config, + (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain }), + { record: this.props.record, data: this.props.data, step: this.props.step } + ).then((options) => { if (JSON.stringify(this.state.options) !== JSON.stringify(options)) { this.setState({ options @@ -107,7 +70,11 @@ export class SelectDisplay extends Display { if (config) { - EnumerationHelper.options(config, (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { + EnumerationHelper.options( + config, + (config, source) => this.interfaceHelper.request(config, source, { record: this.props.record, data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain }), + { record: this.props.record, data: this.props.data, step: this.props.step } + ).then((options) => { if (JSON.stringify(this.state.options) !== JSON.stringify(options)) { this.setState({ options diff --git a/src/steps/header/index.tsx b/src/steps/header/index.tsx index a7ec2d7..d693a2e 100644 --- a/src/steps/header/index.tsx +++ b/src/steps/header/index.tsx @@ -226,9 +226,9 @@ export default class HeaderStep extends Step { ref={(e: Step | null) => { e && e.stepPush() }} data={this.props.data} step={this.props.step} - onSubmit={async (data, unmountView) => {}} - onMount={async () => {}} - onUnmount={async (reload = false, data) => {}} + onSubmit={async (data, unmountView) => { }} + onMount={async () => { }} + onUnmount={async (reload = false, data) => { }} config={merge(config, defaultConfig)} baseRoute={this.props.baseRoute} checkPageAuth={this.props.checkPageAuth} @@ -252,7 +252,11 @@ export default class HeaderStep extends Step { }) case 'enumeration': if (statistic.options) { - EnumerationHelper.options(statistic.options, (config, source) => this.interfaceHelper.request(config, source, { data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain })).then((options) => { + EnumerationHelper.options( + statistic.options, + (config, source) => this.interfaceHelper.request(config, source, { data: this.props.data, step: this.props.step }, { loadDomain: this.props.loadDomain }), + { data: this.props.data, step: this.props.step } + ).then((options) => { if (!this.state || JSON.stringify(this.state[`statistic_options_${_position}_${index}`]) !== JSON.stringify(options)) { this.setState({ [`statistic_options_${_position}_${index}`]: options @@ -289,7 +293,7 @@ export default class HeaderStep extends Step { } } - render () { + render() { const props: IHeaderProps = {} if (this.props.config.breadcrumb && this.props.config.breadcrumb.enable) { diff --git a/src/util/enumeration.ts b/src/util/enumeration.ts index f56f413..9ded388 100644 --- a/src/util/enumeration.ts +++ b/src/util/enumeration.ts @@ -1,7 +1,9 @@ import { InterfaceConfig } from './interface' import { getValue } from './value' +import { ParamConfig } from '../interface' +import ParamHelper from './param' -export type EnumerationOptionsConfig = ManualEnumerationOptionsConfig | InterfaceEnumerationOptionsConfig +export type EnumerationOptionsConfig = ManualEnumerationOptionsConfig | InterfaceEnumerationOptionsConfig | DataEnumerationOptionsConfig interface ManualEnumerationOptionsConfig { from: 'manual' @@ -18,6 +20,14 @@ interface InterfaceEnumerationOptionsConfig { format?: InterfaceEnumerationOptionsKVConfig | InterfaceEnumerationOptionsListConfig } +interface DataEnumerationOptionsConfig { + from: 'data'; + sourceConfig?: ParamConfig; + format?: + | InterfaceEnumerationOptionsKVConfig + | InterfaceEnumerationOptionsListConfig; +} + export interface InterfaceEnumerationOptionsKVConfig { type: 'kv' } @@ -31,7 +41,18 @@ export interface InterfaceEnumerationOptionsListConfig { export default class EnumerationHelper { static _instance: EnumerationHelper - public async options (config: EnumerationOptionsConfig, interfaceRequire: (config: InterfaceConfig, source: any) => Promise) { + optionsDataValue = (sourceConfig: ParamConfig, datas: { record?: object, data: object[], step: number }) => { + if (sourceConfig !== undefined) { + return ParamHelper(sourceConfig, datas) + } + return undefined + } + + public async options( + config: EnumerationOptionsConfig, + interfaceRequire: (config: InterfaceConfig, source: any) => Promise, + datas: { record?: object, data: object[], step: number } + ) { if (config) { if (config.from === 'manual') { if (config.data) { @@ -63,15 +84,41 @@ export default class EnumerationHelper { } } } + } else if (config.from === 'data') { + if (config.sourceConfig && config.sourceConfig.source) { + const data = ParamHelper(config.sourceConfig, datas) + if (config.format) { + if (config.format.type === 'kv') { + return Object.keys(data).map((key) => ({ + value: key, + label: data[key] + })) + } else if (config.format.type === 'list') { + if (Array.isArray(data)) { + return data.map((item: any) => { + return { + value: getValue(item, (config.format as InterfaceEnumerationOptionsListConfig).keyField), + label: getValue(item, (config.format as InterfaceEnumerationOptionsListConfig).labelField) + } + }) + } + } + } + } + return [] } } return [] } - static async options (config: EnumerationOptionsConfig, interfaceRequire: (config: InterfaceConfig, source: any) => Promise) { + static async options( + config: EnumerationOptionsConfig, + interfaceRequire: (config: InterfaceConfig, source: any) => Promise, + datas: { record?: object, data: object[], step: number } + ) { if (!EnumerationHelper._instance) { EnumerationHelper._instance = new EnumerationHelper() } - return await EnumerationHelper._instance.options(config, interfaceRequire) + return await EnumerationHelper._instance.options(config, interfaceRequire, datas) } } -- Gitee From 3f66233f6215f9705224dc44242e43c7f67410d9 Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 14 Apr 2022 17:28:00 +0800 Subject: [PATCH 131/164] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/treeSelect/index.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 6095c81..5af5bde 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -59,20 +59,20 @@ export interface InterfaceOptionsListConfig { childrenField?: string } -export interface ISelectFieldOption { +export interface TreeSelectFieldOption { key: any value: any title: ReactNode - children?: Array + children?: Array } interface TreeSelectFieldState { - interfaceOptionsData: ISelectFieldOption[] + interfaceOptionsData: TreeSelectFieldOption[] } export interface ITreeSelectField { value?: any, - treeData: Array + treeData: Array titleColumn?: string onChange: (value: any) => Promise } @@ -101,10 +101,10 @@ export default class TreeSelectField extends Field { - const rsMenu: ISelectFieldOption[] = [] + const rsMenu: TreeSelectFieldOption[] = [] treeList.forEach((val: any) => { - const theMenu: ISelectFieldOption = { + const theMenu: TreeSelectFieldOption = { title: '', value: null, key: null -- Gitee From 9fd5389cf0162984ff4f95f8805dbc636e4ca28a Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Thu, 14 Apr 2022 17:39:51 +0800 Subject: [PATCH 132/164] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85diffCode?= =?UTF-8?q?=E9=98=BB=E6=AD=A2=E5=86=92=E6=B3=A1=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/diffCode/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/formFields/diffCode/index.tsx b/src/components/formFields/diffCode/index.tsx index eea5d6f..b497fc2 100644 --- a/src/components/formFields/diffCode/index.tsx +++ b/src/components/formFields/diffCode/index.tsx @@ -72,6 +72,7 @@ export default class DiffCodeField extends Field { + e.stopPropagation() const keyCode = e.keyCode || e.which || e.charCode const ctrlKey = e.ctrlKey || e.metaKey if (this.props.config.fullScreen) { -- Gitee From aeb85ae3bd4cf850cfa391bda39b7acb973f0f48 Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 14 Apr 2022 17:59:28 +0800 Subject: [PATCH 133/164] =?UTF-8?q?perf:=20=E6=A0=87=E6=98=8E=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/treeSelect/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 5af5bde..38d3e07 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -9,7 +9,7 @@ import { transformValueType } from '../../../util/value' type OptionsConfigDefaultValue = RecordParamConfig | DataParamConfig | StepParamConfig | SourceParamConfig export interface TreeSelectFieldConfig extends FieldConfig { type: 'tree_select' - mode?: 'tree' | 'table' + mode?: 'tree' | 'table' | 'treeSelect' multiple?: true | TreeSelectMultipleArrayConfig | TreeSelectMultipleSplitConfig, titleColumn?: string, treeData?: ManualOptionsConfig | InterfaceOptionsConfig | DataOptionsConfig @@ -212,7 +212,7 @@ export default class TreeSelectField extends Field { return - 您当前使用的UI版本没有实现TreeSelectSingleField组件的SelectSingle模式。 + 您当前使用的UI版本没有实现TreeSelectField组件的treeSelect模式。
-- Gitee From 52b6c15439168efd05aaf47473bc8f5b7c5aec88 Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 14 Apr 2022 18:33:00 +0800 Subject: [PATCH 134/164] =?UTF-8?q?perf:=20=E5=8E=BB=E6=8E=89any?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formFields/treeSelect/index.tsx | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 38d3e07..00874d0 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -37,7 +37,7 @@ export interface ManualOptionsConfig { } export interface treeTableDataConfig { - value: any + value: string | number title: string children: treeTableDataConfig[] } @@ -60,8 +60,8 @@ export interface InterfaceOptionsListConfig { } export interface TreeSelectFieldOption { - key: any - value: any + key?: string | number + value: string | number, title: ReactNode children?: Array } @@ -70,14 +70,16 @@ interface TreeSelectFieldState { interfaceOptionsData: TreeSelectFieldOption[] } +type TreeSelectValueType = string | Array | undefined + export interface ITreeSelectField { - value?: any, + value: TreeSelectValueType, treeData: Array titleColumn?: string - onChange: (value: any) => Promise + onChange: (value: TreeSelectValueType) => Promise } -export default class TreeSelectField extends Field | undefined> { +export default class TreeSelectField extends Field { interfaceHelper = new InterfaceHelper() interfaceOptionsConfig: string = '' @@ -85,7 +87,7 @@ export default class TreeSelectField extends Field | undefined>) { + constructor(props: FieldProps) { super(props) this.state = { @@ -100,14 +102,14 @@ export default class TreeSelectField extends Field { + formatTree = (treeList: Array, value: string, title: string, children: string) => { const rsMenu: TreeSelectFieldOption[] = [] - treeList.forEach((val: any) => { + treeList.forEach((val: TreeSelectFieldOption) => { const theMenu: TreeSelectFieldOption = { title: '', - value: null, - key: null + value: '', + key: '' } theMenu.title = get(val, title) @@ -192,7 +194,7 @@ export default class TreeSelectField extends Field | undefined): Promise => { + validate = async (_value: TreeSelectValueType): Promise => { const { config: { required @@ -255,7 +257,7 @@ export default class TreeSelectField extends Field | undefined) => { + onChange: async (value: TreeSelectValueType) => { let useV = value if (Array.isArray(useV) && multiple !== true && multiple?.type === 'split') { useV = useV.join(multiple.split || ',') @@ -295,7 +297,7 @@ export default class TreeSelectField extends Field await this.props.onValueSet('', value, await this.validate(value)) + onChange: async (value: TreeSelectValueType) => await this.props.onValueSet('', value, await this.validate(value)) })}
) -- Gitee From a343f8eed6b8019ecc580b15ac28d484b87990b5 Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 14 Apr 2022 21:55:45 +0800 Subject: [PATCH 135/164] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=A1=86=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formFields/treeSelect/index.tsx | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 00874d0..4ebb1bb 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -33,15 +33,14 @@ export interface DataOptionsConfig { export interface ManualOptionsConfig { from: 'manual' defaultIndex?: string | number - data?: treeTableDataConfig[] + data?: TreeSelectFieldOption[] } - -export interface treeTableDataConfig { +export interface TreeSelectFieldOption { + key: string | number value: string | number title: string - children: treeTableDataConfig[] + children?: Array } - export interface InterfaceOptionsConfig { from: 'interface' interface?: InterfaceConfig @@ -59,13 +58,6 @@ export interface InterfaceOptionsListConfig { childrenField?: string } -export interface TreeSelectFieldOption { - key?: string | number - value: string | number, - title: ReactNode - children?: Array -} - interface TreeSelectFieldState { interfaceOptionsData: TreeSelectFieldOption[] } @@ -102,7 +94,7 @@ export default class TreeSelectField extends Field, value: string, title: string, children: string) => { + formatTree = (treeList: TreeSelectFieldOption[], value: string, title: string, children: string) => { const rsMenu: TreeSelectFieldOption[] = [] treeList.forEach((val: TreeSelectFieldOption) => { @@ -294,11 +286,7 @@ export default class TreeSelectField extends Field - {this.renderComponent({ - value, - treeData: this.state.interfaceOptionsData, - onChange: async (value: TreeSelectValueType) => await this.props.onValueSet('', value, await this.validate(value)) - })} + {this.renderComponent(props)}
) } -- Gitee From 717a257d9ec197eccd3cfad3875915aa4aaa524e Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Fri, 15 Apr 2022 10:53:34 +0800 Subject: [PATCH 136/164] =?UTF-8?q?feat:=20detail=E3=80=81=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E9=A1=B9=E5=A2=9E=E5=8A=A0loadPageList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 2 ++ src/components/detail/group/index.tsx | 1 + src/components/detail/table/index.tsx | 2 ++ src/components/formFields/any/index.tsx | 3 +++ src/components/formFields/common.tsx | 2 ++ src/components/formFields/custom/index.tsx | 4 +++- src/components/formFields/form/index.tsx | 1 + src/components/formFields/group/index.tsx | 1 + src/components/formFields/importSubform/index.tsx | 1 + src/components/formFields/object/index.tsx | 1 + src/components/formFields/tabs/index.tsx | 1 + src/main.tsx | 4 ++-- src/steps/common.tsx | 4 ++-- src/steps/detail/index.tsx | 1 + src/steps/filter/index.tsx | 1 + src/steps/form/index.tsx | 1 + src/util/operation.tsx | 4 ++-- 17 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index b4e514f..0a36f6c 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -4,6 +4,7 @@ import { ColumnsConfig, ParamConfig } from '../../interface' import { DetailFieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { CCMSConfig } from '../../main' +import { TreeSelectFieldOption } from '../formFields/treeSelect' /** * 详情页表单项基类配置文件格式定义 @@ -93,6 +94,7 @@ export interface DetailFieldProps { baseRoute: string, loadDomain: (domain: string) => Promise loadPageConfig: (pageID: any) => Promise + loadPageList: () => Promise> handlePageRedirect: (path: string) => void checkPageAuth: (pageID: any) => Promise onUnmount: (reload?: boolean, data?: any) => Promise diff --git a/src/components/detail/group/index.tsx b/src/components/detail/group/index.tsx index 3858b55..c80378a 100644 --- a/src/components/detail/group/index.tsx +++ b/src/components/detail/group/index.tsx @@ -204,6 +204,7 @@ export default class GroupField extends DetailField Promise} loadPageFrameURL={this.props.loadPageFrameURL as (pageID: any) => Promise} loadPageConfig={this.props.loadPageConfig as (pageID: any) => Promise} + loadPageList={this.props.loadPageList} loadDomain={this.props.loadDomain} handlePageRedirect={this.props.handlePageRedirect} onMount={() => { diff --git a/src/components/formFields/any/index.tsx b/src/components/formFields/any/index.tsx index e93f34e..cfc7b75 100644 --- a/src/components/formFields/any/index.tsx +++ b/src/components/formFields/any/index.tsx @@ -97,6 +97,7 @@ export default class AnyField extends Field : ( type === 'number' ? {}} @@ -115,6 +116,7 @@ export default class AnyField extends Field : {}} form={this.props.form} @@ -132,6 +134,7 @@ export default class AnyField extends Field ) })} diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index cf36a02..84f5bc5 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -5,6 +5,7 @@ import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' +import { TreeSelectFieldOption } from './treeSelect' /** * 表单项基类配置文件格式定义 @@ -95,6 +96,7 @@ export interface FieldProps { onValueListSort: (path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => Promise baseRoute: string, loadDomain: (domain: string) => Promise + loadPageList: () => Promise> } /** diff --git a/src/components/formFields/custom/index.tsx b/src/components/formFields/custom/index.tsx index 492ef98..609bc7f 100644 --- a/src/components/formFields/custom/index.tsx +++ b/src/components/formFields/custom/index.tsx @@ -64,9 +64,10 @@ export default class CustomField extends Field imple onValueListSplice: this.props.onValueListSplice, base: this.props.baseRoute, loadDomain: this.props.loadDomain, + loadPageList: this.props.loadPageList, bindValidate: this.bindValidate, bindGet: this.bindGet - }); + }) } } } @@ -93,6 +94,7 @@ export default class CustomField extends Field imple onValueListSplice: this.props.onValueListSplice, base: this.props.baseRoute, loadDomain: this.props.loadDomain, + loadPageList: this.props.loadPageList, bindValidate: this.bindValidate, bindGet: this.bindGet } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 2c738f1..b92be82 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -540,6 +540,7 @@ export default class FormField extends Field await this.handleValueListSort(index, fieldIndex, path, _index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + loadPageList={async () => await this.props.loadPageList()} /> ) }) diff --git a/src/components/formFields/group/index.tsx b/src/components/formFields/group/index.tsx index 7bec8a1..d633fd7 100644 --- a/src/components/formFields/group/index.tsx +++ b/src/components/formFields/group/index.tsx @@ -375,6 +375,7 @@ export default class GroupField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + loadPageList={async () => await this.props.loadPageList()} /> ) } diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 5863faf..5a8c5dd 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -483,6 +483,7 @@ export default class ImportSubformField extends Field this.handleValueListSort(formFieldIndex, path, index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + loadPageList={async () => await this.props.loadPageList()} /> ) } diff --git a/src/components/formFields/object/index.tsx b/src/components/formFields/object/index.tsx index e3ddba5..5d8287b 100644 --- a/src/components/formFields/object/index.tsx +++ b/src/components/formFields/object/index.tsx @@ -479,6 +479,7 @@ export default class ObjectField extends Field this.handleValueListSort(key, formFieldIndex, path, _index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => this.props.loadDomain(domain)} + loadPageList={async () => await this.props.loadPageList()} /> ) }) diff --git a/src/components/formFields/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index 6525e9b..26fb9e3 100644 --- a/src/components/formFields/tabs/index.tsx +++ b/src/components/formFields/tabs/index.tsx @@ -439,6 +439,7 @@ export default class TabsField extends Field this.handleValueListSort(index, formFieldIndex, path, _index, sortType, validation, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + loadPageList={async () => await this.props.loadPageList()} /> ) })} diff --git a/src/main.tsx b/src/main.tsx index 1da690a..98b3b1b 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -3,7 +3,7 @@ import marked from 'marked' import Step, { StepProps } from './steps/common' import StepComponents, { StepConfigs } from './steps' import { RichStringConfig } from './interface' -import { ISelectFieldOption } from './components/formFields/treeSelect' +import { TreeSelectFieldOption } from './components/formFields/treeSelect' /** * 页面配置文件格式定义 @@ -47,7 +47,7 @@ export interface CCMSProps { loadPageURL: (pageID: any) => Promise loadPageFrameURL: (pageID: any) => Promise loadPageConfig: (pageID: any) => Promise - loadPageList: () => Promise> + loadPageList: () => Promise> loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string, replaceHistory: boolean) => void callback: (success: boolean) => void diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 8ed1a7b..9aab662 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -1,6 +1,6 @@ import React from 'react' import { CCMSConfig } from '../main' -import { ISelectFieldOption } from '../components/formFields/treeSelect' +import { TreeSelectFieldOption } from '../components/formFields/treeSelect' /** * 页面流转步骤基类配置定义 @@ -31,7 +31,7 @@ export interface StepProps { loadPageURL: (pageID: any) => Promise loadPageFrameURL: (pageID: any) => Promise loadPageConfig: (pageID: any) => Promise - loadPageList: () => Promise> + loadPageList: () => Promise> baseRoute: string loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string, replaceHistory: boolean) => void diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index 1e294d6..eec9fd1 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -384,6 +384,7 @@ export default class DetailStep extends Step { onUnmount={this.props.onUnmount} checkPageAuth={this.props.checkPageAuth} loadPageConfig={this.props.loadPageConfig} + loadPageList={this.props.loadPageList} loadPageURL={this.props.loadPageURL} loadPageFrameURL={this.props.loadPageFrameURL} handlePageRedirect={() => this.props.handlePageRedirect} diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 8d828f6..75630ec 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -508,6 +508,7 @@ export default class FilterStep extends Step { 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)} + loadPageList={async () => await this.props.loadPageList()} /> ) } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 421ed30..852a1d3 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -743,6 +743,7 @@ export default class FormStep extends Step { 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)} + loadPageList={async () => await this.props.loadPageList()} /> ) } diff --git a/src/util/operation.tsx b/src/util/operation.tsx index 30216c8..2b5181b 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -4,7 +4,7 @@ import { set } from "lodash"; import { ParamConfig } from "../interface"; import { CCMSConfig, CCMSProps } from "../main"; import { getParam } from "./value"; -import { ISelectFieldOption } from '../components/formFields/treeSelect' +import { TreeSelectFieldOption } from '../components/formFields/treeSelect' export type OperationConfig = CCMSOperationConfig @@ -57,7 +57,7 @@ interface OperationHelperProps { loadPageURL: (pageID: any) => Promise, loadPageFrameURL: (pageID: any) => Promise, loadPageConfig: (pageID: any) => Promise, - loadPageList: () => Promise>, + loadPageList: () => Promise>, baseRoute: string, loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string, replaceHistory: boolean) => void -- Gitee From 0634c3d9e409d213f803292bdf6d5afd598b3110 Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 15 Apr 2022 15:52:51 +0800 Subject: [PATCH 137/164] =?UTF-8?q?perf:=20=E5=85=BC=E5=AE=B9treeSelect?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/treeSelect/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/formFields/treeSelect/index.tsx b/src/components/formFields/treeSelect/index.tsx index 4ebb1bb..4f01e85 100644 --- a/src/components/formFields/treeSelect/index.tsx +++ b/src/components/formFields/treeSelect/index.tsx @@ -65,6 +65,7 @@ interface TreeSelectFieldState { type TreeSelectValueType = string | Array | undefined export interface ITreeSelectField { + multiple?: boolean value: TreeSelectValueType, treeData: Array titleColumn?: string @@ -275,7 +276,7 @@ export default class TreeSelectField extends Field {this.renderComponent(props)} -- Gitee From c9148eb8b30b10ea9f15b6e7d820516ba22ba8dc Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 15 Apr 2022 18:30:38 +0800 Subject: [PATCH 138/164] =?UTF-8?q?feat:=20=E8=A1=A8=E6=A0=BCDescriptionCo?= =?UTF-8?q?nfig=20=E5=86=85=E5=AE=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index fa0b40e..e08e9a7 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -71,6 +71,16 @@ export interface TableOperationDropdownConfig { operations: Array } +/** + * 表格步骤-操作配置文件下拉菜单 + */ +export interface TableOperationDropdownConfig { + type: 'dropdown' + label?: string + level?: 'normal' | 'primary' | 'danger' + operations: Array +} + /** * 表格步骤-操作配置文件格式 */ @@ -122,6 +132,12 @@ interface TableOperationConfirmConfig { cancelText: string } +export interface DescriptionConfig { + type: 'text' | 'tooltip' | 'modal' + label: string | undefined + content: React.ReactNode + showIcon: boolean +} /** * 表格步骤组件 - UI渲染方法 - 入参 * - data: 数据 @@ -139,14 +155,9 @@ export interface ITable { onChange: (page: number, pageSize: number) => void } tableOperations: React.ReactNode | null - multirowOperations: React.ReactNode | null, - description?: { - type: 'text' | 'tooltip' | 'modal' - label: string | undefined - content: React.ReactNode - showIcon: boolean - }, leftTableOperations: React.ReactNode | null + multirowOperations: React.ReactNode | null, + description?: DescriptionConfig } /** @@ -546,6 +557,7 @@ export default class TableStep extends Step { 您当前使用的UI版本没有实现Table组件的OperationDropdownItem部分。
} + renderOperationModal = (props: ITableStepOperationModal) => { const mask = document.createElement('DIV') mask.style.position = 'fixed' -- Gitee From 874ddfef764481498d8e684d1b3dee0d5015b2e7 Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 15 Apr 2022 18:34:42 +0800 Subject: [PATCH 139/164] fix: del align --- src/steps/table/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 08fe85e..b8ad46e 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -59,7 +59,6 @@ export interface TableOperationGroupConfig { label?: string level?: 'normal' | 'primary' | 'danger' operations: Array - align: 'left' | 'right' } /** @@ -85,7 +84,6 @@ export interface TableOperationConfig { condition?: ConditionConfig modalWidthMode?: 'none' | 'percentage' | 'pixel' modalWidthValue?: string | number - align: 'left' | 'right' } export interface TableCCMSOperationConfig { @@ -181,7 +179,6 @@ export interface ITableStepTableOperation { export interface ITableStepRowOperationButton { label: string level: 'normal' | 'primary' | 'danger' - align: 'left' | 'right' disabled?: boolean onClick: () => Promise } @@ -191,8 +188,7 @@ export interface ITableStepRowOperationButton { */ export interface ITableStepRowOperationGroup { label?: string - children: React.ReactNode[] - align: 'left' | 'right' + children: React.ReactNode[] } /** -- Gitee From 57081599bb43c3ccfaa91f4ce81d6a68893c8831 Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 15 Apr 2022 18:35:53 +0800 Subject: [PATCH 140/164] fix: align --- src/steps/table/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index b8ad46e..fa0b40e 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -188,7 +188,7 @@ export interface ITableStepRowOperationButton { */ export interface ITableStepRowOperationGroup { label?: string - children: React.ReactNode[] + children: React.ReactNode[] } /** @@ -808,7 +808,6 @@ export default class TableStep extends Step { : this.renderRowOperationButtonComponent({ label: operation.label, level: operation.level || 'normal', - align: operation.align, onClick: async () => { await this.handleRowOperation(operation, record) } })}
@@ -818,7 +817,6 @@ export default class TableStep extends Step { {this.renderRowOperationDropdownComponent({ label: operation.label, - align: operation.align, children: (operation.operations || []).map((operation) => { if (!ConditionHelper(operation.condition, { record, data, step })) { return null -- Gitee From f78a35c6b3d4e8919cc90291e34a1066582d096a Mon Sep 17 00:00:00 2001 From: wangailin Date: Fri, 15 Apr 2022 18:40:00 +0800 Subject: [PATCH 141/164] =?UTF-8?q?perf:=20=E4=BF=AE=E5=A4=8D=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=87=8D=E5=A4=8D=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/detail/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index 5e96082..16bbef6 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -401,7 +401,6 @@ export default class DetailStep extends Step { detail={this} step={step} config={detailFieldConfig} - detail={this} onChange={async (value: any) => { await this.handleChange(detailFieldIndex, value) }} onValueSet={async (path, value) => await this.handleValueSet(detailFieldIndex, path, value)} onValueUnset={async (path) => await this.handleValueUnset(detailFieldIndex, path)} -- Gitee From b6397503e46a6f2d950ba9346eee2af63ad5e4b5 Mon Sep 17 00:00:00 2001 From: wangailin Date: Tue, 19 Apr 2022 15:01:13 +0800 Subject: [PATCH 142/164] feat: create 1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a420bb7..aa50851 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccms", - "version": "1.2.4", + "version": "1.3.0", "description": "ConfigableCMS", "main": "lib/index.js", "module": "dist/index.js", -- Gitee From 4c42a15d5a18809d2369079673767a839405ed6b Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Tue, 19 Apr 2022 18:01:49 +0800 Subject: [PATCH 143/164] =?UTF-8?q?fix:=20=E7=BB=93=E5=90=88noPathCombinat?= =?UTF-8?q?ion=E4=BF=AE=E6=94=B9=E8=A1=A8=E5=8D=95=E9=A1=B9form=E4=B8=8Bdi?= =?UTF-8?q?splay=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/form/display.tsx | 100 ++++----------------- 1 file changed, 19 insertions(+), 81 deletions(-) diff --git a/src/components/formFields/form/display.tsx b/src/components/formFields/form/display.tsx index f6a861a..0999d80 100644 --- a/src/components/formFields/form/display.tsx +++ b/src/components/formFields/form/display.tsx @@ -1,7 +1,7 @@ import React from 'react' import { display as getALLComponents } from '../' import { FormFieldConfig } from '.' -import { Display, FieldConfigs, FieldError, FieldProps } from '../common' +import { Display, FieldConfigs, DisplayProps } from '../common' import { getValue, setValue } from '../../../util/value' import { cloneDeep } from 'lodash' import ConditionHelper from '../../../util/condition' @@ -27,7 +27,6 @@ export interface IFormFieldItemField { interface FormState { didMount: boolean - formDataList: { status: 'normal' | 'error' | 'loading', message?: string }[][] showItem: boolean showIndex: number } @@ -38,12 +37,11 @@ export default class FormField extends Display | null>> = [] formFieldsMountedList: Array> = [] - constructor (props: FieldProps) { + constructor (props: DisplayProps) { super(props) this.state = { didMount: false, - formDataList: [], showItem: false, showIndex: 0 } @@ -116,9 +114,6 @@ export default class FormField extends Display { + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - await this.props.onValueSet(`[${index}]${fullPath}`, value, 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 - }) + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + await this.props.onValueSet(`[${index}]${fullPath}`, value) } } - handleValueUnset = async (index: number, formFieldIndex: number, path: string, validation: true | FieldError[]) => { + handleValueUnset = async (index: number, formFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - await this.props.onValueUnset(`[${index}]${fullPath}`, 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 - }) + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + await this.props.onValueUnset(`[${index}]${fullPath}`) } } - handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - await this.props.onValueListAppend(`[${index}]${fullPath}`, value, 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 - }) + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + await this.props.onValueListAppend(`[${index}]${fullPath}`, value) } } - handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, validation: true | FieldError[]) => { + handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - await this.props.onValueListSplice(`[${index}]${fullPath}`, _index, count, 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 - }) + const fullPath = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + await this.props.onValueListSplice(`[${index}]${fullPath}`, _index, count) } } @@ -289,11 +232,6 @@ export default class FormField extends Display type === formFieldConfig.type)) { - status = 'normal' - } // 渲染表单项容器 return (
@@ -316,10 +254,10 @@ export default class FormField extends Display 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)} + onValueSet={async (path, value, options) => this.handleValueSet(index, fieldIndex, path, value, options)} + onValueUnset={async (path, options) => this.handleValueUnset(index, fieldIndex, path, options)} + onValueListAppend={async (path, value, options) => this.handleValueListAppend(index, fieldIndex, path, value, options)} + onValueListSplice={async (path, _index, count, options) => this.handleValueListSplice(index, fieldIndex, path, _index, count, options)} baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> -- Gitee From 53e4689253c99218b2fe3b5b7b90503ef659b6e7 Mon Sep 17 00:00:00 2001 From: zjt Date: Tue, 19 Apr 2022 20:26:14 +0800 Subject: [PATCH 144/164] =?UTF-8?q?fix:=20=E7=BB=93=E5=90=88noPathCombinat?= =?UTF-8?q?ion=E4=BF=AE=E6=94=B9display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/group/display.tsx | 218 ++++------ .../formFields/importSubform/display.tsx | 18 +- src/components/formFields/tabs/display.tsx | 379 +++++++----------- 3 files changed, 235 insertions(+), 380 deletions(-) diff --git a/src/components/formFields/group/display.tsx b/src/components/formFields/group/display.tsx index fc9a131..48f71a3 100644 --- a/src/components/formFields/group/display.tsx +++ b/src/components/formFields/group/display.tsx @@ -2,7 +2,7 @@ import React from 'react' import { display as getALLComponents, FieldConfigs } from '../' import { GroupFieldConfig, IGroupField } from '.' import { setValue, getValue, getBoolean } from '../../../util/value' -import { Display, FieldError, FieldProps } from '../common' +import { Display, DisplayProps } from '../common' import { IFormItem } from '../../../steps/form' import { cloneDeep } from 'lodash' import ConditionHelper from '../../../util/condition' @@ -10,7 +10,6 @@ import StatementHelper from '../../../util/statement' interface IGroupFieldState { didMount: boolean - formData: { status: 'normal' | 'error' | 'loading', message?: string, name?: string }[] } export default class GroupField extends Display { @@ -20,12 +19,11 @@ export default class GroupField extends Display | null> = [] formFieldsMounted: Array = [] - constructor (props: FieldProps) { + constructor(props: DisplayProps) { super(props) this.state = { - didMount: false, - formData: [] + didMount: false } } @@ -72,105 +70,43 @@ export default class GroupField extends Display { - formData[formFieldIndex] = { status: 'normal', name: formFieldConfig.label } - return { formData: cloneDeep(formData) } - }) - } await formField.didMount() } } } - handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueSet = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = 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) { - formData[formFieldIndex] = { status: 'normal' } - } else { - formData[formFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - formData - }) + const fullPath = options && options.noPathCombination ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueSet(fullPath, value) } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[]) => { + handleValueUnset = async (formFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` - await this.props.onValueUnset(fullPath, 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 - }) - } - } - - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { - const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] - if (formFieldConfig) { - const fullPath = 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) { - formData[formFieldIndex] = { status: 'normal' } - } else { - formData[formFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - formData - }) + const fullPath = options && options.noPathCombination ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueUnset(fullPath) } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[]) => { + handleValueListAppend = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = 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) { - formData[formFieldIndex] = { status: 'normal' } - } else { - formData[formFieldIndex] = { status: 'error', message: validation[0].message } - } - - this.setState({ - formData - }) + const fullPath = options && options.noPathCombination ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListAppend(fullPath, value) } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { + handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - 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 - }) + const fullPath = options && options.noPathCombination ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` + await this.props.onValueListSplice(fullPath, index, count) } } @@ -204,71 +140,65 @@ export default class GroupField extends Display { - if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { - this.formFieldsMounted[formFieldIndex] = false - return null - } - let hidden: boolean = true - let display: boolean = true - - if (formFieldConfig.type === 'hidden') { - hidden = true - display = false - } - - if (formFieldConfig.display === 'none') { - hidden = true - display = false - } - - const FormField = this.getALLComponents(formFieldConfig.type) || Display - - let status = (this.state.formData[formFieldIndex] || {}).status || 'normal' - - if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { - status = 'normal' - } - - const renderData = { - key: formFieldIndex, - label: formFieldConfig.label, - status, - layout: 'horizontal' as 'horizontal', - message: (this.state.formData[formFieldIndex] || {}).message || '', - extra: StatementHelper(formFieldConfig.extra, { record: this.props.record, data: this.props.data, step: this.props.step }), - required: getBoolean(formFieldConfig.required), - visitable: display, - fieldType: formFieldConfig.type, - children: ( - | null) => { - if (formField) { - this.formFields[formFieldIndex] = formField - this.handleMount(formFieldIndex) - } - }} - value={getValue(value, formFieldConfig.field)} - record={record} - data={cloneDeep(data)} - step={step} - config={formFieldConfig} - 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)} - baseRoute={this.props.baseRoute} - loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - /> - ) - } - // 渲染表单项容器 - return ( - hidden - ? this.renderItemComponent(renderData) - : + if (!ConditionHelper(formFieldConfig.condition, { record: value, data: this.props.data, step: this.props.step })) { + this.formFieldsMounted[formFieldIndex] = false + return null + } + let hidden: boolean = true + let display: boolean = true + + if (formFieldConfig.type === 'hidden') { + hidden = true + display = false + } + + if (formFieldConfig.display === 'none') { + hidden = true + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Display + + let status: 'normal' = 'normal' + const renderData = { + key: formFieldIndex, + label: formFieldConfig.label, + status, + layout: 'horizontal' as 'horizontal', + extra: StatementHelper(formFieldConfig.extra, { record: this.props.record, data: this.props.data, step: this.props.step }), + required: getBoolean(formFieldConfig.required), + visitable: display, + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (formField) { + this.formFields[formFieldIndex] = formField + this.handleMount(formFieldIndex) + } + }} + value={getValue(value, formFieldConfig.field)} + record={record} + data={cloneDeep(data)} + step={step} + config={formFieldConfig} + 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)} + /> ) - }) + } + // 渲染表单项容器 + return ( + hidden + ? this.renderItemComponent(renderData) + : + ) + }) : [] })} diff --git a/src/components/formFields/importSubform/display.tsx b/src/components/formFields/importSubform/display.tsx index 98e797e..52b90e5 100644 --- a/src/components/formFields/importSubform/display.tsx +++ b/src/components/formFields/importSubform/display.tsx @@ -54,7 +54,7 @@ export default class ImportSubformFieldDisplay extends DetailField) { + constructor(props: DetailFieldProps) { super(props) this.state = { @@ -65,7 +65,7 @@ export default class ImportSubformFieldDisplay extends DetailField { + getConfigData = () => { const { config, value @@ -148,7 +148,7 @@ export default class ImportSubformFieldDisplay extends DetailField { + didMount: boolean + extra?: S +} export default class TabsField extends Display> { - // 各表单项对应的类型所使用的UI组件的类 - getALLComponents = (type: any): typeof Display => getALLComponents[type] + // 各表单项对应的类型所使用的UI组件的类 + getALLComponents = (type: any): typeof Display => getALLComponents[type] - formFieldsList: Array | null>> = [] - formFieldsMountedList: Array> = [] + formFieldsList: Array | null>> = [] + formFieldsMountedList: Array> = [] - constructor (props: DisplayProps) { - super(props) + constructor(props: DisplayProps) { + super(props) - this.state = { - didMount: false, - formDataList: [] - } - } + this.state = { + didMount: false + } + } + + didMount = async () => { + await this.setState({ + didMount: true + }) + } - didMount = async () => { - await this.setState({ - didMount: true - }) + get = async () => { + let data: any = {} + + for (let index = 0; index < (this.props.config.tabs || []).length; index++) { + const tab = (this.props.config.tabs || [])[index] + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + + for (let formFieldIndex = 0; formFieldIndex < fields.length; formFieldIndex++) { + const formFieldConfig = fields[formFieldIndex] + if (!ConditionHelper(formFieldConfig.condition, { record: getValue(this.props.value, tab.field), data: this.props.data, step: this.props.step })) { + continue + } + const formField = this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex] + if (formField) { + const value = await formField.get() + const fullPath = tab.field === '' || formFieldConfig.field === '' ? `${tab.field}${formFieldConfig.field}` : `${tab.field}.${formFieldConfig.field}` + data = setValue(data, fullPath, value) + } + } } - get = async () => { - let data: any = {} - - for (let index = 0; index < (this.props.config.tabs || []).length; index++) { - const tab = (this.props.config.tabs || [])[index] - const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) - - for (let formFieldIndex = 0; formFieldIndex < fields.length; formFieldIndex++) { - const formFieldConfig = fields[formFieldIndex] - if (!ConditionHelper(formFieldConfig.condition, { record: getValue(this.props.value, tab.field), data: this.props.data, step: this.props.step })) { - continue - } - const formField = this.formFieldsList[index] && this.formFieldsList[index][formFieldIndex] - if (formField) { - const value = await formField.get() - const fullPath = tab.field === '' || formFieldConfig.field === '' ? `${tab.field}${formFieldConfig.field}` : `${tab.field}.${formFieldConfig.field}` - data = setValue(data, fullPath, value) - } - } - } - - return data - } + return data + } handleMount = async (index: number, formFieldIndex: number) => { if (!this.formFieldsMountedList[index]) { @@ -100,16 +103,9 @@ export default class TabsField extends Display { - if (!formDataList[index]) formDataList[index] = [] - formDataList[index][formFieldIndex] = { status: 'normal' } - return { formDataList: cloneDeep(formDataList) } - }) - } await formField.didMount() } } @@ -118,152 +114,86 @@ export default class TabsField extends Display { } - handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueSet = async (index: number, formFieldIndex: number, path: string, value: any, 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 ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` - await this.props.onValueSet(fullPath, value, 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 - }) + await this.props.onValueSet(fullPath, value) } } - handleValueUnset = async (index: number, formFieldIndex: number, path: string, validation: true | FieldError[]) => { + handleValueUnset = async (index: number, formFieldIndex: number, path: string, 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 ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` - await this.props.onValueUnset(fullPath, 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 - }) + await this.props.onValueUnset(fullPath) } } - handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, validation: true | FieldError[]) => { + handleValueListAppend = async (index: number, formFieldIndex: number, path: string, value: any, 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 ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}` const fullPath = tab.field === '' || fieldPath === '' ? `${tab.field}${fieldPath}` : `${tab.field}.${fieldPath}` - await this.props.onValueListAppend(fullPath, value, 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 - }) + await this.props.onValueListAppend(fullPath, value) } } - handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, validation: true | FieldError[]) => { + handleValueListSplice = async (index: number, formFieldIndex: number, path: string, _index: number, count: number, 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 ? `${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) - - 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 - }) + await this.props.onValueListSplice(fullPath, _index, count) } } - handleValueListSort = async (index: number, formFieldIndex: number, path: string, _index: number, sortType: 'up' | 'down', validation: true | FieldError[]) => { - const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) - const formFieldConfig = fields[formFieldIndex] - if (formFieldConfig) { - 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 - }) - } - } - - /** - * 用于展示子表单组件 - * @param _props - * @returns - */ - renderComponent = (_props: ITabsField) => { - return + /** + * 用于展示子表单组件 + * @param _props + * @returns + */ + renderComponent = (_props: ITabsField) => { + return 您当前使用的UI版本没有实现FormField组件。 - } - - /** - * 用于展示子表单组件中的每一个子项 - * @param props - * @returns - */ - renderItemComponent = (props: ITabsFieldItem) => { - return + } + + /** + * 用于展示子表单组件中的每一个子项 + * @param props + * @returns + */ + renderItemComponent = (props: ITabsFieldItem) => { + return 您当前使用的UI版本没有实现FormField组件的renderItemComponent方法。 - } - - /** - * 用于展示子表单组件中的每一子项中的每一个子表单项组件 - * @param props - * @returns - */ - renderItemFieldComponent = (props: ITabsFieldItemField) => { - return + } + + /** + * 用于展示子表单组件中的每一子项中的每一个子表单项组件 + * @param props + * @returns + */ + renderItemFieldComponent = (props: ITabsFieldItemField) => { + return 您当前使用的UI版本没有实现FormField组件的renderItemFieldComponent方法。 - } + } render = () => { const { @@ -277,81 +207,76 @@ export default class TabsField extends Display { - const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) - return ( - - {this.renderItemComponent({ - key: index.toString(), - label: tab.label, - children: fields.map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { - if (!this.formFieldsMountedList[index]) this.formFieldsMountedList[index] = [] - this.formFieldsMountedList[index][formFieldIndex] = false - return null - } - let hidden: boolean = true - let display: boolean = true - - if (formFieldConfig.type === 'hidden') { - hidden = true - display = false - } - - if (formFieldConfig.display === 'none') { - hidden = true - display = false - } - - const FormField = this.getALLComponents(formFieldConfig.type) || Display - - let status = ((this.state.formDataList[index] || [])[formFieldIndex] || {}).status || 'normal' - - if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { - status = 'normal' - } - // 渲染表单项容器 - if (hidden) { - return ( -
- {this.renderItemFieldComponent({ - index: formFieldIndex, - label: formFieldConfig.label, - status, - message: ((this.state.formDataList[index] || [])[formFieldIndex] || {}).message || '', - required: getBoolean(formFieldConfig.required), - fieldType: formFieldConfig.type, - children: ( - | null) => { - if (!this.formFieldsList[index]) this.formFieldsList[index] = [] - this.formFieldsList[index][formFieldIndex] = formField - this.handleMount(index, formFieldIndex) - }} - value={getValue(getValue(value, tab.field), formFieldConfig.field)} - record={getValue(value, tab.field)} - data={cloneDeep(this.props.data)} - step={this.props.step} - config={formFieldConfig} - 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)} - baseRoute={this.props.baseRoute} - loadDomain={async (domain: string) => await this.props.loadDomain(domain)} - /> - ) - })} -
- ) - } else { - return - } - }) - })} - - ) - }) + const fields = this.props.config.mode === 'same' ? (this.props.config.fields || []) : (((this.props.config.tabs || [])[index] || {}).fields || []) + return ( + + {this.renderItemComponent({ + key: index.toString(), + label: tab.label, + children: fields.map((formFieldConfig, formFieldIndex) => { + if (!ConditionHelper(formFieldConfig.condition, { record: this.props.record, data: this.props.data, step: this.props.step })) { + if (!this.formFieldsMountedList[index]) this.formFieldsMountedList[index] = [] + this.formFieldsMountedList[index][formFieldIndex] = false + return null + } + let hidden: boolean = true + let display: boolean = true + + if (formFieldConfig.type === 'hidden') { + hidden = true + display = false + } + + if (formFieldConfig.display === 'none') { + hidden = true + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Display + + let status: 'normal' = 'normal' + // 渲染表单项容器 + if (hidden) { + return ( +
+ {this.renderItemFieldComponent({ + index: formFieldIndex, + label: formFieldConfig.label, + status, + required: getBoolean(formFieldConfig.required), + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (!this.formFieldsList[index]) this.formFieldsList[index] = [] + this.formFieldsList[index][formFieldIndex] = formField + this.handleMount(index, formFieldIndex) + }} + value={getValue(getValue(value, tab.field), formFieldConfig.field)} + record={getValue(value, tab.field)} + data={cloneDeep(this.props.data)} + step={this.props.step} + config={formFieldConfig} + 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)} + baseRoute={this.props.baseRoute} + loadDomain={async (domain: string) => await this.props.loadDomain(domain)} + /> + ) + })} +
+ ) + } else { + return + } + }) + })} + + ) + }) : [] ) }) -- Gitee From 7b651ceaf28542fc992c34a1154bf1a8d5cd9a15 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Wed, 20 Apr 2022 16:29:32 +0800 Subject: [PATCH 145/164] =?UTF-8?q?chore:=20=E5=8E=BB=E6=8E=89=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84step=E4=B8=BAnumber=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 1 - src/components/formFields/common.tsx | 2 -- src/components/formFields/form/index.tsx | 1 - src/components/formFields/importSubform/index.tsx | 1 - src/main.tsx | 3 +-- src/steps/common.tsx | 1 - src/steps/detail/index.tsx | 1 - src/steps/filter/index.tsx | 1 - src/steps/form/index.tsx | 1 - 9 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 89d5cea..81eed86 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -77,7 +77,6 @@ export interface DetailFieldProps { record: { [field: string]: any }, data: any[], step: { [field: string]: any } // formValue挂载 - // step: number, config: C // 挂载引用 detail?: React.ReactNode diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 9cab734..c6118a3 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -81,7 +81,6 @@ export interface FieldProps { value: T, record: { [field: string]: any }, data: any[], - // step: number, config: C // TODO 待删除 onChange: (value: T) => Promise @@ -230,7 +229,6 @@ export interface DisplayProps { value: T, record: { [field: string]: any }, data: any[], - // step: number, step: { [field: string]: any } config: C, // 事件:设置值 diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 54e8ffe..cbf19b9 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -510,7 +510,6 @@ export default class FormField extends Field this.handleChange(index, fieldIndex, value)} onValueSet={async (path, value, validation, options) => this.handleValueSet(index, fieldIndex, path, value, validation, options)} diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index 705331b..e16aa67 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -444,7 +444,6 @@ export default class ImportSubformField extends Field { await this.handleChange(formFieldIndex, value) }} onValueSet={async (path, value, validation, options) => this.handleValueSet(formFieldIndex, path, value, validation, options)} diff --git a/src/main.tsx b/src/main.tsx index 091380d..9097913 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -67,7 +67,7 @@ export interface CCMSState { /** * 页面组件 */ -export default class CCMS1 extends React.Component { +export default class CCMS extends React.Component { getStepComponent = (key: string) => StepComponents[key] /** @@ -265,7 +265,6 @@ export default class CCMS1 extends React.Component { const props: StepProps = { ref: (e) => { this.steps[index] = e }, data, - // step: index, step: data[index], onSubmit: (data: any, unmountView: boolean = true) => this.handleSubmit(index, data, unmountView), onMount: () => this.handleMount(index), diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 0339d19..a9a0d61 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -21,7 +21,6 @@ export interface StepProps { ref: (instance: Step | null) => void data: any[] step: {[field: string]: any} - // step: number config: C onChange?: (data: any) => Promise onSubmit: (data: any, unmountView?: boolean) => Promise diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index b345fe4..7545e8b 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -398,7 +398,6 @@ export default class DetailStep extends Step { value={detailFieldConfig.field !== undefined ? getValue(detailValue, detailFieldConfig.field) || detailFieldConfig.defaultValue : undefined} record={detailValue} step={cloneDeep(detailValue)} - // step={step} data={cloneDeep(data)} detail={this} config={detailFieldConfig} diff --git a/src/steps/filter/index.tsx b/src/steps/filter/index.tsx index 12749d4..e6aad5e 100644 --- a/src/steps/filter/index.tsx +++ b/src/steps/filter/index.tsx @@ -496,7 +496,6 @@ export default class FilterStep extends Step { value={formFieldConfig.field !== undefined ? get(formValue, formFieldConfig.field) : undefined} record={formValue} step={formValue} - // step={step} data={data} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index 1ea6772..45d0e85 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -728,7 +728,6 @@ export default class FormStep extends Step { // ts对clas record={formValue} form={this} data={data} - // step={step} step={formValue} config={formFieldConfig} onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} -- Gitee From 49b62433a87d31b33be8c335208dafc9c44c8a20 Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 20 Apr 2022 18:02:47 +0800 Subject: [PATCH 146/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c2edd2d..3fe0b54 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,13 @@ } }, "lint-staged": { - "src/*.{js, jsx, ts, tsx}": [ - "npm run prettier", - "npm run lint" + "*.{js,jsx,ts,tsx}": [ + "eslint --fix", + "git add" ], - "src/*.{css,scss,less,json,html,md,markdown}": [ - "npm run prettier" + "*.{json,html,md,markdown}": [ + "prettier --write", + "git add -f" ] }, "config": { -- Gitee From 69c128c1ae239b56246768b82ca67c89b336cd3a Mon Sep 17 00:00:00 2001 From: zjt Date: Wed, 20 Apr 2022 21:05:34 +0800 Subject: [PATCH 147/164] =?UTF-8?q?fix:=20=E5=90=88=E5=B9=B6v1.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/util/produce.tsx | 27 +++++++++++++++------------ src/util/value.ts | 4 ++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 3fe0b54..e647667 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "@types/react": "^16.9.46", "@types/react-router-dom": "^5.1.5", "axios": "^0.20.0", + "immer": "^9.0.7", "lodash": "^4.17.21", "marked": "^1.2.5", "moment": "^2.29.0", diff --git a/src/util/produce.tsx b/src/util/produce.tsx index 2d97d10..60b9ff1 100644 --- a/src/util/produce.tsx +++ b/src/util/produce.tsx @@ -1,7 +1,6 @@ import produce, { setAutoFreeze } from 'immer' import lodash from 'lodash' -import { listItemMove } from '../util/value' - +import { listItemMove } from './value' /** * setAutoFreeze @@ -21,7 +20,8 @@ setAutoFreeze(false) export function set(current: any, path?: string, value?: any) { const target = produce(current, (draft: any) => { if (path) { - if (arguments.length === 2) { // 移除对象路径的属性 参数改动时同步修改这块 + if (arguments.length === 2) { + // 移除对象路径的属性 参数改动时同步修改这块 lodash.unset(draft, path) } else { return lodash.set(draft, path, value) @@ -38,11 +38,12 @@ export function set(current: any, path?: string, value?: any) { * @param value * @returns */ -export const push = (current: any, path: string = '', value?: any) => { +export const push = (current: any, path = '', value?: any) => { const target = produce(current, (draft: any) => { const list = lodash.get(draft, path) - if (!Array.isArray(list)) { // 如果指定路径下不是数组类型 - var tempArr = [] + if (!Array.isArray(list)) { + // 如果指定路径下不是数组类型 + const tempArr: any[] = [] tempArr.push(value) lodash.set(draft, path, tempArr) } else { @@ -60,7 +61,7 @@ export const push = (current: any, path: string = '', value?: any) => { * @param count * @returns */ -export const splice = (current: any, path: string = '', index: number, count: number) => { +export const splice = (current: any, path = '', index: number, count: number) => { const target = produce(current, (draft: any) => { const list = lodash.get(draft, path, []) list.splice(index, count) @@ -76,7 +77,7 @@ export const splice = (current: any, path: string = '', index: number, count: nu * @param sortType * @returns */ -export const sort = (current: any, path: string = '', index: number, sortType: 'up' | 'down') => { +export const sort = (current: any, path = '', index: number, sortType: 'up' | 'down') => { const target = produce(current, (draft: any) => { const list = lodash.get(draft, path, []) listItemMove(list, index, sortType) @@ -98,14 +99,13 @@ const merge = (a: any, b: any): any => { if (lodash.isObject(b)) { if (lodash.isArray(a)) { return merge(a, b).filter((i: any) => i !== undefined) - } else { - return merge(a, b) } + return merge(a, b) } }) } -export const setValue = (obj: any, path: string = '', value: any) => { +export const setValue = (obj: any, path = '', value: any) => { const target = produce(obj, (draft: any) => { if (path === '') { if (Object.prototype.toString.call(value) === '[object Object]') { @@ -115,7 +115,10 @@ export const setValue = (obj: any, path: string = '', value: any) => { } } else { const source = lodash.get(draft, path) - if (Object.prototype.toString.call(value) === '[object Object]' && Object.prototype.toString.call(source) === '[object Object]') { + if ( + Object.prototype.toString.call(value) === '[object Object]' && + Object.prototype.toString.call(source) === '[object Object]' + ) { lodash.set(draft, path, merge(source, value)) } else { lodash.set(draft, path, value) diff --git a/src/util/value.ts b/src/util/value.ts index 6a2eef4..6cf1f15 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -134,8 +134,8 @@ export const getChainPath = (...arg: any[]) => { * @param find 目标字符串 * @returns 返回目标字符串出现在来源字符串中所有索引 */ -function indexes (source: string, find: string) { - const result = [] +function indexes(source: string, find: string) { + const result: number[] = [] for (let i = 0; i < source.length; ++i) { if (source.substring(i, i + find.length) === find) { result.push(i) -- Gitee From ae027fcd1ad6e334fe66384f6d6d31f81c3c46e1 Mon Sep 17 00:00:00 2001 From: zhenjintao Date: Thu, 21 Apr 2022 10:47:10 +0800 Subject: [PATCH 148/164] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E5=AF=B9packa?= =?UTF-8?q?ge-lock.json=E7=9A=84=E5=BF=BD=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index acebde4..4c4d10b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ node_modules dist lib coverage -package-lock.json \ No newline at end of file -- Gitee From 424e71756fd5d5903e6963c9e6552fce9cbb639d Mon Sep 17 00:00:00 2001 From: zjt Date: Thu, 21 Apr 2022 16:17:43 +0800 Subject: [PATCH 149/164] =?UTF-8?q?doc:=20=E5=BF=BD=E7=95=A5package-lock.j?= =?UTF-8?q?son?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c4d10b..b3f0ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules dist lib coverage +package-lock.json -- Gitee From de2b6241a7fd63fe2a86a9eab36b406f2d09af9c Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 22 Apr 2022 12:36:41 +0800 Subject: [PATCH 150/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9render?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 257 +++++++++++------- 1 file changed, 166 insertions(+), 91 deletions(-) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 0832aa3..46d3a30 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -1,11 +1,11 @@ import React from 'react' -import { getValue , getChainPath} from '../../../util/value' +import { cloneDeep, isEqual } from 'lodash' +import { getValue, getChainPath } from '../../../util/value' import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../common' import { Display } from '../../formFields/common' import { display as getALLComponents, FieldConfigs } from '../../formFields' import { IDetailItem } from '../../../steps/detail' -import { cloneDeep, isEqual } from 'lodash' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' import { ColumnsConfig } from '../../../interface' @@ -19,7 +19,7 @@ import { ColumnsConfig } from '../../../interface' * - * - interface: 来源接口配置 // 仅type为interface时生效 */ export interface ImportSubformFieldConfig extends DetailFieldConfig { - type: 'import_subform', + type: 'import_subform' configFrom?: ImportSubformConfigFromData | ImportSubformConfigFromInterface childColumns?: ColumnsConfig } @@ -43,23 +43,28 @@ export interface IImportSubformField { interface IImportSubformFieldState { didMount: boolean fields: FieldConfigs[] - formData: { status: 'normal' | 'error' | 'loading', message?: string }[] + formData: { status: 'normal' | 'error' | 'loading'; message?: string }[] } -export default class DetailImportSubformField extends DetailField implements IDetailField { +export default class DetailImportSubformField + extends DetailField + implements IDetailField +{ // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Display => getALLComponents[type] // 用于请求防频的判断条件 - requestConfig: string = '' - value: string = '' + requestConfig = '' + + value = '' formFields: Array | null> = [] + formFieldsMounted: Array = [] interfaceHelper = new InterfaceHelper() - constructor (props: DetailFieldProps) { + constructor(props: DetailFieldProps) { super(props) this.state = { @@ -69,8 +74,6 @@ export default class DetailImportSubformField extends DetailField { await this.setState({ didMount: true @@ -86,11 +89,14 @@ export default class DetailImportSubformField extends DetailField { - const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' + handleValueSet = async ( + formFieldIndex: number, + path: string, + value: any, + options?: { noPathCombination?: boolean } + ) => { + const withConfigPath = + this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField + ? `${this.props.config.configFrom.dataField}` + : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueSet(fullPath, value) } } handleValueUnset = async (formFieldIndex: number, path: string, options?: { noPathCombination?: boolean }) => { - const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' + const withConfigPath = + this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField + ? `${this.props.config.configFrom.dataField}` + : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueUnset(fullPath) } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, options?: { noPathCombination?: boolean }) => { - const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' + handleValueListAppend = async ( + formFieldIndex: number, + path: string, + value: any, + options?: { noPathCombination?: boolean } + ) => { + const withConfigPath = + this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField + ? `${this.props.config.configFrom.dataField}` + : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListAppend(fullPath, value) } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, options?: { noPathCombination?: boolean }) => { - const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' + handleValueListSplice = async ( + formFieldIndex: number, + path: string, + index: number, + count: number, + options?: { noPathCombination?: boolean } + ) => { + const withConfigPath = + this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField + ? `${this.props.config.configFrom.dataField}` + : '' const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListSplice(fullPath, index, count) } } renderComponent = (props: IImportSubformField) => { - return - 您当前使用的UI版本没有实现ImportSubformField组件。 - + return <>您当前使用的UI版本没有实现ImportSubformField组件。 } /** @@ -150,83 +186,117 @@ export default class DetailImportSubformField extends DetailField { - return - 您当前使用的UI版本没有实现FormItem组件。 - + return <>您当前使用的UI版本没有实现FormItem组件。 + } + + /** + * 处理data 兼容非法json的情况 + * @param {any} data 待处理数据 + * @returns 返回data反序列化形式 + */ + handleDataToUnstringfy = (data: any) => { + let dataToUnstringfy = data + if (Object.prototype.toString.call(data) === '[object String]') { + try { + dataToUnstringfy = JSON.parse(data) + } catch (e) { + console.error('当前动态子表单接口响应数据格式不是合格的json字符串') + dataToUnstringfy = [] + } + } + return dataToUnstringfy } - getConfigData=() => { - const { - config, - value - } = this.props + getConfigData = () => { + const { config, value } = this.props if (config.configFrom && config.configFrom.type === 'interface' && config.configFrom.interface) { - this.interfaceHelper.request( - config.configFrom.interface, - {}, - { record: this.props.record, data: this.props.data, step: this.props.step }, - { loadDomain: this.props.loadDomain } - ).then((data: any) => { - 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.interfaceHelper + .request( + config.configFrom.interface, + {}, + { record: this.props.record, data: this.props.data, step: this.props.step }, + { loadDomain: this.props.loadDomain } + ) + .then((data: any) => { + const dataToUnstringfy = this.handleDataToUnstringfy(data) + if (!isEqual(dataToUnstringfy, this.state.fields)) { + this.setState({ + fields: dataToUnstringfy + }) } - } - if (dataToStringfy !== JSON.stringify(this.state.fields)) { - this.setState({ - fields: dataToUnstringfy - }) - } - }) + }) } - let fields = this.state.fields + + let { fields } = this.state if (config.configFrom && config.configFrom.type === 'data') { fields = config.configFrom.configField ? getValue(value, config.configFrom.configField) : [] - if (!isEqual(fields, this.state.fields)) { + const dataToUnstringfy = this.handleDataToUnstringfy(fields) + if (!isEqual(dataToUnstringfy, this.state.fields)) { this.setState({ - fields + fields: dataToUnstringfy }) } } } - componentDidMount () { - this.getConfigData() - } + // componentDidMount() { + // this.getConfigData() + // } + + // componentDidUpdate() { + // this.getConfigData() + // } render = () => { - const { - config, - formLayout, - value, - record, - data, - step - } = this.props - - const fields = this.state.fields + const { config, formLayout, value, record, data, step } = this.props + + let { fields } = this.state + if (config.configFrom && config.configFrom.type === 'data') { + fields = config.configFrom.configField ? getValue(value, config.configFrom.configField) : [] + const dataToUnstringfy = this.handleDataToUnstringfy(fields) + if (!isEqual(dataToUnstringfy, this.state.fields)) { + this.setState({ + fields: dataToUnstringfy + }) + } + } + + if (config.configFrom && config.configFrom.type === 'interface' && config.configFrom.interface) { + this.interfaceHelper + .request( + config.configFrom.interface, + {}, + { record: this.props.record, data: this.props.data, step: this.props.step }, + { loadDomain: this.props.loadDomain } + ) + .then((data: any) => { + const dataToUnstringfy = this.handleDataToUnstringfy(data) + if (!isEqual(dataToUnstringfy, this.state.fields)) { + this.setState({ + fields: dataToUnstringfy + }) + } + }) + } + if (!fields || !Array.isArray(fields) || fields.length === 0) { - return - } else { - const withConfigPath = this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField ? `${this.props.config.configFrom.dataField}` : '' - return ( - - {this.renderComponent({ - columns: config?.columns?.enable ? config.columns : undefined, - children: this.state.didMount - ? fields.map((formFieldConfig, formFieldIndex) => { + return <> + } + const withConfigPath = + this.props.config.configFrom?.type === 'data' && this.props.config.configFrom.dataField + ? `${this.props.config.configFrom.dataField}` + : '' + return ( + <> + {this.renderComponent({ + columns: config?.columns?.enable ? config.columns : undefined, + children: this.state.didMount + ? fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { this.formFieldsMounted[formFieldIndex] = false return null } - let display: boolean = true + let display = true if (formFieldConfig.type === 'hidden' || formFieldConfig.display === 'none') { display = false @@ -263,10 +333,16 @@ export default class DetailImportSubformField extends DetailField this.handleValueSet(formFieldIndex, path, value, options)} + 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)} + 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)} /> @@ -275,10 +351,9 @@ export default class DetailImportSubformField extends DetailField - ) - } + : [] + })} + + ) } } -- Gitee From a10471d4d5326949122370e0a2521e6deedc928e Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 22 Apr 2022 13:37:21 +0800 Subject: [PATCH 151/164] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/importSubform/index.tsx | 42 +----- .../formFields/importSubform/display.tsx | 141 +++++++++--------- 2 files changed, 79 insertions(+), 104 deletions(-) diff --git a/src/components/detail/importSubform/index.tsx b/src/components/detail/importSubform/index.tsx index 46d3a30..a4360cd 100644 --- a/src/components/detail/importSubform/index.tsx +++ b/src/components/detail/importSubform/index.tsx @@ -1,5 +1,6 @@ import React from 'react' import { cloneDeep, isEqual } from 'lodash' +import { setTimeout } from 'timers' import { getValue, getChainPath } from '../../../util/value' import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../common' @@ -239,45 +240,18 @@ export default class DetailImportSubformField } } - // componentDidMount() { - // this.getConfigData() - // } + componentDidMount() { + this.getConfigData() + } - // componentDidUpdate() { - // this.getConfigData() - // } + componentDidUpdate() { + this.getConfigData() + } render = () => { const { config, formLayout, value, record, data, step } = this.props - let { fields } = this.state - if (config.configFrom && config.configFrom.type === 'data') { - fields = config.configFrom.configField ? getValue(value, config.configFrom.configField) : [] - const dataToUnstringfy = this.handleDataToUnstringfy(fields) - if (!isEqual(dataToUnstringfy, this.state.fields)) { - this.setState({ - fields: dataToUnstringfy - }) - } - } - - if (config.configFrom && config.configFrom.type === 'interface' && config.configFrom.interface) { - this.interfaceHelper - .request( - config.configFrom.interface, - {}, - { record: this.props.record, data: this.props.data, step: this.props.step }, - { loadDomain: this.props.loadDomain } - ) - .then((data: any) => { - const dataToUnstringfy = this.handleDataToUnstringfy(data) - if (!isEqual(dataToUnstringfy, this.state.fields)) { - this.setState({ - fields: dataToUnstringfy - }) - } - }) - } + const { fields } = this.state if (!fields || !Array.isArray(fields) || fields.length === 0) { return <> diff --git a/src/components/formFields/importSubform/display.tsx b/src/components/formFields/importSubform/display.tsx index 52b90e5..4e0eae5 100644 --- a/src/components/formFields/importSubform/display.tsx +++ b/src/components/formFields/importSubform/display.tsx @@ -1,11 +1,11 @@ import React from 'react' +import { cloneDeep, isEqual } from 'lodash' import { getValue } from '../../../util/value' import { DetailField, DetailFieldConfig, DetailFieldProps, IDetailField } from '../../detail/common' -import { Display } from '../../formFields/common' -import { display as getALLComponents, FieldConfigs } from '../../formFields' +import { Display } from '../common' +import { display as getALLComponents, FieldConfigs } from '..' import { IDetailItem } from '../../../steps/detail' -import { cloneDeep, isEqual } from 'lodash' import ConditionHelper from '../../../util/condition' import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' /** @@ -16,7 +16,7 @@ import InterfaceHelper, { InterfaceConfig } from '../../../util/interface' * - * - configField: (序列化)配置 */ export interface ImportSubformFieldConfig extends DetailFieldConfig { - type: 'import_subform', + type: 'import_subform' configFrom?: ImportSubformConfigFromData | ImportSubformConfigFromInterface } @@ -38,18 +38,23 @@ export interface IImportSubformField { interface IImportSubformFieldState { didMount: boolean fields: FieldConfigs[] - formData: { status: 'normal' | 'error' | 'loading', message?: string }[] + formData: { status: 'normal' | 'error' | 'loading'; message?: string }[] } -export default class ImportSubformFieldDisplay extends DetailField implements IDetailField { +export default class ImportSubformFieldDisplay + extends DetailField + implements IDetailField +{ // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Display => getALLComponents[type] // 用于请求防频的判断条件 - requestConfig: string = '' - value: string = '' + requestConfig = '' + + value = '' formFields: Array | null> = [] + formFieldsMounted: Array = [] interfaceHelper = new InterfaceHelper() @@ -64,9 +69,11 @@ export default class ImportSubformFieldDisplay extends DetailField Promise = async (value) => { return value - }; + } handleMount = async (formFieldIndex: number) => { if (this.formFieldsMounted[formFieldIndex]) { @@ -94,7 +101,7 @@ export default class ImportSubformFieldDisplay extends DetailField { - const { - config, - value - } = this.props + const { config, value } = this.props if (config.configFrom && config.configFrom.type === 'interface' && config.configFrom.interface) { - this.interfaceHelper.request( - config.configFrom.interface, - {}, - { record: this.props.record, data: this.props.data, step: this.props.step }, - { loadDomain: this.props.loadDomain } - ).then((data: any) => { - 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.interfaceHelper + .request( + config.configFrom.interface, + {}, + { record: this.props.record, data: this.props.data, step: this.props.step }, + { loadDomain: this.props.loadDomain } + ) + .then((data: any) => { + 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 = '[]' + } } - } - if (dataToStringfy !== JSON.stringify(this.state.fields)) { - this.setState({ - fields: dataToUnstringfy - }) - } - }) + if (dataToStringfy !== JSON.stringify(this.state.fields)) { + this.setState({ + fields: dataToUnstringfy + }) + } + }) } - let fields = this.state.fields + let { fields } = this.state if (config.configFrom && config.configFrom.type === 'data') { fields = config.configFrom.configField ? getValue(value, config.configFrom.configField) : [] if (!isEqual(fields, this.state.fields)) { @@ -152,6 +158,10 @@ export default class ImportSubformFieldDisplay extends DetailField { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { @@ -185,9 +195,7 @@ export default class ImportSubformFieldDisplay extends DetailField { - return - 您当前使用的UI版本没有实现ImportSubformField组件。 - + return <>您当前使用的UI版本没有实现ImportSubformField组件。 } /** @@ -196,34 +204,26 @@ export default class ImportSubformFieldDisplay extends DetailField { - return - 您当前使用的UI版本没有实现FormItem组件。 - + return <>您当前使用的UI版本没有实现FormItem组件。 } render = () => { - const { - config, - value, - record, - data, - step - } = this.props - const fields = this.state.fields + const { config, value, record, data, step } = this.props + const { fields } = this.state if (!fields || !Array.isArray(fields) || fields.length === 0) { - return - } else { - return ( - - {this.renderComponent({ - children: this.state.didMount - ? fields.map((formFieldConfig, formFieldIndex) => { + return <> + } + return ( + <> + {this.renderComponent({ + children: this.state.didMount + ? fields.map((formFieldConfig, formFieldIndex) => { if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step })) { this.formFieldsMounted[formFieldIndex] = false return null } - let display: boolean = true + let display = true if (formFieldConfig.type === 'hidden' || formFieldConfig.display === 'none') { display = false @@ -236,7 +236,7 @@ export default class ImportSubformFieldDisplay 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)} + onValueListSplice={async (path, index, count) => + this.handleValueListSplice(formFieldIndex, path, index, count) + } baseRoute={this.props.baseRoute} loadDomain={async (domain: string) => await this.props.loadDomain(domain)} /> @@ -263,10 +265,9 @@ export default class ImportSubformFieldDisplay extends DetailField - ) - } + : [] + })} + + ) } } -- Gitee From 4de1c769703445cff3e021b445e8622e18cb6543 Mon Sep 17 00:00:00 2001 From: zjt Date: Fri, 22 Apr 2022 16:35:57 +0800 Subject: [PATCH 152/164] =?UTF-8?q?fix:=20fields/importSubform=E7=9A=84ren?= =?UTF-8?q?der=E4=B8=AD=E5=8E=BB=E6=8E=89setState?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formFields/importSubform/index.tsx | 449 +++++++++++------- 1 file changed, 281 insertions(+), 168 deletions(-) diff --git a/src/components/formFields/importSubform/index.tsx b/src/components/formFields/importSubform/index.tsx index e16aa67..f2e7fed 100644 --- a/src/components/formFields/importSubform/index.tsx +++ b/src/components/formFields/importSubform/index.tsx @@ -3,7 +3,7 @@ import { isEqual } from 'lodash' import { getValue, getBoolean, getChainPath } from '../../../util/value' import { Field, FieldConfig, FieldError, FieldProps, IField } from '../common' -import getALLComponents, { FieldConfigs } from '../' +import getALLComponents, { FieldConfigs } from '..' import { IFormItem } from '../../../steps/form' import { set, setValue } from '../../../util/produce' import ConditionHelper from '../../../util/condition' @@ -24,7 +24,7 @@ import { ColumnsConfig } from '../../../interface' * - * - configField: (序列化)配置 */ export interface ImportSubformFieldConfig extends FieldConfig { - type: 'import_subform', + type: 'import_subform' interface?: InterfaceConfig configFrom?: ImportSubformConfigFromData | ImportSubformConfigFromInterface withConfig?: { @@ -52,22 +52,28 @@ export interface IImportSubformField { interface IImportSubformFieldState { didMount: boolean fields: FieldConfigs[] - formData: { status: 'normal' | 'error' | 'loading', message?: string }[] + formData: { status: 'normal' | 'error' | 'loading'; message?: string }[] } -export default class ImportSubformField extends Field implements IField { +export default class ImportSubformField + extends Field + implements IField +{ // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Field => getALLComponents[type] // 用于请求防频的判断条件 - requestConfig: string = '' - value: string = '' + requestConfig = '' + + value = '' formFields: Array | null> = [] + formFieldsMounted: Array = [] + interfaceHelper = new InterfaceHelper() - constructor (props: FieldProps) { + constructor(props: FieldProps) { super(props) this.state = { @@ -89,19 +95,37 @@ export default class ImportSubformField extends Field => { const errors: FieldError[] = [] let childrenError = 0 - const childrenErrorMsg: Array<{name:string, msg:string}> = [] + const childrenErrorMsg: Array<{ name: string; msg: string }> = [] - let formData = this.state.formData + let { formData } = this.state - for (const fieldIndex in (this.state.fields || [])) { + for (const fieldIndex in this.state.fields || []) { const formItem = this.formFields[fieldIndex] - const formConfig = this.state.fields?.[fieldIndex] - if (formItem !== null && formItem !== undefined) { - const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - const validation = await formItem.validate(getValue(value, getChainPath(withConfigPath, (this.state.fields || [])[fieldIndex].field))) + const formConfig = this.state.fields?.[fieldIndex] + if (formItem !== null && formItem !== undefined) { + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + const validation = await formItem.validate( + getValue(value, getChainPath(withConfigPath, (this.state.fields || [])[fieldIndex].field)) + ) if (validation === true || this.formFieldsMounted[fieldIndex] === false) { formData = set(formData, `[${fieldIndex}]`, { status: 'normal' }) @@ -154,7 +182,9 @@ export default class ImportSubformField extends Field 0) { - const errTips = `${this.props.config.label || ''}子项中错误。\n ${childrenErrorMsg.map(err => `${err.name}:${err.msg}`).join('; ')}。` + const errTips = `${this.props.config.label || ''}子项中错误。\n ${childrenErrorMsg + .map((err) => `${err.name}:${err.msg}`) + .join('; ')}。` errors.push(new FieldError(errTips)) } @@ -171,12 +201,15 @@ export default class ImportSubformField extends Field { // const formField = this.formFields[formFieldIndex] // const formFieldConfig = this.state.fields[formFieldIndex] - // const formData = cloneDeep(this.state.formData) - // if (formField && formFieldConfig) { // if (this.props.onChange) { // if (formFieldConfig.field === '') { @@ -208,14 +239,12 @@ export default class ImportSubformField extends Field { - let formData = this.state.formData + let { formData } = this.state if (validation === true) { formData = set(formData, `[${formFieldIndex}]`, { status: 'normal' }) } else { @@ -237,55 +266,106 @@ 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 withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueSet(fullPath, value, true) this.handleValueCallback(formFieldIndex, validation) } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + handleValueUnset = async ( + formFieldIndex: number, + path: string, + validation: true | FieldError[], + options?: { noPathCombination?: boolean } + ) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueUnset(fullPath, true) this.handleValueCallback(formFieldIndex, validation) } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + handleValueListAppend = async ( + formFieldIndex: number, + path: string, + value: any, + validation: true | FieldError[], + options?: { noPathCombination?: boolean } + ) => { const formFieldConfig = (this.state.fields || [])[formFieldIndex] if (formFieldConfig) { - const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListAppend(fullPath, value, true) this.handleValueCallback(formFieldIndex, validation) } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + 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 withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListSplice(fullPath, index, count, true) this.handleValueCallback(formFieldIndex, validation) } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + 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 withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - const fullPath = options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + const fullPath = + options && options.noPathCombination ? path : getChainPath(withConfigPath, formFieldConfig.field, path) await this.props.onValueListSort(fullPath, index, sortType, true) this.handleValueCallback(formFieldIndex, validation) @@ -311,9 +391,7 @@ export default class ImportSubformField extends Field { - return - 您当前使用的UI版本没有实现ImportSubformField组件。 - + return <>您当前使用的UI版本没有实现ImportSubformField组件。 } /** @@ -321,22 +399,13 @@ export default class ImportSubformField extends Field { - return - 您当前使用的UI版本没有实现FormItem组件。 - - } + renderItemComponent = (props: IFormItem) => { + return <>您当前使用的UI版本没有实现FormItem组件。 + } - render = () => { - const { - config, - formLayout, - value, - data, - step - } = this.props - - let fields = this.state.fields + getConfigData = () => { + const { config, value } = this.props + let { fields } = this.state let interfaceConfig: InterfaceConfig | undefined if (config.configFrom) { if (config.configFrom.type === 'interface') { @@ -357,118 +426,162 @@ export default class ImportSubformField extends Field { - 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 - }) - } - }) + this.interfaceHelper + .request( + interfaceConfig, + {}, + { record: this.props.record, data: this.props.data, step: this.props.step }, + { loadDomain: this.props.loadDomain }, + this + ) + .then((data: any) => { + 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 + }) + } + }) } + } + + componentDidMount() { + this.getConfigData() + } + + componentDidUpdate() { + this.getConfigData() + } + + render = () => { + const { config, formLayout, value, data, step } = this.props + + const { fields } = this.state if (!fields || !Array.isArray(fields) || fields.length === 0) { - return - } else { - const withConfigPath = this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField ? `${this.props.config.withConfig.dataField}` : '' - return ( - - {this.renderComponent({ - columns: config.columns, - children: this.state.didMount - ? (Array.isArray(this.state.fields) ? this.state.fields : []).map((formFieldConfig, formFieldIndex) => { - if (!ConditionHelper(formFieldConfig.condition, { record: value, data, step, extraContainerPath: this.props.config.field }, this)) { - this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) - this.formFields && (this.formFields[formFieldIndex] = null) - return null - } - let hidden: boolean = true - let display: boolean = true - - if (formFieldConfig.type === 'hidden') { - hidden = true - display = false - } - - if (formFieldConfig.display === 'none') { - hidden = true - display = false - } - - const FormField = this.getALLComponents(formFieldConfig.type) || Field - - let status = (this.state.formData[formFieldIndex] || {}).status || 'normal' - - if (['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type)) { - status = 'normal' - } - - const renderData = { - key: formFieldIndex, - label: formFieldConfig.label, - status, - columns: config.columns?.enable - ? { - type: formFieldConfig.columns?.type || config.childColumns?.type || 'span', - value: formFieldConfig.columns?.value || config.childColumns?.value || 1, - wrap: formFieldConfig.columns?.wrap || config.childColumns?.wrap || false, - gap: config.columns?.gap || 0, - rowGap: config.columns?.rowGap || 0 + return <> + } + const withConfigPath = + this.props.config.withConfig?.enable && this.props.config.withConfig?.dataField + ? `${this.props.config.withConfig.dataField}` + : '' + return ( + <> + {this.renderComponent({ + columns: config.columns, + children: this.state.didMount + ? (Array.isArray(this.state.fields) ? this.state.fields : []).map((formFieldConfig, formFieldIndex) => { + if ( + !ConditionHelper( + formFieldConfig.condition, + { record: value, data, step, extraContainerPath: this.props.config.field }, + this + ) + ) { + this.formFieldsMounted = set(this.formFieldsMounted, `[${formFieldIndex}]`, false) + this.formFields && (this.formFields[formFieldIndex] = null) + return null + } + let hidden = true + let display = true + + if (formFieldConfig.type === 'hidden') { + hidden = true + display = false + } + + if (formFieldConfig.display === 'none') { + hidden = true + display = false + } + + const FormField = this.getALLComponents(formFieldConfig.type) || Field + + let status = (this.state.formData[formFieldIndex] || {}).status || 'normal' + + if ( + ['group', 'import_subform', 'object', 'tabs', 'form'].some((type) => type === formFieldConfig.type) + ) { + status = 'normal' + } + + const renderData = { + key: formFieldIndex, + label: formFieldConfig.label, + status, + columns: config.columns?.enable + ? { + type: formFieldConfig.columns?.type || config.childColumns?.type || 'span', + value: formFieldConfig.columns?.value || config.childColumns?.value || 1, + wrap: formFieldConfig.columns?.wrap || config.childColumns?.wrap || false, + gap: config.columns?.gap || 0, + rowGap: config.columns?.rowGap || 0 + } + : undefined, + message: (this.state.formData[formFieldIndex] || {}).message || '', + extra: StatementHelper( + formFieldConfig.extra, + { + record: this.props.value, + data: this.props.data, + step: this.props.step, + extraContainerPath: this.props.config.field + }, + this + ), + required: getBoolean(formFieldConfig.required), + layout: formLayout, + visitable: display, + fieldType: formFieldConfig.type, + children: ( + | null) => { + if (formField) { + this.formFields = set(this.formFields, `[${formFieldIndex}]`, formField) + this.handleMount(formFieldIndex) } - : undefined, - message: (this.state.formData[formFieldIndex] || {}).message || '', - extra: StatementHelper(formFieldConfig.extra, { record: this.props.value, data: this.props.data, step: this.props.step, extraContainerPath: this.props.config.field }, this), - required: getBoolean(formFieldConfig.required), - layout: formLayout, - visitable: display, - fieldType: formFieldConfig.type, - children: ( - | null) => { - if (formField) { - this.formFields = set(this.formFields, `[${formFieldIndex}]`, formField) - this.handleMount(formFieldIndex) - } - }} - form={this.props.form} - formLayout={formLayout} - value={getValue(value, getChainPath(withConfigPath, formFieldConfig.field))} - record={value} - step={this.props.step} - data={data} - config={formFieldConfig} - onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} - 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)} - containerPath={getChainPath(this.props.containerPath, this.props.config.field)} - onReportFields={async (field: string) => await this.handleReportFields(field)} - /> - ) - } - // 渲染表单项容器 - return ( - hidden - ? this.renderItemComponent(renderData) - : + }} + form={this.props.form} + formLayout={formLayout} + value={getValue(value, getChainPath(withConfigPath, formFieldConfig.field))} + record={value} + step={this.props.step} + data={data} + config={formFieldConfig} + onChange={async (value: any) => { + await this.handleChange(formFieldIndex, value) + }} + 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)} + containerPath={getChainPath(this.props.containerPath, this.props.config.field)} + onReportFields={async (field: string) => await this.handleReportFields(field)} + /> ) - }) - : [] - })} - - ) - } + } + // 渲染表单项容器 + return hidden ? this.renderItemComponent(renderData) : + }) + : [] + })} + + ) } } -- Gitee From 16db0e5d878dbbef949e4fe68c27c456abae01ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E6=96=87=E9=9A=86?= Date: Fri, 22 Apr 2022 23:18:51 +0800 Subject: [PATCH 153/164] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 1b67ce3..225b8f1 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -192,10 +192,7 @@ export class Field extends React.Component< } shouldComponentUpdate (nextProps: FieldProps, nextState: S) { - // console.log('nextProps', nextProps, this.props, nextProps.value == this.props.value); - const dependentFieldsArr = this.dependentFields - // console.log('dependentFieldsArr',dependentFieldsArr); let dependentIsChange = false if (dependentFieldsArr && dependentFieldsArr.length) { for (let i = dependentFieldsArr.length; i >= 0; i--) { @@ -214,7 +211,6 @@ export class Field extends React.Component< * record也不比较,需要比较的话就在dependentFieldsArr取出record绝对路径 * */ if (!dependentIsChange && isEqual(this.state, nextState) && nextProps.value === this.props.value && this.props.config === nextProps.config) { - // console.log('no update' ); return false } return true -- Gitee From 4723a05ec9e8dbf77c36fc54f4995ca2d8fa7dea Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Sun, 24 Apr 2022 15:21:33 +0800 Subject: [PATCH 154/164] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9PageList?= =?UTF-8?q?=E5=AD=90=E9=A1=B9=E7=B1=BB=E5=9E=8B=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 4 ++-- src/components/formFields/common.tsx | 4 ++-- src/main.tsx | 17 +++++++++++++++-- src/steps/common.tsx | 4 ++-- src/util/operation.tsx | 4 ++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 889933c..6cae4e8 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -4,7 +4,7 @@ import { ColumnsConfig, ParamConfig } from '../../interface' import { DetailFieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { CCMSConfig } from '../../main' -import { TreeSelectFieldOption } from '../formFields/treeSelect' +import { PageListItem } from '../../main' /** * 详情页表单项基类配置文件格式定义 @@ -94,7 +94,7 @@ export interface DetailFieldProps { baseRoute: string, loadDomain: (domain: string) => Promise loadPageConfig: (pageID: any) => Promise - loadPageList: () => Promise> + loadPageList: () => Promise> handlePageRedirect: (path: string) => void checkPageAuth: (pageID: any) => Promise onUnmount: (reload?: boolean, data?: any) => Promise diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 225b8f1..eef2ebd 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -6,7 +6,7 @@ import ParamHelper from '../../util/param' import { updateCommonPrefixItem } from '../../util/value' import { ConditionConfig } from '../../util/condition' import { StatementConfig } from '../../util/statement' -import { TreeSelectFieldOption } from './treeSelect' +import { PageListItem } from '../../main' import { isEqual, get } from 'lodash' /** @@ -100,7 +100,7 @@ export interface FieldProps { onReportFields?: (field: string) => Promise // 向父组件上报依赖字段 1.3.0新增 step: { [field: string]: any } // 传递formValue loadDomain: (domain: string) => Promise - loadPageList: () => Promise> + loadPageList: () => Promise> } /** diff --git a/src/main.tsx b/src/main.tsx index 7bed1a1..2aadfb6 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -3,7 +3,6 @@ import marked from 'marked' import Step, { StepProps } from './steps/common' import StepComponents, { StepConfigs } from './steps' import { RichStringConfig } from './interface' -import { TreeSelectFieldOption } from './components/formFields/treeSelect' /** * 页面配置文件格式定义 @@ -47,7 +46,7 @@ export interface CCMSProps { loadPageURL: (pageID: any) => Promise loadPageFrameURL: (pageID: any) => Promise loadPageConfig: (pageID: any) => Promise - loadPageList: () => Promise> + loadPageList: () => Promise> loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string, replaceHistory: boolean) => void callback: (success: boolean) => void @@ -67,6 +66,20 @@ export interface CCMSState { data: any[] } +/** + * 页面列表项 + * - key: 此项必须设置(其值在整个树范围内唯一) + * - value: 默认根据此属性值进行筛选(其值在整个树范围内唯一) + * - title: 树节点显示的内容 + * - children: 子节点 + */ + export interface PageListItem { + key: string | number + value: string | number + title: string + children?: Array +} + /** * 页面组件 */ diff --git a/src/steps/common.tsx b/src/steps/common.tsx index fec990b..61244fa 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -1,6 +1,6 @@ import React from 'react' import { CCMSConfig } from '../main' -import { TreeSelectFieldOption } from '../components/formFields/treeSelect' +import { PageListItem } from '../main' /** * 页面流转步骤基类配置定义 @@ -31,7 +31,7 @@ export interface StepProps { loadPageURL: (pageID: any) => Promise loadPageFrameURL: (pageID: any) => Promise loadPageConfig: (pageID: any) => Promise - loadPageList: () => Promise> + loadPageList: () => Promise> baseRoute: string loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string, replaceHistory: boolean) => void diff --git a/src/util/operation.tsx b/src/util/operation.tsx index 14222c9..ef437eb 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -4,7 +4,7 @@ import { set } from '../util/produce' import { ParamConfig } from '../interface' import { CCMSConfig, CCMSProps } from '../main' import { getParam } from './value' -import { TreeSelectFieldOption } from '../components/formFields/treeSelect' +import { PageListItem } from '../main' export type OperationConfig = CCMSOperationConfig @@ -57,7 +57,7 @@ interface OperationHelperProps { loadPageURL: (pageID: any) => Promise, loadPageFrameURL: (pageID: any) => Promise, loadPageConfig: (pageID: any) => Promise, - loadPageList: () => Promise>, + loadPageList: () => Promise>, baseRoute: string, loadDomain: (domain: string) => Promise handlePageRedirect?: (path: string, replaceHistory: boolean) => void -- Gitee From bba45cd3a317bd79e49037add8348a01aa2cbe0c Mon Sep 17 00:00:00 2001 From: zjt Date: Sun, 24 Apr 2022 15:34:10 +0800 Subject: [PATCH 155/164] =?UTF-8?q?style:=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rollup.config.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 6b20707..53ba1f0 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,11 +1,11 @@ -import path from 'path'; -import ts from 'rollup-plugin-typescript2'; -import { nodeResolve } from '@rollup/plugin-node-resolve'; -import { babel } from '@rollup/plugin-babel'; -import commonjs from '@rollup/plugin-commonjs'; -import { eslint } from 'rollup-plugin-eslint'; -import json from '@rollup/plugin-json'; -import { terser } from 'rollup-plugin-terser'; +import path from 'path' +import ts from 'rollup-plugin-typescript2' +import { nodeResolve } from '@rollup/plugin-node-resolve' +import { babel } from '@rollup/plugin-babel' +import commonjs from '@rollup/plugin-commonjs' +import { eslint } from 'rollup-plugin-eslint' +import json from '@rollup/plugin-json' +import { terser } from 'rollup-plugin-terser' export default { input: 'src/index.tsx', @@ -39,4 +39,4 @@ export default { watch: { include: 'src/**' } -}; +} -- Gitee From 6d3befbd88c0dc79a2d5f319eb35de77a6b46e8e Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Sun, 24 Apr 2022 15:43:17 +0800 Subject: [PATCH 156/164] =?UTF-8?q?style:=20=E7=AE=80=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/detail/common.tsx | 3 +-- src/steps/common.tsx | 3 +-- src/util/operation.tsx | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/detail/common.tsx b/src/components/detail/common.tsx index 6cae4e8..3c830fe 100644 --- a/src/components/detail/common.tsx +++ b/src/components/detail/common.tsx @@ -3,8 +3,7 @@ import { ColumnsConfig, ParamConfig } from '../../interface' import { DetailFieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' -import { CCMSConfig } from '../../main' -import { PageListItem } from '../../main' +import { CCMSConfig, PageListItem } from '../../main' /** * 详情页表单项基类配置文件格式定义 diff --git a/src/steps/common.tsx b/src/steps/common.tsx index 61244fa..d7bb160 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -1,6 +1,5 @@ import React from 'react' -import { CCMSConfig } from '../main' -import { PageListItem } from '../main' +import { CCMSConfig, PageListItem } from '../main' /** * 页面流转步骤基类配置定义 diff --git a/src/util/operation.tsx b/src/util/operation.tsx index ef437eb..d7e7018 100644 --- a/src/util/operation.tsx +++ b/src/util/operation.tsx @@ -2,9 +2,8 @@ import React from 'react' import queryString from 'query-string' import { set } from '../util/produce' import { ParamConfig } from '../interface' -import { CCMSConfig, CCMSProps } from '../main' +import { CCMSConfig, CCMSProps, PageListItem } from '../main' import { getParam } from './value' -import { PageListItem } from '../main' export type OperationConfig = CCMSOperationConfig -- Gitee From db5490340ed204fe033c7d61905460b7539fe0ee Mon Sep 17 00:00:00 2001 From: zjt Date: Sun, 24 Apr 2022 19:04:40 +0800 Subject: [PATCH 157/164] fix: replace eval --- .eslintrc | 30 +++++++++-- src/util/condition.ts | 119 ++++++++++++++++++++++++------------------ 2 files changed, 94 insertions(+), 55 deletions(-) diff --git a/.eslintrc b/.eslintrc index fc8dbf2..cd4cc07 100644 --- a/.eslintrc +++ b/.eslintrc @@ -23,24 +23,44 @@ "ecmaVersion": 12, "sourceType": "module" }, - "plugins": ["react", "babel", "jest", "react-hooks", "@typescript-eslint"], + "plugins": [ + "react", + "babel", + "jest", + "react-hooks", + "@typescript-eslint" + ], "settings": { "react": { "version": "16.13.1" }, - "polyfills": ["Promise"] + "polyfills": [ + "Promise" + ] }, "rules": { "react/jsx-props-no-spreading": 0, "no-use-before-define": "off", "react/display-name": 0, "import/extensions": 0, - "comma-dangle": ["error", "never"], - "space-before-function-paren": [0, "always"], + "import/no-cycle": 1, + "comma-dangle": [ + "error", + "never" + ], + "space-before-function-paren": [ + 0, + "always" + ], "react/jsx-filename-extension": [ 2, { - "extensions": [".js", ".jsx", ".ts", ".tsx"] + "extensions": [ + ".js", + ".jsx", + ".ts", + ".tsx" + ] } ] } diff --git a/src/util/condition.ts b/src/util/condition.ts index 2fe70fd..7de2fc5 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,5 +1,5 @@ import { template } from 'lodash' -import { set } from '../util/produce' +import { set } from './produce' import { ParamConfig } from '../interface' import ParamHelper from './param' import { Field } from '../components/formFields/common' @@ -24,79 +24,98 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: { [field: string]: any }, extraContainerPath?: string }, _this?: Field): boolean { +export default function ConditionHelper( + condition: ConditionConfig | undefined, + datas: { record?: object; data: object[]; step: { [field: string]: any }; extraContainerPath?: string }, + _this?: Field +): boolean { // 条件语句模版 let conditionTemplate = '' // 条件语句模版入参 let statementParams = {} - if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { + if ( + condition === undefined || + ((condition.statement === undefined || condition.statement === '') && + (condition.template === undefined || condition.template === '')) + ) { return true - } else { - if (condition.template) { - conditionTemplate = condition.template - if (condition.params) { - condition.params.forEach((param) => { - if (param.field !== undefined && param.data !== undefined) { - const value = ParamHelper(param.data, datas, _this) - if (param.field === '') { - statementParams = value === undefined ? 'undefined' : JSON.stringify(value) - } else { - statementParams = set(statementParams, param.field, value === undefined ? 'undefined' : JSON.stringify(value)) - } + } + if (condition.template) { + conditionTemplate = condition.template + if (condition.params) { + condition.params.forEach((param) => { + if (param.field !== undefined && param.data !== undefined) { + const value = ParamHelper(param.data, datas, _this) + if (param.field === '') { + statementParams = value === undefined ? 'undefined' : JSON.stringify(value) + } else { + statementParams = set( + statementParams, + param.field, + value === undefined ? 'undefined' : JSON.stringify(value) + ) } - }) - } - } else { - // 用于兼容旧版本中的通配符 - // V2新增逻辑段 - 开始 - // const statementTemplate = template(condition.statement) - // V2新增逻辑段 - 结束 - // V2移除逻辑段 - 开始 - conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || '' - // V2移除逻辑段 - 结束 + } + }) + } + } else { + // 用于兼容旧版本中的通配符 + // V2新增逻辑段 - 开始 + // const statementTemplate = template(condition.statement) + // V2新增逻辑段 - 结束 + // V2移除逻辑段 - 开始 + conditionTemplate = condition.statement?.replace(/([^$])\{/g, '$1${') || '' + // V2移除逻辑段 - 结束 - if (condition.params) { - condition.params.forEach((param) => { - if (param.field !== undefined && param.data !== undefined) { - if (param.field === '') { - statementParams = ParamHelper(param.data, datas, _this) - } else { - statementParams = set(statementParams, param.field, ParamHelper(param.data, datas, _this)) - } + if (condition.params) { + condition.params.forEach((param) => { + if (param.field !== undefined && param.data !== undefined) { + if (param.field === '') { + statementParams = ParamHelper(param.data, datas, _this) + } else { + statementParams = set(statementParams, param.field, ParamHelper(param.data, datas, _this)) } - }) - } + } + }) } - - return execConditionHandler(condition, conditionTemplate, statementParams) } + + return execConditionHandler(condition, conditionTemplate, statementParams) +} + +const evil = (fn) => { + const Fn = Function // 一个变量指向Function,防止有些前端编译工具报错 + return new Fn(`return ${fn}`)()() } // 执行条件语句,返回结果 -const execConditionHandler = (condition: ConditionConfig | undefined, conditionTemplate: string, statementParams: object): boolean => { +const execConditionHandler = ( + condition: ConditionConfig | undefined, + conditionTemplate: string, + statementParams: object +): boolean => { try { if (Object.values(statementParams).some((param) => param === undefined)) { if (condition?.debug) { console.info(`CCMS debug: condition ${conditionTemplate} => false`) } return false - } else { - const statement = template(conditionTemplate)(statementParams) + } + const statement = template(conditionTemplate)(statementParams) - try { - const result = eval(statement) - if (condition?.debug) { - console.info(`CCMS debug: condition ${statement} => ${result}`) - } - return result - } catch (e) { - console.error('表单项展示条件语句执行错误。', conditionTemplate, statement) - return false + try { + const result = evil(statement) + if (condition?.debug) { + console.info(`CCMS debug: condition ${statement} => ${result}`) } + return result + } catch (e) { + console.error('表单项展示条件语句执行错误。', conditionTemplate, statement) + return false } } catch (e) { if (condition?.debug) { - console.info('CCMS debug: condition - `' + conditionTemplate + '` => error') + console.info(`CCMS debug: condition - \`${conditionTemplate}\` => error`) } console.error('表单项展示条件语句执行错误。', conditionTemplate) return false -- Gitee From 900e9ff8efa6c52e8bc8ec91ef2338819e4f17f2 Mon Sep 17 00:00:00 2001 From: zjt Date: Sun, 24 Apr 2022 19:17:17 +0800 Subject: [PATCH 158/164] fix: replace eval --- src/util/condition.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/condition.ts b/src/util/condition.ts index 7de2fc5..4d04bf0 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -85,7 +85,7 @@ export default function ConditionHelper( const evil = (fn) => { const Fn = Function // 一个变量指向Function,防止有些前端编译工具报错 - return new Fn(`return ${fn}`)()() + return new Fn(`return ${fn}`)() } // 执行条件语句,返回结果 -- Gitee From d2d05f2d394f7e337f129315b336f169475e8344 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Sat, 7 May 2022 11:02:11 +0800 Subject: [PATCH 159/164] =?UTF-8?q?feat:=20=E8=A1=A8=E5=8D=95=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=EF=BC=88=E4=B8=8D=E6=B6=89=E5=8F=8A=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E6=AD=A5=E9=AA=A4=EF=BC=89=E3=80=81formFields=E5=8C=85?= =?UTF-8?q?=E8=A3=B9=E7=BB=84=E4=BB=B6=E5=A2=9EsubLabelConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 26 ++++++++++++++++++- src/components/formFields/form/index.tsx | 2 ++ src/components/formFields/group/index.tsx | 1 + .../formFields/importSubform/index.tsx | 1 + src/components/formFields/tabs/index.tsx | 2 ++ src/steps/common.tsx | 21 +++++++++++++++ src/steps/form/index.tsx | 2 ++ 7 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 3bc88d3..320797e 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -1,11 +1,12 @@ import React from 'react' +import marked from 'marked' import { ColumnsConfig, ParamConfig } from '../../interface' import { FieldConfigs as getFieldConfigs } from './' import ParamHelper from '../../util/param' import { updateCommonPrefixItem } from '../../util/value' import { ConditionConfig } from '../../util/condition' -import { StatementConfig } from '../../util/statement' +import StatementHelper, { StatementConfig} from '../../util/statement' import { PageListItem } from '../../main' import { isEqual, get } from 'lodash' @@ -37,6 +38,11 @@ export interface FieldConfig { disabled?: boolean display?: 'none' defaultValue?: ParamConfig, + subLabelConfig?: { + enable: boolean + mode: 'plain' | 'markdown' | 'html' + content: StatementConfig + } condition?: ConditionConfig extra?: StatementConfig columns?: ColumnsConfig @@ -174,6 +180,24 @@ export class Field extends React.Component< didMount: () => Promise = async () => { } + /** + * 根据mode不同,处理subLabel内容 + * @param config 子项config + * @returns + */ + + handleSubLabelContent (config) { + const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') + const mode = config.subLabelConfig?.mode + switch (mode) { + case 'markdown': + return
+ case 'html': + return
+ } + return
{content}
+ } + /** * 上报param依赖字段名称 * @param field diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index f5c0f57..9459012 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -45,6 +45,7 @@ export interface IFormFieldItem { export interface IFormFieldItemField { index: number label: string + subLabel?: React.ReactNode required: boolean status: 'normal' | 'error' | 'loading' description?: string @@ -488,6 +489,7 @@ export default class FormField extends Field extends Field extends React.Component< } }; + +/** + * 步骤 根据mode不同,处理subLabel内容\ + * @param config 子项config + * @returns + */ + + handleSubLabelContent (config) { + const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') + const mode = config.subLabelConfig?.mode + switch (mode) { + case 'markdown': + return
+ case 'html': + return
+ } + return
{content}
+ } + stepPush = () => { this.props.onMount() } diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index cd077f1..c456641 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -154,6 +154,7 @@ export interface IButtonProps { export interface IFormItem { key: string | number, label: string, + subLabel?: React.ReactNode status: 'normal' | 'error' | 'loading' required: boolean description?: string @@ -699,6 +700,7 @@ export default class FormStep extends Step { // ts对clas const renderData = { key: formFieldIndex, label: formFieldConfig.label, + subLabel: formFieldConfig?.subLabelConfig?.enable ? this.handleSubLabelContent(formFieldConfig) : undefined, columns: columns?.enable ? { type: formFieldConfig.columns?.type || columns?.type || 'span', -- Gitee From 651d9b1f924410ce6342416a7e152e5c1805c058 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Sat, 7 May 2022 11:06:00 +0800 Subject: [PATCH 160/164] =?UTF-8?q?feat:=20code=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/code/index.tsx | 51 +++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/components/formFields/code/index.tsx b/src/components/formFields/code/index.tsx index 09d8f27..17a0087 100644 --- a/src/components/formFields/code/index.tsx +++ b/src/components/formFields/code/index.tsx @@ -8,6 +8,10 @@ import { getBoolean } from '../../../util/value' * - height: 代码编辑器高度 * - theme: 编辑器主题风格 * - fullScreen: 是否支持全屏 + * - maxLength: 最大字符长度 + * - minLength: 最小字符长度 + * - cjkLength: 中文占字符数 + * - regExp: 正则校验配置 */ export interface CodeFieldConfig extends FieldConfig { type: 'code' @@ -15,6 +19,10 @@ export interface CodeFieldConfig extends FieldConfig { height: number theme: 'white' | 'black' fullScreen: boolean + maxLength?: number + minLength?: number + cjkLength?: number + regExp?: { expression: string, message?: string } } export interface ICodeField { @@ -61,7 +69,11 @@ export default class CodeField extends Field= 0 && valueMaxLength.length > maxLength) { + errors.push(new FieldError(`最长可输入${maxLength}个字符。`)) + } + } + + if (minLength !== undefined) { + let valueMinLength = value + if (cjkLength !== undefined) { + let valueMinCJKLength = '' + for (let valueMinCJKIndex = 0; valueMinCJKIndex < cjkLength; valueMinCJKIndex++) { + valueMinCJKLength += '*' + } + valueMinLength = valueMinLength.replace(/[\u4e00-\u9fa5]/g, valueMinCJKLength) + } + if (valueMinLength && minLength >= 0 && valueMinLength.length < minLength) { + errors.push(new FieldError(`最短需输入${minLength}个字符。`)) + } + } + + if (regExp !== undefined) { + if (!(new RegExp(regExp.expression)).test(value)) { + if (regExp.message) { + errors.push(new FieldError(regExp.message)) + } else { + errors.push(new FieldError('格式错误')) + } + } + } return errors.length ? errors : true } -- Gitee From da1682501d257997e14f3d34396c31889d56ec28 Mon Sep 17 00:00:00 2001 From: zjt Date: Mon, 9 May 2022 16:08:15 +0800 Subject: [PATCH 161/164] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E5=8F=B3=E4=B8=8A=E8=A7=92=E6=8C=89=E9=92=AE=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 20 +- src/steps/form/index.tsx | 389 ++++++++++++++++++++++++++------------- 2 files changed, 275 insertions(+), 134 deletions(-) diff --git a/.eslintrc b/.eslintrc index cd4cc07..cff24b5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -40,10 +40,26 @@ }, "rules": { "react/jsx-props-no-spreading": 0, - "no-use-before-define": "off", + "no-use-before-define": 0, "react/display-name": 0, "import/extensions": 0, - "import/no-cycle": 1, + "import/no-cycle": 0, + "consistent-return": 0, + "no-restricted-syntax": 0, + "import/no-extraneous-dependencies": 1, + "@typescript-eslint/no-empty-function": 1, + "typescript-eslint/no-explicit-any": 0, + "no-underscore-dangle": 0, + "no-unused-expressions": 0, + "no-plusplus": 0, + "no-continue": 0, + "react/no-array-index-key": 1, + "no-return-await": 1, + "import/no-unresolved": 1, + "no-await-in-loop": 1, + "no-nested-ternary": 1, + "react/jsx-no-useless-fragment": 1, + "no-shadow": 1, "comma-dangle": [ "error", "never" diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index cd077f1..ad61663 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -42,13 +42,14 @@ export interface FormConfig extends StepConfig { * 表单组件配置文件格式定义 * 参照其它组件定义 */ - fields?: FieldConfigs[], - defaultValue?: ParamConfig, + fields?: FieldConfigs[] + defaultValue?: ParamConfig validations?: Array<{ condition?: ConditionConfig message?: StatementConfig }> actions: Array | [] + rightTopActions: Array | [] stringify?: string[] // 序列化字段 unstringify?: string[] // 反序列化字段 hiddenSubmit?: boolean // 是否隐藏提交按钮 TODO 待删除 @@ -76,9 +77,9 @@ export interface FormConfig extends StepConfig { * - * - * - cancel: 取消表单 */ export interface ActionConfig { - type: 'submit' | 'cancel' | 'ccms', - label: string, - mode: 'normal' | 'primary' | 'link', + type: 'submit' | 'cancel' | 'ccms' + label: string + mode: 'normal' | 'primary' | 'link' submitValidate: boolean condition?: ConditionConfig handle?: OperationConfig @@ -116,6 +117,7 @@ export interface IForm { layout: 'horizontal' | 'vertical' | 'inline' columns?: ColumnsConfig actions?: React.ReactNode[] + rightTopActions?: React.ReactNode[] children: React.ReactNode[] onSubmit?: () => Promise onCancel?: () => Promise @@ -152,8 +154,8 @@ export interface IButtonProps { * - children: 表单项内容 */ export interface IFormItem { - key: string | number, - label: string, + key: string | number + label: string status: 'normal' | 'error' | 'loading' required: boolean description?: string @@ -173,32 +175,39 @@ export interface IFormItem { interface FormState { ready: boolean formValue: { [field: string]: any } - formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] + formData: { status: 'normal' | 'error' | 'loading'; message?: string; name: string }[] } /** * 表单步骤组件 */ -export default class FormStep extends Step { // ts对class的声明文件报错,临时解决 +export default class FormStep extends Step { + // ts对class的声明文件报错,临时解决 // 各表单项对应的类型所使用的UI组件的类 getALLComponents = (type: any): typeof Field => getALLComponents[type] + OperationHelper = OperationHelper // 各表单项所使用的UI组件的实例 - formFields: Array | null> = [] + formFields: Array, any> | null> = [] + formFieldsMounted: Array = [] + dependentFields_: string[] = [] formValue: { [field: string]: any } = {} - formData: { status: 'normal' | 'error' | 'loading', message?: string, name: string }[] = [] - canSubmit: boolean = false + + formData: { status: 'normal' | 'error' | 'loading'; message?: string; name: string }[] = [] + + canSubmit = false + submitData: object = {} /** * 初始化表单的值 * @param props */ - constructor (props: StepProps) { + constructor(props: StepProps) { super(props) this.state = { ready: false, @@ -213,9 +222,7 @@ export default class FormStep extends Step { // ts对clas stepPush = async () => { // 处理表单步骤配置文件的默认值 const { - config: { - fields: formFieldsConfig = [] - }, + config: { fields: formFieldsConfig = [] }, data, step, onMount @@ -238,7 +245,7 @@ export default class FormStep extends Step { // ts对clas } } - for (const formFieldIndex in formFieldsConfig) { + for (let formFieldIndex = 0; formFieldIndex < formFieldsConfig.length; formFieldIndex++) { const formFieldConfig = formFieldsConfig[formFieldIndex] const value = getValue(formDefault, formFieldConfig.field) @@ -268,7 +275,7 @@ export default class FormStep extends Step { // ts对clas if (formField) { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] let value = getValue(this.formValue, formFieldConfig.field) - if ((formFieldConfig.defaultValue) && value === undefined) { + if (formFieldConfig.defaultValue && value === undefined) { value = await formField.reset() } value = await formField.set(value) @@ -279,7 +286,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } } await formField.didMount() @@ -300,9 +311,20 @@ export default class FormStep extends Step { // ts对clas this.submitData = {} if (this.props.config.validations) { for (const validation of this.props.config.validations) { - if (!ConditionHelper(validation.condition, { record: this.state.formValue, data: this.props.data, step: this.formValue })) { + if ( + !ConditionHelper(validation.condition, { + record: this.state.formValue, + data: this.props.data, + step: this.formValue + }) + ) { this.canSubmit = false - const message = StatementHelper(validation.message, { record: this.state.formValue, data: this.props.data, step: this.formValue }) || '未填写失败文案或失败文案配置异常' + const message = + StatementHelper(validation.message, { + record: this.state.formValue, + data: this.props.data, + step: this.formValue + }) || '未填写失败文案或失败文案配置异常' this.renderModalComponent({ message }) return } @@ -310,7 +332,7 @@ export default class FormStep extends Step { // ts对clas if (!this.canSubmit) return } - for (const formFieldIndex in (this.props.config.fields || [])) { + for (const formFieldIndex in this.props.config.fields || []) { if (this.formFields[formFieldIndex]) { const formField = this.formFields[formFieldIndex] const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] @@ -319,7 +341,11 @@ export default class FormStep extends Step { // ts对clas const validation = await formField.validate(value) if (validation !== true) { console.warn('表单项中存在问题', value, formFieldConfig) - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) this.canSubmit = false } this.submitData = setValue(this.submitData, formFieldConfig.field, value) @@ -356,9 +382,7 @@ export default class FormStep extends Step { // ts对clas * 处理表单返回事件 */ handleCancel = async () => { - const { - onUnmount - } = this.props + const { onUnmount } = this.props onUnmount() } @@ -378,7 +402,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } await this.setState({ @@ -391,10 +419,21 @@ export default class FormStep extends Step { // ts对clas } } - handleValueSet = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + const fullPath = + options && options.noPathCombination + ? path + : formFieldConfig.field === '' || path === '' + ? `${formFieldConfig.field}${path}` + : `${formFieldConfig.field}.${path}` this.formValue = set(this.formValue, fullPath, value) this.setState(({ formValue }) => ({ @@ -408,7 +447,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } console.log('form set data', this.formData) @@ -419,10 +462,20 @@ export default class FormStep extends Step { // ts对clas } } - handleValueUnset = async (formFieldIndex: number, path: string, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + handleValueUnset = async ( + formFieldIndex: number, + path: string, + validation: true | FieldError[], + options?: { noPathCombination?: boolean } + ) => { const formFieldConfig = (this.props.config.fields || [])[formFieldIndex] if (formFieldConfig) { - const fullPath = options && options.noPathCombination ? path : (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.formValue = set(this.formValue, fullPath) @@ -436,7 +489,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } await this.setState({ @@ -445,10 +502,21 @@ export default class FormStep extends Step { // ts对clas } } - handleValueListAppend = async (formFieldIndex: number, path: string, value: any, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + const fullPath = + options && options.noPathCombination + ? path + : formFieldConfig.field === '' || path === '' + ? `${formFieldConfig.field}${path}` + : `${formFieldConfig.field}.${path}` this.formValue = push(this.formValue, fullPath, value) // 向this.formValue的fullPath下的值添加value this.setState({ @@ -461,7 +529,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } await this.setState({ @@ -470,10 +542,22 @@ export default class FormStep extends Step { // ts对clas } } - handleValueListSplice = async (formFieldIndex: number, path: string, index: number, count: number, validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + const fullPath = + options && options.noPathCombination + ? path + : formFieldConfig.field === '' || path === '' + ? `${formFieldConfig.field}${path}` + : `${formFieldConfig.field}.${path}` this.formValue = splice(this.formValue, fullPath, index, count) this.setState({ @@ -486,7 +570,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } await this.setState({ @@ -495,10 +583,22 @@ export default class FormStep extends Step { // ts对clas } } - handleValueListSort = async (formFieldIndex: number, path: string, index: number, sortType: 'up' | 'down', validation: true | FieldError[], options?: { noPathCombination?: boolean }) => { + 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 = options && options.noPathCombination ? path : (formFieldConfig.field === '' || path === '' ? `${formFieldConfig.field}${path}` : `${formFieldConfig.field}.${path}`) + const fullPath = + options && options.noPathCombination + ? path + : formFieldConfig.field === '' || path === '' + ? `${formFieldConfig.field}${path}` + : `${formFieldConfig.field}.${path}` this.formValue = sort(this.formValue, fullPath, index, sortType) this.setState({ @@ -511,7 +611,11 @@ export default class FormStep extends Step { // ts对clas if (validation === true) { this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) } else { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'error', message: validation[0].message, name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'error', + message: validation[0].message, + name: formFieldConfig.label + }) } await this.setState({ @@ -528,7 +632,11 @@ export default class FormStep extends Step { // ts对clas if (success) { const callbackType = action.callback?.type if (callbackType) { - if (callbackType === 'submit') { this.handleSubmit() } else if (callbackType === 'cancel') { this.handleCancel() } + if (callbackType === 'submit') { + this.handleSubmit() + } else if (callbackType === 'cancel') { + this.handleCancel() + } } } } @@ -539,9 +647,7 @@ export default class FormStep extends Step { // ts对clas * @param props */ renderComponent = (props: IForm) => { - return - 您当前使用的UI版本没有实现Form组件。 - + return <>您当前使用的UI版本没有实现Form组件。 } /** @@ -549,9 +655,7 @@ export default class FormStep extends Step { // ts对clas * @param props */ renderButtonComponent = (props: IButtonProps) => { - return - 您当前使用的UI版本没有实现FormButton组件。 - + return <>您当前使用的UI版本没有实现FormButton组件。 } /** @@ -560,9 +664,7 @@ export default class FormStep extends Step { // ts对clas * @param props */ renderItemComponent = (props: IFormItem) => { - return - 您当前使用的UI版本没有实现FormItem组件。 - + return <>您当前使用的UI版本没有实现FormItem组件。 } /** @@ -576,26 +678,7 @@ export default class FormStep extends Step { // ts对clas }) } - render () { - const { - data, - config: { - columns, - // layout = 'horizontal', - // fields = [] - actions - } - } = this.props - - const layout = this.props.config?.layout || 'horizontal' - const fields = this.props.config?.fields || [] - - const { - ready, - formValue, - formData - } = this.state - + getActios = (actions: Array | [], formValue: { [field: string]: any }, data: any[]) => { let actions_ if (Object.prototype.toString.call(actions) === '[object Array]') { actions_ = [] @@ -604,62 +687,94 @@ export default class FormStep extends Step { // ts对clas continue } if (actions[index].type === 'submit') { - actions_.push(this.renderButtonComponent({ - label: actions[index].label || '', - mode: actions[index].mode, - onClick: () => this.handleSubmit() - })) + actions_.push( + this.renderButtonComponent({ + label: actions[index].label || '', + mode: actions[index].mode, + onClick: () => this.handleSubmit() + }) + ) } else if (actions[index].type === 'cancel') { - actions_.push(this.renderButtonComponent({ - label: actions[index].label || '', - mode: actions[index].mode, - onClick: () => this.handleCancel() - })) + actions_.push( + this.renderButtonComponent({ + label: actions[index].label || '', + mode: actions[index].mode, + onClick: () => this.handleCancel() + }) + ) } else { - const submitValidate = actions[index].submitValidate - const OperationHelperWrapper = { await this.handleCallback(actions[index], success) }} - > - {(onClick) => ( - this.renderButtonComponent({ - label: actions[index].label || '', - mode: actions[index].mode, - onClick: submitValidate - ? async () => { - await this.handleValidations() - console.info('表单参数信息', this.submitData, this.state.formValue, this.formData) - if (this.canSubmit) { - onClick() - } - } - : onClick - }) - )} - + const { submitValidate } = actions[index] + const OperationHelperWrapper = ( + { + await this.handleCallback(actions[index], success) + }} + > + {(onClick) => + this.renderButtonComponent({ + label: actions[index].label || '', + mode: actions[index].mode, + onClick: submitValidate + ? async () => { + await this.handleValidations() + console.info('表单参数信息', this.submitData, this.state.formValue, this.formData) + if (this.canSubmit) { + onClick() + } + } + : onClick + }) + } + + ) actions_.push(OperationHelperWrapper) } } } + return actions_ + } + + render() { + const { + data, + config: { + columns, + // layout = 'horizontal', + // fields = [] + actions, + rightTopActions + } + } = this.props + + const layout = this.props.config?.layout || 'horizontal' + const fields = this.props.config?.fields || [] + + const { ready, formValue, formData } = this.state + + const actions_ = this.getActios(actions, formValue, data) + + const rightTopActions_ = this.getActios(rightTopActions, formValue, data) if (ready) { return ( - + <> {/* 渲染表单 */} {this.renderComponent({ layout, columns: columns?.enable ? columns : undefined, actions: actions_, + rightTopActions: rightTopActions_, onSubmit: this.props.config.hiddenSubmit ? undefined : async () => this.handleSubmit(), // TODO 待删除 onCancel: this.props.config.hiddenCancel ? undefined : async () => this.handleCancel(), // TODO 待删除 submitText: this.props.config?.submitText?.replace(/(^\s*)|(\s*$)/g, ''), // TODO 待删除 @@ -670,8 +785,8 @@ export default class FormStep extends Step { // ts对clas this.formFields && (this.formFields[formFieldIndex] = null) return null } - let hidden: boolean = true - let display: boolean = true + let hidden = true + let display = true if (formFieldConfig.type === 'hidden') { hidden = true @@ -685,7 +800,10 @@ export default class FormStep extends Step { // ts对clas // 隐藏项同时打标录入数据并清空填写项 if (!hidden) { - this.formData = set(this.formData, `[${formFieldIndex}]`, { status: 'normal', name: formFieldConfig.label }) + this.formData = set(this.formData, `[${formFieldIndex}]`, { + status: 'normal', + name: formFieldConfig.label + }) } const FormField = this.getALLComponents(formFieldConfig.type) || Field @@ -731,31 +849,38 @@ export default class FormStep extends Step { // ts对clas data={data} step={formValue} config={formFieldConfig} - onChange={async (value: any) => { await this.handleChange(formFieldIndex, value) }} - 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)} + onChange={async (value: any) => { + await this.handleChange(formFieldIndex, value) + }} + 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)} loadPageList={async () => await this.props.loadPageList()} - containerPath={''} + containerPath="" /> ) } // 渲染表单项容器 - return ( - hidden - ? this.renderItemComponent(renderData) - : - ) + return hidden ? this.renderItemComponent(renderData) : }) })} - + ) - } else { - return <> } + return <> } } -- Gitee From 7715d1a3338ed6e1d996fe5094fcc724b0b3ccdb Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 9 May 2022 17:52:43 +0800 Subject: [PATCH 162/164] =?UTF-8?q?perf:=20enable=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=94=BE=E5=85=A5handleSubLabelContent?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formFields/common.tsx | 23 +++++++++++-------- src/components/formFields/form/index.tsx | 2 +- src/components/formFields/group/index.tsx | 2 +- .../formFields/importSubform/index.tsx | 2 +- src/components/formFields/tabs/index.tsx | 2 +- src/steps/common.tsx | 19 ++++++++------- src/steps/form/index.tsx | 2 +- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/components/formFields/common.tsx b/src/components/formFields/common.tsx index 320797e..7cb767b 100644 --- a/src/components/formFields/common.tsx +++ b/src/components/formFields/common.tsx @@ -185,17 +185,20 @@ export class Field extends React.Component< * @param config 子项config * @returns */ - - handleSubLabelContent (config) { - const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') - const mode = config.subLabelConfig?.mode - switch (mode) { - case 'markdown': - return
- case 'html': - return
+ + handleSubLabelContent (config) { + if (config?.subLabelConfig?.enable) { + const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') + const mode = config.subLabelConfig?.mode + switch (mode) { + case 'markdown': + return
+ case 'html': + return
+ } + return
{content}
} - return
{content}
+ return undefined } /** diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index 9459012..25a229f 100644 --- a/src/components/formFields/form/index.tsx +++ b/src/components/formFields/form/index.tsx @@ -489,7 +489,7 @@ export default class FormField extends Field extends Field extends React.Component< */ handleSubLabelContent (config) { - const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') - const mode = config.subLabelConfig?.mode - switch (mode) { - case 'markdown': - return
- case 'html': - return
+ if (config?.subLabelConfig?.enable) { + const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') + const mode = config.subLabelConfig?.mode + switch (mode) { + case 'markdown': + return
+ case 'html': + return
+ } + return
{content}
} - return
{content}
+ return undefined } stepPush = () => { diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index c456641..1685d11 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -700,7 +700,7 @@ export default class FormStep extends Step { // ts对clas const renderData = { key: formFieldIndex, label: formFieldConfig.label, - subLabel: formFieldConfig?.subLabelConfig?.enable ? this.handleSubLabelContent(formFieldConfig) : undefined, + subLabel: this.handleSubLabelContent(formFieldConfig), columns: columns?.enable ? { type: formFieldConfig.columns?.type || columns?.type || 'span', -- Gitee From 8e8c8264a3856541f169cc28b6cde0e19f53f580 Mon Sep 17 00:00:00 2001 From: cuiwenlong7 Date: Mon, 9 May 2022 17:58:14 +0800 Subject: [PATCH 163/164] =?UTF-8?q?style:=20=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/common.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/steps/common.tsx b/src/steps/common.tsx index ae16174..de4853a 100644 --- a/src/steps/common.tsx +++ b/src/steps/common.tsx @@ -55,8 +55,8 @@ export default class Step extends React.Component< * @returns */ - handleSubLabelContent (config) { - if (config?.subLabelConfig?.enable) { + handleSubLabelContent (config) { + if (config?.subLabelConfig?.enable) { const content = StatementHelper({ statement: config.subLabelConfig?.content?.statement || '', params: config.subLabelConfig?.content?.params || [] }, { data: this.props.data, step: this.props.step }).replace(/(^\s*)|(\s*$)/g, '') const mode = config.subLabelConfig?.mode switch (mode) { -- Gitee From 0706cccac4a25198f4489d317cda072fcbd2122c Mon Sep 17 00:00:00 2001 From: zjt Date: Tue, 10 May 2022 12:03:30 +0800 Subject: [PATCH 164/164] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=B8=BAany?= =?UTF-8?q?=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/form/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/steps/form/index.tsx b/src/steps/form/index.tsx index a2f2b57..9e04c4b 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -190,7 +190,7 @@ export default class FormStep extends Step { OperationHelper = OperationHelper // 各表单项所使用的UI组件的实例 - formFields: Array, any> | null> = [] + formFields: Array, any> | null> = [] formFieldsMounted: Array = [] -- Gitee