|
|
@ -5,6 +5,9 @@ |
|
|
<template slot="prepend" v-if="prepend"> |
|
|
<template slot="prepend" v-if="prepend"> |
|
|
{{ prepend }} |
|
|
{{ prepend }} |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
<template slot="append" v-if="append"> |
|
|
|
|
|
{{ append }} |
|
|
|
|
|
</template> |
|
|
</el-input> |
|
|
</el-input> |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
@ -32,6 +35,10 @@ export default { |
|
|
type: String, |
|
|
type: String, |
|
|
default: '' |
|
|
default: '' |
|
|
}, |
|
|
}, |
|
|
|
|
|
append: { |
|
|
|
|
|
type: String, |
|
|
|
|
|
default: '' |
|
|
|
|
|
}, |
|
|
}, |
|
|
}, |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
@ -108,7 +115,7 @@ export default { |
|
|
this.isNA = false; |
|
|
this.isNA = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否匹配特殊模式(NA或FRACTION) |
|
|
// 检查是否匹配特殊模式(NA或FRACTION) |
|
|
// 优先检查完整的NA模式 |
|
|
// 优先检查完整的NA模式 |
|
|
if (/^NA$/i.test(upperVal)) { |
|
|
if (/^NA$/i.test(upperVal)) { |
|
|
@ -123,7 +130,7 @@ export default { |
|
|
// 检查FRACTION模式 |
|
|
// 检查FRACTION模式 |
|
|
matchedRule = this.getMatchingRule(val); |
|
|
matchedRule = this.getMatchingRule(val); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (matchedRule) { |
|
|
if (matchedRule) { |
|
|
if (matchedRule.name === 'FRACTION') { |
|
|
if (matchedRule.name === 'FRACTION') { |
|
|
cleaned = val.replace(/[^\d/]/g, ''); |
|
|
cleaned = val.replace(/[^\d/]/g, ''); |
|
|
@ -141,10 +148,10 @@ export default { |
|
|
} else { |
|
|
} else { |
|
|
// 处理数字和小数点输入 |
|
|
// 处理数字和小数点输入 |
|
|
// 当 decimalDigits 为 0 时,不允许输入小数点 |
|
|
// 当 decimalDigits 为 0 时,不允许输入小数点 |
|
|
const allowedPattern = this.decimalDigits === 0 ? /[^\d-]/g : /[^\d.-]/g; |
|
|
|
|
|
|
|
|
// 禁止输入负数符号 |
|
|
|
|
|
const allowedPattern = this.decimalDigits === 0 ? /[^\d]/g : /[^\d.]/g; |
|
|
cleaned = val |
|
|
cleaned = val |
|
|
.replace(allowedPattern, '') |
|
|
|
|
|
.replace(/^(-)\1+/, '$1'); |
|
|
|
|
|
|
|
|
.replace(allowedPattern, ''); |
|
|
|
|
|
|
|
|
// 确保只有一个小数点 |
|
|
// 确保只有一个小数点 |
|
|
const firstDotIndex = cleaned.indexOf('.'); |
|
|
const firstDotIndex = cleaned.indexOf('.'); |
|
|
@ -166,28 +173,26 @@ export default { |
|
|
// 处理以小数点开头的情况(仅当允许小数时) |
|
|
// 处理以小数点开头的情况(仅当允许小数时) |
|
|
if (this.decimalDigits > 0) { |
|
|
if (this.decimalDigits > 0) { |
|
|
if (cleaned === '.') cleaned = '0.'; |
|
|
if (cleaned === '.') cleaned = '0.'; |
|
|
else if (cleaned === '-.') cleaned = '-0.'; |
|
|
|
|
|
else if (cleaned.startsWith('.')) cleaned = '0' + cleaned; |
|
|
else if (cleaned.startsWith('.')) cleaned = '0' + cleaned; |
|
|
else if (cleaned.startsWith('-.')) cleaned = '-0.' + cleaned.slice(2); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 处理整数部分的前导零 |
|
|
// 处理整数部分的前导零 |
|
|
if (cleaned.includes('.')) { |
|
|
if (cleaned.includes('.')) { |
|
|
const [int, dec] = cleaned.split('.'); |
|
|
const [int, dec] = cleaned.split('.'); |
|
|
let newInt = int; |
|
|
let newInt = int; |
|
|
if (/^-?0+\d/.test(int)) { |
|
|
|
|
|
newInt = int.replace(/^-?0+(\d)/, '$1'); |
|
|
|
|
|
} else if (int === '' || int === '-') { |
|
|
|
|
|
newInt = int + '0'; |
|
|
|
|
|
} else if (int === '00' || /^-00+$/.test(int)) { |
|
|
|
|
|
newInt = int.startsWith('-') ? '-0' : '0'; |
|
|
|
|
|
|
|
|
if (/^0+\d/.test(int)) { |
|
|
|
|
|
newInt = int.replace(/^0+(\d)/, '$1'); |
|
|
|
|
|
} else if (int === '') { |
|
|
|
|
|
newInt = '0'; |
|
|
|
|
|
} else if (int === '00' || /^00+$/.test(int)) { |
|
|
|
|
|
newInt = '0'; |
|
|
} |
|
|
} |
|
|
cleaned = newInt + '.' + dec; |
|
|
cleaned = newInt + '.' + dec; |
|
|
} else { |
|
|
} else { |
|
|
if (/^-?0+\d/.test(cleaned)) { |
|
|
|
|
|
cleaned = cleaned.replace(/^-?0+(\d)/, '$1'); |
|
|
|
|
|
} else if (cleaned === '00' || /^-00+$/.test(cleaned)) { |
|
|
|
|
|
cleaned = cleaned.startsWith('-') ? '-0' : '0'; |
|
|
|
|
|
|
|
|
if (/^0+\d/.test(cleaned)) { |
|
|
|
|
|
cleaned = cleaned.replace(/^0+(\d)/, '$1'); |
|
|
|
|
|
} else if (cleaned === '00' || /^00+$/.test(cleaned)) { |
|
|
|
|
|
cleaned = '0'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -218,7 +223,7 @@ export default { |
|
|
const actVal = val || this.internalValue; |
|
|
const actVal = val || this.internalValue; |
|
|
let finalValue = actVal.trim(); |
|
|
let finalValue = actVal.trim(); |
|
|
|
|
|
|
|
|
if (finalValue === '' || finalValue === '-') { |
|
|
|
|
|
|
|
|
if (finalValue === '') { |
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -242,7 +247,7 @@ export default { |
|
|
|
|
|
|
|
|
handleBlur() { |
|
|
handleBlur() { |
|
|
const val = this.internalValue.trim(); |
|
|
const val = this.internalValue.trim(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (val === '') { |
|
|
if (val === '') { |
|
|
this.oldValue = null; |
|
|
this.oldValue = null; |
|
|
this.oldPattern = null; |
|
|
this.oldPattern = null; |
|
|
@ -253,7 +258,7 @@ export default { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const upperVal = val.toUpperCase(); |
|
|
const upperVal = val.toUpperCase(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否匹配特殊模式 |
|
|
// 检查是否匹配特殊模式 |
|
|
for (const rule of this.patternRules) { |
|
|
for (const rule of this.patternRules) { |
|
|
if (rule.pattern.test(upperVal)) { |
|
|
if (rule.pattern.test(upperVal)) { |
|
|
@ -271,7 +276,7 @@ export default { |
|
|
if (val.includes('/')) { |
|
|
if (val.includes('/')) { |
|
|
const parts = val.split('/'); |
|
|
const parts = val.split('/'); |
|
|
const validParts = parts.filter(part => part !== ''); |
|
|
const validParts = parts.filter(part => part !== ''); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (validParts.length === 0) { |
|
|
if (validParts.length === 0) { |
|
|
if (this.oldValue) { |
|
|
if (this.oldValue) { |
|
|
this.internalValue = this.oldValue; |
|
|
this.internalValue = this.oldValue; |
|
|
@ -284,7 +289,7 @@ export default { |
|
|
} |
|
|
} |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (validParts.length === 1) { |
|
|
if (validParts.length === 1) { |
|
|
const result = validParts[0]; |
|
|
const result = validParts[0]; |
|
|
this.oldValue = result; |
|
|
this.oldValue = result; |
|
|
@ -294,7 +299,7 @@ export default { |
|
|
this.$emit('blur', result); |
|
|
this.$emit('blur', result); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formattedValue = validParts.join('/'); |
|
|
const formattedValue = validParts.join('/'); |
|
|
this.oldValue = formattedValue; |
|
|
this.oldValue = formattedValue; |
|
|
this.oldPattern = this.patternRules.find(r => r.name === 'FRACTION'); |
|
|
this.oldPattern = this.patternRules.find(r => r.name === 'FRACTION'); |
|
|
|