EnergyWeekCard.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="energy-week-card">
  3. <view class="ewc-header">
  4. <text class="ewc-title">📈 {{ title }}</text>
  5. </view>
  6. <view class="ewc-body">
  7. <view class="ewc-stat-row">
  8. <text class="ewc-stat-label">本周获取</text>
  9. <text class="ewc-stat-value accent">+{{ weekGain }}</text>
  10. <text class="ewc-stat-label" style="margin-left: 24rpx;">上周</text>
  11. <text class="ewc-stat-value" :class="gainTrend >= 0 ? 'up' : 'down'">{{ lastWeekGain }}</text>
  12. <text class="ewc-trend" :class="gainTrend >= 0 ? 'up' : 'down'">
  13. {{ gainTrend >= 0 ? '↑' : '↓' }}{{ Math.abs(gainTrend) }}%
  14. </text>
  15. </view>
  16. <view class="ewc-mini-chart">
  17. <view class="ewc-bar" v-for="(val, i) in weekData" :key="i"
  18. :style="{ height: (val / maxVal * 80) + 'rpx' }"
  19. :class="{ 'ewc-bar--today': i === weekData.length - 1 }">
  20. </view>
  21. </view>
  22. <text class="ewc-tip" v-if="tip">{{ tip }}</text>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. props: {
  29. title: { type: String, default: '能量周报' },
  30. weekGain: { type: Number, default: 0 },
  31. lastWeekGain: { type: Number, default: 0 },
  32. gainTrend: { type: Number, default: 0 },
  33. weekData: { type: Array, default: function() { return [10, 20, 30, 40, 50, 60, 70] } },
  34. tip: { type: String, default: '' }
  35. },
  36. computed: {
  37. maxVal() {
  38. return Math.max.apply(null, this.weekData.concat([1]))
  39. }
  40. }
  41. }
  42. </script>
  43. <style scoped>
  44. .energy-week-card {
  45. background: #fff;
  46. border-radius: 20rpx;
  47. padding: 24rpx;
  48. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  49. }
  50. .ewc-header { margin-bottom: 16rpx; }
  51. .ewc-title { font-size: 28rpx; font-weight: 700; color: #333; }
  52. .ewc-stat-row {
  53. display: flex;
  54. align-items: baseline;
  55. flex-wrap: wrap;
  56. margin-bottom: 16rpx;
  57. }
  58. .ewc-stat-label { font-size: 22rpx; color: #999; }
  59. .ewc-stat-value { font-size: 28rpx; font-weight: 700; }
  60. .ewc-stat-value.accent { color: #F97316; }
  61. .ewc-stat-value.up { color: #10B981; }
  62. .ewc-stat-value.down { color: #EF4444; }
  63. .ewc-trend { font-size: 22rpx; margin-left: 8rpx; }
  64. .ewc-trend.up { color: #10B981; }
  65. .ewc-trend.down { color: #EF4444; }
  66. .ewc-mini-chart {
  67. display: flex;
  68. align-items: flex-end;
  69. gap: 8rpx;
  70. height: 90rpx;
  71. margin-bottom: 12rpx;
  72. }
  73. .ewc-bar {
  74. flex: 1;
  75. background: #E2E8F0;
  76. border-radius: 4rpx 4rpx 0 0;
  77. min-height: 8rpx;
  78. }
  79. .ewc-bar--today { background: #F97316; }
  80. .ewc-tip { font-size: 22rpx; color: #F97316; display: block; }
  81. </style>