zoukankan      html  css  js  c++  java
  • 每天不同时间段,认领状态判断问题

    需求每天多个时间段里可认领,在可认领时间段的倒计时一小时内,显示倒计时;在可认领时间段内,按钮为亮色;不在可认领时间段内,按钮为灰色
    解决:
    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
      },
    
  • 相关阅读:
    克如斯卡尔 P1546
    真正的spfa
    第四课 最小生成树 要点
    关于vscode中nullptr未定义
    cmake学习笔记
    python学习笔记
    (BFS 图的遍历) 2906. kotori和迷宫
    (图论基础题) leetcode 997. Find the Town Judge
    (BFS DFS 并查集) leetcode 547. Friend Circles
    (BFS DFS 图的遍历) leetcode 841. Keys and Rooms
  • 原文地址:https://www.cnblogs.com/yangAL/p/10525102.html
Copyright © 2011-2022 走看看