From 6e5dfee8983b7a194f44ab664082bb95edcd41ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Sat, 26 Oct 2024 19:35:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(ywq):=20=E6=96=B0=E5=A2=9E=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E5=85=B3=E7=B3=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加授权关系列表和新增授权医生页面 - 实现授权请求的处理逻辑 - 优化刷新组件,支持分页加载 - 修复确认对话框的返回逻辑 --- src/main/ets/utils/ToolsHelper.ets | 59 ++++++++++++++++-------------- src/main/ets/view/RefreshView.ets | 19 +++++++--- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/main/ets/utils/ToolsHelper.ets b/src/main/ets/utils/ToolsHelper.ets index 98f2422..7793d3d 100644 --- a/src/main/ets/utils/ToolsHelper.ets +++ b/src/main/ets/utils/ToolsHelper.ets @@ -176,34 +176,37 @@ export class ToolsHelper { * 弹出Confirm弹窗 * @param options */ - static showConfirmDialog(options: ConfirmOptions) { - try { - promptAction.showDialog({ - alignment: 1, - title: options.title, - message: options.msg, - buttons: [{ - text: options.confirm?.text ?? "确定", - color: options.confirm?.color ?? "#000000", - }, { - text: options.cancel?.text ?? "取消", - color: options.cancel?.color ?? "#666666", - }] - }) - .then((data) => { - if (data.index === 0) { - options.confirm?.onClick && options.confirm.onClick() - } else { - options.cancel?.onClick && options.cancel.onClick() - } + static showConfirmDialog(options: ConfirmOptions): Promise { + return new Promise((reject) => { + try { + promptAction.showDialog({ + alignment: 1, + title: options.title, + message: options.msg, + buttons: [{ + text: options.confirm?.text ?? "确定", + color: options.confirm?.color ?? "#000000", + }, { + text: options.cancel?.text ?? "取消", + color: options.cancel?.color ?? "#666666", + }] }) - .catch((err: Error) => { - ToolsHelper.showMessage(err.message) - }) - } catch (error) { - let message = (error as BusinessError).message - ToolsHelper.showMessage(message) - } + .then((data) => { + if (data.index === 0) { + options.confirm?.onClick && options.confirm.onClick() + } else { + options.cancel?.onClick && options.cancel.onClick() + } + }) + .catch((err: Error) => { + ToolsHelper.showMessage(err.message) + }) + } catch (error) { + reject() + let message = (error as BusinessError).message + ToolsHelper.showMessage(message) + } + }) } public static mapDialog = new HashMap() @@ -345,7 +348,7 @@ export class ToolsHelper { }); } - private static getUniqueId(fun: Function): string { + static getUniqueId(fun: Function): string { if (!ToolsHelper.uniqueIdMap.has(fun)) { ToolsHelper.uniqueIdMap.set(fun, ToolsHelper.getUuid()); } diff --git a/src/main/ets/view/RefreshView.ets b/src/main/ets/view/RefreshView.ets index 1600338..04bfa0d 100644 --- a/src/main/ets/view/RefreshView.ets +++ b/src/main/ets/view/RefreshView.ets @@ -7,7 +7,9 @@ type ItemType = (string | number | Object) export struct RefreshView { @Link isLoading: boolean @Prop data: Array - onLoadMore?: () => void + @Require keyGenerator?: (item: ESObject, index: number) => string + pageSize: number = 10 + onLoadMore?: (pageNum: number) => void onRefresh?: () => void private startY: number = 0 private endY: number = 0 @@ -15,7 +17,7 @@ export struct RefreshView { private _openMore: boolean = false aboutToAppear(): void { - // this.onRefresh && this.onRefresh() + this.onRefresh && this.onRefresh() } // 使用父组件@Builder装饰的方法初始化子组件@BuilderParam @@ -30,7 +32,7 @@ export struct RefreshView { ListItem() { this.customBuilderParam(item, index) } - }, (index: number) => index.toString()) + }, (item: ESObject, index: number) => this.keyGenerator!(item, index)) } .onTouch((event: TouchEvent) => { const e1 = event.touches[0] @@ -48,13 +50,18 @@ export struct RefreshView { case TouchType.Up: this.endY = e1.y if (this.endY - this.startY < -100 && this._openMore) { - this.onLoadMore && this.onLoadMore() + const v = this.data && (this.data.length % this.pageSize) === 0 + if (v) { + this.onLoadMore && this.onLoadMore(Math.floor(this.data.length / this.pageSize)) + } else { + ToolsHelper.showMessage('没有更多数据了') + } } break } }) .onScrollIndex((first: number, last: number) => { - this.lastNum = last + this.lastNum = last + 1 }) .width('100%') .height('100%') @@ -65,7 +72,7 @@ export struct RefreshView { .width('100%') .height('100%') .textAlign(TextAlign.Center) - + } } .width('100%')