widget.qw 1.0.81 → 1.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.development +10 -10
- package/.env.production +8 -8
- package/README.md +75 -75
- package/build/style.css +471 -471
- package/build/widget.qw.es.js +64 -65
- package/build/widget.qw.umd.js +64 -65
- package/index.html +17 -17
- package/package.json +47 -47
- package/src/App.vue +26 -26
- package/src/api/index.js +165 -165
- package/src/components/AuditBar.vue +396 -396
- package/src/components/BillCard.vue +164 -164
- package/src/components/CascaderPicker.vue +132 -132
- package/src/components/CascaderPop.vue +371 -371
- package/src/components/CheckGroup.vue +113 -113
- package/src/components/DatetimePicker/DatetimePop.vue +342 -342
- package/src/components/DatetimePicker/index.vue +124 -124
- package/src/components/DayDropdown.vue +56 -56
- package/src/components/FilePicker.vue +169 -169
- package/src/components/Input.vue +80 -80
- package/src/components/MonthDropdown.vue +51 -51
- package/src/components/MultiPicker.vue +123 -123
- package/src/components/ObjsEditor.vue +334 -334
- package/src/components/SecretNotify.js +5 -5
- package/src/components/Sheet.vue +92 -92
- package/src/components/SingleApiPicker.vue +108 -108
- package/src/components/SinglePicker.vue +102 -102
- package/src/components/SingleUserSelector.vue +425 -425
- package/src/components/Switch.vue +64 -64
- package/src/components/TreePicker.vue +113 -113
- package/src/components/UserPicker.vue +106 -106
- package/src/components/UserProfile.vue +129 -129
- package/src/components/UsersPicker.vue +118 -118
- package/src/components/YearDropdown.vue +59 -59
- package/src/components/data_selector.vue +303 -303
- package/src/components/image_picker.vue +123 -123
- package/src/components/images_picker.vue +195 -195
- package/src/components/index.js +162 -162
- package/src/components/mult_list_selector.vue +155 -155
- package/src/components/subdepartment_selector.vue +481 -481
- package/src/components/user_selector.vue +639 -639
- package/src/components/widget/DataPop.vue +95 -95
- package/src/components/widget/TreePop.vue +88 -88
- package/src/components/widget/UserPop.vue +347 -347
- package/src/env.d.ts +8 -8
- package/src/main.js +117 -117
- package/src/router/index.ts +173 -173
- package/src/util/array_util.js +32 -32
- package/src/util/auth_util.js +72 -73
- package/src/util/bool_util.js +5 -5
- package/src/util/bus.js +1 -1
- package/src/util/cache_util.js +18 -18
- package/src/util/errer_code.js +6 -6
- package/src/util/eval_util.js +19 -19
- package/src/util/icon_util.js +36 -36
- package/src/util/image_util.js +27 -27
- package/src/util/index.js +57 -57
- package/src/util/num_util.js +70 -70
- package/src/util/obj_util.js +28 -28
- package/src/util/request.js +73 -73
- package/src/util/request_json.js +71 -71
- package/src/util/request_json_mute.js +65 -65
- package/src/util/request_upload.js +79 -79
- package/src/util/route_util.js +31 -31
- package/src/util/str_util.js +143 -143
- package/src/util/time_util.js +406 -406
- package/src/util/toast_util.js +24 -24
- package/src/util/tree_util.js +153 -153
- package/src/util/uuid_util.js +9 -9
- package/src/util/validate.js +182 -182
- package/src/util/vue_filter.js +223 -223
- package/src/views/auditbar/index.vue +78 -78
- package/src/views/billcard/index.vue +48 -48
- package/src/views/cascaderpop/index.vue +90 -90
- package/src/views/checkgroup/index.vue +35 -35
- package/src/views/dataSelector/index.vue +48 -48
- package/src/views/datetimepicker/index.vue +34 -34
- package/src/views/daydropdown/index.vue +31 -31
- package/src/views/filepicker/index.vue +32 -32
- package/src/views/imagepicker/index.vue +31 -31
- package/src/views/imagespicker/index.vue +37 -37
- package/src/views/input/index.vue +35 -35
- package/src/views/monthdropdown/index.vue +31 -31
- package/src/views/multListSelector/index.vue +61 -61
- package/src/views/multipicker/index.vue +36 -36
- package/src/views/objseditor/index.vue +277 -277
- package/src/views/productSelector/index.vue +35 -35
- package/src/views/projectpicker/index.vue +41 -41
- package/src/views/secretnotify/index.vue +27 -27
- package/src/views/sheet/index.vue +45 -45
- package/src/views/singlepicker/index.vue +35 -35
- package/src/views/subdepartmentSelector/index.vue +40 -40
- package/src/views/switch/index.vue +34 -34
- package/src/views/treepicker/index.vue +41 -41
- package/src/views/userSelector/index.vue +54 -54
- package/src/views/userSelectorNew/index.vue +45 -45
- package/src/views/userpicker/index.vue +43 -43
- package/src/views/userprofile/index.vue +30 -30
- package/src/views/userspicker/index.vue +43 -43
- package/src/views/yeardropdown/index.vue +32 -32
- package/src/vm/index.js +1 -1
- package/tsconfig.json +19 -19
- package/tsconfig.node.json +8 -8
- package/vite.config.ts +122 -122
package/src/util/time_util.js
CHANGED
|
@@ -1,407 +1,407 @@
|
|
|
1
|
-
import dayjs from "dayjs"
|
|
2
|
-
import moment from 'moment'
|
|
3
|
-
|
|
4
|
-
export function isValidDatetime(datetimeStr) {
|
|
5
|
-
let dateString = datetimeStr.substring(0, 10)
|
|
6
|
-
let [year, month, day] = dateString.split('-').map(Number);
|
|
7
|
-
month = month - 1; // 因为JavaScript中月份是从0开始计数
|
|
8
|
-
let daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
9
|
-
if (year % 4 === 0 && (year % 100!== 0 || year % 400 === 0)) {
|
|
10
|
-
daysInMonth[1] = 29; // 闰年2月有29天
|
|
11
|
-
}
|
|
12
|
-
return day <= daysInMonth[month];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function startOfToday() {
|
|
16
|
-
const d = new Date();
|
|
17
|
-
const yyyy = d.getFullYear()
|
|
18
|
-
const MM = pad0(d.getMonth() + 1)
|
|
19
|
-
const dd = pad0(d.getDate())
|
|
20
|
-
const HH = '00'
|
|
21
|
-
const mm = '00'
|
|
22
|
-
const ss = '00'
|
|
23
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function endOfToday() {
|
|
27
|
-
const d = new Date();
|
|
28
|
-
const yyyy = d.getFullYear()
|
|
29
|
-
const MM = pad0(d.getMonth() + 1)
|
|
30
|
-
const dd = pad0(d.getDate())
|
|
31
|
-
const HH = '23'
|
|
32
|
-
const mm = '59'
|
|
33
|
-
const ss = '59'
|
|
34
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function isToday(str) {
|
|
38
|
-
let t = dayjs(str)
|
|
39
|
-
let s = dayjs(startOfToday())
|
|
40
|
-
let e = dayjs(endOfToday())
|
|
41
|
-
return t >= s && t <= e
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function startOfYestoday() {
|
|
45
|
-
const d = new Date();
|
|
46
|
-
d.setTime(d.getTime() - 24 * 60 * 60 * 1000);
|
|
47
|
-
const yyyy = d.getFullYear()
|
|
48
|
-
const MM = pad0(d.getMonth() + 1)
|
|
49
|
-
const dd = pad0(d.getDate())
|
|
50
|
-
const HH = '00'
|
|
51
|
-
const mm = '00'
|
|
52
|
-
const ss = '00'
|
|
53
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function endOfYestoday() {
|
|
57
|
-
const d = new Date();
|
|
58
|
-
d.setTime(d.getTime() - 24 * 60 * 60 * 1000);
|
|
59
|
-
const yyyy = d.getFullYear()
|
|
60
|
-
const MM = pad0(d.getMonth() + 1)
|
|
61
|
-
const dd = pad0(d.getDate())
|
|
62
|
-
const HH = '24'
|
|
63
|
-
const mm = '00'
|
|
64
|
-
const ss = '00'
|
|
65
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export function startOfWeek() {
|
|
70
|
-
const now = new Date();
|
|
71
|
-
const nowTime = now.getTime();
|
|
72
|
-
const day = now.getDay();
|
|
73
|
-
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
74
|
-
|
|
75
|
-
//周一
|
|
76
|
-
const d = new Date(nowTime - (day - 1) * oneDayDuration)
|
|
77
|
-
const yyyy = d.getFullYear()
|
|
78
|
-
const MM = pad0(d.getMonth() + 1)
|
|
79
|
-
const dd = pad0(d.getDate())
|
|
80
|
-
const HH = '00'
|
|
81
|
-
const mm = '00'
|
|
82
|
-
const ss = '00'
|
|
83
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function endOfWeek() {
|
|
87
|
-
const now = new Date();
|
|
88
|
-
const nowTime = now.getTime();
|
|
89
|
-
const day = now.getDay();
|
|
90
|
-
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
91
|
-
|
|
92
|
-
//本周日
|
|
93
|
-
const d = new Date(nowTime + (7 - day) * oneDayDuration);
|
|
94
|
-
|
|
95
|
-
const yyyy = d.getFullYear()
|
|
96
|
-
const MM = pad0(d.getMonth() + 1)
|
|
97
|
-
const dd = pad0(d.getDate())
|
|
98
|
-
const HH = '24'
|
|
99
|
-
const mm = '00'
|
|
100
|
-
const ss = '00'
|
|
101
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function startOfLastWeek() {
|
|
105
|
-
const now = new Date();
|
|
106
|
-
const nowTime = now.getTime();
|
|
107
|
-
const day = now.getDay();
|
|
108
|
-
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
109
|
-
|
|
110
|
-
//上周一
|
|
111
|
-
const d = new Date(nowTime - (7 + day - 1) * oneDayDuration);
|
|
112
|
-
const yyyy = d.getFullYear()
|
|
113
|
-
const MM = pad0(d.getMonth() + 1)
|
|
114
|
-
const dd = pad0(d.getDate())
|
|
115
|
-
const HH = '00'
|
|
116
|
-
const mm = '00'
|
|
117
|
-
const ss = '00'
|
|
118
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function endOfLastWeek() {
|
|
122
|
-
const now = new Date();
|
|
123
|
-
const nowTime = now.getTime();
|
|
124
|
-
const day = now.getDay();
|
|
125
|
-
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
126
|
-
|
|
127
|
-
//上周日
|
|
128
|
-
const d = new Date(nowTime - day * oneDayDuration);
|
|
129
|
-
|
|
130
|
-
const yyyy = d.getFullYear()
|
|
131
|
-
const MM = pad0(d.getMonth() + 1)
|
|
132
|
-
const dd = pad0(d.getDate())
|
|
133
|
-
const HH = '24'
|
|
134
|
-
const mm = '00'
|
|
135
|
-
const ss = '00'
|
|
136
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function startOfMonth() {
|
|
140
|
-
const date = new Date()
|
|
141
|
-
const y = date.getFullYear()
|
|
142
|
-
const m = date.getMonth();
|
|
143
|
-
//本月1号
|
|
144
|
-
const d = new Date(y, m, 1);
|
|
145
|
-
const yyyy = d.getFullYear()
|
|
146
|
-
const MM = pad0(d.getMonth() + 1)
|
|
147
|
-
const dd = pad0(d.getDate())
|
|
148
|
-
const HH = '00'
|
|
149
|
-
const mm = '00'
|
|
150
|
-
const ss = '00'
|
|
151
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function endOfMonth() {
|
|
155
|
-
const date = new Date()
|
|
156
|
-
let y = date.getFullYear()
|
|
157
|
-
let m = date.getMonth();
|
|
158
|
-
if (m == 11) {
|
|
159
|
-
m = 1
|
|
160
|
-
y = y + 1
|
|
161
|
-
} else {
|
|
162
|
-
m = m + 1
|
|
163
|
-
}
|
|
164
|
-
//下个月第0天=本月的最后一天
|
|
165
|
-
const d = new Date(y, m, 0);
|
|
166
|
-
|
|
167
|
-
const yyyy = d.getFullYear()
|
|
168
|
-
const MM = pad0(d.getMonth() + 1)
|
|
169
|
-
const dd = pad0(d.getDate())
|
|
170
|
-
const HH = '24'
|
|
171
|
-
const mm = '00'
|
|
172
|
-
const ss = '00'
|
|
173
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
export function startOfLastMonth() {
|
|
178
|
-
const now = new Date()
|
|
179
|
-
let y = now.getFullYear()
|
|
180
|
-
let m = now.getMonth();
|
|
181
|
-
if (m == 0) {
|
|
182
|
-
y = y - 1
|
|
183
|
-
m = 11
|
|
184
|
-
} else {
|
|
185
|
-
m = m - 1
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
//上个月1号
|
|
189
|
-
const d = new Date(y, m, 1);
|
|
190
|
-
const yyyy = d.getFullYear()
|
|
191
|
-
const MM = pad0(d.getMonth() + 1)
|
|
192
|
-
const dd = pad0(d.getDate())
|
|
193
|
-
const HH = '00'
|
|
194
|
-
const mm = '00'
|
|
195
|
-
const ss = '00'
|
|
196
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export function endOfLastMonth() {
|
|
200
|
-
const now = new Date()
|
|
201
|
-
const y = now.getFullYear()
|
|
202
|
-
const m = now.getMonth();
|
|
203
|
-
|
|
204
|
-
//上个月最后一天
|
|
205
|
-
const d = new Date(y, m, 0);
|
|
206
|
-
|
|
207
|
-
const yyyy = d.getFullYear()
|
|
208
|
-
const MM = pad0(d.getMonth() + 1)
|
|
209
|
-
const dd = pad0(d.getDate())
|
|
210
|
-
const HH = '24'
|
|
211
|
-
const mm = '00'
|
|
212
|
-
const ss = '00'
|
|
213
|
-
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// 字符串转时间戳
|
|
217
|
-
export function str2timestamp(time) {
|
|
218
|
-
time = time.substring(0, 19);
|
|
219
|
-
time = time.replace(/-/g, '/');
|
|
220
|
-
return new Date(time).getTime();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function date2timestamp(date) {
|
|
224
|
-
return date.getTime();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// 日期转中文
|
|
228
|
-
// 日期转今天、明天、xx月xx日
|
|
229
|
-
export function date2Chinese(date) {
|
|
230
|
-
const today = format(new Date() + "");
|
|
231
|
-
const tomorrow = format(new Date() + "", 1);
|
|
232
|
-
const other = format(date);
|
|
233
|
-
if (today.yyyy === other.yyyy) {
|
|
234
|
-
return other.MM + '月' + other.dd + '日';
|
|
235
|
-
} else return other.yyyy + '年' + other.MM + '月' + other.dd + '日';
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// 日期转年月日
|
|
239
|
-
// 格式:yyyy-MM-dd
|
|
240
|
-
export function date2yyyyMMdd(date) {
|
|
241
|
-
const formatedDate = format(date);
|
|
242
|
-
return formatedDate.yyyy + '-' + formatedDate.MM + '-' + formatedDate.dd;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// 日期转数组
|
|
246
|
-
// 格式:[yyyy,MM,dd]
|
|
247
|
-
export function date2array(date) {
|
|
248
|
-
const formatedDate = format(date);
|
|
249
|
-
return [formatedDate.yyyy, formatedDate.MM, formatedDate.dd];
|
|
250
|
-
}
|
|
251
|
-
// 月份转数组
|
|
252
|
-
// 格式:[yyyy,MM]
|
|
253
|
-
export function month2array(date) {
|
|
254
|
-
const formatedDate = format(date);
|
|
255
|
-
return [formatedDate.yyyy, formatedDate.MM];
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// 日期转年月日
|
|
259
|
-
// 格式:yyyy-MM-dd hh:mm
|
|
260
|
-
export function date2yyyyMMddhhmm(date) {
|
|
261
|
-
const formatedDate = format(date);
|
|
262
|
-
return formatedDate.yyyy + '-' + formatedDate.MM + '-' + formatedDate.dd + ' ' + formatedDate.hh + ':' + formatedDate.mm;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// 日期转年月日
|
|
266
|
-
// 格式:yyyy-MM-dd hh:mm:ss
|
|
267
|
-
export function date2yyyyMMddhhmmss(date) {
|
|
268
|
-
const formatedDate = format(date)
|
|
269
|
-
let str = formatedDate.yyyy + '-' + formatedDate.MM + '-' + formatedDate.dd + ' ' + formatedDate.hh + ':' + formatedDate.mm + ':' + formatedDate.ss
|
|
270
|
-
return str
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// 时间转小时:分钟
|
|
274
|
-
// 格式:hh:mm
|
|
275
|
-
export function time2hhmm(time) {
|
|
276
|
-
const formatedDate = format(time);
|
|
277
|
-
return formatedDate.hh + ':' + formatedDate.mm;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// 时间转小时:分钟:秒
|
|
281
|
-
// 格式:hh:mm:ss
|
|
282
|
-
export function time2hhmmss(time) {
|
|
283
|
-
const formatedDate = format(time);
|
|
284
|
-
return formatedDate.hh + ':' + formatedDate.mm + ':' + formatedDate.ss;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// 判断是否为本月
|
|
288
|
-
export function isSameMonth(inDate) {
|
|
289
|
-
var nowDate = new Date();
|
|
290
|
-
return ((nowDate.getFullYear() == inDate.getFullYear()) && (nowDate.getMonth() == inDate.getMonth()))
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
//获取某年某月多少天
|
|
294
|
-
export const YYYYMM2max_day = (YYYY, MM)=> {
|
|
295
|
-
let year = YYYY
|
|
296
|
-
let month = MM
|
|
297
|
-
if(month == 12){
|
|
298
|
-
year = year + 1
|
|
299
|
-
month = 1
|
|
300
|
-
}else{
|
|
301
|
-
month = month + 1
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// 创建指定年份和月份的下一个月的第一天的日期对象
|
|
305
|
-
// 月份是从0 - 11,所以需要将传入的月份减1
|
|
306
|
-
let nextMonth = new Date(year, month-1, 1, 0, 0, 1)
|
|
307
|
-
// 将日期减去1天,得到指定月份的最后一天
|
|
308
|
-
let lastDayOfMonth = new Date(nextMonth.getTime() - 24*60*60)
|
|
309
|
-
|
|
310
|
-
return lastDayOfMonth.getDate();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
//日期转星期
|
|
314
|
-
export const date2week_day = (date)=> {
|
|
315
|
-
if(!date)
|
|
316
|
-
return ''
|
|
317
|
-
|
|
318
|
-
let time = date
|
|
319
|
-
if(typeof time === 'string')
|
|
320
|
-
time = new Date(moment(time))
|
|
321
|
-
|
|
322
|
-
let dayOfWeek = time.getDay()
|
|
323
|
-
let weekDays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]
|
|
324
|
-
return weekDays[dayOfWeek]
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export const time_pad0 = (date, types)=>{
|
|
328
|
-
let time = date
|
|
329
|
-
if(typeof time === 'string')
|
|
330
|
-
time = new Date(moment(time))
|
|
331
|
-
|
|
332
|
-
time = date2yyyyMMddhhmmss(time)
|
|
333
|
-
|
|
334
|
-
let res = ''
|
|
335
|
-
|
|
336
|
-
if(types.includes('year'))
|
|
337
|
-
res+=time.slice(0,4)
|
|
338
|
-
else
|
|
339
|
-
res+='0000'
|
|
340
|
-
|
|
341
|
-
if(types.includes('month'))
|
|
342
|
-
res+='-'+time.slice(5,7)
|
|
343
|
-
else
|
|
344
|
-
res+='-'+'0000'
|
|
345
|
-
|
|
346
|
-
if(types.includes('day'))
|
|
347
|
-
res+='-'+time.slice(8,10)
|
|
348
|
-
else
|
|
349
|
-
res+='-'+'00'
|
|
350
|
-
|
|
351
|
-
if(types.includes('hour'))
|
|
352
|
-
res+=' '+time.slice(11,13)
|
|
353
|
-
else
|
|
354
|
-
res+=' '+'00'
|
|
355
|
-
|
|
356
|
-
if(types.includes('minute'))
|
|
357
|
-
res+=':'+time.slice(13,15)
|
|
358
|
-
else
|
|
359
|
-
res+=':'+'00'
|
|
360
|
-
|
|
361
|
-
if(types.includes('second'))
|
|
362
|
-
res+=':'+time.slice(15,17)
|
|
363
|
-
else
|
|
364
|
-
res+=':'+'00'
|
|
365
|
-
|
|
366
|
-
return res
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
//格式化时间
|
|
370
|
-
//输入:
|
|
371
|
-
//val:待格式化时间
|
|
372
|
-
//delayDay:延期天数
|
|
373
|
-
//输出:
|
|
374
|
-
// {
|
|
375
|
-
// mmdd: MM + '月' + dd + '日',
|
|
376
|
-
// day: dd,
|
|
377
|
-
// month: MM,
|
|
378
|
-
// time: hh:mm:ss
|
|
379
|
-
// }
|
|
380
|
-
const format = (val, delayDay = 0) => {
|
|
381
|
-
typeof val === 'string' ? (val = val.replace(/-/g, '/')) : null
|
|
382
|
-
const date = val ? new Date(val) : new Date()
|
|
383
|
-
date.setDate(date.getDate() + delayDay)
|
|
384
|
-
const yyyy = date.getFullYear();
|
|
385
|
-
const MM = pad0(date.getMonth() + 1)
|
|
386
|
-
const dd = pad0(date.getDate())
|
|
387
|
-
// const time = formatTime(date.getTime());
|
|
388
|
-
const hh = pad0(date.getHours());
|
|
389
|
-
const mm = pad0(date.getMinutes());
|
|
390
|
-
const ss = pad0(date.getSeconds());
|
|
391
|
-
return {
|
|
392
|
-
yyyy,
|
|
393
|
-
MM,
|
|
394
|
-
dd,
|
|
395
|
-
hh,
|
|
396
|
-
mm,
|
|
397
|
-
ss,
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
//小于10补0
|
|
402
|
-
export const pad0 = (value) => {
|
|
403
|
-
if(null == value)
|
|
404
|
-
return '00'
|
|
405
|
-
|
|
406
|
-
return value < 10 ? '0' + value : value+''
|
|
1
|
+
import dayjs from "dayjs"
|
|
2
|
+
import moment from 'moment'
|
|
3
|
+
|
|
4
|
+
export function isValidDatetime(datetimeStr) {
|
|
5
|
+
let dateString = datetimeStr.substring(0, 10)
|
|
6
|
+
let [year, month, day] = dateString.split('-').map(Number);
|
|
7
|
+
month = month - 1; // 因为JavaScript中月份是从0开始计数
|
|
8
|
+
let daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
9
|
+
if (year % 4 === 0 && (year % 100!== 0 || year % 400 === 0)) {
|
|
10
|
+
daysInMonth[1] = 29; // 闰年2月有29天
|
|
11
|
+
}
|
|
12
|
+
return day <= daysInMonth[month];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function startOfToday() {
|
|
16
|
+
const d = new Date();
|
|
17
|
+
const yyyy = d.getFullYear()
|
|
18
|
+
const MM = pad0(d.getMonth() + 1)
|
|
19
|
+
const dd = pad0(d.getDate())
|
|
20
|
+
const HH = '00'
|
|
21
|
+
const mm = '00'
|
|
22
|
+
const ss = '00'
|
|
23
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function endOfToday() {
|
|
27
|
+
const d = new Date();
|
|
28
|
+
const yyyy = d.getFullYear()
|
|
29
|
+
const MM = pad0(d.getMonth() + 1)
|
|
30
|
+
const dd = pad0(d.getDate())
|
|
31
|
+
const HH = '23'
|
|
32
|
+
const mm = '59'
|
|
33
|
+
const ss = '59'
|
|
34
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function isToday(str) {
|
|
38
|
+
let t = dayjs(str)
|
|
39
|
+
let s = dayjs(startOfToday())
|
|
40
|
+
let e = dayjs(endOfToday())
|
|
41
|
+
return t >= s && t <= e
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function startOfYestoday() {
|
|
45
|
+
const d = new Date();
|
|
46
|
+
d.setTime(d.getTime() - 24 * 60 * 60 * 1000);
|
|
47
|
+
const yyyy = d.getFullYear()
|
|
48
|
+
const MM = pad0(d.getMonth() + 1)
|
|
49
|
+
const dd = pad0(d.getDate())
|
|
50
|
+
const HH = '00'
|
|
51
|
+
const mm = '00'
|
|
52
|
+
const ss = '00'
|
|
53
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function endOfYestoday() {
|
|
57
|
+
const d = new Date();
|
|
58
|
+
d.setTime(d.getTime() - 24 * 60 * 60 * 1000);
|
|
59
|
+
const yyyy = d.getFullYear()
|
|
60
|
+
const MM = pad0(d.getMonth() + 1)
|
|
61
|
+
const dd = pad0(d.getDate())
|
|
62
|
+
const HH = '24'
|
|
63
|
+
const mm = '00'
|
|
64
|
+
const ss = '00'
|
|
65
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export function startOfWeek() {
|
|
70
|
+
const now = new Date();
|
|
71
|
+
const nowTime = now.getTime();
|
|
72
|
+
const day = now.getDay();
|
|
73
|
+
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
74
|
+
|
|
75
|
+
//周一
|
|
76
|
+
const d = new Date(nowTime - (day - 1) * oneDayDuration)
|
|
77
|
+
const yyyy = d.getFullYear()
|
|
78
|
+
const MM = pad0(d.getMonth() + 1)
|
|
79
|
+
const dd = pad0(d.getDate())
|
|
80
|
+
const HH = '00'
|
|
81
|
+
const mm = '00'
|
|
82
|
+
const ss = '00'
|
|
83
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function endOfWeek() {
|
|
87
|
+
const now = new Date();
|
|
88
|
+
const nowTime = now.getTime();
|
|
89
|
+
const day = now.getDay();
|
|
90
|
+
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
91
|
+
|
|
92
|
+
//本周日
|
|
93
|
+
const d = new Date(nowTime + (7 - day) * oneDayDuration);
|
|
94
|
+
|
|
95
|
+
const yyyy = d.getFullYear()
|
|
96
|
+
const MM = pad0(d.getMonth() + 1)
|
|
97
|
+
const dd = pad0(d.getDate())
|
|
98
|
+
const HH = '24'
|
|
99
|
+
const mm = '00'
|
|
100
|
+
const ss = '00'
|
|
101
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function startOfLastWeek() {
|
|
105
|
+
const now = new Date();
|
|
106
|
+
const nowTime = now.getTime();
|
|
107
|
+
const day = now.getDay();
|
|
108
|
+
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
109
|
+
|
|
110
|
+
//上周一
|
|
111
|
+
const d = new Date(nowTime - (7 + day - 1) * oneDayDuration);
|
|
112
|
+
const yyyy = d.getFullYear()
|
|
113
|
+
const MM = pad0(d.getMonth() + 1)
|
|
114
|
+
const dd = pad0(d.getDate())
|
|
115
|
+
const HH = '00'
|
|
116
|
+
const mm = '00'
|
|
117
|
+
const ss = '00'
|
|
118
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function endOfLastWeek() {
|
|
122
|
+
const now = new Date();
|
|
123
|
+
const nowTime = now.getTime();
|
|
124
|
+
const day = now.getDay();
|
|
125
|
+
const oneDayDuration = 24 * 60 * 60 * 1000;
|
|
126
|
+
|
|
127
|
+
//上周日
|
|
128
|
+
const d = new Date(nowTime - day * oneDayDuration);
|
|
129
|
+
|
|
130
|
+
const yyyy = d.getFullYear()
|
|
131
|
+
const MM = pad0(d.getMonth() + 1)
|
|
132
|
+
const dd = pad0(d.getDate())
|
|
133
|
+
const HH = '24'
|
|
134
|
+
const mm = '00'
|
|
135
|
+
const ss = '00'
|
|
136
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function startOfMonth() {
|
|
140
|
+
const date = new Date()
|
|
141
|
+
const y = date.getFullYear()
|
|
142
|
+
const m = date.getMonth();
|
|
143
|
+
//本月1号
|
|
144
|
+
const d = new Date(y, m, 1);
|
|
145
|
+
const yyyy = d.getFullYear()
|
|
146
|
+
const MM = pad0(d.getMonth() + 1)
|
|
147
|
+
const dd = pad0(d.getDate())
|
|
148
|
+
const HH = '00'
|
|
149
|
+
const mm = '00'
|
|
150
|
+
const ss = '00'
|
|
151
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function endOfMonth() {
|
|
155
|
+
const date = new Date()
|
|
156
|
+
let y = date.getFullYear()
|
|
157
|
+
let m = date.getMonth();
|
|
158
|
+
if (m == 11) {
|
|
159
|
+
m = 1
|
|
160
|
+
y = y + 1
|
|
161
|
+
} else {
|
|
162
|
+
m = m + 1
|
|
163
|
+
}
|
|
164
|
+
//下个月第0天=本月的最后一天
|
|
165
|
+
const d = new Date(y, m, 0);
|
|
166
|
+
|
|
167
|
+
const yyyy = d.getFullYear()
|
|
168
|
+
const MM = pad0(d.getMonth() + 1)
|
|
169
|
+
const dd = pad0(d.getDate())
|
|
170
|
+
const HH = '24'
|
|
171
|
+
const mm = '00'
|
|
172
|
+
const ss = '00'
|
|
173
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
export function startOfLastMonth() {
|
|
178
|
+
const now = new Date()
|
|
179
|
+
let y = now.getFullYear()
|
|
180
|
+
let m = now.getMonth();
|
|
181
|
+
if (m == 0) {
|
|
182
|
+
y = y - 1
|
|
183
|
+
m = 11
|
|
184
|
+
} else {
|
|
185
|
+
m = m - 1
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
//上个月1号
|
|
189
|
+
const d = new Date(y, m, 1);
|
|
190
|
+
const yyyy = d.getFullYear()
|
|
191
|
+
const MM = pad0(d.getMonth() + 1)
|
|
192
|
+
const dd = pad0(d.getDate())
|
|
193
|
+
const HH = '00'
|
|
194
|
+
const mm = '00'
|
|
195
|
+
const ss = '00'
|
|
196
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function endOfLastMonth() {
|
|
200
|
+
const now = new Date()
|
|
201
|
+
const y = now.getFullYear()
|
|
202
|
+
const m = now.getMonth();
|
|
203
|
+
|
|
204
|
+
//上个月最后一天
|
|
205
|
+
const d = new Date(y, m, 0);
|
|
206
|
+
|
|
207
|
+
const yyyy = d.getFullYear()
|
|
208
|
+
const MM = pad0(d.getMonth() + 1)
|
|
209
|
+
const dd = pad0(d.getDate())
|
|
210
|
+
const HH = '24'
|
|
211
|
+
const mm = '00'
|
|
212
|
+
const ss = '00'
|
|
213
|
+
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 字符串转时间戳
|
|
217
|
+
export function str2timestamp(time) {
|
|
218
|
+
time = time.substring(0, 19);
|
|
219
|
+
time = time.replace(/-/g, '/');
|
|
220
|
+
return new Date(time).getTime();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function date2timestamp(date) {
|
|
224
|
+
return date.getTime();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 日期转中文
|
|
228
|
+
// 日期转今天、明天、xx月xx日
|
|
229
|
+
export function date2Chinese(date) {
|
|
230
|
+
const today = format(new Date() + "");
|
|
231
|
+
const tomorrow = format(new Date() + "", 1);
|
|
232
|
+
const other = format(date);
|
|
233
|
+
if (today.yyyy === other.yyyy) {
|
|
234
|
+
return other.MM + '月' + other.dd + '日';
|
|
235
|
+
} else return other.yyyy + '年' + other.MM + '月' + other.dd + '日';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 日期转年月日
|
|
239
|
+
// 格式:yyyy-MM-dd
|
|
240
|
+
export function date2yyyyMMdd(date) {
|
|
241
|
+
const formatedDate = format(date);
|
|
242
|
+
return formatedDate.yyyy + '-' + formatedDate.MM + '-' + formatedDate.dd;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 日期转数组
|
|
246
|
+
// 格式:[yyyy,MM,dd]
|
|
247
|
+
export function date2array(date) {
|
|
248
|
+
const formatedDate = format(date);
|
|
249
|
+
return [formatedDate.yyyy, formatedDate.MM, formatedDate.dd];
|
|
250
|
+
}
|
|
251
|
+
// 月份转数组
|
|
252
|
+
// 格式:[yyyy,MM]
|
|
253
|
+
export function month2array(date) {
|
|
254
|
+
const formatedDate = format(date);
|
|
255
|
+
return [formatedDate.yyyy, formatedDate.MM];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 日期转年月日
|
|
259
|
+
// 格式:yyyy-MM-dd hh:mm
|
|
260
|
+
export function date2yyyyMMddhhmm(date) {
|
|
261
|
+
const formatedDate = format(date);
|
|
262
|
+
return formatedDate.yyyy + '-' + formatedDate.MM + '-' + formatedDate.dd + ' ' + formatedDate.hh + ':' + formatedDate.mm;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 日期转年月日
|
|
266
|
+
// 格式:yyyy-MM-dd hh:mm:ss
|
|
267
|
+
export function date2yyyyMMddhhmmss(date) {
|
|
268
|
+
const formatedDate = format(date)
|
|
269
|
+
let str = formatedDate.yyyy + '-' + formatedDate.MM + '-' + formatedDate.dd + ' ' + formatedDate.hh + ':' + formatedDate.mm + ':' + formatedDate.ss
|
|
270
|
+
return str
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// 时间转小时:分钟
|
|
274
|
+
// 格式:hh:mm
|
|
275
|
+
export function time2hhmm(time) {
|
|
276
|
+
const formatedDate = format(time);
|
|
277
|
+
return formatedDate.hh + ':' + formatedDate.mm;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// 时间转小时:分钟:秒
|
|
281
|
+
// 格式:hh:mm:ss
|
|
282
|
+
export function time2hhmmss(time) {
|
|
283
|
+
const formatedDate = format(time);
|
|
284
|
+
return formatedDate.hh + ':' + formatedDate.mm + ':' + formatedDate.ss;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 判断是否为本月
|
|
288
|
+
export function isSameMonth(inDate) {
|
|
289
|
+
var nowDate = new Date();
|
|
290
|
+
return ((nowDate.getFullYear() == inDate.getFullYear()) && (nowDate.getMonth() == inDate.getMonth()))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
//获取某年某月多少天
|
|
294
|
+
export const YYYYMM2max_day = (YYYY, MM)=> {
|
|
295
|
+
let year = YYYY
|
|
296
|
+
let month = MM
|
|
297
|
+
if(month == 12){
|
|
298
|
+
year = year + 1
|
|
299
|
+
month = 1
|
|
300
|
+
}else{
|
|
301
|
+
month = month + 1
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// 创建指定年份和月份的下一个月的第一天的日期对象
|
|
305
|
+
// 月份是从0 - 11,所以需要将传入的月份减1
|
|
306
|
+
let nextMonth = new Date(year, month-1, 1, 0, 0, 1)
|
|
307
|
+
// 将日期减去1天,得到指定月份的最后一天
|
|
308
|
+
let lastDayOfMonth = new Date(nextMonth.getTime() - 24*60*60)
|
|
309
|
+
|
|
310
|
+
return lastDayOfMonth.getDate();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
//日期转星期
|
|
314
|
+
export const date2week_day = (date)=> {
|
|
315
|
+
if(!date)
|
|
316
|
+
return ''
|
|
317
|
+
|
|
318
|
+
let time = date
|
|
319
|
+
if(typeof time === 'string')
|
|
320
|
+
time = new Date(moment(time))
|
|
321
|
+
|
|
322
|
+
let dayOfWeek = time.getDay()
|
|
323
|
+
let weekDays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]
|
|
324
|
+
return weekDays[dayOfWeek]
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export const time_pad0 = (date, types)=>{
|
|
328
|
+
let time = date
|
|
329
|
+
if(typeof time === 'string')
|
|
330
|
+
time = new Date(moment(time))
|
|
331
|
+
|
|
332
|
+
time = date2yyyyMMddhhmmss(time)
|
|
333
|
+
|
|
334
|
+
let res = ''
|
|
335
|
+
|
|
336
|
+
if(types.includes('year'))
|
|
337
|
+
res+=time.slice(0,4)
|
|
338
|
+
else
|
|
339
|
+
res+='0000'
|
|
340
|
+
|
|
341
|
+
if(types.includes('month'))
|
|
342
|
+
res+='-'+time.slice(5,7)
|
|
343
|
+
else
|
|
344
|
+
res+='-'+'0000'
|
|
345
|
+
|
|
346
|
+
if(types.includes('day'))
|
|
347
|
+
res+='-'+time.slice(8,10)
|
|
348
|
+
else
|
|
349
|
+
res+='-'+'00'
|
|
350
|
+
|
|
351
|
+
if(types.includes('hour'))
|
|
352
|
+
res+=' '+time.slice(11,13)
|
|
353
|
+
else
|
|
354
|
+
res+=' '+'00'
|
|
355
|
+
|
|
356
|
+
if(types.includes('minute'))
|
|
357
|
+
res+=':'+time.slice(13,15)
|
|
358
|
+
else
|
|
359
|
+
res+=':'+'00'
|
|
360
|
+
|
|
361
|
+
if(types.includes('second'))
|
|
362
|
+
res+=':'+time.slice(15,17)
|
|
363
|
+
else
|
|
364
|
+
res+=':'+'00'
|
|
365
|
+
|
|
366
|
+
return res
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
//格式化时间
|
|
370
|
+
//输入:
|
|
371
|
+
//val:待格式化时间
|
|
372
|
+
//delayDay:延期天数
|
|
373
|
+
//输出:
|
|
374
|
+
// {
|
|
375
|
+
// mmdd: MM + '月' + dd + '日',
|
|
376
|
+
// day: dd,
|
|
377
|
+
// month: MM,
|
|
378
|
+
// time: hh:mm:ss
|
|
379
|
+
// }
|
|
380
|
+
const format = (val, delayDay = 0) => {
|
|
381
|
+
typeof val === 'string' ? (val = val.replace(/-/g, '/')) : null
|
|
382
|
+
const date = val ? new Date(val) : new Date()
|
|
383
|
+
date.setDate(date.getDate() + delayDay)
|
|
384
|
+
const yyyy = date.getFullYear();
|
|
385
|
+
const MM = pad0(date.getMonth() + 1)
|
|
386
|
+
const dd = pad0(date.getDate())
|
|
387
|
+
// const time = formatTime(date.getTime());
|
|
388
|
+
const hh = pad0(date.getHours());
|
|
389
|
+
const mm = pad0(date.getMinutes());
|
|
390
|
+
const ss = pad0(date.getSeconds());
|
|
391
|
+
return {
|
|
392
|
+
yyyy,
|
|
393
|
+
MM,
|
|
394
|
+
dd,
|
|
395
|
+
hh,
|
|
396
|
+
mm,
|
|
397
|
+
ss,
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
//小于10补0
|
|
402
|
+
export const pad0 = (value) => {
|
|
403
|
+
if(null == value)
|
|
404
|
+
return '00'
|
|
405
|
+
|
|
406
|
+
return value < 10 ? '0' + value : value+''
|
|
407
407
|
}
|