Commit 19ae235d by 姜雷

记录菜单状态

parent b7b4ce1e
...@@ -63,6 +63,8 @@ import UserBox from './containers/layout/components/UserBox'; ...@@ -63,6 +63,8 @@ import UserBox from './containers/layout/components/UserBox';
import IconMenus from './containers/layout/IconMenu/IconMenu'; import IconMenus from './containers/layout/IconMenu/IconMenu';
import CollectMenu from './containers/layout/Collect/Collect'; import CollectMenu from './containers/layout/Collect/Collect';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { getStorageData, setStorageData } from '@/utils/auth';
import { STSTEM_STATE_KEY } from '@/config';
export default { export default {
name: 'App', name: 'App',
...@@ -78,15 +80,14 @@ export default { ...@@ -78,15 +80,14 @@ export default {
}, },
}, },
data() { data() {
console.log(this.$route); const { selectedRoute, showFastLink, showSelected } = this.loadRouteState();
return { return {
title: '', title: '',
selectedRoute: [], selectedRoute: selectedRoute,
routerDone: false, routerDone: false,
isInnerPage: false, isInnerPage: false,
showFastLink: false, showFastLink: showFastLink,
showSelected: false, showSelected: showSelected,
}; };
}, },
computed: { computed: {
...@@ -136,11 +137,37 @@ export default { ...@@ -136,11 +137,37 @@ export default {
this.showFastLink = entity; this.showFastLink = entity;
this.showSelected = false; this.showSelected = false;
} }
this.saveRouteState();
}, },
selectRouteMenu(routes) { selectRouteMenu(routes) {
this.selectedRoute = routes; this.selectedRoute = routes;
this.showSelected = true; this.showSelected = true;
this.showFastLink = false; this.showFastLink = false;
this.saveRouteState();
},
saveRouteState() {
const { selectedRoute, showFastLink, showSelected } = this;
setStorageData(
STSTEM_STATE_KEY,
JSON.stringify({
selectedRoute,
showFastLink,
showSelected,
})
);
},
loadRouteState() {
let dataStr = getStorageData(STSTEM_STATE_KEY);
if (dataStr) {
let data = JSON.parse(dataStr);
return data;
} else {
return {
selectedRoute: [],
showFastLink: false,
showSelected: false,
};
}
}, },
}, },
}; };
......
...@@ -56,6 +56,7 @@ service.interceptors.response.use(response => { ...@@ -56,6 +56,7 @@ service.interceptors.response.use(response => {
if (res.code !== SUCCESS_CODE) { if (res.code !== SUCCESS_CODE) {
if ( if (
response.headers && response.headers &&
response.headers['content-type'] &&
/application\/octet-stream/.test( /application\/octet-stream/.test(
response.headers['content-type'].toLowerCase() response.headers['content-type'].toLowerCase()
) )
......
export const TOKEN_KEY = 'dcrym'; export const TOKEN_KEY = 'dcrym';
export const STSTEM_STATE_KEY = 'dcrym-state';
export const SUCCESS_CODE = 1000; export const SUCCESS_CODE = 1000;
export const LOGOUT_CODE = -2; export const LOGOUT_CODE = -2;
......
...@@ -57,6 +57,7 @@ const createBaseFetch = config => { ...@@ -57,6 +57,7 @@ const createBaseFetch = config => {
if (res.code !== SUCCESS_CODE) { if (res.code !== SUCCESS_CODE) {
if ( if (
response.headers && response.headers &&
response.headers['content-type'] &&
/application\/octet-stream/.test( /application\/octet-stream/.test(
response.headers['content-type'].toLowerCase() response.headers['content-type'].toLowerCase()
) )
......
import { TOKEN_KEY } from '@/config/index'; import { TOKEN_KEY, STSTEM_STATE_KEY } from '@/config/index';
const TokenKey = TOKEN_KEY; const TokenKey = TOKEN_KEY;
export function getToken() { export function getToken() {
return sessionStorage.getItem(TokenKey); return getStorageData(TokenKey);
} }
export function setToken(token, expires) { export function setToken(token, expires) {
return sessionStorage.setItem(TokenKey, token); return setStorageData(TokenKey, token);
} }
export function removeToken() { export function removeToken() {
return sessionStorage.removeItem(TOKEN_KEY); removeStorageData(TOKEN_KEY);
removeStorageData(STSTEM_STATE_KEY);
return;
}
export function getStorageData(key) {
return sessionStorage.getItem(key);
}
export function setStorageData(key, data) {
return sessionStorage.setItem(key, data);
}
export function removeStorageData(key) {
return sessionStorage.removeItem(key);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment