boxMadeFont.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. // pages/customized/made/madeFont/madeFont.js
  2. import * as util from '../../../../utils/util.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. dataPositionObj: {},
  9. propSize: {},
  10. isActive: '5', // 默认是正面
  11. obverseImgObject: {},
  12. // radarImg:null,
  13. fontColorArray: ['#ffffff', '#000000', '#e70012', '#ff8500', '#fff100', '#22ad38', '#00b7f0', '#920784'],
  14. fontFamilyArray: ['Nomal', 'Monospace', 'Sans', 'Serif'], // 自带字体样式
  15. addFontStatic: false, // 添加文字
  16. inputFont: null,
  17. fontTouch: {
  18. isActive: '1', // 表示正面
  19. fontContent: '可定制区域',
  20. isColor: '#ffffff', // 默认是白色
  21. x: 10, // 字体的top值 x坐标
  22. y: 10, // 字体的 left值,y坐标
  23. angle: 0, // 旋转度数
  24. fontSize: null,
  25. clientX: 0, // 默认初始值
  26. clientY: 0, // 默认初始值
  27. width: 0,
  28. height: 0,
  29. bold:false,
  30. },
  31. imgFont:{}, // 图片对象
  32. animationData: {}, //旋转动画
  33. imgAnimationData: {}, // 图片的旋转
  34. imgTouch:{},
  35. box:{},
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. let that = this;
  42. that.animation = wx.createAnimation({
  43. timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
  44. })
  45. that.imgAnimation = wx.createAnimation({
  46. timingFunction: 'step-start', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
  47. })
  48. if ('id' in options) {
  49. let cupNum = util.changeCup(options.id);
  50. let madeTouchFont = wx.getStorageSync('madeCupFontData' + options.id);
  51. if (madeTouchFont) {
  52. that.animation.rotate(madeTouchFont.angle).step();
  53. that.setData({
  54. fontTouch: madeTouchFont,
  55. animationData: that.animation.export(),
  56. isActive: options.id,
  57. dataPositionObj: cupNum.dataPositionObj,
  58. propSize: cupNum.propSize
  59. })
  60. } else {
  61. that.setData({
  62. 'fontTouch.isActive': options.id,
  63. isActive: options.id,
  64. dataPositionObj: cupNum.dataPositionObj,
  65. propSize: cupNum.propSize
  66. })
  67. }
  68. }
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function () {
  74. let that = this;
  75. that.changeCupImg('1');
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. this.setData({
  82. box: wx.getStorageSync('box'),
  83. obverseImgObject: util.changeImg
  84. })
  85. this.getDataTouch(this)
  86. },
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面卸载
  94. */
  95. onUnload: function () {
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh: function () {
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function () {
  111. },
  112. changeCupImg(index) {
  113. let canvasBg = this.data.obverseImgObject[index],
  114. that = this;
  115. // wx.getSystemInfo({
  116. // success: function (res) {
  117. // let rpx = res.windowWidth / 750;
  118. // const ctx = wx.createCanvasContext('madeContent');
  119. // ctx.drawImage(canvasBg, 0, 0, 750 * rpx, 588 * rpx)
  120. // ctx.draw();
  121. // setTimeout(()=>{
  122. // that.handleCanvarToImg(that)
  123. // },1000)
  124. // },
  125. // })
  126. },
  127. addFont() { // 添加文字
  128. let that = this;
  129. that.setData({
  130. addFontStatic: true
  131. })
  132. },
  133. fontCancel() {
  134. this.setData({
  135. addFontStatic: false
  136. })
  137. },
  138. bindinput(e) {
  139. this.setData({
  140. inputFont: e.detail.value,
  141. })
  142. },
  143. fontConfirm(e) {
  144. let that = this;
  145. if (that.data.inputFont) {
  146. this.animation.rotate(0).step()
  147. that.setData({
  148. 'fontTouch.fontContent': that.data.inputFont,
  149. 'fontTouch.fontSize': 30,
  150. 'fontTouch.angle': 0,
  151. addFontStatic: false,
  152. animationData: this.animation.export()
  153. })
  154. // that.getTouchFontInformation(that)
  155. that.setData({
  156. inputFont: null,
  157. })
  158. }
  159. },
  160. handleCanvarToImg(that) {
  161. wx.canvasToTempFilePath({
  162. x: 0,
  163. y: 0,
  164. width: 750,
  165. height: 588,
  166. canvasId: 'madeContent',
  167. success: function (res) {
  168. that.setData({
  169. radarImg: res.tempFilePath,
  170. })
  171. }
  172. });
  173. },
  174. selectColor(e) { // 选择颜色
  175. this.setData({
  176. 'fontTouch.isColor': e.currentTarget.dataset.color
  177. })
  178. },
  179. // touch 事件
  180. fontTouchstart(e) {
  181. //1.获取鼠标点击下去的
  182. this.setData({
  183. "fontTouch.clientX": e.touches[0].clientX - this.data.fontTouch.x,
  184. "fontTouch.clientY": e.touches[0].clientY - this.data.fontTouch.y
  185. });
  186. console.log(this.data.fontTouch, "touch")
  187. },
  188. fontTouchmove(e) {
  189. // 鼠标移动的位置
  190. this.setData({
  191. "fontTouch.x": e.changedTouches[0].clientX - this.data.fontTouch.clientX,
  192. "fontTouch.y": e.changedTouches[0].clientY - this.data.fontTouch.clientY
  193. });
  194. // console.log(this.data.touch)
  195. },
  196. fontTouchend(e) {
  197. console.log('移动结束', e)
  198. console.log(this.data.fontTouch)
  199. },
  200. fontDelete() {
  201. // 删除
  202. let touch = {
  203. fontContent: '可定制区域',
  204. isColor: '#ffffff', // 默认是白色
  205. x: 10, // 字体的top值 x坐标
  206. y: 10, // 字体的 left值,y坐标
  207. rotate: 180, // 旋转度数
  208. fontSize: null,
  209. clientX: 0, // 默认初始值
  210. clientY: 0, // 默认初始值
  211. width: 0,
  212. height: 0,
  213. }
  214. this.setData({
  215. fontTouch: touch,
  216. })
  217. },
  218. fontEnlarge(e) { // 放大与缩小
  219. console.log(e.detail)
  220. this.setData({
  221. 'fontTouch.fontSize': e.detail.value
  222. })
  223. },
  224. fontRotate(e) { // 旋转
  225. this.animation.rotate(e.detail.value).step();
  226. this.setData({
  227. animationData: this.animation.export(),
  228. 'fontTouch.angle': e.detail.value
  229. });
  230. },
  231. fontWeight(e) {
  232. this.setData({
  233. 'fontTouch.bold': e.detail.value
  234. })
  235. },
  236. madeConfirm() { // 设计完成进行确定
  237. let that = this;
  238. if (that.data.fontTouch.fontSize) {
  239. that.getTouchFontInformation(that);
  240. // wx.redirectTo({
  241. // url: '/customized/pages/made/made?id='+ this.data.isActive,
  242. // })
  243. } else {
  244. wx.showToast({
  245. title: '您还没有添加文字进行设计',
  246. icon: 'none'
  247. })
  248. }
  249. },
  250. getTouchFontInformation(that) {
  251. let query = wx.createSelectorQuery();
  252. query.select('#touchFont').boundingClientRect()
  253. query.exec(function (res) {
  254. console.log(res, "获取font的宽高");
  255. that.setData({
  256. 'fontTouch.width': res[0].width,
  257. 'fontTouch.height': res[0].height
  258. });
  259. wx.setStorageSync('madeCupFontData' + that.data.isActive, that.data.fontTouch);
  260. wx.navigateBack()
  261. })
  262. },
  263. getDataTouch(that) {
  264. let madeTouchImg = wx.getStorageSync('madeCupImgData' + that.data.isActive)
  265. if (madeTouchImg) {
  266. that.imgAnimation.rotate(madeTouchImg.angle).step();
  267. that.setData({
  268. imgAnimationData: that.imgAnimation.export(),
  269. imgTouch: madeTouchImg ? madeTouchImg : {}, //存储图片数据
  270. })
  271. }
  272. },
  273. weightBtn(){
  274. let that = this;
  275. that.setData({
  276. 'fontTouch.bold':!that.data.fontTouch.bold
  277. })
  278. }
  279. })