提交 30406e11 编写于 作者: guangjun.yang's avatar guangjun.yang

修改cookies写法

详情样式
上级 1f4ec2c7
...@@ -185,28 +185,36 @@ export function formatLeftTimeObj(time, hasZero = true) { ...@@ -185,28 +185,36 @@ export function formatLeftTimeObj(time, hasZero = true) {
} }
} }
export const setCookie = (cname, cvalue, exdays = 30, domain = '.yunqueyi.com') => { //yunqueyi.com export const setCookie = (name, value, time) => {
let d = new Date(), expires = ''; var expires = 30 * 24 * 60 * 60 * 1000; //一天
if (BUILD_ENV === 'dev') { var date = new Date(+new Date() + expires);
domain = window.location.hostname; if (time) {
document.cookie =
name +
'=' +
escape(value) +
'; path=/' +
';expires=' +
date.toUTCString();
} else {
document.cookie = name + '=' + escape(value) + '; path=/';
} }
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); };
expires = `expires=${d.toUTCString()}`;
document.cookie = `${cname}=${cvalue};path=/;${expires};domain=${domain}`;
}
export const getCookie = (cname) => { export const delCookie = key => {
const reg = new RegExp('(^| )' + cname + '=([^;]*)(;|$)'); var expires = -1 * 24 * 60 * 60 * 1000; //一天
const arr = document.cookie.match(reg); var date = new Date(+new Date() + expires);
return arr ? unescape(arr[2]) : null; document.cookie =
} key + '=' + escape('') + '; path=/' + ';expires=' + date.toUTCString(); //这里只需要把Cookie保质期退回一天便可以删除
};
export const delCookie = (cname) => { export const getCookie = key => {
var exp = new Date(); var cookieArr = document.cookie.split('; ');
exp.setTime(exp.getTime() - 1); for (var i = 0; i < cookieArr.length; i++) {
var cval = getCookie(cname); var arr = cookieArr[i].split('=');
if (cval != null) { if (arr[0] === key) {
document.cookie = 'token=; path=/; expires=' + new Date(0).toUTCString(); return arr[1];
document.cookie = 'token=; path=/; domain=.yunqueyi.com; expires=' + new Date(0).toUTCString();
} }
} }
\ No newline at end of file return '';
};
\ No newline at end of file
...@@ -892,7 +892,7 @@ export default { ...@@ -892,7 +892,7 @@ export default {
link: shareUrl, link: shareUrl,
title: this.project.projectName, title: this.project.projectName,
friendtitle: this.project.projectName, friendtitle: this.project.projectName,
desc: this.project.projectName, desc: this.project.projectIntro,
imgUrl: "https://file.yunqueyi.com/logo.png" imgUrl: "https://file.yunqueyi.com/logo.png"
}, },
() => { () => {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册