From afb39f8ab004b2607bb718edab02e99c7a010114 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 22 三月 2023 14:36:44 +0800 Subject: [PATCH] 2023-03-22 --- src/menu/components/chart/antv-bar/chartcompile/index.jsx | 165 +++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 125 insertions(+), 40 deletions(-) diff --git a/src/menu/components/chart/antv-bar/chartcompile/index.jsx b/src/menu/components/chart/antv-bar/chartcompile/index.jsx index b2d1d56..f0bfcc6 100644 --- a/src/menu/components/chart/antv-bar/chartcompile/index.jsx +++ b/src/menu/components/chart/antv-bar/chartcompile/index.jsx @@ -2,7 +2,7 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { Modal, Form, Row, Col, Select, Radio, Tooltip, Input, InputNumber, Tabs, Button } from 'antd' -import { QuestionCircleOutlined, EditOutlined } from '@ant-design/icons' +import { QuestionCircleOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons' import Utils from '@/utils/utils.js' import { chartColors } from '@/utils/option.js' @@ -17,7 +17,6 @@ class LineChartDrawerForm extends Component { static propTpyes = { - dict: PropTypes.object, plot: PropTypes.object, config: PropTypes.object, plotchange: PropTypes.func @@ -45,6 +44,18 @@ inputType: 'color', editable: true, width: '40%', + render: (text, record) => { + return (<div style={{width: '80px', height: '23px', background: text}}></div>) + } + }, + ], + barColorColumns: [ + { + title: '棰滆壊', + dataIndex: 'color', + inputType: 'color', + editable: true, + width: '70%', render: (text, record) => { return (<div style={{width: '80px', height: '23px', background: text}}></div>) } @@ -262,20 +273,41 @@ } }) - if (config.plot.correction) { - delete config.plot.correction // 鏁版嵁淇锛堝凡寮冪敤锛� - config.plot.barSize = 35 + let plot = fromJS(config.plot).toJS() + + if (plot.correction) { + delete plot.correction // 鏁版嵁淇锛堝凡寮冪敤锛� + plot.barSize = 35 + } + + if (plot.datatype !== 'statistics') { + if (plot.colors) { + plot.colors = plot.colors.map(item => { + if (fieldName[item.type]) { + item.label = fieldName[item.type] + } + return item + }) + } + if (plot.customs) { + plot.customs = plot.customs.map(item => { + if (fieldName[item.type]) { + item.name = fieldName[item.type] + } + return item + }) + } } this.setState({ visible: true, view: 'normal', - ramp: config.plot.ramp || 'false', - datatype: config.plot.datatype || 'query', + ramp: plot.ramp || 'false', + datatype: plot.datatype || 'query', fieldName: fieldName, - plot: fromJS(config.plot).toJS(), - baseFormlist: getBaseForm(config.plot, config.columns), - formlist: getOptionForm(config.plot, config.columns) + plot: plot, + baseFormlist: getBaseForm(plot, config.columns), + formlist: getOptionForm(plot, config.columns) }) } @@ -344,7 +376,7 @@ rules: [ { required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' + message: '璇疯緭鍏�' + item.label + '!' } ] })(<Input placeholder="" autoComplete="off" disabled={item.readonly} onPressEnter={this.onSubmit}/>)} @@ -365,7 +397,7 @@ rules: [ { required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' + message: '璇疯緭鍏�' + item.label + '!' } ] })(<InputNumber min={item.min} max={item.max} precision={item.decimal} onPressEnter={this.onSubmit}/>)} @@ -386,7 +418,7 @@ rules: [ { required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' + message: '璇烽�夋嫨' + item.label + '!' } ] })( @@ -415,7 +447,7 @@ rules: [ { required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' + message: '璇烽�夋嫨' + item.label + '!' } ] })( @@ -497,17 +529,39 @@ if (!err) { let _plot = {...plot, ...values} - if (values.datatype === 'statistics' || values.datatype !== plot.datatype) { - _plot.enabled = 'false' - _plot.customs = [] - } else if (!values.Yaxis || !plot.Yaxis || !is(fromJS(values.Yaxis), fromJS(plot.Yaxis))) { - _plot.enabled = 'false' - _plot.customs = [] - _plot.colors = null - } - if (values.datatype !== plot.datatype) { _plot.colors = null + } + if (values.datatype === 'statistics') { + _plot.enabled = 'false' + _plot.customs = [] + delete _plot.Yaxis + } else if (!is(fromJS(values.Yaxis), fromJS(plot.Yaxis || []))) { + _plot.enabled = 'false' + _plot.colors = null + + let labels = {} + config.columns.forEach(col => { + labels[col.field] = col.label + }) + + let cus = {} + _plot.customs && _plot.customs.forEach(m => { + cus[m.type] = m + }) + _plot.customs = _plot.Yaxis.map((item, i) => { + if (cus[item]) return cus[item] + + return { + uuid: Utils.getuuid(), + type: item, + name: labels[item] || item, + axis: i === 0 ? 'true' : 'false', + label: 'false', + title: 'true', + shape: _plot.chartType === 'bar' && i === 0 ? ['bar', 'rect'] : ['line', 'smooth'] + } + }) } this.setState({ @@ -580,22 +634,29 @@ if (!err) { let _plot = {...plot, ...values} - if (values.datatype === 'statistics' || values.datatype !== plot.datatype) { - _plot.enabled = 'false' - _plot.customs = [] - } else if (!values.Yaxis || !plot.Yaxis || !is(fromJS(values.Yaxis), fromJS(plot.Yaxis))) { - _plot.enabled = 'false' - _plot.customs = [] - _plot.colors = null - } - let labels = {} config.columns.forEach(col => { labels[col.field] = col.label }) - if (values.datatype !== 'statistics' && (!_plot.customs || _plot.customs.length === 0)) { + if (values.datatype !== plot.datatype) { + _plot.colors = null + } + if (values.datatype === 'statistics') { + _plot.enabled = 'false' + _plot.customs = [] + delete _plot.Yaxis + } else if (!is(fromJS(values.Yaxis), fromJS(plot.Yaxis || []))) { + _plot.enabled = 'false' + _plot.colors = null + + let cus = {} + _plot.customs && _plot.customs.forEach(m => { + cus[m.type] = m + }) _plot.customs = _plot.Yaxis.map((item, i) => { + if (cus[item]) return cus[item] + return { uuid: Utils.getuuid(), type: item, @@ -607,7 +668,8 @@ } }) } - if (values.datatype !== plot.datatype || !_plot.colors) { + + if (!_plot.colors) { _plot.colors = [] if (_plot.datatype === 'query') { let limit = chartColors.length @@ -695,10 +757,28 @@ this.setState({plot}) } + addbarColor = () => { + let plot = fromJS(this.state.plot).toJS() + plot.barcolors = plot.barcolors || [] + + plot.barcolors.push({ + uuid: Utils.getuuid(), + color: 'rgb(91, 143, 249)' + }) + + this.setState({plot}) + } + changeColor = (colors) => { const { plot } = this.state this.setState({plot: {...plot, colors}}) + } + + changebarColor = (colors) => { + const { plot } = this.state + + this.setState({plot: {...plot, barcolors: colors}}) } changeCustom = (customs) => { @@ -709,7 +789,7 @@ render() { const { config } = this.props - const { view, visible, datatype, plot, ramp, colorColumns, rampColorColumns, statColorColumns, rampStatColorColumns, cusColumns, baseFormlist } = this.state + const { view, visible, datatype, plot, ramp, colorColumns, barColorColumns, rampColorColumns, statColorColumns, rampStatColorColumns, cusColumns, baseFormlist } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -725,8 +805,7 @@ <div className="line-chart-drawer-form"> <EditOutlined title="缂栬緫" onClick={this.showDrawer}/> <Modal - wrapClassName="popview-modal menu-chart-edit-modal" - title={config.type === 'bar' ? '鏌辩姸鍥剧紪杈�' : '鎶樼嚎鍥剧紪杈�'} + wrapClassName="mk-pop-modal" visible={visible} width={1000} maskClosable={false} @@ -734,9 +813,10 @@ onCancel={() => { this.setState({ visible: false }) }} destroyOnClose > + {config.name ? <div className="mk-com-name">{config.name} - 缂栬緫</div> : null} <Tabs activeKey={view} className="menu-chart-edit-box" onChange={this.changeTab}> <TabPane tab="缁勪欢璁剧疆" key="base"> - <NormalForm dict={this.props.dict} formlist={baseFormlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.baseRef = inst}/> + <NormalForm formlist={baseFormlist} inputSubmit={this.onSubmit} wrappedComponentRef={(inst) => this.baseRef = inst}/> </TabPane> <TabPane tab="鍥捐〃璁剧疆" key="normal"> <Form {...formItemLayout}> @@ -765,12 +845,17 @@ </Form.Item> </Form> </Col> : null} - {datatype === 'statistics' ? <Button className="color-add mk-green" onClick={this.addColor}>{this.props.dict['model.add']}</Button> : null} + {datatype === 'statistics' ? <Button className="color-add mk-green" onClick={this.addColor}>娣诲姞</Button> : null} {datatype === 'statistics' ? <EditTable actions={['edit', 'move', 'del']} data={plot.colors || []} columns={ramp ==='true' ? rampStatColorColumns : statColorColumns} onChange={this.changeColor}/> : null} {datatype !== 'statistics' ? <EditTable actions={['edit']} data={plot.colors || []} columns={ramp ==='true' ? rampColorColumns : colorColumns} onChange={this.changeColor}/> : null} + {plot.chartType === 'bar' && plot.datatype === 'query' ? <div className="mk-bar-colors"> + <p>鏌卞舰棰滆壊锛氬彲鏍规嵁鏌卞浘搴忓彿璁剧疆棰滆壊锛堣璁剧疆鏌卞舰瀹藉害锛夈�傛敞锛氫娇鐢ㄨ嚜瀹氫箟鍥惧舰璁剧疆鎴栧鏍规煴鍥炬椂鏃犳晥銆�</p> + <div className="bar-color-add"><PlusOutlined onClick={this.addbarColor}/></div> + <EditTable actions={['edit', 'move', 'del']} data={plot.barcolors || []} columns={barColorColumns} onChange={this.changebarColor}/> + </div> : null} </div> </TabPane> : null} - {plot ? <TabPane tab="鑷畾涔夎缃�" disabled={datatype === 'statistics'} key="custom"> + {plot ? <TabPane tab="鑷畾涔夊浘褰㈣缃�" disabled={datatype === 'statistics'} key="custom"> <Col span={12}> <Form {...formItemLayout}> <Form.Item label="鏄惁鍚敤" style={{marginBottom: 10}}> -- Gitblit v1.8.0