diff --git a/src/components/AdminPage/ActionLinkAddN/ActionSelect/CalModal.js b/src/components/AdminPage/ActionLinkAddN/ActionSelect/CalModal.js
new file mode 100644
index 0000000..baa457c
--- /dev/null
+++ b/src/components/AdminPage/ActionLinkAddN/ActionSelect/CalModal.js
@@ -0,0 +1,74 @@
+import React from 'react';
+import {Modal, Input, Button, Form, Grid} from 'semantic-ui-react';
+
+const CalModal = ({ i18n, onClose, onSubmit }) => {
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
+
+export default CalModal;
\ No newline at end of file
diff --git a/src/components/AdminPage/ActionLinkAddN/ActionSelect/UnitModbus.js b/src/components/AdminPage/ActionLinkAddN/ActionSelect/UnitModbus.js
index 597a612..2806e36 100644
--- a/src/components/AdminPage/ActionLinkAddN/ActionSelect/UnitModbus.js
+++ b/src/components/AdminPage/ActionLinkAddN/ActionSelect/UnitModbus.js
@@ -1,6 +1,7 @@
import React from 'react';
import {Form, Input} from 'semantic-ui-react';
import { getRequest } from '../../../../actions';
+import CalModal from './CalModal';
class UnitLeone extends React.Component {
state = {
@@ -12,7 +13,8 @@ class UnitLeone extends React.Component {
funcName: '',
addr: '',
value: ''
- }
+ },
+ modal: false
}
componentDidMount() {
@@ -27,6 +29,38 @@ class UnitLeone extends React.Component {
})
}
+ renderModal = () => {
+ let {i18n} = this.props;
+ return (
+ this.state.modal ?
+ (
+
+ ): null
+ )
+ }
+
+ closeModal = () => {
+ this.setState({
+ modal: false
+ })
+ }
+
+ submitModal = (data) => {
+ if(!data) return ;
+ let {showDialog} = this.props;
+ let {r1, r2, s1, s2, val} = data;
+ if(!isFinite(r1) || !isFinite(r2) || !isFinite(s1) || !isFinite(s2) || !isFinite(val)) return showDialog('請勿輸入數字以外的內容');
+
+ let value = Math.round(((val - r1) * (s2 - s1)) / (r2 - r1));
+
+ this.setState({
+ data:{
+ ...this.state.data,
+ value
+ }
+ }, ()=>{this.closeModal()})
+ }
+
changeState = (tag, value) =>{
let data = {...this.state.data};
@@ -77,7 +111,7 @@ class UnitLeone extends React.Component {
let {i18n} = this.props;
let dev = '';
let m = this.state.data.dev.match(/(\d+)/);
- console.log(this.state)
+
if(m!=null && m.length > 1){
dev = m[1];
}
@@ -128,8 +162,21 @@ class UnitLeone extends React.Component {
{this.changeState('addr', d.value)}} />
- {this.changeState('value', d.value)}} />
+ {this.changeState('value', d.value)}}
+ action={{
+ content:"數值換算",
+ basic: true,
+ onClick: ()=>{
+ this.setState({
+ modal: true
+ })
+ },
+ type: 'button'
+ }} />
+ {this.renderModal()}
)
}
diff --git a/src/components/AdminPage/ModbusCmd/CalModal.js b/src/components/AdminPage/ModbusCmd/CalModal.js
new file mode 100644
index 0000000..baa457c
--- /dev/null
+++ b/src/components/AdminPage/ModbusCmd/CalModal.js
@@ -0,0 +1,74 @@
+import React from 'react';
+import {Modal, Input, Button, Form, Grid} from 'semantic-ui-react';
+
+const CalModal = ({ i18n, onClose, onSubmit }) => {
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+}
+
+export default CalModal;
\ No newline at end of file
diff --git a/src/components/AdminPage/ModbusCmd/index.js b/src/components/AdminPage/ModbusCmd/index.js
index fbcffae..1dcf577 100644
--- a/src/components/AdminPage/ModbusCmd/index.js
+++ b/src/components/AdminPage/ModbusCmd/index.js
@@ -1,11 +1,14 @@
import React from 'react';
import {Container, Segment, Input, Form, Button} from 'semantic-ui-react';
import {getRequest} from '../../../actions';
+import CalModal from './CalModal';
class ModbusCmdPage extends React.Component {
state = {
- res: ''
+ res: '',
+ value: '',
+ modal: false
}
handleSubmit = (data) => {
@@ -24,6 +27,35 @@ class ModbusCmdPage extends React.Component {
});
}
+ renderModal = () => {
+ let {i18n} = this.props;
+ return (
+ this.state.modal ?
+ (
+
+ ): null
+ )
+ }
+
+ closeModal = () => {
+ this.setState({
+ modal: false
+ })
+ }
+
+ submitModal = (data) => {
+ if(!data) return ;
+ let {showDialog} = this.props;
+ let {r1, r2, s1, s2, val} = data;
+ if(!isFinite(r1) || !isFinite(r2) || !isFinite(s1) || !isFinite(s2) || !isFinite(val)) return showDialog('請勿輸入數字以外的內容');
+
+ let value = Math.round(((val - r1) * (s2 - s1)) / (r2 - r1));
+
+ this.setState({
+ value
+ }, ()=>{this.closeModal()})
+ }
+
render() {
return (
@@ -66,7 +98,20 @@ class ModbusCmdPage extends React.Component {
-
+ {
+ this.setState({
+ modal: true
+ })
+ }
+ }}
+ value={this.state.value}
+ onChange={(e,d) => {this.setState({value: d.value})}} />
@@ -78,6 +123,7 @@ class ModbusCmdPage extends React.Component {
))
}
+ {this.renderModal()}
)
}