poster.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. var app = getApp()
  2. Page({
  3. data: {
  4. erweima:'',
  5. poster:"",
  6. img:app.globalData.imgUrl
  7. },
  8. onLoad: function (options) {
  9. var that = this;
  10. wx.showLoading({
  11. title: '加载中...',
  12. mask:true
  13. })
  14. app.request('/user/getInviteWechatQrcode', '', 'GET').then(res => {
  15. console.log(res)
  16. if (res.statusCode == 200) {
  17. that.setData({erweima:res.data.path})
  18. }
  19. })
  20. app.request('/user/getInvitePoster', '', 'GET').then(res => {
  21. console.log(res)
  22. if (res.statusCode == 200) {
  23. that.setData({poster:res.data.path})
  24. }
  25. wx.hideLoading()
  26. })
  27. },
  28. // previewImage:function(e){
  29. // var that = this;
  30. // var arr = []
  31. // arr = arr.concat(that.data.poster)
  32. // console.log(arr)
  33. // wx.previewImage({
  34. // current: that.data.poster,//当前显示图片的http链接
  35. // urls: arr, //要预览的图片
  36. // })
  37. // wx.getImageInfo({
  38. // src: that.data.poster[0],
  39. // success(res){
  40. // console.log(res)
  41. // }
  42. // })
  43. // },
  44. saveImg(e){
  45. // let url = e.currentTarget.dataset.url;
  46. //用户需要授权
  47. var that = this;
  48. wx.getSetting({
  49. success: (res) => {
  50. if (!res.authSetting['scope.writePhotosAlbum']) {
  51. wx.authorize({
  52. scope: 'scope.writePhotosAlbum',
  53. success:()=> {
  54. // 同意授权
  55. this.saveImg1(that.data.poster);
  56. },
  57. fail: (res) =>{
  58. wx.showModal({
  59. title: '保存失败',
  60. content: '请开启访问手机相册权限',
  61. success(res) {
  62. wx.openSetting()
  63. }
  64. })
  65. }
  66. })
  67. }else{
  68. // 已经授权了
  69. this.saveImg1(that.data.poster);
  70. }
  71. },
  72. fail: (res) =>{
  73. console.log(res)
  74. }
  75. })
  76. },
  77. saveImg1(url){
  78. wx.getImageInfo({
  79. src: url,
  80. success:(res)=> {
  81. let path = res.path;
  82. wx.saveImageToPhotosAlbum({
  83. filePath:path,
  84. success:(res)=> {
  85. console.log(res);
  86. wx.showToast({
  87. title: '保存成功发给朋友吧~',
  88. icon:'none'
  89. })
  90. },
  91. fail:(res)=>{
  92. console.log(res);
  93. wx.showToast({
  94. title: '保存失败',
  95. icon:'none'
  96. })
  97. }
  98. })
  99. },
  100. fail:(res)=> {
  101. // this.saveImg()
  102. }
  103. })
  104. },
  105. onReady: function () {
  106. },
  107. onShow: function () {
  108. },
  109. onHide: function () {
  110. },
  111. onUnload: function () {
  112. },
  113. onPullDownRefresh: function () {
  114. },
  115. onReachBottom: function () {
  116. }
  117. })