使用vue-data-dict,简化数据字典使用

This commit is contained in:
RuoYi
2021-09-17 15:36:54 +08:00
parent 23270c60bc
commit 12ab8b03d9
28 changed files with 503 additions and 325 deletions

View File

@ -0,0 +1,21 @@
import Vue from 'vue'
import DataDict from '@/utils/dict'
import { getDicts as getDicts } from '@/api/system/dict/data'
function install() {
Vue.use(DataDict, {
metas: {
'*': {
labelField: 'dictLabel',
valueField: 'dictValue',
request(dictMeta) {
return getDicts(dictMeta.type).then(res => res.data)
},
},
},
})
}
export default {
install,
}

View File

@ -1,23 +1,23 @@
<template>
<div>
<template v-for="(item, index) in options">
<template v-if="values.includes(item.dictValue)">
<template v-if="values.includes(item.value)">
<span
v-if="item.listClass == 'default' || item.listClass == ''"
:key="item.dictValue"
v-if="item.raw.listClass == 'default' || item.raw.listClass == ''"
:key="item.value"
:index="index"
:class="item.cssClass"
>{{ item.dictLabel }}</span
:class="item.raw.cssClass"
>{{ item.label }}</span
>
<el-tag
v-else
:disable-transitions="true"
:key="item.dictValue"
:key="item.value"
:index="index"
:type="item.listClass == 'primary' ? '' : item.listClass"
:class="item.cssClass"
:type="item.raw.listClass == 'primary' ? '' : item.raw.listClass"
:class="item.raw.cssClass"
>
{{ item.dictLabel }}
{{ item.label }}
</el-tag>
</template>
</template>
@ -49,4 +49,4 @@ export default {
.el-tag + .el-tag {
margin-left: 10px;
}
</style>
</style>