You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
3.3 KiB

  1. <template>
  2. <view class="index-card">
  3. <view class="card-header">
  4. <view class="flag-container">
  5. <image :src="flagIcon" class="flag-icon" mode="aspectFit"></image>
  6. </view>
  7. <text class="index-name">{{ indexName }}</text>
  8. </view>
  9. <view class="price-info">
  10. <text class="current-price" :style="{ color: priceColor }">{{ currentPrice }}</text>
  11. <view class="change-info">
  12. <text class="change-amount" :style="{ color: priceColor }">{{ changeAmount }}</text>
  13. <text class="change-percent" :style="{ color: priceColor }">{{ changePercent }}</text>
  14. </view>
  15. </view>
  16. <view class="chart-container">
  17. <view class="mini-chart" :style="{ backgroundColor: chartBgColor }">
  18. <!-- 这里可以放置实际的图表组件目前用简单的波浪线表示 -->
  19. <view class="chart-line" :style="{ borderColor: priceColor }"></view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup>
  25. import { computed } from 'vue'
  26. // 定义组件属性
  27. const props = defineProps({
  28. // 国旗图标路径
  29. flagIcon: {
  30. type: String,
  31. required: true
  32. },
  33. // 指数名称
  34. indexName: {
  35. type: String,
  36. required: true
  37. },
  38. // 当前价格
  39. currentPrice: {
  40. type: [String, Number],
  41. required: true
  42. },
  43. // 涨跌金额
  44. changeAmount: {
  45. type: [String, Number],
  46. required: true
  47. },
  48. // 涨跌幅
  49. changePercent: {
  50. type: [String, Number],
  51. required: true
  52. },
  53. // 是否上涨
  54. isRising: {
  55. type: Boolean,
  56. default: true
  57. }
  58. })
  59. // 计算价格颜色
  60. const priceColor = computed(() => {
  61. return props.isRising ? '#00C853' : '#FF1744'
  62. })
  63. // 计算图表背景色
  64. const chartBgColor = computed(() => {
  65. return props.isRising ? '#E8F5E8' : '#FFEBEE'
  66. })
  67. </script>
  68. <style scoped>
  69. .index-card {
  70. background-color: #ffffff;
  71. border-radius: 12rpx;
  72. padding: 20rpx;
  73. margin: 16rpx;
  74. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  75. border: 1rpx solid #f0f0f0;
  76. }
  77. .card-header {
  78. display: flex;
  79. align-items: center;
  80. margin-bottom: 16rpx;
  81. }
  82. .flag-container {
  83. width: 48rpx;
  84. height: 32rpx;
  85. margin-right: 12rpx;
  86. border-radius: 4rpx;
  87. overflow: hidden;
  88. }
  89. .flag-icon {
  90. width: 100%;
  91. height: 100%;
  92. }
  93. .index-name {
  94. font-size: 28rpx;
  95. font-weight: 500;
  96. color: #333333;
  97. flex: 1;
  98. white-space: nowrap;
  99. overflow: hidden;
  100. text-overflow: ellipsis;
  101. }
  102. .price-info {
  103. margin-bottom: 20rpx;
  104. }
  105. .current-price {
  106. font-size: 36rpx;
  107. font-weight: bold;
  108. display: block;
  109. margin-bottom: 8rpx;
  110. }
  111. .change-info {
  112. display: flex;
  113. align-items: center;
  114. gap: 16rpx;
  115. }
  116. .change-amount {
  117. font-size: 24rpx;
  118. font-weight: 500;
  119. }
  120. .change-percent {
  121. font-size: 24rpx;
  122. font-weight: 500;
  123. }
  124. .chart-container {
  125. height: 80rpx;
  126. border-radius: 8rpx;
  127. overflow: hidden;
  128. }
  129. .mini-chart {
  130. width: 100%;
  131. height: 100%;
  132. position: relative;
  133. border-radius: 8rpx;
  134. }
  135. .chart-line {
  136. position: absolute;
  137. bottom: 20rpx;
  138. left: 10rpx;
  139. right: 10rpx;
  140. height: 2rpx;
  141. border-top: 2rpx solid;
  142. border-style: solid;
  143. }
  144. /* 添加一些波浪效果 */
  145. .chart-line::before {
  146. content: '';
  147. position: absolute;
  148. top: -10rpx;
  149. left: 20%;
  150. width: 20rpx;
  151. height: 20rpx;
  152. border: 2rpx solid;
  153. border-color: inherit;
  154. border-radius: 50%;
  155. background: transparent;
  156. }
  157. .chart-line::after {
  158. content: '';
  159. position: absolute;
  160. top: -6rpx;
  161. right: 30%;
  162. width: 12rpx;
  163. height: 12rpx;
  164. border: 2rpx solid;
  165. border-color: inherit;
  166. border-radius: 50%;
  167. background: transparent;
  168. }
  169. </style>