HarmonyOS 有没有接口请求时loading组件

有没有接口请求时loading组件

1、类似于promptAction一样,直接显示在页面最上层

2、不需要laodingProgress页面组件的形式

HarmonyOS
2025-01-09 14:32:20
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

可以参考以下dmeo:

Index.ets

import { GlobalContext } from './GlobalContext';
import { testPromptDialog } from './HttpUtil';

@Entry
@Component
struct Index {
  aboutToAppear(): void {
    GlobalContext.getContext().setObject('UIContext', this)
  }

  build() {
    Row() {
      Column() {
        Button("promptAction弹窗").onClick(() => {
          testPromptDialog()
        })
      }.width('100%')
    }.height('100%')
  }
} 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

GlobalContext.ets

export class GlobalContext {
  private constructor() {
  }

  private static instance: GlobalContext;
  private _objects = new Map<string, Object>();

  public static getContext(): GlobalContext {
    if (!GlobalContext.instance) {
      GlobalContext.instance = new GlobalContext();
    }
    return GlobalContext.instance;
  }

  getObject(value: string): Object | undefined {
    return this._objects.get(value);
  }

  setObject(key: string, objectClass: Object): void {
    this._objects.set(key, objectClass);
  }
} 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

HttpUtil.ets

import { GlobalContext } from './GlobalContext';
import { promptAction } from '@kit.ArkUI';

let customDialogId: number = 0

@Builder
export function customDialogBuilder(content: String) {
  Column() {
    `Text(Tip: ${content} `
    )
    .
    fontSize(20).height("30%")
    Text('失败原因:失败原因!').fontSize(16).height("30%")
    Row() {
      Button("确认").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
      Blank().width(50)
      Button("取消").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
    }.margin({ top: 30 })
  }.height(200).padding(5)
}

export function testPromptDialog() {
  const that = GlobalContext.getContext().getObject('UIContext') as UIContext;
  if (that) {
    promptAction.openCustomDialog({ builder: customDialogBuilder.bind(that, "网络请求失败!") })
      .then((dialogId: number) => {
        customDialogId = dialogId;
      })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
分享
微博
QQ
微信
回复
2025-01-09 18:08:25
相关问题
鸿蒙JS开发 接口请求loading?
6199浏览 • 1回复 待解决
鸿蒙JS开发 接口请求loading??
7013浏览 • 1回复 已解决
鸿蒙JS开发 蓠接口请求loading?
4261浏览 • 1回复 待解决
HarmonyOS 接口请求处理
913浏览 • 1回复 待解决
HarmonyOS axios接口请求
701浏览 • 1回复 待解决
HarmonyOS 接口请求处理处理
703浏览 • 1回复 待解决
HarmonyOS 网络接口请求查看功能
537浏览 • 1回复 待解决
HarmonyOS 接口请求数据处理
566浏览 • 1回复 待解决
HarmonyOS 如何发起网络接口请求
599浏览 • 1回复 待解决
HarmonyOS 网络请求loading
592浏览 • 1回复 待解决
有没有接口能获取到组件的宽度
1363浏览 • 1回复 待解决
HarmonyOS 轮询请求有没有限制
401浏览 • 1回复 待解决
HarmonyOS 网络请求loading
619浏览 • 1回复 待解决
有没有调用日历的接口?
6974浏览 • 1回复 待解决
有没有获取appid的接口
1620浏览 • 1回复 待解决
没有专类Post请求接口公共请求
3340浏览 • 1回复 待解决
HarmonyOS APP有没有清除缓存的接口
1116浏览 • 1回复 待解决