view.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. //获取应用实例
  29. var app = getApp()
  30. Page({
  31. data: {
  32. "hash_key":"",
  33. "imageSrc":"",
  34. "text":""
  35. },
  36. onLoad: function (e) {
  37. console.log('onLoad');
  38. this.setData({
  39. hash_key:e.hash_key
  40. })
  41. },
  42. onShow: function () {
  43. console.log('onShow');
  44. var self=this
  45. qcloud.request({
  46. // 要请求的地址
  47. url: config.service.apiUrl+'messages/'+self.data.hash_key,
  48. success(result) {
  49. console.log(result);
  50. if(result.data.success==true){
  51. self.setData({
  52. text:result.data.message_data.text,
  53. imageSrc:result.data.message_data.image_url
  54. });
  55. }else{
  56. wx.redirectTo({
  57. url: '/pages/index/index'
  58. })
  59. }
  60. },
  61. fail(error) {
  62. console.log('request fail', error);
  63. },
  64. complete() {
  65. console.log('request complete');
  66. }
  67. });
  68. },
  69. edit:function(){
  70. wx.redirectTo({
  71. url: '/pages/add/add'
  72. })
  73. },
  74. send:function(){
  75. wx.redirectTo({
  76. url: '/pages/send/send'
  77. })
  78. },
  79. onShareAppMessage: function () {
  80. return {
  81. title: '密件',
  82. desc: '密件',
  83. path: 'pages/send/send?hash_key='+this.data.hash_key
  84. }
  85. }
  86. })