🐛(component): 修复 date-picker 组件默认值不存在时导致选择值不回显
This commit is contained in:
parent
5c5add2ca6
commit
200ba6c384
@ -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") {
|
||||||
// date与datetime容错
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user