sharePianoImg.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // pages/Components/sharePianoImg/sharePianoImg.js
  2. const app = getApp()
  3. const util = require('../../../utils/util.js')
  4. const base64Util = require('../../../utils/base64')
  5. Component({
  6. lifetimes: {
  7. ready: function () {
  8. var obj = this.data.piano
  9. var str = ''
  10. for (var i = 0; i < obj.code.length; i++) {
  11. str += obj.code.substring(i, i + 1);
  12. if ((i + 1) % 4 == 0) {
  13. str += " "
  14. }
  15. }
  16. const imgUrl = "https://app.schoolwisdoms.com/schoolbaby/api/code/generate?content=" + obj.code
  17. const posterConfig = this.data.posterConfig
  18. posterConfig.images[0].url = imgUrl
  19. posterConfig.images[1].url = this.data.piano.imgUrl
  20. posterConfig.texts[1].text = str
  21. posterConfig.texts[2].text = this.data.piano.schemeType
  22. posterConfig.texts[3].text = "购买日期:" + this.data.piano.createdDate
  23. posterConfig.texts[4].text = app.globalData.orgTitle
  24. this.setData({
  25. posterConfig
  26. })
  27. },
  28. },
  29. /**
  30. * 组件的属性列表
  31. */
  32. properties: {
  33. code: {
  34. type: String,
  35. value: ''
  36. },
  37. piano: {
  38. type: Object,
  39. value: null
  40. }
  41. },
  42. /**
  43. * 组件的初始数据
  44. */
  45. data: {
  46. code: '',
  47. schoolName: app.globalData.orgTitle,
  48. posterConfig: {
  49. 'width': 590,
  50. 'height': 840,
  51. 'backgroundColor': '#fff',
  52. 'debug': false,
  53. 'preload': true,
  54. 'hide-loading': true,
  55. images: [{
  56. x: 45,
  57. y: 160,
  58. url: 'https://app.schoolwisdoms.com/schoolbaby/api/code/generate?content=',
  59. width: 500,
  60. height: 500
  61. },
  62. {
  63. x: 20,
  64. y: 20,
  65. url: '',
  66. width: 180,
  67. height: 120
  68. },
  69. ],
  70. texts: [{
  71. x: 247,
  72. y: 700,
  73. baseLine: 'middle',
  74. text: '序列号',
  75. fontSize: 32,
  76. color: '#333',
  77. },
  78. {
  79. x: 100,
  80. y: 770,
  81. baseLine: 'middle',
  82. text: '',
  83. fontSize: 32,
  84. color: '#333',
  85. },
  86. {
  87. x: 220,
  88. y: 40,
  89. baseLine: 'middle',
  90. title: '',
  91. fontSize: 32,
  92. color: '#333',
  93. },
  94. {
  95. x: 220,
  96. y: 80,
  97. baseLine: 'middle',
  98. title: '',
  99. fontSize: 24,
  100. color: '#999',
  101. },
  102. {
  103. x: 220,
  104. y: 120,
  105. baseLine: 'middle',
  106. title: '',
  107. fontSize: 24,
  108. color: '#999',
  109. }
  110. ]
  111. },
  112. },
  113. /**
  114. * 组件的方法列表
  115. */
  116. methods: {
  117. //生成图片并保存
  118. onPosterSuccess(e) {
  119. let that = this;
  120. let {
  121. detail
  122. } = e;
  123. wx.saveImageToPhotosAlbum({
  124. filePath: detail,
  125. success(res) {
  126. wx.showToast({
  127. title: '图片已保存到本地相册',
  128. icon: 'none'
  129. })
  130. that.setData({
  131. showSaveImage: false
  132. })
  133. that.triggerEvent("callMethod")
  134. },
  135. fail(res) {
  136. that.getSetting()
  137. },
  138. complete(res){
  139. that.triggerEvent('closeWindow')
  140. }
  141. })
  142. },
  143. closeWindow:function(){
  144. this.triggerEvent('closeWindow')
  145. },
  146. getSetting: function () {
  147. // 相册授权
  148. wx.getSetting({
  149. success(res) {
  150. // 进行授权检测,未授权则进行弹层授权
  151. if (!res.authSetting["scope.writePhotosAlbum"]) {
  152. wx.showModal({
  153. title: '提示',
  154. content: '您未授权相册使用权限,是否重新授权?',
  155. success: function (res) {
  156. if (res.confirm) {
  157. wx.openSetting({
  158. success(settingdata) {
  159. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  160. console.log("获取权限成功,再次点击图片保存到相册")
  161. } else {
  162. console.log("获取权限失败")
  163. }
  164. },
  165. fail(res) {
  166. console.log(res)
  167. }
  168. })
  169. }
  170. }
  171. })
  172. }
  173. },
  174. fail(res) {
  175. console.log(res);
  176. }
  177. });
  178. },
  179. }
  180. })