fix
This commit is contained in:
1 parent
57a2029847
commit
badf131dde
18 files changed
+1081
-2824
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import Decimal from 'decimal.js'
|
||||
|
||||
type MaybeNumber = number | null | undefined
|
||||
type DecimalInput = Decimal.Value
|
||||
|
||||
export const toDecimal = (value: DecimalInput) => new Decimal(value)
|
||||
|
||||
export const roundTo = (value: DecimalInput, decimalPlaces = 2) =>
|
||||
new Decimal(value).toDecimalPlaces(decimalPlaces, Decimal.ROUND_HALF_UP).toNumber()
|
||||
|
||||
export const addNumbers = (...values: MaybeNumber[]) => {
|
||||
let total = new Decimal(0)
|
||||
for (const value of values) {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value)) continue
|
||||
total = total.plus(value)
|
||||
}
|
||||
return total.toNumber()
|
||||
}
|
||||
|
||||
export const sumByNumber = <T>(list: T[], pick: (item: T) => MaybeNumber) => {
|
||||
let total = new Decimal(0)
|
||||
for (const item of list) {
|
||||
const value = pick(item)
|
||||
if (typeof value !== 'number' || !Number.isFinite(value)) continue
|
||||
total = total.plus(value)
|
||||
}
|
||||
return total.toNumber()
|
||||
}
|
||||
|
||||
export const decimalAggSum = (params: { values?: unknown[] }) => {
|
||||
let total = new Decimal(0)
|
||||
for (const value of params.values || []) {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value)) continue
|
||||
total = total.plus(value)
|
||||
}
|
||||
return total.toNumber()
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
|
||||
GridOptions,
|
||||
themeQuartz
|
||||
} from "ag-grid-community"
|
||||
const borderConfig = {
|
||||
@@ -27,4 +28,21 @@ export const myTheme = themeQuartz.withParams({
|
||||
|
||||
// 可选:偶数行背景色(轻微区分,更清新)
|
||||
dataBackgroundColor: "#fefefe"
|
||||
});
|
||||
});
|
||||
export const gridOptions: GridOptions<any> = {
|
||||
treeData: true,
|
||||
animateRows: true,
|
||||
suppressAggFuncInHeader: true,
|
||||
singleClickEdit: true,
|
||||
suppressClickEdit: false,
|
||||
suppressContextMenu: false,
|
||||
groupDefaultExpanded: -1,
|
||||
suppressFieldDotNotation: true,
|
||||
getDataPath: data => data.path,
|
||||
getContextMenuItems: () => ['copy', 'paste', 'separator', 'export'],
|
||||
defaultColDef: {
|
||||
resizable: true,
|
||||
sortable: false,
|
||||
filter: false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user