美文网首页
日历效果实现

日历效果实现

作者: 一枚小菜 | 来源:发表于2020-06-05 11:02 被阅读0次
效果
    <div class="bf2">
      <div class="f2">
        <div class="ititle">
          <div class="im" @click="plusMonth()">
            <img src="static/images/icon/sileft.png"/>
          </div>
          <div class="title">{{nowMonth}}</div>
          <div class="im1" @click="addMonth()">
            <img src="static/images/icon/siright.png"/>
          </div>
        </div>
        <div class="week">
          <div class="weeekRes">
            <div class="weekResT1" v-for="(item,index) in days" :key="index">
              <div class="weekResti1"><span>{{item.week}}</span></div>
            </div>
            <div class="weekResT2" v-for="(item,index) in list" :key="index">
              <div :class="['orderYuan']">
                <span :class="['orderYuanTT',{'cirTT':item.sign},{'y':!item.inMonth}]">{{item.name}}</span>
              </div>
            </div>
          </div>
        </div>
        <div>
          <div class="btn">签到</div>
          <div class="share">分享好友,签到积分翻倍!
            <img src="/static/img/share.png">
          </div>
        </div>
      </div>
    </div>
 .bf2 {
    width: 100%;
    margin-top: 57px;
  }

  .btn {
    color: #fff;
    background: #00B1F1;
    text-align: center;
    border-radius: 13px;
    height: 27px;
    line-height: 27px;
    width: 75px;
    margin: 10px auto 0;
  }

  .share {
    font-size: 12px;
    color: #656565;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}
 .share img {
   width: 12px;
   height: 12px;
    }
 
  .f2 {
    background: #fff;
    border-radius: 9px;
    box-shadow: 0 2px 8px 0 rgba(204, 204, 204, 0.5);
    margin-bottom: 14px;
    margin: 0 15px;
  }

  .f2 .ititle .title {
    font-size: 16px;
    color: #333;
    text-align: center;
  }

  .f2 .ititle {
    display: flex;
    padding: 14px 0 12px;
    margin: 0 9px;
  }

  .f2 .ititle img {
    height: 16px;
    width: 16px;
  }

  .f2 .ititle .im {
    margin-right: auto;
    margin-top: 3px;
  }

  .f2 .ititle .im1 {
    margin-left: auto;
    margin-top: 4px;
  }

  .f2 .week {
    display: flex;
    text-align: center;
    flex-wrap: wrap;

  }

  .f2 .week .weeekRes {
    display: flex;
    text-align: center;
    flex-wrap: wrap;
    width: 100%;
  }

  .f2 .week .weekResT1 {
    width: 14.28%;
    padding-bottom: 5px;
  }

  .f2 .week .weekResT2 {
    width: 14.28%;
    font-size: 12px;
    margin-bottom: 3px;
  }

  .f2 .week .weekResti1 {
    font-size: 12px;
  }

  .f2 .week .orderYuan {
    height: 24px;
    line-height: 24px;
    width: 100%;
  }

  .f2 .week .orderYuanTT {
    width: 24px;
    display: block;
    margin: 0 auto;
    border-radius: 51px;
    align-items: center;
    vertical-align: middle;
  }

  .f2 .week .y {
    color: #999;
  }

  .cirTT {
    background-color: #44c4a0 !important;
    color: #fff !important;
  }

  .f2 .week .t1 {
    width: 14.2%;
    box-sizing: border-box;
    flex-wrap: wrap;
    font-size: 14px;
    color: #333;
    padding: 2px 0;
  }

  .f2 .week .t1 .lp1 {
    font-size: 16px;
    color: #333;
  }

  .f2 .week .t1 .lp2 {
    font-size: 12px;
    color: #333;
    margin: 2px 12.5px;
    padding: 2.5px 0;
  }

  .f2 .week .t1 .cur {
    background-color: #44c4a0;
    border-radius: 25px;
    color: #fff;
    width: 24px;
    text-align: center;
    align-items: center;
    margin: 2px auto;
  }
   data() {
      return {
        monthOffset: 0,
        shows: true,
        exceed: true,
        nowMonth: '',
        list: [],
        days: [{
          week: '日'
        }, {
          week: '一'
        }, {
          week: '二'
        }, {
          week: '三'
        }, {
          week: '四'
        }, {
          week: '五'
        }, {
          week: '六'
        }]
      }
    }
    created() {
      let nowMonth = util.formatYY()
      this.nowMonth = nowMonth
      this.getCal()
    }
    methods: {
      getCal() {
        let monthOffset = this.monthOffset
        let nowMonth = moment().add(monthOffset, 'month').format('YYYY-MM') + '-01'
        //当前选择的年月(获取到1号)
        let list = []
        //算出周几
        let vWeekOfDay = moment(nowMonth).format('E') //算出这周的周几
        if (vWeekOfDay == 7) {
          vWeekOfDay = 0
        }
        //获取这个月的日历需要补满上个月的几天
        for (let i = vWeekOfDay; i > 0; i--) {
          //10-1往前减
          let xdate = moment(nowMonth).subtract(i, 'days')
          console.log(xdate)
          let xname = xdate.format('D')
          console.log(xname)
          list.push({
            name: xname,
            date: xdate.format('YYYY-MM-DD'), sign: false
          })
        }
        if (this.exceed) {
          if (vWeekOfDay > 4) {
            for (let i = 0; i < 42 - vWeekOfDay; i++) {
              let xdate = moment(nowMonth).add(i, 'days')
              let xname = xdate.format('D')
              list.push({
                name: xname,
                date: xdate.format('YYYY-MM-DD'),
                sign: false
              })
            }
          } else {
            for (let i = 0; i < 35 - vWeekOfDay; i++) {
              let xdate = moment(nowMonth).add(i, 'days')
              let xname = xdate.format('D')
              list.push({
                name: xname,
                date: xdate.format('YYYY-MM-DD'),
                sign: false
              })
            }
          }
        } else {
          //7-少了几个
          for (let i = 0; i < 7 - vWeekOfDay; i++) {
            let xdate = moment(nowMonth).add(i, 'days')
            let xname = xdate.format('D')
            list.push({
              name: xname,
              date: xdate.format('YYYY-MM-DD'),
              sign: false
            })
          }
        }
        this.list = list
        let that = this
        this.list.forEach(item => {
          item.inMonth = that.isInMoth(item.date)
        })
      },
      isInMoth(date) {
        let tmonth = moment(date).format('YYYY年MM月')
        if (tmonth == this.nowMonth) {
          return true
        }
        return false
      },
      plusMonth() {
        let monthOffset = this.monthOffset
        monthOffset = monthOffset - 1
        let nowMonth = moment().add(monthOffset, 'month').format('YYYY年MM月')
        this.monthOffset = monthOffset
        this.nowMonth = nowMonth
        this.getCal()
      },
      addMonth() {
        let monthOffset = this.monthOffset
        monthOffset = monthOffset + 1
        let nowMonth = moment().add(monthOffset, 'month').format('YYYY年MM月')
        this.monthOffset = monthOffset
        this.nowMonth = nowMonth
        this.getCal()
      }
    }

相关文章

  • iOS 日历控件

    使用 swift 实现的日历控件,效果如图: demo:https://github.com/yuetianlu/...

  • Android超简单实现自定义日历

    目录 前言 由于只想单纯的实现一个日历,因此整体比较简单,没有过多的代码,更方便捋清楚实现日历的逻辑 效果展示 实...

  • 月历+周历

    >功能 ``` 月历日历单独封装 各自带星期条 月历: 大 collectview(实现左右分页切换效果) +小 ...

  • 微信小程序picker时间选择器 预约时间选择器 自定义时间选择

    直接上效果图 实现利用多列选择器效果以及滑动事件加上实现类似日历的算法微信小程序自带的 picker 是没有这种效...

  • Vue纯JS实现日历

    效果图 不说废话,先上效果图: 实现代码 核心方法是pushDays() 思路 为了日历的完整和美观,采用的6行 ...

  • 时间管理100讲44(工具)

    时间管理用工具平台来实现,达到最好的效果。 1.日历系统(系统自带的日历,同步) 2.清单系统(todo) 3.笔...

  • 回头看UITableView(三)-下拉刷新的实现

    最近陷入了项目中一个日历月视图与周视图切换效果的实现,长时间没有实现想要的效果,沮丧至极。烦请有好想法的同学指点一...

  • 可滑动的日历

    实现可滑动的日历 这是简单的效果,可以滑动,是用的viewpager和自定义view实现的 首先是viewpage...

  • 原生JS实现日历组件

    想要实现的效果 点击日期选择框出现日历 有个日期控制栏帮助选择日期, 包括年、月、日的选择和今天 日历格子,初次点...

  • 日历的简单应用

    日历的简单应用。 通过日历获取到当前时间 查看今天是在今年的第几周 现在往后5天8小时 实现效果如下图: demo...

网友评论

      本文标题:日历效果实现

      本文链接:https://www.haomeiwen.com/subject/qldzzhtx.html