yujiandongtian2022.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // temp1/yujiandongtian2022/yujiandongtian2022.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. // 背景音乐
  8. bgmusic: {
  9. music: null,
  10. playing: false
  11. },
  12. ads: null,
  13. hasLoadAdConfig: false,
  14. photoIndex: 0,
  15. templateName: 'yujiandongtian2022',
  16. imageURLList: [],
  17. examplePhotos: [
  18. 'ac_317918916r8020.jpeg',
  19. 'ac_318236669r1319.jpeg',
  20. 'ac_317922035r8317.jpeg',
  21. 'ac_317922036r7219.jpeg',
  22. 'ac_317925006r4661.jpeg',
  23. 'ac_317924076r7251.jpeg',
  24. 'ac_317924074r7850.jpeg',
  25. 'ac_317924908r5638.jpeg',
  26. 'ac_317920724r9814.jpeg',
  27. 'ac_317919339r2625.jpeg',
  28. ],
  29. imageWidths: [],
  30. imageHeights: [],
  31. imageStyles: [],
  32. page1BlockStyle: '',
  33. page1Image: ``,
  34. page2BlockStyle: '',
  35. page2Image: ``,
  36. page3BlockStyle: '',
  37. page3Image: ``,
  38. photo_load: "",
  39. biaotiimg: "",
  40. pagetitle: "",
  41. bg1imgBox: "",
  42. bg1img: "",
  43. snowBox: "",
  44. snow: "",
  45. tabimgBox: "",
  46. tabimg: "",
  47. bg2imgBox: "",
  48. bg2img: "",
  49. kuangtopBox: "",
  50. kuangbotBox: "",
  51. snowhua: "",
  52. timeouts: []
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad(options) {
  58. this.setData({
  59. imageURLList: this.data.examplePhotos.map(item => {
  60. return `https://novel-video.hongdes.cn/kawaalbum/${this.data.templateName}/example/${item}`
  61. })
  62. })
  63. this.initAnimation()
  64. },
  65. initAnimation() {
  66. const _this = this
  67. this.setData({
  68. photoIndex: 0
  69. })
  70. _this.setData({
  71. photo_load: "animation: fadeOut 0.5s linear both",
  72. biaotiimg: "animation: biaotiimg_an 4.3s linear both",
  73. pagetitle: "animation: pagetitle_an 5.4s 3.2s linear both",
  74. bg1imgBox: "animation: bg1imgBox_an 8.8s linear both",
  75. bg1img: "animation: bg1img_an 6.7s steps(1) both",
  76. snowBox: "animation: fadeIn 0.9s linear both",
  77. snow: "animation: snow_an 3.1s steps(1) infinite",
  78. })
  79. _this.data.timeouts.push(setTimeout(function () {
  80. _this.setData({
  81. tabimgBox: "animation: fadeIn 0.3s linear both",
  82. tabimg: "animation: tabimg_an 1.2s steps(1) both"
  83. })
  84. }, 7700))
  85. _this.data.timeouts.push(setTimeout(function () {
  86. _this.setData({
  87. bg2imgBox: "animation: fadeIn 0.9s linear both",
  88. bg2img: "animation: bg2img_an 3.4s steps(1) infinite",
  89. kuangtopBox: "animation: kuangtopBox_an 1.2s linear both",
  90. kuangbotBox: "animation: kuangbotBox_an 1.2s linear both",
  91. })
  92. _this.showPage()
  93. }, 8600))
  94. },
  95. showPage() {
  96. const _this = this
  97. if (this.data.photoIndex === this.data.examplePhotos.length - 1) {
  98. // 图片轮询完重新开始
  99. this.setData({
  100. 'photoIndex': 0
  101. })
  102. }
  103. const pageIndex = this.data.photoIndex % 3 + 1
  104. const imageURL = `https://novel-video.hongdes.cn/kawaalbum/${this.data.templateName}/example/${this.data.examplePhotos[this.data.photoIndex]}`
  105. wx.getImageInfo({
  106. src: imageURL,
  107. success(res) {
  108. const imageWidth = res.width
  109. const imageHeight = res.height
  110. let blockStyle = ''
  111. if (imageWidth > imageHeight) {
  112. // 横版图片
  113. blockStyle = 'top:30%;'
  114. } else {
  115. // 竖版图片
  116. blockStyle = 'top:10%;'
  117. }
  118. _this.setData({
  119. snowhua: 'animation: snowhua_an 1.4s steps(1) both;',
  120. [`page${pageIndex}BlockStyle`]: `${blockStyle}animation: showimg 7.9s linear both;`,
  121. [`page${pageIndex}Image`]: imageURL,
  122. [`page${pageIndex === 1 ? 2 : 1}BlockStyle`]: '',
  123. })
  124. _this.data.timeouts.push(setTimeout(function () {
  125. _this.setData({
  126. snowhua: '',
  127. })
  128. }, 3000))
  129. _this.data.timeouts.push(setTimeout(() => {
  130. _this.setData({
  131. 'photoIndex': _this.data.photoIndex + 1
  132. })
  133. _this.showPage()
  134. }, 6800));
  135. _this.data.timeouts.push(setTimeout(function () {
  136. _this.setData({
  137. [`page${pageIndex}BlockStyle`]: ``,
  138. })
  139. }, 8000))
  140. },
  141. fail(err) {
  142. console.error(err);
  143. }
  144. })
  145. },
  146. /**
  147. * 播放音乐
  148. */
  149. initBgMusic() {
  150. let _this = this
  151. if (!app.globalData.audioContext) {
  152. app.globalData.audioContext = wx.createInnerAudioContext()
  153. }
  154. // obeyMuteSwitch(仅在 iOS 生效)是否遵循静音开关,设置为 false 之后,即使是在静音模式下,也能播放声音
  155. wx.setInnerAudioOption({
  156. obeyMuteSwitch: false
  157. })
  158. // 设置音乐循环
  159. app.globalData.audioContext.loop = true
  160. // 监听音乐播放
  161. app.globalData.audioContext.onPlay(() => {
  162. _this.setData({
  163. 'bgmusic.playing': true
  164. })
  165. console.log('music play', _this.data.bgmusic.playing)
  166. })
  167. // 监听音乐暂停
  168. app.globalData.audioContext.onPause(() => {
  169. console.log('music pause')
  170. _this.setData({
  171. 'bgmusic.playing': false
  172. })
  173. })
  174. app.globalData.audioContext.src = this.data.bgmusic.music.url
  175. app.globalData.audioContext.play()
  176. },
  177. /**
  178. * 音乐播放按钮
  179. */
  180. musicPlayTap() {
  181. app.globalData.audioContext.paused ? app.globalData.audioContext.play() : app.globalData.audioContext.pause()
  182. },
  183. /**
  184. * 生命周期函数--监听页面显示
  185. */
  186. onShow() {
  187. },
  188. /**
  189. * 生命周期函数--监听页面隐藏
  190. */
  191. onHide() {
  192. },
  193. /**
  194. * 生命周期函数--监听页面卸载
  195. */
  196. onUnload() {
  197. this.clearTimeoutTask()
  198. },
  199. // 清除定时任务
  200. clearTimeoutTask() {
  201. this.data.timeouts.forEach(timeout => clearTimeout(timeout));
  202. },
  203. /**
  204. * 用户点击右上角分享
  205. */
  206. onShareAppMessage() {
  207. }
  208. })