C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.5 KiB

  1. var barcode = require('./barcode');
  2. var qrcode = require('./qrcode');
  3. const formatTime = (date, fmt) => {
  4. try {
  5. if (!date) {
  6. return date;
  7. }
  8. if (typeof date == "number") {
  9. date = new Date(date);
  10. }
  11. // console.log(date);
  12. var o = {
  13. "M+": date.getMonth() + 1, //月份
  14. "d+": date.getDate(), //日
  15. "h+": date.getHours(), //小时
  16. "m+": date.getMinutes(), //分
  17. "s+": date.getSeconds(), //秒
  18. "q+": Math.floor((date.getMonth() + 3) / 3), //季度
  19. "S": date.getMilliseconds() //毫秒
  20. };
  21. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  22. for (var k in o)
  23. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  24. return fmt;
  25. } catch (error) {
  26. return date;
  27. }
  28. }
  29. const formatNumber = n => {
  30. n = n.toString()
  31. return n[1] ? n : '0' + n
  32. }
  33. function convert_length(length) {
  34. return Math.round(wx.getSystemInfoSync().windowWidth * length / 750);
  35. }
  36. function barc(id, code, width, height) {
  37. barcode.code128(wx.createCanvasContext(id), code, convert_length(width), convert_length(height))
  38. }
  39. function qrc(id, code, width, height) {
  40. qrcode.api.draw(code, {
  41. ctx: wx.createCanvasContext(id),
  42. width: convert_length(width),
  43. height: convert_length(height)
  44. })
  45. }
  46. module.exports = {
  47. formatTime: formatTime,
  48. barcode: barc,
  49. qrcode: qrc
  50. }