export default class ManageCookie{
/**
* 存储cookie
* @param {*} name
* @param {*} value
* @param {*} time 单位:秒
*/
static setCookie (name, value, time) {
document && (document.cookie = `${name}=${value}; max-age=${time}`)
}
/**
* 获取cookie
* @param {*} name
*/
static getCookie (name) {
if (document && new RegExp(name).test(document.cookie)) {
const cookies = document.cookie.split("; ").map(str => {
const arr = str.split("=")
if (arr[1]) {
return [arr[0].trim(), arr[1].trim()]
}
return [undefined, undefined]
})
return cookies.find(c=> c[0] === name)[1]
}
return null
}
/**
* 移除cookie
* @param {*} name
*/
static removeCookie (name) {
this.setCookie(name, "", 0)
}
}
|