view.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // 引入 QCloud 小程序增强 SDK
  2. var qcloud = require('../../../../vendor/qcloud-weapp-client-sdk/index');
  3. // 引入配置
  4. var config = require('../../../../config');
  5. // 显示繁忙提示
  6. var showBusy = text => wx.showToast({
  7. title: text,
  8. icon: 'loading',
  9. duration: 10000
  10. });
  11. // 显示成功提示
  12. var showSuccess = text => {
  13. wx.hideToast();
  14. wx.showToast({
  15. title: text,
  16. icon: 'success'
  17. });
  18. };
  19. // 显示失败提示
  20. var showModel = (title, content) => {
  21. wx.hideToast();
  22. wx.showModal({
  23. title,
  24. content: JSON.stringify(content),
  25. showCancel: false
  26. });
  27. };
  28. function formatDate(now) {
  29. var year=now.getFullYear();
  30. var month=now.getMonth()+1;
  31. if(month<10){
  32. month='0'+month.toString();
  33. }
  34. var date=now.getDate();
  35. if(date<10){
  36. date='0'+date.toString();
  37. }
  38. var hour=now.getHours();
  39. if(hour<10){
  40. hour='0'+hour.toString();
  41. }
  42. var minute=now.getMinutes();
  43. if(minute<10){
  44. minute='0'+minute.toString();
  45. }
  46. var second=now.getSeconds();
  47. return month+"-"+date+" "+hour+":"+minute;
  48. }
  49. //获取应用实例
  50. var app = getApp()
  51. Page({
  52. data: {
  53. "hash_key":"",
  54. "videoSrc":"",
  55. "height":"",
  56. "is_qun":false,
  57. "share":false,
  58. "video_hidden":true,
  59. "share_txt":"",
  60. "expire_time":"",
  61. "text":""
  62. },
  63. onLoad: function (e) {
  64. console.log('onLoad');
  65. app.getUserInfo(function(userInfo){
  66. console.log(userInfo);
  67. });
  68. this.setData({
  69. hash_key:e.hash_key
  70. })
  71. var self=this
  72. try {
  73. var res = wx.getSystemInfoSync();
  74. self.setData({
  75. height:(res.windowWidth)*0.8
  76. });
  77. } catch (e) {
  78. // Do something when catch error
  79. }
  80. qcloud.request({
  81. // 要请求的地址
  82. url: config.service.apiUrl+'messages/'+self.data.hash_key,
  83. success(result) {
  84. console.log(result);
  85. if(result.data.success==true){
  86. if(result.data.message_data.type!==3){
  87. wx.switchTab({
  88. url: '/pages/perosn/image/view/view?hash_key='+self.data.hash_key
  89. })
  90. }
  91. self.setData({
  92. videoSrc:result.data.message_data.image_url
  93. });
  94. if(result.data.message_data.is_qun==0){
  95. self.setData({
  96. is_qun:false,
  97. expire_time:"",
  98. share_txt:'密件已经准备好了,你可以将本页发给你的朋友了,对方观看一次后立即销毁',
  99. });
  100. }else{
  101. var expire=result.data.message_data.expire_time;
  102. var d=new Date(expire*1000);
  103. self.setData({
  104. is_qun:true,
  105. expire_time:formatDate(d),
  106. share_txt:'密件已经准备好了,你可以将本页发到群中了。6小时后本密件自动销毁',
  107. });
  108. }
  109. }else{
  110. wx.switchTab({
  111. url: '/pages/person/index/index'
  112. })
  113. }
  114. },
  115. fail(error) {
  116. console.log('request fail', error);
  117. },
  118. complete() {
  119. console.log('request complete');
  120. }
  121. });
  122. },
  123. onShow: function () {
  124. console.log('onShow');
  125. },
  126. edit:function(){
  127. wx.switchTab({
  128. url: '/pages/person/index/index'
  129. })
  130. },
  131. share:function(){
  132. this.setData({
  133. share:true
  134. })
  135. var self=this
  136. setTimeout(function(){
  137. self.setData({
  138. share:false
  139. })
  140. }, 500);
  141. },
  142. play:function(){
  143. this.setData({
  144. video_hidden:false
  145. });
  146. this.videoContext = wx.createVideoContext('myVideo');
  147. var self=this;
  148. setTimeout(function(){
  149. self.videoContext.play();
  150. }, 500);
  151. },
  152. ended:function(e){
  153. this.setData({
  154. video_hidden:true
  155. });
  156. },
  157. onShareAppMessage: function () {
  158. return {
  159. title: '密件-只有我们知道',
  160. path: 'pages/person/video/send/send?hash_key='+this.data.hash_key
  161. }
  162. }
  163. })