diff --git a/includes/language/zh.json b/includes/language/zh.json index 9228395..ab828ea 100644 --- a/includes/language/zh.json +++ b/includes/language/zh.json @@ -60,6 +60,7 @@ "ERR0058": "timezone輸入錯誤", "ERR0059": "timezone設定失敗", "ERR0060": "手環ID輸入錯誤", + "ERR0061": "手環ID已存在", "ERR7000": "命令執行失敗", diff --git a/public/js/admin_bundle.js b/public/js/admin_bundle.js index cbc939f..b819b37 100644 --- a/public/js/admin_bundle.js +++ b/public/js/admin_bundle.js @@ -84787,10 +84787,10 @@ var IOPanel = function (_React$Component) { _react2.default.createElement( _semanticUiReact.Menu, { attached: 'top', tabular: true }, - _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'DigitOutput', name: '1', active: this.state.tabIdx == "1", onClick: this.tabItemClick }), - _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'DigitInput', name: '2', active: this.state.tabIdx == "2", onClick: this.tabItemClick }), - _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'AnalogyOutput', name: '3', active: this.state.tabIdx == "3", onClick: this.tabItemClick }), - _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'AnalogyInput', name: '4', active: this.state.tabIdx == "4", onClick: this.tabItemClick }), + _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'DigitalOutput', name: '1', active: this.state.tabIdx == "1", onClick: this.tabItemClick }), + _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'DigitalInput', name: '2', active: this.state.tabIdx == "2", onClick: this.tabItemClick }), + _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'AnalogOutput', name: '3', active: this.state.tabIdx == "3", onClick: this.tabItemClick }), + _react2.default.createElement(_semanticUiReact.Menu.Item, { content: 'AnalogInput', name: '4', active: this.state.tabIdx == "4", onClick: this.tabItemClick }), _react2.default.createElement( _semanticUiReact.Menu.Menu, { position: 'right' }, @@ -87814,7 +87814,7 @@ var ListItem = function ListItem(_ref) { _react2.default.createElement( _semanticUiReact.Table.Cell, null, - data.mac + data.wristband ), _react2.default.createElement( _semanticUiReact.Table.Cell, @@ -88143,6 +88143,10 @@ var _WristbandInfo = __webpack_require__(1141); var _WristbandInfo2 = _interopRequireDefault(_WristbandInfo); +var _Location = __webpack_require__(1145); + +var _Location2 = _interopRequireDefault(_Location); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -88179,6 +88183,8 @@ var WristbandPage = function (_React$Component) { return _react2.default.createElement(_LocStatus2.default, null); case 'wristband': return _react2.default.createElement(_WristbandInfo2.default, null); + case 'location': + return _react2.default.createElement(_Location2.default, null); default: return null; } @@ -88222,6 +88228,13 @@ var WristbandPage = function (_React$Component) { } }, '\u624B\u74B0\u540D\u7A31\u8A2D\u5B9A' ), + _react2.default.createElement( + _semanticUiReact.Menu.Item, + { active: this.state.page == 'location', onClick: function onClick() { + _this2.changePage('location'); + } }, + '\u5B9A\u4F4D\u9EDE\u8A2D\u5B9A' + ), _react2.default.createElement( _semanticUiReact.Menu.Item, { active: this.state.page == 'locstatus', onClick: function onClick() { @@ -92941,10 +92954,11 @@ var WristbandInfo = function (_React$Component) { showDialog = _this$props.showDialog, toggleLoading = _this$props.toggleLoading; - + toggleLoading(1); fetch('/api/wristband/getwristbandlist', (0, _actions.getRequest)()).then(function (response) { return response.json(); }).then(function (json) { + toggleLoading(0); if (json.status != 1) return showDialog(json.message); _this.setState({ list: json.data.record || [] @@ -93041,6 +93055,26 @@ var WristbandInfo = function (_React$Component) { _semanticUiReact.Table.HeaderCell, null, '\u624B\u74B0\u540D\u7A31' + ), + _react2.default.createElement( + _semanticUiReact.Table.HeaderCell, + null, + '\u8EAB\u4EFD' + ), + _react2.default.createElement( + _semanticUiReact.Table.HeaderCell, + null, + '\u76E3\u63A7' + ), + _react2.default.createElement( + _semanticUiReact.Table.HeaderCell, + null, + '\u901A\u77E5' + ), + _react2.default.createElement( + _semanticUiReact.Table.HeaderCell, + null, + '\u555F\u7528' ) ) ), @@ -93158,6 +93192,26 @@ var ListItem = function ListItem(_ref) { _semanticUiReact.Table.Cell, null, data.name + ), + _react2.default.createElement( + _semanticUiReact.Table.Cell, + null, + data.identity + ), + _react2.default.createElement( + _semanticUiReact.Table.Cell, + null, + data.monitor == 1 ? '啟用' : '停用' + ), + _react2.default.createElement( + _semanticUiReact.Table.Cell, + null, + data.notify == 1 ? '啟用' : '停用' + ), + _react2.default.createElement( + _semanticUiReact.Table.Cell, + null, + data.switch == 1 ? '啟用' : '停用' ) ); }; @@ -93279,5 +93333,147 @@ var WristbandModal = function WristbandModal(_ref) { }; exports.default = WristbandModal; +/***/ }), +/* 1144 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _react = __webpack_require__(0); + +var _react2 = _interopRequireDefault(_react); + +var _semanticUiReact = __webpack_require__(8); + +var _actions = __webpack_require__(22); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var stateDefault = function stateDefault() { + return { + list: [], + modal: { + open: false, + type: 0, + data: {} + } + }; +}; + +var Location = function (_React$Component) { + _inherits(Location, _React$Component); + + function Location() { + var _ref; + + var _temp, _this, _ret; + + _classCallCheck(this, Location); + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Location.__proto__ || Object.getPrototypeOf(Location)).call.apply(_ref, [this].concat(args))), _this), _this.state = _extends({}, stateDefault()), _this.getList = function () { + var _this$props = _this.props, + showDialog = _this$props.showDialog, + toggleLoading = _this$props.toggleLoading; + + toggleLoading(1); + fetch('/api/wristband/getlocationlist', (0, _actions.getRequest)()).then(function (response) { + return response.json(); + }).then(function (json) { + toggleLoading(0); + if (json.status != 1) return showDialog(json.message); + _this.setState({ + list: json.data.record || [] + }); + }); + }, _temp), _possibleConstructorReturn(_this, _ret); + } + + _createClass(Location, [{ + key: 'componentDidMount', + value: function componentDidMount() { + this.getList(); + } + }, { + key: 'render', + value: function render() { + + return _react2.default.createElement( + _semanticUiReact.Container, + { fluid: true }, + _react2.default.createElement( + _semanticUiReact.Segment, + { className: 'clearfix' }, + _react2.default.createElement(_semanticUiReact.Button, { floated: 'right', basic: true, color: 'green', style: { marginBottom: '15px' }, content: '\u65B0\u589E', icon: 'plus' }) + ) + ); + } + }]); + + return Location; +}(_react2.default.Component); + +exports.default = Location; + +/***/ }), +/* 1145 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _reactRedux = __webpack_require__(25); + +var _actions = __webpack_require__(22); + +var _Location = __webpack_require__(1144); + +var _Location2 = _interopRequireDefault(_Location); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var mapStateToProps = function mapStateToProps(state) { + return { + i18n: state.i18n + }; +}; + +var mapDispatchToProps = function mapDispatchToProps(dispatch, ownProps) { + return { + showDialog: function showDialog(msg) { + dispatch((0, _actions.add_dialog_msg)(msg)); + }, + toggleLoading: function toggleLoading() { + var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + dispatch((0, _actions.toggle_loading)(flag)); + } + }; +}; + +exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_Location2.default); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/public/locales/zh.json b/public/locales/zh.json index 3a78a8d..fb0bca9 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -344,8 +344,8 @@ "porttype": [ { "code": "1", "name": "DigitalOutput" }, { "code": "2", "name": "DigitalInput" }, - { "code": "3", "name": "AnalogyOutput" }, - { "code": "4", "name": "AnalogyInput" } + { "code": "3", "name": "AnalogOutput" }, + { "code": "4", "name": "AnalogInput" } ], "select": { "select_action": "請選擇動作", diff --git a/route/api/wristband.js b/route/api/wristband.js index 2cb3202..1e96a91 100644 --- a/route/api/wristband.js +++ b/route/api/wristband.js @@ -128,7 +128,7 @@ router .post('/getstatus', (req, res, n) => { if (!config.permission.wristband) return n('ERR9000'); - let query = "select w.`name`, coalesce(l.`name`, l2.`name`) as locname, ll.*\ + let query = "select w.`name`, w.`mac` as wristband, coalesce(l.`name`, l2.`name`) as locname, ll.*\ from ??.?? w\ left join ( \ select * from ( \ @@ -145,7 +145,8 @@ router left join ??.?? l2\ on \ l2.`serialnumber` = ll.`devid` \ - "; + where \ + w.`switch` = 1 "; let param = [config.db.db9, 'wristband', config.db.db9, 'rawdata', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location', ]; let sortfield = ''; @@ -233,25 +234,32 @@ router if (!arr.data) return n('ERR0000') if (!arr.data.mac) return n('ERR0060'); - let name = arr.data.name || ''; - let identity = arr.data.identity || 0; - let monitor = arr.data.monitor || 0; - let notify = arr.data.notify || 0; - let sw = arr.data.switch || 0; - - let query = "insert into ??.?? (`mac`, `name`, `identity`, `monitor`, `notify`, `switch`, `ctime`, `mtime`) values \ - ( ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp() )"; - let param = [config.db.db9, 'wristband', arr.data.mac, name, identity, monitor, notify, sw]; + let query = "select count(*) as c from ??.?? where `mac` = ?"; + let param = [config.db.db9, 'wristband', arr.data.mac]; res.db.query(query, param, (err, row) => { - if (err) return rt.err(res, err, n, 'ERR8001'); + if (err || row.length == 0) return rt.err(res, err, n, "ERR8000"); + if (row[0].c > 0) return n("ERR0061"); - res.api_res = { - record: [] - }; - n(); - }); + let name = arr.data.name || ''; + let identity = arr.data.identity || 0; + let monitor = arr.data.monitor || 0; + let notify = arr.data.notify || 0; + let sw = arr.data.switch || 0; + let query = "insert into ??.?? (`mac`, `name`, `identity`, `monitor`, `notify`, `switch`, `ctime`, `mtime`) values \ + ( ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp() )"; + let param = [config.db.db9, 'wristband', arr.data.mac, name, identity, monitor, notify, sw]; + + res.db.query(query, param, (err, row) => { + if (err) return rt.err(res, err, n, 'ERR8001'); + + res.api_res = { + record: [] + }; + n(); + }); + }) }) .post('/editwristband', (req, res, n) => { if (!config.permission.wristband) return n('ERR9000'); @@ -285,6 +293,25 @@ router n(); }) }) + .post('/getlocationlist', (req, res, n) => { + if (!config.permission.wristband) return n('ERR9000'); + + let query = "select * from ??.??"; + let param = [config.db.db9, 'location']; + + res.db.query(query, param, (err, row) => { + if (err) return rt.err(res, err, n, "ERR8000"); + + res.api_res = { + record: tool.checkArray(row) + } + n(); + }); + }) + .post('/addlocation', (req, res, n) => { + if (!config.permission.wristband) return n('ERR9000'); + if (!tool.checkPermission(req)) return n('ERR9000'); + }) .all('*', rt.send); module.exports = router; \ No newline at end of file diff --git a/src/components/AdminPage/Modbus/IOPanel.js b/src/components/AdminPage/Modbus/IOPanel.js index b6284b9..2f06cf9 100644 --- a/src/components/AdminPage/Modbus/IOPanel.js +++ b/src/components/AdminPage/Modbus/IOPanel.js @@ -41,10 +41,10 @@ class IOPanel extends React.Component { return (