From f134d0468580797c184753ce17d9085a71e96516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Mon, 18 Jul 2022 09:15:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D(select):=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datePicker/components/DateRange.vue | 44 ++++--- .../datePicker/components/MonthRange.vue | 114 ++++++++++++++---- .../src/component/datePicker/index.vue | 91 ++++++++++---- .../src/document/zh-CN/components/select.md | 4 +- 4 files changed, 182 insertions(+), 71 deletions(-) diff --git a/package/component/src/component/datePicker/components/DateRange.vue b/package/component/src/component/datePicker/components/DateRange.vue index 3de93e0a..32426d6f 100644 --- a/package/component/src/component/datePicker/components/DateRange.vue +++ b/package/component/src/component/datePicker/components/DateRange.vue @@ -279,16 +279,22 @@ const closeRightMonthPanel = () => { const footOnOk = () => { let format = datePicker.type === "datetime" ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD"; - let startTimeVal =startTime.day!==-1&&endTime.day!==-1?dayjs(startTime.day) - .hour(startTime.hms.hh) - .minute(startTime.hms.mm) - .second(startTime.hms.ss) - .format(format):''; - let endTimeVal = startTime.day!==-1&&endTime.day!==-1?dayjs(endTime.day) - .hour(endTime.hms.hh) - .minute(endTime.hms.mm) - .second(endTime.hms.ss) - .format(format):''; + let startTimeVal = + startTime.day !== -1 && endTime.day !== -1 + ? dayjs(startTime.day) + .hour(startTime.hms.hh) + .minute(startTime.hms.mm) + .second(startTime.hms.ss) + .format(format) + : ""; + let endTimeVal = + startTime.day !== -1 && endTime.day !== -1 + ? dayjs(endTime.day) + .hour(endTime.hms.hh) + .minute(endTime.hms.mm) + .second(endTime.hms.ss) + .format(format) + : ""; emits("update:startTime", startTimeVal); emits("update:endTime", endTimeVal); datePicker.ok(); @@ -296,18 +302,18 @@ const footOnOk = () => { //现在回调 const footOnNow = () => { - startTime.year=dayjs().year(); - startTime.month=dayjs().month(); - startTime.day=new Date(new Date().toDateString()).getTime(); - startTime.hms.hh=dayjs().hour(); - startTime.hms.mm=dayjs().minute(); - startTime.hms.ss=dayjs().second(); - endTime.day=-1; + startTime.year = dayjs().year(); + startTime.month = dayjs().month(); + startTime.day = new Date(new Date().toDateString()).getTime(); + startTime.hms.hh = dayjs().hour(); + startTime.hms.mm = dayjs().minute(); + startTime.hms.ss = dayjs().second(); + endTime.day = -1; }; //清空回调 const footOnClear = () => { - startTime.day=-1; - endTime.day=-1; + startTime.day = -1; + endTime.day = -1; }; diff --git a/package/component/src/component/datePicker/components/MonthRange.vue b/package/component/src/component/datePicker/components/MonthRange.vue index 4f6dba78..6cee2c9a 100644 --- a/package/component/src/component/datePicker/components/MonthRange.vue +++ b/package/component/src/component/datePicker/components/MonthRange.vue @@ -3,21 +3,43 @@
- +
- {{ startTime.year || "--" }}年 + {{ startTime.year || "--" }}年
    -
  • +
  • {{ item.slice(0, 3) }}
@@ -29,17 +51,37 @@ {{ startTime.year + 1 }}年
- +
@@ -83,11 +125,15 @@ const datePicker: provideType = inject("datePicker") as provideType; const startTime = reactive({ year: props.startTime ? dayjs(props.startTime).year() : dayjs().year(), - unix: props.startTime ? dayjs(props.startTime).hour(0).minute(0).second(0).valueOf() : -1, + unix: props.startTime + ? dayjs(props.startTime).hour(0).minute(0).second(0).valueOf() + : -1, }); const endTime = reactive({ year: props.endTime ? dayjs(props.endTime).year() : dayjs().year() + 1, - unix: props.startTime ? dayjs(props.endTime).hour(0).minute(0).second(0).valueOf() : -1, + unix: props.startTime + ? dayjs(props.endTime).hour(0).minute(0).second(0).valueOf() + : -1, }); let hoverMonth = ref(-1); const MONTH_NAME = [ @@ -134,11 +180,17 @@ const handleMonthClick = (item: number) => { watch( () => [props.startTime, props.endTime], () => { - startTime.year = props.startTime ? dayjs(props.startTime).year() : dayjs().year(); - startTime.unix = props.startTime ? dayjs(props.startTime).hour(0).minute(0).second(0).valueOf() : -1; + startTime.year = props.startTime + ? dayjs(props.startTime).year() + : dayjs().year(); + startTime.unix = props.startTime + ? dayjs(props.startTime).hour(0).minute(0).second(0).valueOf() + : -1; endTime.year = props.endTime ? dayjs(props.endTime).year() : dayjs().year(); - endTime.unix = props.startTime ? dayjs(props.endTime).hour(0).minute(0).second(0).valueOf() : -1; - }, + endTime.unix = props.startTime + ? dayjs(props.endTime).hour(0).minute(0).second(0).valueOf() + : -1; + } ); //关闭选择时间的面板 @@ -155,8 +207,14 @@ const closeRightYearPanel = () => { //关闭回调 const footOnOk = () => { let format = "YYYY-MM"; - let startTimeVal = startTime.unix !== -1 && endTime.unix !== -1 ? dayjs(startTime.unix).format(format) : ''; - let endTimeVal = endTime.unix !== -1 && endTime.unix !== -1 ? dayjs(endTime.unix).format(format) : ''; + let startTimeVal = + startTime.unix !== -1 && endTime.unix !== -1 + ? dayjs(startTime.unix).format(format) + : ""; + let endTimeVal = + endTime.unix !== -1 && endTime.unix !== -1 + ? dayjs(endTime.unix).format(format) + : ""; emits("update:startTime", startTimeVal); emits("update:endTime", endTimeVal); datePicker.ok(); @@ -165,7 +223,9 @@ const footOnOk = () => { //现在回调 const footOnNow = () => { startTime.year = dayjs().year(); - startTime.unix = dayjs(startTime.year + '-' + (dayjs().month() + 1)).valueOf(); + startTime.unix = dayjs( + startTime.year + "-" + (dayjs().month() + 1) + ).valueOf(); endTime.unix = -1; hoverMonth.value = -1; }; @@ -188,7 +248,9 @@ const monthItemMouseEnter = (event: MouseEvent, item: any) => { hoverMonth.value = -1; return; } - hoverMonth.value = parseInt((event.target as HTMLElement).dataset.unix as string); + hoverMonth.value = parseInt( + (event.target as HTMLElement).dataset.unix as string + ); }; const ifHasRangeHoverClass = computed(() => { return function (item: any) { @@ -212,10 +274,10 @@ const ifHasRangeHoverClass = computed(() => { }); const getUnix = computed(() => { - return function (item: any, position: 'left' | 'right') { + return function (item: any, position: "left" | "right") { let month = MONTH_NAME.indexOf(item); - let year = position === 'left' ? startTime.year : startTime.year + 1; - return dayjs(year + '-' + (month + 1)).valueOf(); - } -}) + let year = position === "left" ? startTime.year : startTime.year + 1; + return dayjs(year + "-" + (month + 1)).valueOf(); + }; +}); diff --git a/package/component/src/component/datePicker/index.vue b/package/component/src/component/datePicker/index.vue index 94b90200..a2f3c92c 100644 --- a/package/component/src/component/datePicker/index.vue +++ b/package/component/src/component/datePicker/index.vue @@ -1,33 +1,74 @@