util.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. // console.log('杯底');
  107. break;
  108. default:
  109. break;
  110. }
  111. return {
  112. dataPositionObj: dataPositionObj,
  113. propSize: propSize
  114. }
  115. }
  116. module.exports = {
  117. formatTime: formatTime,
  118. changeCup: changeCup
  119. }
  120. // function imageUtil(e) {
  121. // var imageSize = {};
  122. // var originalWidth = e.detail.width;//图片原始宽
  123. // var originalHeight = e.detail.height;//图片原始高
  124. // var originalScale = originalHeight / originalWidth;//图片高宽比
  125. // //获取屏幕宽高
  126. // wx.getSystemInfo({
  127. // success: function (res) {
  128. // var windowWidth = res.windowWidth;
  129. // var windowHeight = res.windowHeight;
  130. // var windowscale = windowHeight / windowWidth;//屏幕高宽比
  131. // imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth;
  132. // }
  133. // })
  134. // //return imageSize;
  135. // }
  136. // module.exports = {
  137. // imageUtil: imageUtil
  138. // }
  139. // import _Promise from 'bluebird';
  140. // /**
  141. // * @param {Function} fun 接口
  142. // * @param {Object} options 接口参数
  143. // * @returns {Promise} Promise对象
  144. // */
  145. // function Promise(fun, options) {
  146. // options = options || {};
  147. // return new _Promise((resolve, reject) => {
  148. // if (typeof fun !== 'function') {
  149. // reject();
  150. // }
  151. // options.success = resolve;
  152. // options.fail = reject;
  153. // fun(options);
  154. // });
  155. // }
  156. // /**
  157. // * 手势库
  158. // */
  159. // function touchstart(e, _this) {
  160. // const t = e.touches[0],
  161. // startX = t.clientX,
  162. // startY = t.clientY;
  163. // _this.setData({
  164. // 'gesture.startX': startX,
  165. // 'gesture.startY': startY,
  166. // 'gesture.out': true
  167. // })
  168. // }
  169. // /**
  170. // * 左滑
  171. // * @returns {boolean} 布尔值
  172. // */
  173. // function isLeftSlide(e, _this) {
  174. // if (_this.data.gesture.out) {
  175. // const t = e.touches[0],
  176. // deltaX = t.clientX - _this.data.gesture.startX,
  177. // deltaY = t.clientY - _this.data.gesture.startY;
  178. // if (deltaX < -20 && deltaX > -40 && deltaY < 8 && deltaY > -8) {
  179. // _this.setData({
  180. // 'gesture.out': false
  181. // })
  182. // return true;
  183. // } else {
  184. // return false;
  185. // }
  186. // }
  187. // }
  188. // /**
  189. // * 右滑
  190. // * @returns {boolean} 布尔值
  191. // */
  192. // function isRightSlide(e, _this) {
  193. // if (_this.data.gesture.out) {
  194. // const t = e.touches[0],
  195. // deltaX = t.clientX - _this.data.gesture.startX,
  196. // deltaY = t.clientY - _this.data.gesture.startY;
  197. // if (deltaX > 20 && deltaX < 40 && deltaY < 8 && deltaY > -8) {
  198. // _this.setData({
  199. // 'gesture.out': false
  200. // })
  201. // return true;
  202. // } else {
  203. // return false;
  204. // }
  205. // }
  206. // }
  207. // module.exports = {
  208. // Promise: Promise,
  209. // Gesture: {
  210. // touchstart: touchstart,
  211. // isLeftSlide: isLeftSlide,
  212. // isRightSlide: isRightSlide
  213. // }
  214. // }