share.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const app = require('../../utils/util.js');
  2. Page({
  3. data: {
  4. codeImg: '../../images/ewm.png',
  5. bj: '../../images/ewmbj.png'
  6. },
  7. save() {
  8. wx.saveImageToPhotosAlbum({
  9. filePath: this.data.imagePath,
  10. success:(data)=> {
  11. console.log(data)
  12. let fileMgr = wx.getFileSystemManager()
  13. fileMgr.unlink({
  14. filePath: this.data.imagePath,
  15. success() {
  16. wx.showToast({
  17. title: '已保存',
  18. duration: 2000
  19. })
  20. }
  21. })
  22. },
  23. fail(err) {
  24. if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
  25. wx.showModal({
  26. title: '提示',
  27. content: '需要您授权保存相册',
  28. showCancel: false,
  29. success: modalSuccess => {
  30. wx.openSetting({
  31. success(settingdata) {
  32. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  33. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  34. } else {
  35. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  36. }
  37. }
  38. })
  39. }
  40. })
  41. }
  42. }
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. wx.showLoading();
  50. console.log('1111111')
  51. const ctx = wx.createCanvasContext('myCanvasId');
  52. ctx.drawImage(this.data.bj, 0, 0, 302, 256); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
  53. ctx.drawImage(this.data.codeImg, 88, 114, 114, 114);
  54. ctx.draw();
  55. this.save();
  56. setTimeout(() => {
  57. wx.canvasToTempFilePath({
  58. canvasId: 'myCanvasId',
  59. success: (res) => {
  60. var tempFilePath = res.tempFilePath;
  61. this.setData({
  62. imagePath: tempFilePath
  63. })
  64. wx.hideLoading();
  65. },
  66. fail: (res) => {
  67. console.log(res);
  68. wx.hideLoading();
  69. }
  70. });
  71. }, 200);
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. onUnload: function () {
  89. },
  90. onPullDownRefresh: function () {
  91. },
  92. /**
  93. * 页面上拉触底事件的处理函数
  94. */
  95. onReachBottom: function () {
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function () {
  101. }
  102. })