feat: 增加全局loading

This commit is contained in:
fit2cloud-chenyw
2021-03-04 14:58:52 +08:00
parent 2b104fa0f6
commit 02230d5e51
12 changed files with 104 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ import { constantRoutes } from '@/router'
import Layout from '@/layout/index'
const state = {
currentPath: null,
routes: [],
addRoutes: [],
currentRoutes: {}
@@ -14,12 +15,18 @@ const mutations = {
},
SET_CURRENT_ROUTES: (state, routes) => {
state.currentRoutes = routes
},
SET_CURRENT_PATH: (state, path) => {
state.currentPath = path
}
}
const actions = {
GenerateRoutes({ commit }, asyncRouter) {
commit('SET_ROUTERS', asyncRouter)
},
setCurrentPath({ commit }, path) {
commit('SET_CURRENT_PATH', path)
}
}

View File

@@ -0,0 +1,46 @@
const state = {
loadingMap: {}
}
const mutations = {
SET_LOADING_MAP: (state, value) => {
state.loadingMap = value
},
ADD_LOADING: (state, key) => {
if (state.loadingMap.hasOwnProperty(key)) {
const map = state.loadingMap
map[key] += 1
state.loadingMap = map
} else {
const nMap = {}
nMap[key] = 1
state.loadingMap = nMap
}
},
REDUCE_LOADING: (state, key) => {
if (state.loadingMap) {
const map = state.loadingMap
map[key] -= 1
state.loadingMap = map
}
}
}
const actions = {
addLoading({ commit }, data) {
commit('ADD_LOADING', data)
},
reduceLoading({ commit }, data) {
commit('REDUCE_LOADING', data)
}
}
export default {
namespaced: true,
state,
mutations,
actions
}