cnhis-design-vue 3.1.24-beta.5 → 3.1.24-beta.6
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.
|
@@ -7,6 +7,7 @@ import { NDatePicker } from 'naive-ui';
|
|
|
7
7
|
import { useCommonInjection } from '../../hooks/useCommonInjection.js';
|
|
8
8
|
import '../../utils/index.js';
|
|
9
9
|
import { assignUpdateValue, assignClearBindVisited } from '../../utils/schema.js';
|
|
10
|
+
import { businessDateParser } from '../../utils/business.js';
|
|
10
11
|
|
|
11
12
|
const script = defineComponent({
|
|
12
13
|
props: {
|
|
@@ -110,6 +111,39 @@ const script = defineComponent({
|
|
|
110
111
|
return value;
|
|
111
112
|
return format(new Date(value), props.valueFormat);
|
|
112
113
|
}
|
|
114
|
+
let prevInputContent = "";
|
|
115
|
+
function onKeydown(evt) {
|
|
116
|
+
if (evt.key !== "Enter") {
|
|
117
|
+
prevInputContent = evt.target.value + evt.key;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const result = businessDateParser(prevInputContent);
|
|
121
|
+
if (!result)
|
|
122
|
+
return;
|
|
123
|
+
const {
|
|
124
|
+
isTimeDisabled: isTimeDisabled2,
|
|
125
|
+
isDateDisabled: isDateDisabled2
|
|
126
|
+
} = validateConfig.value;
|
|
127
|
+
if (!isValidDate(result))
|
|
128
|
+
return;
|
|
129
|
+
valueRef.value = format(result, props.valueFormat);
|
|
130
|
+
function isValidDate(date) {
|
|
131
|
+
const dateDisabled = !isDateDisabled2 || isDateDisabled2(date.getTime());
|
|
132
|
+
if (dateDisabled)
|
|
133
|
+
return;
|
|
134
|
+
const {
|
|
135
|
+
isHourDisabled,
|
|
136
|
+
isMinuteDisabled
|
|
137
|
+
} = isTimeDisabled2 ? isTimeDisabled2(date.getTime()) : {};
|
|
138
|
+
const hourDisabled = !isHourDisabled || isHourDisabled(date.getHours());
|
|
139
|
+
if (hourDisabled)
|
|
140
|
+
return;
|
|
141
|
+
const minuteDisabled = !isMinuteDisabled || isMinuteDisabled(date.getMinutes());
|
|
142
|
+
if (minuteDisabled)
|
|
143
|
+
return;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
113
147
|
watch(() => props.value, (value) => {
|
|
114
148
|
if (!value || formatDate(value) === value)
|
|
115
149
|
return;
|
|
@@ -117,14 +151,18 @@ const script = defineComponent({
|
|
|
117
151
|
});
|
|
118
152
|
const valueRef = computed({
|
|
119
153
|
get: () => formatDate(props.value),
|
|
120
|
-
set: (value) =>
|
|
154
|
+
set: (value) => {
|
|
155
|
+
emit("update:value", value);
|
|
156
|
+
prevInputContent = "";
|
|
157
|
+
}
|
|
121
158
|
});
|
|
122
159
|
const key = injectValueBindKey(valueRef);
|
|
123
160
|
return () => createVNode(NDatePicker, mergeProps({
|
|
124
161
|
"key": key.value
|
|
125
162
|
}, validateConfig.value, formatConfig.value, {
|
|
126
163
|
"formatted-value": valueRef.value,
|
|
127
|
-
"onUpdate:formatted-value": ($event) => valueRef.value = $event
|
|
164
|
+
"onUpdate:formatted-value": ($event) => valueRef.value = $event,
|
|
165
|
+
"onKeydown": onKeydown
|
|
128
166
|
}), null);
|
|
129
167
|
}
|
|
130
168
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { differenceInDays, differenceInMonths, differenceInYears, format } from 'date-fns';
|
|
2
|
+
import { isString } from 'lodash-es';
|
|
2
3
|
import { FIELD_AGE_UNIT, FIELD_SEX_VALUE } from '../constants/index.js';
|
|
3
4
|
|
|
4
5
|
function parseIdCard(idCardNo) {
|
|
@@ -19,7 +20,7 @@ function parseIdCard(idCardNo) {
|
|
|
19
20
|
return parseInner(idCardNo, idCardNo.length == 15 ? 14 : 16, idCardNo.length == 15 ? 2 : 4);
|
|
20
21
|
}
|
|
21
22
|
function isMonthType(format2) {
|
|
22
|
-
return format2 && format2.
|
|
23
|
+
return format2 && format2.toUpperCase() === "YYYY-MM";
|
|
23
24
|
}
|
|
24
25
|
function transformDateFormat(format2 = "") {
|
|
25
26
|
if (isMonthType(format2))
|
|
@@ -74,5 +75,15 @@ function parseAge2Birthday(age, ageUnit, formatter = "yyyy-MM-dd") {
|
|
|
74
75
|
function parseAge2FromContext(context) {
|
|
75
76
|
return context.day < 30 ? { ageUnit: FIELD_AGE_UNIT.DAY, age: context.day } : context.day < 365 ? { ageUnit: FIELD_AGE_UNIT.MONTH, age: context.month } : { ageUnit: FIELD_AGE_UNIT.YEAR, age: context.year };
|
|
76
77
|
}
|
|
78
|
+
const businessDateMatcher = /^(\d{4})-?(\d{2})-?(\d{2})?\s?(\d{2})?:?(\d{2})?:?(\d{2})?$/;
|
|
79
|
+
function businessDateParser(dateString) {
|
|
80
|
+
if (!isString(dateString))
|
|
81
|
+
return;
|
|
82
|
+
const matched = dateString.match(businessDateMatcher);
|
|
83
|
+
if (!matched)
|
|
84
|
+
return;
|
|
85
|
+
const [, year, month, day, hour, minute, second] = matched;
|
|
86
|
+
return new Date(`${year}-${month}-${day || "01"} ${hour || "00"}:${minute || "00"}:${second || "00"}`);
|
|
87
|
+
}
|
|
77
88
|
|
|
78
|
-
export { isIdCard, isMobile, parseAge2Birthday, parseAge2FromContext, parseBirthday, parseIdCard, transformDateFormat };
|
|
89
|
+
export { businessDateParser, isIdCard, isMobile, parseAge2Birthday, parseAge2FromContext, parseBirthday, parseIdCard, transformDateFormat };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cnhis-design-vue",
|
|
3
|
-
"version": "3.1.24-beta.
|
|
3
|
+
"version": "3.1.24-beta.6",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"module": "./es/components/index.js",
|
|
6
6
|
"main": "./es/components/index.js",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"iOS 7",
|
|
67
67
|
"last 3 iOS versions"
|
|
68
68
|
],
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "e20944cd695f9fd8c1a267ebee989aaf4e3bd279"
|
|
70
70
|
}
|