抽奖小程序

entry->src->main->module.json5

"requestPermissions": [ {"name": "ohos.permission.INTERNET"} ],

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  datalist = [{"name":"P50","imgUrl":"https://img1.baidu.com/it/u=3916636701,1432676148&fm=253&fmt=auto&app=138&f=JPEG?w=822&h=500"},
    {"name":"食用油","imgUrl":"https://img0.baidu.com/it/u=945056545,3821334541&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"},
    {"name":"大米","imgUrl":"https://img0.baidu.com/it/u=3786834027,1648217721&fm=253&fmt=auto&app=120&f=JPEG?w=870&h=800"},
    {"name":"PC","imgUrl":"https://img2.baidu.com/it/u=438093967,2270718079&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"},
    {"name":"P50","imgUrl":"https://img1.baidu.com/it/u=3916636701,1432676148&fm=253&fmt=auto&app=138&f=JPEG?w=822&h=500"},
    {"name":"液晶电视","imgUrl":"https://img0.baidu.com/it/u=2113291026,4031727881&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"},
    {"name":"PAD","imgUrl":"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F2f536536-0600-4c0e-b5eb-79be53aa842d%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1682756379&t=e3c5202f540205c5b182165b18acaf1f"},
    {"name":"P50","imgUrl":"https://img1.baidu.com/it/u=3916636701,1432676148&fm=253&fmt=auto&app=138&f=JPEG?w=822&h=500"},
    {"name":"谢谢老板","imgUrl":"https://img0.baidu.com/it/u=1886917040,3182261868&fm=253&fmt=auto&app=138&f=JPEG?w=282&h=279"},

  ]

  //选中奖品的下标
  @State currentIndex: number = 0

  //  旋转的真实坐标
  selectIndex = [0, 1, 2, 5, 8, 7, 6, 3, 0]

  //真实的下标
  @State realIndex: number = 0
  //三元运算符

  //固定抽奖的下标
  mustIndex = 8

  build() {
    Column() {
      Flex({
        direction: FlexDirection.Row,
        justifyContent: FlexAlign.SpaceAround,
        alignItems: ItemAlign.Center,
        wrap: FlexWrap.Wrap,
        alignContent: FlexAlign.SpaceAround
      }) {
        //通过for 循环来创建
        ForEach(this.datalist, (item, index) => {
          if (index == 4) {
            //开始抽奖的按钮
            Text("开始抽奖")
              .width("30%")
              .backgroundColor(Color.Blue)
              .height(140)
              .borderRadius(20)
              .fontColor(Color.White)
              .fontSize(20)
              .fontWeight(FontWeight.Bold)
              .textAlign(TextAlign.Center)
              .onClick(() => {
                this.startGame()
              })
          } else {
            Column() {
              Image(item.imgUrl)
                .height(100)
                .width(100)
                .margin({top:15})
              Text(item.name)
                .fontSize(20)
                .fontColor(Color.Black)
                .fontWeight(FontWeight.Bold)
                .margin({ top: 10, bottom: 10 })
            }.backgroundColor(this.realIndex == index ? Color.Pink : Color.White)
            .borderRadius(20)
            .width("30%")
          }

        })
      }.height(500)
      .backgroundColor("#ffc6ee9d")

      Text("中奖内容:" + this.datalist[this.realIndex].name)
        .fontSize(20)
        .fontColor(Color.Red)
        .fontWeight(FontWeight.Bold)
        .margin({ top: 10 })
    }

  }

  //任务id
  taskId = -1
  //当前转的圈数
  currentCount = 0
  //开始游戏
  startGame() {
    //初始化随机停止数
    this.stopCount = Math.floor(Math.random() * 10) + 40
    this.taskId = setInterval(() => {
      this.countTime()
    }, 150)

  }

  //停止的圈数
  stopCount = 0
  //倒计时函数
  countTime() {
    //周期执行的函数
    if (this.currentCount<this.stopCount) {
      //当前圈数小于停止圈数 才能+1
      this.currentCount++
    }

    this.currentIndex++
    if (this.currentIndex > 7) {
      //重置为起点
      this.currentIndex = 0
    }

    this.realIndex = this.selectIndex[this.currentIndex]
    console.info(this.currentIndex + "")

    //减速操作
    if (this.currentCount == 30) {
      //先停止以前的任务
      clearInterval(this.taskId)
      //重新开启一个比较慢的任务
      this.taskId = setInterval(() => {
        this.countTime()
      }, 400)
    }

    //停止逻辑
    if (this.stopCount == this.currentCount) {

        //可以停止
        clearInterval(this.taskId)

        //重置当前圈数为0
        this.currentCount = 0

    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抽奖小程序是一种基于CSDN平台开发的应用程序,旨在为用户提供简便的抽奖活动管理和参与方式。下面我将从功能、使用方法和优势三个方面对该小程序进行介绍。 首先,抽奖小程序具有丰富的功能。用户可以通过该小程序创建自定义的抽奖活动,设置奖品种类和数量,定义参与条件和抽奖规则等。同时,小程序提供了参与抽奖的入口,用户可以根据活动需求进行报名和参与。在抽奖过程中,小程序还会提供随机抽奖的功能,确保公平公正的抽奖结果。除此之外,抽奖小程序还具备数据统计和分析的功能,用户可以及时获取参与人数、中奖情况等数据,方便后续的运营管理和效果评估。 其次,抽奖小程序使用简便。用户只需在CSDN平台上搜索并下载该小程序,即可方便地进行抽奖活动的管理和运营。小程序界面友好,功能操作简单明了,不需要编程或专业知识,即可快速上手使用,节省了用户的时间和精力。 最后,抽奖小程序具有许多优势。首先,小程序基于CSDN平台,具有强大的用户基础和社区资源,能够吸引更多的用户参与抽奖活动,提高活动的知名度和影响力。其次,小程序抽奖机制公平公正,使用随机算法确保抽奖结果的客观性和公正性。此外,小程序提供的数据统计和分析功能可帮助用户对抽奖活动进行实时监测和优化,提升活动效果和用户体验。最重要的是,抽奖小程序是免费提供给用户使用的,不需要支付额外费用,降低了用户的成本。 综上所述,抽奖小程序是一款方便实用的应用程序,通过简单易上手的操作方式和强大的功能优势,让用户能够更高效地管理、参与和运营抽奖活动。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值