From 3d1afe5271cd70b48ba56b8dde5b215d70f30870 Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 21 Jul 2022 18:14:53 +0800 Subject: [PATCH] =?UTF-8?q?vue2:=20=E7=A7=BB=E9=99=A4=20js-cookie=20?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=20localStorage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-ui-admin/package.json | 1 - yudao-ui-admin/src/main.js | 6 +-- yudao-ui-admin/src/store/modules/app.js | 60 ++++++++++++------------ yudao-ui-admin/src/views/login.vue | 3 +- yudao-ui-admin/src/views/socialLogin.vue | 2 - 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/yudao-ui-admin/package.json b/yudao-ui-admin/package.json index 11ffd16e2..61608e9a5 100644 --- a/yudao-ui-admin/package.json +++ b/yudao-ui-admin/package.json @@ -50,7 +50,6 @@ "fuse.js": "6.4.3", "highlight.js": "9.18.5", "js-beautify": "1.13.0", - "js-cookie": "3.0.1", "jsencrypt": "3.0.0-rc.1", "nprogress": "0.2.0", "quill": "1.3.7", diff --git a/yudao-ui-admin/src/main.js b/yudao-ui-admin/src/main.js index 9f1be03b8..1413fc539 100644 --- a/yudao-ui-admin/src/main.js +++ b/yudao-ui-admin/src/main.js @@ -1,7 +1,5 @@ import Vue from 'vue' -import Cookies from 'js-cookie' - import Element from 'element-ui' import './assets/styles/element-variables.scss' @@ -84,8 +82,8 @@ import '@/styles/index.scss' */ Vue.use(Element, { - size: Cookies.get('size') || 'medium' // set element-ui default size -}) + size: localStorage.getItem("size") || "medium", // set element-ui default size +}); Vue.config.productionTip = false diff --git a/yudao-ui-admin/src/store/modules/app.js b/yudao-ui-admin/src/store/modules/app.js index 3e22d1c16..623622e10 100644 --- a/yudao-ui-admin/src/store/modules/app.js +++ b/yudao-ui-admin/src/store/modules/app.js @@ -1,66 +1,66 @@ -import Cookies from 'js-cookie' - const state = { sidebar: { - opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, + opened: localStorage.getItem("sidebarStatus") + ? !!+localStorage.getItem("sidebarStatus") + : true, withoutAnimation: false, - hide: false + hide: false, }, - device: 'desktop', - size: Cookies.get('size') || 'medium' -} + device: "desktop", + size: localStorage.getItem("size") || "medium", +}; const mutations = { - TOGGLE_SIDEBAR: state => { + TOGGLE_SIDEBAR: (state) => { if (state.sidebar.hide) { return false; } - state.sidebar.opened = !state.sidebar.opened - state.sidebar.withoutAnimation = false + state.sidebar.opened = !state.sidebar.opened; + state.sidebar.withoutAnimation = false; if (state.sidebar.opened) { - Cookies.set('sidebarStatus', 1) + localStorage.setItem("sidebarStatus", 1); } else { - Cookies.set('sidebarStatus', 0) + localStorage.setItem("sidebarStatus", 0); } }, CLOSE_SIDEBAR: (state, withoutAnimation) => { - Cookies.set('sidebarStatus', 0) - state.sidebar.opened = false - state.sidebar.withoutAnimation = withoutAnimation + localStorage.setItem("sidebarStatus", 0); + state.sidebar.opened = false; + state.sidebar.withoutAnimation = withoutAnimation; }, TOGGLE_DEVICE: (state, device) => { - state.device = device + state.device = device; }, SET_SIZE: (state, size) => { - state.size = size - Cookies.set('size', size) + state.size = size; + localStorage.setItem("size", size); }, SET_SIDEBAR_HIDE: (state, status) => { - state.sidebar.hide = status - } -} + state.sidebar.hide = status; + }, +}; const actions = { toggleSideBar({ commit }) { - commit('TOGGLE_SIDEBAR') + commit("TOGGLE_SIDEBAR"); }, closeSideBar({ commit }, { withoutAnimation }) { - commit('CLOSE_SIDEBAR', withoutAnimation) + commit("CLOSE_SIDEBAR", withoutAnimation); }, toggleDevice({ commit }, device) { - commit('TOGGLE_DEVICE', device) + commit("TOGGLE_DEVICE", device); }, setSize({ commit }, size) { - commit('SET_SIZE', size) + commit("SET_SIZE", size); }, toggleSideBarHide({ commit }, status) { - commit('SET_SIDEBAR_HIDE', status) - } -} + commit("SET_SIDEBAR_HIDE", status); + }, +}; export default { namespaced: true, state, mutations, - actions -} + actions, +}; diff --git a/yudao-ui-admin/src/views/login.vue b/yudao-ui-admin/src/views/login.vue index 034421071..b236cb20f 100644 --- a/yudao-ui-admin/src/views/login.vue +++ b/yudao-ui-admin/src/views/login.vue @@ -106,7 +106,6 @@