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
      },
    
  • 相关阅读:
    Vue 数组响应
    Vue 事件监听
    Vue 分支循环
    Vue 计算属性与方法
    Vue 属性与样式
    Vue mustache语法&常用指令
    vue 基本介绍
    linux(centos7) 安装nginx
    python 创建虚拟环境(一个独立的环境)
    Python标准库学习--->1、内置函数(1-10个)
  • 原文地址:https://www.cnblogs.com/yangAL/p/10525102.html
Copyright © 2011-2022 走看看