king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
src/templates/sharecomponent/chartgroupcomponent/chartform/index.jsx
@@ -18,6 +18,9 @@
import card3 from '@/assets/img/card3.png'
import card4 from '@/assets/img/card4.png'
import card5 from '@/assets/img/card5.png'
import card6 from '@/assets/img/card6.png'
import card7 from '@/assets/img/card7.png'
import card8 from '@/assets/img/card8.png'
import './index.scss'
const syslegends = {
@@ -121,14 +124,29 @@
      subelement: ['content', 'avatar']
    },
    {
      uuid: 'card6',
      url: card6,
      subelement: ['content', 'header']
    },
    {
      uuid: 'card3',
      url: card3,
      subelement: ['content', 'avatar', 'header']
    },
    {
      uuid: 'card8',
      url: card8,
      subelement: ['content', 'bottom']
    },
    {
      uuid: 'card4',
      url: card4,
      subelement: ['content', 'avatar', 'bottom']
    },
    {
      uuid: 'card7',
      url: card7,
      subelement: ['content', 'header', 'bottom']
    },
    {
      uuid: 'card5',
@@ -192,18 +210,18 @@
      columns: _columns,
      selectlegend: _selectlegend,
      formlist: formlist.map(item => {
        if (item.key === 'height' && ['table', 'card'].includes(_type)) {
        if (item.key === 'actions' && ['table'].includes(_type)) { // 按钮组
          item.hidden = true
        } else if (item.key === 'widthType' && _type === 'card') {
          item.hidden = false
        } else if (item.key === 'height' && ['table', 'card'].includes(_type)) {
          item.hidden = true
        } else if (item.key === 'cardWidth' && _type === 'card') {
          item.hidden = false
        } else if (item.key === 'over' && _type === 'card') {
          item.hidden = false
        } else if (item.key === 'border' && _type === 'card') {
          item.hidden = false
        } else if (item.key === 'switch' && _type === 'card') {
          item.hidden = false
        } else if (item.key === 'extraAction') {
          item.hidden = _type !== 'card'
        } else if (item.key === 'bgfield') {
          item.hidden = _type !== 'card'
        }
@@ -219,7 +237,7 @@
      try {
        let _form = document.getElementById('title')
        _form.select()
      } catch {
      } catch (e) {
        console.warn('表单focus失败!')
      }
    }
@@ -234,7 +252,6 @@
  }
  typeChange = (key, value) => {
    const { card } = this.props
    let formlist = JSON.parse(JSON.stringify(this.props.formlist))
    if (key === 'chartType') {
@@ -242,66 +259,21 @@
        legends: syslegends[value] || null,
        selectlegend: syslegends[value] ? syslegends[value][0] : null,
        formlist: formlist.map(item => {
          if (item.key === 'height' && ['table', 'card'].includes(value)) {
          if (item.key === 'actions' && ['table'].includes(value)) { // 按钮组
            item.hidden = true
          } else if (item.key === 'widthType' && value === 'card') {
            item.hidden = false
          } else if (item.key === 'height' && ['table', 'card'].includes(value)) {
            item.hidden = true
          } else if (item.key === 'cardWidth' && value === 'card') {
            item.min = card.widthType === 'absolute' ? 50 : 1
            item.max = card.widthType === 'absolute' ? 1000 : 24
            item.hidden = false
          } else if (item.key === 'over' && value === 'card') {
            item.hidden = false
          } else if (item.key === 'border' && value === 'card') {
            item.hidden = false
          } else if (item.key === 'switch' && value === 'card') {
            item.hidden = false
          } else if (item.key === 'extraAction') {
            item.hidden = value !== 'card'
          } else if (item.key === 'bgfield') {
            item.hidden = value !== 'card'
          }
          return item
        })
      })
    }
  }
  radioChange = (val, key) => {
    const { formlist } = this.state
    if (key === 'widthType') {
      this.setState({
        formlist: formlist.map(item => {
          if (item.key === 'cardWidth') {
            item.min = val === 'absolute' ? 50 : 1
            item.max = val === 'absolute' ? 1000 : 24
          }
          return item
        })
      })
    } else if (key === 'over' && val === 'roll') {
      this.setState({
        formlist: formlist.map(item => {
          if (item.key === 'cardWidth') {
            item.min = 50
            item.max = 1000
          } else if (item.key === 'widthType') {
            item.readonly = true
          }
          return item
        })
      })
      if (this.props.form.getFieldValue('widthType') !== undefined) {
        this.props.form.setFieldsValue({widthType: 'absolute'})
      }
    } else if (key === 'over' && val === 'whole') {
      this.setState({
        formlist: formlist.map(item => {
          if (item.key === 'widthType') {
            item.readonly = false
          }
          return item
        })
      })
@@ -317,6 +289,7 @@
  getFields() {
    const { getFieldDecorator } = this.props.form
    const fields = []
    this.state.formlist.forEach((item, index) => {
      if (item.hidden) return
      
@@ -369,7 +342,12 @@
      } else if (item.type === 'select') { // 下拉搜索
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.label}>
            <Form.Item label={item.tooltip ?
              <Tooltip placement="topLeft" overlayClassName={item.tooltipClass} title={item.tooltip}>
                <Icon type="question-circle" />
                {item.label}
              </Tooltip> : item.label
            }>
              {getFieldDecorator(item.key, {
                initialValue: item.initVal || '',
                rules: [
@@ -399,7 +377,12 @@
      } else if (item.type === 'radio') {
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.label}>
            <Form.Item label={item.tooltip ?
              <Tooltip placement="topLeft" overlayClassName={item.tooltipClass} title={item.tooltip}>
                <Icon type="question-circle" />
                {item.label}
              </Tooltip> : item.label
            }>
              {getFieldDecorator(item.key, {
                initialValue: item.initVal,
                rules: [
@@ -409,7 +392,7 @@
                  }
                ]
              })(
                <Radio.Group onChange={(e) => this.radioChange(e.target.value, item.key)} disabled={item.readonly}>
                <Radio.Group disabled={item.readonly}>
                  {
                    item.options.map(option => {
                      return (
@@ -425,7 +408,12 @@
      } else if (item.type === 'multiselect') { // 多选
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.label}>
            <Form.Item label={item.tooltip ?
              <Tooltip placement="topLeft" overlayClassName={item.tooltipClass} title={item.tooltip}>
                <Icon type="question-circle" />
                {item.label}
              </Tooltip> : item.label
            }>
              {getFieldDecorator(item.key, {
                initialValue: item.initVal || []
              })(
@@ -463,7 +451,7 @@
            card: 'credit-card'
          }
          if (result.chartType === 'line' || result.chartType === 'bar' || result.chartType === 'line') {
          if (result.chartType === 'line' || result.chartType === 'bar' || result.chartType === 'pie') {
            if (selectlegend && this.props.card.modelId !== selectlegend.uuid) {
              result = {...result, ...selectlegend.options}
            }
@@ -484,8 +472,8 @@
            if (!result.details) {
              result.details = [
                {elemType: 'detail', bold: 'true', uuid: 'cardtitle', content: 'Card title', datatype: 'static', align: 'left'},
                {elemType: 'detail',bold: 'false', uuid: 'carddescription', content: 'Card content', datatype: 'static', align: 'left'}
                {elemType: 'detail', fontWeight: 'normal', fontSize: 14, width: 100, height: 1, uuid: 'cardtitle', content: 'Card content', datatype: 'static', align: 'left'},
                {elemType: 'detail', fontWeight: 'normal', fontSize: 14, width: 100, height: 1, uuid: 'carddescription', content: 'Card content', datatype: 'static', align: 'left'}
              ]
              result.bottom = {
                elemType: 'bottom',
@@ -505,8 +493,9 @@
                type: 'picture',
                field: '',
                size: 14,
                widthType: 'absolute',
                width: 32
                width: 32,
                radius: 'true',
                display: 'inline'
              }
            }
@@ -544,7 +533,7 @@
        <Row gutter={24}>{this.getFields()}</Row>
        {legends ? <Row gutter={24} className="chart-model-image">
          {legends.map(item => <Col span={6} key={item.uuid}>
            <img onClick={() => this.changeSelectLegend(item)} src={item.url} className={selectlegend.uuid === item.uuid ? 'active' : ''} alt=""/>
            <img onClick={() => this.changeSelectLegend(item)} src={item.url} className={selectlegend && selectlegend.uuid === item.uuid ? 'active' : ''} alt=""/>
          </Col>)}
        </Row> : null}
      </Form>