mirror of
https://github.com/dataease/dataease.git
synced 2026-05-18 17:58:11 +08:00
feat: 增加全局loading
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
46
frontend/src/store/modules/request.js
Normal file
46
frontend/src/store/modules/request.js
Normal 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user