Blame view

ant-design-vue-jeecg/src/components/chart/Trend.vue 1.43 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
<template>
  <div class="chart-trend">
    {{ term }}
    <span>{{ rate }}%</span>
    <span :class="['trend-icon', trend]"><a-icon :type="'caret-' + trend"/></span>
  </div>
</template>

<script>
肖超群 authored
10
11
12
13
14
15
16
17
export default {
  name: "Trend",
  props: {
    // 同title
    term: {
      type: String,
      default: '',
      required: true
肖超群 authored
18
    },
肖超群 authored
19
20
21
22
23
24
25
26
    // 百分比
    percentage: {
      type: Number,
      default: null
    },
    type: {
      type: Boolean,
      default: null
肖超群 authored
27
    },
肖超群 authored
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    target: {
      type: Number,
      default: 0
    },
    value: {
      type: Number,
      default: 0
    },
    fixed: {
      type: Number,
      default: 2
    }
  },
  data() {
    return {
      trend: this.type && 'up' || 'down',
      rate: this.percentage
肖超群 authored
45
    }
肖超群 authored
46
47
48
49
50
  },
  created() {
    let type = this.type === null ? this.value >= this.target : this.type
    this.trend = type ? 'up' : 'down';
    this.rate = (this.percentage === null ? Math.abs(this.value - this.target) * 100 / this.target : this.percentage).toFixed(this.fixed)
肖超群 authored
51
  }
肖超群 authored
52
}
肖超群 authored
53
54
55
</script>

<style lang="less" scoped>
肖超群 authored
56
57
58
59
.chart-trend {
  display: inline-block;
  font-size: 14px;
  line-height: 22px;
肖超群 authored
60
肖超群 authored
61
62
  .trend-icon {
    font-size: 12px;
肖超群 authored
63
肖超群 authored
64
65
66
67
    &.up, &.down {
      margin-left: 4px;
      position: relative;
      top: 1px;
肖超群 authored
68
肖超群 authored
69
70
71
      i {
        font-size: 12px;
        transform: scale(.83);
肖超群 authored
72
      }
肖超群 authored
73
    }
肖超群 authored
74
肖超群 authored
75
76
77
78
79
80
81
    &.up {
      color: #f5222d;
    }

    &.down {
      color: #52c41a;
      top: -1px;
肖超群 authored
82
83
    }
  }
肖超群 authored
84
}
肖超群 authored
85
</style>