jiaosong
2023-08-11 c2e4ed1a6e3a14406db471304360cd45ac8177d1
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
<template>
  <div class="value">
    <i class="el-icon-loading" v-if="data == null"></i>
    <slot v-else>{{getValue()}}{{suffix}}</slot>
  </div>
</template>
 
<script>
export default {
  name: 'Value',
  props: {
    data: {
      type: Object
    },
    prop: {
      type: String
    },
    suffix: {
      type: String
    },
    handler: {
      type: Function
    }
  },
  methods: {
    getValue () {
      if (this.data == null) {
        return ''
      }
      if (this.prop == null) {
        return this.data
      }
      const props = this.prop.split('.')
      let i = 0
      let value = this.data
      while (i < props.length) {
        value = value[props[i]]
        i++
      }
      if (this.handler == null) {
        return value
      }
      return this.handler(value)
    }
  }
}
</script>
 
<style scoped lang="scss">
.value {
  word-break: break-all;
  .el-icon-loading {
    font-size: 16px;
    color: #999;
    position: relative;
    top: 1px;
  }
}
</style>