shortcuts.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import moment from 'moment'
  2. import { getFormatDatetime } from "@/utils/date";
  3. export const shortcuts = [
  4. {
  5. text: '今天',
  6. value: (() => {
  7. let start = new Date()
  8. return [getFormatDatetime(start, 'YYYY-MM-DD'), getFormatDatetime(start, 'YYYY-MM-DD')]
  9. })(),
  10. },
  11. {
  12. text: '最近一周',
  13. value: (() => {
  14. const end = new Date()
  15. const start = new Date()
  16. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  17. return [start, end]
  18. })(),
  19. },
  20. {
  21. text: '最近一个月',
  22. value: (() => {
  23. const end = new Date()
  24. const start = new Date()
  25. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  26. return [start, end]
  27. })(),
  28. },
  29. {
  30. text: '最近三个月',
  31. value: (() => {
  32. const end = new Date()
  33. const start = new Date()
  34. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  35. return [start, end]
  36. })(),
  37. },
  38. ]
  39. export const clockinShortcuts = [
  40. {
  41. text: '上一个月',
  42. value: (() => {
  43. const start = moment(moment().month(moment().month() - 1).startOf('month').valueOf()).format('YYYY-MM-DD');
  44. const end = moment(moment().month(moment().month() - 1).endOf('month').valueOf()).format('YYYY-MM-DD');
  45. return [start, end]
  46. })(),
  47. },
  48. {
  49. text: '本月',
  50. value: (() => {
  51. const start = moment(moment().month(moment().month()).startOf('month').valueOf()).format('YYYY-MM-DD')
  52. const end = new Date()
  53. return [start, end]
  54. })(),
  55. },
  56. ]
  57. export const healthCardShortcuts = [
  58. {
  59. text: '最近三天',
  60. value: (() => {
  61. const end = new Date()
  62. const start = new Date()
  63. start.setTime(start.getTime() - 3600 * 1000 * 24 * 3)
  64. return [start, end]
  65. })(),
  66. },
  67. {
  68. text: '最近一周',
  69. value: (() => {
  70. const end = new Date()
  71. const start = new Date()
  72. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  73. return [start, end]
  74. })(),
  75. },
  76. {
  77. text: '最近一个月',
  78. value: (() => {
  79. const end = new Date()
  80. const start = new Date()
  81. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  82. return [start, end]
  83. })(),
  84. },
  85. ]
  86. export const maxHalfYear = [
  87. {
  88. text: '最近一个月',
  89. value: (() => {
  90. const end = new Date()
  91. const start = new Date()
  92. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  93. return [start, end]
  94. })(),
  95. },
  96. {
  97. text: '最近三个月',
  98. value: (() => {
  99. const end = new Date()
  100. const start = new Date()
  101. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  102. return [start, end]
  103. })(),
  104. },
  105. {
  106. text: '最近半年',
  107. value: (() => {
  108. const end = new Date()
  109. const start = new Date()
  110. start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
  111. return [start, end]
  112. })(),
  113. },
  114. ]
  115. export const setlShtcuts = [
  116. {
  117. text: '最近一周',
  118. value: (() => {
  119. const end = new Date()
  120. const start = new Date()
  121. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  122. return [start, end]
  123. })(),
  124. },
  125. {
  126. text: '最近半个月',
  127. value: (() => {
  128. const end = new Date()
  129. const start = new Date()
  130. start.setTime(start.getTime() - 3600 * 1000 * 24 * 15)
  131. return [start, end]
  132. })(),
  133. },
  134. {
  135. text: '最近一个月',
  136. value: (() => {
  137. const end = new Date()
  138. const start = new Date()
  139. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  140. return [start, end]
  141. })(),
  142. },
  143. ]
  144. export const seltYearAndNowLast = [
  145. {
  146. text: '第一个月',
  147. value: (() => {
  148. const now = new Date()
  149. const start = now.getFullYear() + "-01-01";
  150. const end = now.getFullYear() + "-01-31";
  151. return [start, end]
  152. })(),
  153. },
  154. {
  155. text: '上一个月',
  156. value: (() => {
  157. const nowDate = new Date()
  158. const month = nowDate.getMonth()
  159. // 如果是现在1月份,就取现在1月份的时间,否则取上一个月的时间
  160. if (month === 1) {
  161. const start = nowDate.getFullYear() + "-01-01";
  162. const end = nowDate.getFullYear() + "-01-31";
  163. return [start, end]
  164. } else {
  165. const start = moment(moment().month(moment().month() - 1).startOf('month').valueOf()).format('YYYY-MM-DD');
  166. const end = moment(moment().month(moment().month() - 1).endOf('month').valueOf()).format('YYYY-MM-DD');
  167. return [start, end]
  168. }
  169. })(),
  170. },
  171. ]
  172. export const monthShortcuts = [
  173. {
  174. text: '这个月',
  175. value: [new Date(), new Date()],
  176. },
  177. {
  178. text: '这一年',
  179. value: () => {
  180. const end = new Date()
  181. const start = new Date(new Date().getFullYear(), 0)
  182. return [start, end]
  183. },
  184. },
  185. {
  186. text: '最近半年',
  187. value: () => {
  188. const end = new Date()
  189. const start = new Date()
  190. start.setMonth(start.getMonth() - 6)
  191. return [start, end]
  192. },
  193. },
  194. ]