对token增加单独的h5的处理

This commit is contained in:
daihh
2023-03-17 17:22:48 +08:00
parent 005b3e6270
commit 6d66f7362c
2 changed files with 23 additions and 12 deletions

View File

@@ -47,11 +47,6 @@
} }
console.log(pv,'=',options[pv]); console.log(pv,'=',options[pv]);
}); });
//if(params){
console.log(this.redirect+params)
//}
}, },
mounted() { mounted() {
//对cookies进行操作这里是写 //对cookies进行操作这里是写

View File

@@ -2,19 +2,35 @@
const TOKEN_KEY = 'token' const TOKEN_KEY = 'token'
export function getToken() { export function getToken() {
let token=uni.getStorageSync(TOKEN_KEY);
if(!token){ let token='';
token=uni.getStorageSync('userInfo'); // #ifdef H5
if(token){ var ca = document.cookie.split(';');
token=JSON.parse(token).token; 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; return token;
//return uni.getStorageSync(TOKEN_KEY);
} }
export function setToken(token) { export function setToken(token) {
return uni.setStorageSync(TOKEN_KEY,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() { export function removeToken() {