From eec619b6e3339e9999a7a1c2c5454cef5d763b24 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 29 四月 2022 18:38:55 +0800 Subject: [PATCH] 2022-04-29 --- src/menu/modalconfig/index.jsx | 135 +++++++++++++++++++++++++++++++------------- 1 files changed, 94 insertions(+), 41 deletions(-) diff --git a/src/menu/modalconfig/index.jsx b/src/menu/modalconfig/index.jsx index fc2a91e..aba31bb 100644 --- a/src/menu/modalconfig/index.jsx +++ b/src/menu/modalconfig/index.jsx @@ -4,7 +4,8 @@ import { DndProvider } from 'react-dnd' import HTML5Backend from 'react-dnd-html5-backend' import moment from 'moment' -import { Button, Card, Modal, Collapse, notification, Icon, Switch } from 'antd' +import { Button, Card, Modal, Collapse, notification, Switch } from 'antd' +import { SettingOutlined } from '@ant-design/icons' import Api from '@/api' import Utils from '@/utils/utils.js' @@ -65,6 +66,7 @@ componentDidMount () { MKEmitter.addListener('completeSave', this.completeSave) + MKEmitter.addListener('submitStyle', this.getStyle) } /** @@ -75,6 +77,7 @@ return } MKEmitter.removeListener('completeSave', this.completeSave) + MKEmitter.removeListener('submitStyle', this.getStyle) } /** @@ -87,7 +90,7 @@ let _config = fromJS(this.state.config).toJS() if (list.length > _config.fields.length) { - _config.fields = list.filter(item => !item.origin) + _config.fields = list this.setState({ config: _config @@ -113,35 +116,62 @@ let _inputfields = [] let _tabfields = [] let _linkableFields = [] - let _linksupFields = [{ - value: '', - text: '绌�' - }] + let _linksupFields = [] let standardform = null - _inputfields = config.fields.filter(item => item.type === 'text' || item.type === 'number' || item.type === 'textarea' || item.type === 'color') - _tabfields = config.fields.filter(item => card.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) - _tabfields.unshift({field: '', text: '鍘熻〃鍗�'}) - let uniq = new Map() - uniq.set(card.field, true) let index = null + uniq.set(card.field, true) + + let _inputIndex = 1 + let _tabIndex = 1 + let _linkIndex = 1 config.fields.forEach((item, i) => { if (card.uuid === item.uuid) { index = i } + + let label = item.label || '' + if (item.field && item.field.toLowerCase() !== label.toLowerCase()) { + label = label + ' (' + item.field + ')' + } + + if (['text', 'number', 'textarea', 'color'].includes(item.type) && card.field !== item.field) { + _inputfields.push({ + field: item.field, + label: _inputIndex + '銆�' + label + }) + _inputIndex++ + } + if (card.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) { + _tabfields.push({ + field: item.field, + label: _tabIndex + '銆�' + label + }) + _tabIndex++ + } + + if (item.type === 'switch') { + _linksupFields.push({ + field: item.field, + label: _linkIndex + '銆�' + label + }) + } + if (!['select', 'link', 'radio', 'checkcard'].includes(item.type)) return + if (item.type === 'checkcard' && item.multiple === 'true') return // 閫夐」鍗″閫� if (item.field && !uniq.has(item.field)) { uniq.set(item.field, true) _linkableFields.push({ - value: item.field, - text: item.label + ' (琛ㄥ崟)' + field: item.field, + label: _linkIndex + '銆�' + item.label + ' (琛ㄥ崟)' }) _linksupFields.push({ - value: item.field, - text: item.label + field: item.field, + label: _linkIndex + '銆�' + label }) + _linkIndex++ } }) if (index !== null) { @@ -152,14 +182,17 @@ } } + _tabfields.unshift({field: '', label: '鍘熻〃鍗�'}) + componentConfig.columns.forEach(col => { if (col.field && !uniq.has(col.field)) { uniq.set(col.field, true) _linkableFields.push({ - value: col.field, - text: col.label + ' (鏄剧ず鍒�)' + field: col.field, + label: _linkIndex + '銆�' + col.label + ' (鏄剧ず鍒�)' }) + _linkIndex++ } }) @@ -177,7 +210,25 @@ standardform, visible: true, card: card, - formlist: getModalForm(card, _inputfields, _tabfields, _linkableFields, _linksupFields, !!this.props.editTab) + formlist: getModalForm(card, _inputfields, _tabfields, _linkableFields, _linksupFields) + }) + } + + getStyle = (comIds, style) => { + const { config } = this.state + + if (comIds[0] !== 'form') return + + let Index = config.fields.findIndex(n => n.uuid === comIds[1]) + + if (Index === -1) return + + let _config = fromJS(config).toJS() + + _config.fields[Index].style = style + + this.setState({ + config: _config }) } @@ -191,16 +242,16 @@ this.formRef.handleConfirm().then(res => { let _config = fromJS(this.state.config).toJS() let fieldrepet = false // 瀛楁閲嶅 - let labelrepet = false // 鎻愮ず鏂囧瓧閲嶅 _config.fields = _config.fields.map(item => { if (item.uuid !== res.uuid && res.field && item.field && item.field.toLowerCase() === res.field.toLowerCase()) { fieldrepet = true - } else if (res.label && item.uuid !== res.uuid && item.label === res.label) { - labelrepet = true } if (item.uuid === res.uuid) { + if (item.style) { + res.style = item.style + } return res } else { return item @@ -214,16 +265,7 @@ duration: 10 }) return - } else if (labelrepet) { - notification.warning({ - top: 92, - message: '鍚嶇О宸插瓨鍦紒', - duration: 10 - }) - return } - - _config.fields = _config.fields.filter(item => !item.origin) if (['select', 'multiselect', 'link', 'checkbox', 'radio', 'checkcard'].includes(res.type) && res.resourceType === '1' && /\s/.test(res.dataSource)) { this.setState({ @@ -422,6 +464,20 @@ }) } + plusFields = (items) => { + let _config = fromJS(this.state.config).toJS() + + _config.fields.push(...items) + + this.setState({ + config: _config + }, () => { + if (items.length === 1 && items[0].focus) { + this.handleForm(items[0]) + } + }) + } + render () { const { config, dict, saving } = this.state @@ -436,25 +492,21 @@ return (<SourceElement key={index} content={item}/>) })} </div> - <FieldsComponent - config={config} - type="form" - updatefield={this.updateConfig} - /> + <FieldsComponent config={config} type="form" plusFields={this.plusFields}/> </Panel> </Collapse> </div> <div className="setting"> - <Card title={dict['header.menu.form.configurable']} bordered={false} extra={ + <Card title="琛ㄥ崟閰嶇疆" bordered={false} extra={ <div> <Button type="danger" onClick={this.clearConfig}>娓呯┖</Button> - <EditComponent dict={dict} options={['form']} config={this.state.config} refresh={(res) => this.updateConfig(res.config)}/> - <Button type="primary" loading={saving} onClick={this.submitConfig}>淇濆瓨</Button> + <EditComponent dict={dict} options={['form']} config={this.state.config} plusFields={this.plusFields}/> + <Button type="primary" id="save-modal-config" loading={saving} onClick={this.submitConfig}>淇濆瓨</Button> <Button onClick={this.cancelConfig}>杩斿洖</Button> </div> } style={{ width: '100%' }}> - <Icon type="setting" onClick={this.changeSetting} /> - <div className="ant-modal-content" style={{width: config.setting.width + '%'}}> + <SettingOutlined onClick={this.changeSetting} /> + <div className="ant-modal-content" style={{width: config.setting.width > 100 ? config.setting.width : config.setting.width + '%'}}> <div className="ant-modal-header"> <div className="ant-modal-title">{config.setting.title}</div> <Button className="mk-cols-change" onClick={() => this.changecols(1)}>1鍒�</Button> @@ -494,7 +546,8 @@ <Modal title={this.state.dict['model.edit']} visible={this.state.visible} - width={850} + width={950} + maskClosable={false} onCancel={this.editModalCancel} onOk={this.handleSubmit} confirmLoading={this.state.sqlVerifing} -- Gitblit v1.8.0