修改公共配置字典

This commit is contained in:
wuweihua
2026-09-08 10:51:20 +08:00
parent 647be14d66
commit 38796d8683
25 changed files with 389 additions and 80 deletions
+41 -7
View File
@@ -1,13 +1,16 @@
import { getDictAll } from '@/api/system/dict/data'
const useDictStore = defineStore(
'dict',
{
state: () => ({
dict: new Array()
dict: new Array(),
loaded: false
}),
actions: {
// 获取字典
getDict(_key) {
if (_key == null && _key == "") {
if (_key == null || _key === '') {
return null
}
try {
@@ -19,19 +22,49 @@ const useDictStore = defineStore(
} catch (e) {
return null
}
return null
},
// 设置字典
// 设置字典(同 key 覆盖)
setDict(_key, value) {
if (_key !== null && _key !== "") {
if (_key !== null && _key !== '') {
for (let i = 0; i < this.dict.length; i++) {
if (this.dict[i].key == _key) {
this.dict[i].value = value
return
}
}
this.dict.push({
key: _key,
value: value
})
}
},
// 全量写入:{ dictType: [{dictLabel,dictValue,...}] }
setDictMap(dictMap) {
this.cleanDict()
if (!dictMap || typeof dictMap !== 'object') {
return
}
Object.keys(dictMap).forEach(dictType => {
const list = dictMap[dictType] || []
this.setDict(dictType, list.map(p => ({
label: p.dictLabel,
value: p.dictValue,
elTagType: p.listClass,
elTagClass: p.cssClass
})))
})
this.loaded = true
},
// 登录后单独拉取全量字典
loadAllDicts() {
return getDictAll().then(res => {
this.setDictMap(res.data || {})
return res.data
})
},
// 删除字典
removeDict(_key) {
var bln = false
try {
for (let i = 0; i < this.dict.length; i++) {
if (this.dict[i].key == _key) {
@@ -40,13 +73,14 @@ const useDictStore = defineStore(
}
}
} catch (e) {
bln = false
return false
}
return bln
return false
},
// 清空字典
cleanDict() {
this.dict = new Array()
this.loaded = false
},
// 初始字典
initDict() {
+2
View File
@@ -5,6 +5,7 @@ import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { isHttp, isEmpty } from "@/utils/validate"
import useLockStore from '@/store/modules/lock'
import useDictStore from '@/store/modules/dict'
import defAva from '@/assets/images/profile.jpg'
const useUserStore = defineStore(
@@ -82,6 +83,7 @@ const useUserStore = defineStore(
this.token = ''
this.roles = []
this.permissions = []
useDictStore().cleanDict()
removeToken()
resolve()
}).catch(error => {