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.

192 lines
4.0 KiB

  1. <!-- @format -->
  2. <template>
  3. <view class="index-card">
  4. <view class="card-header">
  5. <view class="flag-container">
  6. <image :src="getMarketFlag(market)" class="flag-icon" mode="aspectFit"></image>
  7. </view>
  8. <text class="index-name">{{ stockName }}</text>
  9. </view>
  10. <view class="price-info">
  11. <text class="current-price" :style="{ color: priceColor }">{{ currentPrice }}</text>
  12. <view class="change-info">
  13. <text class="change-amount" :style="{ color: priceColor }">{{ judgeSymbol(changeAmount) }}</text>
  14. <text class="change-percent" :style="{ color: priceColor }">{{ judgeSymbol(changePercent) }}</text>
  15. </view>
  16. </view>
  17. <view class="chart-container">
  18. <view class="mini-chart" >
  19. <image class="time-chart" :src="timeChart" mode="aspectFit"></image>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup>
  25. import { computed } from "vue";
  26. // 定义组件属性
  27. const props = defineProps({
  28. // 国旗图标路径
  29. market: {
  30. type: String,
  31. required: true,
  32. },
  33. // 指数名称
  34. stockName: {
  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. const judgeSymbol = (num) => {
  60. return num[0] === "-" ? num : "+" + num;
  61. };
  62. const getMarketFlag = (market) => {
  63. let imagePath;
  64. if (market === "cn") {
  65. imagePath = "/static/marketSituation-image/country-flag/cn.png";
  66. } else if (market === "hk") {
  67. imagePath = "/static/marketSituation-image/country-flag/hk.png";
  68. } else if (market === "can") {
  69. imagePath = "/static/marketSituation-image/country-flag/can.png";
  70. } else if (market === "my") {
  71. imagePath = "/static/marketSituation-image/country-flag/my.png";
  72. } else if (market === "sg") {
  73. imagePath = "/static/marketSituation-image/country-flag/sg.png";
  74. } else if (market === "th") {
  75. imagePath = "/static/marketSituation-image/country-flag/th.png";
  76. } else if (market === "vi") {
  77. imagePath = "/static/marketSituation-image/country-flag/vi.png";
  78. } else if (market === "us" || market === "usa") {
  79. imagePath = "/static/marketSituation-image/country-flag/us.png";
  80. } else {
  81. imagePath = "/static/marketSituation-image/country-flag/global.png";
  82. }
  83. return imagePath;
  84. };
  85. // 计算价格颜色
  86. const priceColor = computed(() => {
  87. return props.isRising ? "#00C853" : "#FF1744";
  88. });
  89. const timeChart = computed(() => {
  90. return props.isRising ? "/static/marketSituation-image/upTimeChart.png" : "/static/marketSituation-image/downTimeChart.png";
  91. });
  92. // 计算图表背景色
  93. // const chartBgColor = computed(() => {
  94. // return props.isRising ? "#E8F5E8" : "#FFEBEE";
  95. // });
  96. </script>
  97. <style scoped>
  98. .index-card {
  99. background-color: #ffffff;
  100. border-radius: 12rpx;
  101. padding: 20rpx;
  102. margin: 16rpx;
  103. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  104. border: 1rpx solid #f0f0f0;
  105. }
  106. .card-header {
  107. display: flex;
  108. align-items: center;
  109. margin-bottom: 16rpx;
  110. }
  111. .flag-container {
  112. width: 48rpx;
  113. height: 32rpx;
  114. margin-right: 12rpx;
  115. border-radius: 4rpx;
  116. overflow: hidden;
  117. }
  118. .flag-icon {
  119. width: 100%;
  120. height: 100%;
  121. }
  122. .index-name {
  123. font-size: 28rpx;
  124. font-weight: 500;
  125. color: #333333;
  126. flex: 1;
  127. white-space: nowrap;
  128. overflow: hidden;
  129. text-overflow: ellipsis;
  130. }
  131. .price-info {
  132. margin-bottom: 20rpx;
  133. }
  134. .current-price {
  135. font-size: 36rpx;
  136. font-weight: bold;
  137. display: block;
  138. margin-bottom: 8rpx;
  139. }
  140. .change-info {
  141. display: flex;
  142. align-items: center;
  143. gap: 16rpx;
  144. }
  145. .change-amount {
  146. font-size: 24rpx;
  147. font-weight: 500;
  148. }
  149. .change-percent {
  150. font-size: 24rpx;
  151. font-weight: 500;
  152. }
  153. .chart-container {
  154. height: 80rpx;
  155. border-radius: 8rpx;
  156. overflow: hidden;
  157. }
  158. .mini-chart {
  159. width: 100%;
  160. height: 100%;
  161. position: relative;
  162. border-radius: 8rpx;
  163. }
  164. .time-chart {
  165. width: 100%;
  166. height: 100%;
  167. }
  168. </style>