Commit 96619cbc authored by lvxiaowu's avatar lvxiaowu

菜单登录

parent 250cb9fc
......@@ -51,6 +51,8 @@
"devDependencies": {
"cross-fetch": "^3.0.4",
"lodash": "^4.17.15",
"mobx": "^5.15.4",
"mobx-react": "^6.2.2",
"moment": "^2.26.0",
"node-sass": "^4.14.1"
}
......
......@@ -32,7 +32,7 @@ export function api(url: string, options: Options) {
method: type,
headers: {
'Content-Type': 'application/json;charset=utf-8',
Authorization: window.sessionStorage.getItem('token'),
Authorization: window.localStorage.getItem('token'),
...options.header
},
body: type === 'GET' ? '' : formate('post', options.data)
......@@ -47,15 +47,15 @@ export function api(url: string, options: Options) {
res.json().then((r: any) => {
let msg = r.error || r.msg || 'error';
message.error(msg);
if (r.error) {
if (r.error.match(/token/)) {
message.error('登录过期,请重新登录');
window.location.href = '/inclass/login';
}
}
if (options.error && typeof options.error === 'function') {
options.error(r);
}
// if (r.error) {
// if (r.error.match(/token/)) {
// message.error('登录过期,请重新登录');
// window.location.href = '/inclass/login';
// }
// }
// if (options.error && typeof options.error === 'function') {
// options.error(r);
// }
});
}
})
......
......@@ -13,7 +13,7 @@ const AccountName: React.FC = () => {
const [user, set_user] = useState('');
useEffect(() => {
set_user(window.sessionStorage.getItem('user') as string);
set_user(window.localStorage.getItem('user') as string);
}, []);
const { Item } = Menu;
......@@ -25,9 +25,10 @@ const AccountName: React.FC = () => {
);
const handleOk = () => {
window.sessionStorage.removeItem('user');
window.sessionStorage.removeItem('token');
window.localStorage.removeItem('user');
window.localStorage.removeItem('token');
set_pwdModal(false);
window.localStorage.removeItem('routerConf');
window.location.href = '/inclass/login';
};
......
......@@ -18,41 +18,47 @@ interface ConfigI {
const MenuBar: React.FC<ConfigI> = props => {
const [defKey, set_defKey] = useState(
window.sessionStorage.getItem('menu_defKey') || '1'
window.localStorage.getItem('menu_defKey') || '1'
);
const [openKey, set_openKey] = useState(
window.sessionStorage.getItem('menu_openKey') || '1'
window.localStorage.getItem('menu_openKey') || '1'
);
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'
const routerConfStr = window.localStorage.getItem('routerConf') || '';
if (!routerConfStr) {
window.location.href = '/inclass/login';
}
]
}
];
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(() => {
matchPath(routerConf);
......@@ -65,18 +71,18 @@ const MenuBar: React.FC<ConfigI> = props => {
if (routeItem.path === curPathName) {
set_defKey(defKey);
set_openKey(openKey);
window.sessionStorage.setItem('menu_defKey', defKey);
window.sessionStorage.setItem('menu_openKey', openKey);
window.localStorage.setItem('menu_defKey', defKey);
window.localStorage.setItem('menu_openKey', openKey);
}
};
routerConf.map(item => {
if (item.subs.length === 0) {
match(item, item.key, item.key);
match(item, String(item.id), String(item.id));
}
if (item.subs.length) {
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 => {
const CreateItem = (item: any) => {
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>
</Menu.Item>
);
};
const GererateRouter = () => {
return routerConf.map(item => {
return routerConf.map((item: any) => {
if (item.subs && item.subs.length > 0) {
return (
<SubMenu
key={item.key}
key={item.id}
icon={CreateIcon(item.icon)}
title={item.title}
>
{item.subs.map(idx => CreateItem(idx))}
{item.subs.map((idx: any) => CreateItem(idx))}
</SubMenu>
);
} else {
......@@ -116,8 +122,8 @@ const MenuBar: React.FC<ConfigI> = props => {
set_defKey(data.key);
let keyPath = data.keyPath[data.keyPath.length - 1];
set_openKey(keyPath);
window.sessionStorage.setItem('menu_defKey', data.key);
window.sessionStorage.setItem('menu_openKey', keyPath);
window.localStorage.setItem('menu_defKey', data.key);
window.localStorage.setItem('menu_openKey', keyPath);
};
return (
......
......@@ -44,25 +44,74 @@ const Login: React.FC<RouteComponentProps> = () => {
const info = (msg: string) => {
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 submit = () => {
if (isEnable) {
const { history } = props;
api('/yizhi_server/api/user/login', {
api('/51business/api/course/back/login', {
data: {
passport: passport,
account: passport,
password: password
},
error: () => {
set_password('');
}
})
.then(res => {
.then(async res => {
if (res) {
window.sessionStorage.setItem('token', res.token);
window.sessionStorage.setItem('user', passport);
window.localStorage.setItem('token', res.auth_token);
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');
}
})
......
......@@ -4,6 +4,7 @@ import moment from 'moment';
import { Input, Button, Form, DatePicker, Row, Col } from 'antd';
import 'moment/locale/zh-cn';
import List from './list';
import BasicPage from '../../layout/basicPage';
import excelFn from '../../common/excel';
......@@ -26,6 +27,8 @@ interface FilterData {
pageSize?: number;
}
const OrderList: React.FC = () => {
const [courseName, set_courseName] = useState('');
const [userName, set_userName] = useState('');
......
......@@ -13,7 +13,8 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
"jsx": "react",
"experimentalDecorators": true
},
"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