madeFont.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/customized/made/madeFont/madeFont.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. fontContent: '可定制区域',
  20. fontColor:'#fff',
  21. fontSize:null,
  22. isActive: '1', // 默认是正面
  23. obverseImgObject: {
  24. '1': '/customized/images/customized/cup_black_big.png',/*正面 */
  25. '2': '/customized/images/customized/cup_black_side.png',/*侧面面 */
  26. '3': '/customized/images/customized/cup_black_handle.png',/*手柄 */
  27. '4': '/customized/images/customized/cup_black_bottom.png',/*底部 */
  28. },
  29. radarImg:null,
  30. fontColor: ['#ffffff','#000000', '#e70012', '#ff8500', '#fff100', '#22ad38', '#00b7f0', '#920784'],
  31. isColor: '#ffffff', // 默认是白色
  32. addFontStatic: false, // 添加文字
  33. inputFont:null
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady: function () {
  44. let that = this;
  45. that.changeCupImg('1');
  46. },
  47. /**
  48. * 生命周期函数--监听页面显示
  49. */
  50. onShow: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面隐藏
  54. */
  55. onHide: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面卸载
  59. */
  60. onUnload: function () {
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function () {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. },
  77. changeCupImg(index) {
  78. let canvasBg = this.data.obverseImgObject[index],that = this;
  79. // wx.getSystemInfo({
  80. // success: function (res) {
  81. // let rpx = res.windowWidth / 750;
  82. // const ctx = wx.createCanvasContext('madeContent');
  83. // ctx.drawImage(canvasBg, 0, 0, 750 * rpx, 588 * rpx)
  84. // ctx.draw();
  85. // setTimeout(()=>{
  86. // that.handleCanvarToImg(that)
  87. // },1000)
  88. // },
  89. // })
  90. },
  91. addFont(){ // 添加文字
  92. let that = this;
  93. that.setData({
  94. addFontStatic: true
  95. })
  96. },
  97. fontCancel(){
  98. this.setData({
  99. addFontStatic: false
  100. })
  101. },
  102. bindinput(e){
  103. this.setData({
  104. inputFont: e.detail.value,
  105. })
  106. },
  107. fontConfirm(e){
  108. console.log('点击完成', e.detail)
  109. let that = this;
  110. if (that.data.inputFont){
  111. that.setData({
  112. fontContent: that.data.inputFont,
  113. fontColor: that.data.isColor,
  114. fontSize:'88rpx',
  115. addFontStatic: false
  116. })
  117. }
  118. },
  119. handleCanvarToImg(that){
  120. wx.canvasToTempFilePath({
  121. x: 0,
  122. y: 0,
  123. width: 750,
  124. height: 588,
  125. canvasId: 'madeContent',
  126. success: function (res) {
  127. that.setData({
  128. radarImg: res.tempFilePath,
  129. })
  130. }
  131. });
  132. },
  133. selectColor(e){ // 选择颜色
  134. this.setData({
  135. isColor: e.currentTarget.dataset.color
  136. })
  137. }
  138. })