add setting wristband

This commit is contained in:
Jay 2017-04-06 16:28:57 +08:00
parent b781efabea
commit e18fa6546b
13 changed files with 826 additions and 62 deletions

View File

@ -59,6 +59,7 @@
"ERR0057": "連動資料輸入錯誤",
"ERR0058": "timezone輸入錯誤",
"ERR0059": "timezone設定失敗",
"ERR0060": "手環ID輸入錯誤",
"ERR7000": "命令執行失敗",

View File

@ -34369,7 +34369,7 @@ var DeviceSelect = function DeviceSelect(_ref) {
permissions.dio ? _react2.default.createElement(
'option',
{ value: 'do' },
i18n && i18n.t ? i18n.t('select.digitoutput') : ''
i18n && i18n.t ? i18n.t('select.digitaloutput') : ''
) : null,
permissions.leone ? _react2.default.createElement(
'option',
@ -88088,8 +88088,11 @@ var LocStatus = function (_React$Component) {
),
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
'\u6642\u9593'
{ className: 'pointer', onClick: function onClick() {
_this2.handlerSort('time');
} },
'\u66F4\u65B0\u6642\u9593',
this.renderSortIcon('time')
)
)
),
@ -88136,6 +88139,10 @@ var _LocStatus = __webpack_require__(1103);
var _LocStatus2 = _interopRequireDefault(_LocStatus);
var _WristbandInfo = __webpack_require__(1141);
var _WristbandInfo2 = _interopRequireDefault(_WristbandInfo);
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"); } }
@ -88165,9 +88172,13 @@ var WristbandPage = function (_React$Component) {
page: page
});
}, _this.getRenderPage = function () {
var i18n = _this.props.i18n;
switch (_this.state.page) {
case 'locstatus':
return _react2.default.createElement(_LocStatus2.default, null);
case 'wristband':
return _react2.default.createElement(_WristbandInfo2.default, null);
default:
return null;
}
@ -88179,9 +88190,11 @@ var WristbandPage = function (_React$Component) {
value: function render() {
var _this2 = this;
var i18n = this.props.i18n;
return _react2.default.createElement(
_semanticUiReact.Container,
{ fluid: true },
{ fluid: true, style: { paddingLeft: '10px', paddingRight: '10px' } },
_react2.default.createElement(
_semanticUiReact.Grid,
null,
@ -88190,7 +88203,7 @@ var WristbandPage = function (_React$Component) {
{ width: 4 },
_react2.default.createElement(
_semanticUiReact.Menu,
{ vertical: true },
{ vertical: true, fluid: true },
_react2.default.createElement(
_semanticUiReact.Menu.Item,
null,
@ -88202,6 +88215,13 @@ var WristbandPage = function (_React$Component) {
_react2.default.createElement(
_semanticUiReact.Menu.Menu,
null,
_react2.default.createElement(
_semanticUiReact.Menu.Item,
{ active: this.state.page == 'wristband', onClick: function onClick() {
_this2.changePage('wristband');
} },
'\u624B\u74B0\u540D\u7A31\u8A2D\u5B9A'
),
_react2.default.createElement(
_semanticUiReact.Menu.Item,
{ active: this.state.page == 'locstatus', onClick: function onClick() {
@ -88259,7 +88279,7 @@ var AlertItem = function AlertItem(_ref) {
_react2.default.createElement(
_semanticUiReact.Grid.Column,
null,
_react2.default.createElement(_semanticUiReact.Label, { basic: true, content: type == 'di' ? "DigitInput" : "LeOne" })
_react2.default.createElement(_semanticUiReact.Label, { basic: true, content: type == 'di' ? "DigitalInput" : "LeOne" })
),
_react2.default.createElement(
_semanticUiReact.Grid.Column,
@ -88271,7 +88291,7 @@ var AlertItem = function AlertItem(_ref) {
_semanticUiReact.Grid.Column,
null,
_react2.default.createElement(_semanticUiReact.Label, { basic: true, content: i18n && i18n.t ? i18n.t('dashboard.label.status') : '' }),
i18n && i18n.t ? type == 'di' ? i18n.t('dashboard.status.digitinput') : i18n.t('dashboard.status.leone') : ''
i18n && i18n.t ? type == 'di' ? i18n.t('dashboard.status.digitalinput') : i18n.t('dashboard.status.leone') : ''
)
);
};
@ -92851,5 +92871,413 @@ var PageRoot = function (_React$Component) {
_reactDom2.default.render(_react2.default.createElement(PageRoot, null), document.getElementById('app'));
/***/ }),
/* 1139 */,
/* 1140 */
/***/ (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);
var _ListItem = __webpack_require__(1142);
var _ListItem2 = _interopRequireDefault(_ListItem);
var _WristbandModal = __webpack_require__(1143);
var _WristbandModal2 = _interopRequireDefault(_WristbandModal);
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 WristbandInfo = function (_React$Component) {
_inherits(WristbandInfo, _React$Component);
function WristbandInfo() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, WristbandInfo);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WristbandInfo.__proto__ || Object.getPrototypeOf(WristbandInfo)).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;
fetch('/api/wristband/getwristbandlist', (0, _actions.getRequest)()).then(function (response) {
return response.json();
}).then(function (json) {
if (json.status != 1) return showDialog(json.message);
_this.setState({
list: json.data.record || []
});
});
}, _this.delWristband = function (id) {
if (!id) return;
fetch('/api/wristband/delwristband', (0, _actions.getRequest)({ id: id })).then(function (response) {
return response.json();
}).then(function (json) {
if (json.status != 1) return showDialog(json.message);
_this.getList();
});
}, _this.openModal = function (type) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_this.setState({
modal: {
type: type,
data: data,
open: true
}
});
}, _this.closeModal = function () {
_this.setState({
modal: _extends({}, stateDefault().modal)
});
}, _this.submitModal = function (type) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _this$props2 = _this.props,
showDialog = _this$props2.showDialog,
toggleLoading = _this$props2.toggleLoading;
if (type == 1 && !data.id) return showDialog('資料取得失敗');
if (type == 0 && !data.mac) return showDialog('請填寫手環ID');
var url = type == 1 ? '/api/wristband/editwristband' : '/api/wristband/addwristband';
fetch(url, (0, _actions.getRequest)(data)).then(function (response) {
return response.json();
}).then(function (json) {
if (json.status != 1) return showDialog(json.message);
_this.setState({
modal: _extends({}, stateDefault().modal)
}, function () {
_this.getList();
});
});
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(WristbandInfo, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.getList();
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var i18n = this.props.i18n;
return _react2.default.createElement(
_semanticUiReact.Container,
{ fluid: true },
_react2.default.createElement(
_semanticUiReact.Segment,
{ className: 'clearfix' },
_react2.default.createElement(_semanticUiReact.Button, { basic: true, color: 'green', icon: 'plus', content: '\u65B0\u589E', floated: 'right', onClick: function onClick() {
_this2.openModal(0);
}, style: { marginBottom: '15px' } }),
_react2.default.createElement(
_semanticUiReact.Table,
null,
_react2.default.createElement(
_semanticUiReact.Table.Header,
null,
_react2.default.createElement(
_semanticUiReact.Table.Row,
null,
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
'\u64CD\u4F5C'
),
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
'\u624B\u74B0ID'
),
_react2.default.createElement(
_semanticUiReact.Table.HeaderCell,
null,
'\u624B\u74B0\u540D\u7A31'
)
)
),
_react2.default.createElement(
_semanticUiReact.Table.Body,
null,
this.state.list.map(function (t, idx) {
return _react2.default.createElement(_ListItem2.default, { key: idx, data: t, i18n: i18n, delWristband: _this2.delWristband, editWristband: _this2.openModal });
})
)
)
),
_react2.default.createElement(_WristbandModal2.default, { i18n: i18n,
open: this.state.modal.open,
type: this.state.modal.type,
data: this.state.modal.data,
closeModal: this.closeModal,
submitModal: this.submitModal })
);
}
}]);
return WristbandInfo;
}(_react2.default.Component);
exports.default = WristbandInfo;
/***/ }),
/* 1141 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _reactRedux = __webpack_require__(25);
var _actions = __webpack_require__(22);
var _WristbandInfo = __webpack_require__(1140);
var _WristbandInfo2 = _interopRequireDefault(_WristbandInfo);
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)(_WristbandInfo2.default);
/***/ }),
/* 1142 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _semanticUiReact = __webpack_require__(8);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var ListItem = function ListItem(_ref) {
var i18n = _ref.i18n,
data = _ref.data,
delWristband = _ref.delWristband,
editWristband = _ref.editWristband;
return _react2.default.createElement(
_semanticUiReact.Table.Row,
null,
_react2.default.createElement(
_semanticUiReact.Table.Cell,
null,
_react2.default.createElement(_semanticUiReact.Button, { content: 'Edit', basic: true, onClick: function onClick() {
editWristband(1, data);
} }),
_react2.default.createElement(_semanticUiReact.Button, { content: 'Delete', basic: true, onClick: function onClick() {
delWristband(data.uid);
} })
),
_react2.default.createElement(
_semanticUiReact.Table.Cell,
null,
data.mac
),
_react2.default.createElement(
_semanticUiReact.Table.Cell,
null,
data.name
)
);
};
exports.default = ListItem;
/***/ }),
/* 1143 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _semanticUiReact = __webpack_require__(8);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var WristbandModal = function WristbandModal(_ref) {
var i18n = _ref.i18n,
open = _ref.open,
type = _ref.type,
data = _ref.data,
closeModal = _ref.closeModal,
submitModal = _ref.submitModal;
return _react2.default.createElement(
_semanticUiReact.Modal,
{ open: open },
_react2.default.createElement(_semanticUiReact.Modal.Header, { content: type == 1 ? '修改資料' : '新增資料' }),
_react2.default.createElement(
_semanticUiReact.Modal.Content,
null,
_react2.default.createElement(
_semanticUiReact.Form,
{ onSubmit: function onSubmit(e, d) {
e.preventDefault();
submitModal(type, d.formData);
}, serializer: function serializer(e) {
var json = {
name: '',
identity: '',
monitor: 0,
notify: 0,
id: type == 1 ? data.uid : '',
mac: ''
};
var mac = e.querySelector('input[name="mac"]');
if (mac && 'value' in mac) json.mac = mac.value;
var name = e.querySelector('input[name="name"]');
if (name && 'value' in name) json.name = name.value;
var identity = e.querySelector('input[name="identity"]');
if (identity && 'value' in identity) json.identity = identity.value;
var monitor = e.querySelector('input[name="monitor"]');
if (monitor && 'checked' in monitor) json.monitor = monitor.checked ? 1 : 0;
var notify = e.querySelector('input[name="notify"]');
if (notify && 'checked' in notify) json.notify = notify.checked ? 1 : 0;
return json;
} },
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { label: '\u624B\u74B0ID', name: 'mac', defaultValue: data.mac, disabled: type == 1 })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { label: '\u540D\u7A31', name: 'name', defaultValue: data.name })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Input, { label: '\u8EAB\u4EFD', name: 'identity', defaultValue: data.identity })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Checkbox, { label: '\u76E3\u63A7', name: 'monitor', defaultChecked: data.monitor == 1 })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Checkbox, { label: '\u901A\u77E5', name: 'notify', defaultChecked: data.notify == 1 })
),
_react2.default.createElement(
_semanticUiReact.Form.Field,
null,
_react2.default.createElement(_semanticUiReact.Checkbox, { label: '\u555F\u7528', name: 'switch', defaultChecked: data.switch == 1 })
),
_react2.default.createElement(
_semanticUiReact.Grid,
{ columns: 2 },
_react2.default.createElement(
_semanticUiReact.Grid.Column,
null,
_react2.default.createElement(_semanticUiReact.Button, { content: '\u9001\u51FA', fluid: true, type: 'submit' })
),
_react2.default.createElement(
_semanticUiReact.Grid.Column,
null,
_react2.default.createElement(_semanticUiReact.Button, { content: '\u53D6\u6D88', fluid: true, type: 'button', onClick: function onClick() {
closeModal();
} })
)
)
)
)
);
};
exports.default = WristbandModal;
/***/ })
/******/ ]);

View File

@ -74,8 +74,8 @@
},
"dio": {
"title": {
"di": "DigitInput",
"do": "DigitOutput"
"di": "DigitalInput",
"do": "DigitalOutput"
},
"form": {
"label": {
@ -255,7 +255,7 @@
},
"status": {
"leone": "無回應(網路問題或是IP/密碼錯誤)",
"digitinput": "觸發"
"digitalinput": "觸發"
}
},
"menu": {
@ -342,8 +342,8 @@
"sun": "週日"
},
"porttype": [
{"code": "1", "name":"DigitOutput"},
{"code": "2", "name":"DigitInput"},
{ "code": "1", "name": "DigitalOutput" },
{ "code": "2", "name": "DigitalInput" },
{ "code": "3", "name": "AnalogyOutput" },
{ "code": "4", "name": "AnalogyInput" }
],
@ -352,7 +352,7 @@
"dev_type": "請選擇裝置類型",
"dev_name": "請選擇裝置",
"action": "請選擇動作",
"digitoutput": "DigitOutput",
"digitaloutput": "DigitalOutput",
"leone": "LeOne",
"iogroup": "IOGroup"
}

View File

@ -176,6 +176,8 @@ router
if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028');
res.db.query(`use ${config.db.db5}`);
let query = "delete d,i,s,rt from ??.?? d \
left join ??.?? i \
on d.`uid` = i.`devuid` \

View File

@ -126,6 +126,7 @@ router
n();
})
.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.*\
from ??.?? w\
@ -172,6 +173,9 @@ router
case 'loc':
query += `order by locname ${sortorder}`;
break;
case 'time':
query += 'order by ll.`timestamp` ' + sortorder;
break;
default:
query += 'order by w.`uid`';
break;
@ -186,6 +190,101 @@ router
n();
})
})
.post('/getwristbandlist', (req, res, n) => {
if (!config.permission.wristband) return n('ERR9000');
let query = "select * from ??.?? ";
let param = [config.db.db9, 'wristband'];
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('/delwristband', (req, res, n) => {
if (!config.permission.wristband) return n('ERR9000');
if (!tool.checkPermission(req)) return n('ERR9000');
let arr = req.body;
if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028');
res.db.query(`use ${config.db.db9}`);
let query = "delete from ??.?? where `uid` = ?";
let param = [config.db.db9, 'wristband', arr.data.id];
res.db.query(query, param, (err, row) => {
if (err) return rt.err(res, err, n, 'ERR8003');
res.api_res = {
record: []
};
n();
});
})
.post('/addwristband', (req, res, n) => {
if (!config.permission.wristband) return n('ERR9000');
if (!tool.checkPermission(req)) return n('ERR9000');
let arr = req.body;
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];
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');
if (!tool.checkPermission(req)) return n('ERR9000');
let arr = req.body;
if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028');
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 = "update ??.?? set \
`name` = ?, \
`identity` = ?, \
`monitor` = ?, \
`notify` = ?, \
`switch` = ?, \
`mtime` = unix_timestamp() \
where \
`uid` = ?";
let param = [config.db.db9, 'wristband', name, identity, monitor, notify, sw, arr.data.id];
res.db.query(query, param, (err, row) => {
if (err) return rt.err(res, err, n, 'ERR8002');
res.api_res = {
record: []
}
n();
})
})
.all('*', rt.send);
module.exports = router;

View File

@ -138,7 +138,10 @@ class LocStatus extends React.Component{
SOS
{this.renderSortIcon('val9')}
</Table.HeaderCell>
<Table.HeaderCell>時間</Table.HeaderCell>
<Table.HeaderCell className="pointer" onClick={()=>{this.handlerSort('time')}}>
更新時間
{this.renderSortIcon('time')}
</Table.HeaderCell>
{/*<Table.HeaderCell></Table.HeaderCell>*/}
</Table.Row>
</Table.Header>

View File

@ -0,0 +1,18 @@
import React from 'react';
import { Table, Button } from 'semantic-ui-react';
const ListItem = ({ i18n, data, delWristband, editWristband }) => {
return (
<Table.Row>
<Table.Cell>
<Button content="Edit" basic onClick={()=>{editWristband(1, data)}} />
<Button content="Delete" basic onClick={()=>{delWristband(data.uid)}} />
</Table.Cell>
<Table.Cell>{data.mac}</Table.Cell>
<Table.Cell>{data.name}</Table.Cell>
</Table.Row>
)
}
export default ListItem;

View File

@ -0,0 +1,67 @@
import React from 'react';
import { Modal, Form, Input, Button, Checkbox, Grid } from 'semantic-ui-react';
const WristbandModal = ({ i18n, open, type, data, closeModal, submitModal }) => {
return (
<Modal open={open}>
<Modal.Header content={type == 1 ? '修改資料' : '新增資料'} />
<Modal.Content>
<Form onSubmit={(e,d)=>{
e.preventDefault();
submitModal(type, d.formData);
}} serializer={e => {
let json = {
name: '',
identity: '',
monitor: 0,
notify: 0,
id: type == 1 ? data.uid : '',
mac: ''
};
let mac = e.querySelector('input[name="mac"]');
if(mac && 'value' in mac) json.mac = mac.value;
let name = e.querySelector('input[name="name"]');
if(name && 'value' in name) json.name = name.value;
let identity = e.querySelector('input[name="identity"]');
if(identity && 'value' in identity) json.identity = identity.value;
let monitor = e.querySelector('input[name="monitor"]');
if(monitor && 'checked' in monitor) json.monitor = monitor.checked ? 1 : 0;
let notify = e.querySelector('input[name="notify"]');
if(notify && 'checked' in notify) json.notify = notify.checked ? 1 : 0;
return json;
}}>
<Form.Field>
<Input label="手環ID" name="mac" defaultValue={data.mac} disabled={type == 1} />
</Form.Field>
<Form.Field>
<Input label="名稱" name="name" defaultValue={data.name} />
</Form.Field>
<Form.Field>
<Input label="身份" name="identity" defaultValue={data.identity} />
</Form.Field>
<Form.Field>
<Checkbox label="監控" name="monitor" defaultChecked={data.monitor == 1} />
</Form.Field>
<Form.Field>
<Checkbox label="通知" name="notify" defaultChecked={data.notify == 1} />
</Form.Field>
<Form.Field>
<Checkbox label="啟用" name="switch" defaultChecked={data.switch == 1} />
</Form.Field>
<Grid columns={2}>
<Grid.Column>
<Button content="送出" fluid type="submit" />
</Grid.Column>
<Grid.Column>
<Button content="取消" fluid type="button" onClick={()=>{ closeModal() }} />
</Grid.Column>
</Grid>
</Form>
</Modal.Content>
</Modal>
)
}
export default WristbandModal;

View File

@ -0,0 +1,120 @@
import React from 'react';
import { Container, Segment, Table, Button } from 'semantic-ui-react';
import {getRequest} from '../../../../actions';
import ListItem from './ListItem';
import WristbandModal from './WristbandModal';
const stateDefault = ()=>({
list: [],
modal: {
open: false,
type: 0,
data: {}
}
})
class WristbandInfo extends React.Component {
state = {
...stateDefault()
}
componentDidMount(){
this.getList();
}
getList = () => {
let {showDialog, toggleLoading} = this.props;
fetch('/api/wristband/getwristbandlist', getRequest())
.then(response=>response.json())
.then(json =>{
if(json.status != 1) return showDialog(json.message);
this.setState({
list: json.data.record || []
})
});
}
delWristband = (id) => {
if(!id) return ;
fetch('/api/wristband/delwristband', getRequest({id}))
.then(response=>response.json())
.then(json=>{
if(json.status!=1) return showDialog(json.message);
this.getList();
})
}
openModal = (type, data = {}) => {
this.setState({
modal: {
type,
data,
open: true
}
})
}
closeModal = () => {
this.setState({
modal: {
...stateDefault().modal
}
})
}
submitModal = (type, data = {}) => {
let {showDialog, toggleLoading} = this.props;
if(type == 1 && !data.id) return showDialog('資料取得失敗');
if(type == 0 && !data.mac) return showDialog('請填寫手環ID');
let url = type == 1 ? '/api/wristband/editwristband' : '/api/wristband/addwristband';
fetch(url, getRequest(data))
.then(response=>response.json())
.then(json => {
if(json.status != 1) return showDialog(json.message);
this.setState({
modal: {...stateDefault().modal}
}, ()=>{
this.getList();
})
})
}
render() {
let { i18n } = this.props;
return (
<Container fluid>
<Segment className="clearfix">
<Button basic color="green" icon="plus" content="新增" floated="right" onClick={()=>{this.openModal(0)}} style={{marginBottom: '15px'}} />
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>操作</Table.HeaderCell>
<Table.HeaderCell>手環ID</Table.HeaderCell>
<Table.HeaderCell>手環名稱</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{
this.state.list.map((t,idx) => (
<ListItem key={idx} data={t} i18n={i18n} delWristband={this.delWristband} editWristband={this.openModal}/>
))
}
</Table.Body>
</Table>
</Segment>
<WristbandModal i18n={i18n}
open={this.state.modal.open}
type={this.state.modal.type}
data={this.state.modal.data}
closeModal={this.closeModal}
submitModal={this.submitModal} />
</Container>
)
}
}
export default WristbandInfo;

View File

@ -1,6 +1,7 @@
import React from 'react';
import {Grid, Container, Segment, Menu, List} from 'semantic-ui-react';
import LocStatus from '../../../containers/AdminPage/Wristband/LocStatus';
import WristbandInfo from '../../../containers/AdminPage/Wristband/WristbandInfo';
class WristbandPage extends React.Component{
state = {
@ -14,24 +15,30 @@ class WristbandPage extends React.Component{
}
getRenderPage = () => {
let {i18n} = this.props;
switch(this.state.page) {
case 'locstatus':
return <LocStatus/>;
case 'wristband':
return <WristbandInfo />
default:
return null;
}
}
render(){
let {i18n} = this.props;
return (
<Container fluid>
<Container fluid style={{paddingLeft: '10px', paddingRight: '10px'}}>
<Grid>
<Grid.Column width={4}>
<Menu vertical={true}>
<Menu vertical={true} fluid>
<Menu.Item>
<Menu.Header>主選單</Menu.Header>
<Menu.Menu>
<Menu.Item active={this.state.page == 'wristband'} onClick={()=>{this.changePage('wristband')}}>
手環名稱設定
</Menu.Item>
<Menu.Item active={this.state.page == 'locstatus'} onClick={()=>{ this.changePage('locstatus'); }}>
位置資訊
</Menu.Item>

View File

@ -14,7 +14,7 @@ const DeviceSelect = ({i18n, querySelectList, page, permissions, devs, addSelect
<option value="">{i18n&&i18n.t?i18n.t('select.dev_type') : ''}</option>
{
permissions.dio ?
<option value="do">{i18n&&i18n.t ? i18n.t('select.digitoutput') : ''}</option> : null
<option value="do">{i18n&&i18n.t ? i18n.t('select.digitaloutput') : ''}</option> : null
}
{
permissions.leone ?

View File

@ -6,14 +6,14 @@ const AlertItem = ({i18n, name, type}) => {
return (
<Grid.Row columns={3} color="red">
<Grid.Column>
<Label basic content={type == 'di' ? "DigitInput" : "LeOne"} />
<Label basic content={type == 'di' ? "DigitalInput" : "LeOne"} />
</Grid.Column>
<Grid.Column>
<Label basic content={i18n&&i18n.t ? i18n.t('dashboard.label.name') : ''} />{name}
</Grid.Column>
<Grid.Column>
<Label basic content={i18n&&i18n.t ? i18n.t('dashboard.label.status') : ''} />
{i18n&&i18n.t ? ( type == 'di' ? i18n.t('dashboard.status.digitinput') : i18n.t('dashboard.status.leone') ): ''}
{i18n&&i18n.t ? ( type == 'di' ? i18n.t('dashboard.status.digitalinput') : i18n.t('dashboard.status.leone') ): ''}
</Grid.Column>
</Grid.Row>
)

View File

@ -0,0 +1,19 @@
import { connect } from 'react-redux';
import { add_dialog_msg, toggle_loading } from '../../../actions';
import WristbandInfo from '../../../components/AdminPage/Wristband/WristbandInfo';
const mapStateToProps = (state) => ({
i18n: state.i18n
});
const mapDispatchToProps = (dispatch, ownProps) => ({
showDialog: (msg) => {
dispatch(add_dialog_msg(msg));
},
toggleLoading: (flag = false) => {
dispatch(toggle_loading(flag));
}
})
export default connect(mapStateToProps, mapDispatchToProps)(WristbandInfo);