Files
zszq-trs/YLErpWeb/wwwroot/Scripts/app/trade/percentColumnText.js
T
hjhan 0ff7375696 refactor(web): 百分比列展示嗅探一行式显式化——6处逐字重复抽PercentColumnText纯函数
structure.js×3/structure_dz.js/tradeEditV2.js/tradeEditGroup.js的setExtendInfo里同一行式:靠indexOf("%")>0嗅探值是否已带%,决定原样展示还是×100加%。抽为app/trade/percentColumnText.js纯函数(UMD,jest可测),表达式逐字符等价——含>0而非>=0、空值回退ColumnDefaultValue、回退源也无值时NaN%等历史行为全部被7个特征测试冻结(TDD:测试先红后绿)。四个页面cshtml在tradeHelper后补脚本序;jest覆盖率清单纳入。fe-tests 326/326通过
2026-08-22 07:46:58 +08:00

34 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* percentColumnText.js — 交易要素列的百分比展示文本(纯函数)
* ============================================================================
* 把散落在 structure.js ×3 / structure_dz.js / tradeEditV2.js / tradeEditGroup.js
* 的六处逐字相同一行式显式化为命名函数。
* 【约定】ColumnType==4 = 百分比列:值以小数形式存储(如 0.05),展示时 ×100 追加 %;
* 若值文本已含 %(人工录入或后端已格式化)则原样展示,不做二次换算;
* 非百分比列一律原样字符串化。
*
* 表达式与原一行式逐字符等价(含 >0 而非 >=0、空值回退 ColumnDefaultValue、
* 回退源也无值时 NaN% 等历史行为)——特征测试见 fe-tests/percentColumnText.test.js。
* 输入契约:value 须为字符串或空值(数字会与原式同样抛 TypeError)。
*
* 加载:浏览器 script 标签(先于 structure/tradeEditV2/tradeEditGroup 页面脚本);
* Nodemodule.exports 供 jest。
*/
var PercentColumnText = (function () {
'use strict';
function displayText(item) {
var raw = item.value || item.ColumnDefaultValue;
if (item.ColumnType !== 4 || (item.value || item.ColumnDefaultValue + "").indexOf("%") > 0) {
return raw + "";
}
return (raw * 100) + "%";
}
return Object.freeze({
displayText: displayText
});
}());
if (typeof module === 'object' && module.exports) module.exports = PercentColumnText;