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>

效果如下

相关推荐
【ql君】qlexcel6 分钟前
Notepad++ 复制宏、编辑宏的方法
开发语言·javascript·notepad++··宏编辑·宏复制
MiyueFE7 分钟前
14 个逻辑驱动的 UI 设计技巧,助您改善任何界面
前端·设计
啃火龙果的兔子11 分钟前
前端单元测试覆盖率工具有哪些,分别有什么优缺点
前端·单元测试
「、皓子~39 分钟前
后台管理系统的诞生 - 利用AI 1天完成整个后台管理系统的微服务后端+前端
前端·人工智能·微服务·小程序·go·ai编程·ai写作
就改了41 分钟前
Ajax——在OA系统提升性能的局部刷新
前端·javascript·ajax
凌冰_43 分钟前
Ajax 入门
前端·javascript·ajax
京东零售技术1 小时前
京东小程序JS API仓颉改造实践
前端
奋飛1 小时前
TypeScript系列:第六篇 - 编写高质量的TS类型
javascript·typescript·ts·declare·.d.ts
老A技术联盟1 小时前
从小白入门,基于Cursor开发一个前端小程序之Cursor 编程实践与案例分析
前端·小程序
风铃喵游1 小时前
构建引擎: 打造小程序编译器
前端·小程序·架构