From 97b29f3e99263d9a3ed63c96803c157ae3978e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Thu, 7 Nov 2024 10:14:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(ywq):=20=E5=A2=9E=E5=8A=A0=E5=B7=B2?= =?UTF-8?q?=E7=AD=BE=E5=88=97=E8=A1=A8=E6=97=B6=E9=97=B4=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E5=8A=9F=E8=83=BD-=20=E5=9C=A8=20SignedView=20=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20-=20=E5=AE=9E=E7=8E=B0=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E9=80=89=E5=AE=9A=E6=9C=88=E4=BB=BD=E7=AD=9B=E9=80=89=E5=B7=B2?= =?UTF-8?q?=E7=AD=BE=E5=88=97=E8=A1=A8=E7=9A=84=E9=80=BB=E8=BE=91=20-=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20UnSignView=20=E5=92=8C=20UnSignBatchView?= =?UTF-8?q?=20=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=A0=B7=E5=BC=8F=20-=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=20DatePickerView=20=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E7=8B=AC=E9=80=89=E6=8B=A9=E5=B9=B4?= =?UTF-8?q?=E3=80=81=E6=9C=88=E3=80=81=E6=97=A5-=20=E5=9C=A8=20TimeHelper?= =?UTF-8?q?=20=E4=B8=AD=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=9C=88?= =?UTF-8?q?=E4=BB=BD=E5=A4=A9=E6=95=B0=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/ets/utils/TimeHelper.ts | 14 +++++- src/main/ets/utils/compose/DatePickerView.ets | 44 +++++++++++++------ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/main/ets/utils/TimeHelper.ts b/src/main/ets/utils/TimeHelper.ts index d5b5e07..5c17134 100644 --- a/src/main/ets/utils/TimeHelper.ts +++ b/src/main/ets/utils/TimeHelper.ts @@ -16,6 +16,7 @@ export class TimeHelper { private constructor() { } + /** * 获取当前时间戳 * @returns @@ -30,8 +31,9 @@ export class TimeHelper { * 'yyyy-MM-dd HH:mm:ss' */ static getTime(format: string = 'yyyy-MM-dd HH:mm:ss') { - return TimeHelper.formatDate(new Date(),format) + return TimeHelper.formatDate(new Date(), format) } + static formatDate(date: Date, format: string) { const replacements: { [key: string]: string } = { yyyy: date.getFullYear().toString(), @@ -43,4 +45,14 @@ export class TimeHelper { }; return format.replace(/yyyy|MM|dd|HH|mm|ss/g, matched => replacements[matched]); } + + /** + * 获取月份天数 + * @param year + * @param month + * @returns + */ + static getMonthDays(year: number, month: number) { + return new Date(year, month, 0).getDate() + } } diff --git a/src/main/ets/utils/compose/DatePickerView.ets b/src/main/ets/utils/compose/DatePickerView.ets index 7534b73..bf3a8a7 100644 --- a/src/main/ets/utils/compose/DatePickerView.ets +++ b/src/main/ets/utils/compose/DatePickerView.ets @@ -6,6 +6,9 @@ import { ToolsHelper } from '../ToolsHelper' export struct DatePickerView { @Prop option: DateDialogOptions | undefined = undefined @Prop dialogTag: string | undefined = undefined + @State showYear: boolean = false + @State showMonth: boolean = false + @State showDay: boolean = false //年份相关 @State startYear: number = 1970 @State endYear: number = 1970 @@ -26,7 +29,14 @@ export struct DatePickerView { if (!this.option?.type) { this.option!.type = 'YYYY-MM-DD' } - if (this.option!.type.indexOf('YYYY') > -1) { + this.checkYear() + this.checkMonth() + this.checkDays() + } + + checkYear() { + this.showYear = this.option!.type!.indexOf('YYYY') > -1 + if (this.showYear) { if (this.option?.startDate) { this.startYear = Number.parseInt(this.option.startDate?.split('-')[0]) } @@ -46,12 +56,11 @@ export struct DatePickerView { this.currentYear = this.years.indexOf(new Date().getFullYear().toString()) } } - this.checkMonth() - this.checkDays() } checkMonth() { - if (this.option!.type!.indexOf('MM') > -1) { + this.showMonth = this.option!.type!.indexOf('MM') > -1 + if (this.showMonth) { if (this.option?.startDate) { this.startMonth = Number.parseInt(this.option.startDate?.split('-')[1]) } @@ -80,7 +89,8 @@ export struct DatePickerView { } checkDays() { - if (this.option!.type!.indexOf('DD') > -1) { + this.showDay = this.option!.type!.indexOf('DD') > -1 + if (this.showDay) { if (this.option?.startDate) { this.startDay = Number.parseInt(this.option.startDate?.split('-')[2]) } @@ -135,15 +145,21 @@ export struct DatePickerView { .padding(15) Row() { - TextPicker({ range: this.years, selected: $$this.currentYear }) - .onChange((value: string | string[], index: number | number[]) => { - this.checkDays() - }).canLoop(false) - TextPicker({ range: this.months, selected: $$this.currentMonth }) - .onChange((value: string | string[], index: number | number[]) => { - this.checkDays() - }).canLoop(false) - TextPicker({ range: this.days, selected: $$this.currentDay }) + if (this.startYear) { + TextPicker({ range: this.years, selected: $$this.currentYear }) + .onChange((value: string | string[], index: number | number[]) => { + this.checkDays() + }).canLoop(false) + } + if (this.startMonth) { + TextPicker({ range: this.months, selected: $$this.currentMonth }) + .onChange((value: string | string[], index: number | number[]) => { + this.checkDays() + }).canLoop(false) + } + if (this.startDay) { + TextPicker({ range: this.days, selected: $$this.currentDay }) + } }.width('100%').justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center) }