king
2023-07-07 ac4e2892a68bb4ef5b35e8e2e12e76d3ec3ede35
src/tabviews/custom/components/calendar/index.jsx
@@ -8,12 +8,12 @@
import asyncComponent from '@/utils/asyncComponent'
import UtilsDM from '@/utils/utils-datamanage.js'
import MKEmitter from '@/utils/events.js'
import CalendarBoard from './board'
import './index.scss'
const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
const CalendarBoard = asyncComponent(() => import('./board'))
class NormalCalendar extends Component {
  static propTpyes = {
@@ -25,7 +25,7 @@
    BID: '',                   // 上级ID
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    data: null,                // 数据
    data: [],                // 数据
    search: '',
    year: new Date().getFullYear(),
    BData: ''
@@ -55,6 +55,10 @@
      _config.setting.$re_year = true
    }
    if (_config.wrap.colorField && (!_config.wrap.signs || _config.wrap.signs.length === 0)) {
      _config.wrap.colorField = ''
    }
    this.setState({
      BID: BData ? (BData.$BID || '') : '',
      BData: BData,
@@ -81,13 +85,19 @@
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        this.setState({data: res.map((item, index) => {
        let data = []
        res.forEach((item, index) => {
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
          item.$Index = index + 1 + ''
          
          return item
        })})
          let pass = this.resetLine(item)
          if (pass) {
            data.push(item)
          }
        })
        this.setState({data: data})
      })
    }
  }
@@ -196,12 +206,17 @@
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      let data = result.data.map((item, index) => {
      let data = []
      result.data.forEach((item, index) => {
        item.key = index
        item.$$uuid = item[config.setting.primaryKey] || ''
        item.$$BID = BID || ''
        return item
        let pass = this.resetLine(item)
        if (pass) {
          data.push(item)
        }
      })
      this.setState({
@@ -242,6 +257,42 @@
    }
  }
  resetLine = (item) => {
    const { config: { wrap } } = this.state
    let startTime = item[wrap.timeField] || ''
    let endTime = item[wrap.endField || wrap.timeField] || ''
    item.$message = item[wrap.remarkField]
    if (!/^(1|2)\d{3}(-|\/)\d{2}(-|\/)\d{2}/.test(startTime)) return false
    if (!/^(1|2)\d{3}(-|\/)\d{2}(-|\/)\d{2}/.test(endTime)) return false
    if (!item.$message) return false
    if (wrap.colorField) {
      let sign = item[wrap.colorField] || ''
      wrap.signs.forEach(cell => {
        if (cell.sign !== sign) return
        item.$style = cell.style
        item.$color = cell.background
        item.$level = cell.$index
      })
    }
    let equal = endTime.substr(0, 4) === startTime.substr(0, 4)
    item.$startM = +(startTime.substr(0, 4) + startTime.substr(5, 2))
    item.$endM = +(endTime.substr(0, 4) + endTime.substr(5, 2))
    item.$start = +(startTime.substr(0, 4) + startTime.substr(5, 2) + startTime.substr(8, 2))
    item.$end = +(endTime.substr(0, 4) + endTime.substr(5, 2) + endTime.substr(8, 2))
    item.$startTime = equal ? `${startTime.substr(5, 2)}-${startTime.substr(8, 2)}` : `${startTime.substr(0, 4)}-${startTime.substr(5, 2)}-${startTime.substr(8, 2)}`
    item.$endTime = equal ?  `${endTime.substr(5, 2)}-${endTime.substr(8, 2)}` : `${endTime.substr(0, 4)}-${endTime.substr(5, 2)}-${endTime.substr(8, 2)}`
    return true
  }
  refreshbysearch = (searches) => {
    this.setState({
      search: searches
@@ -257,7 +308,7 @@
      <div className="normal-calendar-box" id={'anchor' + config.uuid} style={{...config.style}}>
        {loading ?
          <div className="loading-mask">
            {data ? <div className="ant-spin-blur"></div> : null}
            <div className="ant-spin-blur"></div>
            <Spin />
          </div> : null
        }
@@ -268,7 +319,7 @@
        {config.action[0] ? 
          <PopupButton disabled={false} BID={BID} btn={config.action[0]} BData={BData} setting={config.setting} selectedData={[]}/> : null
        }
        <CalendarBoard config={config} />
        <CalendarBoard config={config} data={data}/>
      </div>
    )
  }