diff --git a/src/api/method.js b/src/api/method.js index 557c4988..5c4742d3 100644 --- a/src/api/method.js +++ b/src/api/method.js @@ -231,6 +231,37 @@ function changeOwnership(classify, selectProjectId, selectPeopleArr) { }); } +//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 = { @@ -254,7 +285,8 @@ export { getWeek, autoComma, formatNumber, - + setCookie, + getCookie, scrollLoad, changeOwnership, commonData,