mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-11 03:46:45 +08:00
feat:增加获取用户信息以及token失效跳到登录页
This commit is contained in:
@@ -162,11 +162,47 @@ function autoComma(number) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//把token存到cookie
|
||||
//name 字段名 value 字段值 perpetual 有效期
|
||||
const setCookie = (name, value, perpetual) => {
|
||||
console.log('存储token到cookie')
|
||||
let exdate = new Date()
|
||||
exdate.setDate(perpetual * 24 * 60 * 60 * 1000) //exdate.setDate(exdate.getDate() + 365)
|
||||
document.cookie = name + '=' + value + ';expires=' + exdate.toGMTString()
|
||||
//永久有效
|
||||
//document.cookie = name + '=' + value + ';expires=' + 'Fri, 31 Dec 9999 23:59:59 GMT'
|
||||
}
|
||||
//获取cookie数据
|
||||
|
||||
//先写一个方法
|
||||
function getCookie(name) {
|
||||
//1.获取cookie字符串
|
||||
var cookies = document.cookie;
|
||||
//通过;来分割字符串
|
||||
var cookie = cookies.split("; ");
|
||||
// console.log('cookie', cookie)
|
||||
//遍历,使键值对匹配上
|
||||
for (var i = 0; i < cookie.length; i++) {
|
||||
var arr = cookie[i].split("token=");
|
||||
// console.log('arr', arr)
|
||||
console.log('name', name)
|
||||
// if (arr[0] == name) {
|
||||
// console.log('arr[1]', arr[1])
|
||||
// return arr[1];
|
||||
// }
|
||||
// console.log('arr[1]', arr[1])
|
||||
return arr[1]
|
||||
}
|
||||
return "";
|
||||
}
|
||||
//最后通
|
||||
|
||||
|
||||
//新建延迟
|
||||
const commonData = {
|
||||
timeout: 50
|
||||
timeout: 50,
|
||||
}
|
||||
|
||||
// const organizationalTree = [
|
||||
// {
|
||||
// title: "京东方",
|
||||
@@ -376,6 +412,8 @@ export {
|
||||
getWeek,
|
||||
autoComma,
|
||||
formatNumber,
|
||||
setCookie,
|
||||
getCookie,
|
||||
commonData,
|
||||
organizationalTree,
|
||||
iframeUrl,
|
||||
|
||||
Reference in New Issue
Block a user