Trend.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // 同title
  13. term: {
  14. type: String,
  15. default: '',
  16. required: true
  17. },
  18. // 百分比
  19. percentage: {
  20. type: Number,
  21. default: null
  22. },
  23. type: {
  24. type: Boolean,
  25. default: null
  26. },
  27. target: {
  28. type: Number,
  29. default: 0
  30. },
  31. value: {
  32. type: Number,
  33. default: 0
  34. },
  35. fixed: {
  36. type: Number,
  37. default: 2
  38. }
  39. },
  40. data () {
  41. return {
  42. trend: this.type && 'up' || 'down',
  43. rate: this.percentage
  44. }
  45. },
  46. created () {
  47. let type = this.type === null ? this.value >= this.target : this.type
  48. this.trend = type ? 'up' : 'down';
  49. this.rate = (this.percentage === null ? Math.abs(this.value - this.target) * 100 / this.target : this.percentage).toFixed(this.fixed)
  50. }
  51. }
  52. </script>
  53. <style lang="less" scoped>
  54. .chart-trend {
  55. display: inline-block;
  56. font-size: 14px;
  57. line-height: 22px;
  58. .trend-icon {
  59. font-size: 12px;
  60. &.up, &.down {
  61. margin-left: 4px;
  62. position: relative;
  63. top: 1px;
  64. i {
  65. font-size: 12px;
  66. transform: scale(.83);
  67. }
  68. }
  69. &.up {
  70. color: #f5222d;
  71. }
  72. &.down {
  73. color: #52c41a;
  74. top: -1px;
  75. }
  76. }
  77. }
  78. </style>