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.

412 lines
9.8 KiB

1 month ago
1 month ago
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" @click="goToMorningAnalysis">
  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. // 跳转到早盘解析页面
  140. goToMorningAnalysis() {
  141. uni.navigateTo({
  142. url: '/pages/morningMarketAnalysis/morningMarketAnalysis'
  143. })
  144. },
  145. showMarketSelector() {
  146. // 切换显示外汇市场内容
  147. this.showForexMarket = !this.showForexMarket;
  148. // 更新按钮文本
  149. this.buttonText = this.showForexMarket ? '外汇市场' : '切换市场';
  150. },
  151. popupChange(e) {
  152. // 对话框关闭时,如果没有确认,则恢复原来的选择
  153. if (!e.show && this.tempSelectedMarket !== this.selectedMarket) {
  154. this.tempSelectedMarket = this.selectedMarket;
  155. }
  156. },
  157. selectMarket(marketId) {
  158. // 临时选择市场,不立即应用
  159. this.tempSelectedMarket = marketId;
  160. },
  161. confirmMarketSelection() {
  162. // 确认选择,应用市场选择并关闭对话框
  163. this.selectedMarket = this.tempSelectedMarket;
  164. this.showSelector = false;
  165. this.$refs.marketPopup.close();
  166. },
  167. getSelectedMarketName() {
  168. if (!this.selectedMarket) return '';
  169. return this.marketData[this.selectedMarket].name;
  170. },
  171. getSelectedMarketValue() {
  172. if (!this.selectedMarket) return '';
  173. return this.marketData[this.selectedMarket].value;
  174. },
  175. getSelectedMarketTrend() {
  176. if (!this.selectedMarket) return '';
  177. return this.marketData[this.selectedMarket].trend;
  178. },
  179. getSelectedMarketIndicators() {
  180. if (!this.selectedMarket) return [];
  181. return this.marketData[this.selectedMarket].indicators;
  182. }
  183. }
  184. }
  185. </script>
  186. <style>
  187. /* 市场概览样式 */
  188. .market-header {
  189. display: flex;
  190. justify-content: space-between;
  191. align-items: center;
  192. padding: 10px 15px;
  193. background-color: #ffffff;
  194. }
  195. .section-title {
  196. font-size: 16px;
  197. font-weight: bold;
  198. color: #333;
  199. }
  200. .more-btn {
  201. font-size: 14px;
  202. color: #4080ff;
  203. }
  204. .market-content {
  205. margin: 0 0 15px;
  206. background-color: #f5f7fa;
  207. border-radius: 8px;
  208. overflow: hidden;
  209. }
  210. /* 外汇市场样式 */
  211. .forex-market {
  212. padding: 15px;
  213. }
  214. .forex-rates {
  215. display: flex;
  216. justify-content: space-between;
  217. gap: 10px;
  218. margin-bottom: 15px;
  219. }
  220. .forex-rate-item {
  221. width: 30%;
  222. padding: 10px;
  223. border-radius: 6px;
  224. display: flex;
  225. flex-direction: column;
  226. align-items: center;
  227. }
  228. .forex-rate-item.up {
  229. background-color: rgba(82, 196, 26, 0.1);
  230. border: 1px solid #52c41a;
  231. }
  232. .forex-rate-item.down {
  233. background-color: rgba(245, 34, 45, 0.1);
  234. border: 1px solid #f5222d;
  235. }
  236. .forex-pair {
  237. font-size: 12px;
  238. color: #666;
  239. margin-bottom: 5px;
  240. }
  241. .forex-value {
  242. font-size: 16px;
  243. font-weight: bold;
  244. color: #333;
  245. margin-bottom: 5px;
  246. }
  247. .forex-change {
  248. font-size: 12px;
  249. color: #52c41a;
  250. }
  251. .forex-rate-item.down .forex-change {
  252. color: #f5222d;
  253. }
  254. .forex-analysis-title {
  255. display: flex;
  256. align-items: center;
  257. margin-bottom: 10px;
  258. border-left: 3px solid #f5222d;
  259. padding-left: 8px;
  260. }
  261. .analysis-title {
  262. font-size: 14px;
  263. font-weight: bold;
  264. color: #333;
  265. }
  266. .forex-analysis-content {
  267. display: flex;
  268. background-color: #fff;
  269. border-radius: 6px;
  270. padding: 12px;
  271. }
  272. .analysis-icon-container {
  273. width: 40px;
  274. height: 40px;
  275. margin-right: 10px;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. align-self: center;
  280. }
  281. .analysis-brain-icon {
  282. width: 100%;
  283. height: 100%;
  284. }
  285. .analysis-items {
  286. flex: 1;
  287. }
  288. .analysis-item {
  289. display: flex;
  290. align-items: center;
  291. margin-bottom: 8px;
  292. }
  293. .analysis-item:last-child {
  294. margin-bottom: 0;
  295. }
  296. .analysis-dot {
  297. width: 8px;
  298. height: 8px;
  299. border-radius: 50%;
  300. margin-right: 8px;
  301. }
  302. .analysis-dot.orange {
  303. background-color: #fa8c16;
  304. }
  305. .analysis-dot.blue {
  306. background-color: #1890ff;
  307. }
  308. .analysis-dot.green {
  309. background-color: #52c41a;
  310. }
  311. .analysis-text {
  312. font-size: 12px;
  313. color: #333;
  314. line-height: 1.4;
  315. }
  316. /* 市场选择对话框样式 */
  317. .market-dialog {
  318. width: 300px;
  319. background-color: #fff;
  320. border-radius: 10px;
  321. overflow: hidden;
  322. }
  323. .dialog-title {
  324. padding: 15px;
  325. text-align: center;
  326. border-bottom: 1px solid #eee;
  327. }
  328. .market-list {
  329. max-height: 300px;
  330. overflow-y: auto;
  331. }
  332. .market-option {
  333. display: flex;
  334. align-items: center;
  335. padding: 12px 15px;
  336. border-bottom: 1px solid #f5f5f5;
  337. }
  338. .market-flag {
  339. width: 24px;
  340. height: 24px;
  341. margin-right: 10px;
  342. }
  343. .flag-image {
  344. width: 100%;
  345. height: 100%;
  346. border-radius: 50%;
  347. }
  348. .market-name-container {
  349. flex: 1;
  350. }
  351. .market-option-name {
  352. font-size: 14px;
  353. color: #333;
  354. }
  355. .dialog-buttons {
  356. padding: 10px 15px 15px;
  357. display: flex;
  358. justify-content: center;
  359. }
  360. .confirm-btn {
  361. width: 80%;
  362. height: 40px;
  363. line-height: 40px;
  364. text-align: center;
  365. background-color: #4080ff;
  366. color: #fff;
  367. border-radius: 20px;
  368. font-size: 14px;
  369. }
  370. </style>