import { AppStorageKeyFishCollect, avPlayerManager, BlessCustomCustomDialog, IBestInit, IBestToast, Params, Vibration, YTAvoid, YTHeader, yTRouter, YTUserRequest } from 'basic'; import { faceDetector } from '@kit.CoreVisionKit'; import { trustedAppService } from '@kit.DeviceSecurityKit'; import { promptAction } from '@kit.ArkUI'; import { Cell } from '../models'; import { it } from '@ohos/hypium'; import { TimeTextCom } from '../component/TimeTextCom'; import { CountTextCom } from '../component/CountTextCom'; import { TimeProgressCom } from '../component/TimeProgressCom'; import { AutoAdComponent } from '@ohos.advertising.AutoAdComponent'; import { AutoDesiciTime } from '../component/AutoDesiciTime'; @Component export struct MainView{ @Watch('changeText') @StorageProp(AppStorageKeyFishCollect.FISHTEXT) text:string="" @State private currentIndex: number = 0 tabsController: TabsController = new TabsController() @StorageProp(YTAvoid.SAFE_TOP_KEY) top: number = 0 @State list: Cell[] = []; // 存储所有 Cell 对象的数组 private indexCount: number = 0; // 记录当前滚动的索引 private count: number = 10; // 列表中 Cell 对象的数量 private image: ResourceStr=$r('app.media.muyu') changeText(){ if(this.text!="") { this.list.forEach(item => item.value = this.text) } } //是否是手动 @State isAuto:boolean=false //是否展示侧边工具栏 @State isShowSilder:boolean=true //是否展示信息展示 @State isShowMessage:boolean=true //是否开启声音 @State isOpenMusic:boolean=true //是否开启震动 @State isOpenVibration:boolean=true //动画true/false @State isAnimation:boolean=false @State isShowTimeManger:boolean=false //时间间隔 @State time:number=1000 //当前倒计时 分钟渲染参数 @State valueTime:number=10 //全部用分钟来计算,实际传递给后端用小时制 //实际后端要的小时来算的数据 // @Watch('caluc') @State countdownHour:number=10 //倒计时时间间隔 @State countdownTime:number=1 //倒计时敲击次数渲染文本 // @Watch('caluc') @State countdownCount:string="1" //倒计时自定义的文本分钟 @State countAutoHour:string="" caluc(){ //计算间隔时长 this.countdownTime=this.countdownHour*60/Number(this.countdownCount) } //固定次数 @State fixedNum:number=1 //固定间隔时间 @State fixedTime:number=1 //固定次数渲染文本 @State fixedNumText:string="1" //固定间隔时间渲染文本 @State fixedTimeText:string="1" //无限模式间隔时长 @State infiniteTime:number=1 //无限模式间隔时长渲染文本 @State infiniteTimeText:string="1" //模式 1(结束 手动) 2无限,3固定次数 4倒计时 @State woodenfishModel:number=1 //进度条功德数 @Watch('total') @State currentMerit:number=0 //总功德数 @State totalMerit:number=10 private Merit:number[]=[10,200,500,1000,2000,5000,6000,8000] private MeritIndex:number=0 //自动点击缩放参数 @State scaleValue:number=1 @State inversetId:number=-1 dialogController: CustomDialogController=new CustomDialogController({ builder:BlessCustomCustomDialog({ imgIndex:Math.floor(Math.random()*12) }), alignment:DialogAlignment.Center, customStyle:true, width:'100%', height:'100%', }) total(){ if(this.currentMerit>this.totalMerit){ this.MeritIndex++ this.totalMerit=this.Merit[this.MeritIndex] } } // 初始化方法,在组件即将显示时被调用 aboutToAppear(): void { for (let i = 0; i < this.count; i++) { this.list.push(new Cell()); // 初始化 Cell 数组 } YTUserRequest.getFishFra((res)=>{ // promptAction.showToast({ // message:JSON.stringify(res) // }) AppStorage.setOrCreate('updateID',res.id as number) this.currentMerit=res.meritsValue as number this.woodenfishModel=res.woodenfishModel as number //无限间隔时长 this.infiniteTime=res.infiniteTime as number //固定 this.fixedNum=res.fixedNum as number this.fixedTime=res.fixedTime as number //倒计时 this.countdownTime=res.countdownTime as number this.countdownHour=(res.countdownHour as number) if(this.countdownHour>60){ this.countAutoHour=this.countdownHour.toString() } this.isAuto=this.woodenfishModel!=1?true:false this.text=res.suspensionCharacters as string //需要渲染 this.infiniteTimeText=this.infiniteTime.toString() this.fixedNumText=this.fixedNum.toString() this.fixedTimeText=this.fixedTime.toString() this.countdownCount=(this.countdownHour*60/this.countdownTime).toString() for (let i = 0; i < this.Merit.length; i++) { if(this.currentMerit>this.Merit[i]&&this.currentMerit { // 动画完成后的回调 this.scaleValue=1 animateToImmediately({ // 再次立即开始动画 duration: 250, // 动画持续时间为1000毫秒 onFinish:()=>{ this.isAnimation=false this.closeMusic() } }, () => { this.list[index].y = -150 // 设置 Cell 的垂直偏移量 this.list[index].opacity = 0 // 设置 Cell 的透明度 }) } }, () => { this.list[index].y = 0 // 设置 Cell 的垂直偏移量 this.list[index].opacity = 1 // 设置 Cell 的透明度 this.scaleValue=0.8 }) } //自动敲击 autoOnclick(){ clearInterval(this.inversetId) if(this.woodenfishModel==1){ this.isAuto=false }else if(this.woodenfishModel==2){ this.inversetId= setInterval(()=>{ this.onclikMerit() },this.infiniteTime*1000) }else if(this.woodenfishModel==3){ this.inversetId=setInterval(()=>{ this.onclikMerit() },this.fixedTime*1000) const b=setTimeout(()=>{ clearInterval(this.inversetId) clearTimeout(b) },this.fixedTime*1000*this.fixedNum) }else if(this.woodenfishModel==4){ this.onclikMerit() this.inversetId=setInterval(()=>{ this.onclikMerit() },this.countdownTime*1000) const b=setTimeout(()=>{ clearInterval(this.inversetId) clearTimeout(b) },this.countdownHour*60000) } } @Builder TimeMangerBuilder(){ Column(){ //图标 Row(){ Image($r('[basic].media.quxiao')).width(20).onClick(()=>{ this.isShowTimeManger = false this.caluc() // 发送请求 YTUserRequest.updateFishWoodenModel( { countdownHour:this.countdownHour, countdownTime:this.countdownTime, fixedNum:this.fixedNum, fixedTime:this.fixedTime, infiniteTime:this.infiniteTime, woodenfishModel:this.woodenfishModel } as Params) // promptAction.showToast({ // message:JSON.stringify( { // countdownHour:this.countdownHour, // countdownTime:this.countdownTime, // fixedNum:this.fixedNum, // fixedTime:this.fixedTime, // infiniteTime:this.infiniteTime, // woodenfishModel:this.woodenfishModel // } as Params) // }) this.autoOnclick() }) }.width('100%') .justifyContent(FlexAlign.End) //标题 Row(){ Text('自动敲击设置').fontColor(Color.White).fontSize(20) }.width('100%') .justifyContent(FlexAlign.Center) .margin({bottom:20}) Stack({alignContent:Alignment.Top}) { Tabs({ barPosition: BarPosition.Start, controller: this.tabsController,index:this.currentIndex }) { TabContent() { Column() { Column() { TimeTextCom({ onclickTime: this.infiniteTimeText, changeText: (value: string) => { this.infiniteTimeText = value //获取到无限模式间隔时间 this.infiniteTime=Number(this.infiniteTimeText) } }) }.width('100%') .height(136) .borderRadius(8) .padding(20) .backgroundColor('rgba(77, 77, 77, 1)') }.layoutWeight(1).justifyContent(FlexAlign.Start) }.tabBar('无限').layoutWeight(1) TabContent() { Column(){ Column({space:16}) { CountTextCom({ onclickCount:this.fixedNumText, changeOnclickCount:(value:string)=>{ this.fixedNumText=value //固定模式敲击次数 this.fixedNum=Number(this.fixedNumText) } }) TimeTextCom({ onclickTime:this.fixedTimeText, changeText:(value:string)=>{ this.fixedTimeText=value //固定模式间隔时间 this.fixedTime=Number(this.fixedTimeText) } }) }.width('100%').height(210).borderRadius(8).padding(20).backgroundColor('rgba(77, 77, 77, 1)') }.layoutWeight(1).justifyContent(FlexAlign.Start) }.tabBar('固定次数').layoutWeight(1) TabContent() { Column(){ Column({space:16}) { TimeProgressCom({ progressValue:this.countdownHour, changeTabCurrNumberAndCountTime:(progressValue:string,tabIndex?:number,)=>{ if(progressValue!='自定义') { this.countdownHour = Number(progressValue) } if(tabIndex==3) { this.tabsController.changeIndex(tabIndex) } } }) CountTextCom({ onclickCount:this.countdownCount, changeOnclickCount:(value:string)=>{ this.countdownCount=value } }) }.width('100%').borderRadius(8).padding(20).backgroundColor('rgba(77, 77, 77, 1)') }.layoutWeight(1).justifyContent(FlexAlign.Start) }.tabBar('倒计时').layoutWeight(1) TabContent() { Column(){ AutoDesiciTime({ countAutoHour:this.countAutoHour, changeAutoHour:(countAutoHour:string)=>{ this.countAutoHour=countAutoHour this.countdownHour=Number(this.countAutoHour) }, backTab:(woodenfishModel:number,tabChangeIndex:number)=>{ this.woodenfishModel=woodenfishModel this.tabsController.changeIndex(tabChangeIndex) } }) }.layoutWeight(1).justifyContent(FlexAlign.Start) }.tabBar('自定义').layoutWeight(1) }.width('100%').margin({top:20}).barHeight(0) Row(){ Text('无限') .layoutWeight(1) .textAlign(TextAlign.Center) .borderRadius(10) .height(40) .fontColor(this.currentIndex==0?Color.Black:'rgba(255, 255, 255, 0.35)') .backgroundColor(this.currentIndex==0?'rgba(250, 222, 113, 1)':Color.Transparent) .onClick(()=>{ this.currentIndex=0 this.tabsController.changeIndex(this.currentIndex) this.woodenfishModel=2 }) Text('固定次数') .layoutWeight(1) .textAlign(TextAlign.Center) .borderRadius(10) .height(40) .fontColor(this.currentIndex==1?Color.Black:'rgba(255, 255, 255, 0.35)') .backgroundColor(this.currentIndex==1?'rgba(250, 222, 113, 1)':Color.Transparent).onClick(()=>{ this.currentIndex=1 this.tabsController.changeIndex(this.currentIndex) this.woodenfishModel=3 }) Text('倒计时') .layoutWeight(1) .borderRadius(10) .textAlign(TextAlign.Center) .height(40) .fontColor((this.currentIndex==2||this.currentIndex==3)?Color.Black:'rgba(255, 255, 255, 0.35)') .backgroundColor((this.currentIndex==2||this.currentIndex==3)?'rgba(250, 222, 113, 1)':Color.Transparent) .onClick(()=>{ this.currentIndex=2 this.tabsController.changeIndex(this.currentIndex) this.woodenfishModel=4 }) }.width('100%') .borderRadius(10) .height(40) .backgroundColor('rgba(77, 77, 77, 1)') }.layoutWeight(1) }.width('100%') .height('100%') .padding(20) .backgroundColor('rgba(25, 25, 25, 1)') } clockFish(){ YTUserRequest.knockingFish() } build() { Stack() { Image($r('[basic].media.dengguang')).width('100%').height('100%') Image($r('[basic].media.dizuo')).width(256).height(60).margin({top:460}) Column() { Stack({ alignContent: Alignment.Bottom }) { Column() { if (this.isShowMessage) { Row() { Column({ space: 20 }) { //积功德+清零 Row() { Text() { Span('积功德: ').fontColor(Color.White).fontSize(18) Span(`${this.currentMerit}`).fontSize(18).fontColor($r('[basic].color.login_main_yellow')) }.margin({ left: 50 }) Row() { Text('清零') .borderRadius(20) .fontSize(14) .padding({ left: 8, right: 8, top: 5, bottom: 5 }) .backgroundColor($r('[basic].color.login_main_yellow')) .fontColor('rgba(0, 0, 0, 0.95)') .onClick(() => { this.currentMerit = 0 this.totalMerit=this.Merit[0] YTUserRequest.resetFish() }) } }.width('100%').justifyContent(FlexAlign.SpaceAround) //进度条 Column() { Stack({ alignContent: Alignment.Center }) { Progress({ value: this.currentMerit, total: this.totalMerit, type: ProgressType.Ring }) .width(80).color('rgba(61, 186, 208, 1)') .style({ strokeWidth: 7, shadow: true }) .backgroundColor(Color.White) .value(this.currentMerit) Text('集福').fontSize(20).fontColor('rgba(252, 253, 237, 1)') }.margin({ left: 10 }) Text() { Span(`${this.currentMerit}`).fontColor($r('[basic].color.login_main_yellow')) Span(`/${this.totalMerit}`) }.fontColor(Color.White).margin({ left: 10 }).width(80).textAlign(TextAlign.Center) }.width('100%').justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start) }.layoutWeight(1) //右边的按钮 Column({ space: 20 }) { Image($r('[basic].media.shezhix')).width(32).onClick(() => { this.isShowSilder = !this.isShowSilder }) if (this.isShowSilder) { //是否开启声音 Image($r('[basic].media.zhendong')).width(32).onClick(() => { this.isOpenMusic = !this.isOpenMusic }) //是否开启震动 Image($r('[basic].media.shengying')).width(32).onClick(() => { this.isOpenVibration = !this.isOpenVibration }) Column() { Column() { Text(this.isAuto ? '自动' : '手动') .padding({ left: 3, right: 3, top: 10, bottom: 10 }) .margin({ bottom: 10 }) .backgroundColor('#252111') .fontColor(Color.White) .onClick(() => { this.isAuto = !this.isAuto //如果是本来自动,再点击就是手动,不需要设置任何东西 if (this.isAuto) { // this.woodenfishModel } else { //如果本来是手动,再点击就是自动,就需要设置东西 // this.isHand = false this.woodenfishModel=1 clearInterval(this.inversetId) } }) if (this.isAuto) { Column({ space: 10 }) { Text('结束') .padding({ left: 3, right: 3, top: 10, bottom: 10 }) .fontColor(Color.White) .backgroundColor('#252111') .onClick(() => { this.isAuto = !this.isAuto if(this.isAuto==false){ this.woodenfishModel=1 clearInterval(this.inversetId) } }) Text('无限') .padding({ left: 3, right: 3, top: 10, bottom: 10 }) .fontColor(Color.White) .backgroundColor('#252111') .bindSheet($$this.isShowTimeManger, this.TimeMangerBuilder , { width: '100%', height: 400, showClose: false, onWillDismiss: ((dismissSheetAction: DismissSheetAction) => { if (dismissSheetAction.reason == DismissReason.SLIDE_DOWN) { dismissSheetAction.dismiss(); //注册dismiss行为 } }), }) .onClick(() => { this.isShowTimeManger = true this.woodenfishModel=2 // YTUserRequest.getFishFra((res)=>{ // // promptAction.showToast({ // message:JSON.stringify(res) // }) // AppStorage.setOrCreate('updateID',res.id as number) // this.currentMerit=res.meritsValue as number // this.woodenfishModel=res.woodenfishModel as number // //无限间隔时长 // this.infiniteTime=res.infiniteTime as number // //固定 // this.fixedNum=res.fixedNum as number // this.fixedTime=res.fixedTime as number // // //倒计时 // this.countdownTime=res.countdownTime as number // this.countdownHour=(res.countdownHour as number) // this.isAuto=this.woodenfishModel!=1?true:false // //判断是否自动并设置敲击时间 // clearInterval(this.inversetId) // //自动敲击 // // this.autoOnclick() // // }) }) Text('设置') .padding({ left: 3, right: 3, top: 10, bottom: 10 }) .fontColor(Color.White) .backgroundColor('#252111') .onClick(() => { //去往设置页面 yTRouter.router2FishSettingPage() }) } } } } } }.width(50) .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.End) }.width('100%') .height(400) .alignItems(VerticalAlign.Top) } } .height('100%') .margin({ top: 20 }) Column() { Stack() { // 创建一个堆栈布局容器 ForEach(this.list, (item: Cell, _index: number) => { // 遍历 list 中的每一个 Cell Text(item.value)// 显示 Cell 中的文字 .fontColor(Color.White)// 设置文字颜色为白色 .fontSize('50lpx')// 设置文字大小 .translate({ x: 0, y: `${item.y}lpx` })// 设置文字的垂直偏移量 .opacity(item.opacity) // 设置文字的透明度 }) } .width(200) // .height(70) .align(Alignment.BottomEnd) Image(this.image) .width(200) .height(200) .objectFit(ImageFit.Contain) .scale({ x:this.scaleValue, y:this.scaleValue }) // .clickEffect({ // // 点击效果配置 // scale: 0.5, // 缩放比例 // level: ClickEffectLevel.LIGHT // 效果级别 // }) .onClick(() => { // 点击图片时触发的回调 if(!this.isAuto) { this.onclikMerit() } }) Row() { Image($r('[basic].media.suoxiao')).width(24).onClick(() => { this.isShowMessage = !this.isShowMessage }) }.width('100%') .margin({ top: 50 }) .justifyContent(FlexAlign.End) } .width('100%') .margin({ bottom: 20 }) }.height('100%') // Row(){ // Button('改变文字').onClick(()=>{ // this.list.forEach(item=>{item.value='吴亮+1'}) // }) // Button('敲击时长间隔1秒').onClick(()=>{ // this.time=1000 // // }) // Button('固定10次').onClick(()=>{ // //自动敲击 // const a=setInterval(()=>{ // this.onclikMerit() // // },this.time) // const b=setTimeout(()=>{ // clearInterval(a) // clearTimeout(b) // },this.time*10) // // // }) // Button('倒计时规定时间').onClick(()=>{ // this.onclikMerit() // const a=setInterval(()=>{ // this.onclikMerit() // },this.time) // const b=setTimeout(()=>{ // clearInterval(a) // clearTimeout(b) // },10000) // // }) // } // // Button('xxx').bindSheet($$this.isShowTimeManger,this.timeMangerBuilder(),{ // width:'100%', // height:400, // showClose:false // }).onClick(()=>{ // this.isShowTimeManger=true // }) // // Button('震动').onClick(()=>{ // Vibration.startVibration() // }) // Stack() { // Progress({ value: this.valueTime, total: 70, type: ProgressType.Linear }).backgroundColor(Color.White) // Row({space:30}){ // ForEach([0,10,20,30,40,50,60,70],(item:number)=>{ // Column(){ // }.width(10) // .height(10) // .borderRadius('50%') // .onClick(()=>{ // this.valueTime=item // }) // .backgroundColor(this.valueTime>=item?Color.Pink:Color.White) // }) // // // }.width('100%') // // } }.width('100%') .height('100%') .padding({ top: this.top + 22, left: 20, right: 20 }) }.backgroundColor(Color.Black) } }