|
@@ -12,8 +12,8 @@ export interface Btn {
|
|
|
}
|
|
|
|
|
|
export interface AlertOptions {
|
|
|
- title?: string
|
|
|
- msg?: string
|
|
|
+ title?: string,
|
|
|
+ msg?: string,
|
|
|
action?: Btn
|
|
|
}
|
|
|
|
|
@@ -37,7 +37,7 @@ interface ListItem {
|
|
|
}
|
|
|
|
|
|
@Builder
|
|
|
-function customDialogBuilder<T>(option: ListOptions<T>, dialogId: number) {
|
|
|
+function customDialogBuilder<T>(option: ListOptions<T>, dialogTag: string) {
|
|
|
|
|
|
Column() {
|
|
|
Text(option.title)
|
|
@@ -58,9 +58,9 @@ function customDialogBuilder<T>(option: ListOptions<T>, dialogId: number) {
|
|
|
.fontSize(16)
|
|
|
.textAlign(TextAlign.Center)
|
|
|
.onClick(() => {
|
|
|
- if (ToolsHelper.mapDialog.get(dialogId)) {
|
|
|
- promptAction.closeCustomDialog(ToolsHelper.mapDialog.get(dialogId))
|
|
|
- ToolsHelper.mapDialog.remove(dialogId)
|
|
|
+ if (ToolsHelper.mapDialog.get(dialogTag)) {
|
|
|
+ promptAction.closeCustomDialog(ToolsHelper.mapDialog.get(dialogTag))
|
|
|
+ ToolsHelper.mapDialog.remove(dialogTag)
|
|
|
}
|
|
|
option.onSelected(index, item)
|
|
|
})
|
|
@@ -149,22 +149,19 @@ export class ToolsHelper {
|
|
|
* 弹出Alert弹窗
|
|
|
* @param options
|
|
|
*/
|
|
|
- static showAlertDialog(
|
|
|
- title?: string,
|
|
|
- msg?: string,
|
|
|
- action?: Btn) {
|
|
|
+ static showAlertDialog(options: AlertOptions) {
|
|
|
try {
|
|
|
promptAction.showDialog({
|
|
|
- alignment: 1,
|
|
|
- title: title,
|
|
|
- message: msg,
|
|
|
+ alignment: DialogAlignment.Center,
|
|
|
+ title: options.title,
|
|
|
+ message: options.msg,
|
|
|
buttons: [{
|
|
|
- text: action?.text ?? "确定",
|
|
|
- color: action?.color ?? "#000000",
|
|
|
+ text: options.action?.text ?? "确定",
|
|
|
+ color: options.action?.color ?? "#000000",
|
|
|
}]
|
|
|
})
|
|
|
.then(() => {
|
|
|
- action?.onClick && action?.onClick()
|
|
|
+ options.action?.onClick && options.action?.onClick()
|
|
|
})
|
|
|
.catch((err: Error) => {
|
|
|
ToolsHelper.showMessage(err.message)
|
|
@@ -209,7 +206,7 @@ export class ToolsHelper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static mapDialog = new HashMap<number, number>()
|
|
|
+ public static mapDialog = new HashMap<string, number>()
|
|
|
|
|
|
/**
|
|
|
* 弹出List弹窗
|
|
@@ -228,7 +225,7 @@ export class ToolsHelper {
|
|
|
if (isSuccess.length > 0) {
|
|
|
options.onError && options.onError(`第(${isSuccess.join("、")})个数据中,没有content字段。`)
|
|
|
} else {
|
|
|
- const dialogTag = new Date().getTime()
|
|
|
+ const dialogTag = ToolsHelper.getUuid()
|
|
|
promptAction.openCustomDialog({
|
|
|
alignment: 1,
|
|
|
builder: customDialogBuilder.bind(p, options, dialogTag)
|
|
@@ -242,8 +239,7 @@ export class ToolsHelper {
|
|
|
* 弹出自定义弹窗
|
|
|
* @param alignment 弹窗在竖直方向上的对齐方式
|
|
|
*/
|
|
|
- static showCustomDialog(b: CustomBuilder, alignment?: DialogAlignment) {
|
|
|
- const dialogTag = new Date().getTime()
|
|
|
+ static showCustomDialog(dialogTag: string, b: CustomBuilder, alignment?: DialogAlignment) {
|
|
|
promptAction.openCustomDialog({
|
|
|
alignment: alignment ?? DialogAlignment.Center,
|
|
|
builder: b
|
|
@@ -254,6 +250,17 @@ export class ToolsHelper {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 关闭自定义弹窗
|
|
|
+ * @param dialogTag 开启时的tag
|
|
|
+ */
|
|
|
+ static closeCustomDialog(dialogTag: string) {
|
|
|
+ if (ToolsHelper.mapDialog.get(dialogTag)) {
|
|
|
+ promptAction.closeCustomDialog(ToolsHelper.mapDialog.get(dialogTag))
|
|
|
+ ToolsHelper.mapDialog.remove(dialogTag)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取调用栈第一个类
|
|
|
*/
|
|
@@ -314,7 +321,7 @@ export class ToolsHelper {
|
|
|
private static setTimeOutMap: Map<string, ThrottleInterface> = new Map()
|
|
|
private static uniqueIdMap = new WeakMap<Function, string>();
|
|
|
|
|
|
- private static getUuid() {
|
|
|
+ public static getUuid() {
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
|
let r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
|
return v.toString(16);
|