boxMade.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // pages/customized/made/made.js
  2. import * as util from '../../../utils/util.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. dataPositionObj: {},
  9. propSize: {},
  10. isActive: '5', // 默认是正面
  11. obverseImgObject: {},
  12. imgTouch: {}, // 图片的对象,分为正面,侧面,手柄,底部
  13. fontTouch: {}, //文字的对象,分为正面,侧面,手柄,底部
  14. imgAnimationData: {}, // 图片的旋转
  15. fontAnimationData: {}, // 文字的旋转
  16. touchStatic: true,
  17. fontContent: '可定制区域',
  18. rpx: 1, // 获取页面的rpx
  19. imgSrcArray: [],
  20. imgBuildArray: [], // 生成后图片的数组
  21. simulation: { // 模拟字体,获取字体的宽高
  22. fontContent: '',
  23. fontSize: '',
  24. height: '',
  25. width: '',
  26. },
  27. dataId:['5','6']
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. let that = this;
  34. wx.getSystemInfo({
  35. success: function (res) {
  36. let rpx = res.windowWidth / 750;
  37. that.setData({
  38. rpx: rpx
  39. });
  40. console.log(rpx, 'rpx')
  41. },
  42. })
  43. if ('id' in options) {
  44. this.setData({
  45. isActive: options.id,
  46. dataId: options.dataId.split(',')
  47. })
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. let that = this;
  55. // console.log('页面开始准备中'
  56. that.imgAnimation = wx.createAnimation({
  57. timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
  58. })
  59. that.fontAnimation = wx.createAnimation({
  60. timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面显示
  65. */
  66. onShow: function () {
  67. console.log('onshow')
  68. let that = this;
  69. let cupNum = util.changeCup(that.data.isActive);
  70. console.log(cupNum,"changeCup")
  71. that.setData({
  72. dataPositionObj: cupNum.dataPositionObj,
  73. propSize: cupNum.propSize,
  74. obverseImgObject: util.changeImg
  75. })
  76. that.getDataTouch(that)
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function () {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom: function () {
  97. },
  98. /**
  99. * 用户点击右上角分享
  100. */
  101. onShareAppMessage: function () {
  102. },
  103. // changeCupImg(index){
  104. // console.log(this.data.imgTouch,"this.data.imgTouch")
  105. // let rpx = this.data.rpx;
  106. // let canvasBg = this.data.obverseImgObject[index];
  107. // const ctx = wx.createCanvasContext('madeContent');
  108. // ctx.drawImage(canvasBg, 0, 0, 750 * rpx, 588 * rpx)
  109. // ctx.draw()
  110. // },
  111. changeCup(e) {
  112. console.log(e,"点击了e")
  113. let that = this;
  114. let cupNum = util.changeCup(e.currentTarget.dataset.id);
  115. that.setData({
  116. isActive: e.currentTarget.dataset.id,
  117. dataPositionObj: cupNum.dataPositionObj,
  118. propSize: cupNum.propSize,
  119. })
  120. that.getDataTouch(that)
  121. },
  122. addImgRouter() {
  123. console.log('添加图片');
  124. wx.setStorageSync('box',this.data.box)
  125. wx.navigateTo({
  126. url: '/customized/pages/boxMade/boxMadeImg/boxMadeImg?id=' + this.data.isActive+'&dataId='+this.data.dataId,
  127. })
  128. },
  129. addFontRouter() {
  130. console.log('添加文字');
  131. wx.setStorageSync('box', this.data.box)
  132. wx.navigateTo({
  133. url: '/customized/pages/boxMade/boxMadeFont/boxMadeFont?id=' + this.data.isActive,
  134. })
  135. },
  136. getDataTouch(that) {
  137. let madeTouchImg = wx.getStorageSync('madeCupImgData' + that.data.isActive)
  138. let madeTouchFont = wx.getStorageSync('madeCupFontData' + that.data.isActive)
  139. console.log(madeTouchImg, madeTouchFont, "madeTouchFontmadeTouchFont")
  140. if (madeTouchImg || madeTouchFont) {
  141. that.setData({
  142. touchStatic: false
  143. })
  144. if (madeTouchImg) {
  145. that.imgAnimation.rotate(madeTouchImg.angle).step();
  146. that.setData({
  147. imgAnimationData: that.imgAnimation.export(),
  148. })
  149. }
  150. if (madeTouchFont) {
  151. that.fontAnimation.rotate(madeTouchFont.angle).step();
  152. that.setData({
  153. fontAnimationData: that.fontAnimation.export(),
  154. })
  155. that.setData({
  156. 'simulation.fontContent': madeTouchFont.fontContent,
  157. 'simulation.fontSize': madeTouchFont.fontSize
  158. })
  159. that.getTouchFontInformation(that)
  160. }
  161. } else {
  162. that.setData({
  163. touchStatic: true
  164. })
  165. }
  166. that.setData({
  167. imgTouch: madeTouchImg ? madeTouchImg : {}, //存储图片数据
  168. fontTouch: madeTouchFont ? madeTouchFont : {},
  169. })
  170. },
  171. finishDesign() { // 完成设计
  172. let that = this;
  173. let designObj = ['正面','背面'],
  174. designVal = '',
  175. madeStatic = false;
  176. for (let i = that.data.dataId[0] * 1; i <= that.data.dataId[1] * 1; i++) {
  177. if (!wx.getStorageSync('madeCupImgData' + i) && !wx.getStorageSync('madeCupFontData' + i)) {
  178. designVal += designObj[i - that.data.dataId[0] * 1] + ','
  179. } else {
  180. madeStatic = true; // 表示已经有设计过的页面
  181. }
  182. }
  183. if (madeStatic) {
  184. if (!designVal) {
  185. console.log('可以完成')
  186. wx.navigateTo({
  187. url: '/customized/pages/boxMade/boxComb/boxComb?dataId=' + that.data.dataId
  188. })
  189. } else {
  190. wx.showModal({
  191. title: '温馨提示',
  192. content: '您的' + designVal.substring(0, designVal.length - 1) + '还没有设计,是否确定不设计了?',
  193. success: function (res) {
  194. if (res.confirm) {
  195. console.log('用户点击确定,不设计了,直接完成')
  196. wx.navigateTo({
  197. url: '/customized/pages/boxMade/boxComb/boxComb?dataId=' + that.data.dataId
  198. })
  199. } else {
  200. console.log('用户点击取消')
  201. }
  202. }
  203. })
  204. }
  205. } else {
  206. wx.showToast({
  207. title: '您还没有设计',
  208. icon: 'none'
  209. })
  210. }
  211. },
  212. getTouchFontInformation(that) {
  213. let query = wx.createSelectorQuery();
  214. query.select('#simulation').boundingClientRect()
  215. query.exec(function (res) {
  216. console.log(res, "获取font的宽高");
  217. that.setData({
  218. 'simulation.height': res[0].height,
  219. 'simulation.width': res[0].width
  220. });
  221. wx.setStorageSync('simulationFont' + that.data.isActive, that.data.simulation);
  222. })
  223. },
  224. })