add timezone setting

This commit is contained in:
Jay 2017-04-05 11:26:30 +08:00
parent 7cfdf4f2af
commit 57a37b047f
5 changed files with 438 additions and 264 deletions

View File

@ -57,6 +57,8 @@
"ERR0055": "Func Code 輸入錯誤", "ERR0055": "Func Code 輸入錯誤",
"ERR0056": "LeOne數量已達上限", "ERR0056": "LeOne數量已達上限",
"ERR0057": "連動資料輸入錯誤", "ERR0057": "連動資料輸入錯誤",
"ERR0058": "timezone輸入錯誤",
"ERR0059": "timezone設定失敗",
"ERR7000": "命令執行失敗", "ERR7000": "命令執行失敗",

File diff suppressed because it is too large Load Diff

View File

@ -63,7 +63,7 @@
/******/ __webpack_require__.p = ""; /******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1138); /******/ return __webpack_require__(__webpack_require__.s = 1139);
/******/ }) /******/ })
/************************************************************************/ /************************************************************************/
/******/ ([ /******/ ([
@ -62129,7 +62129,7 @@ var _i18next2 = _interopRequireDefault(_i18next);
var _semanticUiReact = __webpack_require__(8); var _semanticUiReact = __webpack_require__(8);
var _Form = __webpack_require__(1085); var _Form = __webpack_require__(1086);
var _Form2 = _interopRequireDefault(_Form); var _Form2 = _interopRequireDefault(_Form);
@ -62321,7 +62321,8 @@ exports.default = (0, _reactRedux.connect)()(Root);
/* 1082 */, /* 1082 */,
/* 1083 */, /* 1083 */,
/* 1084 */, /* 1084 */,
/* 1085 */ /* 1085 */,
/* 1086 */
/***/ (function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
@ -62377,7 +62378,6 @@ var loginForm = function loginForm(_ref) {
exports.default = loginForm; exports.default = loginForm;
/***/ }), /***/ }),
/* 1086 */,
/* 1087 */, /* 1087 */,
/* 1088 */, /* 1088 */,
/* 1089 */, /* 1089 */,
@ -62429,7 +62429,8 @@ exports.default = loginForm;
/* 1135 */, /* 1135 */,
/* 1136 */, /* 1136 */,
/* 1137 */, /* 1137 */,
/* 1138 */ /* 1138 */,
/* 1139 */
/***/ (function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";

View File

@ -461,6 +461,27 @@ router
return n(); return n();
}); });
}) })
.post('/settimezone', (req,res,n) => {
if(!tool.checkPermission(req)) return n('ERR9000');
let arr = req.body;
if(!arr.data) return n('ERR0000');
if(!arr.data.timezone) return n('ERR0058');
let cmd = `timedatectl set-timezone ${arr.data.timezone}`;
exec(cmd, (err, stdout, stderr) => {
if(err) return rt.err(res,err, n, 'ERR0059');
let query = "update ??.?? set `value` = ? where `type` = ?";
let param = [config.db.db1, 'system', arr.data.timezone, 'timezone'];
res.db.query(query, param, (err, row) => {
if(err ) return rt.err(res, err, n, 'ERR8002');
res.api_res = {
record: []
}
n();
})
})
})
.all('*', rt.send); .all('*', rt.send);
module.exports = router; module.exports = router;

View File

@ -1,12 +1,14 @@
import React from 'react'; import React from 'react';
import {Form, Input, Button} from 'semantic-ui-react'; import {Form, Input, Button, Label, Message} from 'semantic-ui-react';
import {getRequest} from '../../../actions'; import {getRequest} from '../../../actions';
class TimezoneForm extends React.Component { class TimezoneForm extends React.Component {
state = { state = {
zones: [], zones: [],
zone: '', zone: '',
loc: '' loc: '',
selZone: null,
selLoc: null
} }
componentDidMount(){ componentDidMount(){
@ -38,14 +40,75 @@ class TimezoneForm extends React.Component {
}) })
} }
zonesChange = (data) => {
this.setState({
selZone: data == '' ? null : data
})
}
handleSubmit = () => {
if(this.state.selZone == null || this.state.selLoc == null ) return this.props.showDialog('請選擇區域與城市');
let zone = this.state.zones[this.state.selZone].name;
let loc = this.state.zones[this.state.selZone].location[this.state.selLoc];
fetch('/api/system/settimezone', getRequest({timezone: `${zone}/${loc}`}))
.then(response=>response.json())
.then(json => {
if(json.status != 1) return this.props.showDialog(json.message);
this.setState({
selZone: null,
selLoc: null
}, () => {
this.getZoneSet();
})
})
}
render(){ render(){
return ( return (
<Form> <Form onSubmit={(e,d) => {
<Form.Field> e.preventDefault();
<Input label="系統Timezone" this.handleSubmit();
value={`${this.state.zone}${this.state.zone.length > 0 ? '/' : ''}${this.state.loc}`} /> }} serializer={e=>{
return {};
}}>
<Form.Field inline>
{/*<Input label="Timezone"
value={`${this.state.zone}${this.state.zone.length > 0 ? '/' : ''}${this.state.loc}`}
disabled />*/}
<label>系統Timezone</label>
<Label content={`${this.state.zone}${this.state.zone.length > 0 ? '/' : ''}${this.state.loc}`} basic/>
</Form.Field> </Form.Field>
<Form.Group inline>
<Form.Field>
<label>設定Timezone</label>
<select value={this.state.selZone == null ? '' : this.state.selZone} onChange={e=>{ this.zonesChange(e.target.value); }}>
<option value="">選擇區域</option>
{
this.state.zones.map((t,idx)=>(
<option key={idx} value={idx}>{t.name}</option>
))
}
</select>
</Form.Field>
{
this.state.selZone == null ? null :
(
<Form.Field>
<select value={this.state.selLoc == null ? '' : this.state.selLoc}
onChange={e => { this.setState({selLoc: e.target.value == '' ? null : e.target.value}) }}>
<option value="">選擇城市</option>
{
this.state.zones[this.state.selZone].location.map((t,idx) => (
<option key={idx} value={idx}>{t}</option>
))
}
</select>
</Form.Field>
)
}
</Form.Group>
<Button type="submit" fluid content="更新Timezone" />
</Form> </Form>
) )
} }