send.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. var showMsg = (title, content) => {
  29. wx.hideToast();
  30. wx.showModal({
  31. title,
  32. content: content,
  33. showCancel: false
  34. });
  35. };
  36. //获取应用实例
  37. var app = getApp()
  38. var busy=false;
  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. },
  51. Interval:function(){
  52. var self=this;
  53. this.data.intervarID= setInterval(function(){
  54. self.animation.scale(2, 2).step()
  55. self.animation.scale(1, 1).step()
  56. self.setData({
  57. animationData: self.animation.export()
  58. })
  59. self.setData({
  60. num:self.data.num-1,
  61. });
  62. if(self.data.num == 0){
  63. clearInterval(self.data.intervarID);
  64. setTimeout(function(){
  65. wx.switchTab({
  66. url: '/pages/person/index/index'
  67. })
  68. }, 1000);
  69. }
  70. },1000);
  71. },
  72. onLoad: function (e) {
  73. console.log('onLoad');
  74. if(busy){
  75. return;
  76. }
  77. this.setData({
  78. hash_key:e.hash_key,
  79. num:5
  80. })
  81. busy=true;
  82. var animation = wx.createAnimation({
  83. duration: 100,
  84. timingFunction: 'ease',
  85. })
  86. this.animation = animation
  87. var self=this;
  88. app.getUserInfo(function(userInfo){
  89. console.log(userInfo);
  90. qcloud.request({
  91. // 要请求的地址
  92. url: config.service.apiUrl+'messages/'+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.message_data.dead==0){
  98. if(result.data.is_mine==true){
  99. self.setData({
  100. is_mine:true
  101. });
  102. }else{
  103. self.setData({
  104. is_mine:false
  105. });
  106. }
  107. self.setData({
  108. start:true,
  109. text:result.data.message_data.text,
  110. imageSrc:result.data.message_data.image_url,
  111. nicker_name:result.data.message_data.user.nickname
  112. });
  113. if(result.data.message_data.type==2){
  114. self.setData({
  115. loading:true
  116. });
  117. }
  118. if(result.data.message_data.image_url==""&&result.data.is_mine==false){
  119. self.Interval();
  120. }
  121. }else{
  122. if(result.data.message_data.is_qun==1){
  123. wx.hideToast();
  124. wx.showModal({
  125. title:'提示信息',
  126. content: '你来晚了,本密件已经被销毁',
  127. showCancel: false,
  128. success: function(res) {
  129. if (res.confirm) {
  130. wx.switchTab({
  131. url: '/pages/person/index/index'
  132. })
  133. }
  134. }
  135. });
  136. }else{
  137. wx.switchTab({
  138. url: '/pages/person/index/index'
  139. })
  140. }
  141. }
  142. }else{
  143. wx.hideToast();
  144. wx.showModal({
  145. title:'提示信息',
  146. content: result.data.message,
  147. showCancel: false,
  148. success: function(res) {
  149. if (res.confirm) {
  150. wx.switchTab({
  151. url: '/pages/person/index/index'
  152. })
  153. }
  154. }
  155. });
  156. }
  157. }else{
  158. wx.switchTab({
  159. url: '/pages/person/index/index'
  160. })
  161. }
  162. },
  163. fail(error) {
  164. console.log('request fail', error);
  165. },
  166. complete() {
  167. busy=false;
  168. console.log('request complete');
  169. }
  170. });
  171. });
  172. },
  173. onShow: function () {
  174. console.log('onShow');
  175. },
  176. imageLoad: function(e){
  177. console.log(e);
  178. var self=this;
  179. self.setData({
  180. loading:false
  181. });
  182. if(self.data.is_mine==false){
  183. self.Interval();
  184. }
  185. }
  186. })