view.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // pages/channel/view/view.js
  2. // 引入 QCloud 小程序增强 SDK
  3. var qcloud = require('../../../vendor/qcloud-weapp-client-sdk/index');
  4. // 引入配置
  5. var config = require('../../../config');
  6. // 显示繁忙提示
  7. var showBusy = text => wx.showToast({
  8. title: text,
  9. icon: 'loading',
  10. duration: 10000
  11. });
  12. // 显示成功提示
  13. var showSuccess = text => {
  14. wx.hideToast();
  15. wx.showToast({
  16. title: text,
  17. icon: 'success'
  18. });
  19. };
  20. // 显示失败提示
  21. var showModel = (title, content) => {
  22. wx.hideToast();
  23. wx.showModal({
  24. title,
  25. content: JSON.stringify(content),
  26. showCancel: false
  27. });
  28. };
  29. var showMsg = (title, content) => {
  30. wx.hideToast();
  31. wx.showModal({
  32. title,
  33. content: content,
  34. showCancel: false
  35. });
  36. };
  37. //获取应用实例
  38. var app = getApp()
  39. Page({
  40. data: {
  41. hash_key:"",
  42. loading:false,
  43. start:false,
  44. text:"",
  45. is_mine:false,
  46. imageSrc:"",
  47. nicker_name:"",
  48. animationData: {},
  49. num:5,
  50. video_hidden:true,
  51. },
  52. Interval:function(){
  53. var self=this;
  54. this.data.intervarID= setInterval(function(){
  55. self.animation.scale(2, 2).step()
  56. self.animation.scale(1, 1).step()
  57. self.setData({
  58. animationData: self.animation.export()
  59. })
  60. self.setData({
  61. num:self.data.num-1,
  62. });
  63. if(self.data.num == 0){
  64. clearInterval(self.data.intervarID);
  65. setTimeout(function(){
  66. wx.switchTab({
  67. url: '/pages/channel/index/index'
  68. })
  69. }, 1000);
  70. }
  71. },1000);
  72. },
  73. onLoad: function (e) {
  74. console.log('onLoad');
  75. app.getUserInfo(function(userInfo){
  76. console.log(userInfo);
  77. });
  78. this.setData({
  79. hash_key:e.hash_key
  80. })
  81. this.setData({
  82. num:5,
  83. });
  84. var animation = wx.createAnimation({
  85. duration: 100,
  86. timingFunction: 'ease',
  87. })
  88. this.animation = animation
  89. var self=this
  90. qcloud.request({
  91. // 要请求的地址
  92. url: config.service.apiUrl+'posts/'+self.data.hash_key,
  93. success(result) {
  94. console.log(result);
  95. if(result.statusCode==200){
  96. if(result.data.success==true){
  97. if(result.data.is_mine==true){
  98. self.setData({
  99. is_mine:true
  100. });
  101. }else{
  102. self.setData({
  103. is_mine:false
  104. });
  105. }
  106. self.setData({
  107. start:true,
  108. type:result.data.post.type,
  109. text:result.data.post.text,
  110. imageSrc:result.data.post.image_url,
  111. nicker_name:result.data.post.user.nickname
  112. });
  113. if(result.data.post.type==1&&result.data.is_mine==false){
  114. self.Interval();
  115. }else if(result.data.post.type==2){
  116. self.setData({
  117. loading:true
  118. });
  119. }
  120. }else{
  121. wx.hideToast();
  122. wx.showModal({
  123. title:'提示信息',
  124. content: result.data.message,
  125. showCancel: false,
  126. success: function(res) {
  127. if (res.confirm) {
  128. wx.switchTab({
  129. url: '/pages/channel/index/index'
  130. })
  131. }
  132. }
  133. });
  134. }
  135. }else{
  136. wx.switchTab({
  137. url: '/pages/channel/index/index'
  138. })
  139. }
  140. },
  141. fail(error) {
  142. console.log('request fail', error);
  143. },
  144. complete() {
  145. console.log('request complete');
  146. }
  147. });
  148. },
  149. onShow: function () {
  150. console.log('onShow');
  151. },
  152. imageLoad: function(e){
  153. console.log(e);
  154. var self=this;
  155. self.setData({
  156. loading:false
  157. });
  158. if(self.data.is_mine==false){
  159. self.Interval();
  160. }
  161. },
  162. play:function(e){
  163. console.log(e);
  164. },
  165. videoPlay:function(){
  166. this.setData({
  167. video_hidden:false
  168. });
  169. this.videoContext = wx.createVideoContext('myVideo');
  170. var self=this;
  171. setTimeout(function(){
  172. self.videoContext.play();
  173. }, 500);
  174. },
  175. timeUpdate: function(e){
  176. console.log(e);
  177. var self=this;
  178. var num=Math.floor(e.detail.duration)-Math.floor(e.detail.currentTime);
  179. if(num!==self.data.num){
  180. self.animation.scale(2, 2).step()
  181. self.animation.scale(1, 1).step()
  182. self.setData({
  183. animationData: self.animation.export()
  184. })
  185. self.setData({
  186. num:num,
  187. });
  188. }
  189. },
  190. ended:function(e){
  191. var self=this;
  192. if(self.data.is_mine==false){
  193. setTimeout(function(){
  194. wx.switchTab({
  195. url: '/pages/channel/index/index'
  196. })
  197. }, 1000);
  198. }
  199. }
  200. })