12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- let JV = require('../jpc_value_define');
- let JpcFieldHelper = require('./jpc_helper_field');
- let JpcCommonOutputHelper = {
- createCommonOutputWithoutDecorate: function (node, value) {
- let rst = {};
- //1. font/style/control
- rst[JV.PROP_FONT] = node[[JV.PROP_FONT]];
- rst[JV.PROP_CONTROL] = node[[JV.PROP_CONTROL]];
- rst[JV.PROP_STYLE] = node[[JV.PROP_STYLE]];
- //2. value
- rst[JV.PROP_VALUE] = value;
- innerFormat(node[JV.PROP_FORMAT], rst);
- if (node[JV.PROP_PREFIX] && rst[JV.PROP_VALUE] !== null) {
- rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX] + rst[JV.PROP_VALUE];
- }
- if (node[JV.PROP_SUFFIX] && rst[JV.PROP_VALUE] !== null) {
- rst[JV.PROP_VALUE] = rst[JV.PROP_VALUE] + node[JV.PROP_SUFFIX];
- }
- return rst;
- },
- createCommonOutput: function (node, value, controls) {
- let rst = {};
- //1. font/style/control
- rst[JV.PROP_FONT] = node[[JV.PROP_FONT]];
- rst[JV.PROP_CONTROL] = node[[JV.PROP_CONTROL]];
- rst[JV.PROP_STYLE] = node[[JV.PROP_STYLE]];
- //2. value
- rst[JV.PROP_VALUE] = value;
- JpcFieldHelper.decorateValue(rst, controls);
- innerFormat(node[JV.PROP_FORMAT], rst);
- if (node[JV.PROP_PREFIX] && rst[JV.PROP_VALUE] !== null && rst[JV.PROP_VALUE] !== "") {
- rst[JV.PROP_VALUE] = node[JV.PROP_PREFIX] + rst[JV.PROP_VALUE];
- }
- if (node[JV.PROP_SUFFIX] && rst[JV.PROP_VALUE] !== null && rst[JV.PROP_VALUE] !== "") {
- rst[JV.PROP_VALUE] = rst[JV.PROP_VALUE] + node[JV.PROP_SUFFIX];
- }
- return rst;
- }
- };
- function innerFormat(formatStr, rst) {
- if (formatStr) {
- if (!(isNaN(parseFloat(rst[JV.PROP_VALUE])))) {
- let dotIdx = formatStr.indexOf(".");
- if (dotIdx >= 0) {
- rst[JV.PROP_VALUE] = parseFloat(rst[JV.PROP_VALUE]).toFixed(formatStr.length - dotIdx - 1);
- } else {
- rst[JV.PROP_VALUE] = parseFloat(rst[JV.PROP_VALUE]).toFixed(0);
- }
- let commaIdx = formatStr.indexOf(",");
- if (commaIdx >= 0) {
- rst[JV.PROP_VALUE] = comdify(rst[JV.PROP_VALUE].toString());
- }
- }
- }
- }
- function comdify(numStr){
- let re = /\d{1,3}(?=(\d{3})+$)/g;
- return numStr.replace(/^(\d+)((\.\d+)?)$/,function(s,s1,s2){return s1.replace(re,"$&,")+s2;});
- }
- module.exports = JpcCommonOutputHelper;
|