add page chk login

This commit is contained in:
Jay 2017-03-27 18:11:27 +08:00
parent e2040a181e
commit 52e18de9ac
7 changed files with 150 additions and 27 deletions

View File

@ -65,5 +65,6 @@
"ERR8002": "資料更新失敗",
"ERR8003": "資料刪除失敗",
"ERR8100": "DB連線失敗",
"ERR9000": "操作權限不足"
"ERR9000": "操作權限不足",
"ERR9001": "登入Token無效"
}

View File

@ -80128,6 +80128,10 @@ var _ActionLinkAdd = __webpack_require__(1080);
var _ActionLinkAdd2 = _interopRequireDefault(_ActionLinkAdd);
var _IPCam = __webpack_require__(1127);
var _IPCam2 = _interopRequireDefault(_IPCam);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Routes = _react2.default.createElement(
@ -80144,7 +80148,8 @@ var Routes = _react2.default.createElement(
_react2.default.createElement(_reactRouter.Route, { path: 'modbus', component: _Modbus2.default }),
_react2.default.createElement(_reactRouter.Route, { path: 'link', component: _ActionLink2.default }),
_react2.default.createElement(_reactRouter.Route, { path: 'addlink', component: _ActionLinkAdd2.default }),
_react2.default.createElement(_reactRouter.Route, { path: 'modbuscmd', component: _ModbusCmd2.default })
_react2.default.createElement(_reactRouter.Route, { path: 'modbuscmd', component: _ModbusCmd2.default }),
_react2.default.createElement(_reactRouter.Route, { path: 'ipcam', component: _IPCam2.default })
);
exports.default = Routes;
@ -87352,6 +87357,9 @@ var MainMenu = function MainMenu(_ref) {
_react2.default.createElement(_Item2.default, { toLink: '/admin/link', txt: i18n && 't' in i18n ? i18n.t('menu.item.link') : '', permission: permissions.link, onClick: function onClick() {
return toggleMenu();
} }),
_react2.default.createElement(_Item2.default, { toLink: '/admin/ipcam', txt: i18n && 't' in i18n ? i18n.t('menu.item.ipcam') : '', permission: permissions.ipcam, onClick: function onClick() {
return toggleMenu();
} }),
_react2.default.createElement(_Item2.default, { toLink: '/admin', txt: i18n && 't' in i18n ? i18n.t('menu.item.logout') : '', permission: true, onClick: function onClick() {
sessionStorage.clear();
location.replace('/');
@ -91414,17 +91422,22 @@ var PageRoot = function (_React$Component) {
_createClass(PageRoot, [{
key: 'componentDidMount',
value: function componentDidMount() {
var lang = navigator.language.substring(0, 2);
fetch('/locales/' + lang + '.json').then(function (response) {
if (response.status == 200) return response.json();
return {};
fetch('/api/system/chklogin', (0, _actions.getRequest)()).then(function (response) {
return response.json();
}).then(function (json) {
var lang = Object.keys(json)[0] || '';
_i18next2.default.init({
lng: lang,
resources: json
}, function () {
store.dispatch((0, _actions.set_i18n)(_i18next2.default));
if (json.status != 1) return location.replace('/');
var lang = navigator.language.substring(0, 2);
fetch('/locales/' + lang + '.json').then(function (response) {
if (response.status == 200) return response.json();
return {};
}).then(function (json) {
var lang = Object.keys(json)[0] || '';
_i18next2.default.init({
lng: lang,
resources: json
}, function () {
store.dispatch((0, _actions.set_i18n)(_i18next2.default));
});
});
});
}
@ -91444,5 +91457,97 @@ var PageRoot = function (_React$Component) {
_reactDom2.default.render(_react2.default.createElement(PageRoot, null), document.getElementById('app'));
/***/ }),
/* 1125 */,
/* 1126 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
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);
__webpack_require__(13);
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 IPCamPage = function (_React$Component) {
_inherits(IPCamPage, _React$Component);
function IPCamPage() {
_classCallCheck(this, IPCamPage);
return _possibleConstructorReturn(this, (IPCamPage.__proto__ || Object.getPrototypeOf(IPCamPage)).apply(this, arguments));
}
_createClass(IPCamPage, [{
key: 'render',
value: function render() {
return null;
}
}]);
return IPCamPage;
}(_react2.default.Component);
exports.default = IPCamPage;
/***/ }),
/* 1127 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _reactRedux = __webpack_require__(30);
var _actions = __webpack_require__(24);
var _IPCam = __webpack_require__(1126);
var _IPCam2 = _interopRequireDefault(_IPCam);
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)(_IPCam2.default);
/***/ })
/******/ ]);

View File

@ -272,6 +272,7 @@
"modbus": "Modbus",
"modbuscmd": "Modbus CMD",
"link": "連動",
"ipcam": "網路攝影機",
"logout": "登出"
}
},

View File

@ -393,6 +393,13 @@ router
return n();
})
})
.post('/chklogin', (req,res,n) => {
if(!tool.checkPermission(req)) return n('ERR9001');
res.api_res = {
record: []
}
n();
})
.all('*', rt.send);
module.exports = router;

View File

@ -8,6 +8,7 @@ import routes from './routes';
import thunk from 'redux-thunk';
import {set_i18n} from './actions';
import i18next from 'i18next';
import {getRequest} from './actions';
const middleware = [thunk];
@ -34,22 +35,27 @@ const store = createStore(reducers, NODE_ENV && NODE_ENV == 'production' ? apply
class PageRoot extends React.Component {
componentDidMount(){
let lang = navigator
.language
.substring(0, 2);
fetch(`/locales/${lang}.json`).then(response => {
if (response.status == 200)
return response.json();
return {}
}).then(json => {
let lang = Object.keys(json)[0] || '';
i18next.init({
lng: lang,
resources: json
}, () => {
store.dispatch(set_i18n(i18next));
fetch('/api/system/chklogin', getRequest())
.then(response=>response.json())
.then(json => {
if(json.status != 1) return location.replace('/');
let lang = navigator
.language
.substring(0, 2);
fetch(`/locales/${lang}.json`).then(response => {
if (response.status == 200)
return response.json();
return {}
}).then(json => {
let lang = Object.keys(json)[0] || '';
i18next.init({
lng: lang,
resources: json
}, () => {
store.dispatch(set_i18n(i18next));
})
})
})
})
}
render() {

View File

@ -18,6 +18,7 @@ const MainMenu = ({i18n, show, toggleMenu, children, permissions, showDashboard,
<MItem toLink="/admin/modbus" txt={i18n && 't' in i18n ? i18n.t('menu.item.modbus') : ''} permission={permissions.modbus} onClick={()=>toggleMenu()} />
<MItem toLink="/admin/modbuscmd" txt={i18n && 't' in i18n ? i18n.t('menu.item.modbuscmd') : ''} permission={permissions.modbus} onClick={()=>toggleMenu()} />
<MItem toLink="/admin/link" txt={i18n && 't' in i18n ? i18n.t('menu.item.link') : ''} permission={permissions.link} onClick={()=>toggleMenu()} />
<MItem toLink="/admin/ipcam" txt={i18n && 't' in i18n ? i18n.t('menu.item.ipcam') : ''} permission={permissions.ipcam} onClick={()=>toggleMenu()} />
<MItem toLink="/admin" txt={i18n && 't' in i18n ? i18n.t('menu.item.logout') : ''} permission={true} onClick={()=>{
sessionStorage.clear();
location.replace('/');

View File

@ -13,6 +13,7 @@ import Modbus from './containers/AdminPage/Modbus';
import ModbusCmd from './containers/AdminPage/ModbusCmd';
import ActionLink from './containers/AdminPage/ActionLink';
import ActionLinkAdd from './containers/AdminPage/ActionLinkAdd';
import IPCam from './containers/AdminPage/IPCam';
const Routes = (
<Route path="/admin" component={AdminPage}>
@ -28,6 +29,7 @@ const Routes = (
<Route path="link" component={ActionLink} />
<Route path="addlink" component={ActionLinkAdd} />
<Route path="modbuscmd" component={ModbusCmd} />
<Route path="ipcam" component={IPCam} />
</Route>
);