// 核心库 import React from 'react' import { connect } from 'dva' // 组件库 import { Menu, Input, Row, Col, Form, Radio, Button, Icon, Popconfirm, Result, Empty, message, Modal } from 'antd' import { Scrollbars } from 'react-custom-scrollbars' import { LayoutCard, IFComponent, TableTransfer } from '@woowalker/feui' // 工具库 import { initFilter, guid } from "../../../utils/common" import { gradientColors } from '../../../utils/gradientColors' // 样式 import styles from './index.css' const { GradientCard } = LayoutCard class FMVarCruveConfigModel extends React.Component { constructor(props) { super(props) this.state = { visible: false, loading: false, // 配置项 activeKey: '', selectVar: {}, selectVarCurve: [], //selectedVar: [], config_name: '', // 配置项对应数据 tableData: {}, dataSource: [], // 配置项校验 formValid: { help: '', validateStatus: '' }, paginat: { current: 1 }, search: '' } // scroll bar ref this.scrollRef = null this.columns = [{ title: '变量名称', dataIndex: 'NAME', key: 'NAME' }] } componentDidMount() { this.getCurveConfigs(); if (this.props.onRef) { this.props.onRef(this) } } showModal = () => { this.setState({ visible: true, }, () => { }) } handleOK = e => { this.setState({ visible: false }, () => { this.props.getTableData(this.state.activeKey) }) } saveSetting = () => { const { selectVar } = this.state const json = { OrgId: this.props.login.OrgId, Data: selectVar } this.props.dispatch({ type: 'app/getDataByPost', url: 'FM/FMVarCurve/SaveVariableSetting', payload: json }).then(res => { if (res) { if (!res.IsSucceed) { message.error(res.Msg) } } }) } handleCancel = e => { this.setState({ visible: false, }) } getCurveConfigs = () => { const { login, dispatch } = this.props const json = initFilter(login.OrgId); return dispatch({ type: 'app/getDataByPost', url: 'FM/FMVarCurve/getCurveConfigs', payload: json, onlyData: false }).then(res => { if (res && res.Data.length > 0) { this.setState({ selectVarCurve: res.Data, selectVar: res.Data[0], activeKey: res.Data[0].ID, }, () => { }) } else { this.handleOptionAdd(); } }) } getTransferData = ({ pagination, searchVal }) => { const { login, dispatch } = this.props const { activeKey, selectVar } = this.state var strActiveKey = activeKey; if (selectVar.newOption) strActiveKey = ""; const json = initFilter(login.OrgId, searchVal, '', 0, pagination.current || 1, strActiveKey) return dispatch({ type: 'app/getDataByPost', url: 'FM/FMVarCurve/GetTransferData', payload: json, onlyData: false }).then(res => { selectVar.Nav_VarCurveDetail = res.Data.selectedData; this.setState({ selectVar }); return res; }) } addTransferData = () => { const { login, dispatch } = this.props const json = initFilter(login.OrgId, '', '', 0, 1) return dispatch({ type: 'app/getDataByPost', url: 'FM/FMVarCurve/AddTransferData', payload: json, onlyData: false }).then(res => { if (res?.Data?.selectVarCurve) { this.setState({ selectVarCurve: { Nav_VarCurveDetail: [] } }) } return res }) } handleTransferChange = (data) => { const { selectVar } = this.state selectVar.Nav_VarCurveDetail = data.map(({ ID, VAR_ID }) => ({ VAR_CURVE_ID: this.state.activeKey, VAR_ID: VAR_ID, YAXIS_INDEX: 0, ORG_ID: this.props.login.OrgId })) this.setState({ selectVar }, () => { //this.saveSetting() this.handleOptionSave(false); }) } handleRadioChange = (evt, index) => { const { selectVar } = this.state selectVar.Nav_VarCurveDetail[index].YAXIS_INDEX = evt.target.value this.setState({ selectVar }, () => { //this.saveSetting() }) } handleMenuSelected = ({ selectedKeys }) => { this.setState({ activeKey: selectedKeys[0], selectVar: this.state.selectVarCurve.find(x => x.ID === selectedKeys[0]) }) } handleOptionAdd = () => { const activeKey = guid(); var newOptionConfig = { ID: activeKey, CONFIG_NAME: `配置${this.state.selectVarCurve.length + 1}`, GET_INTERVALS: 1, Nav_VarCurveDetail: [], newOption: true }; this.setState({ activeKey, selectVarCurve: [].concat(this.state.selectVarCurve, [newOptionConfig]), selectVar: newOptionConfig }, () => { //this.saveSetting() this.addTransferData().then(() => { this.scrollRef && this.scrollRef.scrollToBottom() }) }) } handleOptionDel = () => { const { selectVarCurve, activeKey, selectVar } = this.state const findIndex = selectVarCurve.findIndex(item => item.ID === activeKey) const lowerIndex = findIndex - 1 const higherIndex = findIndex + 1 const newActiveKey = lowerIndex >= 0 ? selectVarCurve[lowerIndex].ID : higherIndex <= selectVarCurve.length - 1 ? selectVarCurve[higherIndex].ID : '' if (selectVarCurve[findIndex].newOption) { message.success('删除成功') selectVarCurve.splice(findIndex, 1) this.setState({ activeKey: newActiveKey, selectVarCurve }, () => { this.setState({ selectVar: selectVarCurve.find(x => x.ID === newActiveKey) }, () => { //this.saveSetting() }) }); return } this.props.dispatch({ type: 'app/getDataByGet', url: 'FM/FMVarCurve/FullDelete', payload: { ID: selectVarCurve[findIndex].ID } }).then(res => { if (res) { message.success('删除成功') selectVarCurve.splice(findIndex, 1) this.setState({ activeKey: newActiveKey, selectVarCurve }, () => { this.setState({ selectVar: selectVarCurve.find(x => x.ID === newActiveKey) }, () => { //this.saveSetting() }) }) } }) } handleOptionSave = (msg) => { const { selectVar } = this.state const { login, dispatch } = this.props const updateData = { ID: selectVar.ID, ORG_ID: login.OrgId, USER_ID: login.userId, CONFIG_NAME: selectVar.CONFIG_NAME, GET_INTERVALS: selectVar.GET_INTERVALS, Nav_VarCurveDetail: selectVar.Nav_VarCurveDetail } dispatch({ type: 'app/getDataByPost', url: 'FM/FMVarCurve/FullUpdate', payload: updateData }).then(res => { if (msg && res) { message.success('保存成功') } // selectVar.newOption = false; this.setState(selectVar); }) } handleFormChange = (val) => { const { selectVarCurve, activeKey, selectVar } = this.state const find = selectVarCurve.find(item => item.ID === activeKey) find['CONFIG_NAME'] = val selectVar.CONFIG_NAME = val this.setState({ formValid: { help: val ? '' : '请输入配置名称', validateStatus: val ? '' : 'error' }, selectVarCurve, selectVar }) } handleChartChange = (evt) => { const { selectVar } = this.state selectVar.GET_INTERVALS = evt.target.value this.setState({ selectVar }, () => { //this.saveSetting() }) } render() { const { loading, selectVarCurve, activeKey, formValid, visible, selectVar } = this.state return (
this.scrollRef = ref} hideTracksWhenNotNeeded autoHeight autoHeightMax={384} autoHide autoHideTimeout={1000} autoHideDuration={200} style={{ marginBottom: 8 }} > { selectVarCurve.map(item => { return ( {item.newOption ? '*' : ''}{item.CONFIG_NAME} ) }) }
: } title={loading ? '数据加载中,请稍后...' : '暂无配置项,请新增配置'} extra={} /> } >
this.handleFormChange(evt.target.value)} /> 五分钟 一小时 一天
{ selectVar?.Nav_VarCurveDetail != null && selectVar?.Nav_VarCurveDetail.length > 0 ? selectVar?.Nav_VarCurveDetail.map((item, index) => { const varName = item?.Nav_Var?.NAME return ( this.handleRadioChange(evt, index)} style={{ padding: '8px 0' }} > Y1轴 Y2轴 ) }) : null }
) } } export default connect(({ login, app }) => ({ login, app }))(FMVarCruveConfigModel)