main.js
Vue . prototype. $api. setting. SystemDictType. all ( ) . then ( ( { data} ) => {
loadDictsToLocalStorage ( data)
} )
新增 dictionary.js 放在 Utils文件夹里面
export function getDictByType ( dictType ) {
const dicts = JSON . parse ( localStorage. getItem ( 'dicts' ) || '[]' ) ;
if ( Array. isArray ( dicts) && dicts. length > 0 ) {
return dicts. find ( dict => dict. dictType === dictType) ;
}
console. error ( '字典数据格式不正确或为空' ) ;
return null ;
}
export function getDictLabel ( dictType, dictValue ) {
const dict = getDictByType ( dictType) ;
if ( dict) {
const item = dict. dataList. find ( i => i. dictValue === dictValue) ;
return item ? item. dictLable : '' ;
}
return '' ;
}
export function loadDictsToLocalStorage ( dictData ) {
localStorage. removeItem ( 'dicts' ) ;
localStorage. setItem ( 'dicts' , JSON . stringify ( dictData) ) ;
}
页面使用
< Table : datas= "datas" ref= "table" : border= "true" >
< TableItem title= "事件状态" : render= "messageRender" > < / TableItem>
< / Table>
methods : {
messageRender ( data ) {
return getDictLabel ( 'eventStatus' , data. status. toString ( ) )
}
}