// 设置cookie
const setCookie = (cName: string, value: string, expiredays: number = 30) => {
const exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = cName + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
};
// 取回cookie
const getCookie = (cName: string) => {
if (document.cookie.length > 0) {
let cStart = document.cookie.indexOf(cName + "=");
if (cStart !== -1) {
cStart = cStart + cName.length + 1;
let cEnd = document.cookie.indexOf(";", cStart);
if (cEnd === -1) {
cEnd = document.cookie.length;
}
return unescape(document.cookie.substring(cStart, cEnd));
}
}
return "";
};
// 清除cookie
const removeCookie = (name: string) => {
setCookie(name, "", -1);
};