made.js 7.3 KB

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