🐛(component): 修复 date-picker 组件默认值不存在时导致选择值不回显

This commit is contained in:
就眠儀式 2022-08-18 16:24:46 +08:00
parent 5c5add2ca6
commit 200ba6c384
2 changed files with 8 additions and 10 deletions

View File

@ -294,26 +294,24 @@ watch(
if (unWatch) { if (unWatch) {
return; return;
} }
let initModelValue = let initModelValue = props.range && props.modelValue ? (props.modelValue as string[])[0] || "" : (props.modelValue as string);
props.range && props.modelValue
? (props.modelValue as string[])[0] || "" hms.value.hh = isNaN(dayjs(initModelValue).hour()) ? 0 : dayjs(initModelValue).hour();
: (props.modelValue as string); hms.value.mm = isNaN(dayjs(initModelValue).minute()) ? 0 : dayjs(initModelValue).minute();
hms.value.hh = dayjs(initModelValue).hour(); hms.value.ss = isNaN(dayjs(initModelValue).second()) ? 0 : dayjs(initModelValue).second();
hms.value.mm = dayjs(initModelValue).minute();
hms.value.ss = dayjs(initModelValue).second();
if (initModelValue.length === 8 && props.type === "time") { if (initModelValue.length === 8 && props.type === "time") {
//dayjs
let modelValue = initModelValue; let modelValue = initModelValue;
modelValue = "1970-01-01 " + modelValue; modelValue = "1970-01-01 " + modelValue;
hms.value.hh = dayjs(modelValue).hour(); hms.value.hh = dayjs(modelValue).hour();
hms.value.mm = dayjs(modelValue).minute(); hms.value.mm = dayjs(modelValue).minute();
hms.value.ss = dayjs(modelValue).second(); hms.value.ss = dayjs(modelValue).second();
} }
currentYear.value = initModelValue ? getYear(initModelValue) : -1; currentYear.value = initModelValue ? getYear(initModelValue) : -1;
currentMonth.value = initModelValue ? getMonth(initModelValue) : -1; currentMonth.value = initModelValue ? getMonth(initModelValue) : -1;
currentDay.value = initModelValue ? getDay(initModelValue) : -1; currentDay.value = initModelValue ? getDay(initModelValue) : -1;
if (props.type === "date" || props.type === "datetime") { if (props.type === "date" || props.type === "datetime") {
// datedatetime
if (currentYear.value === -1) currentYear.value = dayjs().year(); if (currentYear.value === -1) currentYear.value = dayjs().year();
if (currentMonth.value === -1) currentMonth.value = dayjs().month(); if (currentMonth.value === -1) currentMonth.value = dayjs().month();
} }

View File

@ -49,7 +49,7 @@ import { ref } from 'vue'
export default { export default {
setup() { setup() {
const endTime2 = ref("2022-06-04 17:35:00"); const endTime2 = ref("");
return { return {
endTime2 endTime2