king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/tabviews/custom/components/carousel/prop-card/index.jsx
@@ -12,6 +12,7 @@
import './index.scss'
const CardItem = asyncComponent(() => import('../cardItem'))
const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
class PropCard extends Component {
  static propTpyes = {
@@ -30,10 +31,11 @@
    visible: false
  }
  loaded = false
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
    let _data = {$$empty: true}
    let _sync = false
@@ -50,7 +52,7 @@
      BID = BData.$BID || ''
    }
    
    if (_config.setting && _config.wrap.datatype === 'dynamic') {
    if (_config.wrap.datatype === 'dynamic') {
      _sync = _config.setting.sync === 'true'
      if (_sync && data) {
@@ -59,35 +61,33 @@
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
      } else if (_sync && initdata) {
        _data = initdata
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
      }
    } else if (_config.wrap.datatype === 'static') {
      this.loaded = true
    }
    _data.$$uuid = _data[_config.setting.primaryKey] || ''
    _data.$$BID = BID || ''
    _data.$$BData = BData || ''
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    if (!_config.wrap.height) { // 兼容
      _config.wrap.height = _config.style.height || '300px'
      delete _config.style.height
    }
    _config.subcards.forEach(card => {
      card.style.height = _config.style.height
      card.style.height = _config.wrap.height
      if (card.setting.click) {
        card.style.cursor = 'pointer'
      }
      card.elements = card.elements.map(item => {
        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
    })
    _config.wrap.speed = (_config.wrap.speed || 3) * 1000
@@ -122,6 +122,17 @@
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
        this.loadData('timer')
      })
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res[0]
        _data.$$uuid = _data[config.setting.primaryKey] || ''
        this.setState({data: _data})
      })
    }
  }
@@ -161,6 +172,8 @@
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      this.loaded = true
      this.setState({sync: false, data: _data}, () => {
        if (config.wrap.display === 'modal') {
          this.openModal()
@@ -173,7 +186,7 @@
    }
  }
  openModal = () => {
  openModal = (ErrCode) => {
    const { config, data } = this.state
    
    let code = config.wrap.code || ('modal' + config.uuid)
@@ -185,6 +198,10 @@
      localStorage.setItem(code, data.$$uuid || 'true')
      Api.getAppVersion(true)
      if (ErrCode === '-1') {
        return
      }
    }
    setTimeout(() => {
@@ -265,6 +282,8 @@
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true}
      })
      this.loaded = true
      return
    }
@@ -288,6 +307,11 @@
    if (result.status) {
      let _data = {}
      this.loaded = true
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      if (!result.data || !result.data[0]) {
        _data.$$empty = true
      } else {
@@ -303,9 +327,16 @@
        loading: false
      }, () => {
        if (config.wrap.display === 'modal') {
          this.openModal()
          this.openModal(result.ErrCode)
        }
      })
      if (config.timer && config.clearField && result.data && result.data[0]) {
        let vals = (config.clearValue || '').split(',')
        if (vals.includes(result.data[0][config.clearField])) {
          this.timer && this.timer.stop()
        }
      }
    } else {
      this.setState({
        loading: false
@@ -353,22 +384,25 @@
        destroyOnClose
      >
        <div className="custom-prop-carousel-box" style={config.style}>
          {config.subcards.length > 1 && config.wrap.autoplay === 'false' ? <div className="prev" onClick={() => this.node && this.node.prev()}><LeftOutlined /></div> : null}
          {config.subcards.length > 1 && config.wrap.autoplay === 'false' ? <div className="next" onClick={() => this.node && this.node.next()}><RightOutlined /></div> : null}
          <Carousel
            autoplay={config.wrap.autoplay !== 'false'}
            dots={config.wrap.dots !== 'false'}
            dotPosition={config.wrap.dotPosition || 'bottom'}
            effect={config.wrap.effect || 'scrollx'}
            autoplaySpeed={config.wrap.speed}
            ref={ref => this.node = ref}
          >
            {config.subcards.map((item, index) => (
              <div key={index}>
                <CardItem card={item} cards={config} data={data}/>
              </div>
            ))}
          </Carousel>
          <NormalHeader config={config}/>
          <div className="carousel-wrap" style={{height: config.wrap.height}}>
            {config.subcards.length > 1 && config.wrap.autoplay === 'false' ? <div className="prev" onClick={() => this.node && this.node.prev()}><LeftOutlined /></div> : null}
            {config.subcards.length > 1 && config.wrap.autoplay === 'false' ? <div className="next" onClick={() => this.node && this.node.next()}><RightOutlined /></div> : null}
            <Carousel
              autoplay={config.wrap.autoplay !== 'false'}
              dots={config.wrap.dots !== 'false'}
              dotPosition={config.wrap.dotPosition || 'bottom'}
              effect={config.wrap.effect || 'scrollx'}
              autoplaySpeed={config.wrap.speed}
              ref={ref => this.node = ref}
            >
              {config.subcards.map((item, index) => (
                <div key={index}>
                  <CardItem card={item} cards={config} data={data}/>
                </div>
              ))}
            </Carousel>
          </div>
        </div>
        {config.wrap.modalContent !== 'update' ? <div className="mk-footer">
          <Checkbox defaultChecked={false} onChange={this.onTipChange}>不在提醒</Checkbox>
@@ -387,19 +421,22 @@
            <Spin />
          </div> : null
        }
        <Carousel
          autoplay={config.wrap.autoplay !== 'false'}
          dots={config.wrap.dots !== 'false'}
          dotPosition={config.wrap.dotPosition || 'bottom'}
          effect={config.wrap.effect || 'scrollx'}
          autoplaySpeed={config.wrap.speed}
        >
          {config.subcards.map((item, index) => (
            <div key={index}>
              <CardItem card={item} cards={config} data={data}/>
            </div>
          ))}
        </Carousel>
        <NormalHeader config={config}/>
        <div className="carousel-wrap" style={{height: config.wrap.height}}>
          <Carousel
            autoplay={config.wrap.autoplay !== 'false'}
            dots={config.wrap.dots !== 'false'}
            dotPosition={config.wrap.dotPosition || 'bottom'}
            effect={config.wrap.effect || 'scrollx'}
            autoplaySpeed={config.wrap.speed}
          >
            {config.subcards.map((item, index) => (
              <div key={index}>
                <CardItem card={item} cards={config} data={data}/>
              </div>
            ))}
          </Carousel>
        </div>
      </div>
    )
  }