share.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // pages/share/share.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. codeImg: 'https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E4%BA%8C%E7%BB%B4%E7%A0%81&step_word=&hs=0&pn=0&spn=0&di=19620&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=65199140%2C1406017826&os=695039919%2C3289081284&simid=0%2C0&adpicid=0&lpn=0&ln=1845&fr=&fmq=1607396518663_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined&copyright=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=11&oriquery=&objurl=http%3A%2F%2Fremote.yunnan.cn%2Fqr%2Fphp%2Fqr.php%3Fd%3Dhttp%3A%2F%2Fnews.yunnan.cn%2Fsystem%2F2020%2F12%2F08%2F031165250.shtml&fromurl=ippr_z2C%24qAzdH3FAzdH3Fgjof_z%26e3By7ggwg_z%26e3BvgAzdH3Ffyfpj4AzdH3FdadaAzdH3F8dAzdH3FabAzdH3Fan88mcdca_z%26e3Bfip4s&gsm=1&rpstart=0&rpnum=0&islist=&querylist=&force=undefined'
  8. },
  9. save() {
  10. wx.getSetting({
  11. success: (res) => {
  12. console.log(res)
  13. if (!res.authSetting['scope.writePhotosAlbum']) {
  14. wx.authorize({
  15. scope: 'scope.writePhotosAlbum',
  16. success() {
  17. console.log(res, "我点击同意啦")
  18. wx.showLoading({
  19. title: '保存中...'
  20. })
  21. let imgSrc = this.data.codeImg;
  22. wx.downloadFile({
  23. url: imgSrc,
  24. success: function (res) {
  25. console.log(res, '我下载完成啦');
  26. //图片保存到本地
  27. wx.saveImageToPhotosAlbum({
  28. filePath: res.tempFilePath,
  29. success: function (data) {
  30. console.log(data, '我保存成功啦')
  31. wx.hideLoading();
  32. wx.showToast({
  33. title: '保存成功',
  34. icon: 'success',
  35. duration: 2000
  36. })
  37. },
  38. fail: function (err) {
  39. console.log(err, '我保存失败啦')
  40. wx.hideLoading();
  41. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  42. console.log("当初用户拒绝,再次发起授权")
  43. wx.openSetting({
  44. success(settingdata) {
  45. console.log(settingdata)
  46. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  47. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  48. } else {
  49. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  50. }
  51. }
  52. })
  53. }
  54. },
  55. complete(res) {
  56. console.log(res);
  57. }
  58. })
  59. },
  60. complete(res) {
  61. wx.hideLoading()
  62. }
  63. })
  64. }
  65. })
  66. } else {
  67. wx.showLoading({
  68. title: '保存中...'
  69. })
  70. console.log(this.data.classInfo.codeImg)
  71. let imgSrc = this.data.classInfo.codeImg
  72. wx.downloadFile({
  73. url: imgSrc,
  74. success: function (res) {
  75. console.log(res, '我下载完成啦');
  76. wx.hideLoading();
  77. //图片保存到本地
  78. wx.saveImageToPhotosAlbum({
  79. filePath: res.tempFilePath,
  80. success: function (data) {
  81. console.log(data, '我保存成功啦')
  82. wx.hideLoading();
  83. wx.showToast({
  84. title: '保存成功',
  85. icon: 'success',
  86. duration: 2000
  87. })
  88. },
  89. fail: function (err) {
  90. console.log(err, '我保存失败啦')
  91. wx.hideLoading();
  92. if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  93. console.log("当初用户拒绝,再次发起授权")
  94. wx.openSetting({
  95. success(settingdata) {
  96. console.log(settingdata)
  97. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  98. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  99. } else {
  100. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  101. }
  102. }
  103. })
  104. }
  105. },
  106. complete(res) {
  107. console.log(res);
  108. }
  109. })
  110. }
  111. })
  112. }
  113. }
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad: function (options) {
  120. },
  121. /**
  122. * 生命周期函数--监听页面初次渲染完成
  123. */
  124. onReady: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面显示
  128. */
  129. onShow: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面隐藏
  133. */
  134. onHide: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面卸载
  138. */
  139. onUnload: function () {
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh: function () {
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. onReachBottom: function () {
  150. },
  151. /**
  152. * 用户点击右上角分享
  153. */
  154. onShareAppMessage: function () {
  155. }
  156. })