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.

406 lines
9.6 KiB

1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view>
  3. <!-- 第一行白色背景标题和按钮 -->
  4. <view class="market-header">
  5. <text class="section-title">今日市场概览</text>
  6. <text class="more-btn" @click="showMarketSelector">{{ buttonText }}</text>
  7. </view>
  8. <!-- 第二行灰色圆角背景市场数据 -->
  9. <view class="market-content">
  10. <!-- 默认显示图片 -->
  11. <view class="selected-market" v-if="!showForexMarket">
  12. <image class="market-image" src="https://d31zlh4on95l9h.cloudfront.net/images/dee46373b5593d5f315d91675a38fb61.png" mode="widthFix"></image>
  13. </view>
  14. <!-- 外汇市场样式 -->
  15. <view class="selected-market" v-if="showForexMarket">
  16. <view class="forex-market">
  17. <!-- 上部分三个汇率容器 -->
  18. <view class="forex-rates">
  19. <view class="forex-rate-item"
  20. v-for="(stock, index) in stockInfoList"
  21. :key="index"
  22. :class="stock.change_percent >= 0 ? 'up' : 'down'">
  23. <text class="forex-pair">{{ stock.stock_name }}</text>
  24. <text class="forex-value">{{ stock.current_price }}</text>
  25. <text class="forex-change">{{ stock.change }}</text>
  26. </view>
  27. </view>
  28. <!-- 中部分智能解读标题 -->
  29. <view class="forex-analysis-title">
  30. <text class="analysis-title">智能解读</text>
  31. </view>
  32. <!-- 下部分智能解读内容 -->
  33. <view class="forex-analysis-content">
  34. <view class="analysis-icon-container">
  35. <image class="analysis-brain-icon" src="https://d31zlh4on95l9h.cloudfront.net/images/8f35e54c52412467101370aa70d8fdb2.png" mode="aspectFit"></image>
  36. </view>
  37. <view class="analysis-items">
  38. <view class="analysis-item">
  39. <text class="analysis-dot orange"></text>
  40. <text class="analysis-text">今日市场情报: 偏乐观</text>
  41. </view>
  42. <view class="analysis-item">
  43. <text class="analysis-dot blue"></text>
  44. <text class="analysis-text">市场风险评级: 需警惕潜在风险</text>
  45. </view>
  46. <view class="analysis-item">
  47. <text class="analysis-dot green"></text>
  48. <text class="analysis-text">早盘解析: 今日高开, 芯片稀土公共</text>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 市场选择对话框 -->
  56. <uni-popup ref="marketPopup" type="center" :mask-click="true" @change="popupChange">
  57. <view class="market-dialog">
  58. <view class="dialog-title">
  59. <text>选择市场</text>
  60. </view>
  61. <view class="market-list">
  62. <view class="market-option" v-for="(market, index) in marketOptions" :key="index" @click="selectMarket(market.id)">
  63. <view class="market-flag">
  64. <image :src="market.flag" mode="aspectFit" class="flag-image"></image>
  65. </view>
  66. <view class="market-name-container">
  67. <text class="market-option-name">{{ market.name }}</text>
  68. </view>
  69. <view class="market-checkbox">
  70. <radio :checked="selectedMarket === market.id" color="#4080ff" />
  71. </view>
  72. </view>
  73. </view>
  74. <view class="dialog-buttons">
  75. <button class="confirm-btn" @click="confirmMarketSelection">确认</button>
  76. </view>
  77. </view>
  78. </uni-popup>
  79. </view>
  80. </template>
  81. <script>
  82. export default {
  83. name: 'MarketOverview',
  84. props: {
  85. // 接收来自父组件的3个股票数据
  86. stockInfoList: {
  87. type: Array,
  88. default: () => ([
  89. {
  90. stock_name: '美元/日元',
  91. current_price: '151.13',
  92. change: '+1.62%',
  93. change_value: 0,
  94. change_percent: 0
  95. },
  96. {
  97. stock_name: '美元/韩元',
  98. current_price: '1424.900',
  99. change: '-2.92%',
  100. change_value: 0,
  101. change_percent: 0
  102. },
  103. {
  104. stock_name: '美元/英镑',
  105. current_price: '0.730',
  106. change: '+2.92%',
  107. change_value: 0,
  108. change_percent: 0
  109. }
  110. ])
  111. }
  112. },
  113. data() {
  114. return {
  115. selectedMarket: 'forex',
  116. tempSelectedMarket: 'forex', // 临时选择,确认后才会应用
  117. previousMarket: null,
  118. buttonText: '切换市场',
  119. showSelector: false,
  120. showForexMarket: false, // 默认不显示外汇市场内容
  121. marketOptions: [
  122. { id: 'forex', name: '外汇市场', flag: '/static/c2.png', value: '+1.62%', trend: 'up' }
  123. ],
  124. marketData: {
  125. 'forex': {
  126. name: '外汇市场',
  127. value: '+1.62%',
  128. trend: 'up',
  129. indicators: [
  130. { name: '美元/日元', value: '151.13 +1.62%', trend: 'up' },
  131. { name: '美元/韩元', value: '1424.900 -2.92%', trend: 'down' },
  132. { name: '美元/英镑', value: '0.79 +2.92%', trend: 'up' }
  133. ]
  134. }
  135. }
  136. }
  137. },
  138. methods: {
  139. showMarketSelector() {
  140. // 切换显示外汇市场内容
  141. this.showForexMarket = !this.showForexMarket;
  142. // 更新按钮文本
  143. this.buttonText = this.showForexMarket ? '外汇市场' : '切换市场';
  144. },
  145. popupChange(e) {
  146. // 对话框关闭时,如果没有确认,则恢复原来的选择
  147. if (!e.show && this.tempSelectedMarket !== this.selectedMarket) {
  148. this.tempSelectedMarket = this.selectedMarket;
  149. }
  150. },
  151. selectMarket(marketId) {
  152. // 临时选择市场,不立即应用
  153. this.tempSelectedMarket = marketId;
  154. },
  155. confirmMarketSelection() {
  156. // 确认选择,应用市场选择并关闭对话框
  157. this.selectedMarket = this.tempSelectedMarket;
  158. this.showSelector = false;
  159. this.$refs.marketPopup.close();
  160. },
  161. getSelectedMarketName() {
  162. if (!this.selectedMarket) return '';
  163. return this.marketData[this.selectedMarket].name;
  164. },
  165. getSelectedMarketValue() {
  166. if (!this.selectedMarket) return '';
  167. return this.marketData[this.selectedMarket].value;
  168. },
  169. getSelectedMarketTrend() {
  170. if (!this.selectedMarket) return '';
  171. return this.marketData[this.selectedMarket].trend;
  172. },
  173. getSelectedMarketIndicators() {
  174. if (!this.selectedMarket) return [];
  175. return this.marketData[this.selectedMarket].indicators;
  176. }
  177. }
  178. }
  179. </script>
  180. <style>
  181. /* 市场概览样式 */
  182. .market-header {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. padding: 10px 15px;
  187. background-color: #ffffff;
  188. }
  189. .section-title {
  190. font-size: 16px;
  191. font-weight: bold;
  192. color: #333;
  193. }
  194. .more-btn {
  195. font-size: 14px;
  196. color: #4080ff;
  197. }
  198. .market-content {
  199. margin: 0 0 15px;
  200. background-color: #f5f7fa;
  201. border-radius: 8px;
  202. overflow: hidden;
  203. }
  204. /* 外汇市场样式 */
  205. .forex-market {
  206. padding: 15px;
  207. }
  208. .forex-rates {
  209. display: flex;
  210. justify-content: space-between;
  211. gap: 10px;
  212. margin-bottom: 15px;
  213. }
  214. .forex-rate-item {
  215. width: 30%;
  216. padding: 10px;
  217. border-radius: 6px;
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. }
  222. .forex-rate-item.up {
  223. background-color: rgba(82, 196, 26, 0.1);
  224. border: 1px solid #52c41a;
  225. }
  226. .forex-rate-item.down {
  227. background-color: rgba(245, 34, 45, 0.1);
  228. border: 1px solid #f5222d;
  229. }
  230. .forex-pair {
  231. font-size: 12px;
  232. color: #666;
  233. margin-bottom: 5px;
  234. }
  235. .forex-value {
  236. font-size: 16px;
  237. font-weight: bold;
  238. color: #333;
  239. margin-bottom: 5px;
  240. }
  241. .forex-change {
  242. font-size: 12px;
  243. color: #52c41a;
  244. }
  245. .forex-rate-item.down .forex-change {
  246. color: #f5222d;
  247. }
  248. .forex-analysis-title {
  249. display: flex;
  250. align-items: center;
  251. margin-bottom: 10px;
  252. border-left: 3px solid #f5222d;
  253. padding-left: 8px;
  254. }
  255. .analysis-title {
  256. font-size: 14px;
  257. font-weight: bold;
  258. color: #333;
  259. }
  260. .forex-analysis-content {
  261. display: flex;
  262. background-color: #fff;
  263. border-radius: 6px;
  264. padding: 12px;
  265. }
  266. .analysis-icon-container {
  267. width: 40px;
  268. height: 40px;
  269. margin-right: 10px;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. align-self: center;
  274. }
  275. .analysis-brain-icon {
  276. width: 100%;
  277. height: 100%;
  278. }
  279. .analysis-items {
  280. flex: 1;
  281. }
  282. .analysis-item {
  283. display: flex;
  284. align-items: center;
  285. margin-bottom: 8px;
  286. }
  287. .analysis-item:last-child {
  288. margin-bottom: 0;
  289. }
  290. .analysis-dot {
  291. width: 8px;
  292. height: 8px;
  293. border-radius: 50%;
  294. margin-right: 8px;
  295. }
  296. .analysis-dot.orange {
  297. background-color: #fa8c16;
  298. }
  299. .analysis-dot.blue {
  300. background-color: #1890ff;
  301. }
  302. .analysis-dot.green {
  303. background-color: #52c41a;
  304. }
  305. .analysis-text {
  306. font-size: 12px;
  307. color: #333;
  308. line-height: 1.4;
  309. }
  310. /* 市场选择对话框样式 */
  311. .market-dialog {
  312. width: 300px;
  313. background-color: #fff;
  314. border-radius: 10px;
  315. overflow: hidden;
  316. }
  317. .dialog-title {
  318. padding: 15px;
  319. text-align: center;
  320. border-bottom: 1px solid #eee;
  321. }
  322. .market-list {
  323. max-height: 300px;
  324. overflow-y: auto;
  325. }
  326. .market-option {
  327. display: flex;
  328. align-items: center;
  329. padding: 12px 15px;
  330. border-bottom: 1px solid #f5f5f5;
  331. }
  332. .market-flag {
  333. width: 24px;
  334. height: 24px;
  335. margin-right: 10px;
  336. }
  337. .flag-image {
  338. width: 100%;
  339. height: 100%;
  340. border-radius: 50%;
  341. }
  342. .market-name-container {
  343. flex: 1;
  344. }
  345. .market-option-name {
  346. font-size: 14px;
  347. color: #333;
  348. }
  349. .dialog-buttons {
  350. padding: 10px 15px 15px;
  351. display: flex;
  352. justify-content: center;
  353. }
  354. .confirm-btn {
  355. width: 80%;
  356. height: 40px;
  357. line-height: 40px;
  358. text-align: center;
  359. background-color: #4080ff;
  360. color: #fff;
  361. border-radius: 20px;
  362. font-size: 14px;
  363. }
  364. </style>