Commit d6751b33 authored by rocosen's avatar rocosen

fix:免登录

parent 1787f9ce
import Controller from './controller'; import Controller from './controller';
import store from '../reduxs/store'; import store from '../reduxs/store';
import { setRequest } from '../reduxs/actions'; import { setRequest } from '../reduxs/actions';
import qs from "qs";
import API from '../../commons/utils/api_manager';
import { Constants } from '../../commons/utils/constants';
import axios from 'axios';
class Axios { class Axios {
static async request({ static async request({
url = '', url = '',
...@@ -30,6 +34,22 @@ class Axios { ...@@ -30,6 +34,22 @@ class Axios {
res, res,
}; };
} catch (error) { } catch (error) {
if(error.response.data.errorCode=== '100003'){
let reLoad = await Axios.request_reLoad();
if (reLoad['access_token']) {
localStorage.setItem(Constants.TOKEN_KEY, JSON.stringify(data))
window.location.reload();
}else{
setTimeout(() => {
localStorage.removeItem(Constants.TEMPORARY_TOKEN_KEY);
localStorage.removeItem(Constants.TOKEN_KEY);
}, 3000);
}
}
return;
actions && store.dispatch(setRequest(error)); actions && store.dispatch(setRequest(error));
if (!actions) { if (!actions) {
return { return {
...@@ -40,5 +60,19 @@ class Axios { ...@@ -40,5 +60,19 @@ class Axios {
} }
} }
} }
static request_reLoad() {
let token = localStorage.getItem(Constants.TOKEN_KEY) && JSON.parse(localStorage.getItem(Constants.TOKEN_KEY)).refresh_token
let data = qs.stringify({ 'scope': 'ui', 'grant_type': 'refresh_token', 'refresh_token': token});
return new Promise((resolve, reject) => {
axios.post(API.API_USER_LOGIN, data, {
headers: {
'Authorization': 'Basic YnJvd3Nlcjo=',
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function (response) { resolve(response.data) })
.catch(function (error) { reject(error) })
})
}
} }
export default Axios; export default Axios;
...@@ -40,8 +40,6 @@ const getAssetPath = (...paths: string[]): string => { ...@@ -40,8 +40,6 @@ const getAssetPath = (...paths: string[]): string => {
return path.join(RESOURCES_PATH, ...paths); return path.join(RESOURCES_PATH, ...paths);
}; };
const exeName = path.basename(process.execPath);
let image: any; let image: any;
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
......
...@@ -172,7 +172,7 @@ export default (props) => { ...@@ -172,7 +172,7 @@ export default (props) => {
marginBottom: '10px', marginBottom: '10px',
}} }}
> >
将云挂载到本地文件夹 将云文件挂载到本地文件夹
</Grid> </Grid>
<Grid <Grid
......
...@@ -64,19 +64,35 @@ export default (props) => { ...@@ -64,19 +64,35 @@ export default (props) => {
const [usernameError, setUsernameError] = useState(false); const [usernameError, setUsernameError] = useState(false);
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [passwordError, setPasswordError] = useState(false); const [passwordError, setPasswordError] = useState(false);
const [checked, setChecked] = useState(true); const [checked, setChecked] = useState(localStorage.getItem('stay') && localStorage.getItem('stay') === "1" ? true :false );
useEffect(() => { useEffect(() => {
if(localStorage.getItem(Constants.TOKEN_KEY) && localStorage.getItem('stay') === "1" ){
getUserData();
}
if (!localStorage.getItem('Preferences')) { if (!localStorage.getItem('Preferences')) {
localStorage.setItem( localStorage.setItem(
'Preferences', 'Preferences',
JSON.stringify({ selfStart: true }) JSON.stringify({ selfStart: true })
); );
} }
if(!localStorage.getItem('stay')){
localStorage.setItem(
'stay',
'1'
);
}
}, []); }, []);
const handleChange = (event) => { const handleChange = (event) => {
setChecked(event.target.checked); setChecked(event.target.checked);
localStorage.setItem(
'stay',
event.target.checked ? '1':"2"
);
}; };
const login = async () => { const login = async () => {
......
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