util.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. function formatTime(date) {
  2. var year = date.getFullYear()
  3. var month = date.getMonth() + 1
  4. var day = date.getDate()
  5. var hour = date.getHours()
  6. var minute = date.getMinutes()
  7. var second = date.getSeconds()
  8. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  9. }
  10. function formatNumber(n) {
  11. n = n.toString()
  12. return n[1] ? n : '0' + n
  13. }
  14. function changeCup(e) {
  15. // e== 1正面,2背面,3手柄,4杯底
  16. let dataPositionObj = null, propSize = null;
  17. switch (e) {
  18. case '1':
  19. // console.log('正面')
  20. dataPositionObj = { // 正面数据
  21. top: 42,
  22. left: 256,
  23. width: 334,
  24. height: 450
  25. };
  26. propSize = {
  27. top: '6cm',
  28. right: '9.5cm',
  29. bottom: '6cm',
  30. left: '9.5cm',
  31. };
  32. break;
  33. case '2':
  34. dataPositionObj = { // 侧面数据
  35. top: 42,
  36. left: 154,
  37. width: 334,
  38. height: 450
  39. };
  40. propSize = {
  41. top: '6cm',
  42. right: '9.5cm',
  43. bottom: '6cm',
  44. left: '9.5cm',
  45. };
  46. // console.log('背面');
  47. break;
  48. case '3':
  49. dataPositionObj = { // 手柄数据
  50. top: 172,
  51. left: 346,
  52. width: 70,
  53. height: 246
  54. };
  55. propSize = {
  56. top: '1cm',
  57. right: '5cm',
  58. bottom: '1cm',
  59. left: '5cm',
  60. };
  61. // console.log('手柄');
  62. break;
  63. case '4':
  64. dataPositionObj = { // 正面数据
  65. top: 138,
  66. left: 178,
  67. width: 304,
  68. height: 304
  69. };
  70. propSize = {
  71. top: '5cm',
  72. right: '5cm',
  73. bottom: '5cm',
  74. left: '5cm',
  75. };
  76. // console.log('杯底');
  77. break;
  78. case '5': //表示是箱子
  79. dataPositionObj = { // 正面数据
  80. top: 74,
  81. left: 104,
  82. width: 536,
  83. height: 712
  84. };
  85. propSize = {
  86. top: '',
  87. right: '',
  88. bottom: '',
  89. left: '',
  90. };
  91. // console.log('杯底');
  92. break;
  93. case '6': //表示是箱子
  94. dataPositionObj = { // 正面数据
  95. top: 128,
  96. left: 109,
  97. width: 534,
  98. height: 654
  99. };
  100. propSize = {
  101. top: '',
  102. right: '',
  103. bottom: '',
  104. left: '',
  105. };
  106. break;
  107. case '9': //黑色T恤
  108. dataPositionObj = {
  109. top: 254,
  110. left: 204,
  111. width: 368,
  112. height: 440
  113. };
  114. propSize = {
  115. top: '',
  116. right: '',
  117. bottom: '',
  118. left: '',
  119. };
  120. // console.log('杯底');
  121. break;
  122. default:
  123. break;
  124. }
  125. return {
  126. dataPositionObj: dataPositionObj,
  127. propSize: propSize
  128. }
  129. }
  130. let changeImg={
  131. '9': '/customized/images/customized/shirt1.png',//黑色T恤
  132. '9_1': '/customized/images/customized/shirt1_1.png', //黑色T恤镂空
  133. '9_2': '/customized/images/customized/shirt1_2.png', //黑色T恤
  134. '10': '/customized/images/customized/shirt2.png',//红色T恤
  135. '10_1': '/customized/images/customized/shirt2_1.png',//红色T恤镂空
  136. '10_2': '/customized/images/customized/shirt2_2.png',//红色T恤
  137. '11': '/customized/images/customized/cup1.png',//白色杯子
  138. '11_1': '/customized/images/customized/cup1_1.png',//白色杯子镂空
  139. '11_2': '/customized/images/customized/cup1_2.png',//白色杯子
  140. '12': '/customized/images/customized/cup2.png',//黑色杯子
  141. '12_1': '/customized/images/customized/cup2_1.png',//白色杯子镂空
  142. '12_2': '/customized/images/customized/cup2_2.png',//白色杯子
  143. }
  144. module.exports = {
  145. formatTime: formatTime,
  146. changeCup: changeCup,
  147. changeImg: changeImg
  148. }
  149. // function imageUtil(e) {
  150. // var imageSize = {};
  151. // var originalWidth = e.detail.width;//图片原始宽
  152. // var originalHeight = e.detail.height;//图片原始高
  153. // var originalScale = originalHeight / originalWidth;//图片高宽比
  154. // //获取屏幕宽高
  155. // wx.getSystemInfo({
  156. // success: function (res) {
  157. // var windowWidth = res.windowWidth;
  158. // var windowHeight = res.windowHeight;
  159. // var windowscale = windowHeight / windowWidth;//屏幕高宽比
  160. // imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth;
  161. // }
  162. // })
  163. // //return imageSize;
  164. // }
  165. // module.exports = {
  166. // imageUtil: imageUtil
  167. // }
  168. // import _Promise from 'bluebird';
  169. // /**
  170. // * @param {Function} fun 接口
  171. // * @param {Object} options 接口参数
  172. // * @returns {Promise} Promise对象
  173. // */
  174. // function Promise(fun, options) {
  175. // options = options || {};
  176. // return new _Promise((resolve, reject) => {
  177. // if (typeof fun !== 'function') {
  178. // reject();
  179. // }
  180. // options.success = resolve;
  181. // options.fail = reject;
  182. // fun(options);
  183. // });
  184. // }
  185. // /**
  186. // * 手势库
  187. // */
  188. // function touchstart(e, _this) {
  189. // const t = e.touches[0],
  190. // startX = t.clientX,
  191. // startY = t.clientY;
  192. // _this.setData({
  193. // 'gesture.startX': startX,
  194. // 'gesture.startY': startY,
  195. // 'gesture.out': true
  196. // })
  197. // }
  198. // /**
  199. // * 左滑
  200. // * @returns {boolean} 布尔值
  201. // */
  202. // function isLeftSlide(e, _this) {
  203. // if (_this.data.gesture.out) {
  204. // const t = e.touches[0],
  205. // deltaX = t.clientX - _this.data.gesture.startX,
  206. // deltaY = t.clientY - _this.data.gesture.startY;
  207. // if (deltaX < -20 && deltaX > -40 && deltaY < 8 && deltaY > -8) {
  208. // _this.setData({
  209. // 'gesture.out': false
  210. // })
  211. // return true;
  212. // } else {
  213. // return false;
  214. // }
  215. // }
  216. // }
  217. // /**
  218. // * 右滑
  219. // * @returns {boolean} 布尔值
  220. // */
  221. // function isRightSlide(e, _this) {
  222. // if (_this.data.gesture.out) {
  223. // const t = e.touches[0],
  224. // deltaX = t.clientX - _this.data.gesture.startX,
  225. // deltaY = t.clientY - _this.data.gesture.startY;
  226. // if (deltaX > 20 && deltaX < 40 && deltaY < 8 && deltaY > -8) {
  227. // _this.setData({
  228. // 'gesture.out': false
  229. // })
  230. // return true;
  231. // } else {
  232. // return false;
  233. // }
  234. // }
  235. // }
  236. // module.exports = {
  237. // Promise: Promise,
  238. // Gesture: {
  239. // touchstart: touchstart,
  240. // isLeftSlide: isLeftSlide,
  241. // isRightSlide: isRightSlide
  242. // }
  243. // }