From 0f6c07ed2f8dddd3ad6e37268bf06df6d82961ed Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 24 五月 2024 17:57:30 +0800 Subject: [PATCH] 2024-05-24 --- src/menu/modalconfig/formfork/index.jsx | 186 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 170 insertions(+), 16 deletions(-) diff --git a/src/menu/modalconfig/formfork/index.jsx b/src/menu/modalconfig/formfork/index.jsx index 0a37edd..30a865c 100644 --- a/src/menu/modalconfig/formfork/index.jsx +++ b/src/menu/modalconfig/formfork/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Modal } from 'antd' +import { Modal, Empty, Radio } from 'antd' import { ForkOutlined } from '@ant-design/icons' import './index.scss' @@ -13,6 +13,15 @@ state = { visible: false, + empty: false, + ctrlFields: [], + ctrlRFields: [], + subFields: [], + subRFields: [], + linkFields: [], + tabFields: [], + type: '', + forward: 'true', } shouldComponentUpdate (nextProps, nextState) { @@ -21,12 +30,6 @@ trigger = () => { const { forms } = this.props - - // let linkSubField = [] - // let supField = [] - // let tabField = [] - // let linkField = [] - let linkFields = {} // 鍏宠仈鑿滃崟 let controlFields = {} // 鎺у埗琛ㄥ崟 @@ -48,7 +51,7 @@ } supvals = Array.from(new Set(supvals)) controlFields[item.supField] = controlFields[item.supField] || [] - controlFields[item.supField].push({field: item.field, values: supvals.join(',')}) + controlFields[item.supField].push({field: item.field, values: supvals.join(','), type: item.type}) } else { delete item.supField delete item.supvalue @@ -159,7 +162,9 @@ } else { item.tabLabel = fieldMap.get(item.tabField).label } - } + } else { + delete item.tabField + } } else { delete item.tabField } @@ -184,8 +189,6 @@ delete item.multiple delete item.linkSubField - // if (!item.controlFields && !item.linkFields && !item.subFields && !item.resubFields) - fieldMap.set(item.field, item) }) @@ -208,30 +211,181 @@ }) } }) - + + let _n = [...fieldMap.values()] + + let ctrlFields = [] + let ctrlRFields = [] + let subFields = [] + let subRFields = [] + let _linkFields = [] + let tabFields = [] + + _n.forEach(cell => { + if (cell.controlFields) { + ctrlFields.push({ + field: cell.field, + label: cell.label, + children: cell.controlFields.map(m => { + return { + field: ['hint', 'split', 'formula'].includes(m.type) ? '' : m.field, + label: m.label, + tail: `${m.values}` + } + }) + }) + } + if (cell.supField) { + ctrlRFields.push({ + field: ['hint', 'split', 'formula'].includes(cell.type) ? '' : cell.field, + label: cell.label, + children: [{ + field: cell.supField, + label: cell.supLabel, + tail: `${cell.supvalue}` + }] + }) + } + + if (cell.subFields) { + subFields.push({ + field: cell.field, + label: cell.label, + children: cell.subFields + }) + } + if (cell.resubFields) { + subRFields.push({ + field: cell.field, + label: cell.label, + children: cell.resubFields + }) + } + if (cell.linkFields) { + _linkFields.push({ + field: cell.field, + label: cell.label, + children: cell.linkFields + }) + } + if (cell.tabField) { + tabFields.push({ + field: cell.field, + label: cell.label, + children: [{ + field: cell.tabField, + label: cell.tabLabel, + }] + }) + } + }) + + let type = '' + if (ctrlFields.length > 0) { + type = 'ctrl' + } else if (subFields.length > 0) { + type = 'input' + } else if (_linkFields.length > 0) { + type = 'link' + } else if (tabFields.length > 0) { + type = 'switch' + } + this.setState({ + type, + forward: 'true', + empty: type === '', + ctrlFields, + ctrlRFields, + subFields, + subRFields, + linkFields: _linkFields, + tabFields, visible: true }) } + getcontent = () => { + const { ctrlFields, ctrlRFields, subFields, subRFields, linkFields, tabFields, visible, type, forward } = this.state + + if (!visible) return null + + let header = <div className="fork-tabs"> + {ctrlFields.length ? <div onClick={() => this.setState({type: 'ctrl', forward: 'true'})} className={'tab-item' + (type === 'ctrl' ? ' active' : '')}>琛ㄥ崟鎺у埗</div> : null} + {subFields.length ? <div onClick={() => this.setState({type: 'input', forward: 'true'})} className={'tab-item' + (type === 'input' ? ' active' : '')}>琛ㄥ崟濉厖</div> : null} + {linkFields.length ? <div onClick={() => this.setState({type: 'link', forward: 'true'})} className={'tab-item' + (type === 'link' ? ' active' : '')}>琛ㄥ崟鍏宠仈</div> : null} + {tabFields.length ? <div onClick={() => this.setState({type: 'switch', forward: 'true'})} className={'tab-item' + (type === 'switch' ? ' active' : '')}>琛ㄥ崟鍒囨崲</div> : null} + </div> + + let items = [] + + if (type === 'ctrl') { + if (forward === 'true') { + items = ctrlFields + } else { + items = ctrlRFields + } + } else if (type === 'input') { + if (forward === 'true') { + items = subFields + } else { + items = subRFields + } + } else if (type === 'link') { + items = linkFields + } else if (type === 'switch') { + items = tabFields + } + + let content = items.map((item, i) => { + return <div className="fork-item-wrap" key={i}> + <div className="fork-left"> + <div className="fork-item"> + <span>{item.label}</span> + <span>{item.field}</span> + </div> + </div> + <div className="fork-right"> + {item.children.map((cell, n) => <div className="fork-item" key={n}> + <span>{cell.label}</span> + <span>{cell.field}</span> + {cell.tail ? <span className="fork-tail">{cell.tail}</span> : null} + </div>)} + </div> + </div> + }) + + return <div> + {header} + {type === 'ctrl' || type === 'input' ? <div className="forward-wrap"><Radio.Group value={forward} onChange={(e) => this.setState({forward: e.target.value})}> + <Radio value="true">姝e悜</Radio> + <Radio value="false">鍙嶅悜</Radio> + </Radio.Group></div> : null} + <div className="fork-wrap"> + {content} + </div> + </div> + } + render() { - const { visible } = this.state + const { visible, empty } = this.state return ( <> <ForkOutlined title="琛ㄥ崟鍏崇郴鍥�" onClick={this.trigger}/> <Modal - title="琛ㄥ崟鍏崇郴鍥�" + title={empty ? '琛ㄥ崟鍏崇郴鍥�' : ''} wrapClassName="form-fork-modal mk-scroll-modal" visible={visible} width={900} - maskClosable={false} + maskClosable={true} + closable={false} cancelText="鍏抽棴" onOk={() => { this.setState({ visible: false })}} onCancel={() => { this.setState({ visible: false })}} destroyOnClose > - + {empty ? <Empty description="鏃犺〃鍗曞叧鑱斾俊鎭��" /> : this.getcontent()} </Modal> </> ) -- Gitblit v1.8.0