oneMade.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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: '9', // 默认是正面
  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. box: { // 盒子默认是白色正面
  28. static: true,
  29. left: 'box-white-1-left',
  30. right: 'box-white-1-right'
  31. }
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. let that = this;
  38. wx.getSystemInfo({
  39. success: function (res) {
  40. let rpx = res.windowWidth / 750;
  41. that.setData({
  42. rpx: rpx
  43. });
  44. console.log(rpx, 'rpx')
  45. },
  46. })
  47. if ('id' in options) {
  48. this.setData({
  49. isActive: options.id
  50. })
  51. }
  52. },
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function () {
  57. let that = this;
  58. // console.log('页面开始准备中'
  59. that.imgAnimation = wx.createAnimation({
  60. timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
  61. })
  62. that.fontAnimation = wx.createAnimation({
  63. timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
  64. })
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. console.log('onshow')
  71. let that = this;
  72. let cupNum = util.changeCup(that.data.isActive);
  73. console.log(cupNum)
  74. that.setData({
  75. dataPositionObj: cupNum.dataPositionObj,
  76. propSize: cupNum.propSize,
  77. obverseImgObject:util.changeImg
  78. })
  79. that.getDataTouch(that);
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage: function () {
  105. },
  106. addImgRouter() {
  107. console.log('添加图片');
  108. wx.setStorageSync('box',this.data.box)
  109. wx.navigateTo({
  110. url: '/customized/pages/oneMade/oneMadeImg/oneMadeImg?id=' + this.data.isActive,
  111. })
  112. },
  113. addFontRouter() {
  114. console.log('添加文字');
  115. wx.setStorageSync('box', this.data.box)
  116. wx.navigateTo({
  117. url: '/customized/pages/oneMade/oneMadeFont/oneMadeFont?id=' + this.data.isActive,
  118. })
  119. },
  120. getDataTouch(that) {
  121. let madeTouchImg = wx.getStorageSync('madeImgData' + that.data.isActive)
  122. let madeTouchFont = wx.getStorageSync('madeFontData' + that.data.isActive)
  123. console.log(madeTouchImg, madeTouchFont, "madeTouchFontmadeTouchFont")
  124. if (madeTouchImg || madeTouchFont) {
  125. that.setData({
  126. touchStatic: false
  127. })
  128. if (madeTouchImg) {
  129. that.imgAnimation.rotate(madeTouchImg.angle).step();
  130. that.setData({
  131. imgAnimationData: that.imgAnimation.export(),
  132. })
  133. }
  134. if (madeTouchFont) {
  135. that.fontAnimation.rotate(madeTouchFont.angle).step();
  136. that.setData({
  137. fontAnimationData: that.fontAnimation.export(),
  138. })
  139. that.setData({
  140. 'simulation.fontContent': madeTouchFont.fontContent,
  141. 'simulation.fontSize': madeTouchFont.fontSize
  142. })
  143. that.getTouchFontInformation(that)
  144. }
  145. } else {
  146. that.setData({
  147. touchStatic: true
  148. })
  149. }
  150. that.setData({
  151. imgTouch: madeTouchImg ? madeTouchImg : {}, //存储图片数据
  152. fontTouch: madeTouchFont ? madeTouchFont : {},
  153. })
  154. },
  155. finishDesign() { // 完成设计
  156. let that = this;
  157. if (!wx.getStorageSync('madeImgData' + this.data.isActive) && !wx.getStorageSync('madeFontData' + this.data.isActive)) {
  158. wx.showToast({
  159. title: '您还没有设计',
  160. icon: 'none'
  161. })
  162. } else {
  163. wx.navigateTo({
  164. url: '/customized/pages/oneMade/oneComb/oneComb?id=' + this.data.isActive
  165. })
  166. }
  167. },
  168. getTouchFontInformation(that) {
  169. let query = wx.createSelectorQuery();
  170. query.select('#simulation').boundingClientRect()
  171. query.exec(function (res) {
  172. console.log(res, "获取font的宽高");
  173. that.setData({
  174. 'simulation.height': res[0].height,
  175. 'simulation.width': res[0].width
  176. });
  177. wx.setStorageSync('simulationFont' + that.data.isActive, that.data.simulation);
  178. })
  179. },
  180. })