Jelajahi Sumber

feat(ywq): 增加已签列表时间筛选功能- 在 SignedView 页面添加时间筛选功能
- 实现根据选定月份筛选已签列表的逻辑
- 优化 UnSignView 和 UnSignBatchView 页面的样式
-改进 DatePickerView 组件,支持单独选择年、月、日- 在 TimeHelper 中添加获取月份天数的方法

徐勤民 5 bulan lalu
induk
melakukan
97b29f3e99

+ 13 - 1
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()
+  }
 }

+ 30 - 14
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)
     }