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.

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