util.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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: '156rpx',
  22. left: '286rpx',
  23. width: '',
  24. height: ''
  25. };
  26. propSize = {
  27. top: '8cm',
  28. right: '8cm',
  29. bottom: '8cm',
  30. left: '8cm',
  31. };
  32. break;
  33. case '2':
  34. dataPositionObj = { // 正面数据
  35. top: '156rpx',
  36. left: '180rpx',
  37. width: '',
  38. height: ''
  39. };
  40. propSize = {
  41. top: '8cm',
  42. right: '8cm',
  43. bottom: '8cm',
  44. left: '8cm',
  45. };
  46. // console.log('背面');
  47. break;
  48. case '3':
  49. dataPositionObj = { // 正面数据
  50. top: '150rpx',
  51. left: '348rpx',
  52. width: '70rpx',
  53. height: '268rpx'
  54. };
  55. propSize = {
  56. top: '1cm',
  57. right: '6cm',
  58. bottom: '1cm',
  59. left: '6cm',
  60. };
  61. // console.log('手柄');
  62. break;
  63. case '4':
  64. dataPositionObj = { // 正面数据
  65. top: '160rpx',
  66. left: '190rpx',
  67. width: '265rpx',
  68. height: '265rpx'
  69. };
  70. propSize = {
  71. top: '6cm',
  72. right: '6cm',
  73. bottom: '6cm',
  74. left: '6cm',
  75. };
  76. // console.log('杯底');
  77. break;
  78. default:
  79. break;
  80. }
  81. return {
  82. dataPositionObj: dataPositionObj,
  83. propSize: propSize
  84. }
  85. }
  86. module.exports = {
  87. formatTime: formatTime,
  88. changeCup: changeCup
  89. }
  90. // function imageUtil(e) {
  91. // var imageSize = {};
  92. // var originalWidth = e.detail.width;//图片原始宽
  93. // var originalHeight = e.detail.height;//图片原始高
  94. // var originalScale = originalHeight / originalWidth;//图片高宽比
  95. // //获取屏幕宽高
  96. // wx.getSystemInfo({
  97. // success: function (res) {
  98. // var windowWidth = res.windowWidth;
  99. // var windowHeight = res.windowHeight;
  100. // var windowscale = windowHeight / windowWidth;//屏幕高宽比
  101. // imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth;
  102. // }
  103. // })
  104. // //return imageSize;
  105. // }
  106. // module.exports = {
  107. // imageUtil: imageUtil
  108. // }
  109. // import _Promise from 'bluebird';
  110. // /**
  111. // * @param {Function} fun 接口
  112. // * @param {Object} options 接口参数
  113. // * @returns {Promise} Promise对象
  114. // */
  115. // function Promise(fun, options) {
  116. // options = options || {};
  117. // return new _Promise((resolve, reject) => {
  118. // if (typeof fun !== 'function') {
  119. // reject();
  120. // }
  121. // options.success = resolve;
  122. // options.fail = reject;
  123. // fun(options);
  124. // });
  125. // }
  126. // /**
  127. // * 手势库
  128. // */
  129. // function touchstart(e, _this) {
  130. // const t = e.touches[0],
  131. // startX = t.clientX,
  132. // startY = t.clientY;
  133. // _this.setData({
  134. // 'gesture.startX': startX,
  135. // 'gesture.startY': startY,
  136. // 'gesture.out': true
  137. // })
  138. // }
  139. // /**
  140. // * 左滑
  141. // * @returns {boolean} 布尔值
  142. // */
  143. // function isLeftSlide(e, _this) {
  144. // if (_this.data.gesture.out) {
  145. // const t = e.touches[0],
  146. // deltaX = t.clientX - _this.data.gesture.startX,
  147. // deltaY = t.clientY - _this.data.gesture.startY;
  148. // if (deltaX < -20 && deltaX > -40 && deltaY < 8 && deltaY > -8) {
  149. // _this.setData({
  150. // 'gesture.out': false
  151. // })
  152. // return true;
  153. // } else {
  154. // return false;
  155. // }
  156. // }
  157. // }
  158. // /**
  159. // * 右滑
  160. // * @returns {boolean} 布尔值
  161. // */
  162. // function isRightSlide(e, _this) {
  163. // if (_this.data.gesture.out) {
  164. // const t = e.touches[0],
  165. // deltaX = t.clientX - _this.data.gesture.startX,
  166. // deltaY = t.clientY - _this.data.gesture.startY;
  167. // if (deltaX > 20 && deltaX < 40 && deltaY < 8 && deltaY > -8) {
  168. // _this.setData({
  169. // 'gesture.out': false
  170. // })
  171. // return true;
  172. // } else {
  173. // return false;
  174. // }
  175. // }
  176. // }
  177. // module.exports = {
  178. // Promise: Promise,
  179. // Gesture: {
  180. // touchstart: touchstart,
  181. // isLeftSlide: isLeftSlide,
  182. // isRightSlide: isRightSlide
  183. // }
  184. // }