king
2023-06-19 78ff405688a2f299272c93ca3115ec00b52139f8
2023-06-19
1个文件已修改
2个文件已添加
484 ■■■■■ 已修改文件
src/tabviews/zshare/topSearch/index.jsx 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/zshare/topSearch/mkCheckCard/index.jsx 302 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/zshare/topSearch/mkCheckCard/index.scss 180 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/zshare/topSearch/index.jsx
@@ -15,7 +15,7 @@
import './index.scss'
const MutilForm = asyncSpinComponent(() => import('./advanceform'))
const MKCheckCard = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkCheckCard'))
const MKCheckCard = asyncComponent(() => import('./mkCheckCard'))
const MKCheck = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkCheck'))
const MKSwitch = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkSwitch'))
const MKSelect = asyncComponent(() => import('./mkSelect'))
src/tabviews/zshare/topSearch/mkCheckCard/index.jsx
New file
@@ -0,0 +1,302 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Col, Row } from 'antd'
import { CheckOutlined } from '@ant-design/icons'
import MKEmitter from '@/utils/events.js'
import './index.scss'
class MKCheckCard extends Component {
  static propTpyes = {
    config: PropTypes.object,
    onChange: PropTypes.func
  }
  state = {
    selectKeys: null,
    config: null,
    options: []
  }
  UNSAFE_componentWillMount() {
    let config = fromJS(this.props.config).toJS()
    let selectKeys = config.initval
    let initlength = 0
    if (config.multiple === 'true') {
      selectKeys = config.initval ? config.initval.split(',') : []
      initlength = selectKeys.length
      selectKeys = this.filterVals(config.options, selectKeys)
    }
    if (!config.selectStyle && config.backgroundColor) {
      config.selectStyle = 'custom'
    } else if (!config.selectStyle) {
      config.selectStyle = 'background'
    }
    if (config.display === 'picture' && !config.picratio) { // 兼容旧数据
      config.picratio = config.ratio || '1:1'
    }
    config.selectClass = ` mk-${config.selectStyle} `
    config.fields = config.fields || []
    this.setState({
      config: config,
      options: fromJS(config.options).toJS(),
      selectKeys: selectKeys
    }, () => {
      if (config.multiple === 'true' && selectKeys.length < initlength) {
        this.props.onChange(selectKeys.join(','))
      }
    })
  }
  componentDidMount () {
    const { config } = this.state
    if (config.linkField) {
      MKEmitter.addListener('mkFP', this.mkFormHandle)
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { config, selectKeys } = this.state
    if (!is(fromJS(config.oriOptions), fromJS(nextProps.config.oriOptions))) {
      if (config.multiple === 'true') {
        let keys = this.filterVals(nextProps.config.options, fromJS(selectKeys).toJS())
        if (keys.length < selectKeys.length) {
          this.setState({
            selectKeys: keys
          }, () => {
            this.props.onChange(keys.join(','))
          })
        }
      }
      this.setState({
        config: {...config, oriOptions: nextProps.config.oriOptions},
        options: fromJS(nextProps.config.options).toJS()
      })
    }
  }
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('mkFP', this.mkFormHandle)
  }
  filterVals = (options, vals) => {
    if (options.length === 0 || vals.length === 0) return vals
    let ops = options.map(item => item.$value)
    vals = vals.filter(val => ops.includes(val))
    return vals
  }
  mkFormHandle = (uuid, parentId, level) => {
    if (uuid !== this.state.config.uuid) return
    const { config } = this.state
    let options = config.oriOptions.filter(option => option.ParentID === parentId)
    if (config.multiple === 'true') {
      this.setState({
        options,
        selectKeys: []
      })
      this.props.onChange('')
    } else {
      let _option = options[0] ? options[0] : null
      let val = _option ? _option.$value : ''
      this.setState({
        options,
        selectKeys: val
      })
      let other = {}
      if (config.subFields && _option) {
        config.subFields.forEach((n, i) => {
          other[n.field] = _option[n.field]
          setTimeout(() => {
            MKEmitter.emit('mkFC', 'input', n.uuid, _option[n.field])
          }, i * 5)
        })
      }
      this.props.onChange(val, other)
      if (level < 7 && config.linkFields) {
        config.linkFields.forEach((m, i) => {
          setTimeout(() => {
            MKEmitter.emit('mkFP', m.uuid, val, level + 1)
          }, (i + 1) * 70)
        })
      }
    }
  }
  changeCard = (item) => {
    const { selectKeys, config } = this.state
    if (config.multiple === 'true') {
      let keys = []
      if (selectKeys.includes(item.$value)) {
        keys = selectKeys.filter(key => key !== item.$value)
      } else {
        keys = [...selectKeys, item.$value]
      }
      this.setState({
        selectKeys: keys
      }, () => {
        this.props.onChange(keys.join(','))
      })
    } else if (selectKeys !== item.$value) {
      let other = {}
      config.subFields && config.subFields.forEach((n, i) => {
        other[n.field] = item[n.field]
        setTimeout(() => {
          MKEmitter.emit('mkFC', 'input', n.uuid, item[n.field])
        }, i * 5)
      })
      config.linkFields && config.linkFields.forEach((m, i) => {
        setTimeout(() => {
          MKEmitter.emit('mkFP', m.uuid, item.$value, 0)
        }, (i + 1) * 100)
      })
      this.setState({
        selectKeys: item.$value
      }, () => {
        this.props.onChange(item.$value, other)
      })
    } else {
      let other = {}
      config.linkFields && config.linkFields.forEach((m, i) => {
        setTimeout(() => {
          MKEmitter.emit('mkFP', m.uuid, '', 0)
        }, (i + 1) * 100)
      })
      this.setState({
        selectKeys: ''
      }, () => {
        this.props.onChange('', other)
      })
    }
  }
  getCards = () => {
    const { selectKeys, options, config } = this.state
    const { display, width, fields, picratio, multiple, backgroundColor, selectStyle, selectClass } = config
    if (options.length === 0) {
      return null
    } else if (display === 'color') {
      return options.map(item => {
        let _active = false
        if (multiple === 'true') {
          _active = selectKeys.includes(item.$value)
        } else {
          _active = selectKeys === item.$value
        }
        return <Col span={width} key={item.key}>
          <div className={'card-color-cell' + (_active ? ' active' : '')} style={{background: item.$color}} onClick={() => this.changeCard(item)}>
            {fields.map(col => {
              return <span className="content-line" key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{item[col.field]}</span>
            })}
            <CheckOutlined />
          </div>
        </Col>
      })
    } else if (display !== 'picture') {
      let _style = selectStyle === 'custom' ? {backgroundColor} : null
      return options.map(item => {
        let _active = false
        if (multiple === 'true') {
          _active = selectKeys.includes(item.$value)
        } else {
          _active = selectKeys === item.$value
        }
        return <Col span={width} key={item.key}>
          <div className={'card-cell' + (_active ? ' active' : '') + selectClass} onClick={() => this.changeCard(item)}>
            <div className="bg-mask" style={_style}></div>
            {fields.map(col => {
              return <span className="content-line" key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{item[col.field]}</span>
            })}
          </div>
        </Col>
      })
    } else {
      let paddingTop = '100%'
      if (picratio === '4:3') {
        paddingTop = '75%'
      } else if (picratio === '3:2') {
        paddingTop = '66.7%'
      } else if (picratio === '16:9') {
        paddingTop = '56.25%'
      }
      return options.map(item => {
        let _active = false
        if (multiple === 'true') {
          _active = selectKeys.includes(item.$value)
        } else {
          _active = selectKeys === item.$value
        }
        return <Col span={width} key={item.key}>
          <div className={'card-pic-cell ' + (_active ? 'active' : '')} onClick={() => this.changeCard(item)} style={{paddingTop, backgroundImage: `url(${item.$url})`}}>
            <div className="content-wrap">
              <div className="content-center">
                {fields.map(col => {
                  return <span className="content-line" key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{item[col.field]}</span>
                })}
              </div>
              <CheckOutlined />
            </div>
          </div>
        </Col>
      })
    }
  }
  render() {
    const { config, options } = this.state
    let extend = ''
    if (options.length * config.width > 24) {
      extend += ' mutile-line'
    }
    if (config.border === 'hide') {
      extend += ' border-hide'
    }
    return (
      <div className={'check-card-form-wrap ' + extend}>
        <Row gutter={12}>{this.getCards()}</Row>
      </div>
    )
  }
}
export default MKCheckCard
src/tabviews/zshare/topSearch/mkCheckCard/index.scss
New file
@@ -0,0 +1,180 @@
.check-card-form-wrap {
  margin-top: 5px;
  .card-cell {
    position: relative;
    border: 1px solid #bcbcbc;
    background: #ffffff;
    border-radius: 4px;
    padding: 4px 6px;
    margin-bottom: 2px;
    line-height: 1.5;
    transition: all 0.3s;
    cursor: pointer;
    .bg-mask {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      opacity: 0.6;
      border-radius: 4px;
      background-color: transparent;
      transition: opacity 0.3s;
    }
  }
  .content-line {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    position: relative;
    z-index: 1;
    line-height: 1.5;
  }
  .card-cell.mk-background.active {
    border-color: var(--mk-sys-color);
    background: var(--mk-sys-color);
    span {
      color: #ffffff!important;
    }
  }
  .card-cell.mk-background.active::after {
    content: ' ';
    position: absolute;
    display: table;
    border: 2px solid #ffffff;
    border-top: 0;
    border-left: 0;
    bottom: 0;
    right: 10px;
    width: 6px;
    height: 12px;
    transform: rotate(45deg) scale(1) translate(-50%, -50%);
  }
  .card-cell.mk-font.active {
    border-color: var(--mk-sys-color);
    span {
      color: var(--mk-sys-color)!important;
    }
  }
  .card-cell.mk-custom {
    border-color: transparent;
  }
  .card-cell.mk-custom.active {
    .bg-mask {
      opacity: 1;
    }
  }
  .card-pic-cell {
    position: relative;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    background-size: cover;
    background-position: center;
    margin-bottom: 2px;
    line-height: 1.5;
    cursor: pointer;
    transition: all 0.3s;
    .content-wrap {
      position: absolute;
      top: 6px;
      left: 6px;
      right: 6px;
      bottom: 6px;
      .content-center {
        position: relative;
        top: 50%;
        transform: translate(0px, -50%);
      }
    }
    .anticon-check {
      display: none;
      position: absolute;
      color: #ffffff;
      border-radius: 20px;
      padding: 3px;
      width: 18px;
      height: 18px;
      font-size: 12px;
      right: -2px;
      bottom: -2px;
      background: var(--mk-sys-color);
    }
  }
  .card-color-cell {
    position: relative;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 6px;
    margin-bottom: 2px;
    min-height: 32px;
    cursor: pointer;
    .anticon-check {
      display: none;
      position: absolute;
      color: #ffffff;
      border-radius: 20px;
      padding: 3px;
      width: 18px;
      height: 18px;
      font-size: 12px;
      right: 0px;
      bottom: 0px;
      background: var(--mk-sys-color);
    }
  }
  .card-pic-cell.active, .card-color-cell.active {
    .anticon-check {
      display: inline-block;
    }
  }
}
.check-card-form-wrap.mutile-line {
  .card-cell {
    margin-bottom: 12px;
  }
  .card-pic-cell {
    margin-bottom: 12px;
  }
  .card-color-cell {
    margin-bottom: 12px;
  }
}
.check-card-form-wrap {
  .card-cell.mk-background:hover {
    border-color: var(--mk-sys-color);
    background: var(--mk-sys-color);
    span {
      color: #ffffff!important;
    }
  }
  .card-cell.mk-font:hover {
    border-color: var(--mk-sys-color);
    span {
      color: var(--mk-sys-color)!important;
    }
  }
  .card-cell.mk-custom:not(.active):hover {
    .bg-mask {
      opacity: 0.8;
    }
  }
  .card-pic-cell:hover {
    border-color: var(--mk-sys-color);
    box-shadow: 0px 0px 4px var(--mk-sys-color);
  }
}
.check-card-form-wrap.border-hide {
  .card-cell {
    border: 0px;
  }
}