index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {
  2. getreadInfo
  3. } from '~/api/video'
  4. let rowHeight = 0
  5. Page({
  6. data: {
  7. videoInfo: {},
  8. currentRow: null,
  9. state: false,
  10. countDown: {
  11. state: false,
  12. num: 3,
  13. },
  14. scrollTop: 0,
  15. article: [{
  16. id: 1,
  17. text: '传说在很久很久以前,',
  18. time: '0'
  19. }, {
  20. id: 2,
  21. text: '天和地还没有分开,',
  22. time: '4010'
  23. }, {
  24. id: 3,
  25. text: '整个宇宙混沌一团,',
  26. time: '7080'
  27. }, {
  28. id: 4,
  29. text: '像个大鸡蛋。',
  30. time: '10150'
  31. }, {
  32. id: 5,
  33. text: '有个叫盘古的大神,',
  34. time: '13150'
  35. }, {
  36. id: 6,
  37. text: '昏睡了一万八千年。',
  38. time: '16190'
  39. }, {
  40. id: 7,
  41. text: '一天,大神醒来,睁眼一看,',
  42. time: '20030'
  43. }, {
  44. id: 8,
  45. text: '周围黑乎乎一片,',
  46. time: '24210'
  47. }, {
  48. id: 9,
  49. text: '什么也看不见。',
  50. time: '27300'
  51. }, {
  52. id: 10,
  53. text: '他一使劲翻身坐了起来,',
  54. time: '29210'
  55. }, {
  56. id: 11,
  57. text: '只听“咔嚓”一声,',
  58. time: '32700'
  59. }, {
  60. id: 12,
  61. text: '“大鸡蛋”裂开了一条缝,',
  62. time: '35320'
  63. }, {
  64. id: 13,
  65. text: '一丝微光透了进来。',
  66. time: '38270'
  67. }, ]
  68. },
  69. onLoad(options) {
  70. let videoId = options.videoId
  71. this.getreadInfo(videoId)
  72. let data = this.data.article
  73. data = data.map((item, index) => {
  74. item.readTime = data[index + 1] ? data[index + 1].time - item.time : ''
  75. return item
  76. })
  77. this.setData({
  78. article: data
  79. })
  80. var query = wx.createSelectorQuery();
  81. query.select('.row').boundingClientRect((rect) => {
  82. this.rowHeight = rect.height
  83. console.log(rect);
  84. }).exec()
  85. },
  86. async getreadInfo(videoId) {
  87. let videoInfo = await getreadInfo(videoId)
  88. console.log(videoInfo);
  89. wx.setNavigationBarTitle({
  90. title: videoInfo.userRead.title
  91. })
  92. this.setData({
  93. videoInfo
  94. })
  95. },
  96. // 开始录制
  97. setCountDown() {
  98. // this.setData({
  99. // state: true,
  100. // 'countDown.state': true
  101. // })
  102. // let sto = setInterval(() => {
  103. // if (this.data.countDown.num == 0) {
  104. // clearInterval(sto)
  105. // this.setData({
  106. // countDown: {
  107. // state: false,
  108. // num: 3
  109. // }
  110. // })
  111. this.startRecording()
  112. // } else {
  113. // this.setData({
  114. // 'countDown.num': --this.data.countDown.num
  115. // })
  116. // }
  117. // }, 1000)
  118. },
  119. startRecording() {
  120. if (this.data.currentRow == null) {
  121. this.setData({
  122. currentRow: 0
  123. })
  124. }
  125. let row = this.data.article[this.data.currentRow]
  126. if (!row.readTime) {
  127. return
  128. }
  129. let setTimeoutObj = setTimeout(() => {
  130. this.setData({
  131. currentRow: ++this.data.currentRow
  132. })
  133. this.setData({
  134. scrollTop: this.rowHeight * this.data.currentRow
  135. })
  136. this.startRecording()
  137. },
  138. row.readTime);
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload() {
  144. },
  145. onShareAppMessage() {
  146. }
  147. })