Trend.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="chart-trend">
  3. {{ term }}
  4. <span>{{ rate }}%</span>
  5. <span :class="['trend-icon', trend]"><a-icon :type="'caret-' + trend"/></span>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'Trend',
  11. props: {
  12. term: {
  13. type: String,
  14. default: '',
  15. required: true
  16. },
  17. percentage: {
  18. type: Number,
  19. default: null
  20. },
  21. type: {
  22. type: Boolean,
  23. default: null
  24. },
  25. target: {
  26. type: Number,
  27. default: 0
  28. },
  29. value: {
  30. type: Number,
  31. default: 0
  32. },
  33. fixed: {
  34. type: Number,
  35. default: 2
  36. }
  37. },
  38. data () {
  39. return {
  40. trend: this.type && 'up' || 'down',
  41. rate: this.percentage
  42. }
  43. },
  44. created () {
  45. const type = this.type === null ? this.value >= this.target : this.type
  46. this.trend = type ? 'up' : 'down'
  47. this.rate = Math.abs(this.percentage)
  48. },
  49. watch: {
  50. percentage() {
  51. this.rate = Math.abs(this.percentage)
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="less" scoped>
  57. .chart-trend {
  58. display: inline-block;
  59. font-size: 14px;
  60. line-height: 22px;
  61. .trend-icon {
  62. font-size: 12px;
  63. &.up, &.down {
  64. margin-left: 4px;
  65. position: relative;
  66. top: 1px;
  67. i {
  68. font-size: 12px;
  69. transform: scale(.83);
  70. }
  71. }
  72. &.up {
  73. color: #f5222d;
  74. }
  75. &.down {
  76. color: #52c41a;
  77. top: -1px;
  78. }
  79. }
  80. }
  81. </style>