浏览代码

feat(ywq): 添加已签信息作废功能并优化签名相关页面

- 新增已签信息作废接口和相关逻辑
- 重构签名详情页面,增加作废操作
- 优化已签列表页面布局和展示
- 新增日期选择器组件和相关工具类
徐勤民 5 月之前
父节点
当前提交
b513137ccd

+ 1 - 0
Index.ets

@@ -11,6 +11,7 @@ export { FileHelper } from './src/main/ets/utils/FileHelper'
 export { PickerHelper } from './src/main/ets/utils/PickerHelper'
 export { StrHelper } from './src/main/ets/utils/StrHelper'
 export { LogHelper } from './src/main/ets/utils/LogHelper'
+export { PickerDateTimeHelper } from './src/main/ets/utils/PickerDateTimeHelper'
 
 /**
  * 存储相关

+ 34 - 0
src/main/ets/utils/PickerDateTimeHelper.ets

@@ -0,0 +1,34 @@
+import { DatePickerView } from './compose/DatePickerView'
+import { ToolsHelper } from './ToolsHelper'
+
+export interface DateDialogOptions {
+  // 'YYYY-MM-DD'年月日对应的标识,随意组合
+  type?: string
+  startDate?: string
+  endDate?: string
+  currentDate?: string
+  onConfirm: (date: string) => void
+  onCancel?: () => void
+}
+
+@Builder
+function dateDialogBuilder(option: DateDialogOptions, dialogTag: string) {
+
+  DatePickerView({
+    option: option,
+    dialogTag: dialogTag,
+  })
+}
+
+
+export class PickerDateTimeHelper {
+  private constructor() {
+  }
+
+
+  static showDateDialog(options: DateDialogOptions, p: object) {
+    const dialogTag = ToolsHelper.getUuid()
+    ToolsHelper.showCustomDialog(dialogTag, dateDialogBuilder.bind(p, options, dialogTag),
+      DialogAlignment.Bottom)
+  }
+}

+ 4 - 1
src/main/ets/utils/ToolsHelper.ets

@@ -219,6 +219,7 @@ export class ToolsHelper {
   /**
    * 弹出List弹窗
    * @param options values 如果是非string列表的话,需要存在content字段
+   * @param p 调用页面,直接this 即可
    */
   static showListDialog<T = string>(options: ListOptions<T>, p: object) {
 
@@ -250,7 +251,9 @@ export class ToolsHelper {
   static showCustomDialog(dialogTag: string, b: CustomBuilder, alignment?: DialogAlignment) {
     promptAction.openCustomDialog({
       alignment: alignment ?? DialogAlignment.Center,
-      builder: b
+      builder: b,
+      cornerRadius: 3,
+      width: '100%',
     }).then((dialogId: number) => {
       ToolsHelper.mapDialog.set(dialogTag, dialogId)
     }).catch((error: Error) => {

+ 4 - 0
src/main/ets/utils/compose/DateDialogController.ets

@@ -0,0 +1,4 @@
+export interface DateDialogController{
+  confirm: (value:string) => void
+  cancel: () => void
+}

+ 152 - 0
src/main/ets/utils/compose/DatePickerView.ets

@@ -0,0 +1,152 @@
+import { DateDialogOptions } from '../PickerDateTimeHelper'
+import { ToolsHelper } from '../ToolsHelper'
+
+
+@Component
+export struct DatePickerView {
+  @Prop option: DateDialogOptions | undefined = undefined
+  @Prop dialogTag: string | undefined = undefined
+  //年份相关
+  @State startYear: number = 1970
+  @State endYear: number = 1970
+  @State currentYear: number = 0
+  @State years: string[] = []
+  // 月份相关
+  @State startMonth: number = 1
+  @State endMonth: number = 12
+  @State currentMonth: number = 0
+  @State months: string[] = []
+  // day相关
+  @State startDay: number = 1
+  @State endDay: number = 30
+  @State currentDay: number = -1
+  @State days: string[] = []
+
+  aboutToAppear(): void {
+    if (!this.option?.type) {
+      this.option!.type = 'YYYY-MM-DD'
+    }
+    if (this.option!.type.indexOf('YYYY') > -1) {
+      if (this.option?.startDate) {
+        this.startYear = Number.parseInt(this.option.startDate?.split('-')[0])
+      }
+      if (this.option?.endDate) {
+        this.endYear = Number.parseInt(this.option.endDate?.split('-')[0])
+      } else {
+        this.endYear = new Date().getFullYear() + 10
+      }
+      this.years = []
+      for (let index = this.startYear; index <= this.endYear; index++) {
+        this.years.push(index.toString())
+      }
+      if (this.option?.currentDate) {
+        const cy = this.option.currentDate?.split('-')[0]
+        this.currentYear = this.years.indexOf(cy)
+      } else {
+        this.currentYear = this.years.indexOf(new Date().getFullYear().toString())
+      }
+    }
+    this.checkMonth()
+    this.checkDays()
+  }
+
+  checkMonth() {
+    if (this.option!.type!.indexOf('MM') > -1) {
+      if (this.option?.startDate) {
+        this.startMonth = Number.parseInt(this.option.startDate?.split('-')[1])
+      }
+      if (this.option?.endDate) {
+        this.endMonth = Number.parseInt(this.option.endDate?.split('-')[1])
+      } else {
+        this.endMonth = 12
+      }
+      if (this.endMonth > 12) {
+        this.endMonth = 12
+      }
+      if (this.endMonth < 1) {
+        this.endMonth = 1
+      }
+      this.months = []
+      for (let index = this.startMonth; index <= this.endMonth; index++) {
+        this.months.push(index.toString())
+      }
+      if (this.option?.currentDate) {
+        const cy = this.option.currentDate?.split('-')[1]
+        this.currentMonth = this.months.indexOf(cy)
+      } else {
+        this.currentMonth = this.months.indexOf((new Date().getMonth() + 1).toString())
+      }
+    }
+  }
+
+  checkDays() {
+    if (this.option!.type!.indexOf('DD') > -1) {
+      if (this.option?.startDate) {
+        this.startDay = Number.parseInt(this.option.startDate?.split('-')[2])
+      }
+      const d = new Date(this.currentYear, this.currentMonth + 1, 0).getDate()
+      if (this.option?.endDate) {
+        this.endDay = Number.parseInt(this.option.endDate?.split('-')[2])
+      } else {
+        this.endDay = d
+      }
+      if (this.endDay > d) {
+        this.endDay = d
+      }
+      if (this.endDay < 1) {
+        this.endDay = 1
+      }
+      this.days = []
+      for (let index = this.startDay; index <= this.endDay; index++) {
+        this.days.push(index.toString())
+      }
+      if (this.currentDay === -1) {
+        if (this.option?.currentDate) {
+          const cy = this.option.currentDate?.split('-')[2]
+          this.currentDay = this.days.indexOf(cy)
+        } else {
+          this.currentDay = this.days.indexOf((new Date().getDate()).toString())
+        }
+      } else {
+        if (this.currentDay > this.days.length - 1) {
+          this.currentDay = this.days.length - 1
+        }
+      }
+    }
+  }
+
+  build() {
+    Column() {
+      Row() {
+        Text('取消').fontSize(17).fontColor('#333333').onClick(() => {
+          this.option?.onCancel?.()
+          ToolsHelper.closeCustomDialog(this.dialogTag!)
+        })
+        Text('确定').fontSize(17).fontColor('#18ABFB').onClick(() => {
+          this.option?.onConfirm?.(this.option!.type!.replace('YYYY', this.years[this.currentYear])
+            .replace('MM', this.months[this.currentMonth])
+            .replace('DD', this.days[this.currentDay])
+          )
+          ToolsHelper.closeCustomDialog(this.dialogTag!)
+        })
+      }.alignItems(VerticalAlign.Center)
+      .justifyContent(FlexAlign.SpaceBetween)
+      .width('100%')
+      .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 })
+
+      }.width('100%').justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center)
+    }
+
+  }
+}

+ 3 - 3
src/main/ets/view/SafeView.ets

@@ -39,10 +39,10 @@ export struct SafeView {
    */
   @Prop showBadgeRight: boolean;
   // 设置返回按钮事件,如果hideBack为true,该事件无效
-  onBackEvent?: () => void = undefined
+  @Prop onBackEvent?: () => void = undefined
   // 设置返回按钮事件
-  onClickLeft?: TitleBarBtn
-  onClickRight?: TitleBarBtn
+  @Prop onClickLeft?: TitleBarBtn
+  @Prop onClickRight?: TitleBarBtn
 
   @Builder
   doNothingBuilder() {