FragranceView.ets 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. import { AppStorageKeyFishCollect, YTHeader, yTRouter, YTUserRequest } from 'basic';
  2. import { promptAction } from '@kit.ArkUI';
  3. @Component
  4. export struct FragranceView{
  5. // @StorageProp(AppStorageKeyFishCollect.TEXTARR)
  6. // @State
  7. // textArr:string[]=['xxxx','xxxx','xxxx','xxx','xxxx','xxxx']
  8. private averageAngle: number = 0
  9. private radius1: number = 50
  10. private radius2: number =1
  11. private img: number = 90
  12. private isRotate:boolean = true;//按下暂停转动
  13. @State widAr:Array<number> = [this.radius1,this.radius1,this.radius1,this.radius1,this.radius1]
  14. @State heiAr:Array<number> = [this.radius2,this.radius2,this.radius2,this.radius2,this.radius2]
  15. @State rotateAngle: number = 0
  16. private intervalID = setInterval(()=> {//每0.1秒执行5°的转动,动画更平滑
  17. for (let index = 0; index < 6; index++) {
  18. let doubleAngle = (this.averageAngle -60 * index + 0) * Math.PI / 180
  19. let sin = Math.sin(doubleAngle);
  20. let cos = Math.cos(doubleAngle);
  21. this.widAr[index] =this.radius1+this.radius1*cos
  22. this.heiAr[index] =this.radius2+this.radius2*sin * Math.cos(Math.PI * 5 / 18)
  23. }
  24. if (this.isRotate) {
  25. if (this.averageAngle<360) {//0~360°循环
  26. this.averageAngle+=1
  27. }else {
  28. this.averageAngle = 0;
  29. }
  30. this.rotateAngle = 360
  31. }
  32. }, 100)
  33. imagesThree: ImageFrameInfo[] =Array.from<string>({length:20}).map<ImageFrameInfo>((v:string,index:number)=>{
  34. return {
  35. src: $r(`app.media.three_Fra_${index+1}`),
  36. }
  37. })
  38. imagesOne: ImageFrameInfo[] =Array.from<string>({length:20}).map<ImageFrameInfo>((v:string,index:number)=>{
  39. return {
  40. src: $r(`app.media.one_Fra_${index+1}`),
  41. }
  42. })
  43. images2: ImageFrameInfo[] =Array.from<string>({length:5}).map<ImageFrameInfo>((v:string,index:number)=>{
  44. return {
  45. src: $r(`app.media.huo${index+1}`),
  46. }
  47. })
  48. image3: ImageFrameInfo[] =Array.from<string>({length:25}).map<ImageFrameInfo>((v:string,index:number)=>{
  49. return {
  50. src: $r(`app.media.fragrance${index+1}`),
  51. }
  52. })
  53. @State state:AnimationStatus = AnimationStatus.Initial
  54. @State moveY:number=0
  55. //燃烧时间
  56. @State time:number=-1
  57. //烧香数量
  58. @State num:number=1
  59. @State interId:number=0
  60. @State isShow:boolean=false
  61. //获取香烟数量和燃烧时间
  62. updateNumAndTime(){
  63. YTUserRequest.getFishFra((res)=>{
  64. const time=res.incenseTime as number
  65. if(time==10){
  66. this.time=10
  67. }else if(time==30){
  68. this.time=30
  69. }else {
  70. this.time=-1
  71. }
  72. const num=res.incenseNum as number
  73. if(num==1){
  74. this.num=1
  75. }else{
  76. this.num=3
  77. }
  78. //测试时间
  79. this.time=1
  80. })
  81. }
  82. //计算香烟位置,启动动画
  83. caluePosition(){
  84. clearInterval(this.interId)
  85. this.moveY=0
  86. this.state=AnimationStatus.Stopped
  87. //显示烟
  88. this.isShow=true
  89. //香缩减动画开始
  90. this.state=AnimationStatus.Running
  91. //位移计算
  92. this.moveY=0
  93. if(this.time!=-1) {
  94. this.interId = setInterval(() => {
  95. this.moveY = this.moveY + 8
  96. }, this.time * 60000 / 20)
  97. }
  98. }
  99. aboutToAppear(): void {
  100. this.updateNumAndTime()
  101. this.caluePosition()
  102. // if(this.textArr.length==0){
  103. // this.textArr.push('诸事顺遂')
  104. // }
  105. //
  106. // this.widAr=[]
  107. // this.heiAr=[]
  108. // this.textArr.forEach((item)=>{
  109. // this.widAr.push(this.radius1)
  110. // this.heiAr.push(this.radius2)
  111. // })
  112. }
  113. aboutToDisappear() {
  114. clearInterval(this.intervalID);
  115. }
  116. build() {
  117. Column(){
  118. //文字环绕
  119. Stack() {
  120. Image($r('[basic].media.dengguang')).width('100%').height('100%')
  121. Image($r('[basic].media.dizuo')).width(256).height(60).margin({top:450})
  122. Stack({alignContent:Alignment.Top}) {
  123. RelativeContainer() {
  124. // ForEach(this.textArr,(item:string,index:number)=>{
  125. // Column() {
  126. // Text(item)
  127. // .width(this.img)
  128. // .height(this.img)
  129. // .fontColor(Color.White)
  130. // }.position({ x: this.widAr[index], y: this.heiAr[index] })
  131. // })
  132. Column() {
  133. Text('天天吃饭')
  134. .fontSize(20)
  135. .width(this.img)
  136. .height(this.img)
  137. .fontColor(Color.White)
  138. }.position({ x: this.widAr[0], y: this.heiAr[0] })
  139. Column() {
  140. Text('天天向上')
  141. .fontSize(20)
  142. .width(this.img)
  143. .height(this.img)
  144. .fontColor(Color.White)
  145. }.position({ x: this.widAr[1], y: this.heiAr[1] })
  146. Column() {
  147. Text('清纯男大')
  148. .fontSize(20)
  149. .width(this.img)
  150. .height(this.img)
  151. .fontColor(Color.White)
  152. }.position({ x: this.widAr[2], y: this.heiAr[2] })
  153. Column() {
  154. Text('官人梧州')
  155. .fontSize(20)
  156. .width(this.img)
  157. .height(this.img)
  158. .fontColor(Color.White)
  159. }.position({ x: this.widAr[3], y: this.heiAr[3] })
  160. Column() {
  161. Text('年年岁岁')
  162. .fontSize(20)
  163. .width(this.img)
  164. .height(this.img)
  165. .fontColor(Color.White)
  166. }.position({ x: this.widAr[4], y: this.heiAr[4] })
  167. Column() {
  168. Text('平平安安')
  169. .fontSize(20)
  170. .width(this.img)
  171. .height(this.img)
  172. .fontColor(Color.White)
  173. }.position({ x: this.widAr[5], y: this.heiAr[5] })
  174. }.width(300)
  175. .height(350)
  176. .margin({top:44,left:20})
  177. .onAreaChange((oldValue: Area, newValue: Area) => {
  178. this.radius1 = new Number(newValue.width).valueOf() / 3
  179. this.radius2 = new Number(newValue.height).valueOf() / 4
  180. })
  181. }.width('100%')
  182. .height('100%')
  183. Stack(){
  184. //一根香烟
  185. if(this.num==1){
  186. ImageAnimator()
  187. .width('100%')
  188. .height('100%')
  189. // .animatorFancy()// 抽取公共属性
  190. .images(this.imagesOne)// 动画数组 十秒
  191. .duration(this.time==-1?9999999:this.time*60000)
  192. // .duration(this.imagesOne.length * 500*this.time)// 持续
  193. .state(this.state)// 动画状态
  194. .iterations(-1) // 播放次数
  195. //三更香烟
  196. }else {
  197. ImageAnimator()
  198. .width('100%')
  199. .height('100%')
  200. // .animatorFancy()// 抽取公共属性
  201. .images(this.imagesThree)// 动画数组 //十秒
  202. .duration(this.time==-1?9999999:this.time*60000)
  203. // .duration(this.imagesThree.length * 500*this.time)// 持续
  204. .state(this.state)// 动画状态
  205. .iterations(-1) // 播放次数
  206. }
  207. //火
  208. ImageAnimator()
  209. .width('100%')
  210. .height('100%')
  211. // .animatorFancy()// 抽取公共属性
  212. .images(this.images2)// 动画数组
  213. .duration(this.images2.length * 100)// 持续
  214. .state(AnimationStatus.Running)// 动画状态
  215. .iterations(-1) // 播放次数
  216. //烟显示
  217. if(this.isShow) {
  218. if(this.num==1) {
  219. Stack() {
  220. ImageAnimator()
  221. .width('100%')
  222. .height('100%')
  223. .images(this.image3)// 动画数组
  224. .duration(this.image3.length * 100)// 持续
  225. .state(AnimationStatus.Running)// 动画状态
  226. .iterations(-1) // 播放次数
  227. // ImageAnimator()
  228. // .width('100%')
  229. // .height('100%')
  230. // // .animatorFancy()// 抽取公共属性
  231. // .images(this.images2)// 动画数组
  232. // .duration(this.images2.length * 100)// 持续
  233. // .state(AnimationStatus.Running)// 动画状态
  234. // .iterations(-1) // 播放次数
  235. }.width('100%')
  236. .height('100%')
  237. .translate({
  238. y: this.moveY
  239. })
  240. }else {
  241. Stack() {
  242. ImageAnimator()
  243. .width('100%')
  244. .height('100%')
  245. .images(this.image3)// 动画数组
  246. .duration(this.image3.length * 100)// 持续
  247. .state(AnimationStatus.Running)// 动画状态
  248. .iterations(-1) // 播放次数
  249. ImageAnimator()
  250. .width('100%')
  251. .height('100%')
  252. .margin({ right: 35 })
  253. .images(this.image3)// 动画数组
  254. .duration(this.image3.length * 100)// 持续
  255. .state(AnimationStatus.Running)// 动画状态
  256. .iterations(-1) // 播放次数
  257. ImageAnimator()
  258. .width('100%')
  259. .height('100%')
  260. .margin({ left: 35 })
  261. .images(this.image3)// 动画数组
  262. .duration(this.image3.length * 100)// 持续
  263. .state(AnimationStatus.Running)// 动画状态
  264. .iterations(-1) // 播放次数
  265. // ImageAnimator()
  266. // .width('100%')
  267. // .height('100%')
  268. // // .animatorFancy()// 抽取公共属性
  269. // .images(this.images2)// 动画数组
  270. // .duration(this.images2.length * 100)// 持续
  271. // .state(AnimationStatus.Running)// 动画状态
  272. // .iterations(-1) // 播放次数
  273. }.width('100%')
  274. .height('100%')
  275. .translate({
  276. y: this.moveY
  277. })
  278. }
  279. }
  280. // 按钮控制区域
  281. Row(){
  282. Button('xxx').onClick(()=>{
  283. this.time=1
  284. this.caluePosition()
  285. })
  286. }
  287. // Row({space:20}){
  288. // Button('启动').onClick(()=>{
  289. // this.isShow=true
  290. // this.state=AnimationStatus.Running
  291. // this.interId=setInterval(()=>{
  292. // //2秒,20张,170 0.1秒一----10
  293. // //20秒 20张 170 1秒一张 0.9
  294. // //60秒 20张 170 3秒一张 170
  295. // //另外一种解决办法,根据照片的分布来设置位置position
  296. // //170 20张 第一张170 第二张160,10分钟,每半分钟一个状态移动位置
  297. // this.time=this.time+1
  298. // this.moveY=this.moveY+this.time*1
  299. // },1000)
  300. // setTimeout(()=>{
  301. // clearInterval(this.interId)
  302. // this.isShow=false
  303. // },20000)
  304. //
  305. // })
  306. // Button('暂停').onClick(()=>{
  307. // this.state=AnimationStatus.Paused
  308. // })
  309. // Button('停止').onClick(()=>{
  310. // this.state=AnimationStatus.Stopped
  311. // this.moveY=0
  312. // this.time=0
  313. // this.isShow=false
  314. // clearTimeout(this.interId)
  315. // })
  316. // Button('XX').onClick(()=>{
  317. // promptAction.showToast({
  318. // message:this.moveY.toString()
  319. // })
  320. // })
  321. // // Button('xxxxx').onClick(()=>{
  322. // //
  323. // // })
  324. // }
  325. }
  326. Row(){
  327. Column(){
  328. }.width(24).height(24)
  329. Row({space:32}){
  330. Text(`30:00`).fontColor($r('[basic].color.login_main_yellow'))
  331. Text('重置')
  332. .borderRadius(20)
  333. .padding({
  334. left: 6,
  335. right: 6,
  336. top: 4,
  337. bottom: 4
  338. })
  339. .backgroundColor($r('[basic].color.login_main_yellow'))
  340. .fontColor(Color.Black)
  341. .onClick(() => {
  342. })
  343. }
  344. Image($r('[basic].media.shezhix')).width(24).onClick(()=>{
  345. yTRouter.router2FragranceSettingPage()
  346. })
  347. }.width('100%')
  348. .margin({bottom:640})
  349. .padding({left:16,right:16})
  350. .justifyContent(FlexAlign.SpaceBetween)
  351. }.width('100%')
  352. .height('100%')
  353. }.width('100%')
  354. .height('100%')
  355. .backgroundColor(Color.Black)
  356. .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => {
  357. console.info('IsaKit Test Text isVisible: ' + isVisible + ', currentRatio:' + currentRatio)
  358. if (isVisible) {
  359. this.updateNumAndTime()
  360. this.caluePosition()
  361. }
  362. })
  363. }
  364. }