|
@@ -4,7 +4,18 @@ import { buffer, HashMap, util } from '@kit.ArkTS';
|
|
|
import { DeviceInfo } from '../bean/DeviceInfo';
|
|
|
import { common } from '@kit.AbilityKit';
|
|
|
import { md5_hex } from '../util/md5';
|
|
|
-import { LogHelper } from '../../../../Index';
|
|
|
+import { GlobalContext, LogHelper } from '../../../../Index';
|
|
|
+import { ComponentContent } from '@kit.ArkUI';
|
|
|
+
|
|
|
+class AlertBean {
|
|
|
+ options: AlertOptions
|
|
|
+ dialogTag: string
|
|
|
+
|
|
|
+ constructor(options: AlertOptions, dialogTag: string) {
|
|
|
+ this.options = options
|
|
|
+ this.dialogTag = dialogTag
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
export interface Btn {
|
|
|
text?: string | Resource;
|
|
@@ -128,6 +139,30 @@ function customDialogBuilder<T>(option: ListOptions<T>, dialogTag: string) {
|
|
|
}.justifyContent(FlexAlign.Start)
|
|
|
}
|
|
|
|
|
|
+@Builder
|
|
|
+function alertDialogBuilder(options: AlertBean) {
|
|
|
+
|
|
|
+ Column() {
|
|
|
+ Text('---------')
|
|
|
+ .fontSize(16)
|
|
|
+ .fontColor('#00BE87')
|
|
|
+ .textAlign(TextAlign.Center)
|
|
|
+ .width('100%')
|
|
|
+ .height(60)
|
|
|
+ .backgroundColor('#F0FFFA')
|
|
|
+ .borderRadius({
|
|
|
+ topLeft: 10,
|
|
|
+ topRight: 10
|
|
|
+ })
|
|
|
+ .onClick(() => {
|
|
|
+ if (ToolsHelper.mapAlertDialog.get(options.dialogTag)) {
|
|
|
+ ToolsHelper.closeAlertDialog(ToolsHelper.mapAlertDialog.get(options.dialogTag))
|
|
|
+ ToolsHelper.mapAlertDialog.remove(options.dialogTag)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }.justifyContent(FlexAlign.Start)
|
|
|
+}
|
|
|
+
|
|
|
interface ThrottleInterface {
|
|
|
startTime: number; //调用的时间
|
|
|
timeoutNumber: number; //setTimeout的句柄
|
|
@@ -187,31 +222,47 @@ export class ToolsHelper {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
- /**kio9
|
|
|
+ static closeAlertDialog(content: ComponentContent<Object>) {
|
|
|
+ try {
|
|
|
+ GlobalContext.getUiContext().getPromptAction().closeCustomDialog(content)
|
|
|
+ } catch (err) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 弹出Alert弹窗
|
|
|
* @param options
|
|
|
*/
|
|
|
static showAlertDialog(options: AlertOptions) {
|
|
|
- try {
|
|
|
- promptAction.showDialog({
|
|
|
- alignment: DialogAlignment.Center,
|
|
|
- title: options.title,
|
|
|
- message: options.msg,
|
|
|
- buttons: [{
|
|
|
- text: options.action?.text ?? "确定",
|
|
|
- color: options.action?.color ?? "#000000",
|
|
|
- }]
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- options.action?.onClick && options.action?.onClick()
|
|
|
- })
|
|
|
- .catch((err: Error) => {
|
|
|
- // ToolsHelper.showMessage(err.message)
|
|
|
+ const dialogTag = ToolsHelper.getUuid()
|
|
|
+ const ui = GlobalContext.getUiContext()
|
|
|
+ const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder), new AlertBean(options, dialogTag))
|
|
|
+ ui.getPromptAction().openCustomDialog(c,{
|
|
|
+ autoCancel: false
|
|
|
+ }).then(() => {
|
|
|
+ ToolsHelper.mapAlertDialog.set(dialogTag, c)
|
|
|
+ }).catch(() => {
|
|
|
+ try {
|
|
|
+ promptAction.showDialog({
|
|
|
+ alignment: DialogAlignment.Center,
|
|
|
+ title: options.title,
|
|
|
+ message: options.msg,
|
|
|
+ buttons: [{
|
|
|
+ text: options.action?.text ?? "确定",
|
|
|
+ color: options.action?.color ?? "#000000",
|
|
|
+ }]
|
|
|
})
|
|
|
- } catch (error) {
|
|
|
- let message = (error as BusinessError).message
|
|
|
- // ToolsHelper.showMessage(message)
|
|
|
- }
|
|
|
+ .then(() => {
|
|
|
+ options.action?.onClick && options.action?.onClick()
|
|
|
+ })
|
|
|
+ .catch((err: Error) => {
|
|
|
+ ToolsHelper.showMessage(err.message)
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ let message = (error as BusinessError).message
|
|
|
+ ToolsHelper.showMessage(message)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -252,6 +303,7 @@ export class ToolsHelper {
|
|
|
}
|
|
|
|
|
|
public static mapDialog = new HashMap<string, number>()
|
|
|
+ public static mapAlertDialog = new HashMap<string, ComponentContent<Object>>()
|
|
|
|
|
|
/**
|
|
|
* 弹出List弹窗
|