share.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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(result,'我完善头像了并获取授权了')
  55. tool.isFinishInfo().then(result2 => {
  56. console.log(result2.id,'我完善了')
  57. tool.isFinishTargetInfo().then(redult3 => {
  58. wx.showLoading();
  59. wx.request({
  60. url: app.globalData.publicUrl + '/wx/mpuser/wxeef6678b92b6c856/qrCode',
  61. method: "get",
  62. data: {
  63. memberId:result2.id
  64. },
  65. success: (res) => {
  66. console.log(res)
  67. this.draw(res.data);
  68. },
  69. fail() {
  70. wx.hideLoading();
  71. }
  72. })
  73. }).catch(err => {
  74. wx.showModal({
  75. title: '您还未完善择偶信息',
  76. showCancel: false,
  77. success(res) {
  78. if (res.confirm) {
  79. wx.redirectTo({
  80. url: '/pages/targetInfo/targetInfo',
  81. })
  82. }
  83. }
  84. })
  85. return false;
  86. })
  87. }).catch(err => {
  88. wx.showModal({
  89. title: '您还未完善个人或者详细信息',
  90. showCancel: false,
  91. success(res) {
  92. if (res.confirm) {
  93. wx.redirectTo({
  94. url: '/pages/personInfo/personInfo',
  95. })
  96. }
  97. }
  98. })
  99. return false;
  100. })
  101. }).catch(err => {
  102. wx.showModal({
  103. title: '您还未登录',
  104. showCancel: false,
  105. success(res) {
  106. if (res.confirm) {
  107. wx.redirectTo({
  108. url: '/pages/personal/personal',
  109. })
  110. }
  111. }
  112. });
  113. return false;
  114. })
  115. },
  116. draw(qrcode) {
  117. wx.downloadFile({
  118. url: qrcode,
  119. success: (res) => {
  120. const ctx = wx.createCanvasContext('myCanvasId');
  121. ctx.drawImage(this.data.bj, 10, 0, 355, 295); //里面的参数无非就是图片放置的位置即图片的横纵坐标,图片的宽高
  122. ctx.drawImage(res.tempFilePath, 106, 124, 148, 148);
  123. ctx.draw();
  124. setTimeout(() => {
  125. wx.canvasToTempFilePath({
  126. canvasId: 'myCanvasId',
  127. success: (res) => {
  128. var tempFilePath = res.tempFilePath;
  129. this.setData({
  130. imagePath: tempFilePath
  131. })
  132. wx.hideLoading();
  133. },
  134. fail: (res) => {
  135. console.log(res);
  136. wx.hideLoading();
  137. }
  138. });
  139. }, 200);
  140. }
  141. })
  142. },
  143. /**
  144. * 生命周期函数--监听页面加载
  145. */
  146. // getInfos() {
  147. // wx.request({
  148. // url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
  149. // method: "get",
  150. // success: (res) => {
  151. // console.log(res, '我是获取的信息')
  152. // if (res.data.code == 0) {
  153. // // this.setData({
  154. // // myInfo: res.data.info
  155. // // })
  156. // this.getEwm(res.data.info.id);
  157. // }
  158. // }
  159. // })
  160. // },
  161. onLoad: function (options) {
  162. tool.openidStatus().then(result => {
  163. this.setData({
  164. openid: result[0],
  165. sessionkey: result[1]
  166. })
  167. this.getEwm();
  168. })
  169. }
  170. })