qingrenjie2020.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // temp1/qingrenjie2020/qingrenjie2020.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: 'qingrenjie2020',
  16. examplePhotos: [
  17. 'ac_1025868734706.jpeg',
  18. 'ac_1025868889836.jpeg',
  19. 'ac_1025869003213.jpeg',
  20. 'ac_1025869293008.jpeg',
  21. 'ac_1025869619587.jpeg',
  22. 'ac_1025871041645.jpeg',
  23. 'ac_1025870641427.jpeg',
  24. 'ac_1025870863984.jpeg',
  25. 'ac_1025871122158.jpeg',
  26. 'ac_1025871242452.jpeg'
  27. ],
  28. imageWidths: [],
  29. imageHeights: [],
  30. imageStyles: [],
  31. page1BlockStyle: '',
  32. page1WordStyle: '',
  33. page1ImageStyle: ``,
  34. page2BlockStyle: '',
  35. page2WordStyle: '',
  36. page2ImageStyle: ``,
  37. page3BlockStyle: '',
  38. page3WordStyle: '',
  39. page3ImageStyle: ``,
  40. top_block: "",
  41. top1_block: "",
  42. top2_block: "",
  43. top3_block: "",
  44. top4_block: "",
  45. top5_block: "",
  46. bottom_block: "",
  47. bottom2_block: "",
  48. bottom3_block: "",
  49. bottom4_block: "",
  50. love1: "",
  51. love2: "",
  52. love3: "",
  53. love4: "",
  54. qiubite_block: "",
  55. arrow: "",
  56. qiubitexin: "",
  57. qbt_block: "",
  58. love_block: "",
  59. pagetitle: "",
  60. timeouts: []
  61. },
  62. /**
  63. * 生命周期函数--监听页面加载
  64. */
  65. onLoad(options) {
  66. this.initAnimation()
  67. },
  68. initAnimation() {
  69. const _this = this
  70. this.setData({
  71. photoIndex: 0
  72. })
  73. _this.setData({
  74. top_block: "animation: topmove 1s linear both",
  75. top1_block: "animation: topmove 1s linear both",
  76. top2_block: "animation: topmove 1s linear both",
  77. top3_block: "animation: topmove 1s linear both",
  78. top4_block: "animation: topmove 1s linear both",
  79. top5_block: "animation: topmove 1s linear both",
  80. bottom_block: "animation: bottomshow 1s linear both",
  81. bottom2_block: "animation: bottomshow 1s linear both",
  82. bottom3_block: "animation: bottomshow 1s linear both",
  83. bottom4_block: "animation: bottomshow 1s linear both",
  84. love1: "animation: lovemove 3s 1.8s linear both",
  85. love2: "animation: lovemove 3s 2.5s linear both",
  86. love3: "animation: lovemove 3s linear both",
  87. love4: "animation: lovemove 3s 1s linear both",
  88. qiubite_block: "animation: qiubite_blockshow 1s 3s linear both",
  89. arrow: "animation: arrowshow 0.9s 4.1s linear both",
  90. qiubitexin: "animation: qiubitexinshow 2s 3s linear both",
  91. qbt_block: "animation: qbt_blockshow 1.8s 5s linear both",
  92. love_block: "animation: love_blockmove 6.7s 1s linear both",
  93. pagetitle: "animation: pagetitleshow 1s 3s linear both"
  94. })
  95. _this.data.timeouts.push(setTimeout(function () {
  96. _this.showPage()
  97. }, 7000))
  98. },
  99. showPage() {
  100. const _this = this
  101. if (this.data.photoIndex === this.data.examplePhotos.length - 1) {
  102. // 图片轮询完重新开始
  103. this.setData({
  104. 'photoIndex': 0
  105. })
  106. }
  107. const pageIndex = this.data.photoIndex % 3 + 1
  108. const imageURL = `https://novel-video.hongdes.cn/kawaalbum/${this.data.templateName}/example/${this.data.examplePhotos[this.data.photoIndex]}`
  109. console.log(imageURL)
  110. wx.getImageInfo({
  111. src: imageURL,
  112. success(res) {
  113. const imageWidth = res.width
  114. const imageHeight = res.height
  115. let blockStyle = ''
  116. if (imageWidth > imageHeight) {
  117. // 横版图片
  118. blockStyle = 'top:30%;'
  119. } else {
  120. // 竖版图片
  121. blockStyle = 'top:10%;'
  122. }
  123. _this.setData({
  124. [`page${pageIndex}BlockStyle`]: `${blockStyle}animation: pageshow 7.5s linear both;`,
  125. [`page${pageIndex}WordStyle`]: `animation: wordshow 4.5s 1.5s linear both;`,
  126. [`page${pageIndex}ImageStyle`]: imageURL,
  127. })
  128. _this.data.timeouts.push(setTimeout(() => {
  129. _this.setData({
  130. [`page${pageIndex + 1}BlockStyle`]: ``,
  131. [`page${pageIndex + 1}WordStyle`]: ``,
  132. })
  133. }, 4800));
  134. _this.data.timeouts.push(setTimeout(() => {
  135. _this.setData({
  136. 'photoIndex': _this.data.photoIndex + 1
  137. })
  138. _this.showPage();
  139. }, 6000));
  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. })