Trend.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = (this.percentage === null ? Math.abs(this.value - this.target) * 100 / this.target : this.percentage).toFixed(this.fixed)
  48. }
  49. }
  50. </script>
  51. <style lang="less" scoped>
  52. .chart-trend {
  53. display: inline-block;
  54. font-size: 14px;
  55. line-height: 22px;
  56. .trend-icon {
  57. font-size: 12px;
  58. &.up, &.down {
  59. margin-left: 4px;
  60. position: relative;
  61. top: 1px;
  62. i {
  63. font-size: 12px;
  64. transform: scale(.83);
  65. }
  66. }
  67. &.up {
  68. color: #f5222d;
  69. }
  70. &.down {
  71. color: #52c41a;
  72. top: -1px;
  73. }
  74. }
  75. }
  76. </style>