• 每天不同时间段,认领状态判断问题


    需求每天多个时间段里可认领,在可认领时间段的倒计时一小时内,显示倒计时;在可认领时间段内,按钮为亮色;不在可认领时间段内,按钮为灰色
    解决:
    const timeSolts = res.data.data.limitTime
    // const timeSolts = '10:40-11:00;12:00-02:00'
    let obj = []
    if (!timeSolts) {
      obj = {
        'handleValue': 'canClaim',
        'beginArr': [],
        'overArr': [],
      }
    } else {
      obj = await con.handleTime(timeSolts, diff)
    }
    
    //处理可认领时间段数据
      handleTime: async (timeSolts, diff) => {
        let timeArrays = timeSolts.split(';')
        let curArray = []
        let obj = {}
        let val = ''
        let beginArr = []
        let overArr = []
        if (!timeArrays) {
          val = 'canClaim'
        } else {
          timeArrays.forEach((item) => {
            if (!item) {
              return
            }
            const limitBegin = item.split('-')[0]
            const limitOver = item.split('-')[1]
            const today = moment().format('YYYY-MM-DD')
            //开抢时间
            const timeBeginToday = moment(today + ' ' + limitBegin).unix()
            const timeOverToday = moment(today + ' ' + limitOver).unix()
            beginArr.push(timeBeginToday - 3600)
            overArr.push(timeOverToday)
            //现在时间
            const nowTime = moment().unix() + parseInt(diff)
            let handleValue = ''
            if (nowTime >= timeBeginToday && nowTime < timeOverToday) {
              handleValue = 'canClaim'
            } else if (nowTime > timeOverToday) {
              handleValue = 'cannotCliaim'
            } else if (nowTime < timeBeginToday && (timeBeginToday - nowTime) > 3600) {
              handleValue = 'cannotCliaim'
            } else if (nowTime < timeBeginToday && (timeBeginToday - nowTime) <= 3600) {
              handleValue = (timeBeginToday - nowTime)
            }
            curArray.push(handleValue)
          })
          let curSet = new Set(curArray)
          if (curSet.has('canClaim')) {
            val = 'canClaim'
          } else {
            let newArray = []
            for (let v of curSet) {
              if (typeof (v) === 'number') {
                newArray.push(v)
              }
            }
            if (newArray.length === 0 && !curSet.has('canClaim')) {
              val = 'cannotCliaim'
            } else if (newArray.length) {
              val = Math.min(...newArray)
            }
          }
        }
        obj = {
          val,
          beginArr,
          overArr
        }
        return obj
      },
    
  • 相关阅读:
    工欲性能调优,必先利其器(2)- 火焰图
    工欲性能调优,必先利其器(1)
    关于烂代码的那些事(上)
    HTTP 返回码中 301 与 302 的区别
    HTTP 状态码 301 和 302 详解及区别——辛酸的探索之路
    HTTP 状态码之:301、302 重定向
    记一次获得 3 倍性能的 go 程序优化实践,及 on-cpu / off-cpu 火焰图的使用
    Coloring Flame Graphs: Code Hues
    StackOverflow 创始人关于如何高效编程的清单
    Spring Bean的生命周期(非常详细)
  • 原文地址:https://www.cnblogs.com/yangAL/p/10525102.html
Copyright © 2020-2023  润新知