From b513137ccddca87256f301341b1374fe72c7b2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Wed, 6 Nov 2024 20:14:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(ywq):=20=E6=B7=BB=E5=8A=A0=E5=B7=B2?= =?UTF-8?q?=E7=AD=BE=E4=BF=A1=E6=81=AF=E4=BD=9C=E5=BA=9F=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E7=AD=BE=E5=90=8D=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增已签信息作废接口和相关逻辑 - 重构签名详情页面,增加作废操作 - 优化已签列表页面布局和展示 - 新增日期选择器组件和相关工具类 --- Index.ets | 1 + src/main/ets/utils/PickerDateTimeHelper.ets | 34 ++++ src/main/ets/utils/ToolsHelper.ets | 5 +- .../utils/compose/DateDialogController.ets | 4 + src/main/ets/utils/compose/DatePickerView.ets | 152 ++++++++++++++++++ src/main/ets/view/SafeView.ets | 6 +- 6 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 src/main/ets/utils/PickerDateTimeHelper.ets create mode 100644 src/main/ets/utils/compose/DateDialogController.ets create mode 100644 src/main/ets/utils/compose/DatePickerView.ets diff --git a/Index.ets b/Index.ets index c9b075d..9510a5c 100644 --- a/Index.ets +++ b/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' /** * 存储相关 diff --git a/src/main/ets/utils/PickerDateTimeHelper.ets b/src/main/ets/utils/PickerDateTimeHelper.ets new file mode 100644 index 0000000..4ce5508 --- /dev/null +++ b/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) + } +} \ No newline at end of file diff --git a/src/main/ets/utils/ToolsHelper.ets b/src/main/ets/utils/ToolsHelper.ets index 4e0e713..55e9957 100644 --- a/src/main/ets/utils/ToolsHelper.ets +++ b/src/main/ets/utils/ToolsHelper.ets @@ -219,6 +219,7 @@ export class ToolsHelper { /** * 弹出List弹窗 * @param options values 如果是非string列表的话,需要存在content字段 + * @param p 调用页面,直接this 即可 */ static showListDialog(options: ListOptions, 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) => { diff --git a/src/main/ets/utils/compose/DateDialogController.ets b/src/main/ets/utils/compose/DateDialogController.ets new file mode 100644 index 0000000..7640c2f --- /dev/null +++ b/src/main/ets/utils/compose/DateDialogController.ets @@ -0,0 +1,4 @@ +export interface DateDialogController{ + confirm: (value:string) => void + cancel: () => void +} \ No newline at end of file diff --git a/src/main/ets/utils/compose/DatePickerView.ets b/src/main/ets/utils/compose/DatePickerView.ets new file mode 100644 index 0000000..7534b73 --- /dev/null +++ b/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) + } + + } +} \ No newline at end of file diff --git a/src/main/ets/view/SafeView.ets b/src/main/ets/view/SafeView.ets index 624e68f..ed036b8 100644 --- a/src/main/ets/view/SafeView.ets +++ b/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() {