Data.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. # 配置一些常用的数据
  4. class Data
  5. {
  6. public function getShortcuts($type)
  7. {
  8. if (strstr($type, 'range')) {
  9. return [
  10. [
  11. 'text' => '今天',
  12. 'func' => 'return [new Date(new Date().setHours(0,0,0,0)), new Date()]',
  13. ],
  14. [
  15. 'text' => '昨天',
  16. 'func' => 'const now = new Date(); const start = new Date(now.setDate(now.getDate() - 1)); start.setHours(0,0,0,0); const end = new Date(start); end.setHours(23,59,59,999); return [start, end]',
  17. ],
  18. [
  19. 'text' => '本周',
  20. 'func' => 'const now = new Date(); const day = now.getDay() || 7; const start = new Date(now); start.setDate(now.getDate() - day + 1); start.setHours(0,0,0,0); return [start, new Date()]',
  21. ],
  22. [
  23. 'text' => '上周',
  24. 'func' => 'const now = new Date(); const day = now.getDay() || 7; const end = new Date(now); end.setDate(now.getDate() - day); end.setHours(23,59,59,999); const start = new Date(end); start.setDate(end.getDate() - 6); start.setHours(0,0,0,0); return [start, end]',
  25. ],
  26. [
  27. 'text' => '本月',
  28. 'func' => 'const now = new Date(); const start = new Date(now.getFullYear(), now.getMonth(), 1); return [start, new Date()]',
  29. ],
  30. [
  31. 'text' => '上月',
  32. 'func' => 'const now = new Date(); const start = new Date(now.getFullYear(), now.getMonth() - 1, 1); const end = new Date(now.getFullYear(), now.getMonth(), 0); end.setHours(23,59,59,999); return [start, end]',
  33. ],
  34. [
  35. 'text' => '最近7天',
  36. 'func' => 'const start = new Date(); start.setDate(start.getDate() - 6); start.setHours(0,0,0,0); return [start, new Date()]',
  37. ],
  38. [
  39. 'text' => '最近30天',
  40. 'func' => 'const start = new Date(); start.setDate(start.getDate() - 29); start.setHours(0,0,0,0); return [start, new Date()]',
  41. ],
  42. [
  43. 'text' => '最近90天',
  44. 'func' => 'const start = new Date(); start.setDate(start.getDate() - 89); start.setHours(0,0,0,0); return [start, new Date()]',
  45. ],
  46. [
  47. 'text' => '最近1年',
  48. 'func' => 'const start = new Date(); start.setFullYear(start.getFullYear() - 1); start.setDate(start.getDate() + 1); start.setHours(0,0,0,0); return [start, new Date()]',
  49. ],
  50. [
  51. 'text' => '本年',
  52. 'func' => 'const now = new Date(); const start = new Date(now.getFullYear(), 0, 1); return [start, new Date()]',
  53. ],
  54. [
  55. 'text' => '去年',
  56. 'func' => 'const now = new Date(); const start = new Date(now.getFullYear() - 1, 0, 1); const end = new Date(now.getFullYear() - 1, 11, 31, 23, 59, 59, 999); return [start, end]',
  57. ],
  58. ];
  59. } else {
  60. return [
  61. // --- 过去 ---
  62. [
  63. 'text' => '今天',
  64. 'func' => 'return new Date()',
  65. ],
  66. [
  67. 'text' => '昨天',
  68. 'func' => 'const d = new Date(); d.setDate(d.getDate() - 1); return d',
  69. ],
  70. [
  71. 'text' => '前天',
  72. 'func' => 'const d = new Date(); d.setDate(d.getDate() - 2); return d',
  73. ],
  74. [
  75. 'text' => '三天前',
  76. 'func' => 'const d = new Date(); d.setDate(d.getDate() - 3); return d',
  77. ],
  78. [
  79. 'text' => '五天前',
  80. 'func' => 'const d = new Date(); d.setDate(d.getDate() - 5); return d',
  81. ],
  82. [
  83. 'text' => '一周前',
  84. 'func' => 'const d = new Date(); d.setDate(d.getDate() - 7); return d',
  85. ],
  86. [
  87. 'text' => '一个月前',
  88. 'func' => 'const d = new Date(); d.setMonth(d.getMonth() - 1); return d',
  89. ],
  90. [
  91. 'text' => '一年前',
  92. 'func' => 'const d = new Date(); d.setFullYear(d.getFullYear() - 1); return d',
  93. ],
  94. // --- 未来 ---
  95. [
  96. 'text' => '明天',
  97. 'func' => 'const d = new Date(); d.setDate(d.getDate() + 1); return d',
  98. ],
  99. [
  100. 'text' => '后天',
  101. 'func' => 'const d = new Date(); d.setDate(d.getDate() + 2); return d',
  102. ],
  103. [
  104. 'text' => '三天后',
  105. 'func' => 'const d = new Date(); d.setDate(d.getDate() + 3); return d',
  106. ],
  107. [
  108. 'text' => '五天后',
  109. 'func' => 'const d = new Date(); d.setDate(d.getDate() + 5); return d',
  110. ],
  111. [
  112. 'text' => '一周后',
  113. 'func' => 'const d = new Date(); d.setDate(d.getDate() + 7); return d',
  114. ],
  115. [
  116. 'text' => '一个月后',
  117. 'func' => 'const d = new Date(); d.setMonth(d.getMonth() + 1); return d',
  118. ],
  119. [
  120. 'text' => '一年后',
  121. 'func' => 'const d = new Date(); d.setFullYear(d.getFullYear() + 1); return d',
  122. ],
  123. ];
  124. }
  125. }
  126. }