WXL (wul)
6 天以前 a5cba9ab040f6f97558046885dce3017f9bab7e9
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
<template>
  <div class="info-field">
    <label>{{ label }}:</label>
    <template v-if="editing && type === 'select'">
      <el-select :value="value" size="small" style="width:100%" @change="$emit('change', $event)">
        <el-option v-for="o in options" :key="o.value || o" :label="o.label || o" :value="o.value || o" />
      </el-select>
    </template>
    <template v-else-if="editing">
      <el-input :value="value" size="small" @input="$emit('update:modelValue', $event)" />
    </template>
    <span v-else>{{ displayValue }}</span>
  </div>
</template>
 
<script>
export default {
  name: "InfoField",
  props: {
    label: { type: String, default: "" },
    value: { default: "" },
    editing: { type: Boolean, default: false },
    type: { type: String, default: "text" },
    options: { type: Array, default: () => [] },
  },
  computed: {
    displayValue() {
      if (this.type === 'select' && this.options.length) {
        const opt = this.options.find(o => (o.value || o) === this.value);
        return opt ? (opt.label || opt) : (this.value || "-");
      }
      return this.value || "-";
    },
  },
};
</script>
 
<style scoped>
.info-field { font-size: 14px; line-height: 2; }
.info-field label { color: #909399; }
.info-field span { color: #303133; }
</style>