antd-vue 实现自定义日期头部

javascript 复制代码
<template>
 <a-config-provider :locale="zhCN">
                <a-calendar 
                :fullscreen="true"  
                :disabled-date="dateDisabled"
                @panelChange="panelChange">
                <!-- :headerRender="headerRender" -->
                  <div slot="headerRender" slot-scope="{ value, type, onChange, onTypeChange }" class="ant-fullcalendar-date" >
                    <div class="slotHeader" style="padding:15px 15px 40px 15px; textAlign: center; position: relative; ">
                        <div style="position: absolute;left: 15px;top: 20px;">
                        </div>
                        <div style="display: inline-block; textAlign: center;">
                          <Select  style="width:200px" :value="moment(value).year()" @on-change="(year) =>{changeYear(value,year,onChange)}">
                              <Option v-for="item in yearOptions" :value="item.value" :key="item.value">{{ item.label }}</Option>
                          </Select>
                          <Select style="width:140px" :value="moment(value).month()" @on-change="(month) => {changeMonth(value,month,onChange)}">
                              <Option v-for="item in monthOptions" :value="item.value" :key="item.value">{{ item.label }}</Option>
                          </Select>
                        </div>
                        <div style="position: absolute;right: 15px;top: 20px;">
                          <ButtonGroup>
                            <Button type="primary" @click="() => {prevMonth(value,onChange)}">
                                <Icon type="ios-arrow-back"></Icon>
                            </Button>
                            <Button type="primary" @click="() => {showTotay(value,onChange)}">本月</Button>
                            <Button type="primary" @click="()=> {nextMonth(value,onChange)}">
                                <Icon type="ios-arrow-forward"></Icon>
                            </Button>
                        </ButtonGroup>
                        </div>
                        </div>
                  </div>
                  <ul slot="dateCellRender" slot-scope="value" class="events">
                    <li
                        v-for="(row, index) in getListData(value)"
                        :key="row.formId"
                        class="li-item"
                      >
                      </li>

                  </ul>
                </a-calendar>
              </a-config-provider>
           </template>
<script>
import zhCN from "ant-design-vue/es/locale-provider/zh_CN";
data() {
	return {
		zhCN,
		 yearOptions:[],
         monthOptions:[],
	}
},
methods: {
    getMonthOptions() {
      let monthOptions = []
      for (let i = 0; i <= 11; i++) {
        monthOptions.push({
          label: `${i+1}月`,
          value: i,
        })
      }
      this.monthOptions = monthOptions
    },
    getYearOptions() {
      let yearOptions = []
      for (let i = 2020; i <= new Date().getFullYear()+5; i++) {
        yearOptions.push({
          label: `${i}年`,
          value: i,
        })
      }
      this.yearOptions = yearOptions
    },
        changeYear(value,newYear, onChange) {
      const now =  value.clone().year(newYear)
      onChange(now)

    },
    changeMonth(value,selectedMonth, onChange) {
      const newValue = value.clone()
      newValue.month(parseInt(selectedMonth, 10))
      onChange(newValue)
    },
    prevMonth(value, onChange) {
      let newMonth = moment(value).subtract(1, 'months');
      onChange(newMonth);
    },
    nextMonth(value, onChange) {
      let newMonth = moment(value).add(1, 'months');
      onChange(newMonth);
    },
    showTotay(value,onChange) {
      const today = moment(new Date())
      onChange(today)
    },
}
</script>

效果如下

相关推荐
举个栗子dhy3 分钟前
解决在父元素上同时使用 onMouseEnter和 onMouseLeave时导致下拉菜单无法正常展开或者提前收起问题
前端·javascript·react.js
Coding_Doggy10 分钟前
苍穹外卖前端Day1 | vue基础、Axios、路由vue-router、状态管理vuex、TypeScript
前端
前端与小赵10 分钟前
vue3和vue2生命周期的区别
前端·javascript·vue.js
用户4582031531714 分钟前
10个你可能不知道的实用CSS技巧,立竿见影提升开发效率
前端·css
在逃牛马14 分钟前
【Uni-App+SSM+MP 宠物实战】Day4:Uni-App 项目初始化
前端
J_Asia15 分钟前
如何exclude不必要的so文件?
前端
一鹿有你们~17 分钟前
面试题-前端如何解决跨域
前端·javascript·跨域
文心快码BaiduComate21 分钟前
文心快码升级至3.5S版本,强化多智能体自协同能力
前端·后端·程序员
Sailing22 分钟前
👉 👉 Vue3 自定义 Hook:从入门到进阶(~~安静的阅读2分钟,相信我,这篇文章一定能给你启发)
前端·javascript·vue.js