mirror of
https://github.com/1024-lab/smart-admin.git
synced 2026-06-09 23:36:09 +00:00
v3.15.0【新增】升级SaToken到最新版本;【新增】重磅优化 数据字典;【新增】升级wangEditor-next;【新增】优化缓存实现redis与caffeine
This commit is contained in:
@@ -1,53 +1,57 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { dictApi } from '/@/api/support/dict-api';
|
||||
import { smartSentry } from '/@/lib/smart-sentry';
|
||||
import { DICT_SPLIT } from '/@/constants/support/dict-const.js';
|
||||
import _ from 'lodash';
|
||||
|
||||
export const useDictStore = defineStore({
|
||||
id: 'dict',
|
||||
state: () => ({
|
||||
dict: new Array(),
|
||||
// 字典集合
|
||||
dictMap: new Map(),
|
||||
}),
|
||||
|
||||
actions: {
|
||||
// 获取字典
|
||||
getDict(keyCode) {
|
||||
if (keyCode == null && keyCode == '') {
|
||||
return null;
|
||||
// 获取字典数据
|
||||
getDictData(dictCode) {
|
||||
if (!dictCode) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
for (let i = 0; i < this.dict.length; i++) {
|
||||
if (this.dict[i].keyCode == keyCode) {
|
||||
return this.dict[i].value;
|
||||
}
|
||||
let dictDataList = this.dictMap.get(dictCode);
|
||||
return dictDataList ? dictDataList : [];
|
||||
},
|
||||
|
||||
// 获取字典的值名称
|
||||
getDataLabels(dictCode, dataValue) {
|
||||
if (!dataValue) {
|
||||
return '';
|
||||
}
|
||||
let dict = this.getDictData(dictCode);
|
||||
if (dict.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let valueArray = dataValue.split(DICT_SPLIT);
|
||||
let result = [];
|
||||
for (let item of valueArray) {
|
||||
let target = _.find(dict, { dataValue: item });
|
||||
if (target) {
|
||||
result.push(target.dataLabel);
|
||||
}
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
return result.join(DICT_SPLIT);
|
||||
},
|
||||
// 设置字典
|
||||
setDict(keyCode, value) {
|
||||
if (keyCode !== null && keyCode !== '') {
|
||||
this.dict.push({
|
||||
key: keyCode,
|
||||
value: value,
|
||||
});
|
||||
}
|
||||
},
|
||||
// 删除字典
|
||||
removeDict(keyCode) {
|
||||
let flag = false;
|
||||
try {
|
||||
for (let i = 0; i < this.dict.length; i++) {
|
||||
if (this.dict[i].keyCode == keyCode) {
|
||||
this.dict.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
// 初始化字典
|
||||
initData(dictDataList){
|
||||
this.dictMap.clear();
|
||||
for (let data of dictDataList) {
|
||||
let dataArray = this.dictMap.get(data.dictCode);
|
||||
if (!dataArray) {
|
||||
dataArray = [];
|
||||
this.dictMap.set(data.dictCode, dataArray);
|
||||
}
|
||||
} catch (e) {
|
||||
flag = false;
|
||||
dataArray.push(data);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
// 清空字典
|
||||
cleanDict() {
|
||||
this.dict = new Array();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user