update modbus db and view

This commit is contained in:
Jay 2017-03-28 13:53:16 +08:00
parent 52e18de9ac
commit eeead43baf
10 changed files with 110 additions and 33 deletions

5
app.js
View File

@ -47,4 +47,9 @@ app.get('/', (req, res) => {
app.get(['/admin','/admin/*'], (req,res) => {
res.sendFile(path.resolve(__dirname, 'views', 'admin.html'));
});
app.get('/servcmd', (req,res) => {
res.send({status: `exit time ${Date.now()}`});
setTimeout(()=>{process.exit(1)}, 2000);
});

View File

@ -84434,21 +84434,27 @@ var DeviceListItem = function DeviceListItem(_ref) {
return _react2.default.createElement(
_semanticUiReact.List.Item,
{ active: data.uid == showDev },
_react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'trash', title: 'Delete', onClick: function onClick() {
delModbus(data.uid || '');
} }),
_react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'write', title: 'Edit', onClick: function onClick() {
editModbus(1, data);
} }),
_react2.default.createElement(
'span',
_semanticUiReact.List.Content,
{ style: { cursor: 'pointer' }, onClick: function onClick() {
selectDevToShow(data.uid);
} },
data.name,
' / Node:',
data.node
),
_react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'trash', onClick: function onClick() {
delModbus(data.uid || '');
} }),
_react2.default.createElement(_semanticUiReact.Icon, { style: { cursor: 'pointer' }, name: 'write', onClick: function onClick() {
editModbus(1, data);
} })
_react2.default.createElement(
_semanticUiReact.List.Header,
null,
data.name
),
'Node: ',
data.node,
' / Type: ',
data.type
)
);
};
@ -84501,6 +84507,7 @@ var IOModal = function IOModal(_ref) {
id: data.uid || '',
addr: '',
num: '',
datalen: '',
type: ''
};
@ -84510,6 +84517,8 @@ var IOModal = function IOModal(_ref) {
if (num && 'value' in num) json.num = num.value;
var type = e.querySelector('select[name="io_type"]');
if (type && 'value' in type) json.type = type.value;
var len = e.querySelector('input[name="datalen"]');
if (len && 'value' in len) json.datalen = len.value;
return json;
} },
@ -84541,12 +84550,17 @@ var IOModal = function IOModal(_ref) {
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { name: 'addr', label: '\u8D77\u59CB\u4F4D\u5740', defaultValue: data.addr || '' })
_react2.default.createElement(_semanticUiReact.Input, { name: 'addr', label: '\u8D77\u59CB\u4F4D\u5740', defaultValue: data.addr })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { name: 'num', label: '\u6578\u91CF', defaultValue: data.num || '' })
_react2.default.createElement(_semanticUiReact.Input, { name: 'num', label: '\u6578\u91CF', defaultValue: data.num })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { name: 'datalen', label: '\u8CC7\u6599\u9577\u5EA6', defaultValue: data.datalen, placeholder: '\u9577\u5EA6\u4E0D\u586B\u5247\u9810\u8A2D2' })
),
_react2.default.createElement(
_semanticUiReact.Grid,
@ -84701,7 +84715,12 @@ var IOPanel = function (_React$Component) {
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
'\u63A5\u53E3\u6578\u91CF'
'\u8B80\u53D6\u6578\u91CF'
),
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
'\u8CC7\u6599\u9577\u5EA6'
),
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
@ -84784,6 +84803,11 @@ var IOPanelListItem = function IOPanelListItem(_ref) {
null,
data.num
),
_react2.default.createElement(
_semanticUiReact.Table.Cell,
null,
data.datalen
),
_react2.default.createElement(
_semanticUiReact.Table.Cell,
null,
@ -84847,6 +84871,7 @@ var ModbusModal = function ModbusModal(_ref) {
var json = {
name: '',
node: '',
type: '',
id: data.uid || '',
original_node: data.node || ''
};
@ -84855,6 +84880,8 @@ var ModbusModal = function ModbusModal(_ref) {
if (n && 'value' in n) json.name = n.value;
var nn = e.querySelector('input[name="node"]');
if (nn && 'value' in nn) json.node = nn.value;
var type = e.querySelector('input[name="type"]');
if (type && 'value' in type) json.type = type.value;
return json;
} },
@ -84866,7 +84893,12 @@ var ModbusModal = function ModbusModal(_ref) {
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { name: 'node', defaultValue: data.node || '', label: 'Node' })
_react2.default.createElement(_semanticUiReact.Input, { name: 'node', defaultValue: data.node, label: 'Node' })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { name: 'type', defaultValue: data.type, label: 'Type', placeholder: '\u9810\u8A2D\u8ACB\u7559\u7A7A' })
),
_react2.default.createElement(
_semanticUiReact.Grid,
@ -85024,6 +85056,7 @@ var ModbusPage = function (_React$Component) {
var i18n = _this.props.i18n;
if (type == 1 && !data.id || !('addr' in data) || !('num' in data) || !('type' in data)) return _this.props.showDialog(i18n.t('tip.input_empty'));
if (data.datalen == 0) return _this.props.showDialog('資料長度不能為0');
data.devuid = _this.state.showDev;
if (type == 1) {

View File

@ -96,12 +96,14 @@ router
if (!arr.data.name) return n('ERR0026');
if (!('node' in arr.data)) return n('ERR0038');
let type = arr.data.type && isFinite(arr.data.type) ? arr.data.type : 0;
let u = '';
let obj = so.get(req.headers['x-auth-token']);
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
let query = "insert into ??.?? (`name`, `node`, `adduser`, `moduser`, `ctime`, `mtime`) values (?,?,?,?, unix_timestamp(), unix_timestamp())";
let param = [config.db.db5, 'device', arr.data.name, arr.data.node, u, u];
let query = "insert into ??.?? (`name`, `node`, `type`, `adduser`, `moduser`, `ctime`, `mtime`) values (?,?,?,?,?, unix_timestamp(), unix_timestamp())";
let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, u];
res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001');
@ -122,6 +124,8 @@ router
if (!arr.data.name) return n('ERR0026');
if (!('node' in arr.data) || !('original_node' in arr.data)) return n('ERR0038');
let type = arr.data.type && isFinite(arr.data.type) ? arr.data.type : 0;
let query = "select count(*) as num from ??.?? where `node` = ? and `uid` != ?";
let param = [config.db.db5, 'device', arr.data.node, arr.data.id];
res.db.query(query, param, (err, row) => {
@ -135,11 +139,12 @@ router
let query = "update ??.?? set \
`name` = ?, \
`node` = ?, \
`type` = ?, \
`moduser` = ?, \
`mtime` = unix_timestamp() \
where \
`uid` = ?";
let param = [config.db.db5, 'device', arr.data.name, arr.data.node, u, arr.data.id];
let param = [config.db.db5, 'device', arr.data.name, arr.data.node, type, u, arr.data.id];
res.db.query(query, param, (err, row) => {
if (err) return n('ERR8002');
@ -198,7 +203,8 @@ router
where \
d.`uid` = ? \
and rt.`type` = ? \
and i.`uid` is not null ";
and i.`uid` is not null \
order by rt.`port` asc";
let param = [config.db.db6, 'jcmbrt', config.db.db5, 'device', config.db.db5, 'iolist', arr.data.type, config.db.db5, 'aioset', arr.data.id, arr.data.type];
res.db.query(query, param, (err, row) => {
@ -238,6 +244,8 @@ router
if (!arr.data.addr) return n('ERR0048');
if (!arr.data.num) return n('ERR0049');
let dlen = arr.data.datalen || 2;
let query = "select count(*) as c from ??.?? \
where \
`devuid` = ? \
@ -249,8 +257,8 @@ router
if (row[0].c > 0) return n('ERR0054');
let query = "insert into ??.?? (`devuid`,`type`,`addr`,`num`,`ctime`,`mtime`) values (?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr, arr.data.num];
let query = "insert into ??.?? (`devuid`,`type`,`addr`,`num`,`datalen`,`ctime`,`mtime`) values (?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
let param = [config.db.db5, 'iolist', arr.data.id, arr.data.type, arr.data.addr, arr.data.num, dlen];
res.db.query(query, param, (err, row) => {
if (err) return n('ERR8001');
@ -270,6 +278,8 @@ router
if (!arr.data.addr) return n('ERR0048');
if (!arr.data.num) return n('ERR0049');
let dlen = arr.data.datalen || 2;
let query = "select count(*) as c from ??.?? i \
left join ??.?? i2 \
on i2.`type` = i.`type` \
@ -287,10 +297,11 @@ router
let q = "update ??.?? set \
`addr` = ?, \
`num` = ?, \
`datalen` = ?, \
`mtime` = unix_timestamp() \
where \
`uid` = ?";
let p = [config.db.db5, 'iolist', arr.data.addr, arr.data.num, arr.data.id];
let p = [config.db.db5, 'iolist', arr.data.addr, arr.data.num, dlen, arr.data.id];
res.db.query(q, p, (err, row) => {
if (err) return n('ERR8002');

View File

@ -361,25 +361,35 @@ router
let q, p;
switch (arr.data.type) {
case 'do':
if(!config.permission.dio) return n('ERR9000');
q = "select `doname` as name, `douid` as id from ??.??";
p = [config.db.db1, 'dolist'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'di':
if(!config.permission.dio) return n('ERR9000');
q = "select `diname` as name, `diuid` as id from ??.??";
p = [config.db.db1, 'dilist'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'leone':
if(!config.permission.leone) return n('ERR9000');
q = "select `leonename` as name, `leonelistuid` as id from ??.??";
p = [config.db.db1, 'leonelist'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'iogroup':
if(!config.permission.iogroup) return n('ERR9000');
q = "select `iogroupname` as name, `iogroupuid` as id from ??.??";
p = [config.db.db1, 'iogroup'];
pro = tool.promiseQuery(res, q, p, '');
break;
case 'modbus':
if(!config.permission.modbus) return n('ERR9000');
q = "select `name`, `uid` as id from ??.??";
p = [config.db.db5, 'device'];
pro = tool.promiseQuery(res,q,p, '');
break;
default:
return n();
}

View File

@ -5,13 +5,16 @@ const DeviceListItem = ({i18n, idx, data, delModbus, editModbus, showDev, select
return (
<List.Item active={data.uid == showDev}>
<span style={{cursor: 'pointer'}} onClick={() => {
selectDevToShow(data.uid);
}}>
{data.name} / Node:{data.node}
</span>
<Icon style={{cursor: 'pointer'}} name="trash" onClick={()=>{delModbus(data.uid || '')}}/>
<Icon style={{cursor: 'pointer'}} name="write" onClick={()=>{editModbus(1, data)}}/>
<Icon style={{cursor: 'pointer'}} name="trash" title="Delete" onClick={()=>{delModbus(data.uid || '')}}/>
<Icon style={{cursor: 'pointer'}} name="write" title="Edit" onClick={()=>{editModbus(1, data)}}/>
<List.Content style={{cursor: 'pointer'}} onClick={() => {
selectDevToShow(data.uid);
}}>
<List.Header>
{data.name}
</List.Header>
Node: {data.node} / Type: {data.type}
</List.Content>
</List.Item>
)
}

View File

@ -17,6 +17,7 @@ const IOModal = ({i18n, open, type, data, onSubmit, onClose}) => {
id: data.uid || '',
addr: '',
num: '',
datalen: '',
type: ''
};
@ -26,6 +27,8 @@ const IOModal = ({i18n, open, type, data, onSubmit, onClose}) => {
if(num && 'value' in num) json.num = num.value;
let type = e.querySelector('select[name="io_type"]');
if(type && 'value' in type) json.type = type.value;
let len = e.querySelector('input[name="datalen"]');
if(len && 'value' in len) json.datalen = len.value;
return json;
}}>
@ -41,10 +44,13 @@ const IOModal = ({i18n, open, type, data, onSubmit, onClose}) => {
</select>
</Form.Field>
<Form.Field>
<Input name="addr" label="起始位址" defaultValue={data.addr || ''} />
<Input name="addr" label="起始位址" defaultValue={data.addr} />
</Form.Field>
<Form.Field>
<Input name="num" label="數量" defaultValue={data.num || ''} />
<Input name="num" label="數量" defaultValue={data.num} />
</Form.Field>
<Form.Field>
<Input name="datalen" label="資料長度" defaultValue={data.datalen} placeholder="長度不填則預設2"/>
</Form.Field>
<Grid columns={2}>
<Grid.Column>

View File

@ -54,7 +54,8 @@ class IOPanel extends React.Component {
<Table.Header>
<Table.Row>
<Table.HeaderCell>起始位置</Table.HeaderCell>
<Table.HeaderCell>接口數量</Table.HeaderCell>
<Table.HeaderCell>讀取數量</Table.HeaderCell>
<Table.HeaderCell>資料長度</Table.HeaderCell>
<Table.HeaderCell>操作</Table.HeaderCell>
</Table.Row>
</Table.Header>

View File

@ -7,6 +7,7 @@ const IOPanelListItem = ({i18n, data, ioModal, delIOList, showAIOSet}) => {
<Table.Row>
<Table.Cell>{data.addr}</Table.Cell>
<Table.Cell>{data.num}</Table.Cell>
<Table.Cell>{data.datalen}</Table.Cell>
<Table.Cell>
<Button type="button" basic content="修改" onClick={()=>{ioModal(1, data)}}/>
<Button type="button" basic content="刪除" onClick={()=>{delIOList(data.uid || '')}}/>

View File

@ -15,6 +15,7 @@ const ModbusModal = ({i18n, open, type, data, onSubmit, onClose}) => {
let json = {
name: '',
node: '',
type: '',
id: data.uid || '',
original_node: data.node || ''
};
@ -23,6 +24,8 @@ const ModbusModal = ({i18n, open, type, data, onSubmit, onClose}) => {
if(n && 'value' in n) json.name = n.value;
let nn = e.querySelector('input[name="node"]');
if(nn && 'value' in nn) json.node = nn.value;
let type = e.querySelector('input[name="type"]');
if(type && 'value' in type) json.type = type.value;
return json ;
}}>
@ -30,7 +33,10 @@ const ModbusModal = ({i18n, open, type, data, onSubmit, onClose}) => {
<Input name="name" defaultValue={data.name || ''} label="Name"/>
</Form.Field>
<Form.Field>
<Input name="node" defaultValue={data.node || ''} label="Node"/>
<Input name="node" defaultValue={data.node} label="Node"/>
</Form.Field>
<Form.Field>
<Input name="type" defaultValue={data.type} label="Type" placeholder="預設請留空"/>
</Form.Field>
<Grid columns={2}>
<Grid.Column>

View File

@ -101,6 +101,7 @@ class ModbusPage extends React.Component {
submitIOModal = (type, data) => {
let {i18n} = this.props;
if((type == 1 && !data.id) || !('addr' in data) || !('num' in data) || !('type' in data)) return this.props.showDialog(i18n.t('tip.input_empty'));
if(data.datalen == 0) return this.props.showDialog('資料長度不能為0');
data.devuid = this.state.showDev;
if(type == 1){