diff --git a/src/libs/util.js b/src/libs/util.js index a5d58e93..879af305 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -8,57 +8,33 @@ import { version } from '../../package.json' let util = {} /** - * @description 存储 uuid 到 cookie - * @param {String} value uuid value + * @description 存储 cookie 值 + * @param {String} name cookie name + * @param {String} value cookie value * @param {Object} setting cookie setting */ -util.uuidSet = function (value = '', setting = {}) { +util.cookieSet = function (name = 'default', value = '', setting = {}) { let cookieSetting = { expires: 1 } Object.assign(cookieSetting, setting) - Cookies.set(`d2admin-${version}-uuid`, value, cookieSetting) + Cookies.set(`d2admin-${version}-${name}`, value, cookieSetting) } /** - * @description 得到现在的用户 uuid + * @description 拿到 cookie 值 + * @param {String} name cookie name */ -util.uuidGet = function () { - return Cookies.get(`d2admin-${version}-uuid`) +util.cookieGet = function (name = 'default') { + return Cookies.get(`d2admin-${version}-${name}`) } /** - * @description 删除用户 uuid + * @description 删除 cookie + * @param {String} name cookie name */ -util.uuidRemove = function () { - return Cookies.remove(`d2admin-${version}-uuid`) -} - -/** - * @description 存储 token 到 cookie - * @param {String} value token value - * @param {Object} setting cookie setting - */ -util.tokenSet = function (value = '', setting = {}) { - let cookieSetting = { - expires: 1 - } - Object.assign(cookieSetting, setting) - Cookies.set(`d2admin-${version}-token`, value, cookieSetting) -} - -/** - * @description 得到现在的用户 token - */ -util.tokenGet = function () { - return Cookies.get(`d2admin-${version}-token`) -} - -/** - * @description 删除用户 token - */ -util.tokenRemove = function () { - return Cookies.remove(`d2admin-${version}-token`) +util.cookieRemove = function (name = 'default') { + return Cookies.remove(`d2admin-${version}-${name}`) } /** diff --git a/src/router/index.js b/src/router/index.js index c90c70a4..b065a3c3 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -19,7 +19,7 @@ router.beforeEach((to, from, next) => { if (to.matched.some(r => r.meta.requiresAuth)) { // 这里暂时将cookie里是否存有token作为验证是否登陆的条件 // 请根据自身业务需要修改 - const token = util.tokenGet() + const token = util.cookieGet('token') if (token && token !== 'undefined') { next() } else { diff --git a/src/store/modules/d2admin.js.REMOVED.git-id b/src/store/modules/d2admin.js.REMOVED.git-id index 065ad2a4..71dedf57 100644 --- a/src/store/modules/d2admin.js.REMOVED.git-id +++ b/src/store/modules/d2admin.js.REMOVED.git-id @@ -1 +1 @@ -2372f09c3e06b1cc538901de0bb6cd6c3c21b8f2 \ No newline at end of file +7ef7e525f2d37a8e3fef5528dd88a3b143b5d688 \ No newline at end of file