king
2022-04-26 5046d0d13dc6a8563b8e54e31913bc44cfa1072f
src/menu/components/card/cardcellcomponent/elementform/index.jsx
@@ -15,8 +15,8 @@
const cardTypeOptions = {
  sequence: ['eleType', 'width'],
  text: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix', 'link', 'noValue'],
  number: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix'],
  text: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix', 'link', 'noValue', 'bgImage', 'fixStyle'],
  number: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix', 'noValue', 'fixStyle'],
  picture: ['eleType', 'datatype', 'width', 'lenWidRadio', 'maxWidth', 'link', 'noValue'],
  video: ['eleType', 'datatype', 'width', 'aspectRatio', 'autoPlay', 'loop', 'noValue'],
  icon: ['eleType', 'icon', 'datatype', 'width'],
@@ -24,8 +24,8 @@
  splitline: ['eleType', 'color', 'width', 'borderWidth'],
  barcode: ['eleType', 'datatype', 'width', 'barHeight', 'displayValue', 'interval', 'noValue'],
  qrcode: ['eleType', 'datatype', 'width', 'qrWidth', 'color', 'url', 'noValue'],
  currentDate: ['eleType', 'width', 'dateFormat', 'prefix', 'postfix'],
  formula: ['eleType', 'width', 'height', 'prefix', 'postfix', 'eval', 'formula'],
  currentDate: ['eleType', 'width', 'dateFormat', 'prefix', 'postfix', 'fixStyle'],
  formula: ['eleType', 'width', 'height', 'prefix', 'postfix', 'eval', 'formula', 'noValue', 'fixStyle'],
}
class MainSearch extends Component {
@@ -43,12 +43,13 @@
    datatype: '',
    showType: '',
    showInfo: 'false',
    fixStyle: '',
    link: ''
  }
  UNSAFE_componentWillMount () {
    const { card, config } = this.props
    let _options = this.getOptions(card.eleType, card.datatype, card.link, (card.showType || 'line'), card.showInfo)
    let _options = this.getOptions(card.eleType, card.datatype, card.link, (card.showType || 'line'), card.showInfo, card.fixStyle || '')
    
    this.setState({
      link: card.link,
@@ -56,21 +57,26 @@
      datatype: card.datatype,
      showType: card.showType || 'line',
      showInfo: card.showInfo || 'false',
      fixStyle: card.fixStyle || '',
      formlist: this.props.formlist.map(item => {
        item.hidden = !_options.includes(item.key)
        if (item.key === 'field' || item.key === 'linkurl') {
        if (item.key === 'field' || item.key === 'linkurl' || item.key === 'bgImage') {
          item.options = []
          config.columns.forEach(col => {
            let label = col.label
            if (label !== col.field) {
              label = col.field + ' ' + col.label
            }
            if (/^(Int|Decimal)/ig.test(col.datatype) && (card.eleType === 'number' || card.eleType === 'slider')) {
              item.options.push({
                value: col.field,
                text: col.label
                text: label
              })
            } else if (/^(Nvarchar|date)/ig.test(col.datatype) && card.eleType !== 'number' && card.eleType !== 'slider') {
              item.options.push({
                value: col.field,
                text: col.label
                text: label
              })
            }
          })
@@ -95,12 +101,15 @@
    })
  }
  getOptions = (eleType, datatype, link, showType, showInfo) => {
  getOptions = (eleType, datatype, link, showType, showInfo, fixStyle) => {
    let _options = fromJS(cardTypeOptions[eleType]).toJS() // 选项列表
    
    if (['text', 'number', 'picture', 'slider', 'barcode', 'qrcode', 'video'].includes(eleType)) {
      if (datatype === 'dynamic') {
        _options.push('field')
        if (eleType === 'number') {
          _options.push('decimal')
        }
      } else if (eleType === 'picture' || eleType === 'video') {
        _options.push('url')
      } else {
@@ -128,6 +137,9 @@
        _options.push('tooltip')
      }
    }
    if (_options.includes('fixStyle') && fixStyle === 'alone') {
      _options.push('fixSize', 'fixColor', 'fixLeft', 'fixRight')
    }
    return _options
  }
@@ -140,10 +152,10 @@
   */
  selectChange = (key, value, option) => {
    const { card, config } = this.props
    const { datatype, eleType, showType, showInfo } = this.state
    const { datatype, eleType, showType, showInfo, fixStyle } = this.state
    if (key === 'eleType') {
      let _options = this.getOptions(value, datatype, '', showType, showInfo)
      let _options = this.getOptions(value, datatype, '', showType, showInfo, fixStyle)
      
      let _formlist = this.state.formlist.map(item => {
        item.hidden = !_options.includes(item.key)
@@ -151,15 +163,20 @@
        if (item.key === 'field') {
          item.options = []
          config.columns.forEach(col => {
            let label = col.label
            if (label !== col.field) {
              label = col.field + ' ' + col.label
            }
            if (/^(Int|Decimal)/ig.test(col.datatype) && (value === 'number' || value === 'slider')) {
              item.options.push({
                value: col.field,
                text: col.label
                text: label
              })
            } else if (/^(Nvarchar|date)/ig.test(col.datatype) && value !== 'number' && value !== 'slider') {
              item.options.push({
                value: col.field,
                text: col.label
                text: label
              })
            }
          })
@@ -181,6 +198,8 @@
          item.required = value !== 'qrcode'
        } else if (item.key === 'showInfo') {
          item.initVal = showInfo
        } else if (item.key === 'fixStyle') {
          item.initVal = fixStyle
        }
        return item
@@ -210,7 +229,7 @@
        this.props.form.setFieldsValue({value: option.props.title})
      }
    } else if (key === 'link') {
      let _options = this.getOptions(eleType, datatype, value, showType, showInfo)
      let _options = this.getOptions(eleType, datatype, value, showType, showInfo, fixStyle)
      this.setState({
        link: value,
        formlist: this.state.formlist.map(item => {
@@ -225,11 +244,11 @@
  }
  onChange = (e, key) => {
    const { eleType, datatype, link, showType, showInfo } = this.state
    const { eleType, datatype, link, showType, showInfo, fixStyle } = this.state
    let value = e.target.value
    if (key === 'datatype') {
      let _options = this.getOptions(eleType, value, link, showType, showInfo)
      let _options = this.getOptions(eleType, value, link, showType, showInfo, fixStyle)
      this.setState({
        datatype: value,
@@ -240,7 +259,7 @@
        })
      })
    } else if (key === 'link') {
      let _options = this.getOptions(eleType, datatype, value, showType, showInfo)
      let _options = this.getOptions(eleType, datatype, value, showType, showInfo, fixStyle)
      this.setState({
        link: value,
        formlist: this.state.formlist.map(item => {
@@ -252,7 +271,7 @@
        })
      })
    } else if (key === 'showInfo') {
      let _options = this.getOptions(eleType, datatype, link, showType, value)
      let _options = this.getOptions(eleType, datatype, link, showType, value, fixStyle)
      this.setState({
        showInfo: value,
        formlist: this.state.formlist.map(item => {
@@ -264,7 +283,19 @@
      this.setState({
        showType: value
      }, () => {
        let _options = this.getOptions(eleType, datatype, link, value, showInfo)
        let _options = this.getOptions(eleType, datatype, link, value, showInfo, fixStyle)
        this.setState({
          formlist: this.state.formlist.map(item => {
            item.hidden = !_options.includes(item.key)
            return item
          })
        })
      })
    } else if (key === 'fixStyle') {
      this.setState({
        fixStyle: value
      }, () => {
        let _options = this.getOptions(eleType, datatype, link, showType, showInfo, value)
        this.setState({
          formlist: this.state.formlist.map(item => {
            item.hidden = !_options.includes(item.key)
@@ -290,7 +321,7 @@
    this.state.formlist.forEach((item, index) => {
      if (item.hidden || item.forbid) return
      if (item.type === 'text') { // 文本搜索
      if (item.type === 'text') {
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.tooltip ?
@@ -315,7 +346,7 @@
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'textarea') { // 文本搜索
      } else if (item.type === 'textarea') {
        fields.push(
          <Col span={24} className="textarea" key={index}>
            <Form.Item label={item.tooltip ?
@@ -377,7 +408,8 @@
              })(
                <Select
                  showSearch
                  filterOption={(input, option) => option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0}
                  allowClear={item.allowClear || false}
                  filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                  onChange={(value, option) => {this.selectChange(item.key, value, option)}}
                  getPopupContainer={() => document.getElementById('card-winter')}
                >