From b684672ad26e39864a199bd2b9d1b3335417b24b Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 5 Apr 2017 15:10:02 +0800 Subject: [PATCH] update --- public/css/main.css | 22 ++- public/js/admin_bundle.js | 97 +++++++++-- route/api/wristband.js | 156 +++++++++--------- .../AdminPage/Wristband/LocStatus/ListItem.js | 1 + .../AdminPage/Wristband/LocStatus/index.js | 88 ++++++++-- 5 files changed, 256 insertions(+), 108 deletions(-) diff --git a/public/css/main.css b/public/css/main.css index 886013d..10ebe03 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -6,19 +6,25 @@ div#app { } .login-grid { - height: 100%; + height: 100%; } + .login-column { - max-width: 450px; + max-width: 450px; } .clearfix:after { - content: "."; - display: block; - height: 0; - clear: both; - visibility: hidden; + content: "."; + display: block; + height: 0; + clear: both; + visibility: hidden; } + .hide-element { - display: 'none' !important; + display: 'none' !important; +} + +.pointer { + cursor: pointer !important; } \ No newline at end of file diff --git a/public/js/admin_bundle.js b/public/js/admin_bundle.js index 43f51c8..b99bb89 100644 --- a/public/js/admin_bundle.js +++ b/public/js/admin_bundle.js @@ -87851,6 +87851,11 @@ var ListItem = function ListItem(_ref) { null, data.val7 ? '' + parseInt(data.val7, 16) : '' ), + _react2.default.createElement( + _semanticUiReact.Table.Cell, + null, + data.val9 ? '' + parseInt(data.val9, 16) : '' + ), _react2.default.createElement( _semanticUiReact.Table.Cell, null, @@ -87896,6 +87901,11 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen 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 sort_icon = { + "asc": "caret down", + "desc": "caret up" +}; + var LocStatus = function (_React$Component) { _inherits(LocStatus, _React$Component); @@ -87912,7 +87922,11 @@ var LocStatus = function (_React$Component) { return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = LocStatus.__proto__ || Object.getPrototypeOf(LocStatus)).call.apply(_ref, [this].concat(args))), _this), _this.state = { autoRefresh: false, - list: [] + list: [], + sort: { + field: '', + order: '' + } }, _this.tick = null, _this.changeRefresh = function () { _this.setState({ autoRefresh: !_this.state.autoRefresh @@ -87932,7 +87946,11 @@ var LocStatus = function (_React$Component) { toggleLoading = _this$props.toggleLoading, showDialog = _this$props.showDialog; - fetch('/api/wristband/getstatus', (0, _actions.getRequest)()).then(function (response) { + var json = { + sort: _this.state.sort + }; + + fetch('/api/wristband/getstatus', (0, _actions.getRequest)(json)).then(function (response) { return response.json(); }).then(function (json) { if (json.status != 1) return showDialog(json.message); @@ -87940,6 +87958,24 @@ var LocStatus = function (_React$Component) { list: [].concat(_toConsumableArray(json.data.record || [])) }); }); + }, _this.handlerSort = function (tag) { + if (!tag) return; + var sort = _this.state.sort; + if (tag == sort.field) { + if (sort.order == 'asc') sort.order = 'desc';else sort.order = 'asc'; + } else { + sort.field = tag; + sort.order = 'asc'; + } + + _this.setState({ + sort: sort + }, function () { + _this.getList(); + }); + }, _this.renderSortIcon = function (tag) { + if (_this.state.sort.field == tag) return _react2.default.createElement(_semanticUiReact.Icon, { size: 'mini', corner: true, name: sort_icon[_this.state.sort.order] }); + return null; }, _temp), _possibleConstructorReturn(_this, _ret); } @@ -87980,8 +88016,11 @@ var LocStatus = function (_React$Component) { null, _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - '\u624B\u74B0ID' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('mac'); + } }, + '\u624B\u74B0ID', + this.renderSortIcon('mac') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, @@ -87990,33 +88029,59 @@ var LocStatus = function (_React$Component) { ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - '\u6B65\u6578' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val3'); + } }, + '\u6B65\u6578', + this.renderSortIcon('val3') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - '\u5269\u9918\u96FB\u91CF' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val4'); + } }, + '\u5269\u9918\u96FB\u91CF', + this.renderSortIcon('val4') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - 'HR' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val2'); + } }, + 'HR', + this.renderSortIcon('val2') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - 'SBP' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val5'); + } }, + 'SBP', + this.renderSortIcon('val5') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - 'DBP' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val6'); + } }, + 'DBP', + this.renderSortIcon('val6') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, - null, - '\u5361\u8DEF\u91CC' + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val7'); + } }, + '\u5361\u8DEF\u91CC', + this.renderSortIcon('val7') + ), + _react2.default.createElement( + _semanticUiReact.Table.HeaderCell, + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('val9'); + } }, + 'SOS', + this.renderSortIcon('val9') ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, diff --git a/route/api/wristband.js b/route/api/wristband.js index e44cef8..4633faa 100644 --- a/route/api/wristband.js +++ b/route/api/wristband.js @@ -22,14 +22,14 @@ router } let arr = req.query; - if(!arr.mac) return n('ERR0000'); - if(!arr.devid) return n('ERR0000'); + if (!arr.mac) return n('ERR0000'); + if (!arr.devid) return n('ERR0000'); let query = "insert into ??.?? values (null, ?, ?,?,?,?,?,?,?,?,?,?,?,?,unix_timestamp())"; let param = [ config.db.db9, 'rawdata', arr.devid || '', - arr.mac || '', + arr.mac || '', arr.val2 || '', arr.val3 || '', arr.val4 || '', @@ -43,21 +43,21 @@ router arr.timestamp || '', ]; res.db.query(query, param, (err, row) => { - if(err) return n('ERR8001'); + if (err) return n('ERR8001'); res.api_res = { record: [] }; let q = "select count(*) as c from ??.?? where `mac` = ?"; let p = [config.db.db9, 'wristband', arr.mac]; res.db.query(q, p, (err, row) => { - let pros = []; - if(!(err || row.length == 0 || row[0].c > 0)){ - let q = "insert into ??.?? values (null, ?, '', unix_timestamp(), unix_timestamp())"; - let p = [config.db.db9, 'wristband', arr.mac]; - pros.push(tool.promiseQuery(res,q,p,'q1')); - } + let pros = []; + if (!(err || row.length == 0 || row[0].c > 0)) { + let q = "insert into ??.?? values (null, ?, '', unix_timestamp(), unix_timestamp())"; + let p = [config.db.db9, 'wristband', arr.mac]; + pros.push(tool.promiseQuery(res, q, p, 'q1')); + } - let lq = "insert into ??.?? (`mac`, `devid`, `val2`, `val3`, `val4`, `val5`, `val6`, `val7`, `val8`, `val9`, `val10`, `val11`, `timestamp`, `ctime`, `mtime`) values \ + let lq = "insert into ??.?? (`mac`, `devid`, `val2`, `val3`, `val4`, `val5`, `val6`, `val7`, `val8`, `val9`, `val10`, `val11`, `timestamp`, `ctime`, `mtime`) values \ (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp()) ON DUPLICATE KEY \ update \ `devid` = ?, \ @@ -73,46 +73,47 @@ router `val11` = ?, \ `timestamp` = ?, \ `mtime` = unix_timestamp()"; - let lp = [config.db.db9, 'lastdata', - arr.mac, - arr.devid, - arr.val2 || '', - arr.val3 || '', - arr.val4 || '', - arr.val5 || '', - arr.val6 || '', - arr.val7 || '', - arr.val8 || '', - arr.val9 || '', - arr.val10 || '', - arr.val11 || '', - arr.timestamp || '', - arr.devid, - arr.val2 || '', - arr.val3 || '', - arr.val4 || '', - arr.val5 || '', - arr.val6 || '', - arr.val7 || '', - arr.val8 || '', - arr.val9 || '', - arr.val10 || '', - arr.val11 || '', - arr.timestamp || ''] + let lp = [config.db.db9, 'lastdata', + arr.mac, + arr.devid, + arr.val2 || '', + arr.val3 || '', + arr.val4 || '', + arr.val5 || '', + arr.val6 || '', + arr.val7 || '', + arr.val8 || '', + arr.val9 || '', + arr.val10 || '', + arr.val11 || '', + arr.timestamp || '', + arr.devid, + arr.val2 || '', + arr.val3 || '', + arr.val4 || '', + arr.val5 || '', + arr.val6 || '', + arr.val7 || '', + arr.val8 || '', + arr.val9 || '', + arr.val10 || '', + arr.val11 || '', + arr.timestamp || '' + ] - pros.push(tool.promiseQuery(res,lq,lp,'q2')); + pros.push(tool.promiseQuery(res, lq, lp, 'q2')); - Promise.all(pros) - .then(r => { - n() - }) - .catch(err => { - console.log(err); - n(); - }) - - }) - // n(); + Promise.all(pros) + .then(r => { + n() + }) + .catch(err => { + console.log(err); + n(); + }) + + }) + // n(); }) }) .post('*', async(req, res, n) => { @@ -124,27 +125,7 @@ router } n(); }) - .post('/getstatus', (req,res,n) => { - // let query = "select * from \ - // (\ - // select xx.`mac`, xx.`val11`, dd.`val2`, dd.`val3`, dd.`val4`, dd.`val5`, dd.`val6`, dd.`val7`, dd.`val8`, dd.`val9`, dd.`val10`, dd.`timestamp`, l.`name` \ - // from ??.?? xx \ - // left join ??.?? l \ - // on l.`serialnumber` = xx.`devid` \ - // left join ( \ - // select * from (\ - // select * from ??.?? \ - // where `timestamp` > unix_timestamp() - 20 \ - // order by `timestamp` desc \ - // ) t1 group by `mac`\ - // ) dd \ - // on dd.`mac` = xx.`mac`\ - // where xx.`timestamp` > unix_timestamp() - 20 \ - // order by xx.`val11` desc, xx.`timestamp` desc \ - // limit 2147483647\ - // ) x \ - // group by `mac`"; - // let param = [config.db.db9, 'rawdata', config.db.db9, 'location', config.db.db9, 'rawdata'] + .post('/getstatus', (req, res, n) => { let query = "select w.`name`, l.`name` as locname, l2.`name` as last_locname, ll.*\ from ??.?? w\ @@ -163,11 +144,38 @@ router left join ??.?? l2 \ on \ l2.`serialnumber` = ll.`devid` \ - order by w.`uid`"; - let param = [config.db.db9, 'wristband', config.db.db9, 'rawdata', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location',]; + "; + let param = [config.db.db9, 'wristband', config.db.db9, 'rawdata', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location', ]; - res.db.query(query, param, (err,row) => { - if(err) return rt.err(res,err,n,'ERR8000'); + let sortfield = ''; + let sortorder = ''; + + if (req.body.data && req.body.data.sort) { + if (req.body.data.sort.field) sortfield = req.body.data.sort.field; + if (req.body.data.sort.order) sortorder = req.body.data.sort.order; + } + + switch (sortfield) { + case 'mac': + case 'val2': + case 'val3': + case 'val4': + case 'val5': + case 'val6': + case 'val7': + case 'val8': + case 'val9': + case 'val10': + case 'val11': + query += `order by ll.${sortfield} ${sortorder}`; + break; + default: + query += 'order by w.`uid`'; + break; + } + + res.db.query(query, param, (err, row) => { + if (err) return rt.err(res, err, n, 'ERR8000'); res.api_res = { record: tool.checkArray(row) diff --git a/src/components/AdminPage/Wristband/LocStatus/ListItem.js b/src/components/AdminPage/Wristband/LocStatus/ListItem.js index 73de8d7..536f77c 100644 --- a/src/components/AdminPage/Wristband/LocStatus/ListItem.js +++ b/src/components/AdminPage/Wristband/LocStatus/ListItem.js @@ -14,6 +14,7 @@ const ListItem = ({i18n, data}) => { {data.val5 ? `${parseInt(data.val5, 16)}` : ''} {data.val6 ? `${parseInt(data.val6, 16)}` : ''} {data.val7 ? `${parseInt(data.val7, 16)}` : ''} + {data.val9 ? `${parseInt(data.val9, 16)}` : ''} {data.timestamp ? convertTime(data.timestamp, true) : ''} ) diff --git a/src/components/AdminPage/Wristband/LocStatus/index.js b/src/components/AdminPage/Wristband/LocStatus/index.js index 9277c8c..992a41d 100644 --- a/src/components/AdminPage/Wristband/LocStatus/index.js +++ b/src/components/AdminPage/Wristband/LocStatus/index.js @@ -1,12 +1,21 @@ import React from 'react'; -import {Container, Segment, Table, Label, Checkbox} from 'semantic-ui-react'; +import {Container, Segment, Table, Label, Checkbox, Icon} from 'semantic-ui-react'; import {getRequest} from '../../../../actions'; import ListItem from './ListItem'; +const sort_icon = { + "asc": "caret down", + "desc": "caret up" +} + class LocStatus extends React.Component{ state = { autoRefresh: false, - list: [] + list: [], + sort: { + field: '', + order: '' + } } tick = null @@ -40,7 +49,11 @@ class LocStatus extends React.Component{ getList = () => { let {toggleLoading, showDialog} = this.props; - fetch('/api/wristband/getstatus', getRequest()) + let json = { + sort: this.state.sort + }; + + fetch('/api/wristband/getstatus', getRequest(json)) .then(response=>response.json()) .then(json => { if(json.status != 1) return showDialog(json.message); @@ -50,6 +63,30 @@ class LocStatus extends React.Component{ }); } + handlerSort = (tag) => { + if(!tag) return ; + let sort = this.state.sort; + if(tag == sort.field){ + if(sort.order == 'asc') sort.order = 'desc'; + else sort.order = 'asc'; + }else{ + sort.field = tag; + sort.order = 'asc'; + } + + this.setState({ + sort + }, () => { + this.getList(); + }) + } + + renderSortIcon = (tag) => { + if(this.state.sort.field == tag) + return (); + return null; + } + render (){ let {i18n} = this.props; return ( @@ -59,14 +96,45 @@ class LocStatus extends React.Component{ - 手環ID + { this.handlerSort('mac') }}> + 手環ID + { + this.renderSortIcon('mac') + } + 地點 - 步數 - 剩餘電量 - HR - SBP - DBP - 卡路里 + {this.handlerSort('val3')}}> + 步數 + { + this.renderSortIcon('val3') + } + + {this.handlerSort('val4')}}> + 剩餘電量 + { + this.renderSortIcon('val4') + } + + {this.handlerSort('val2')}}> + HR + {this.renderSortIcon('val2')} + + {this.handlerSort('val5')}}> + SBP + {this.renderSortIcon('val5')} + + {this.handlerSort('val6')}}> + DBP + {this.renderSortIcon('val6')} + + {this.handlerSort('val7')}}> + 卡路里 + {this.renderSortIcon('val7')} + + {this.handlerSort('val9')}}> + SOS + {this.renderSortIcon('val9')} + 時間 {/**/}