hy-app 0.3.1 → 0.3.2
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/README.md +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +19 -20
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +52 -26
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -259
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view :class="['hy-datetime-picker', customClass]" :style="customStyle">
|
|
3
|
-
<view
|
|
3
|
+
<view
|
|
4
|
+
v-if="hasInput"
|
|
5
|
+
class="hy-datetime-picker__has-input"
|
|
6
|
+
@click="onShowByClickInput"
|
|
7
|
+
>
|
|
4
8
|
<slot name="trigger" :value="inputValue">
|
|
5
9
|
<HyInput
|
|
6
10
|
v-model="inputValue"
|
|
@@ -17,7 +21,9 @@
|
|
|
17
21
|
:placeholder="input?.placeholder || '请选择时间'"
|
|
18
22
|
:placeholderStyle="input?.placeholderStyle"
|
|
19
23
|
:placeholderClass="input?.placeholderClass"
|
|
20
|
-
:customStyle="
|
|
24
|
+
:customStyle="
|
|
25
|
+
Object.assign({ 'pointer-events': 'none' }, input?.customStyle)
|
|
26
|
+
"
|
|
21
27
|
></HyInput>
|
|
22
28
|
<view class="input-cover"></view>
|
|
23
29
|
</slot>
|
|
@@ -57,32 +63,32 @@
|
|
|
57
63
|
|
|
58
64
|
<script lang="ts">
|
|
59
65
|
export default {
|
|
60
|
-
name:
|
|
66
|
+
name: "hy-datetime-picker",
|
|
61
67
|
options: {
|
|
62
68
|
addGlobalClass: true,
|
|
63
69
|
virtualHost: true,
|
|
64
|
-
styleIsolation:
|
|
70
|
+
styleIsolation: "shared",
|
|
65
71
|
},
|
|
66
|
-
}
|
|
72
|
+
};
|
|
67
73
|
</script>
|
|
68
74
|
|
|
69
75
|
<script setup lang="ts">
|
|
70
|
-
import { computed, onMounted, ref, toRefs, watch } from
|
|
71
|
-
import type { CSSProperties, PropType } from
|
|
72
|
-
import dayjs from
|
|
73
|
-
import { error, padZero } from
|
|
74
|
-
import { DateModeEnum } from
|
|
75
|
-
import type HyInputProps from
|
|
76
|
+
import { computed, onMounted, ref, toRefs, watch } from "vue";
|
|
77
|
+
import type { CSSProperties, PropType } from "vue";
|
|
78
|
+
import dayjs from "dayjs/esm";
|
|
79
|
+
import { error, padZero } from "../../utils";
|
|
80
|
+
import { DateModeEnum } from "../../typing";
|
|
81
|
+
import type HyInputProps from "../hy-input/typing";
|
|
82
|
+
import type { IDatetimePickerEmits } from "./typing";
|
|
76
83
|
// 组件
|
|
77
|
-
import HyInput from
|
|
78
|
-
import HyPicker from
|
|
79
|
-
import { IDatetimePickerEmits } from '@/package/components/hy-datetime-picker/typing'
|
|
84
|
+
import HyInput from "../hy-input/hy-input.vue";
|
|
85
|
+
import HyPicker from "../hy-picker/hy-picker.vue";
|
|
80
86
|
|
|
81
87
|
/**
|
|
82
88
|
* 此选择器用于时间日期选择
|
|
83
89
|
* @displayName hy-datetime-picker
|
|
84
90
|
*/
|
|
85
|
-
defineOptions({})
|
|
91
|
+
defineOptions({});
|
|
86
92
|
|
|
87
93
|
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
88
94
|
const props = defineProps({
|
|
@@ -97,7 +103,7 @@ const props = defineProps({
|
|
|
97
103
|
* */
|
|
98
104
|
popupMode: {
|
|
99
105
|
type: String,
|
|
100
|
-
default:
|
|
106
|
+
default: "bottom",
|
|
101
107
|
},
|
|
102
108
|
/** 是否显示顶部的操作栏 */
|
|
103
109
|
showToolbar: {
|
|
@@ -105,7 +111,10 @@ const props = defineProps({
|
|
|
105
111
|
default: true,
|
|
106
112
|
},
|
|
107
113
|
/** 绑定值 */
|
|
108
|
-
modelValue:
|
|
114
|
+
modelValue: {
|
|
115
|
+
type: [String, Number, Date],
|
|
116
|
+
default: "",
|
|
117
|
+
},
|
|
109
118
|
/** 顶部标题 */
|
|
110
119
|
title: String,
|
|
111
120
|
/**
|
|
@@ -113,7 +122,7 @@ const props = defineProps({
|
|
|
113
122
|
* @values date,time,year-month,datetime
|
|
114
123
|
* */
|
|
115
124
|
mode: {
|
|
116
|
-
type: String
|
|
125
|
+
type: String as PropType<DateModeEnum>,
|
|
117
126
|
default: DateModeEnum.DATETIME,
|
|
118
127
|
},
|
|
119
128
|
/** 可选的最大时间 默认值为后10年 */
|
|
@@ -163,22 +172,22 @@ const props = defineProps({
|
|
|
163
172
|
/** 取消按钮的文字 */
|
|
164
173
|
cancelText: {
|
|
165
174
|
type: String,
|
|
166
|
-
default:
|
|
175
|
+
default: "取消",
|
|
167
176
|
},
|
|
168
177
|
/** 确认按钮的文字 */
|
|
169
178
|
confirmText: {
|
|
170
179
|
type: String,
|
|
171
|
-
default:
|
|
180
|
+
default: "确认",
|
|
172
181
|
},
|
|
173
182
|
/** 取消按钮的颜色 */
|
|
174
183
|
cancelColor: {
|
|
175
184
|
type: String,
|
|
176
|
-
default:
|
|
185
|
+
default: "#909193",
|
|
177
186
|
},
|
|
178
187
|
/** 确认按钮的颜色 */
|
|
179
188
|
confirmColor: {
|
|
180
189
|
type: String,
|
|
181
|
-
default:
|
|
190
|
+
default: "#3c9cff",
|
|
182
191
|
},
|
|
183
192
|
/** 每列中可见选项的数量 */
|
|
184
193
|
visibleItemCount: {
|
|
@@ -194,7 +203,7 @@ const props = defineProps({
|
|
|
194
203
|
defaultIndex: {
|
|
195
204
|
type: Array,
|
|
196
205
|
default() {
|
|
197
|
-
return []
|
|
206
|
+
return [];
|
|
198
207
|
},
|
|
199
208
|
},
|
|
200
209
|
/** 输入框是否显示边框 */
|
|
@@ -219,309 +228,302 @@ const props = defineProps({
|
|
|
219
228
|
},
|
|
220
229
|
/** 自定义外部类名 */
|
|
221
230
|
customClass: String,
|
|
222
|
-
})
|
|
223
|
-
const
|
|
224
|
-
show,
|
|
225
|
-
modelValue,
|
|
226
|
-
hasInput,
|
|
227
|
-
input,
|
|
228
|
-
formatter,
|
|
229
|
-
filter,
|
|
230
|
-
format,
|
|
231
|
-
mode,
|
|
232
|
-
closeOnClickOverlay,
|
|
233
|
-
maxDate,
|
|
234
|
-
minDate,
|
|
235
|
-
minHour,
|
|
236
|
-
maxHour,
|
|
237
|
-
minMinute,
|
|
238
|
-
maxMinute,
|
|
239
|
-
} = toRefs(props)
|
|
240
|
-
const emit = defineEmits<IDatetimePickerEmits>()
|
|
231
|
+
});
|
|
232
|
+
const emit = defineEmits<IDatetimePickerEmits>();
|
|
241
233
|
|
|
242
234
|
// 原来的日期选择器不方便,这里增加一个hasInput选项支持类似element的自带输入框的功能。
|
|
243
|
-
const inputValue = ref<string | number>(
|
|
244
|
-
const innerValue = ref<string | number>(
|
|
245
|
-
const showByClickInput = ref<boolean>(false) // 是否在hasInput模式下显示日期选择弹唱
|
|
246
|
-
const columns = ref<any[]>([])
|
|
247
|
-
const innerDefaultIndex = ref<number[]>([])
|
|
248
|
-
let innerFormatter = (type: any, value: any) => value
|
|
235
|
+
const inputValue = ref<string | number>(""); // 表单显示值
|
|
236
|
+
const innerValue = ref<string | number>(""); // 表单显示值
|
|
237
|
+
const showByClickInput = ref<boolean>(false); // 是否在hasInput模式下显示日期选择弹唱
|
|
238
|
+
const columns = ref<any[]>([]);
|
|
239
|
+
const innerDefaultIndex = ref<number[]>([]);
|
|
240
|
+
let innerFormatter = (type: any, value: any) => value;
|
|
249
241
|
const validModes = new Set([
|
|
250
242
|
DateModeEnum.TIME,
|
|
251
243
|
DateModeEnum.MONTH_DAY,
|
|
252
244
|
DateModeEnum.HOUR_MINUTE,
|
|
253
245
|
DateModeEnum.MINUTE_SECOND,
|
|
254
|
-
])
|
|
246
|
+
]);
|
|
255
247
|
|
|
256
248
|
/**
|
|
257
249
|
* @description 更新各列的值
|
|
258
250
|
* */
|
|
259
251
|
const updateColumns = () => {
|
|
260
|
-
const formatterFn = formatter
|
|
252
|
+
const formatterFn = props.formatter || innerFormatter;
|
|
261
253
|
// 获取各列的值,并且map后,对各列的具体值进行补0操作
|
|
262
254
|
columns.value = getOriginColumns().map((column) =>
|
|
263
255
|
column.values.map((value) => formatterFn(column.type, value)),
|
|
264
|
-
)
|
|
265
|
-
}
|
|
256
|
+
);
|
|
257
|
+
};
|
|
266
258
|
|
|
267
259
|
/**
|
|
268
260
|
* @description 更新各列的值,进行补0、格式化等操作
|
|
269
261
|
* */
|
|
270
262
|
const updateColumnValue = (value: string | number) => {
|
|
271
|
-
innerValue.value = value
|
|
272
|
-
updateColumns()
|
|
263
|
+
innerValue.value = value;
|
|
264
|
+
updateColumns();
|
|
273
265
|
// 延迟执行,等待u-picker组件列数据更新完后再设置选中值索引
|
|
274
266
|
setTimeout(() => {
|
|
275
|
-
updateIndexes(value)
|
|
276
|
-
}, 100)
|
|
277
|
-
}
|
|
267
|
+
updateIndexes(value);
|
|
268
|
+
}, 100);
|
|
269
|
+
};
|
|
278
270
|
|
|
279
271
|
const init = () => {
|
|
280
272
|
// 获取当前值
|
|
281
|
-
innerValue.value = correctValue(modelValue
|
|
273
|
+
innerValue.value = correctValue(props.modelValue);
|
|
282
274
|
// 更新列表
|
|
283
|
-
updateColumnValue(innerValue.value)
|
|
275
|
+
updateColumnValue(innerValue.value);
|
|
284
276
|
|
|
285
277
|
// 初始化hasInput展示
|
|
286
|
-
getInputValue(innerValue.value)
|
|
287
|
-
}
|
|
278
|
+
getInputValue(innerValue.value);
|
|
279
|
+
};
|
|
288
280
|
|
|
289
281
|
watch(
|
|
290
|
-
() => show
|
|
282
|
+
() => props.show,
|
|
291
283
|
(newValue) => {
|
|
292
284
|
if (newValue) {
|
|
293
|
-
updateColumnValue(innerValue.value)
|
|
285
|
+
updateColumnValue(innerValue.value);
|
|
294
286
|
}
|
|
295
287
|
},
|
|
296
|
-
)
|
|
288
|
+
);
|
|
297
289
|
|
|
298
290
|
watch(
|
|
299
|
-
() => modelValue
|
|
291
|
+
() => props.modelValue,
|
|
300
292
|
() => init(),
|
|
301
|
-
)
|
|
293
|
+
);
|
|
302
294
|
|
|
303
295
|
const propsChange = computed(() => {
|
|
304
296
|
return [
|
|
305
|
-
mode
|
|
306
|
-
maxDate
|
|
307
|
-
minDate
|
|
308
|
-
minHour
|
|
309
|
-
maxHour
|
|
310
|
-
minMinute
|
|
311
|
-
maxMinute
|
|
312
|
-
filter
|
|
313
|
-
]
|
|
314
|
-
})
|
|
297
|
+
props.mode,
|
|
298
|
+
props.maxDate,
|
|
299
|
+
props.minDate,
|
|
300
|
+
props.minHour,
|
|
301
|
+
props.maxHour,
|
|
302
|
+
props.minMinute,
|
|
303
|
+
props.maxMinute,
|
|
304
|
+
props.filter,
|
|
305
|
+
];
|
|
306
|
+
});
|
|
315
307
|
|
|
316
308
|
watch(
|
|
317
309
|
() => propsChange.value,
|
|
318
310
|
() => init(),
|
|
319
|
-
)
|
|
311
|
+
);
|
|
320
312
|
|
|
321
313
|
onMounted(() => {
|
|
322
|
-
init()
|
|
323
|
-
})
|
|
314
|
+
init();
|
|
315
|
+
});
|
|
324
316
|
|
|
325
317
|
const getInputValue = (newValue: string | number) => {
|
|
326
|
-
if (newValue ==
|
|
327
|
-
inputValue.value =
|
|
328
|
-
return
|
|
318
|
+
if (newValue == "" || !newValue) {
|
|
319
|
+
inputValue.value = "";
|
|
320
|
+
return;
|
|
329
321
|
}
|
|
330
|
-
if (mode
|
|
331
|
-
inputValue.value = newValue
|
|
322
|
+
if (props.mode === "time") {
|
|
323
|
+
inputValue.value = newValue;
|
|
332
324
|
} else {
|
|
333
|
-
if (format
|
|
334
|
-
inputValue.value = dayjs(newValue).format(format
|
|
325
|
+
if (props.format) {
|
|
326
|
+
inputValue.value = dayjs(newValue).format(props.format);
|
|
335
327
|
} else {
|
|
336
|
-
let format =
|
|
337
|
-
switch (mode
|
|
328
|
+
let format = "";
|
|
329
|
+
switch (props.mode) {
|
|
338
330
|
case DateModeEnum.DATE:
|
|
339
|
-
format =
|
|
340
|
-
break
|
|
331
|
+
format = "YYYY-MM-DD";
|
|
332
|
+
break;
|
|
341
333
|
case DateModeEnum.YEAR_MONTH:
|
|
342
|
-
format =
|
|
343
|
-
break
|
|
334
|
+
format = "YYYY-MM";
|
|
335
|
+
break;
|
|
344
336
|
case DateModeEnum.DATETIME:
|
|
345
|
-
format =
|
|
346
|
-
break
|
|
337
|
+
format = "YYYY-MM-DD HH:mm:ss";
|
|
338
|
+
break;
|
|
347
339
|
case DateModeEnum.MONTH_DAY:
|
|
348
|
-
format =
|
|
349
|
-
break
|
|
340
|
+
format = "MM-DD";
|
|
341
|
+
break;
|
|
350
342
|
case DateModeEnum.HOUR_MINUTE:
|
|
351
|
-
format =
|
|
352
|
-
break
|
|
343
|
+
format = "HH:mm";
|
|
344
|
+
break;
|
|
353
345
|
case DateModeEnum.MINUTE_SECOND:
|
|
354
|
-
format =
|
|
355
|
-
break
|
|
346
|
+
format = "mm:ss";
|
|
347
|
+
break;
|
|
356
348
|
default:
|
|
357
|
-
break
|
|
349
|
+
break;
|
|
358
350
|
}
|
|
359
|
-
inputValue.value = dayjs(newValue).isValid()
|
|
351
|
+
inputValue.value = dayjs(newValue).isValid()
|
|
352
|
+
? dayjs(newValue).format(format)
|
|
353
|
+
: newValue;
|
|
360
354
|
}
|
|
361
355
|
}
|
|
362
|
-
}
|
|
356
|
+
};
|
|
363
357
|
const times = (n: number, iteratee: Function) => {
|
|
364
|
-
let index = -1
|
|
365
|
-
const result = Array(n < 0 ? 0 : n)
|
|
358
|
+
let index = -1;
|
|
359
|
+
const result = Array(n < 0 ? 0 : n);
|
|
366
360
|
while (++index < n) {
|
|
367
|
-
result[index] = iteratee(index)
|
|
361
|
+
result[index] = iteratee(index);
|
|
368
362
|
}
|
|
369
|
-
return result
|
|
370
|
-
}
|
|
363
|
+
return result;
|
|
364
|
+
};
|
|
371
365
|
|
|
372
366
|
/**
|
|
373
367
|
* @description 关闭选择器
|
|
374
368
|
* */
|
|
375
369
|
const close = () => {
|
|
376
|
-
if (closeOnClickOverlay
|
|
377
|
-
if (hasInput
|
|
378
|
-
showByClickInput.value = false
|
|
370
|
+
if (props.closeOnClickOverlay) {
|
|
371
|
+
if (props.hasInput) {
|
|
372
|
+
showByClickInput.value = false;
|
|
379
373
|
}
|
|
380
|
-
emit(
|
|
374
|
+
emit("close");
|
|
381
375
|
}
|
|
382
|
-
}
|
|
376
|
+
};
|
|
383
377
|
|
|
384
378
|
/**
|
|
385
379
|
* @description 点击工具栏的取消按钮
|
|
386
380
|
* */
|
|
387
381
|
const cancel = () => {
|
|
388
|
-
if (hasInput
|
|
389
|
-
showByClickInput.value = false
|
|
382
|
+
if (props.hasInput) {
|
|
383
|
+
showByClickInput.value = false;
|
|
390
384
|
}
|
|
391
|
-
emit(
|
|
392
|
-
}
|
|
385
|
+
emit("cancel");
|
|
386
|
+
};
|
|
393
387
|
|
|
394
388
|
/**
|
|
395
389
|
* @description 点击工具栏的确定按钮
|
|
396
390
|
* */
|
|
397
391
|
const confirm = () => {
|
|
398
|
-
emit(
|
|
399
|
-
if (hasInput
|
|
400
|
-
getInputValue(innerValue.value)
|
|
401
|
-
showByClickInput.value = false
|
|
392
|
+
emit("update:modelValue", innerValue.value);
|
|
393
|
+
if (props.hasInput) {
|
|
394
|
+
getInputValue(innerValue.value);
|
|
395
|
+
showByClickInput.value = false;
|
|
402
396
|
}
|
|
403
|
-
emit(
|
|
397
|
+
emit("confirm", {
|
|
404
398
|
value: innerValue.value,
|
|
405
|
-
mode: mode
|
|
406
|
-
})
|
|
407
|
-
}
|
|
399
|
+
mode: props.mode,
|
|
400
|
+
});
|
|
401
|
+
};
|
|
408
402
|
|
|
409
403
|
/**
|
|
410
404
|
* @description 用正则截取输出值,当出现多组数字时,抛出错误
|
|
411
405
|
* */
|
|
412
406
|
const intercept = (e: any, type?: string) => {
|
|
413
|
-
let judge = e.match(/\d+/g)
|
|
407
|
+
let judge = e.match(/\d+/g);
|
|
414
408
|
//判断是否掺杂数字
|
|
415
409
|
if (judge.length > 1) {
|
|
416
|
-
error(
|
|
417
|
-
return 0
|
|
410
|
+
error("请勿在过滤或格式化函数时添加数字");
|
|
411
|
+
return 0;
|
|
418
412
|
} else if (type && judge[0].length == 4) {
|
|
419
413
|
//判断是否是年份
|
|
420
|
-
return judge[0]
|
|
414
|
+
return judge[0];
|
|
421
415
|
} else if (judge[0].length > 2) {
|
|
422
|
-
error(
|
|
423
|
-
return 0
|
|
416
|
+
error("请勿在过滤或格式化函数时添加数字");
|
|
417
|
+
return 0;
|
|
424
418
|
} else {
|
|
425
|
-
return judge[0]
|
|
419
|
+
return judge[0];
|
|
426
420
|
}
|
|
427
|
-
}
|
|
421
|
+
};
|
|
428
422
|
|
|
429
423
|
/**
|
|
430
424
|
* @description 列发生变化时触发
|
|
431
425
|
* */
|
|
432
426
|
const change = (e: any) => {
|
|
433
|
-
const { indexs, values } = e
|
|
434
|
-
let selectValue: string | number =
|
|
435
|
-
if (validModes.has(mode
|
|
427
|
+
const { indexs, values } = e;
|
|
428
|
+
let selectValue: string | number = "";
|
|
429
|
+
if (validModes.has(props.mode) && props.mode !== DateModeEnum.MONTH_DAY) {
|
|
436
430
|
// 根据value各列索引,从各列数组中,取出当前时间的选中值
|
|
437
|
-
selectValue = `${intercept(values[0][indexs[0]])}:${intercept(values[1][indexs[1]])}
|
|
438
|
-
} else if (mode
|
|
431
|
+
selectValue = `${intercept(values[0][indexs[0]])}:${intercept(values[1][indexs[1]])}`;
|
|
432
|
+
} else if (props.mode === DateModeEnum.MONTH_DAY) {
|
|
439
433
|
// 根据value各列索引,从各列数组中,取出当前时间的选中值
|
|
440
|
-
selectValue = `${intercept(values[0][indexs[0]])}-${intercept(values[1][indexs[1]])}
|
|
434
|
+
selectValue = `${intercept(values[0][indexs[0]])}-${intercept(values[1][indexs[1]])}`;
|
|
441
435
|
} else {
|
|
442
436
|
// 将选择的值转为数值,比如'03'转为数值的3,'2019'转为数值的2019
|
|
443
|
-
const year = parseInt(intercept(values[0][indexs[0]],
|
|
444
|
-
const month = parseInt(intercept(values[1][indexs[1]]))
|
|
445
|
-
let date = parseInt(values[2] ? intercept(values[2][indexs[2]]) : 1)
|
|
437
|
+
const year = parseInt(intercept(values[0][indexs[0]], "year"));
|
|
438
|
+
const month = parseInt(intercept(values[1][indexs[1]]));
|
|
439
|
+
let date = parseInt(values[2] ? intercept(values[2][indexs[2]]) : 1);
|
|
446
440
|
let hour = 0,
|
|
447
441
|
minute = 0,
|
|
448
|
-
second = 0
|
|
442
|
+
second = 0;
|
|
449
443
|
// 此月份的最大天数
|
|
450
|
-
const maxDate = dayjs(`${year}-${month}`).daysInMonth()
|
|
444
|
+
const maxDate = dayjs(`${year}-${month}`).daysInMonth();
|
|
451
445
|
// 不允许超过maxDate值
|
|
452
|
-
date = Math.min(maxDate, date)
|
|
453
|
-
if (mode
|
|
454
|
-
hour = parseInt(intercept(values[3][indexs[3]]))
|
|
455
|
-
minute = parseInt(intercept(values[4][indexs[4]]))
|
|
456
|
-
second = parseInt(intercept(values[5][indexs[5]]))
|
|
446
|
+
date = Math.min(maxDate, date);
|
|
447
|
+
if (props.mode === DateModeEnum.DATETIME) {
|
|
448
|
+
hour = parseInt(intercept(values[3][indexs[3]]));
|
|
449
|
+
minute = parseInt(intercept(values[4][indexs[4]]));
|
|
450
|
+
second = parseInt(intercept(values[5][indexs[5]]));
|
|
457
451
|
}
|
|
458
452
|
// 转为时间模式
|
|
459
|
-
selectValue = Number(new Date(year, month - 1, date, hour, minute, second))
|
|
453
|
+
selectValue = Number(new Date(year, month - 1, date, hour, minute, second));
|
|
460
454
|
}
|
|
461
455
|
// 取出准确的合法值,防止超越边界的情况
|
|
462
|
-
selectValue = correctValue(selectValue)
|
|
463
|
-
innerValue.value = selectValue
|
|
464
|
-
updateColumnValue(selectValue)
|
|
456
|
+
selectValue = correctValue(selectValue);
|
|
457
|
+
innerValue.value = selectValue;
|
|
458
|
+
updateColumnValue(selectValue);
|
|
465
459
|
// 发出change时间,value为当前选中的时间戳
|
|
466
|
-
emit(
|
|
460
|
+
emit("change", {
|
|
467
461
|
value: selectValue,
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
// #endif
|
|
472
|
-
mode: mode.value,
|
|
473
|
-
})
|
|
474
|
-
}
|
|
462
|
+
mode: props.mode,
|
|
463
|
+
});
|
|
464
|
+
};
|
|
475
465
|
|
|
476
466
|
/**
|
|
477
467
|
* @description 更新索引
|
|
478
468
|
* */
|
|
479
469
|
const updateIndexes = (value: number | string) => {
|
|
480
|
-
let values: string[] = []
|
|
481
|
-
let timeArr: string[] = []
|
|
482
|
-
const formatterFn = formatter
|
|
470
|
+
let values: string[] = [];
|
|
471
|
+
let timeArr: string[] = [];
|
|
472
|
+
const formatterFn = props.formatter || innerFormatter;
|
|
483
473
|
|
|
484
|
-
switch (mode
|
|
474
|
+
switch (props.mode) {
|
|
485
475
|
case DateModeEnum.TIME:
|
|
486
|
-
timeArr = value.toString().split(
|
|
476
|
+
timeArr = value.toString().split(":");
|
|
487
477
|
// 使用formatter格式化方法进行管道处理
|
|
488
|
-
values = [
|
|
489
|
-
|
|
478
|
+
values = [
|
|
479
|
+
formatterFn("hour", timeArr[0]),
|
|
480
|
+
formatterFn("minute", timeArr[1]),
|
|
481
|
+
];
|
|
482
|
+
break;
|
|
490
483
|
case DateModeEnum.MONTH_DAY:
|
|
491
|
-
timeArr = value.toString().split(
|
|
484
|
+
timeArr = value.toString().split("-");
|
|
492
485
|
// 使用formatter格式化方法进行管道处理
|
|
493
|
-
values = [
|
|
494
|
-
|
|
486
|
+
values = [
|
|
487
|
+
formatterFn("month", timeArr[0]),
|
|
488
|
+
formatterFn("day", timeArr[1]),
|
|
489
|
+
];
|
|
490
|
+
break;
|
|
495
491
|
case DateModeEnum.HOUR_MINUTE:
|
|
496
|
-
timeArr = value.toString().split(
|
|
492
|
+
timeArr = value.toString().split(":");
|
|
497
493
|
// 使用formatter格式化方法进行管道处理
|
|
498
|
-
values = [
|
|
499
|
-
|
|
494
|
+
values = [
|
|
495
|
+
formatterFn("hour", timeArr[0]),
|
|
496
|
+
formatterFn("minute", timeArr[1]),
|
|
497
|
+
];
|
|
498
|
+
break;
|
|
500
499
|
case DateModeEnum.MINUTE_SECOND:
|
|
501
|
-
timeArr = value.toString().split(
|
|
500
|
+
timeArr = value.toString().split(":");
|
|
502
501
|
// 使用formatter格式化方法进行管道处理
|
|
503
|
-
values = [
|
|
504
|
-
|
|
502
|
+
values = [
|
|
503
|
+
formatterFn("minute", timeArr[0]),
|
|
504
|
+
formatterFn("second", timeArr[1]),
|
|
505
|
+
];
|
|
506
|
+
break;
|
|
505
507
|
default:
|
|
506
508
|
values = [
|
|
507
|
-
formatterFn(
|
|
509
|
+
formatterFn("year", `${dayjs(value).year()}`),
|
|
508
510
|
// 月份补0
|
|
509
|
-
formatterFn(
|
|
510
|
-
]
|
|
511
|
-
if (mode
|
|
511
|
+
formatterFn("month", padZero(dayjs(value).month() + 1)),
|
|
512
|
+
];
|
|
513
|
+
if (props.mode === DateModeEnum.DATE) {
|
|
512
514
|
// date模式,需要添加天列
|
|
513
|
-
values.push(formatterFn(
|
|
515
|
+
values.push(formatterFn("day", padZero(dayjs(value).date())));
|
|
514
516
|
}
|
|
515
|
-
if (mode
|
|
517
|
+
if (props.mode === DateModeEnum.DATETIME) {
|
|
516
518
|
// 数组的push方法,可以写入多个参数
|
|
517
519
|
values.push(
|
|
518
|
-
formatterFn(
|
|
519
|
-
formatterFn(
|
|
520
|
-
formatterFn(
|
|
521
|
-
formatterFn(
|
|
522
|
-
)
|
|
520
|
+
formatterFn("day", padZero(dayjs(value).date())),
|
|
521
|
+
formatterFn("hour", padZero(dayjs(value).hour())),
|
|
522
|
+
formatterFn("minute", padZero(dayjs(value).minute())),
|
|
523
|
+
formatterFn("second", padZero(dayjs(value).second())),
|
|
524
|
+
);
|
|
523
525
|
}
|
|
524
|
-
break
|
|
526
|
+
break;
|
|
525
527
|
}
|
|
526
528
|
// 根据当前各列的所有值,从各列默认值中找到默认值在各列中的索引
|
|
527
529
|
innerDefaultIndex.value = columns.value.map((column, index) => {
|
|
@@ -529,9 +531,9 @@ const updateIndexes = (value: number | string) => {
|
|
|
529
531
|
return Math.max(
|
|
530
532
|
0,
|
|
531
533
|
column.findIndex((item: string) => item === values[index]),
|
|
532
|
-
)
|
|
533
|
-
})
|
|
534
|
-
}
|
|
534
|
+
);
|
|
535
|
+
});
|
|
536
|
+
};
|
|
535
537
|
|
|
536
538
|
/**
|
|
537
539
|
* @description 获取每列数据
|
|
@@ -540,121 +542,127 @@ const getOriginColumns = () => {
|
|
|
540
542
|
// 生成各列的值
|
|
541
543
|
return getRanges().map(({ type, range }) => {
|
|
542
544
|
let values = times(range[1] - range[0] + 1, (index: number) => {
|
|
543
|
-
let value: string | number = range[0] + index
|
|
544
|
-
value = type ===
|
|
545
|
-
return value
|
|
546
|
-
})
|
|
545
|
+
let value: string | number = range[0] + index;
|
|
546
|
+
value = type === "year" ? `${value}` : padZero(value);
|
|
547
|
+
return value;
|
|
548
|
+
});
|
|
547
549
|
// 进行过滤
|
|
548
|
-
if (filter
|
|
549
|
-
values = filter
|
|
550
|
+
if (props.filter) {
|
|
551
|
+
values = props.filter(type, values);
|
|
550
552
|
if (!values || (values && values.length == 0)) {
|
|
551
|
-
error(
|
|
553
|
+
error("日期filter结果不能为空");
|
|
552
554
|
}
|
|
553
555
|
}
|
|
554
|
-
return { type, values }
|
|
555
|
-
})
|
|
556
|
-
}
|
|
556
|
+
return { type, values };
|
|
557
|
+
});
|
|
558
|
+
};
|
|
557
559
|
|
|
558
560
|
/**
|
|
559
561
|
* @description 得出合法的时间
|
|
560
562
|
* */
|
|
561
563
|
const correctValue = (value: number | string | Date): string | number => {
|
|
562
|
-
const isDateMode = mode
|
|
564
|
+
const isDateMode = props.mode !== DateModeEnum.TIME;
|
|
563
565
|
// if (isDateMode && !test.date(value)) {
|
|
564
566
|
if (!isDateMode && !value) {
|
|
565
567
|
// 如果是时间类型,而又没有默认值的话,就用最小时间
|
|
566
|
-
value = `${padZero(minHour
|
|
568
|
+
value = `${padZero(props.minHour)}:${padZero(props.minMinute)}`;
|
|
567
569
|
}
|
|
568
570
|
// 时间类型
|
|
569
|
-
if (validModes.has(mode
|
|
570
|
-
return value as string
|
|
571
|
+
if (validModes.has(props.mode)) {
|
|
572
|
+
return value as string;
|
|
571
573
|
} else {
|
|
572
574
|
// 如果是日期格式,控制在最小日期和最大日期之间
|
|
573
|
-
value = dayjs(value).isBefore(dayjs(minDate
|
|
574
|
-
value = dayjs(value).isAfter(dayjs(maxDate
|
|
575
|
-
return value as string | number
|
|
575
|
+
value = dayjs(value).isBefore(dayjs(props.minDate)) ? props.minDate : value;
|
|
576
|
+
value = dayjs(value).isAfter(dayjs(props.maxDate)) ? props.maxDate : value;
|
|
577
|
+
return value as string | number;
|
|
576
578
|
}
|
|
577
|
-
}
|
|
579
|
+
};
|
|
578
580
|
/**
|
|
579
581
|
* @description 获取每列的最大和最小值
|
|
580
582
|
* */
|
|
581
583
|
const getRanges = () => {
|
|
582
|
-
if (mode
|
|
584
|
+
if (props.mode === DateModeEnum.TIME) {
|
|
583
585
|
return [
|
|
584
586
|
{
|
|
585
|
-
type:
|
|
587
|
+
type: "hour",
|
|
586
588
|
range: [props.minHour, props.maxHour],
|
|
587
589
|
},
|
|
588
590
|
{
|
|
589
|
-
type:
|
|
591
|
+
type: "minute",
|
|
590
592
|
range: [props.minMinute, props.maxMinute],
|
|
591
593
|
},
|
|
592
|
-
]
|
|
594
|
+
];
|
|
593
595
|
}
|
|
594
|
-
const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = getBoundary(
|
|
595
|
-
|
|
596
|
+
const { maxYear, maxDate, maxMonth, maxHour, maxMinute } = getBoundary(
|
|
597
|
+
"max",
|
|
598
|
+
innerValue.value,
|
|
599
|
+
);
|
|
600
|
+
const { minYear, minDate, minMonth, minHour, minMinute } = getBoundary(
|
|
601
|
+
"min",
|
|
602
|
+
innerValue.value,
|
|
603
|
+
);
|
|
596
604
|
const result = [
|
|
597
605
|
{
|
|
598
|
-
type:
|
|
606
|
+
type: "year",
|
|
599
607
|
range: [minYear, maxYear],
|
|
600
608
|
},
|
|
601
609
|
{
|
|
602
|
-
type:
|
|
610
|
+
type: "month",
|
|
603
611
|
range: [minMonth, maxMonth],
|
|
604
612
|
},
|
|
605
613
|
{
|
|
606
|
-
type:
|
|
614
|
+
type: "day",
|
|
607
615
|
range: [minDate, maxDate],
|
|
608
616
|
},
|
|
609
617
|
{
|
|
610
|
-
type:
|
|
618
|
+
type: "hour",
|
|
611
619
|
range: [minHour, maxHour],
|
|
612
620
|
},
|
|
613
621
|
{
|
|
614
|
-
type:
|
|
622
|
+
type: "minute",
|
|
615
623
|
range: [minMinute, maxMinute],
|
|
616
624
|
},
|
|
617
625
|
{
|
|
618
|
-
type:
|
|
626
|
+
type: "second",
|
|
619
627
|
range: [minMinute, maxMinute],
|
|
620
628
|
},
|
|
621
|
-
]
|
|
622
|
-
let arr = result
|
|
629
|
+
];
|
|
630
|
+
let arr = result;
|
|
623
631
|
// 截取对应的列数
|
|
624
|
-
if (mode
|
|
625
|
-
if (mode
|
|
626
|
-
if (mode
|
|
627
|
-
if (mode
|
|
628
|
-
if (mode
|
|
629
|
-
return arr
|
|
630
|
-
}
|
|
632
|
+
if (props.mode === DateModeEnum.DATE) arr = result.splice(0, 3);
|
|
633
|
+
if (props.mode === DateModeEnum.YEAR_MONTH) arr = result.splice(0, 2);
|
|
634
|
+
if (props.mode === DateModeEnum.MONTH_DAY) arr = result.splice(1, 2);
|
|
635
|
+
if (props.mode === DateModeEnum.HOUR_MINUTE) arr = result.splice(3, 2);
|
|
636
|
+
if (props.mode === DateModeEnum.MINUTE_SECOND) arr = result.splice(4, 2);
|
|
637
|
+
return arr;
|
|
638
|
+
};
|
|
631
639
|
/**
|
|
632
640
|
* @description 根据minDate、maxDate、minHour、maxHour等边界值,判断各列的开始和结束边界值
|
|
633
641
|
* */
|
|
634
642
|
const getBoundary = (type: string, innerVal: string | number) => {
|
|
635
|
-
const value = new Date(innerVal)
|
|
636
|
-
const boundary = new Date((props as any)[`${type}Date`])
|
|
637
|
-
const year = dayjs(boundary).year()
|
|
638
|
-
let month = 1
|
|
639
|
-
let date = 1
|
|
640
|
-
let hour = 0
|
|
641
|
-
let minute = 0
|
|
642
|
-
if (type ===
|
|
643
|
-
month = 12
|
|
643
|
+
const value = new Date(innerVal);
|
|
644
|
+
const boundary = new Date((props as any)[`${type}Date`]);
|
|
645
|
+
const year = dayjs(boundary).year();
|
|
646
|
+
let month = 1;
|
|
647
|
+
let date = 1;
|
|
648
|
+
let hour = 0;
|
|
649
|
+
let minute = 0;
|
|
650
|
+
if (type === "max") {
|
|
651
|
+
month = 12;
|
|
644
652
|
// 月份的天数
|
|
645
|
-
date = dayjs(value).daysInMonth() || 31
|
|
646
|
-
hour = 23
|
|
647
|
-
minute = 59
|
|
653
|
+
date = dayjs(value).daysInMonth() || 31;
|
|
654
|
+
hour = 23;
|
|
655
|
+
minute = 59;
|
|
648
656
|
}
|
|
649
657
|
// 获取边界值,逻辑是:当年达到了边界值(最大或最小年),就检查月允许的最大和最小值,以此类推
|
|
650
658
|
if (dayjs(value).year() === year) {
|
|
651
|
-
month = dayjs(boundary).month() + 1
|
|
659
|
+
month = dayjs(boundary).month() + 1;
|
|
652
660
|
if (dayjs(value).month() + 1 === month) {
|
|
653
|
-
date = dayjs(boundary).date()
|
|
661
|
+
date = dayjs(boundary).date();
|
|
654
662
|
if (dayjs(value).date() === date) {
|
|
655
|
-
hour = dayjs(boundary).hour()
|
|
663
|
+
hour = dayjs(boundary).hour();
|
|
656
664
|
if (dayjs(value).hour() === hour) {
|
|
657
|
-
minute = dayjs(boundary).minute()
|
|
665
|
+
minute = dayjs(boundary).minute();
|
|
658
666
|
}
|
|
659
667
|
}
|
|
660
668
|
}
|
|
@@ -665,15 +673,15 @@ const getBoundary = (type: string, innerVal: string | number) => {
|
|
|
665
673
|
[`${type}Date`]: date,
|
|
666
674
|
[`${type}Hour`]: hour,
|
|
667
675
|
[`${type}Minute`]: minute,
|
|
668
|
-
}
|
|
669
|
-
}
|
|
676
|
+
};
|
|
677
|
+
};
|
|
670
678
|
const onShowByClickInput = () => {
|
|
671
|
-
if (!input
|
|
672
|
-
showByClickInput.value = !showByClickInput.value
|
|
679
|
+
if (!props.input?.disabled) {
|
|
680
|
+
showByClickInput.value = !showByClickInput.value;
|
|
673
681
|
}
|
|
674
|
-
}
|
|
682
|
+
};
|
|
675
683
|
</script>
|
|
676
684
|
|
|
677
685
|
<style lang="scss" scoped>
|
|
678
|
-
@import
|
|
686
|
+
@import "./index.scss";
|
|
679
687
|
</style>
|