app.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. App({
  2. onLaunch() {
  3. Object.assign(Date.prototype, {
  4. getDateName(realtime) {
  5. let td = new Date(),
  6. d = new Date(this.getFullYear(), this.getMonth(), this.getDate()),
  7. n
  8. td = new Date(td.getFullYear(), td.getMonth(), td.getDate())
  9. n = (d - td) / 1000 / 60 / 60 / 24;
  10. if (n < -2) {
  11. return -n + '天前'
  12. }
  13. if (n < -1) {
  14. return '前天'
  15. }
  16. if (n < 0) {
  17. return '昨天'
  18. }
  19. if (n == 0) {
  20. return realtime ? this.format(realtime) : '今天'
  21. }
  22. if (n < 2) {
  23. return '明天'
  24. }
  25. if (n < 3) {
  26. return '后天'
  27. }
  28. return n + '天后'
  29. },
  30. format(fmt) { //author: meizz
  31. var o = {
  32. "M+": this.getMonth() + 1, //月份
  33. "d+": this.getDate(), //日
  34. "h+": this.getHours(), //小时
  35. "m+": this.getMinutes(), //分
  36. "s+": this.getSeconds(), //秒
  37. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  38. "S": this.getMilliseconds() //毫秒
  39. };
  40. if (/(y+)/.test(fmt))
  41. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  42. for (var k in o)
  43. if (new RegExp("(" + k + ")").test(fmt))
  44. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  45. return fmt;
  46. }
  47. })
  48. },
  49. data: {
  50. nav: {}
  51. },
  52. config: {},
  53. globalData: {
  54. userInfo: null,
  55. appid: 'wx4398d60942bc7710',
  56. imgUrl: 'https://zmbx.oss-cn-shanghai.aliyuncs.com/'
  57. // imgUrl: 'http://cdn.info666.com/'
  58. // wx289928fedd0242a5 测试
  59. // wx0883711d2af54d70 正式
  60. }
  61. })