view.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. "imageSrc":"",
  55. "height":"",
  56. "share_txt":"",
  57. "share":false,
  58. "is_qun":false,
  59. "expire_time":"",
  60. "text":""
  61. },
  62. onLoad: function (e) {
  63. console.log('onLoad');
  64. app.getUserInfo(function(userInfo){
  65. console.log(userInfo);
  66. });
  67. this.setData({
  68. hash_key:e.hash_key
  69. })
  70. var self=this
  71. try {
  72. var res = wx.getSystemInfoSync();
  73. self.setData({
  74. height:(res.windowWidth)*0.8
  75. });
  76. } catch (e) {
  77. // Do something when catch error
  78. }
  79. qcloud.request({
  80. // 要请求的地址
  81. url: config.service.apiUrl+'messages/'+self.data.hash_key,
  82. success(result) {
  83. console.log(result);
  84. if(result.data.success==true){
  85. self.setData({
  86. text:result.data.message_data.text,
  87. imageSrc:result.data.message_data.image_url
  88. });
  89. if(result.data.message_data.is_qun==0){
  90. self.setData({
  91. is_qun:false,
  92. expire_time:"",
  93. share_txt:'密件已经准备好了,你可以将本页发给你的朋友了,对方观看一次后立即销毁',
  94. });
  95. }else{
  96. var expire=result.data.message_data.expire_time;
  97. var d=new Date(expire*1000);
  98. self.setData({
  99. is_qun:true,
  100. expire_time:formatDate(d),
  101. share_txt:'密件已经准备好了,你可以将本页发到群中了。6小时后本密件自动销毁',
  102. });
  103. }
  104. }else{
  105. wx.switchTab({
  106. url: '/pages/person/index/index'
  107. })
  108. }
  109. },
  110. fail(error) {
  111. console.log('request fail', error);
  112. },
  113. complete() {
  114. console.log('request complete');
  115. }
  116. });
  117. },
  118. onShow: function () {
  119. console.log('onShow');
  120. },
  121. edit:function(){
  122. wx.switchTab({
  123. url: '/pages/person/index/index'
  124. })
  125. },
  126. share:function(){
  127. this.setData({
  128. share:true
  129. })
  130. var self=this
  131. setTimeout(function(){
  132. self.setData({
  133. share:false
  134. })
  135. }, 500);
  136. },
  137. onShareAppMessage: function () {
  138. return {
  139. title: '密件-只有我们知道',
  140. path: 'pages/person/image/send/send?hash_key='+this.data.hash_key
  141. }
  142. }
  143. })