增加字典标签样式回显

pull/77/head
Ricky 3 years ago
parent 5c130cfda6
commit 57f56c2769

@ -0,0 +1,51 @@
<template>
<div>
<template v-for="(item, index) in options">
<template v-if="values.includes(item.dictValue)">
<span
v-if="item.listClass == 'default' || item.listClass == ''"
:key="item.dictValue"
:index="index"
:class="item.cssClass"
>{{ item.dictLabel }}</span
>
<el-tag
v-else
:key="item.dictValue"
:index="index"
:type="item.listClass == 'primary' ? '' : item.listClass"
:class="item.cssClass"
>
{{ item.dictLabel }}
</el-tag>
</template>
</template>
</div>
</template>
<script>
export default {
name: "DictTag",
props: {
options: {
type: Array,
default: null,
},
value: [String, Array],
},
computed: {
values() {
if (this.value) {
return Array.isArray(this.value) ? this.value : [this.value];
} else {
return [];
}
},
},
};
</script>
<style scoped>
.el-tag + .el-tag {
margin-left: 10px;
}
</style>

@ -85,10 +85,19 @@
<el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="字典编码" align="center" prop="dictCode" />
<el-table-column label="字典标签" align="center" prop="dictLabel" />
<el-table-column label="字典标签" align="center" prop="dictLabel">
<template slot-scope="scope">
<span v-if="scope.row.listClass == '' || scope.row.listClass == 'default'">{{scope.row.dictLabel}}</span>
<el-tag v-else :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass">{{scope.row.dictLabel}}</el-tag>
</template>
</el-table-column>
<el-table-column label="字典键值" align="center" prop="dictValue" />
<el-table-column label="字典排序" align="center" prop="dictSort" />
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="statusOptions" :value="scope.row.status"/>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
@ -135,9 +144,22 @@
<el-form-item label="数据键值" prop="dictValue">
<el-input v-model="form.dictValue" placeholder="请输入数据键值" />
</el-form-item>
<el-form-item label="样式属性" prop="cssClass">
<el-input v-model="form.cssClass" placeholder="请输入样式属性" />
</el-form-item>
<el-form-item label="显示排序" prop="dictSort">
<el-input-number v-model="form.dictSort" controls-position="right" :min="0" />
</el-form-item>
<el-form-item label="回显样式" prop="listClass">
<el-select v-model="form.listClass">
<el-option
v-for="item in listClassOptions"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio
@ -162,9 +184,14 @@
<script>
import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data";
import { listType, getType } from "@/api/system/dict/type";
// 使
import DictTag from '@/components/DictTag'
export default {
name: "Data",
components: {
DictTag
},
data() {
return {
//
@ -187,6 +214,33 @@ export default {
title: "",
//
open: false,
//
listClassOptions: [
{
value: "default",
label: "默认"
},
{
value: "primary",
label: "主要"
},
{
value: "success",
label: "成功"
},
{
value: "info",
label: "信息"
},
{
value: "warning",
label: "警告"
},
{
value: "danger",
label: "危险"
}
],
//
statusOptions: [],
//
@ -247,10 +301,6 @@ export default {
this.loading = false;
});
},
//
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
//
cancel() {
this.open = false;
@ -262,6 +312,8 @@ export default {
dictCode: undefined,
dictLabel: undefined,
dictValue: undefined,
cssClass: undefined,
listClass: 'default',
dictSort: 0,
status: "0",
remark: undefined

@ -122,7 +122,11 @@
</router-link>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="statusOptions" :value="scope.row.status"/>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
@ -189,9 +193,14 @@
<script>
import { listType, getType, delType, addType, updateType, refreshCache } from "@/api/system/dict/type";
// 使
import DictTag from '@/components/DictTag'
export default {
name: "Dict",
components: {
DictTag
},
data() {
return {
//
@ -254,10 +263,6 @@ export default {
}
);
},
//
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
//
cancel() {
this.open = false;

Loading…
Cancel
Save