合计浮点数
This commit is contained in:
parent
39587f6b5e
commit
765a4beff9
|
@ -12,6 +12,8 @@ var _react = require("react");
|
|||
|
||||
var _react2 = _interopRequireDefault(_react);
|
||||
|
||||
var _utils = require("../utils");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||
|
@ -83,13 +85,13 @@ function sum(Table) {
|
|||
var count = 0;
|
||||
data.forEach(function (da, i) {
|
||||
|
||||
var _num = parseInt(da[column.key]);
|
||||
var _num = parseFloat(da[column.key]);
|
||||
//排查字段值为NAN情况
|
||||
if (_num === _num) {
|
||||
if (_num) {
|
||||
count += _num;
|
||||
}
|
||||
});
|
||||
sumdata[column.dataIndex] = count;
|
||||
sumdata[column.dataIndex] = (0, _utils.DicimalFormater)(count, 2);
|
||||
}
|
||||
if (index == 0) {
|
||||
sumdata[column.dataIndex] = "合计 " + sumdata[column.dataIndex];
|
||||
|
|
|
@ -16,6 +16,8 @@ exports.ObjectAssign = ObjectAssign;
|
|||
exports.closest = closest;
|
||||
exports.getMaxColChildrenLength = getMaxColChildrenLength;
|
||||
exports.getColChildrenLength = getColChildrenLength;
|
||||
exports.DicimalFormater = DicimalFormater;
|
||||
exports.checkDicimalInvalid = checkDicimalInvalid;
|
||||
|
||||
var _warning = require('warning');
|
||||
|
||||
|
@ -265,6 +267,25 @@ var EventUtil = exports.EventUtil = {
|
|||
element['on' + type] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 处理精度
|
||||
*/
|
||||
};function DicimalFormater(value, precision) {
|
||||
var value = value + '',
|
||||
precision = precision ? precision : 0;
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
if ("-0123456789.".indexOf(value.charAt(i)) == -1) return "";
|
||||
}
|
||||
return checkDicimalInvalid(value, precision);
|
||||
};
|
||||
function checkDicimalInvalid(value, precision) {
|
||||
if (value == null || isNaN(value)) return "";
|
||||
// 浮点数总位数不能超过10位
|
||||
var digit = parseFloat(value);
|
||||
var result = (digit * Math.pow(10, precision) / Math.pow(10, precision)).toFixed(precision);
|
||||
if (result == "NaN") return "";
|
||||
return result;
|
||||
};
|
||||
|
||||
var Event = exports.Event = {
|
||||
|
|
|
@ -58,16 +58,14 @@ const columns13 = [
|
|||
title: "武功级别",
|
||||
dataIndex: "d",
|
||||
key: "d",
|
||||
fixed:'right',
|
||||
width: 200
|
||||
}
|
||||
];
|
||||
|
||||
const data13 = [
|
||||
{ a: "杨过", b: 675, c: 30, d: "内行",e:100, key: "2" },
|
||||
{ a: "令狐冲", b: 43, c: 41, d: "大侠",e:90, key: "1" },
|
||||
{ a: "令狐冲1", b: 43, c: 81, d: "大侠", e:120,key: "4" },
|
||||
{ a: "令狐冲2", b: 43, c: 81, d: "大侠", e:130,key: "5" },
|
||||
{ a: "郭靖", b: 153, c: 25, d: "大侠",e:90, key: "3" }
|
||||
{ a: "令狐冲", b: 43, c: 41, d: "大侠",e:90.52, key: "1" },
|
||||
|
||||
];
|
||||
|
||||
//拼接成复杂功能的table组件不能在render中定义,需要像此例子声明在组件的外侧,不然操作state会导致功能出现异常
|
||||
|
@ -125,6 +123,7 @@ class Demo13 extends Component {
|
|||
data={this.state.data13}
|
||||
multiSelect={multiObj}
|
||||
sort={sortObj}
|
||||
scroll={{x:'100%',y:100}}
|
||||
getSelectedDataFunc={this.getSelectedDataFunc}
|
||||
/>
|
||||
</div>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2422,6 +2422,9 @@ i.uf {
|
|||
/*
|
||||
* 选择时删除文本阴影,及设置默认选中颜色
|
||||
*/
|
||||
::-moz-selection {
|
||||
background: rgb(187,222,251);
|
||||
text-shadow: none; }
|
||||
::selection {
|
||||
background: rgb(187,222,251);
|
||||
text-shadow: none; }
|
||||
|
@ -5285,7 +5288,7 @@ a, .mdl-accordion, .mdl-button, .mdl-card, .mdl-checkbox, .mdl-dropdown-menu,
|
|||
.u-panel .u-panel-body {
|
||||
padding: 15px 15px;
|
||||
position: relative; }
|
||||
.u-panel .u-panel-body .u-panel-copy {
|
||||
.u-panel .u-panel-body .uf {
|
||||
position: absolute;
|
||||
right: 25px;
|
||||
top: 30px;
|
||||
|
@ -5295,7 +5298,7 @@ a, .mdl-accordion, .mdl-button, .mdl-card, .mdl-checkbox, .mdl-dropdown-menu,
|
|||
margin: 8px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer; }
|
||||
.u-panel .u-panel-body .u-panel-copy:hover {
|
||||
.u-panel .u-panel-body .uf:hover {
|
||||
color: #a8a7a7; }
|
||||
|
||||
.u-panel-default {
|
||||
|
@ -6671,8 +6674,7 @@ input.u-button[type="submit"] {
|
|||
border-radius: 0 500px 500px 0; }
|
||||
|
||||
.u-pagination {
|
||||
font-size: 14px;
|
||||
position: relative; }
|
||||
font-size: 14px; }
|
||||
.u-pagination-list {
|
||||
float: left;
|
||||
margin: 5px; }
|
||||
|
@ -6680,10 +6682,6 @@ input.u-button[type="submit"] {
|
|||
clear: both;
|
||||
display: table;
|
||||
content: ''; }
|
||||
.u-pagination-list > li.iconBtn > a {
|
||||
padding: 0 11px;
|
||||
font-size: 22px;
|
||||
line-height: 1.57142857; }
|
||||
.u-pagination-list > li > a, .u-pagination-list > li > span {
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
|
@ -6771,15 +6769,9 @@ input.u-button[type="submit"] {
|
|||
margin: 5px;
|
||||
float: left;
|
||||
min-width: 120px; }
|
||||
.u-pagination .data_per_select > span {
|
||||
display: inline-block;
|
||||
line-height: 36px;
|
||||
float: left; }
|
||||
.u-pagination .data_per_select .u-select {
|
||||
width: 50px;
|
||||
margin: 0 6px;
|
||||
height: 36px;
|
||||
float: left; }
|
||||
margin: 0 6px; }
|
||||
.u-pagination .data_per_select .u-select .u-select-selection {
|
||||
height: 36px; }
|
||||
.u-pagination .data_per_select .u-select .u-select-selection .u-select-selection-rendered {
|
||||
|
@ -6799,26 +6791,20 @@ input.u-button[type="submit"] {
|
|||
.u-pagination .page_jump {
|
||||
float: left;
|
||||
margin: 5px; }
|
||||
.u-pagination .page_jump > span {
|
||||
display: inline-block;
|
||||
line-height: 36px;
|
||||
float: left; }
|
||||
.u-pagination .page_jump_value {
|
||||
outline: none;
|
||||
-webkit-appearance: none;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
line-height: 32px;
|
||||
width: 50px;
|
||||
margin: 0 6px;
|
||||
text-align: center;
|
||||
border: 1px solid #d7d7d7; }
|
||||
.u-pagination .page_jump_btn,
|
||||
.u-pagination .page_jump_value {
|
||||
margin: 0 6px;
|
||||
padding: 0;
|
||||
height: 36px;
|
||||
line-height: 34px;
|
||||
box-sizing: border-box;
|
||||
float: left; }
|
||||
.u-pagination .page_jump_btn {
|
||||
margin-top: -3px;
|
||||
margin-left: 10px;
|
||||
border-color: #d7d7d7; }
|
||||
.u-pagination-total {
|
||||
float: left;
|
||||
height: 36px;
|
||||
|
@ -6826,15 +6812,6 @@ input.u-button[type="submit"] {
|
|||
margin: 5px; }
|
||||
.u-pagination-total span {
|
||||
padding: 0 5px; }
|
||||
.u-pagination.u-pagination-disabled .u-pagination-disabled-mask {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 46px;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
z-index: 2;
|
||||
cursor: not-allowed; }
|
||||
|
||||
.pagination-state {
|
||||
float: left;
|
||||
|
@ -6941,29 +6918,15 @@ input.u-button[type="submit"] {
|
|||
margin: 0 5px;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
position: relative;
|
||||
line-height: 1;
|
||||
vertical-align: middle; }
|
||||
font-size: 14px; }
|
||||
.u-checkbox.disabled .u-checkbox-label {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5; }
|
||||
.u-checkbox input[type='checkbox'] {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%; }
|
||||
display: none;
|
||||
cursor: pointer; }
|
||||
.u-checkbox input[disabled] {
|
||||
cursor: not-allowed; }
|
||||
.u-checkbox input[type='checkbox']:focus + .u-checkbox-label:before {
|
||||
border-color: #1e88e5; }
|
||||
.u-checkbox.is-checked .u-checkbox-label:before {
|
||||
box-shadow: inset 0 0 0 10px rgb(30,136,229);
|
||||
border-color: rgb(30,136,229); }
|
||||
|
@ -7015,37 +6978,22 @@ input.u-button[type="submit"] {
|
|||
box-shadow: inset 0 0 0 10px rgb(76,175,80);
|
||||
border-color: rgb(76,175,80); }
|
||||
|
||||
.u-checkbox.u-checkbox-success input[type='checkbox']:focus + .u-checkbox-label:before {
|
||||
border-color: rgb(76,175,80); }
|
||||
|
||||
.u-checkbox.u-checkbox-warning.is-checked .u-checkbox-label:before {
|
||||
box-shadow: inset 0 0 0 10px rgb(255,152,0);
|
||||
border-color: rgb(255,152,0); }
|
||||
|
||||
.u-checkbox.u-checkbox-warning input[type='checkbox']:focus + .u-checkbox-label:before {
|
||||
border-color: rgb(255,152,0); }
|
||||
|
||||
.u-checkbox.u-checkbox-danger.is-checked .u-checkbox-label:before {
|
||||
box-shadow: inset 0 0 0 10px rgb(244,67,54);
|
||||
border-color: rgb(244,67,54); }
|
||||
|
||||
.u-checkbox.u-checkbox-danger input[type='checkbox']:focus + .u-checkbox-label:before {
|
||||
border-color: rgb(244,67,54); }
|
||||
|
||||
.u-checkbox.u-checkbox-dark.is-checked .u-checkbox-label:before {
|
||||
box-shadow: inset 0 0 0 10px rgb(97,97,97);
|
||||
border-color: rgb(97,97,97); }
|
||||
|
||||
.u-checkbox.u-checkbox-dark input[type='checkbox']:focus + .u-checkbox-label:before {
|
||||
border-color: rgb(97,97,97); }
|
||||
|
||||
.u-checkbox.u-checkbox-info.is-checked .u-checkbox-label:before {
|
||||
box-shadow: inset 0 0 0 10px rgb(0,188,212);
|
||||
border-color: rgb(0,188,212); }
|
||||
|
||||
.u-checkbox.u-checkbox-info input[type='checkbox']:focus + .u-checkbox-label:before {
|
||||
border-color: rgb(0,188,212); }
|
||||
|
||||
/* FormGroup */
|
||||
/* Navlayout */
|
||||
/* keyframes 定义 */
|
||||
|
@ -7583,8 +7531,7 @@ ul {
|
|||
zoom: 1;
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
padding: 0 0 0 8px;
|
||||
top: -3px; }
|
||||
padding: 0 0 0 8px; }
|
||||
.u-select-selection--multiple .u-select-selection-choice-remove:before {
|
||||
display: block;
|
||||
font-family: "uf"; }
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,6 @@
|
|||
import React from "react";
|
||||
|
||||
import {DicimalFormater} from "../utils";
|
||||
export default function sum(Table) {
|
||||
return class SumTable extends React.Component {
|
||||
//无状态
|
||||
|
@ -56,14 +57,14 @@ export default function sum(Table) {
|
|||
let count = 0;
|
||||
data.forEach((da,i)=>{
|
||||
|
||||
let _num = parseInt(da[column.key]);
|
||||
let _num = parseFloat(da[column.key]);
|
||||
//排查字段值为NAN情况
|
||||
if(_num === _num){
|
||||
if(_num == _num){
|
||||
count += _num;
|
||||
}
|
||||
|
||||
})
|
||||
sumdata[column.dataIndex] = count;
|
||||
sumdata[column.dataIndex] = DicimalFormater(count,2);
|
||||
}
|
||||
if(index == 0){
|
||||
sumdata[column.dataIndex] = "合计 "+sumdata[column.dataIndex];
|
||||
|
|
24
src/utils.js
24
src/utils.js
|
@ -249,6 +249,30 @@ export const EventUtil = {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 处理精度
|
||||
*/
|
||||
export function DicimalFormater(value,precision) {
|
||||
var value = value + '',
|
||||
precision = precision?precision:0;
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
if ("-0123456789.".indexOf(value.charAt(i)) == -1)
|
||||
return "";
|
||||
}
|
||||
return checkDicimalInvalid(value, precision);
|
||||
};
|
||||
export function checkDicimalInvalid(value, precision) {
|
||||
if (value == null || isNaN(value))
|
||||
return "";
|
||||
// 浮点数总位数不能超过10位
|
||||
var digit = parseFloat(value);
|
||||
var result = (digit * Math.pow(10, precision) / Math.pow(10, precision))
|
||||
.toFixed(precision);
|
||||
if (result == "NaN")
|
||||
return "";
|
||||
return result;
|
||||
};
|
||||
|
||||
export const Event = {
|
||||
addHandler,
|
||||
removeHandler,
|
||||
|
|
Loading…
Reference in New Issue