MainView.ets 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. import { AppStorageKeyFishCollect, avPlayerManager, Vibration, YTAvoid, YTHeader, yTRouter } from 'basic';
  2. import { faceDetector } from '@kit.CoreVisionKit';
  3. import { trustedAppService } from '@kit.DeviceSecurityKit';
  4. import { promptAction } from '@kit.ArkUI';
  5. import { Cell } from '../models';
  6. @Component
  7. export struct MainView{
  8. @Watch('changeText')
  9. @StorageProp(AppStorageKeyFishCollect.FISHTEXT)
  10. text:string=""
  11. @State private currentIndex: number = 0
  12. tabsController: TabsController = new TabsController()
  13. @StorageProp(YTAvoid.SAFE_TOP_KEY) top: number = 0
  14. @State list: Cell[] = []; // 存储所有 Cell 对象的数组
  15. private indexCount: number = 0; // 记录当前滚动的索引
  16. private count: number = 10; // 列表中 Cell 对象的数量
  17. private image: ResourceStr=$r('app.media.muyu')
  18. changeText(){
  19. if(this.text!="") {
  20. this.list.forEach(item => item.value = this.text)
  21. }
  22. }
  23. //是否是手动
  24. @State isAuto:boolean=false
  25. //是否展示侧边工具栏
  26. @State isShowSilder:boolean=true
  27. //是否展示信息展示
  28. @State isShowMessage:boolean=true
  29. //是否开启声音
  30. @State isOpenMusic:boolean=true
  31. //是否开启震动
  32. @State isOpenVibration:boolean=true
  33. //动画true/false
  34. @State isAnimation:boolean=false
  35. //进度条
  36. @State currentMerit:number=0
  37. @State totalMerit:number=500
  38. //时间间隔
  39. @State time:number=1000
  40. @State isShowTimeManger:boolean=false
  41. @State valueTime:number=10
  42. //开启关闭音乐
  43. async openMusic(){
  44. await avPlayerManager.playByRawSrc('music3.mp3')
  45. }
  46. async closeMusic(){
  47. await avPlayerManager.stop()
  48. }
  49. //点击动画
  50. onclikMerit(){
  51. if(this.isAnimation){
  52. return
  53. }
  54. if(this.isOpenMusic){
  55. this.openMusic()
  56. }
  57. if(this.isOpenVibration){
  58. Vibration.startVibration()
  59. }
  60. this.isAnimation=true
  61. this.currentMerit++
  62. let index = this.indexCount % this.count; // 计算当前滚动的索引
  63. this.indexCount++; // 更新索引计数器
  64. animateToImmediately({
  65. // 立即开始动画
  66. duration: 0, // 动画持续时间为0毫秒
  67. onFinish: () => { // 动画完成后的回调
  68. animateToImmediately({
  69. // 再次立即开始动画
  70. duration: 500, // 动画持续时间为1000毫秒
  71. onFinish:()=>{
  72. this.isAnimation=false
  73. this.closeMusic()
  74. }
  75. }, () => {
  76. this.list[index].y = -200 // 设置 Cell 的垂直偏移量
  77. this.list[index].opacity = 0 // 设置 Cell 的透明度
  78. })
  79. }
  80. }, () => {
  81. this.list[index].y = 0 // 设置 Cell 的垂直偏移量
  82. this.list[index].opacity = 1 // 设置 Cell 的透明度
  83. })
  84. }
  85. @Builder
  86. timeMangerBuilder(){
  87. Column(){
  88. Stack({alignContent:Alignment.Top}) {
  89. Tabs({ barPosition: BarPosition.Start, controller: this.tabsController }) {
  90. TabContent() {
  91. Column() {
  92. Text('敲击间隔时长(1-10秒)')
  93. Row() {
  94. TextInput()
  95. .width(70)
  96. .height(40)
  97. .padding(0)
  98. .type(InputType.Number) // 设置输入类型为数字
  99. .textAlign(TextAlign.Center)
  100. .borderRadius(4)
  101. .backgroundColor(Color.Gray)
  102. Text('秒')
  103. }
  104. }
  105. }.tabBar('无限')
  106. TabContent() {
  107. Column() {
  108. Column() {
  109. Text('敲击次数(1-9999次)')
  110. Row() {
  111. TextInput()
  112. .width(70)
  113. .height(40)
  114. .padding(0)
  115. .type(InputType.Number) // 设置输入类型为数字
  116. .textAlign(TextAlign.Center)
  117. .borderRadius(4)
  118. .backgroundColor(Color.Gray)
  119. Text('秒')
  120. }
  121. }
  122. Column() {
  123. Text('敲击间隔时长(1-10秒)')
  124. Row() {
  125. TextInput()
  126. .width(70)
  127. .height(40)
  128. .padding(0)
  129. .type(InputType.Number) // 设置输入类型为数字
  130. .textAlign(TextAlign.Center)
  131. .borderRadius(4)
  132. .backgroundColor(Color.Gray)
  133. Text('秒')
  134. }
  135. }
  136. }
  137. }.tabBar('固定次数')
  138. TabContent() {
  139. Column() {
  140. Column() {
  141. Text('倒计时(1-9999次)')
  142. Stack() {
  143. Progress({ value: this.valueTime, total: 70, type: ProgressType.Linear }).backgroundColor('#4c4c4c')
  144. Row({space:30}){
  145. ForEach([0,10,20,30,40,50,60,70],(item:number,index:number)=>{
  146. Column(){
  147. }.width(10)
  148. .height(10)
  149. .borderRadius('50%')
  150. .onClick(()=>{
  151. if(index!=7){
  152. this.valueTime=item
  153. }else{
  154. this.currentIndex=3
  155. this.tabsController.changeIndex(this.currentIndex)
  156. }
  157. })
  158. .backgroundColor(Color.Yellow)
  159. // .backgroundColor(this.valueTime>=item?Color.Yellow:Color.White)
  160. })
  161. }.width('100%')
  162. }
  163. }
  164. Column() {
  165. Text('敲击间隔时长(1-10秒)')
  166. Row() {
  167. TextInput()
  168. .width(70)
  169. .height(40)
  170. .padding(0)
  171. .type(InputType.Number) // 设置输入类型为数字
  172. .textAlign(TextAlign.Center)
  173. .borderRadius(4)
  174. .backgroundColor(Color.Gray)
  175. Text('秒')
  176. }
  177. }
  178. }
  179. }.tabBar('倒计时')
  180. TabContent() {
  181. Column() {
  182. Text('自定义时间')
  183. Row() {
  184. TextInput()
  185. .width(70)
  186. .height(40)
  187. .padding(0)
  188. .type(InputType.Number) // 设置输入类型为数字
  189. .textAlign(TextAlign.Center)
  190. .borderRadius(4)
  191. .backgroundColor(Color.Gray)
  192. Text('秒')
  193. }
  194. }
  195. }.tabBar('自定义')
  196. }.width('100%').barHeight(0)
  197. Row(){
  198. Text('无限')
  199. .layoutWeight(1)
  200. .borderRadius(10)
  201. .height(30)
  202. .backgroundColor(this.currentIndex==0?Color.Green:Color.Transparent)
  203. .onClick(()=>{
  204. this.currentIndex=0
  205. this.tabsController.changeIndex(this.currentIndex)
  206. })
  207. Text('固定次数')
  208. .layoutWeight(1)
  209. .borderRadius(10)
  210. .height(30)
  211. .backgroundColor(this.currentIndex==1?Color.Green:Color.Transparent).onClick(()=>{
  212. this.currentIndex=1
  213. this.tabsController.changeIndex(this.currentIndex)
  214. })
  215. Text('倒计时')
  216. .layoutWeight(1)
  217. .borderRadius(10)
  218. .height(30)
  219. .backgroundColor((this.currentIndex==2||this.currentIndex==3)?Color.Green:Color.Transparent)
  220. .onClick(()=>{
  221. this.currentIndex=2
  222. this.tabsController.changeIndex(this.currentIndex)
  223. })
  224. }.width('100%')
  225. .borderRadius(10)
  226. .height(30)
  227. .backgroundColor(Color.Pink)
  228. }
  229. }.width('100%')
  230. .height('100%')
  231. .padding(20)
  232. .backgroundColor(Color.White)
  233. }
  234. // 初始化方法,在组件即将显示时被调用
  235. aboutToAppear(): void {
  236. for (let i = 0; i < this.count; i++) {
  237. this.list.push(new Cell()); // 初始化 Cell 数组
  238. }
  239. }
  240. build() {
  241. Column() {
  242. Stack({alignContent:Alignment.Bottom}) {
  243. Column() {
  244. if (this.isShowMessage) {
  245. Row() {
  246. Column({ space: 20 }) {
  247. //积功德+清零
  248. Row() {
  249. Text() {
  250. Span('积功德: ').fontColor(Color.White).fontSize(18)
  251. Span(`${this.currentMerit}`).fontSize(18).fontColor($r('[basic].color.login_main_yellow'))
  252. }.margin({ left: 50 })
  253. Row() {
  254. Text('清零')
  255. .borderRadius(20)
  256. .padding({
  257. left: 6,
  258. right: 6,
  259. top: 4,
  260. bottom: 4
  261. })
  262. .backgroundColor($r('[basic].color.login_main_yellow'))
  263. .fontColor(Color.Black)
  264. .onClick(() => {
  265. this.currentMerit = 0
  266. })
  267. }
  268. }.width('100%').justifyContent(FlexAlign.SpaceAround)
  269. //进度条
  270. Column() {
  271. Stack({ alignContent: Alignment.Center }) {
  272. Progress({ value: this.currentMerit, total: this.totalMerit, type: ProgressType.Ring })
  273. .width(80).color('#3dbbd1')
  274. .style({ strokeWidth: 6, shadow: true })
  275. .backgroundColor(Color.White)
  276. Text('集福').fontSize(20).fontColor(Color.White)
  277. }.margin({ left: 10 })
  278. Text() {
  279. Span(`${this.currentMerit}`).fontColor($r('[basic].color.login_main_yellow'))
  280. Span(`/${this.totalMerit}`)
  281. }.fontColor(Color.White).margin({ left: 10 }).width(80).textAlign(TextAlign.Center)
  282. }.width('100%').justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)
  283. }.layoutWeight(1)
  284. //右边的按钮
  285. Column({ space: 20 }) {
  286. Image($r('app.media.muyu')).width(30).onClick(() => {
  287. this.isShowSilder = !this.isShowSilder
  288. })
  289. if (this.isShowSilder) {
  290. //是否开启声音
  291. Image($r('app.media.muyu')).width(30).onClick(() => {
  292. this.isOpenMusic = !this.isOpenMusic
  293. })
  294. //是否开启震动
  295. Image($r('app.media.muyu')).width(30).onClick(() => {
  296. this.isOpenVibration = !this.isOpenVibration
  297. })
  298. Column() {
  299. Column() {
  300. Text(this.isAuto ? '自动' : '手动')
  301. .padding({
  302. left: 3,
  303. right: 3,
  304. top: 10,
  305. bottom: 10
  306. })
  307. .margin({ bottom: 10 })
  308. .backgroundColor('#252111')
  309. .fontColor(Color.White)
  310. .onClick(() => {
  311. this.isAuto = !this.isAuto
  312. //如果是本来自动,再点击就是手动,不需要设置任何东西
  313. // if (!this.isHand) {
  314. // this.isHand = true
  315. // } else {
  316. // //如果本来是手动,再点击就是自动,就需要设置东西
  317. // this.isHand = false
  318. // }
  319. })
  320. if (this.isAuto) {
  321. Column({ space: 10 }) {
  322. Text('结束')
  323. .padding({
  324. left: 3,
  325. right: 3,
  326. top: 10,
  327. bottom: 10
  328. })
  329. .fontColor(Color.White)
  330. .backgroundColor('#252111')
  331. .onClick(() => {
  332. this.isAuto = !this.isAuto
  333. })
  334. Text('设置')
  335. .padding({
  336. left: 3,
  337. right: 3,
  338. top: 10,
  339. bottom: 10
  340. })
  341. .fontColor(Color.White)
  342. .backgroundColor('#252111')
  343. .bindSheet($$this.isShowTimeManger, this.timeMangerBuilder(), {
  344. width: '100%',
  345. height: 400,
  346. showClose: false,
  347. })
  348. .onClick(() => {
  349. this.isShowTimeManger = true
  350. })
  351. Text('设置2')
  352. .padding({
  353. left: 3,
  354. right: 3,
  355. top: 10,
  356. bottom: 10
  357. })
  358. .fontColor(Color.White)
  359. .backgroundColor('#252111')
  360. .onClick(() => {
  361. //去往设置页面
  362. yTRouter.router2FishSettingPage()
  363. })
  364. }
  365. }
  366. }
  367. }
  368. }
  369. }.width(50)
  370. .justifyContent(FlexAlign.Center)
  371. .alignItems(HorizontalAlign.End)
  372. }.width('100%')
  373. .height(300)
  374. .alignItems(VerticalAlign.Top)
  375. }
  376. }
  377. .height('100%')
  378. .margin({ top: 20 })
  379. Column() {
  380. Stack() { // 创建一个堆栈布局容器
  381. ForEach(this.list, (item: Cell, _index: number) => { // 遍历 list 中的每一个 Cell
  382. Text(item.value)// 显示 Cell 中的文字
  383. .fontColor(Color.White)// 设置文字颜色为白色
  384. .fontSize('50lpx')// 设置文字大小
  385. .translate({ x: 0, y: `${item.y}lpx` })// 设置文字的垂直偏移量
  386. .opacity(item.opacity) // 设置文字的透明度
  387. })
  388. }
  389. .width(200) //
  390. .height(100)
  391. .align(Alignment.BottomEnd)
  392. Image(this.image)
  393. .width(200)
  394. .height(200)
  395. .objectFit(ImageFit.Contain)
  396. .clickEffect({
  397. // 点击效果配置
  398. scale: 0.5, // 缩放比例
  399. level: ClickEffectLevel.LIGHT // 效果级别
  400. })
  401. .onClick(() => { // 点击图片时触发的回调
  402. this.onclikMerit()
  403. })
  404. Row(){
  405. Image($r('app.media.muyu')).width(30).onClick(()=>{
  406. this.isShowMessage=!this.isShowMessage
  407. })
  408. }.width('100%')
  409. .margin({top:50})
  410. .justifyContent(FlexAlign.End)
  411. }
  412. .width('100%')
  413. .margin({bottom:20})
  414. }.height('100%')
  415. // Row(){
  416. // Button('改变文字').onClick(()=>{
  417. // this.list.forEach(item=>{item.value='吴亮+1'})
  418. // })
  419. // Button('敲击时长间隔1秒').onClick(()=>{
  420. // this.time=1000
  421. //
  422. // })
  423. // Button('固定10次').onClick(()=>{
  424. // //自动敲击
  425. // const a=setInterval(()=>{
  426. // this.onclikMerit()
  427. //
  428. // },this.time)
  429. // const b=setTimeout(()=>{
  430. // clearInterval(a)
  431. // clearTimeout(b)
  432. // },this.time*10)
  433. //
  434. //
  435. // })
  436. // Button('倒计时规定时间').onClick(()=>{
  437. // this.onclikMerit()
  438. // const a=setInterval(()=>{
  439. // this.onclikMerit()
  440. // },this.time)
  441. // const b=setTimeout(()=>{
  442. // clearInterval(a)
  443. // clearTimeout(b)
  444. // },10000)
  445. //
  446. // })
  447. // }
  448. //
  449. // Button('xxx').bindSheet($$this.isShowTimeManger,this.timeMangerBuilder(),{
  450. // width:'100%',
  451. // height:400,
  452. // showClose:false
  453. // }).onClick(()=>{
  454. // this.isShowTimeManger=true
  455. // })
  456. //
  457. // Button('震动').onClick(()=>{
  458. // Vibration.startVibration()
  459. // })
  460. // Stack() {
  461. // Progress({ value: this.valueTime, total: 70, type: ProgressType.Linear }).backgroundColor(Color.White)
  462. // Row({space:30}){
  463. // ForEach([0,10,20,30,40,50,60,70],(item:number)=>{
  464. // Column(){
  465. // }.width(10)
  466. // .height(10)
  467. // .borderRadius('50%')
  468. // .onClick(()=>{
  469. // this.valueTime=item
  470. // })
  471. // .backgroundColor(this.valueTime>=item?Color.Pink:Color.White)
  472. // })
  473. //
  474. //
  475. // }.width('100%')
  476. //
  477. // }
  478. }.width('100%')
  479. .height('100%')
  480. .padding({
  481. top:this.top,
  482. left:16,
  483. right:16
  484. })
  485. .backgroundColor(Color.Black)
  486. }
  487. }