vue3+ant-design-vue

<template>
  <div class="todo-wrap">
  

    <div class="todo-content">
      <div class="main" v-if="isShowForm">

        <div class="main-top">
       
        </div>
        <div class="main-bottom">
      
          <div class="operation">
            <a-range-picker v-model:value="selectDate" @change="changeDate" separator="至" format="YYYY-MM-DD"
              value-format="YYYY-MM-DD" />
            <a-button class="color" @click="currMonth">本月</a-button>
            <a-button class="color" @click="preMonth">上月</a-button>
            <a-button class="color" @click="quarter">本季</a-button>
            <a-button class="color" @click="preQuarter">上季</a-button>
            <a-button class="color" @click="currYear">今年</a-button>
            <a-button class="color" @click="preYear">去年</a-button>
          </div>
        </div>
      
      </div>

     
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import HeaderOption from '../HeaderOption.vue';
import { ref } from 'vue';
import { Form, Input, Button, Table, DatePicker } from 'ant-design-vue';
//const route = useRoute();
import dayjs from 'dayjs'
import quarterOfYear from 'dayjs/plugin/quarterOfYear'   //获取季度需要
dayjs.extend(quarterOfYear)




const selectDate = ref([])
const reset = () => {
  selectDate.value = []
}
const changeDate = (val) => {
  console.log(val, 'changeDate')
}
const currMonth = () => {
  let start: any = null
  let end: any = null
  start = dayjs().startOf('month').format('YYYY-MM-DD')
  end = dayjs().endOf('month').format('YYYY-MM-DD ')
  selectDate.value = [start, end]
}
const preMonth = () => {
  let start: any = null
  let end: any = null
  start = dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD')
  end = dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD ')
  selectDate.value = [start, end]
}
const quarter = () => {

  //获得当前年份4位年 
  let currentYear = dayjs().startOf('year').format('YYYY');
  let num = dayjs().quarter()
  //获得本季度开始月份 
  let quarterSeasonStartMonth = num * 3 - 2;
  //获得本季度结束月份 
  let quarterSeasonEndMonth = num * 3;
  let start: any = dayjs(currentYear + '-' + quarterSeasonStartMonth).startOf('month').format('YYYY-MM-DD')
  let end: any = dayjs(currentYear + '-' + quarterSeasonEndMonth).endOf('month').format('YYYY-MM-DD')


  selectDate.value = [start, end]
}
const preQuarter = () => {
  //获得当前年份4位年 
  let currentYear = dayjs().startOf('year').format('YYYY');
  let num = dayjs().quarter()
  let start: any = null
  let end: any = null
  if(num<2){
 
   start = dayjs((Number(currentYear) -1)+ '-' + 10).startOf('month').format('YYYY-MM-DD')
   end = dayjs((Number(currentYear) -1) + '-' + 12).endOf('month').format('YYYY-MM-DD')

  }else{
 //获得上季度开始月份 
 let quarterSeasonStartMonth = (num -1)* 3 - 2;
  //获得上季度结束月份 
  let quarterSeasonEndMonth = (num -1) * 3;
   start = dayjs(currentYear + '-' + quarterSeasonStartMonth).startOf('month').format('YYYY-MM-DD')
   end = dayjs(currentYear + '-' + quarterSeasonEndMonth).endOf('month').format('YYYY-MM-DD')

  }
 

  selectDate.value = [start, end]
}
const currYear = () => {
  let start: any = null
  let end: any = null
  start = dayjs().startOf('year').format('YYYY-MM-DD')
  end = dayjs().endOf('year').format('YYYY-MM-DD ')
  selectDate.value = [start, end]
}
const preYear = () => {
  let start: any = null
  let end: any = null
  start = dayjs().subtract(1, 'year').startOf('year').format('YYYY-MM-DD')
  end = dayjs().subtract(1, 'year').endOf('year').format('YYYY-MM-DD ')
  selectDate.value = [start, end]
}

</script>
<style lang="less" scoped>
.todo-wrap {
  width: 100%;
  height: 100%;
  background: #fff;
  box-shadow: 1px 2px 8px 0 rgba(160, 187, 180, 1);
  border-radius: 6px 6px 0 6px 6px;
}

.todo-content {
  width: 100%;
  margin: 20px auto;

  ::v-deep(.ant-calendar-picker) {
    margin-right: 10px;
  }

}

.table-box {
  .dutyForm {
    padding-top: 1rem;
    margin: auto;

    h1 {
      text-align: center;
      font-size: 20px;
      font-weight: 700;
    }

  }

  table {
    margin: auto;
    width: 80%;
    border-width: 1px;
    border-color: #666666;
    border-collapse: collapse;

    tr {
      td {
        padding: 10px 20px;
        border-width: 1px;

        border-style: solid;
        border-color: #666666;
      }

      td:first-of-type {
        width: 400px;
      }

      td:nth-of-type(2) {
        width: 200px;
      }

    }
  }
}

.main {
  margin: auto;
  width: 90%;
  margin-top: 120px;

  .title {
    font-size: 22px;
    font-weight: bold;
    margin: 24px 0;
    text-align: center;
  }

  .main-top {
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-weight: 700;
    // background: rgb(207, 207, 205);
    background-image: linear-gradient(180deg, #fff 20%, rgb(207, 207, 205) 100%);
    display: flex;
    width: 100%;

    .left {
      width: 120px;
      border-right: 1px solid #ccc;
    }

    .right {
      width: 80%;
    }
  }

  .main-bottom {
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-weight: 700;
    // background: rgb(207, 207, 205);
    background-image: linear-gradient(180deg, #fff 20%, rgb(207, 207, 205) 100%);
    display: flex;
    width: 100%;

    .date {
      width: 120px;
      border-right: 1px solid #ccc;
    }

    .operation {
      line-height: 40px;
      display: flex;
      align-items: center;
      // background: #fff !important;
    }
  }
}

.reset {
  text-align: center;
  margin: auto;
  margin-top: 20px;
  width: 70%;
}

::v-deep(.ant-input) {
  height: 30px;
  margin-left: 4px;
}

::v-deep(.ant-btn) {
  height: 30px;
  margin: 0 4px;
}
</style>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐