boxMade.js 7.2 KB

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