HarmonyOS 没有全局的api loading动画

接口请求需要全局的loading动画,并且可以进行遮罩(类型微信那种wx.showLoading的方法)。

HarmonyOS
2024-10-28 10:54:43
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

​可以使用promptAction.openCustomDialog自定义弹窗实现loading效果,参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-0000001815086746-V5#ZH-CN_TOPIC_0000001834458276__promptactionopencustomdialog11

https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-promptAction.md#promptactionopencustomdialog11

以下提供个demo可以参考下:

//Index.ets​

import { changeDialogBuilder, MyShowTest } from '../common/HttpUtils'  
import {customDialogBuilder} from './testProm'  
let myShowTest = new MyShowTest()  
@Entry  
@Component  
struct Index {  
  @State message: string = 'Hello World'  
  onPageShow(): void {  
    changeDialogBuilder(customDialogBuilder.bind(this))  
  }  
  build() {  
    Row() {  
      Column() {  
        Text(this.message)  
          .fontSize(50)  
          .fontWeight(FontWeight.Bold)  
          .onClick(() => {  
            myShowTest.showTest()  
          })  
      }  
      .width('100%')  
    }  
    .height('100%')  
  }  
}
  • 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.

//testProm.ets

@Builder  
export function customDialogBuilder() {  
  Column() {  
    Text('正在加载中').fontSize(16)  
  }.height(100).width(100)  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

//HttpUtils.ets

import promptAction from '@ohos.promptAction'  
let myDialogBuilder: CustomBuilder;  
let customDialogId: number = 0  
export function changeDialogBuilder(builder: CustomBuilder) {  
  myDialogBuilder = builder  
}  
export class MyShowTest {  
  showTest() {  
    if (myDialogBuilder === undefined) {  
      return  
    }  
    promptAction.openCustomDialog({  
      builder: myDialogBuilder,  
      alignment: DialogAlignment.Center,  
    }).then((dialogId: number) => {  
      customDialogId = dialogId  
    })  
    setTimeout(() => {  
      promptAction.closeCustomDialog(customDialogId)  
    }, 2000)  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
分享
微博
QQ
微信
回复
2024-10-28 16:51:31
相关问题
HarmonyOS 全局loading
660浏览 • 1回复 待解决
HarmonyOS 全局loading组件
1084浏览 • 1回复 待解决
HarmonyOS 全局loading实现方案
655浏览 • 1回复 待解决
HarmonyOS 全局loading菊花如何实现?
1143浏览 • 1回复 待解决
HarmonyOS 如何在全局使用loading组件?
1622浏览 • 1回复 待解决
HarmonyOS 是否有全局loading这种控件?
1259浏览 • 1回复 待解决
HarmonyOS 全局loading有什么方案吗
712浏览 • 1回复 待解决
HarmonyOS 视频压缩以及请求全局loading
521浏览 • 1回复 待解决
refresh期望能够自定义loading动画
1350浏览 • 1回复 待解决
HarmonyOS没有接口请求时loading组件
493浏览 • 1回复 待解决
如何全局设置页面转场动画
1078浏览 • 1回复 待解决
HarmonyOS 设置全局字体没有效果
477浏览 • 1回复 待解决
HarmonyOS .scale没有动画效果
524浏览 • 1回复 待解决
HarmonyOS没有单指旋转api
861浏览 • 0回复 待解决
HarmonyOS没有单指旋转api
798浏览 • 1回复 待解决
提问
该提问已有0人参与 ,帮助了0人