wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { useI18n } from '@/hooks/web/useI18n'
import dayjs from 'dayjs'
import type { ManipulateType, QUnitType } from 'dayjs'
import quarterOfYear from 'dayjs/plugin/quarterOfYear'
type ManipulateTypeWithQuarter = ManipulateType | 'quarter'
const { t } = useI18n()
dayjs.extend(quarterOfYear)
 
function getThisStart(val = 'month' as ManipulateTypeWithQuarter) {
  return new Date(dayjs().startOf(val).format('YYYY/MM/DD HH:mm:ss'))
}
 
function getThisEnd(val = 'month' as ManipulateTypeWithQuarter) {
  return new Date(dayjs().endOf(val).format('YYYY/MM/DD HH:mm:ss'))
}
 
function getLastStart(val = 'month' as ManipulateTypeWithQuarter) {
  return new Date(
    dayjs()
      .subtract(1, val as QUnitType)
      .startOf(val)
      .format('YYYY/MM/DD HH:mm:ss')
  )
}
 
function getLastEnd(val = 'month' as ManipulateTypeWithQuarter) {
  return new Date(
    dayjs()
      .subtract(1, val as QUnitType)
      .endOf(val)
      .format('YYYY/MM/DD HH:mm:ss')
  )
}
 
function getNextStart(val = 'month' as ManipulateTypeWithQuarter) {
  return new Date(
    dayjs()
      .add(1, val as QUnitType)
      .startOf(val)
      .format('YYYY/MM/DD HH:mm:ss')
  )
}
 
function getNextEnd(val = 'month' as ManipulateTypeWithQuarter) {
  return new Date(
    dayjs()
      .add(1, val as QUnitType)
      .endOf(val)
      .format('YYYY/MM/DD HH:mm:ss')
  )
}
 
// eslint-disable-next-line
let callback: Function = () => {}
const shortcuts = [
  {
    text: 'dynamic_time.cweek',
    onClick: ({ emit }) => {
      const startTime = new Date(+new Date(getThisStart('week')) + 24 * 1000 * 3600)
      const endTime = new Date(+new Date(getThisEnd('week')) + 24 * 1000 * 3600)
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'dynamic_month.current',
    onClick: ({ emit }) => {
      const startTime = getThisStart('month')
      const endTime = getThisEnd('month')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'dynamic_time.cquarter',
    onClick: ({ emit }) => {
      const startTime = getThisStart('quarter')
      const endTime = getThisEnd('quarter')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'dynamic_year.current',
    onClick: ({ emit }) => {
      const startTime = getThisStart('year')
      const endTime = getThisEnd('year')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
 
  {
    text: 'dynamic_time.lweek',
    onClick: ({ emit }) => {
      const startTime = new Date(+new Date(getLastStart('week')) + 24 * 1000 * 3600)
      const endTime = new Date(+new Date(getLastEnd('week')) + 24 * 1000 * 3600)
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'dynamic_month.last',
    onClick: ({ emit }) => {
      const startTime = getLastStart('month')
      const endTime = getLastEnd('month')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'dynamic_time.lquarter',
    onClick: ({ emit }) => {
      const startTime = getLastStart('quarter')
      const endTime = getLastEnd('quarter')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'dynamic_year.last',
    onClick: ({ emit }) => {
      const startTime = getLastStart('year')
      const endTime = getLastEnd('year')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'common.next_week',
    onClick: ({ emit }) => {
      const startTime = getNextStart('week')
      const endTime = getNextEnd('week')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'common.next_month',
    onClick: ({ emit }) => {
      const startTime = getNextStart('month')
      const endTime = getNextEnd('month')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'common.next_quarter',
    onClick: ({ emit }) => {
      const startTime = getNextStart('quarter')
      const endTime = getNextEnd('quarter')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  },
  {
    text: 'common.next_year',
    onClick: ({ emit }) => {
      const startTime = getNextStart('year')
      const endTime = getNextEnd('year')
      if (callback([startTime, endTime])) return
      emit('pick', [dayjs(startTime), dayjs(endTime)])
    }
  }
]
 
shortcuts.forEach(ele => {
  ele.text = t(ele.text)
})
 
const useShortcuts = cb => {
  callback = cb
  return {
    shortcuts
  }
}
 
export { useShortcuts }