diff --git a/package.json b/package.json index b1fc05e9cf651f1de1d46f9c1b13042ea065e0bb..a420bb764744d2f0cef52e073f3793c98d943ce0 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/detail/common.tsx b/src/components/detail/common.tsx index 57902c18fa9ace6e57473ea7a8066cf43eff1e77..adcf97c2995ecb4cf17908ba8fd5a096b41ea470 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 0000000000000000000000000000000000000000..19a582f4153ec1445ca969e4a1a5367d8568ae18 --- /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/detailColor/index.tsx b/src/components/detail/detailColor/index.tsx new file mode 100644 index 0000000000000000000000000000000000000000..d498ce13b2c80f547d5db1aea49e4ab0b6a1c27a --- /dev/null +++ b/src/components/detail/detailColor/index.tsx @@ -0,0 +1,44 @@ +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() + + return ( + + {this.renderComponent({ + value + })} + + ) + } +} diff --git a/src/components/detail/detailInfo/index.tsx b/src/components/detail/detailInfo/index.tsx new file mode 100644 index 0000000000000000000000000000000000000000..912c6640d2c13aad5d32aa17360c354cfb765119 --- /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/group/index.tsx b/src/components/detail/group/index.tsx index c7dd58d9c1ad00c9a059da099d6167f32302480b..47cc62d77037932c82c6359f6e47483be35e6a97 100644 --- a/src/components/detail/group/index.tsx +++ b/src/components/detail/group/index.tsx @@ -276,6 +276,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 24ae0574587bd9fa0fb4b21556f333435775814c..2e550656fc59fd4ccf79c7032a57c4d89b18489a 100644 --- a/src/components/detail/index.tsx +++ b/src/components/detail/index.tsx @@ -2,9 +2,11 @@ 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' +import InfoDetail, { InfoDetailConfig } from './detailInfo' +import ColorDetail, { ColorDetailConfig } from './detailColor' /** * 详情步骤内详情项配置文件格式定义 - 枚举 @@ -14,19 +16,28 @@ export type DetailFieldConfigs = EnumDetailConfig | StatementDetailConfig | GroupFieldConfig | - ImportSubformFieldConfig + ImportSubformFieldConfig | + InfoDetailConfig | + CustomDetailConfig | + ColorDetailConfig export type componentType = 'text' | 'group' | 'detail_enum' | 'statement' | - 'import_subform' + 'import_subform' | + 'detail_info' | + 'detail_color' | + 'custom' export default { group: GroupField, text: TextField, import_subform: ImportSubformField, detail_enum: EnumDetail, - statement: StatementDetail + statement: StatementDetail, + detail_info: InfoDetail, + detail_color: ColorDetail, + custom: CustomDetail } diff --git a/src/components/formFields/form/index.tsx b/src/components/formFields/form/index.tsx index d95ddeaeedadd3d4e9843f6ea100c67d497c0e56..111ac3ce1c2df25f3433b15b3bd9e105e340184f 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 && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true diff --git a/src/components/formFields/select/common.tsx b/src/components/formFields/select/common.tsx index 528b21d335fcb614216e17a0cbb4b14ae9adf729..550175de5da13e2cc33cab55e6f19096aa0a33e4 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'; + sourceConfig?: 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 = (sourceConfig: OptionsConfigDefaultValue) => { + if (sourceConfig !== undefined) { + return ParamHelper(sourceConfig, { 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.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) => ({ + 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 d2dd26346e084f9d3264716aab19da728c22aa94..262c9986c542d160a60a575ce834b092828cded8 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 { @@ -114,7 +115,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), @@ -129,8 +136,8 @@ 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/tabs/index.tsx b/src/components/formFields/tabs/index.tsx index a32b1157b5b184b5c38df4136ce26cb4743a4a6d..0ed46c21360d44cf9cc871bd736d31aff02ef703 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 + data?: treeTableDataConfig[] +} + +export interface treeTableDataConfig { + value: any + title: string + children: treeTableDataConfig[] } export interface InterfaceOptionsConfig { @@ -36,36 +60,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 +93,26 @@ export default class TreeSelectField extends Field { + if (sourceConfig !== undefined) { + return ParamHelper(sourceConfig, { 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 +124,7 @@ export default class TreeSelectField extends Field { if (config) { - if (config.from === 'manual') { + if (config.from === 'automatic') { + if (config.sourceConfig && config.sourceConfig.source && config.sourceConfig.field) { + const data = this.optionsAutomatic(config.sourceConfig) + 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 +192,7 @@ export default class TreeSelectField extends Field => { + validate = async (_value: string | Array | undefined): Promise => { const { config: { required @@ -178,28 +219,86 @@ export default class TreeSelectField extends Field } + renderTreeComponent = (props: ITreeSelectField) => { + return + 您当前使用的UI版本没有实现TreeSelectField组件的tree模式。 +
+ +
+
+ } + + renderTableComponent = (props: ITreeSelectField) => { + return + 您当前使用的UI版本没有实现TreeSelectField组件的table模式。 +
+ +
+
+ } + render = () => { const { value, config: { + multiple, + mode, + titleColumn, treeData: optionsConfig }, - onChange, record, data, step } = this.props - this.options(optionsConfig, { record, data, step }) - - return ( - - {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' && value !== '') { + props.value = transformValueType(String(value).split(multiple.split || ','), multiple?.valueType) + } 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 if (mode === 'tree') { + return this.renderTreeComponent(props) + } else { + return ( + + {this.renderComponent({ + value, + treeData: this.state.interfaceOptionsData, + onChange: async (value: string) => await this.props.onValueSet('', value, await this.validate(value)) + })} + + ) + } } } diff --git a/src/index.tsx b/src/index.tsx index b193a0536d64a8ad4a2c1726d89d8c170a8c9941..4b22927dc9703715554fc731b1ef02a88060fda3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -58,6 +58,9 @@ 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 DetailColorField } from './components/detail/detailColor' +export { default as CustomDetail } from './components/detail/custom' export { default as HeaderStep } from './steps/header' diff --git a/src/interface.ts b/src/interface.ts index 1f559664d9d0d57597e44744d185fff77e557cf3..60a20c5318db17d7005a4f6cb61eee4c5cdc2917 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; } diff --git a/src/steps/detail/index.tsx b/src/steps/detail/index.tsx index e877424d9c34008e7ba8d9f80766cba711642d87..1b41c365ae589060c099efcdb4465a24681df495 100644 --- a/src/steps/detail/index.tsx +++ b/src/steps/detail/index.tsx @@ -458,6 +458,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/form/index.tsx b/src/steps/form/index.tsx index 27debc884e7aebb4c56d66c25caa4cde4987e33f..ed4e6317deeacd4b9b074816193df64675f4df5c 100644 --- a/src/steps/form/index.tsx +++ b/src/steps/form/index.tsx @@ -316,7 +316,6 @@ export default class FormStep extends Step { 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 } @@ -671,6 +670,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 && (this.formFields[formFieldIndex] = null) return null } let hidden: boolean = true diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 44071b1d7968cf6e30e5b03e52f95d66dc79c074..f28a1aa1214b30b1a8c115dee6cdff194d2389ec 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -9,7 +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 StatementHelper, { StatementConfig } from '../../util/statement' +import marked from 'marked' /** * 表格步骤配置文件格式定义 * - field: 表格列表数据来源字段 @@ -32,6 +33,13 @@ export interface TableConfig extends StepConfig { current?: string pageSize?: string total?: string + }, + description?: { + type: 'text' | 'tooltip' | 'modal' + label?: StatementConfig + mode: 'plain' | 'markdown' | 'html' + content?: StatementConfig + showIcon: boolean } } @@ -43,6 +51,7 @@ export interface TableOperationGroupConfig { label?: string level?: 'normal' | 'primary' | 'danger' operations: Array + align: 'left' | 'right' } /** @@ -56,6 +65,7 @@ export interface TableOperationConfig { confirm?: { enable: false } | TableOperationConfirmConfig handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig + align: 'left' | 'right' } export interface TableCCMSOperationConfig { @@ -110,7 +120,13 @@ export interface ITable { onChange: (page: number, pageSize: number) => void } tableOperations: React.ReactNode | null - multirowOperations: React.ReactNode | null + multirowOperations: React.ReactNode | null, + description?: { + type: 'text' | 'tooltip' | 'modal' + label: string | undefined + content: React.ReactNode + showIcon: boolean + } } /** @@ -143,6 +159,7 @@ export interface ITableStepTableOperation { export interface ITableStepRowOperationButton { label: string level: 'normal' | 'primary' | 'danger' + align: 'left' | 'right' disabled?: boolean onClick: () => Promise } @@ -153,6 +170,7 @@ export interface ITableStepRowOperationButton { export interface ITableStepRowOperationGroup { label?: string children: React.ReactNode[] + align: 'left' | 'right' } /** @@ -474,7 +492,7 @@ export default class TableStep extends Step { 您当前使用的UI版本没有实现Table组件的OperationGroupItem部分。 } - + renderOperationModal = (props: ITableStepOperationModal) => { const mask = document.createElement('DIV') mask.style.position = 'fixed' @@ -501,7 +519,8 @@ export default class TableStep extends Step { primary, columns, operations, - pagination + pagination, + description }, data, step, @@ -526,7 +545,6 @@ export default class TableStep extends Step { if (Object.prototype.toString.call(getDate) !== '[object Array]') { getDate = [] } - const props: ITable = { title: label, width, @@ -534,7 +552,6 @@ export default class TableStep extends Step { 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, @@ -609,7 +626,44 @@ export default class TableStep extends Step { : null, multirowOperations: null } - + if(description) { + if(description.type === 'text') { + props.description = { + type: 'text', + 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: StatementHelper(description.label, { data: this.props.data, step: this.props.step }), + content: description.content, + showIcon: description.showIcon + } + } else { + props.description = { + type: '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 + } + } + } 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)) @@ -663,6 +717,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) } })} @@ -672,6 +727,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 diff --git a/src/util/enumeration.ts b/src/util/enumeration.ts index 0b3c41d09c39b7e18f7678360c86e0a0251de4a7..f56f4131fecde5958d5147e05da875a55d62a31e 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 +} diff --git a/src/util/value.ts b/src/util/value.ts index 35a8463c108798c0d5b2015bbddbd7714fa1833a..d45ae5c5d0601ac9dd3c23bd1d05f96521f2e9f3 100644 --- a/src/util/value.ts +++ b/src/util/value.ts @@ -114,10 +114,32 @@ 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 } + +/** + * 转化value数组中的值类型 + * @param list value数组 + * @param type 值类型 + * @returns value数组 + */ +export const transformValueType = (list: any[], type: string | undefined) => { + 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 + } +}