@aspire-ui/element-component-pro 1.0.9 → 1.0.11
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/dist/ProForm/FormattedNumberInput.vue.d.ts +13 -0
- package/dist/element-component-pro.es.js +516 -494
- package/dist/element-component-pro.es.js.map +1 -1
- package/dist/element-component-pro.umd.js +2 -2
- package/dist/element-component-pro.umd.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/utils/formattedNumber.d.ts +5 -0
- package/package.json +1 -1
- package/src/ProForm/FormattedNumberInput.vue +12 -2
- package/src/utils/formattedNumber.ts +34 -0
package/dist/index.d.ts
CHANGED
|
@@ -2594,6 +2594,10 @@ declare const _default: {
|
|
|
2594
2594
|
type: import('vue').PropType<import('.').FormattedNumberRounding>;
|
|
2595
2595
|
default: string;
|
|
2596
2596
|
};
|
|
2597
|
+
inputLimit: {
|
|
2598
|
+
type: import('vue').PropType<boolean>;
|
|
2599
|
+
default: boolean;
|
|
2600
|
+
};
|
|
2597
2601
|
}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
2598
2602
|
input: (value: unknown) => void;
|
|
2599
2603
|
}, string, Readonly<import('vue').ExtractPropTypes<{
|
|
@@ -2618,10 +2622,15 @@ declare const _default: {
|
|
|
2618
2622
|
type: import('vue').PropType<import('.').FormattedNumberRounding>;
|
|
2619
2623
|
default: string;
|
|
2620
2624
|
};
|
|
2625
|
+
inputLimit: {
|
|
2626
|
+
type: import('vue').PropType<boolean>;
|
|
2627
|
+
default: boolean;
|
|
2628
|
+
};
|
|
2621
2629
|
}>>, {
|
|
2622
2630
|
integerDigits: number;
|
|
2623
2631
|
decimalPlaces: number;
|
|
2624
2632
|
rounding: import('.').FormattedNumberRounding;
|
|
2633
|
+
inputLimit: boolean;
|
|
2625
2634
|
}>;
|
|
2626
2635
|
};
|
|
2627
2636
|
export default _default;
|
|
@@ -3,6 +3,11 @@ export type FormattedNumberRounding = 'floor' | 'ceil' | 'round';
|
|
|
3
3
|
/** 仅保留数字、至多一个小数点、可选前导负号 */
|
|
4
4
|
export declare function sanitizeNumericInput(raw: string): string;
|
|
5
5
|
export declare function stripNumberGrouping(s: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* 对已清洗的数字串按整数位、小数位截断输入长度(inputLimit 为 true 时使用)。
|
|
8
|
+
* 整数部分至多 integerDigits 位,小数部分至多 decimalPlaces 位;保留末尾仅小数点(如 `12.`)以便继续输入。
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyNumericInputDigitLimits(sanitized: string, integerDigits: number, decimalPlaces: number): string;
|
|
6
11
|
/** 按整数位数上限约束绝对值 */
|
|
7
12
|
export declare function clampByIntegerDigits(value: number, integerDigits: number, decimalPlaces: number): number;
|
|
8
13
|
export declare function roundToDecimals(value: number, decimalPlaces: number, rounding: FormattedNumberRounding): number;
|
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { ref, watch } from 'vue'
|
|
15
15
|
import type { FormattedNumberRounding } from '../utils/formattedNumber'
|
|
16
16
|
import {
|
|
17
|
+
applyNumericInputDigitLimits,
|
|
17
18
|
formatWithThousands,
|
|
18
19
|
normalizeNumericValue,
|
|
19
20
|
numberToEditString,
|
|
@@ -33,11 +34,17 @@ const props = withDefaults(
|
|
|
33
34
|
decimalPlaces?: number
|
|
34
35
|
/** 进位方式,默认四舍五入 */
|
|
35
36
|
rounding?: FormattedNumberRounding
|
|
37
|
+
/**
|
|
38
|
+
* 为 true 时在输入过程中按 integerDigits / decimalPlaces 限制可输入位数;
|
|
39
|
+
* 为 false 时仅失焦后规范化,输入阶段不截断长度。
|
|
40
|
+
*/
|
|
41
|
+
inputLimit?: boolean
|
|
36
42
|
}>(),
|
|
37
43
|
{
|
|
38
44
|
integerDigits: 5,
|
|
39
45
|
decimalPlaces: 6,
|
|
40
46
|
rounding: 'round',
|
|
47
|
+
inputLimit: true,
|
|
41
48
|
}
|
|
42
49
|
)
|
|
43
50
|
|
|
@@ -46,7 +53,7 @@ const emit = defineEmits<{ (e: 'input', value: unknown): void }>()
|
|
|
46
53
|
const focused = ref(false)
|
|
47
54
|
const displayText = ref('')
|
|
48
55
|
|
|
49
|
-
const intN = () => Math.max(0, Math.floor(props.integerDigits ??
|
|
56
|
+
const intN = () => Math.max(0, Math.floor(props.integerDigits ?? 6))
|
|
50
57
|
const decM = () => Math.max(0, Math.floor(props.decimalPlaces ?? 6))
|
|
51
58
|
|
|
52
59
|
function parseExternalToNumber(v: unknown): number | null {
|
|
@@ -84,7 +91,10 @@ function emitStoredValue(normalized: number) {
|
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
function onInput(val: string) {
|
|
87
|
-
|
|
94
|
+
let clean = sanitizeNumericInput(val)
|
|
95
|
+
if (props.inputLimit !== false) {
|
|
96
|
+
clean = applyNumericInputDigitLimits(clean, intN(), decM())
|
|
97
|
+
}
|
|
88
98
|
displayText.value = clean
|
|
89
99
|
if (clean === '' || clean === '-') return
|
|
90
100
|
const num = Number(clean)
|
|
@@ -31,6 +31,40 @@ export function stripNumberGrouping(s: string): string {
|
|
|
31
31
|
return s.replace(/,/g, '').trim()
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* 对已清洗的数字串按整数位、小数位截断输入长度(inputLimit 为 true 时使用)。
|
|
36
|
+
* 整数部分至多 integerDigits 位,小数部分至多 decimalPlaces 位;保留末尾仅小数点(如 `12.`)以便继续输入。
|
|
37
|
+
*/
|
|
38
|
+
export function applyNumericInputDigitLimits(
|
|
39
|
+
sanitized: string,
|
|
40
|
+
integerDigits: number,
|
|
41
|
+
decimalPlaces: number
|
|
42
|
+
): string {
|
|
43
|
+
if (!sanitized || sanitized === '-') return sanitized
|
|
44
|
+
const neg = sanitized[0] === '-'
|
|
45
|
+
let body = neg ? sanitized.slice(1) : sanitized
|
|
46
|
+
const dotIdx = body.indexOf('.')
|
|
47
|
+
if (dotIdx === -1) {
|
|
48
|
+
const maxInt = Math.max(0, integerDigits)
|
|
49
|
+
body = maxInt > 0 ? body.slice(0, maxInt) : body
|
|
50
|
+
return neg ? '-' + body : body
|
|
51
|
+
}
|
|
52
|
+
let intPart = body.slice(0, dotIdx)
|
|
53
|
+
if (integerDigits > 0) {
|
|
54
|
+
intPart = intPart.slice(0, integerDigits)
|
|
55
|
+
}
|
|
56
|
+
const afterDot = body.slice(dotIdx + 1)
|
|
57
|
+
const endsWithDot = afterDot === '' && body.endsWith('.')
|
|
58
|
+
if (decimalPlaces <= 0) {
|
|
59
|
+
return neg ? '-' + intPart : intPart
|
|
60
|
+
}
|
|
61
|
+
if (endsWithDot) {
|
|
62
|
+
return (neg ? '-' : '') + intPart + '.'
|
|
63
|
+
}
|
|
64
|
+
const decPart = afterDot.slice(0, decimalPlaces)
|
|
65
|
+
return (neg ? '-' : '') + intPart + '.' + decPart
|
|
66
|
+
}
|
|
67
|
+
|
|
34
68
|
function maxAbsValue(integerDigits: number, decimalPlaces: number): number {
|
|
35
69
|
const maxInt = Math.pow(10, integerDigits) - 1
|
|
36
70
|
if (decimalPlaces <= 0) return maxInt
|