madeFont.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. isActive: '1', // 默认是正面
  20. obverseImgObject: {
  21. '1': '/customized/images/customized/cup_black_big.png',/*正面 */
  22. '2': '/customized/images/customized/cup_black_side.png',/*侧面面 */
  23. '3': '/customized/images/customized/cup_black_handle.png',/*手柄 */
  24. '4': '/customized/images/customized/cup_black_bottom.png',/*底部 */
  25. },
  26. radarImg:null,
  27. fontColor: ['#ffffff','#000000', '#e70012', '#ff8500', '#fff100', '#22ad38', '#00b7f0', '#920784'],
  28. isColor: '#ffffff', // 默认是白色
  29. addFontStatic: false, // 添加文字
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. let that = this;
  36. that.changeCupImg('1');
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  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],that = this;
  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. addFont(){ // 添加文字
  85. let that = this;
  86. wx.canvasToTempFilePath({
  87. x: 0,
  88. y: 0,
  89. width: 750,
  90. height: 588,
  91. canvasId: 'madeContent',
  92. success: function (res) {
  93. that.setData({
  94. radarImg: res.tempFilePath,
  95. })
  96. setTimeout(()=>{
  97. that.setData({
  98. addFontStatic: true
  99. })
  100. },200)
  101. }
  102. });
  103. },
  104. handleCanvarToImg(that){
  105. wx.canvasToTempFilePath({
  106. x: 0,
  107. y: 0,
  108. width: 750,
  109. height: 588,
  110. canvasId: 'madeContent',
  111. success: function (res) {
  112. that.setData({
  113. radarImg: res.tempFilePath,
  114. })
  115. }
  116. });
  117. },
  118. selectColor(e){ // 选择颜色
  119. this.setData({
  120. isColor: e.currentTarget.dataset.color
  121. })
  122. }
  123. })