调通登录链路

This commit is contained in:
wfnuser 2018-12-26 23:32:10 +08:00
parent ffd184e527
commit 377e5bb936
3 changed files with 34 additions and 2 deletions

View File

@ -603,7 +603,19 @@ const request = (function(_global) {
beforeSend(xhr) {
config.beforeSend && config.beforeSend(xhr);
},
headers: {
Authorization: localStorage.getItem('token'),
},
})
).then(
success => {},
error => {
// 处理403 forbidden
if (error && error.status === 403) {
// 跳转至login页
window.location = '/#/login';
}
}
);
}
// 暴露方法

View File

@ -1,14 +1,33 @@
import React from 'react';
import { Card, Form, Input } from '@alifd/next';
import { Card, Form, Input, Message } from '@alifd/next';
import './index.scss';
import Header from '../../layouts/Header';
import { request } from '../../globalLib';
const FormItem = Form.Item;
class Login extends React.Component {
handleSubmit = values => {
console.log('Get form value:', values);
request({
type: 'get',
url: 'v1/auth/login',
data: values,
success: res => {
if (res.code === 200) {
const data = res.data;
// TODO: token
localStorage.setItem('token', data);
// TODO: 使react router
window.location = '/#/';
}
},
error: () => {
Message.error({
content: '登录失败',
});
},
});
};
render() {

View File

@ -102,6 +102,7 @@ $contentWidth: 1280px;
color: #fff;
max-width: 780px;
margin: 12px auto 30px;
text-align: left;
}
}
}