refactor(app): 优化登录页面和对话框逻辑

- 修改登录页面布局,增加 SafeView 组件
- 优化用户不存在时的提示对话框
- 调整未签名批次视图的加载逻辑
- 重构 ToolsHelper 中的对话框显示逻辑
- 修改 API 配置的 showLog属性
这个提交包含在:
徐勤民 2025-04-29 18:03:54 +08:00
父节点 b7d0288643
当前提交 699de803ec
共有 3 个文件被更改,包括 95 次插入69 次删除

查看文件

@ -28,7 +28,10 @@ export class GlobalContext {
static popUIContext(): void { static popUIContext(): void {
globalThis._uiUIContext.splice(globalThis._uiUIContext.length-1,1) globalThis._uiUIContext.splice(globalThis._uiUIContext.length-1,1)
} }
static getUiContext(): UIContext { static getUiContext(): UIContext|undefined {
if (globalThis._uiUIContext === undefined) {
return undefined;
}
return globalThis._uiUIContext[globalThis._uiUIContext.length-1]; return globalThis._uiUIContext[globalThis._uiUIContext.length-1];
} }
} }

查看文件

@ -295,7 +295,7 @@ export class ToolsHelper {
static closeAlertDialog(dialogTag: string) { static closeAlertDialog(dialogTag: string) {
if (ToolsHelper.mapAlertDialog.get(dialogTag)) { if (ToolsHelper.mapAlertDialog.get(dialogTag)) {
try { try {
GlobalContext.getUiContext().getPromptAction().closeCustomDialog(ToolsHelper.mapAlertDialog.get(dialogTag)) GlobalContext.getUiContext()?.getPromptAction().closeCustomDialog(ToolsHelper.mapAlertDialog.get(dialogTag))
} catch (err) { } catch (err) {
} }
ToolsHelper.mapAlertDialog.remove(dialogTag) ToolsHelper.mapAlertDialog.remove(dialogTag)
@ -309,34 +309,45 @@ export class ToolsHelper {
static showAlertDialog(options: AlertOptions) { static showAlertDialog(options: AlertOptions) {
const dialogTag = ToolsHelper.getUuid() const dialogTag = ToolsHelper.getUuid()
const ui = GlobalContext.getUiContext() const ui = GlobalContext.getUiContext()
const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder), if (ui) {
new AlertBean({ title: options.title, msg: options.msg, confirm: options.action }, dialogTag)) const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder),
ui.getPromptAction().openCustomDialog(c, { new AlertBean({ title: options.title, msg: options.msg, confirm: options.action }, dialogTag))
autoCancel: false ui.getPromptAction().openCustomDialog(c, {
}).then(() => { autoCancel: false
ToolsHelper.mapAlertDialog.set(dialogTag, c) }).then(() => {
}).catch(() => { ToolsHelper.mapAlertDialog.set(dialogTag, c)
try { }).catch(() => {
promptAction.showDialog({ ToolsHelper.showCommonAlert(options)
alignment: DialogAlignment.Center, })
title: options.title, } else {
message: options.msg, ToolsHelper.showCommonAlert(options)
buttons: [{ }
text: options.action?.text ?? "确定", }
color: options.action?.color ?? "#000000",
}] private static showCommonAlert(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()
}) })
.then(() => { .catch((err: Error) => {
options.action?.onClick && options.action?.onClick() if (err.message === 'cancel') {
}) } else {
.catch((err: Error) => {
ToolsHelper.showMessage(err.message) ToolsHelper.showMessage(err.message)
}) }
} catch (error) { })
let message = (error as BusinessError).message } catch (error) {
ToolsHelper.showMessage(message) let message = (error as BusinessError).message
} ToolsHelper.showMessage(message)
}) }
} }
/** /**
@ -347,49 +358,61 @@ export class ToolsHelper {
const dialogTag = ToolsHelper.getUuid() const dialogTag = ToolsHelper.getUuid()
const ui = GlobalContext.getUiContext() const ui = GlobalContext.getUiContext()
const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder), if (ui) {
new AlertBean({ const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder),
title: options.title, new AlertBean({
msg: options.msg,
cancel: options.cancel ?? {},
confirm: options.confirm
}, dialogTag))
ui.getPromptAction().openCustomDialog(c, {
autoCancel: false
}).then(() => {
ToolsHelper.mapAlertDialog.set(dialogTag, c)
}).catch(() => {
try {
promptAction.showDialog({
alignment: 1,
title: options.title, title: options.title,
message: options.msg, msg: options.msg,
buttons: [{ cancel: options.cancel ?? {},
text: options.cancel?.text ?? "取消", confirm: options.confirm
color: options.cancel?.color ?? "#666666", }, dialogTag))
}, { ui.getPromptAction().openCustomDialog(c, {
text: options.confirm?.text ?? "确定", autoCancel: false
color: options.confirm?.color ?? "#000000", }).then(() => {
},] ToolsHelper.mapAlertDialog.set(dialogTag, c)
}) }).catch(() => {
.then((data) => { ToolsHelper.showCommonConfirm(options)
if (data.index === 0) { })
options.cancel?.onClick && options.cancel.onClick() } else {
} else { ToolsHelper.showCommonConfirm(options)
options.confirm?.onClick && options.confirm.onClick() }
}
})
.catch((err: Error) => {
ToolsHelper.showMessage(err.message)
})
} catch (error) {
let message = (error as BusinessError).message
ToolsHelper.showMessage(message)
}
})
} }
static showCommonConfirm(options: ConfirmOptions) {
try {
promptAction.showDialog({
alignment: 1,
title: options.title,
message: options.msg,
buttons: [{
text: options.cancel?.text ?? "取消",
color: options.cancel?.color ?? "#666666",
}, {
text: options.confirm?.text ?? "确定",
color: options.confirm?.color ?? "#000000",
},]
})
.then((data) => {
if (data.index === 0) {
options.cancel?.onClick && options.cancel.onClick()
} else {
options.confirm?.onClick && options.confirm.onClick()
}
})
.catch((err: Error) => {
if (err.message === 'cancel') {
options.cancel?.onClick && options.cancel.onClick()
} else {
ToolsHelper.showMessage(err.message)
}
})
} catch (error) {
let message = (error as BusinessError).message
ToolsHelper.showMessage(message)
}
}
public static mapDialog = new HashMap<string, number>() public static mapDialog = new HashMap<string, number>()
public static mapAlertDialog = new HashMap<string, ComponentContent<Object>>() public static mapAlertDialog = new HashMap<string, ComponentContent<Object>>()

查看文件

@ -30,7 +30,7 @@ export struct SafeView {
@Prop hideBack: boolean @Prop hideBack: boolean
// 是否显示浅色返回按钮 // 是否显示浅色返回按钮
@Prop lightBack: boolean @Prop lightBack: boolean
// 是否显示返回按钮 // 是否显示导航栏
@Prop hideNavBar: boolean @Prop hideNavBar: boolean
/** /**
* 是否显示左侧角标,存在onClickLeft时生效 * 是否显示左侧角标,存在onClickLeft时生效
@ -42,7 +42,7 @@ export struct SafeView {
@Prop showBadgeRight: boolean; @Prop showBadgeRight: boolean;
// 设置返回按钮事件,如果hideBack为true,该事件无效 // 设置返回按钮事件,如果hideBack为true,该事件无效
onBackEvent?: () => void onBackEvent?: () => void
// 设置返回按钮事件 // 设置导航栏点击事件
@Prop onClickLeft: TitleBarBtn @Prop onClickLeft: TitleBarBtn
@Prop onClickRight: TitleBarBtn @Prop onClickRight: TitleBarBtn
// 设置导航栏底下标题 // 设置导航栏底下标题