forked from ddrilling/asb_cloud_front
makeNumericAvgRange вернут к изначальному виду
This commit is contained in:
parent
44d11d964d
commit
32ec3c22d2
@ -12,6 +12,7 @@ export {
|
|||||||
makeNumericColumnPlanFact,
|
makeNumericColumnPlanFact,
|
||||||
makeNumericStartEnd,
|
makeNumericStartEnd,
|
||||||
makeNumericMinMax,
|
makeNumericMinMax,
|
||||||
|
makeNumericAvgRange,
|
||||||
} from './numeric'
|
} from './numeric'
|
||||||
export { makeColumnsPlanFact } from './plan_fact'
|
export { makeColumnsPlanFact } from './plan_fact'
|
||||||
export { makeSelectColumn } from './select'
|
export { makeSelectColumn } from './select'
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
|
import { ColumnFilterItem } from 'antd/lib/table/interface'
|
||||||
import { InputNumber } from 'antd'
|
import { InputNumber } from 'antd'
|
||||||
import { ReactNode } from 'react'
|
import { ReactNode } from 'react'
|
||||||
|
|
||||||
import { makeNumericSorter } from '../sorters'
|
import { makeNumericSorter } from '../sorters'
|
||||||
import makeColumn, { columnPropsOther, DataType, makeGroupColumn, RenderMethod } from '.'
|
import makeColumn, { columnPropsOther, DataType, makeGroupColumn, RenderMethod } from '.'
|
||||||
import { ColumnFilterItem, CompareFn } from 'antd/lib/table/interface'
|
|
||||||
|
|
||||||
export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
|
export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/
|
||||||
|
|
||||||
type FilterMethod<T> = (value: string | number | boolean, record: DataType<T>) => boolean
|
type FilterMethod<T> = (value: string | number | boolean, record: DataType<T>) => boolean
|
||||||
|
|
||||||
export const makeNumericRender = <T extends unknown>(fixed?: number): RenderMethod<T> => (value: T) => {
|
export const makeNumericRender = <T,>(fixed?: number): RenderMethod<T> => (value: T) => {
|
||||||
let val = '-'
|
let val = '-'
|
||||||
if ((value ?? null) !== null && Number.isFinite(+value)) {
|
if ((value ?? null) !== null && Number.isFinite(+value)) {
|
||||||
val = (fixed ?? null) !== null
|
val = (fixed ?? null) !== null
|
||||||
@ -24,7 +24,7 @@ export const makeNumericRender = <T extends unknown>(fixed?: number): RenderMeth
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const makeNumericColumnOptions = <T extends unknown = any>(fixed?: number, sorterKey?: string): columnPropsOther<T> => ({
|
export const makeNumericColumnOptions = <T,>(fixed?: number, sorterKey?: string): columnPropsOther<T> => ({
|
||||||
editable: true,
|
editable: true,
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
width: 100,
|
width: 100,
|
||||||
@ -37,7 +37,7 @@ export const makeNumericColumnOptions = <T extends unknown = any>(fixed?: number
|
|||||||
render: makeNumericRender<T>(fixed),
|
render: makeNumericRender<T>(fixed),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const makeNumericColumn = <T extends unknown = any>(
|
export const makeNumericColumn = <T,>(
|
||||||
title: ReactNode,
|
title: ReactNode,
|
||||||
key: string,
|
key: string,
|
||||||
filters?: ColumnFilterItem[],
|
filters?: ColumnFilterItem[],
|
||||||
@ -48,7 +48,7 @@ export const makeNumericColumn = <T extends unknown = any>(
|
|||||||
) => makeColumn(title, key, {
|
) => makeColumn(title, key, {
|
||||||
filters,
|
filters,
|
||||||
onFilter: filterDelegate ? filterDelegate(key) : undefined,
|
onFilter: filterDelegate ? filterDelegate(key) : undefined,
|
||||||
sorter: makeNumericSorter(key),
|
sorter: makeNumericSorter<T>(key),
|
||||||
width,
|
width,
|
||||||
input: <InputNumber style={{ width: '100%' }}/>,
|
input: <InputNumber style={{ width: '100%' }}/>,
|
||||||
render: renderDelegate ?? makeNumericRender<T>(2),
|
render: renderDelegate ?? makeNumericRender<T>(2),
|
||||||
@ -56,7 +56,7 @@ export const makeNumericColumn = <T extends unknown = any>(
|
|||||||
...other
|
...other
|
||||||
})
|
})
|
||||||
|
|
||||||
export const makeNumericColumnPlanFact = <T extends unknown = any>(
|
export const makeNumericColumnPlanFact = <T,>(
|
||||||
title: ReactNode,
|
title: ReactNode,
|
||||||
key: string,
|
key: string,
|
||||||
filters?: ColumnFilterItem[],
|
filters?: ColumnFilterItem[],
|
||||||
@ -68,7 +68,7 @@ export const makeNumericColumnPlanFact = <T extends unknown = any>(
|
|||||||
makeNumericColumn<T>('ф', key + 'Fact', filters, filterDelegate, renderDelegate, width),
|
makeNumericColumn<T>('ф', key + 'Fact', filters, filterDelegate, renderDelegate, width),
|
||||||
])
|
])
|
||||||
|
|
||||||
export const makeNumericStartEnd = <T extends unknown = any>(
|
export const makeNumericStartEnd = <T,>(
|
||||||
title: ReactNode,
|
title: ReactNode,
|
||||||
key: string,
|
key: string,
|
||||||
fixed: number,
|
fixed: number,
|
||||||
@ -77,11 +77,11 @@ export const makeNumericStartEnd = <T extends unknown = any>(
|
|||||||
renderDelegate?: RenderMethod<T>,
|
renderDelegate?: RenderMethod<T>,
|
||||||
width?: string | number,
|
width?: string | number,
|
||||||
) => makeGroupColumn(title, [
|
) => makeGroupColumn(title, [
|
||||||
makeNumericColumn<T>('старт', key + 'Start', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Start')),
|
makeNumericColumn<T>('старт', key + 'Start', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, key + 'Start')),
|
||||||
makeNumericColumn<T>('конец', key + 'End', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'End'))
|
makeNumericColumn<T>('конец', key + 'End', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, key + 'End'))
|
||||||
])
|
])
|
||||||
|
|
||||||
export const makeNumericMinMax = <T extends unknown = any>(
|
export const makeNumericMinMax = <T,>(
|
||||||
title: ReactNode,
|
title: ReactNode,
|
||||||
key: string,
|
key: string,
|
||||||
fixed: number,
|
fixed: number,
|
||||||
@ -90,8 +90,22 @@ export const makeNumericMinMax = <T extends unknown = any>(
|
|||||||
renderDelegate?: RenderMethod<T>,
|
renderDelegate?: RenderMethod<T>,
|
||||||
width?: string | number,
|
width?: string | number,
|
||||||
) => makeGroupColumn(title, [
|
) => makeGroupColumn(title, [
|
||||||
makeNumericColumn<T>('мин', key + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Min')),
|
makeNumericColumn<T>('мин', key + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, key + 'Min')),
|
||||||
makeNumericColumn<T>('макс', key + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Max')),
|
makeNumericColumn<T>('макс', key + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, key + 'Max')),
|
||||||
|
])
|
||||||
|
|
||||||
|
export const makeNumericAvgRange = <T,>(
|
||||||
|
title: ReactNode,
|
||||||
|
dataIndex: string,
|
||||||
|
fixed: number,
|
||||||
|
filters: ColumnFilterItem[],
|
||||||
|
filterDelegate: (key: string | number) => FilterMethod<T>,
|
||||||
|
renderDelegate: RenderMethod<T>,
|
||||||
|
width: string
|
||||||
|
) => makeGroupColumn(title, [
|
||||||
|
makeNumericColumn<T>('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, dataIndex + 'Min')),
|
||||||
|
makeNumericColumn<T>('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, dataIndex + 'Avg')),
|
||||||
|
makeNumericColumn<T>('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions<T>(fixed, dataIndex + 'Max'))
|
||||||
])
|
])
|
||||||
|
|
||||||
export default makeNumericColumn
|
export default makeNumericColumn
|
||||||
|
@ -20,6 +20,7 @@ export {
|
|||||||
makeNumericColumnPlanFact,
|
makeNumericColumnPlanFact,
|
||||||
makeNumericStartEnd,
|
makeNumericStartEnd,
|
||||||
makeNumericMinMax,
|
makeNumericMinMax,
|
||||||
|
makeNumericAvgRange,
|
||||||
makeSelectColumn,
|
makeSelectColumn,
|
||||||
makeTagColumn,
|
makeTagColumn,
|
||||||
makeTagInput,
|
makeTagInput,
|
||||||
|
@ -1,89 +1,18 @@
|
|||||||
import { useState, useEffect, useCallback, memo, useMemo } from 'react'
|
import { useState, useEffect, useCallback, memo, useMemo } from 'react'
|
||||||
import { InputNumber } from 'antd'
|
|
||||||
|
|
||||||
import { useWell } from '@asb/context'
|
import { useWell } from '@asb/context'
|
||||||
import {
|
import {
|
||||||
EditableTable,
|
EditableTable,
|
||||||
makeSelectColumn,
|
makeSelectColumn,
|
||||||
makeGroupColumn,
|
|
||||||
makeNumericRender,
|
|
||||||
makeNumericSorter,
|
makeNumericSorter,
|
||||||
RegExpIsFloat,
|
makeNumericAvgRange,
|
||||||
} from '@components/Table'
|
} from '@components/Table'
|
||||||
import LoaderPortal from '@components/LoaderPortal'
|
import LoaderPortal from '@components/LoaderPortal'
|
||||||
import { invokeWebApiWrapperAsync } from '@components/factory'
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
||||||
import { DrillParamsService, WellOperationService } from '@api'
|
import { DrillParamsService, WellOperationService } from '@api'
|
||||||
import { arrayOrDefault } from '@utils'
|
import { arrayOrDefault } from '@utils'
|
||||||
|
|
||||||
import { makeNumericObjSorter } from '@components/Table/sorters'
|
export const getColumns = async (idWell, makeAvgRange = makeNumericAvgRange) => {
|
||||||
|
|
||||||
const makeNumericObjRender = (fixed, columnKey) => (value, obj) => {
|
|
||||||
let val = '-'
|
|
||||||
const isSelected = obj && columnKey && obj[columnKey[0]] ? obj[columnKey[0]][columnKey[1]] : false
|
|
||||||
|
|
||||||
if ((value ?? null) !== null && Number.isFinite(+value)) {
|
|
||||||
val = (fixed ?? null) !== null
|
|
||||||
? (+value).toFixed(fixed)
|
|
||||||
: (+value).toPrecision(5)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`text-align-r-container ${isSelected ? 'color-pale-green' : ''}`}>
|
|
||||||
<span>{val}</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const makeNumericColumnOptionsWithColor = (fixed, sorterKey, columnKey) => ({
|
|
||||||
editable: true,
|
|
||||||
initialValue: 0,
|
|
||||||
width: 100,
|
|
||||||
sorter: sorterKey ? makeNumericObjSorter(sorterKey) : undefined,
|
|
||||||
formItemRules: [{
|
|
||||||
required: true,
|
|
||||||
message: 'Введите число',
|
|
||||||
pattern: RegExpIsFloat,
|
|
||||||
}],
|
|
||||||
render: makeNumericObjRender(fixed, columnKey),
|
|
||||||
})
|
|
||||||
|
|
||||||
const makeNumericObjColumn = (
|
|
||||||
title,
|
|
||||||
dataIndex,
|
|
||||||
filters,
|
|
||||||
filterDelegate,
|
|
||||||
renderDelegate,
|
|
||||||
width,
|
|
||||||
other
|
|
||||||
) => ({
|
|
||||||
title: title,
|
|
||||||
dataIndex: dataIndex,
|
|
||||||
key: dataIndex,
|
|
||||||
filters: filters,
|
|
||||||
onFilter: filterDelegate ? filterDelegate(dataIndex) : null,
|
|
||||||
sorter: makeNumericObjSorter(dataIndex),
|
|
||||||
width: width,
|
|
||||||
input: <InputNumber style={{ width: '100%' }}/>,
|
|
||||||
render: renderDelegate ?? makeNumericRender(),
|
|
||||||
align: 'right',
|
|
||||||
...other
|
|
||||||
})
|
|
||||||
|
|
||||||
const makeNumericAvgRange = (
|
|
||||||
title,
|
|
||||||
dataIndex,
|
|
||||||
fixed,
|
|
||||||
filters,
|
|
||||||
filterDelegate,
|
|
||||||
renderDelegate,
|
|
||||||
width
|
|
||||||
) => makeGroupColumn(title, [
|
|
||||||
makeNumericObjColumn('мин', [dataIndex, 'min'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'min'], [dataIndex, 'isMin'])),
|
|
||||||
makeNumericObjColumn('сред', [dataIndex, 'avg'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'avg'])),
|
|
||||||
makeNumericObjColumn('макс', [dataIndex, 'max'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'max'], [dataIndex, 'isMax']))
|
|
||||||
])
|
|
||||||
|
|
||||||
export const getColumns = async (idWell) => {
|
|
||||||
let sectionTypes = await WellOperationService.getSectionTypes(idWell)
|
let sectionTypes = await WellOperationService.getSectionTypes(idWell)
|
||||||
sectionTypes = Object.entries(sectionTypes).map(([id, value]) => ({
|
sectionTypes = Object.entries(sectionTypes).map(([id, value]) => ({
|
||||||
label: value,
|
label: value,
|
||||||
@ -96,11 +25,11 @@ export const getColumns = async (idWell) => {
|
|||||||
width: 160,
|
width: 160,
|
||||||
sorter: makeNumericSorter('idWellSectionType'),
|
sorter: makeNumericSorter('idWellSectionType'),
|
||||||
}),
|
}),
|
||||||
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
|
makeAvgRange('Нагрузка, т', 'axialLoad', 1),
|
||||||
makeNumericAvgRange('Давление, атм', 'pressure', 1),
|
makeAvgRange('Давление, атм', 'pressure', 1),
|
||||||
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
|
makeAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
|
||||||
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
|
makeAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
|
||||||
makeNumericAvgRange('Расход, л/с', 'flow', 1),
|
makeAvgRange('Расход, л/с', 'flow', 1),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user