2018-08-09 09:52:52 +08:00
|
|
|
import Cookies from 'js-cookie'
|
2018-08-21 23:25:57 +08:00
|
|
|
import setting from '@/setting.js'
|
2018-08-09 09:52:52 +08:00
|
|
|
|
|
|
|
|
const cookies = {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 存储 cookie 值
|
|
|
|
|
* @param {String} name cookie name
|
|
|
|
|
* @param {String} value cookie value
|
|
|
|
|
* @param {Object} setting cookie setting
|
|
|
|
|
*/
|
2018-08-21 23:25:57 +08:00
|
|
|
cookies.set = function (name = 'default', value = '', cookieSetting = {}) {
|
|
|
|
|
let currentCookieSetting = {
|
2018-08-09 09:52:52 +08:00
|
|
|
expires: 1
|
|
|
|
|
}
|
2018-08-21 23:25:57 +08:00
|
|
|
Object.assign(currentCookieSetting, cookieSetting)
|
|
|
|
|
Cookies.set(`d2admin-${setting.releases.version}-${name}`, value, currentCookieSetting)
|
2018-08-09 09:52:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 拿到 cookie 值
|
|
|
|
|
* @param {String} name cookie name
|
|
|
|
|
*/
|
|
|
|
|
cookies.get = function (name = 'default') {
|
2018-08-21 23:25:57 +08:00
|
|
|
return Cookies.get(`d2admin-${setting.releases.version}-${name}`)
|
2018-08-09 09:52:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 拿到 cookie 全部的值
|
|
|
|
|
*/
|
|
|
|
|
cookies.getAll = function () {
|
|
|
|
|
return Cookies.get()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 删除 cookie
|
|
|
|
|
* @param {String} name cookie name
|
|
|
|
|
*/
|
|
|
|
|
cookies.remove = function (name = 'default') {
|
2018-08-21 23:25:57 +08:00
|
|
|
return Cookies.remove(`d2admin-${setting.releases.version}-${name}`)
|
2018-08-09 09:52:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default cookies
|