|
@@ -9,12 +9,12 @@
|
|
|
<i class="hcicon-return"/>
|
|
|
</div>
|
|
|
<div class="hc-date-month-year">
|
|
|
- <n-popselect v-model:value="selectedDate.year" :options="yearOptions" size="large" trigger="click" scrollable @update:value="popselectYear">
|
|
|
+ <!--n-popselect v-model:value="selectedDate.year" :options="yearOptions" size="large" trigger="click" scrollable @update:value="popselectYear">
|
|
|
<div class="date-year">{{selectedDate.year}}年</div>
|
|
|
</n-popselect>
|
|
|
<n-popselect v-model:value="selectedDate.month" :options="monthOptions" size="large" trigger="click" scrollable @update:value="popselectMonth">
|
|
|
<div class="date-month">{{selectedDate.month}}月</div>
|
|
|
- </n-popselect>
|
|
|
+ </n-popselect-->
|
|
|
</div>
|
|
|
<div class="hc-date-month" @click="nextMonthClick">
|
|
|
<i class="hcicon-enter"/>
|
|
@@ -33,7 +33,7 @@
|
|
|
</div>
|
|
|
<div class="hc-date-actions">
|
|
|
<div class="choice-date">{{choiceDate.year}}-{{choiceDate.month}}-{{choiceDate.date}}</div>
|
|
|
- <n-button size="small" @click="backToDay">回到今天</n-button>
|
|
|
+ <!--n-button size="small" @click="backToDay">回到今天</n-button-->
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -41,7 +41,7 @@
|
|
|
|
|
|
<script setup>
|
|
|
import { ref } from "vue";
|
|
|
-import moment from 'moment';
|
|
|
+import dayjs from "dayjs"
|
|
|
const props = defineProps({
|
|
|
ui: {
|
|
|
type: String,
|
|
@@ -54,25 +54,25 @@ const curDateData = ref([]) //设置的日期
|
|
|
const datesDay = ref([]) //日期数据
|
|
|
//选择年月的日期
|
|
|
const selectedDate = ref({
|
|
|
- year: moment().get('year'),
|
|
|
- month: moment().get('month') +1
|
|
|
+ year: dayjs().get('year'),
|
|
|
+ month: dayjs().get('month') +1
|
|
|
})
|
|
|
//选择的日期,年月日
|
|
|
const choiceDate = ref({
|
|
|
- year: moment().get('year'),
|
|
|
- month: moment().get('month') +1,
|
|
|
- date: moment().get('date')
|
|
|
+ year: dayjs().get('year'),
|
|
|
+ month: dayjs().get('month') +1,
|
|
|
+ date: dayjs().get('date')
|
|
|
})
|
|
|
|
|
|
//处理设置的日期
|
|
|
const setCurDateData = (dateData) => {
|
|
|
let curData = [];
|
|
|
for (let i = 0; i < dateData.length; i++) {
|
|
|
- let toDate = moment(dateData[i].date, "YYYY-MM-DD").format("YYYY-MM-DD");
|
|
|
+ let toDate = dayjs(dateData[i].date, "YYYY-MM-DD").format("YYYY-MM-DD");
|
|
|
curData.push({
|
|
|
- year: moment(toDate).get('year'),
|
|
|
- month: moment(toDate).get('month')+1,
|
|
|
- date: moment(toDate).get('date')
|
|
|
+ year: dayjs(toDate).get('year'),
|
|
|
+ month: dayjs(toDate).get('month')+1,
|
|
|
+ date: dayjs(toDate).get('date')
|
|
|
})
|
|
|
}
|
|
|
curDateData.value = curData;
|
|
@@ -115,15 +115,15 @@ setCurDateData(dateData)
|
|
|
//获取日期
|
|
|
const getDatesDay = (year,month) => {
|
|
|
if (year && month) {
|
|
|
- let toDate = moment(year + '-' + month, "YYYY-MM").format("YYYY-MM-DD"); //格式化一下先
|
|
|
- let days = moment(toDate).daysInMonth(); //天数
|
|
|
- let monthOneDay = moment(toDate).startOf("month").format("YYYY-MM-DD"); //获取当月第一天
|
|
|
- let weekday = moment(monthOneDay, "YYYY-MM-DD").get('weekday'); //获取当月第一天是星期几
|
|
|
+ let toDate = dayjs(year + '-' + month, "YYYY-MM").format("YYYY-MM-DD"); //格式化一下先
|
|
|
+ let days = momedayjsnt(toDate).daysInMonth(); //天数
|
|
|
+ let monthOneDay = dayjs(toDate).startOf("month").format("YYYY-MM-DD"); //获取当月第一天
|
|
|
+ let weekday = dayjs(monthOneDay, "YYYY-MM-DD").get('weekday'); //获取当月第一天是星期几
|
|
|
setDatesDay(days,weekday)
|
|
|
} else {
|
|
|
- let days = moment().daysInMonth(); //天数
|
|
|
- let monthOneDay = moment().startOf("month").format("YYYY-MM-DD"); //获取当月第一天
|
|
|
- let weekday = moment(monthOneDay, "YYYY-MM-DD").get('weekday'); //获取当月第一天是星期几
|
|
|
+ let days = dayjs().daysInMonth(); //天数
|
|
|
+ let monthOneDay = dayjs().startOf("month").format("YYYY-MM-DD"); //获取当月第一天
|
|
|
+ let weekday = dayjs(monthOneDay, "YYYY-MM-DD").get('weekday'); //获取当月第一天是星期几
|
|
|
setDatesDay(days,weekday)
|
|
|
}
|
|
|
}
|
|
@@ -134,9 +134,9 @@ const setDatesDay = (days,weekday) => {
|
|
|
const selected = selectedDate.value; //选择的日期
|
|
|
const choiceData = choiceDate.value; //选择的日期
|
|
|
const dayData = {
|
|
|
- year: moment().get('year'),
|
|
|
- month: moment().get('month') +1,
|
|
|
- date: moment().get('date')
|
|
|
+ year: dayjs().get('year'),
|
|
|
+ month: dayjs().get('month') +1,
|
|
|
+ date: dayjs().get('date')
|
|
|
}
|
|
|
//添加头部
|
|
|
for (let i = 0; i < weekday; i++) {
|
|
@@ -229,15 +229,61 @@ const datesDayClick = (item) => {
|
|
|
let {year,month} = selectedDate.value
|
|
|
choiceDate.value = {year: year, month: month, date: item.key}
|
|
|
getDatesDay(year,month)
|
|
|
+ backChoiceDate()
|
|
|
+}
|
|
|
+
|
|
|
+const zpadStart = (val,leng,pad) => {
|
|
|
+ val += ''
|
|
|
+ while (val.length < leng) {
|
|
|
+ val = pad + val
|
|
|
+ }
|
|
|
+ return val
|
|
|
+}
|
|
|
+
|
|
|
+//事件
|
|
|
+const emit = defineEmits(['choice-date'])
|
|
|
+
|
|
|
+//返回选择的日期
|
|
|
+const backChoiceDate = () => {
|
|
|
+ //选择的日期处理
|
|
|
+ const {year,month,date} = choiceDate.value
|
|
|
+ let months = zpadStart(month, 2, '0')
|
|
|
+ let dates = zpadStart(date, 2, '0')
|
|
|
+ const choice = {year: year, month: months, date: dates}
|
|
|
+ const choiceVal = year + months + dates
|
|
|
+ //今天的日期处理
|
|
|
+ const dayData = {
|
|
|
+ year: dayjs().get('year'),
|
|
|
+ month: zpadStart(dayjs().get('month') + 1, 2, '0'),
|
|
|
+ date: zpadStart(dayjs().get('date'), 2, '0')
|
|
|
+ }
|
|
|
+ const today = dayData.year + dayData.month + dayData.date
|
|
|
+ //判断处理
|
|
|
+ if (choiceVal > today) {
|
|
|
+ backToDay(false)
|
|
|
+ } else {
|
|
|
+ emit('choice-date', {date: choice, choice: choiceVal})
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//回到今天
|
|
|
-const backToDay = () => {
|
|
|
- const year = moment().get('year');
|
|
|
- const month = moment().get('month') + 1;
|
|
|
- const date = moment().get('date');
|
|
|
+const backToDay = (isEmit = true) => {
|
|
|
+ const year = dayjs().get('year');
|
|
|
+ const month = dayjs().get('month') + 1;
|
|
|
+ const date = dayjs().get('date');
|
|
|
selectedDate.value = {year: year, month: month}
|
|
|
choiceDate.value = {year: year, month: month, date: date}
|
|
|
getDatesDay(year,month)
|
|
|
+ if (isEmit) {
|
|
|
+ //今天的日期
|
|
|
+ const today = {
|
|
|
+ year: year,
|
|
|
+ month: zpadStart(month, 2, '0'),
|
|
|
+ date: zpadStart(date, 2, '0')
|
|
|
+ }
|
|
|
+ const choice = today.year + today.month + today.date
|
|
|
+ emit('choice-date', {date: today, choice})
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
|