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>

效果如下

相关推荐
漫路在线4 分钟前
JS逆向-某易云音乐下载器
开发语言·javascript·爬虫·python
不爱吃糖的程序媛7 分钟前
浅谈前端架构设计与工程化
前端·前端架构设计
BillKu1 小时前
Vue3 Element Plus 对话框加载实现
javascript·vue.js·elementui
郝YH是人间理想2 小时前
系统架构设计师案例分析题——web篇
前端·软件工程
Evaporator Core2 小时前
深入探索:Core Web Vitals 进阶优化与新兴指标
前端·windows
初遇你时动了情2 小时前
html js 原生实现web组件、web公共组件、template模版插槽
前端·javascript·html
QQ2740287563 小时前
Soundness Gitpod 部署教程
linux·运维·服务器·前端·chrome·web3
前端小崔3 小时前
从零开始学习three.js(18):一文详解three.js中的着色器Shader
前端·javascript·学习·3d·webgl·数据可视化·着色器
哎呦你好3 小时前
HTML 表格与div深度解析区别及常见误区
前端·html
运维@小兵3 小时前
vue配置子路由,实现点击左侧菜单,内容区域显示不同的内容
前端·javascript·vue.js