1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <template> <div class="roc-dict-tag"> <template v-for="(v, i) in valueList" :key="v"> <template v-if="optionsObj[v]"> <template v-if="optionsObj[v].elTagType"> <el-tag :type="optionsObj[v].elTagType">{{ optionsObj[v].label }}</el-tag> </template> <template v-else-if="optionsObj[v].elTagClass"> <span :class="[optionsObj[v].elTagClass]">{{ optionsObj[v].label }}</span> <span v-if="i < valueList.length - 1">{{ dot }}</span> </template> <template v-else> <span>{{ optionsObj[v].label }}</span> <span v-if="i < valueList.length - 1">{{ dot }}</span> </template> </template> <template v-else> <span v-if="showValue">{{ v }}</span> </template> </template> </div> </template>
<script setup> import { computed } from "vue";
const props = defineProps({ options: { type: Array, required: true, }, value: { type: [Number, String, Array], required: true, }, showValue: { type: Boolean, default: true, }, dot: { type: String, default: "、", }, });
const optionsObj = computed(() => { const obj = {}; props.options.forEach((item) => { obj[item.value] = item; }); return obj; });
const valueList = computed(() => { let list; if (!Array.isArray(props.value)) { if (typeof props.value === "string" && props.value.indexOf(",") !== -1) { list = props.value.split(","); } else { list = [props.value]; } } else { list = props.value; } return list; }); </script>
<style scoped> .el-tag + .el-tag { margin-left: 10px; } .primary { color: #409eff; } .success { color: #67c23a; } .info { color: #909399; } .warning { color: #e6a23c; } .danger { color: #f56c6c; } </style>
|