made.js 5.6 KB

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