Newer
Older
SpaceIntegration_front / src / views / home / components / date.vue
liyaguang on 30 Oct 2023 1 KB feat(*): 首页菜单导航样式
<!-- 日期选择 -->
<script name="DateSelect" setup lang="ts">
import dayjs from 'dayjs'
const emits = defineEmits(['confirm'])
const dateActive = ref('')
const dateSelect = ref('')
const dateType = ref('month')
const selectDate = (type: string) => {
  dateType.value = type
  if (type !== 'other') {
    dateSelect.value = ''
  }
  if (type === 'month') {
    // 获取N月前
    const date = dayjs().subtract(1, 'month').format('YYYY-MM-DD')
    console.log(date, 'month')
  }
  else if (type === 'sixmonth') {
    const date = dayjs().subtract(6, 'month').format('YYYY-MM-DD')
    console.log(date, 'sixmonth')
  }
  else if (type === 'year') {
    const date = dayjs().subtract(1, 'year').format('YYYY-MM-DD')
    console.log(date, 'year')
  }
  else {
    console.log(dateSelect.value, 'other')
  }
}
watch(() => dateSelect.value, (newVal) => {
  if (newVal) {
    selectDate('other')
  }
})
defineExpose({ dateSelect })
</script>

<template>
  <div class="container-date">
    <div class="top-date">
      <el-button @click="selectDate('month')">
        近一月
      </el-button>
      <el-button @click="selectDate('sixmonth')">
        近6月
      </el-button>
      <el-button @click="selectDate('year')">
        近一年
      </el-button>
    </div>
    <div>
      <el-date-picker
        v-model="dateSelect"
        type="date"
        placeholder="选择日期(自定义)"
        style="width: 100%;"
        value-format="YYYY-MM-DD"
        format="YYYY-MM-DD"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container-date {
  position: absolute;
  // display: flex;
  z-index: 999;
  top: 10px;
  left: 80px;
  padding: 10px;
  // width: 150px;
  background-color: rgba($color: #2f4261, $alpha: 70%);
  border-radius: 10px;

  .top-date {
    // width: 150px;
    display: flex;
    justify-content: space-around;
    margin-bottom: 10px;
  }
}
</style>