优化字典数据使用store存取
This commit is contained in:
@ -2,6 +2,7 @@ const getters = {
|
||||
sidebar: state => state.app.sidebar,
|
||||
size: state => state.app.size,
|
||||
device: state => state.app.device,
|
||||
dict: state => state.dict.dict,
|
||||
visitedViews: state => state.tagsView.visitedViews,
|
||||
cachedViews: state => state.tagsView.cachedViews,
|
||||
token: state => state.user.token,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import app from './modules/app'
|
||||
import dict from './modules/dict'
|
||||
import user from './modules/user'
|
||||
import tagsView from './modules/tagsView'
|
||||
import permission from './modules/permission'
|
||||
@ -12,6 +13,7 @@ Vue.use(Vuex)
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
app,
|
||||
dict,
|
||||
user,
|
||||
tagsView,
|
||||
permission,
|
||||
|
50
ruoyi-ui/src/store/modules/dict.js
Normal file
50
ruoyi-ui/src/store/modules/dict.js
Normal file
@ -0,0 +1,50 @@
|
||||
const state = {
|
||||
dict: new Array()
|
||||
}
|
||||
const mutations = {
|
||||
SET_DICT: (state, { key, value }) => {
|
||||
if (key !== null && key !== "") {
|
||||
state.dict.push({
|
||||
key: key,
|
||||
value: value
|
||||
})
|
||||
}
|
||||
},
|
||||
REMOVE_DICT: (state, key) => {
|
||||
try {
|
||||
for (let i = 0; i < state.dict.length; i++) {
|
||||
if (state.dict[i].key == key) {
|
||||
state.dict.splice(i, i)
|
||||
return true
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
CLEAN_DICT: (state) => {
|
||||
state.dict = new Array()
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
// 设置字典
|
||||
setDict({ commit }, data) {
|
||||
commit('SET_DICT', data)
|
||||
},
|
||||
// 删除字典
|
||||
removeDict({ commit }, key) {
|
||||
commit('REMOVE_DICT', key)
|
||||
},
|
||||
// 清空字典
|
||||
cleanDict({ commit }) {
|
||||
commit('CLEAN_DICT')
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
}
|
||||
|
Reference in New Issue
Block a user