feat(input): 数字输入整数位数限制功能
- 在 fastVue.base.js 中实现整数位数配置选项 integerDigits - 添加 checkIntegerDigitsInput 函数验证整数位数输入限制 - 实现 limitIntegerDigits 函数控制数值字符串中的整数位数 - 在键盘处理和粘贴事件中集成整数位数限制逻辑 - 更新掉期交易价格精度配置支持 quantityIntegerDigits 选项 - 扩展精度辅助函数支持整数位数配置和验证规则 - 添加完整的单元测试覆盖整数位数限制功能
This commit is contained in:
@@ -2,55 +2,56 @@ var swapPricePrecision = (function (global) {
|
||||
const defaults = Object.freeze({
|
||||
common: {
|
||||
amount: { precision: 2, grouping: true },
|
||||
quantity: { precision: 2, grouping: true },
|
||||
quantity: { integerDigits: 16, precision: 2, grouping: true },
|
||||
rate: { precision: 4 }
|
||||
},
|
||||
Stock: { integerDigits: 7, precision: 2, quantityPrecision: 2 },
|
||||
StockIndex: { integerDigits: 7, precision: 2, quantityPrecision: 2 },
|
||||
StockIF: { integerDigits: 7, precision: 4, quantityPrecision: 2 },
|
||||
CommodityFutures: { integerDigits: 7, precision: 4, quantityPrecision: 2 },
|
||||
CommoditySpot: { integerDigits: 7, precision: 4, quantityPrecision: 2 },
|
||||
NewOtcStock: { integerDigits: 7, precision: 4, quantityPrecision: 2 },
|
||||
HKStock: { integerDigits: 7, precision: 4, quantityPrecision: 2 },
|
||||
HKStockIndex: { integerDigits: 7, precision: 4, quantityPrecision: 2 },
|
||||
Fund: { integerDigits: 7, precision: 4, quantityPrecision: 4 },
|
||||
Stock: { integerDigits: 7, precision: 2, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
StockIndex: { integerDigits: 7, precision: 2, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
StockIF: { integerDigits: 7, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
CommodityFutures: { integerDigits: 7, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
CommoditySpot: { integerDigits: 7, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
NewOtcStock: { integerDigits: 7, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
HKStock: { integerDigits: 7, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
HKStockIndex: { integerDigits: 7, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
Fund: { integerDigits: 7, precision: 4, quantityPrecision: 4, quantityIntegerDigits: 12 },
|
||||
Bond: {
|
||||
quantityPrecision: 0,
|
||||
quantityPrecision: 0, quantityIntegerDigits: 16,
|
||||
grossPrice: { integerDigits: 6, precision: 9 },
|
||||
netPrice: { integerDigits: 6, precision: 9 },
|
||||
yield: { integerDigits: 2, precision: 4 }
|
||||
},
|
||||
TBonds: {
|
||||
quantityPrecision: 0,
|
||||
quantityPrecision: 0, quantityIntegerDigits: 16,
|
||||
grossPrice: { integerDigits: 6, precision: 9 },
|
||||
netPrice: { integerDigits: 6, precision: 9 },
|
||||
yield: { integerDigits: 2, precision: 4 }
|
||||
},
|
||||
CreditBonds: {
|
||||
quantityPrecision: 0,
|
||||
quantityPrecision: 0, quantityIntegerDigits: 16,
|
||||
grossPrice: { integerDigits: 6, precision: 9 },
|
||||
netPrice: { integerDigits: 6, precision: 9 },
|
||||
yield: { integerDigits: 2, precision: 4 }
|
||||
},
|
||||
OtherBonds: {
|
||||
quantityPrecision: 0,
|
||||
quantityPrecision: 0, quantityIntegerDigits: 16,
|
||||
grossPrice: { integerDigits: 6, precision: 9 },
|
||||
netPrice: { integerDigits: 6, precision: 9 },
|
||||
yield: { integerDigits: 2, precision: 4 }
|
||||
},
|
||||
TBFutures: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
OtherFutures: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
GoldSpot: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
OtherSpot: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
AbroadFutures: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
AbroadSpot: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
AbroadStock: { integerDigits: 8, precision: 2, quantityPrecision: 2 },
|
||||
AbroadStockIndex: { integerDigits: 8, precision: 4, quantityPrecision: 2 },
|
||||
ExRate: { integerDigits: 2, precision: 8, quantityPrecision: 8 },
|
||||
Shibor: { integerDigits: 2, precision: 4, quantityPrecision: 2 },
|
||||
FixingRepoRate: { integerDigits: 2, precision: 4, quantityPrecision: 2 },
|
||||
RateYield: {integerDigits: 6, precision: 8, quantityPrecision: 2},
|
||||
BondIndex: {integerDigits: 6, precision: 4, quantityPrecision: 2},
|
||||
TBFutures: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
OtherFutures: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
GoldFutures: { quantityIntegerDigits: 12 },
|
||||
GoldSpot: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
OtherSpot: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
AbroadFutures: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
AbroadSpot: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
AbroadStock: { integerDigits: 8, precision: 2, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
AbroadStockIndex: { integerDigits: 8, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
ExRate: { integerDigits: 2, precision: 8, quantityPrecision: 8, quantityIntegerDigits: 16 },
|
||||
Shibor: { integerDigits: 2, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
FixingRepoRate: { integerDigits: 2, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12 },
|
||||
RateYield: {integerDigits: 6, precision: 8, quantityPrecision: 2, quantityIntegerDigits: 12},
|
||||
BondIndex: {integerDigits: 6, precision: 4, quantityPrecision: 2, quantityIntegerDigits: 12},
|
||||
|
||||
});
|
||||
|
||||
@@ -134,7 +135,12 @@ var swapPricePrecision = (function (global) {
|
||||
if (!rule || typeof rule !== 'object') return null;
|
||||
const precision = Number(rule.precision);
|
||||
if (!Number.isInteger(precision) || precision < 0 || precision > 13) return null;
|
||||
return { precision: precision, grouping: typeof rule.grouping === 'boolean' ? rule.grouping : undefined };
|
||||
const integerDigits = Number(rule.integerDigits);
|
||||
return {
|
||||
precision: precision,
|
||||
integerDigits: Number.isInteger(integerDigits) && integerDigits >= 1 && integerDigits <= 18 ? integerDigits : undefined,
|
||||
grouping: typeof rule.grouping === 'boolean' ? rule.grouping : undefined
|
||||
};
|
||||
}
|
||||
|
||||
function findRule(source, instrumentType, field) {
|
||||
@@ -176,6 +182,15 @@ var swapPricePrecision = (function (global) {
|
||||
return Number.isInteger(precision) && precision >= 0 && precision <= 13 ? precision : fallback;
|
||||
}
|
||||
|
||||
function getQuantityIntegerDigits(instrumentType, fallback) {
|
||||
if (!instrumentType) return fallback;
|
||||
const configured = global.main && global.main.swapPricePrecision;
|
||||
const typeRule = (configured || defaults)[instrumentType];
|
||||
if (!typeRule || !Object.prototype.hasOwnProperty.call(typeRule, 'quantityIntegerDigits')) return fallback;
|
||||
const integerDigits = Number(typeRule.quantityIntegerDigits);
|
||||
return Number.isInteger(integerDigits) && integerDigits >= 1 && integerDigits <= 18 ? integerDigits : fallback;
|
||||
}
|
||||
|
||||
function getCommonRule(kind, instrumentType) {
|
||||
const fallback = normalizeCommonRule(defaults.common[kind]) || { precision: 2, grouping: false };
|
||||
const configured = global.main && global.main.swapPricePrecision
|
||||
@@ -183,7 +198,11 @@ var swapPricePrecision = (function (global) {
|
||||
const configuredRule = normalizeCommonRule(configured && configured[kind]);
|
||||
const rule = configuredRule || fallback;
|
||||
if (rule.grouping === undefined) rule.grouping = fallback.grouping;
|
||||
if (kind === 'quantity') rule.precision = getQuantityPrecision(instrumentType, rule.precision);
|
||||
if (rule.integerDigits === undefined) rule.integerDigits = fallback.integerDigits;
|
||||
if (kind === 'quantity') {
|
||||
rule.precision = getQuantityPrecision(instrumentType, rule.precision);
|
||||
rule.integerDigits = getQuantityIntegerDigits(instrumentType, rule.integerDigits);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
@@ -338,11 +357,13 @@ var swapPricePrecision = (function (global) {
|
||||
const type = instrumentType || inputOptions.instrumentType;
|
||||
delete inputOptions.instrumentType;
|
||||
const rule = getCommonRule(kind, type);
|
||||
return Object.assign(inputOptions, {
|
||||
const result = Object.assign(inputOptions, {
|
||||
precision: rule.precision,
|
||||
grouping: inputOptions.grouping === undefined ? !!rule.grouping : !!inputOptions.grouping,
|
||||
trimTailZeros: false
|
||||
});
|
||||
if (rule.integerDigits !== undefined) result.integerDigits = rule.integerDigits;
|
||||
return result;
|
||||
},
|
||||
formatCommon: formatCommon,
|
||||
normalizeCommon: function (kind, value, instrumentType) {
|
||||
|
||||
Reference in New Issue
Block a user