share.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const app = require('../../utils/util.js');
  2. const tool = require('../../utils/tool.js');
  3. Page({
  4. data: {
  5. codeImg: '../../images/ewm.png',
  6. bj: '../../images/ewmbj.png'
  7. },
  8. save() {
  9. console.log('我调取save了')
  10. wx.saveImageToPhotosAlbum({
  11. filePath: this.data.imagePath,
  12. success(res) {
  13. wx.showToast({
  14. title: '图片保存成功!',
  15. icon: 'none'
  16. })
  17. },
  18. fail: (res) => {
  19. console.log(res)
  20. if (res.errMsg === "saveImageToPhotosAlbum:fail auth deny" || res.errMsg === "saveImageToPhotosAlbum:fail:auth denied") {
  21. this.doAuth()
  22. }
  23. }
  24. })
  25. },
  26. // 获取授权
  27. doAuth() {
  28. wx.showModal({
  29. title: '获取授权',
  30. content: '您是否同意重新授权保存图片',
  31. cancelText: '不同意',
  32. confirmText: '同意',
  33. confirmColor: '#21c0ae',
  34. success: function (res) {
  35. if (res.confirm) { // 点击确认
  36. wx.openSetting({
  37. success(settingdata) {
  38. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  39. console.log("获取权限成功,再次点击图片保存到相册")
  40. } else {
  41. console.log("获取权限失败")
  42. }
  43. },
  44. fail: function (res) {
  45. console.log(res)
  46. }
  47. })
  48. }
  49. }
  50. })
  51. },
  52. getEwm() {
  53. tool.isLogin().then(result => {
  54. console.log('我完善信息了并获取授权了')
  55. tool.isFinishInfo().then(result2 => {
  56. tool.isFinishTargetInfo().then(redult3 => {
  57. wx.request({
  58. url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/share',
  59. method: "get",
  60. success: (res) => {
  61. if (res.data.code == 0) {
  62. this.draw(res.data.qrcode);
  63. }
  64. },
  65. fail(){
  66. wx.hideLoading();
  67. }
  68. })
  69. }).catch(err => {
  70. wx.showModal({
  71. title: '您还未完善择偶信息',
  72. showCancel: false,
  73. success(res) {
  74. if (res.confirm) {
  75. wx.navigateTo({
  76. url: '/pages/targetInfo/targetInfo',
  77. })
  78. }
  79. }
  80. })
  81. return false;
  82. })
  83. }).catch(err => {
  84. wx.showModal({
  85. title: '您还未完善个人信息',
  86. showCancel: false,
  87. success(res) {
  88. if (res.confirm) {
  89. wx.navigateTo({
  90. url: '/pages/personInfo/personInfo',
  91. })
  92. }
  93. }
  94. })
  95. return false;
  96. })
  97. }).catch(err => {
  98. wx.showModal({
  99. title: '您还未登录',
  100. showCancel: false,
  101. success(res) {
  102. if (res.confirm) {
  103. wx.redirectTo({
  104. url: '/pages/personal/personal',
  105. })
  106. }
  107. }
  108. });
  109. return false;
  110. })
  111. },
  112. draw(qrcode) {
  113. wx.downloadFile({
  114. url: qrcode,
  115. success: (res) => {
  116. const ctx = wx.createCanvasContext('myCanvasId');
  117. ctx.drawImage(this.data.bj, 0, 0, 302, 256); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
  118. ctx.drawImage(res.tempFilePath, 88, 114, 114, 114);
  119. ctx.draw();
  120. setTimeout(() => {
  121. wx.canvasToTempFilePath({
  122. canvasId: 'myCanvasId',
  123. success: (res) => {
  124. var tempFilePath = res.tempFilePath;
  125. this.setData({
  126. imagePath: tempFilePath
  127. })
  128. wx.hideLoading();
  129. },
  130. fail: (res) => {
  131. console.log(res);
  132. wx.hideLoading();
  133. }
  134. });
  135. }, 200);
  136. }
  137. })
  138. },
  139. /**
  140. * 生命周期函数--监听页面加载
  141. */
  142. onLoad: function (options) {
  143. wx.showLoading();
  144. tool.openidStatus().then(result => {
  145. this.setData({
  146. openid: result[0],
  147. sessionkey: result[1]
  148. })
  149. this.getEwm();
  150. })
  151. }
  152. })