HarmonyOS 如何实现popupwindow功能

HarmonyOS
2025-01-09 17:13:25
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

示例参考如下:

export class PageIndex {
  pageString: string = "";
  pageIndex: number = 0;
  startIndex: number = 0;
  endIndex: number = 0;
}

@Entry
@Component
struct TestPopUp {
  @State pageColorStart: string = '#FF8C6754'
  @State isPopWindowShow: boolean = false
  @State mPageIndex: PageIndex[] = []

  aboutToAppear(): void {
    this.mPageIndex = this.computePagerIndex(50, 1024, true)
  }

  build() {
    Column() {
      Line()
        .width('100%')
        .height('1px')
        .backgroundColor(Color.Red)
        .bindPopup(this.isPopWindowShow, {
          builder: this.popupBuilder, // 气泡的内容
          placement: Placement.Bottom, // 气泡的弹出位置
          backgroundBlurStyle: BlurStyle.NONE,
          enableArrow: false,
          autoCancel: true,
          arrowOffset: 0,
          targetSpace: 0,
          radius: 0,
          width: "100%",
          showInSubWindow: true,
          maskColor: Color.Transparent,
          shadow: { radius: 0, color: Color.Transparent },
          onStateChange: (e) => {
            if (!e.isVisible) {
              this.isPopWindowShow = false
            }
          }
        })
      Button("点击").onClick(() => {
        this.isPopWindowShow = true
      })
    }.justifyContent(FlexAlign.Center).width('100%').height('100%').backgroundColor(Color.White)
  }

  @Builder
  popupBuilder() {
    List() {
      ForEach(this.mPageIndex, (value: PageIndex) => {
        ListItem() {
          Stack({ alignContent: Alignment.TopEnd }) {
            Row() {
              Text(value.pageString).fontSize(13)
            }.justifyContent(FlexAlign.Center).width('100%').height('100%')
          }
          .backgroundColor('#f8f8fa')
          .borderWidth('1.2px')
          .borderRadius(5)
          .width('100%')
          .height(30)
        }.padding(4).onClick(() => {
        })
      }, (value: PageIndex) => {
        return value.pageIndex + "-" + value.pageString
      })
    }
    .width('100%')
    .height(200)
    .lanes(4)
    .borderRadius({ bottomLeft: 10, bottomRight: 10 })
    .backgroundColor("#ffffff")
    .padding(8)
    .onAreaChange((oldArea: Area, newArea: Area) => {
    })
  }

  computePagerIndex(pageSize: number, trackCounts: number, isAsc: boolean): PageIndex[] {
    const mPagerIndexs: PageIndex[] = [];
    const group: number = Math.ceil(trackCounts / pageSize);
    for (let i: number = 0; i < group; i++) {
      const pi: PageIndex = new PageIndex();
      pi.pageIndex = i + 1;
      if (isAsc) {
        pi.startIndex = pageSize * i + 1;
        pi.endIndex = Math.min(pageSize * (i + 1), trackCounts);
        pi.pageString = `${pi.startIndex}~${pi.endIndex}`;
      } else {
        pi.startIndex = trackCounts - pageSize * i;
        pi.endIndex = Math.max(trackCounts - pageSize * (i + 1) + 1, 1);
        pi.pageString = `${pi.startIndex}~${pi.endIndex}`;
      }
      mPagerIndexs.push(pi);
    }
    return mPagerIndexs;
  }
}
  • 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.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
分享
微博
QQ
微信
回复
2025-01-09 19:40:22
相关问题
HarmonyOS 如何实现ImagePreview功能
446浏览 • 1回复 待解决
HarmonyOS 如何实现轮询功能
713浏览 • 1回复 待解决
HarmonyOS 分享功能如何实现
718浏览 • 1回复 待解决
HarmonyOS 如何实现直播功能
711浏览 • 1回复 待解决
HarmonyOS 曝光功能如何实现
671浏览 • 1回复 待解决
HarmonyOS 如何实现DeepLink功能
661浏览 • 1回复 待解决
HarmonyOS 如何实现文件选择功能
648浏览 • 1回复 待解决
HarmonyOS 如何实现图片编辑功能
714浏览 • 1回复 待解决
HarmonyOS 如何实现搜索历史功能
653浏览 • 1回复 待解决
HarmonyOS如何实现头像选择功能
1356浏览 • 1回复 待解决
HarmonyOS 如何实现长按点击功能
708浏览 • 1回复 待解决
定时提醒功能如何实现?
5629浏览 • 1回复 待解决
鸿蒙如何实现分享功能
18730浏览 • 2回复 待解决
Grid如何实现拖拽功能
3116浏览 • 1回复 待解决
HarmonyOS 如何实现马赛克功能
483浏览 • 1回复 待解决
HarmonyOS 防截屏功能如何实现
637浏览 • 1回复 待解决
HarmonyOS如何实现粘贴板功能
928浏览 • 1回复 待解决
HarmonyOS 如何实现手势密码功能
1185浏览 • 1回复 待解决
HarmonyOS 如何实现锚点定位功能
478浏览 • 1回复 待解决
HarmonyOS 如何实现页面的继承功能
661浏览 • 1回复 待解决
HarmonyOS 如何实现应用全局换肤功能
506浏览 • 1回复 待解决