|
@@ -30,12 +30,17 @@
|
|
import {nextTick, watch, ref} from "vue";
|
|
import {nextTick, watch, ref} from "vue";
|
|
import dayjs from "dayjs"
|
|
import dayjs from "dayjs"
|
|
import 'dayjs/locale/zh-cn'
|
|
import 'dayjs/locale/zh-cn'
|
|
|
|
+import {getObjNullValue} from "vue-utils-plus";
|
|
dayjs.locale('zh-cn')
|
|
dayjs.locale('zh-cn')
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
ui: {
|
|
ui: {
|
|
type: String,
|
|
type: String,
|
|
default: ''
|
|
default: ''
|
|
},
|
|
},
|
|
|
|
+ recordDate: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({})
|
|
|
|
+ },
|
|
dateData: {
|
|
dateData: {
|
|
type: Array,
|
|
type: Array,
|
|
default: () => ([])
|
|
default: () => ([])
|
|
@@ -56,9 +61,12 @@ const datesDay = ref([]) //日期数据
|
|
const emit = defineEmits(['choice-date'])
|
|
const emit = defineEmits(['choice-date'])
|
|
|
|
|
|
//监听
|
|
//监听
|
|
-watch(() => props.dateData, (dateData) => {
|
|
|
|
|
|
+watch(() => [
|
|
|
|
+ props.dateData,
|
|
|
|
+ props.recordDate,
|
|
|
|
+], ([dateData,recordDate]) => {
|
|
selectedDatas.value = dateData
|
|
selectedDatas.value = dateData
|
|
- setCurDateData(dateData)
|
|
|
|
|
|
+ setCurDateData(dateData, recordDate)
|
|
})
|
|
})
|
|
|
|
|
|
//渲染完成
|
|
//渲染完成
|
|
@@ -81,11 +89,11 @@ nextTick(()=> {
|
|
}
|
|
}
|
|
toPicker.value = toDayJs.format('YYYY-MM')
|
|
toPicker.value = toDayJs.format('YYYY-MM')
|
|
emit('choice-date', isDayDateFormat(toDays.value))
|
|
emit('choice-date', isDayDateFormat(toDays.value))
|
|
- setCurDateData(props.dateData)
|
|
|
|
|
|
+ setCurDateData(props.dateData, props.recordDate)
|
|
})
|
|
})
|
|
|
|
|
|
//处理设置的日期
|
|
//处理设置的日期
|
|
-const setCurDateData = (dateData) => {
|
|
|
|
|
|
+const setCurDateData = (dateData, recordDate) => {
|
|
let curData = [];
|
|
let curData = [];
|
|
for (let i = 0; i < dateData.length; i++) {
|
|
for (let i = 0; i < dateData.length; i++) {
|
|
let toDate = dayjs(dateData[i]).format("YYYY-MM-DD");
|
|
let toDate = dayjs(dateData[i]).format("YYYY-MM-DD");
|
|
@@ -97,11 +105,16 @@ const setCurDateData = (dateData) => {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
curDateData.value = curData;
|
|
curDateData.value = curData;
|
|
- getDatesDay()
|
|
|
|
|
|
+ //判断是否选择了日期
|
|
|
|
+ if (getObjNullValue(recordDate)) {
|
|
|
|
+ getDatesDay(recordDate.year, recordDate.month)
|
|
|
|
+ } else {
|
|
|
|
+ getDatesDay()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//获取日期
|
|
//获取日期
|
|
-const getDatesDay = (year,month) => {
|
|
|
|
|
|
+const getDatesDay = (year, month) => {
|
|
if (year && month) {
|
|
if (year && month) {
|
|
let toDate = dayjs(year + '-' + month).format("YYYY-MM-DD"); //格式化一下先
|
|
let toDate = dayjs(year + '-' + month).format("YYYY-MM-DD"); //格式化一下先
|
|
let days = dayjs(toDate).daysInMonth(); //天数
|
|
let days = dayjs(toDate).daysInMonth(); //天数
|
|
@@ -169,7 +182,10 @@ const prevMonthClick = () => {
|
|
} else {
|
|
} else {
|
|
months = month - 1;
|
|
months = month - 1;
|
|
}
|
|
}
|
|
- selectedDate.value = {year: years, month: months}
|
|
|
|
|
|
+ selectedDate.value = {
|
|
|
|
+ year: years,
|
|
|
|
+ month: months
|
|
|
|
+ }
|
|
getDatesDay(years,months)
|
|
getDatesDay(years,months)
|
|
}
|
|
}
|
|
//下一月
|
|
//下一月
|
|
@@ -183,7 +199,10 @@ const nextMonthClick = () => {
|
|
years = year;
|
|
years = year;
|
|
months = month + 1;
|
|
months = month + 1;
|
|
}
|
|
}
|
|
- selectedDate.value = {year: years, month: months}
|
|
|
|
|
|
+ selectedDate.value = {
|
|
|
|
+ year: years,
|
|
|
|
+ month: months
|
|
|
|
+ }
|
|
getDatesDay(years,months)
|
|
getDatesDay(years,months)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -192,7 +211,7 @@ const datesDayClick = (item) => {
|
|
if (item.type !== 'excluded') {
|
|
if (item.type !== 'excluded') {
|
|
let {year,month} = selectedDate.value
|
|
let {year,month} = selectedDate.value
|
|
choiceDate.value = {year: year, month: month, date: item.key}
|
|
choiceDate.value = {year: year, month: month, date: item.key}
|
|
- getDatesDay(year,month)
|
|
|
|
|
|
+ getDatesDay(year, month)
|
|
backChoiceDate()
|
|
backChoiceDate()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -236,7 +255,7 @@ const isDayDateFormat = ({year, month, date}) => {
|
|
}
|
|
}
|
|
const choice = today.year + today.month + today.date
|
|
const choice = today.year + today.month + today.date
|
|
const choices = `${today.year}-${today.month}-${today.date}`
|
|
const choices = `${today.year}-${today.month}-${today.date}`
|
|
- return {date: today, choice, choices}
|
|
|
|
|
|
+ return {date: today, choice, choices, dates: {year, month, date}}
|
|
}
|
|
}
|
|
|
|
|
|
const zpadStart = (val, leng, pad) => {
|
|
const zpadStart = (val, leng, pad) => {
|