refactor(context): 重构上下文管理并优化相关功能
-移除 AppAbility 中的冗余导入 - 调整 MiniAppManager 中的导入顺序 - 重构 GlobalContext 类,使用单个 UIContext 实例替代数组- 优化 SafeView 组件,移除不必要的生命周期方法 -改进 ToolsHelper.showMessage 方法,支持在不同上下文中显示提示信息- 调整 CertDown 页面的逻辑,优化证书下载流程
这个提交包含在:
父节点
13a7ca4e87
当前提交
e8f0a74636
@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
import type common from '@ohos.app.ability.common';
|
import type common from '@ohos.app.ability.common';
|
||||||
import { WindowHelper } from './utils/WindowHelper';
|
import { WindowHelper } from './utils/WindowHelper';
|
||||||
|
import { BusinessError } from '@kit.BasicServicesKit';
|
||||||
|
|
||||||
declare namespace globalThis {
|
declare namespace globalThis {
|
||||||
let _brushEngineContext: common.UIAbilityContext;
|
let _brushEngineContext: common.UIAbilityContext;
|
||||||
let _uiUIContext: UIContext[];
|
let _uiUIContext: UIContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class GlobalContext {
|
export class GlobalContext {
|
||||||
@ -17,22 +18,23 @@ export class GlobalContext {
|
|||||||
|
|
||||||
static setContext(context: common.UIAbilityContext): void {
|
static setContext(context: common.UIAbilityContext): void {
|
||||||
globalThis._brushEngineContext = context;
|
globalThis._brushEngineContext = context;
|
||||||
WindowHelper.windowClass = context.windowStage.getMainWindowSync()
|
|
||||||
|
context.windowStage.getMainWindow((err: BusinessError, data) => {
|
||||||
|
let errCode: number = err.code;
|
||||||
|
if (errCode) {
|
||||||
|
console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
static pushUIContext(context: UIContext): void {
|
WindowHelper.windowClass = data;
|
||||||
if (!globalThis._uiUIContext) {
|
globalThis._uiUIContext = WindowHelper.windowClass.getUIContext();
|
||||||
globalThis._uiUIContext = []
|
});
|
||||||
}
|
|
||||||
globalThis._uiUIContext.push(context);
|
|
||||||
}
|
|
||||||
static popUIContext(): void {
|
|
||||||
globalThis._uiUIContext.splice(globalThis._uiUIContext.length-1,1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getUiContext(): UIContext | undefined {
|
static getUiContext(): UIContext | undefined {
|
||||||
if (globalThis._uiUIContext === undefined) {
|
if (globalThis._uiUIContext === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return globalThis._uiUIContext[globalThis._uiUIContext.length-1];
|
return globalThis._uiUIContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -261,12 +261,20 @@ export class ToolsHelper {
|
|||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
static showMessage(msg: string) {
|
static showMessage(msg: string) {
|
||||||
console.info(msg);
|
|
||||||
|
const pa = GlobalContext.getUiContext()?.getPromptAction()
|
||||||
|
if (pa) {
|
||||||
|
pa.showToast({
|
||||||
|
message: msg,
|
||||||
|
duration: 1500
|
||||||
|
});
|
||||||
|
} else {
|
||||||
promptAction.showToast({
|
promptAction.showToast({
|
||||||
message: msg,
|
message: msg,
|
||||||
duration: 1500
|
duration: 1500
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static oTime: number = 0
|
private static oTime: number = 0
|
||||||
|
|||||||
@ -48,13 +48,6 @@ export struct SafeView {
|
|||||||
// 设置导航栏底下标题
|
// 设置导航栏底下标题
|
||||||
@Prop bottomTitleText: ResourceStr
|
@Prop bottomTitleText: ResourceStr
|
||||||
|
|
||||||
aboutToAppear(): void {
|
|
||||||
GlobalContext.pushUIContext(this.getUIContext())
|
|
||||||
}
|
|
||||||
aboutToDisappear(): void {
|
|
||||||
GlobalContext.popUIContext()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
doNothingBuilder() {
|
doNothingBuilder() {
|
||||||
}
|
}
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户