made.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // pages/customized/made/made.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. dataPositionObj:{ //正面数据
  8. top:'156rpx',
  9. left:'286rpx',
  10. width:'',
  11. height:''
  12. },
  13. propSize:{
  14. top:'8cm',
  15. right:'8cm',
  16. bottom: '8cm',
  17. left:'8cm',
  18. },
  19. isActive: '1', // 默认是正面
  20. obverseImgObject:{
  21. '1': '/images/customized/cup_black_big.png',/*正面 */
  22. '2': '/images/customized/cup_black_side.png',/*侧面面 */
  23. '3': '/images/customized/cup_black_handle.png',/*手柄 */
  24. '4': '/images/customized/cup_black_bottom.png',/*底部 */
  25. },
  26. fontColor: ['#000', '#fff', '#e70012', '#ff8500', '#fff100', '#22ad38', '#00b7f0','#920784']
  27. // obverseImg: '/images/customized/cup_black_big.png',/*正面 */
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. this.changeCupImg(this.data.isActive);
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady: function () {
  39. // console.log('页面开始准备中')
  40. const ctx = wx.createCanvasContext('madeBox');
  41. // Canvas.SetLeft(ctx, '10rpx');
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. },
  73. changeCupImg(index){
  74. let canvasBg = this.data.obverseImgObject[index];
  75. wx.getSystemInfo({
  76. success: function (res) {
  77. let rpx = res.windowWidth / 750;
  78. const ctx = wx.createCanvasContext('madeContent');
  79. ctx.drawImage(canvasBg, 0, 0, 750 * rpx, 588 * rpx)
  80. ctx.draw()
  81. },
  82. })
  83. },
  84. changeCup(e){
  85. // data-id== 1正面,2背面,3手柄,4杯底
  86. this.changeCupImg(e.currentTarget.dataset.id);
  87. let dataPositionObj = null, propSize=null;
  88. switch (e.currentTarget.dataset.id){
  89. case '1':
  90. // console.log('正面')
  91. dataPositionObj = { // 正面数据
  92. top: '156rpx',
  93. left: '286rpx',
  94. width: '',
  95. height: ''
  96. };
  97. propSize={
  98. top: '8cm',
  99. right: '8cm',
  100. bottom: '8cm',
  101. left: '8cm',
  102. };
  103. break;
  104. case '2':
  105. dataPositionObj = { // 正面数据
  106. top: '156rpx',
  107. left: '180rpx',
  108. width: '',
  109. height: ''
  110. };
  111. propSize = {
  112. top: '8cm',
  113. right: '8cm',
  114. bottom: '8cm',
  115. left: '8cm',
  116. };
  117. // console.log('背面');
  118. break;
  119. case '3':
  120. dataPositionObj = { // 正面数据
  121. top: '160rpx',
  122. left: '348rpx',
  123. width: '70rpx',
  124. height: '268rpx'
  125. };
  126. propSize = {
  127. top: '1cm',
  128. right: '6cm',
  129. bottom: '1cm',
  130. left: '6cm',
  131. };
  132. // console.log('手柄');
  133. break;
  134. case '4':
  135. dataPositionObj = { // 正面数据
  136. top: '160rpx',
  137. left: '190rpx',
  138. width: '265rpx',
  139. height: '265rpx'
  140. };
  141. propSize = {
  142. top: '6cm',
  143. right: '6cm',
  144. bottom: '6cm',
  145. left: '6cm',
  146. };
  147. // console.log('杯底');
  148. break;
  149. default:
  150. break;
  151. }
  152. this.setData({
  153. isActive: e.currentTarget.dataset.id,
  154. dataPositionObj: dataPositionObj,
  155. propSize: propSize
  156. })
  157. },
  158. addImg(){
  159. console.log('添加图片')
  160. },
  161. addFont() {
  162. console.log('添加文字')
  163. }
  164. })