构建框架
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @description 自动import导入所有 vuex 模块
|
||||
*/
|
||||
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
const files = require.context('./modules', false, /\.js$/);
|
||||
const modules = {}
|
||||
files.keys().forEach((key) => {
|
||||
modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
|
||||
})
|
||||
|
||||
export default createStore({
|
||||
modules
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import config from "@/config";
|
||||
|
||||
export default {
|
||||
state: {
|
||||
//移动端布局
|
||||
ismobile: false,
|
||||
//布局
|
||||
layout: config.LAYOUT,
|
||||
//菜单是否折叠 toggle
|
||||
menuIsCollapse: config.MENU_IS_COLLAPSE,
|
||||
//多标签栏
|
||||
layoutTags: config.LAYOUT_TAGS,
|
||||
//主题
|
||||
theme: config.THEME,
|
||||
},
|
||||
mutations: {
|
||||
SET_ismobile(state, key){
|
||||
state.ismobile = key
|
||||
},
|
||||
SET_layout(state, key){
|
||||
state.layout = key
|
||||
},
|
||||
SET_theme(state, key){
|
||||
state.theme = key
|
||||
},
|
||||
TOGGLE_menuIsCollapse(state){
|
||||
state.menuIsCollapse = !state.menuIsCollapse
|
||||
},
|
||||
TOGGLE_layoutTags(state){
|
||||
state.layoutTags = !state.layoutTags
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
export default {
|
||||
state: {
|
||||
iframeList: []
|
||||
},
|
||||
mutations: {
|
||||
setIframeList(state, route){
|
||||
state.iframeList = []
|
||||
state.iframeList.push(route)
|
||||
},
|
||||
pushIframeList(state, route){
|
||||
let target = state.iframeList.find((item) => item.path === route.path)
|
||||
if(!target){
|
||||
state.iframeList.push(route)
|
||||
}
|
||||
},
|
||||
removeIframeList(state, route){
|
||||
state.iframeList.forEach((item, index) => {
|
||||
if (item.path === route.path){
|
||||
state.iframeList.splice(index, 1)
|
||||
}
|
||||
})
|
||||
},
|
||||
refreshIframe(state, route){
|
||||
state.iframeList.forEach((item) => {
|
||||
if (item.path == route.path){
|
||||
var url = route.meta.url;
|
||||
item.meta.url = '';
|
||||
setTimeout(function() {
|
||||
item.meta.url = url
|
||||
}, 200);
|
||||
}
|
||||
})
|
||||
},
|
||||
clearIframeList(state){
|
||||
state.iframeList = []
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
export default {
|
||||
state: {
|
||||
keepLiveRoute: [],
|
||||
routeKey: null,
|
||||
routeShow: true
|
||||
},
|
||||
mutations: {
|
||||
pushKeepLive(state, component){
|
||||
if(!state.keepLiveRoute.includes(component)){
|
||||
state.keepLiveRoute.push(component)
|
||||
}
|
||||
},
|
||||
removeKeepLive(state, component){
|
||||
var index = state.keepLiveRoute.indexOf(component);
|
||||
if(index !== -1){
|
||||
state.keepLiveRoute.splice(index, 1);
|
||||
}
|
||||
},
|
||||
clearKeepLive(state){
|
||||
state.keepLiveRoute = []
|
||||
},
|
||||
setRouteKey(state, key){
|
||||
state.routeKey = key
|
||||
},
|
||||
setRouteShow(state, key){
|
||||
state.routeShow = key
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setRouteKey({ commit }, key) {
|
||||
commit('setRouteKey', key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import router from '@/router'
|
||||
|
||||
export default {
|
||||
state: {
|
||||
viewTags: []
|
||||
},
|
||||
mutations: {
|
||||
pushViewTags(state, route){
|
||||
let backPathIndex = state.viewTags.findIndex(item => item.fullPath == router.options.history.state.back)
|
||||
let target = state.viewTags.find((item) => item.fullPath === route.fullPath)
|
||||
let isName = route.name
|
||||
if(!target && isName){
|
||||
if(backPathIndex == -1){
|
||||
state.viewTags.push(route)
|
||||
}else{
|
||||
state.viewTags.splice(backPathIndex+1, 0, route)
|
||||
}
|
||||
}
|
||||
},
|
||||
removeViewTags(state, route){
|
||||
state.viewTags.forEach((item, index) => {
|
||||
if (item.fullPath === route.fullPath){
|
||||
state.viewTags.splice(index, 1)
|
||||
}
|
||||
})
|
||||
},
|
||||
updateViewTags(state, route){
|
||||
state.viewTags.forEach((item) => {
|
||||
if (item.fullPath == route.fullPath){
|
||||
item = Object.assign(item, route)
|
||||
}
|
||||
})
|
||||
},
|
||||
updateViewTagsTitle(state, title=''){
|
||||
const nowFullPath = location.hash.substring(1)
|
||||
state.viewTags.forEach((item) => {
|
||||
if (item.fullPath == nowFullPath){
|
||||
item.meta.title = title
|
||||
}
|
||||
})
|
||||
},
|
||||
clearViewTags(state){
|
||||
state.viewTags = []
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user