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.

573 lines
15 KiB

4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
  1. <template>
  2. <view class="main">
  3. <!-- 固定头部 -->
  4. <view class="header_fixed" :style="{ top: iSMT + 'px' }">
  5. <view class="header_content">
  6. <view class="header_back" @click="goBack">
  7. <image src="/static/marketSituation-image/back.png" mode=""></image>
  8. </view>
  9. <view class="header_input_wrapper">
  10. <image class="search_icon" src="/static/marketSituation-image/search.png" mode=""
  11. @click="onSearchClick"></image>
  12. <input class="header_input" type="text" placeholder="搜索"
  13. placeholder-style="color: #A6A6A6; font-size: 22rpx;" v-model="searchValue"
  14. @input="onSearchInput" @confirm="onSearchConfirm" />
  15. </view>
  16. <view class="header_icons">
  17. <view class="header_icon" @click="selected">
  18. <image src="/static/marketSituation-image/mySeclected.png" mode=""></image>
  19. </view>
  20. <view class="header_icon" @click="history">
  21. <image src="/static/marketSituation-image/history.png" mode=""></image>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="warn">
  26. <image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image>
  27. <view class="warn_text_container">
  28. <text :class="warnTextClass">{{ $t('marketSituation.warn') }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 内容区域 -->
  33. <scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
  34. <!-- 亚太-中华 -->
  35. <view class="market-section">
  36. <view class="market-header">
  37. <text class="market-title">亚太-中华</text>
  38. <view class="market-more" @click="viewMore('asia-china')">
  39. <text class="more-text">查看更多</text>
  40. <text class="more-arrow">></text>
  41. </view>
  42. </view>
  43. <view class="cards-grid-three">
  44. <view v-for="(item, index) in asiachinaIndexes" :key="index" class="card-item">
  45. <IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
  46. :currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
  47. :changePercent="item.changePercent" :isRising="item.isRising"
  48. @click="viewIndexDetail(item)" />
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 亚太 -->
  53. <view class="market-section">
  54. <view class="market-header">
  55. <text class="market-title">亚太</text>
  56. <view class="market-more" @click="viewMore('asia')">
  57. <text class="more-text">查看更多</text>
  58. <text class="more-arrow">></text>
  59. </view>
  60. </view>
  61. <view class="cards-grid-three">
  62. <view v-for="(item, index) in asiaIndexes" :key="index" class="card-item">
  63. <IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
  64. :currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
  65. :changePercent="item.changePercent" :isRising="item.isRising"
  66. @click="viewIndexDetail(item)" />
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 美洲 -->
  71. <view class="market-section">
  72. <view class="market-header">
  73. <text class="market-title">美洲</text>
  74. <view class="market-more" @click="viewMore('america')">
  75. <text class="more-text">查看更多</text>
  76. <text class="more-arrow">></text>
  77. </view>
  78. </view>
  79. <view class="cards-grid-three">
  80. <view v-for="(item, index) in americaIndexes" :key="index" class="card-item">
  81. <IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
  82. :currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
  83. :changePercent="item.changePercent" :isRising="item.isRising"
  84. @click="viewIndexDetail(item)" />
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 底部安全区域 -->
  89. <view class="bottom-safe-area"></view>
  90. </scroll-view>
  91. </view>
  92. <!-- 底部导航栏 -->
  93. <footerBar class="static-footer" :type="'marketSituation'"></footerBar>
  94. </template>
  95. <script setup>
  96. import { ref, onMounted, computed, nextTick, watch } from 'vue'
  97. import footerBar from '../../components/footerBar.vue'
  98. import IndexCard from '../../components/IndexCard.vue'
  99. // 响应式数据
  100. const iSMT = ref(0) // 状态栏高度
  101. const contentHeight = ref(0)
  102. const headerHeight = ref(0) // 头部高度
  103. const searchValue = ref('') // 搜索值
  104. const isWarnTextOverflow = ref(false) // warn文字是否溢出
  105. // warn文字的class计算属性
  106. const warnTextClass = computed(() => {
  107. return isWarnTextOverflow.value ? 'warn_text scroll-active' : 'warn_text'
  108. })
  109. // 检测warn文字是否溢出
  110. const checkWarnTextOverflow = () => {
  111. nextTick(() => {
  112. setTimeout(() => {
  113. const query = uni.createSelectorQuery()
  114. // 同时查询容器和文字元素
  115. query.select('.warn_text_container').boundingClientRect()
  116. query.select('.warn_text').boundingClientRect()
  117. query.exec((res) => {
  118. const containerRect = res[0]
  119. const textRect = res[1]
  120. if (!containerRect || !textRect) {
  121. return
  122. }
  123. // 判断文字是否超出容器(留一些余量)
  124. const isOverflow = textRect.width > (containerRect.width - 10)
  125. isWarnTextOverflow.value = isOverflow
  126. })
  127. }, 500)
  128. })
  129. }
  130. // 亚太-中华指数数据
  131. const asiachinaIndexes = ref([
  132. {
  133. flagIcon: '/static/c1.png',
  134. indexName: '上证指数',
  135. currentPrice: '3933.96',
  136. changeAmount: '+24.32',
  137. changePercent: '+0.62%',
  138. isRising: true
  139. },
  140. {
  141. flagIcon: '/static/c2.png',
  142. indexName: '深证成指',
  143. currentPrice: '45757.90',
  144. changeAmount: '-123.45',
  145. changePercent: '-0.27%',
  146. isRising: false
  147. },
  148. {
  149. flagIcon: '/static/c3.png',
  150. indexName: '创业板指',
  151. currentPrice: '6606.08',
  152. changeAmount: '+89.76',
  153. changePercent: '+1.38%',
  154. isRising: true
  155. },
  156. {
  157. flagIcon: '/static/c4.png',
  158. indexName: 'HSI50',
  159. currentPrice: '22333.96',
  160. changeAmount: '+156.78',
  161. changePercent: '+0.71%',
  162. isRising: true
  163. },
  164. {
  165. flagIcon: '/static/c5.png',
  166. indexName: '沪深300',
  167. currentPrice: '45757.90',
  168. changeAmount: '-89.12',
  169. changePercent: '-0.19%',
  170. isRising: false
  171. },
  172. {
  173. flagIcon: '/static/c6.png',
  174. indexName: '上证50',
  175. currentPrice: '45757.90',
  176. changeAmount: '+234.56',
  177. changePercent: '+0.52%',
  178. isRising: true
  179. }
  180. ])
  181. // 亚太指数数据
  182. const asiaIndexes = ref([
  183. {
  184. flagIcon: '/static/c7.png',
  185. indexName: '日经225',
  186. currentPrice: '28456.78',
  187. changeAmount: '+234.56',
  188. changePercent: '+0.83%',
  189. isRising: true
  190. },
  191. {
  192. flagIcon: '/static/c8.png',
  193. indexName: '韩国KOSPI',
  194. currentPrice: '2567.89',
  195. changeAmount: '-12.34',
  196. changePercent: '-0.48%',
  197. isRising: false
  198. },
  199. {
  200. flagIcon: '/static/c9.png',
  201. indexName: '印度孟买',
  202. currentPrice: '65432.10',
  203. changeAmount: '+456.78',
  204. changePercent: '+0.70%',
  205. isRising: true
  206. }
  207. ])
  208. // 美洲指数数据
  209. const americaIndexes = ref([
  210. {
  211. flagIcon: '/static/c7.png',
  212. indexName: '道琼斯指数',
  213. currentPrice: '34567.89',
  214. changeAmount: '+123.45',
  215. changePercent: '+0.36%',
  216. isRising: true
  217. },
  218. {
  219. flagIcon: '/static/c8.png',
  220. indexName: '纳斯达克',
  221. currentPrice: '13456.78',
  222. changeAmount: '-67.89',
  223. changePercent: '-0.50%',
  224. isRising: false
  225. },
  226. {
  227. flagIcon: '/static/c9.png',
  228. indexName: '标普500',
  229. currentPrice: '4234.56',
  230. changeAmount: '+23.45',
  231. changePercent: '+0.56%',
  232. isRising: true
  233. }
  234. ])
  235. // 计算属性:内容区域顶部位置
  236. const contentTopPosition = computed(() => {
  237. const statusBarHeight = iSMT.value || 0
  238. const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 100
  239. return statusBarHeight + currentHeaderHeight
  240. })
  241. // 方法:返回上一页
  242. const goBack = () => {
  243. uni.navigateBack()
  244. }
  245. // 方法:搜索输入
  246. const onSearchInput = (e) => {
  247. searchValue.value = e.detail.value
  248. }
  249. // 方法:清除搜索
  250. const clearSearch = () => {
  251. searchValue.value = ''
  252. }
  253. // 方法:查看更多
  254. const viewMore = (market) => {
  255. console.log('查看更多:', market)
  256. uni.navigateTo({
  257. url: `/pages/marketSituation/marketDetail?market=${market}`
  258. })
  259. }
  260. // 方法:查看指数详情
  261. const viewIndexDetail = (item) => {
  262. console.log('查看指数详情:', item.indexName)
  263. uni.showToast({
  264. title: `查看 ${item.indexName} 详情`,
  265. icon: 'none',
  266. duration: 2000
  267. })
  268. // 这里可以跳转到具体的指数详情页面
  269. // uni.navigateTo({
  270. // url: `/pages/detail/indexDetail?id=${item.id}`
  271. // })
  272. }
  273. // 生命周期:页面挂载
  274. onMounted(() => {
  275. // 获取系统信息
  276. const systemInfo = uni.getSystemInfoSync()
  277. iSMT.value = systemInfo.statusBarHeight || 0
  278. console.log('全球指数页面加载完成')
  279. // 动态计算header实际高度
  280. uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
  281. if (rect) {
  282. headerHeight.value = rect.height
  283. console.log('Header实际高度:', headerHeight.value, 'px')
  284. }
  285. }).exec()
  286. // 检测warn文字是否溢出
  287. checkWarnTextOverflow()
  288. })
  289. // 监听headerHeight变化,重新计算contentHeight
  290. watch(headerHeight, (newHeight) => {
  291. if (newHeight > 0) {
  292. const systemInfo = uni.getSystemInfoSync()
  293. const windowHeight = systemInfo.windowHeight
  294. const statusBarHeight = systemInfo.statusBarHeight || 0
  295. const footerHeight = 100
  296. contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
  297. console.log('重新计算contentHeight:', contentHeight.value)
  298. }
  299. })
  300. </script>
  301. <style lang="scss" scoped>
  302. .main {
  303. position: relative;
  304. height: 100vh;
  305. overflow: hidden;
  306. background-color: #f5f5f5;
  307. }
  308. /* 状态栏占位 */
  309. .top {
  310. position: fixed;
  311. top: 0;
  312. left: 0;
  313. right: 0;
  314. z-index: 1001;
  315. background-color: #ffffff;
  316. }
  317. /* 固定头部样式 */
  318. .header_fixed {
  319. position: fixed;
  320. left: 0;
  321. right: 0;
  322. z-index: 1000;
  323. background-color: #ffffff;
  324. padding: 20rpx 0 0 0;
  325. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  326. }
  327. .header_content {
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. height: 80rpx;
  332. padding: 0 20rpx;
  333. margin-bottom: 10rpx;
  334. }
  335. .header_back {
  336. margin-right: 20rpx;
  337. width: 25rpx;
  338. height: 30rpx;
  339. }
  340. .header_back image {
  341. width: 25rpx;
  342. height: 30rpx;
  343. }
  344. .header_input_wrapper {
  345. display: flex;
  346. align-items: center;
  347. width: 100%;
  348. margin: 0 20rpx 0 0;
  349. height: 70rpx;
  350. border-radius: 35rpx;
  351. background-color: #ffffff;
  352. border: 1rpx solid #e9ecef;
  353. padding: 0 80rpx 0 30rpx;
  354. font-size: 28rpx;
  355. color: #5c5c5c;
  356. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  357. }
  358. .search_icon {
  359. width: 40rpx;
  360. height: 40rpx;
  361. opacity: 0.6;
  362. }
  363. .header_input {
  364. margin-left: 10rpx;
  365. }
  366. .header_icons {
  367. display: flex;
  368. align-items: center;
  369. gap: 15rpx;
  370. }
  371. .header_icon {
  372. width: 40rpx;
  373. height: 40rpx;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. }
  378. .header_icon image {
  379. width: 40rpx;
  380. height: 40rpx;
  381. }
  382. .warn {
  383. display: flex;
  384. align-items: center;
  385. justify-content: flex-start;
  386. gap: 10rpx;
  387. font-size: 28rpx;
  388. color: #666666;
  389. padding: 20rpx;
  390. max-width: 100%;
  391. overflow: hidden;
  392. position: relative;
  393. }
  394. .warn image {
  395. width: 40rpx;
  396. height: 40rpx;
  397. flex-shrink: 0;
  398. /* 防止图片被压缩 */
  399. position: relative;
  400. z-index: 2;
  401. /* 确保图片在最上层 */
  402. }
  403. .warn_text_container {
  404. flex: 1;
  405. overflow: hidden;
  406. position: relative;
  407. min-width: 0;
  408. /* 允许容器收缩 */
  409. }
  410. .warn_text {
  411. display: block;
  412. white-space: nowrap;
  413. will-change: transform;
  414. /* 优化动画性能 */
  415. }
  416. /* 文字滚动动画 */
  417. @keyframes scrollText {
  418. 0% {
  419. transform: translateX(0);
  420. }
  421. 20% {
  422. transform: translateX(0);
  423. }
  424. 80% {
  425. transform: translateX(-85%);
  426. }
  427. 100% {
  428. transform: translateX(-85%);
  429. }
  430. }
  431. /* 当文字超长时启用滚动动画 */
  432. .warn_text.scroll-active {
  433. animation: scrollText 12s linear infinite;
  434. animation-delay: 2s;
  435. /* 延迟2秒开始滚动,让用户先看到开头 */
  436. }
  437. /* 内容区域 */
  438. .content {
  439. position: fixed;
  440. left: 0;
  441. right: 0;
  442. bottom: 120rpx;
  443. background-color: #f5f5f5;
  444. padding: 0;
  445. }
  446. /* 市场分组 */
  447. .market-section {
  448. background-color: white;
  449. border-radius: 20rpx;
  450. }
  451. .market-header {
  452. margin: 20rpx 20rpx 0 20rpx;
  453. display: flex;
  454. align-items: center;
  455. justify-content: space-between;
  456. margin-bottom: 10rpx;
  457. padding-bottom: 10rpx;
  458. border-bottom: 2rpx solid #f0f0f0;
  459. }
  460. .market-title {
  461. font-size: 32rpx;
  462. font-weight: 600;
  463. color: #333;
  464. }
  465. .market-more {
  466. display: flex;
  467. align-items: center;
  468. gap: 8rpx;
  469. }
  470. .more-text {
  471. font-size: 24rpx;
  472. color: #666;
  473. }
  474. .more-arrow {
  475. font-size: 20rpx;
  476. color: #666;
  477. font-weight: bold;
  478. }
  479. /* 三列卡片网格 */
  480. .cards-grid-three {
  481. display: grid;
  482. grid-template-columns: repeat(3, 1fr);
  483. }
  484. .card-item {
  485. background-color: white;
  486. border-radius: 16rpx;
  487. overflow: hidden;
  488. transition: transform 0.2s ease, box-shadow 0.2s ease;
  489. }
  490. .card-item:active {
  491. transform: scale(0.98);
  492. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.12);
  493. }
  494. /* 底部安全区域 */
  495. .bottom-safe-area {
  496. height: 40rpx;
  497. background-color: transparent;
  498. }
  499. /* 底部导航栏 */
  500. .static-footer {
  501. position: fixed;
  502. bottom: 0;
  503. left: 0;
  504. right: 0;
  505. z-index: 1000;
  506. }
  507. /* 响应式设计 */
  508. @media (max-width: 400rpx) {
  509. .cards-grid-three {
  510. grid-template-columns: repeat(2, 1fr);
  511. }
  512. }
  513. </style>