Commit 96619cbc authored by lvxiaowu's avatar lvxiaowu

菜单登录

parent 250cb9fc
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
"devDependencies": { "devDependencies": {
"cross-fetch": "^3.0.4", "cross-fetch": "^3.0.4",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"mobx": "^5.15.4",
"mobx-react": "^6.2.2",
"moment": "^2.26.0", "moment": "^2.26.0",
"node-sass": "^4.14.1" "node-sass": "^4.14.1"
} }
......
...@@ -32,7 +32,7 @@ export function api(url: string, options: Options) { ...@@ -32,7 +32,7 @@ export function api(url: string, options: Options) {
method: type, method: type,
headers: { headers: {
'Content-Type': 'application/json;charset=utf-8', 'Content-Type': 'application/json;charset=utf-8',
Authorization: window.sessionStorage.getItem('token'), Authorization: window.localStorage.getItem('token'),
...options.header ...options.header
}, },
body: type === 'GET' ? '' : formate('post', options.data) body: type === 'GET' ? '' : formate('post', options.data)
...@@ -47,15 +47,15 @@ export function api(url: string, options: Options) { ...@@ -47,15 +47,15 @@ export function api(url: string, options: Options) {
res.json().then((r: any) => { res.json().then((r: any) => {
let msg = r.error || r.msg || 'error'; let msg = r.error || r.msg || 'error';
message.error(msg); message.error(msg);
if (r.error) { // if (r.error) {
if (r.error.match(/token/)) { // if (r.error.match(/token/)) {
message.error('登录过期,请重新登录'); // message.error('登录过期,请重新登录');
window.location.href = '/inclass/login'; // window.location.href = '/inclass/login';
} // }
} // }
if (options.error && typeof options.error === 'function') { // if (options.error && typeof options.error === 'function') {
options.error(r); // options.error(r);
} // }
}); });
} }
}) })
......
...@@ -13,7 +13,7 @@ const AccountName: React.FC = () => { ...@@ -13,7 +13,7 @@ const AccountName: React.FC = () => {
const [user, set_user] = useState(''); const [user, set_user] = useState('');
useEffect(() => { useEffect(() => {
set_user(window.sessionStorage.getItem('user') as string); set_user(window.localStorage.getItem('user') as string);
}, []); }, []);
const { Item } = Menu; const { Item } = Menu;
...@@ -25,9 +25,10 @@ const AccountName: React.FC = () => { ...@@ -25,9 +25,10 @@ const AccountName: React.FC = () => {
); );
const handleOk = () => { const handleOk = () => {
window.sessionStorage.removeItem('user'); window.localStorage.removeItem('user');
window.sessionStorage.removeItem('token'); window.localStorage.removeItem('token');
set_pwdModal(false); set_pwdModal(false);
window.localStorage.removeItem('routerConf');
window.location.href = '/inclass/login'; window.location.href = '/inclass/login';
}; };
......
...@@ -18,41 +18,47 @@ interface ConfigI { ...@@ -18,41 +18,47 @@ interface ConfigI {
const MenuBar: React.FC<ConfigI> = props => { const MenuBar: React.FC<ConfigI> = props => {
const [defKey, set_defKey] = useState( const [defKey, set_defKey] = useState(
window.sessionStorage.getItem('menu_defKey') || '1' window.localStorage.getItem('menu_defKey') || '1'
); );
const [openKey, set_openKey] = useState( const [openKey, set_openKey] = useState(
window.sessionStorage.getItem('menu_openKey') || '1' window.localStorage.getItem('menu_openKey') || '1'
); );
const routerConf = [ const routerConfStr = window.localStorage.getItem('routerConf') || '';
{ if (!routerConfStr) {
key: '1', window.location.href = '/inclass/login';
title: '订单列表',
path: '/orderList',
icon: 'icon-gongdan',
subs: []
},
{
key: '2',
title: '兑换码',
path: '',
icon: 'icon-set',
subs: [
{
key: '3',
title: '兑换码列表',
path: '/exchangeCode',
icon: 'icon-jixiao'
},
{
key: '4',
title: '兑换码生成',
path: '/generateCode',
icon: 'icon-people'
} }
] const routerConf = JSON.parse(routerConfStr);
}
]; // const routerConf = [
// {
// id: '1',
// title: '订单列表',
// path: '/orderList',
// icon: 'icon-gongdan',
// subs: []
// },
// {
// id: '2',
// title: '兑换码',
// path: '',
// icon: 'icon-set',
// subs: [
// {
// id: '3',
// title: '兑换码列表',
// path: '/exchangeCode',
// icon: 'icon-jixiao'
// },
// {
// id: '4',
// title: '兑换码生成',
// path: '/generateCode',
// icon: 'icon-people'
// }
// ]
// }
// ];
useEffect(() => { useEffect(() => {
matchPath(routerConf); matchPath(routerConf);
...@@ -65,18 +71,18 @@ const MenuBar: React.FC<ConfigI> = props => { ...@@ -65,18 +71,18 @@ const MenuBar: React.FC<ConfigI> = props => {
if (routeItem.path === curPathName) { if (routeItem.path === curPathName) {
set_defKey(defKey); set_defKey(defKey);
set_openKey(openKey); set_openKey(openKey);
window.sessionStorage.setItem('menu_defKey', defKey); window.localStorage.setItem('menu_defKey', defKey);
window.sessionStorage.setItem('menu_openKey', openKey); window.localStorage.setItem('menu_openKey', openKey);
} }
}; };
routerConf.map(item => { routerConf.map(item => {
if (item.subs.length === 0) { if (item.subs.length === 0) {
match(item, item.key, item.key); match(item, String(item.id), String(item.id));
} }
if (item.subs.length) { if (item.subs.length) {
item.subs.map((d: any) => { item.subs.map((d: any) => {
match(d, d.key, item.key); match(d, String(d.id), String(item.id));
}); });
} }
}); });
...@@ -88,22 +94,22 @@ const MenuBar: React.FC<ConfigI> = props => { ...@@ -88,22 +94,22 @@ const MenuBar: React.FC<ConfigI> = props => {
const CreateItem = (item: any) => { const CreateItem = (item: any) => {
return ( return (
<Menu.Item key={item.key} icon={CreateIcon(item.icon)}> <Menu.Item key={item.id} icon={CreateIcon(item.icon)}>
<Link to={item.path}>{item.title}</Link> <Link to={item.path}>{item.title}</Link>
</Menu.Item> </Menu.Item>
); );
}; };
const GererateRouter = () => { const GererateRouter = () => {
return routerConf.map(item => { return routerConf.map((item: any) => {
if (item.subs && item.subs.length > 0) { if (item.subs && item.subs.length > 0) {
return ( return (
<SubMenu <SubMenu
key={item.key} key={item.id}
icon={CreateIcon(item.icon)} icon={CreateIcon(item.icon)}
title={item.title} title={item.title}
> >
{item.subs.map(idx => CreateItem(idx))} {item.subs.map((idx: any) => CreateItem(idx))}
</SubMenu> </SubMenu>
); );
} else { } else {
...@@ -116,8 +122,8 @@ const MenuBar: React.FC<ConfigI> = props => { ...@@ -116,8 +122,8 @@ const MenuBar: React.FC<ConfigI> = props => {
set_defKey(data.key); set_defKey(data.key);
let keyPath = data.keyPath[data.keyPath.length - 1]; let keyPath = data.keyPath[data.keyPath.length - 1];
set_openKey(keyPath); set_openKey(keyPath);
window.sessionStorage.setItem('menu_defKey', data.key); window.localStorage.setItem('menu_defKey', data.key);
window.sessionStorage.setItem('menu_openKey', keyPath); window.localStorage.setItem('menu_openKey', keyPath);
}; };
return ( return (
......
...@@ -44,25 +44,74 @@ const Login: React.FC<RouteComponentProps> = () => { ...@@ -44,25 +44,74 @@ const Login: React.FC<RouteComponentProps> = () => {
const info = (msg: string) => { const info = (msg: string) => {
message.info(msg); message.info(msg);
}; };
const setMenuData = () => {
return new Promise((resolve, reject) => {
const routerConf = [
{
key: '1',
title: '订单列表',
path: '/orderList',
icon: 'icon-gongdan',
subs: []
},
{
key: '2',
title: '兑换码',
path: '',
icon: 'icon-set',
subs: [
{
key: '3',
title: '兑换码列表',
path: '/exchangeCode',
icon: 'icon-jixiao'
},
{
key: '4',
title: '兑换码生成',
path: '/generateCode',
icon: 'icon-people'
}
]
}
];
api('/51business/api/course/back/menu', {
type: 'GET',
data: {},
error: () => {}
}).then(res => {
console.log('res', res);
window.localStorage.setItem('routerConf', JSON.stringify(routerConf));
resolve();
});
});
};
// 登录按钮 // 登录按钮
const LoginBtn: React.FC<Btn & RouteComponentProps> = props => { const LoginBtn: React.FC<Btn & RouteComponentProps> = props => {
const submit = () => { const submit = () => {
if (isEnable) { if (isEnable) {
const { history } = props; const { history } = props;
api('/yizhi_server/api/user/login', { api('/51business/api/course/back/login', {
data: { data: {
passport: passport, account: passport,
password: password password: password
}, },
error: () => { error: () => {
set_password(''); set_password('');
} }
}) })
.then(res => { .then(async res => {
if (res) { if (res) {
window.sessionStorage.setItem('token', res.token); window.localStorage.setItem('token', res.auth_token);
window.sessionStorage.setItem('user', passport); window.localStorage.setItem('user', passport);
let memuData = await api('/51business/api/course/back/menu', {
type: 'GET'
});
window.localStorage.setItem(
'routerConf',
JSON.stringify(memuData.list)
);
history.push('/orderList'); history.push('/orderList');
} }
}) })
......
...@@ -4,6 +4,7 @@ import moment from 'moment'; ...@@ -4,6 +4,7 @@ import moment from 'moment';
import { Input, Button, Form, DatePicker, Row, Col } from 'antd'; import { Input, Button, Form, DatePicker, Row, Col } from 'antd';
import 'moment/locale/zh-cn'; import 'moment/locale/zh-cn';
import List from './list'; import List from './list';
import BasicPage from '../../layout/basicPage'; import BasicPage from '../../layout/basicPage';
import excelFn from '../../common/excel'; import excelFn from '../../common/excel';
...@@ -26,6 +27,8 @@ interface FilterData { ...@@ -26,6 +27,8 @@ interface FilterData {
pageSize?: number; pageSize?: number;
} }
const OrderList: React.FC = () => { const OrderList: React.FC = () => {
const [courseName, set_courseName] = useState(''); const [courseName, set_courseName] = useState('');
const [userName, set_userName] = useState(''); const [userName, set_userName] = useState('');
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"noEmit": true, "noEmit": true,
"jsx": "react" "jsx": "react",
"experimentalDecorators": true
}, },
"include": ["src"] "include": ["src"]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment