mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-07 01:46:44 +08:00
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
//const TOKEN_KEY = 'XBOE-Access-Token'
|
|
const TOKEN_KEY = 'token'
|
|
|
|
export function getToken() {
|
|
|
|
let token='';
|
|
// #ifdef H5
|
|
var ca = document.cookie.split(';');
|
|
for(var i=0; i<ca.length; i++)
|
|
{
|
|
var c = ca[i].trim();
|
|
if (c.indexOf(TOKEN_KEY)==0){
|
|
token=c.substring(TOKEN_KEY.length+1,c.length);
|
|
break;
|
|
}
|
|
}
|
|
// #endif
|
|
// #ifndef H5
|
|
token = uni.getStorageSync(TOKEN_KEY);
|
|
// #endif
|
|
return token;
|
|
|
|
}
|
|
|
|
export function setToken(token) {
|
|
//如果是h5,token两个小时过期
|
|
// #ifdef H5
|
|
var expires = "max-age="+(2*60*60*1000);
|
|
document.cookie = TOKEN_KEY + "=" + token + ";path=/;" + expires;
|
|
// #endif
|
|
// #ifndef H5
|
|
uni.setStorageSync(TOKEN_KEY,token);
|
|
// #endif
|
|
}
|
|
|
|
export function removeToken() {
|
|
// uni.removeStorageSync(TOKEN_KEY);
|
|
// uni.removeStorageSync('returnUrl');
|
|
// //uni.setStorageSync('oh','quit');
|
|
// uni.removeStorageSync('userInfo');
|
|
// uni.removeStorageSync('inner');
|
|
uni.clearStorageSync();
|
|
// #ifdef H5
|
|
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
document.cookie = "userInfo=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
document.cookie = "inner=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
// #endif
|
|
}
|
|
|
|
export const tokenName='token'; |