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.

483 lines
9.4 KiB

  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-left" @click="goBack">
  7. <text class="back-text"></text>
  8. </view>
  9. <view class="header-center">
  10. <text class="header-title">{{ marketTitle }}</text>
  11. </view>
  12. <view class="header-right">
  13. <image src="/static/marketSituation-image/search.png" class="header-icon" mode="aspectFit"></image>
  14. <text class="more-text">···</text>
  15. </view>
  16. </view>
  17. <!-- 表头 -->
  18. <view class="table-header">
  19. <view class="header-item name-column">
  20. <text class="header-text">名称</text>
  21. </view>
  22. <view class="header-item price-column" @click="sortByPrice">
  23. <text class="header-text">最新</text>
  24. <text class="sort-icon">{{ sortType === 'price' ? (sortOrder === 'asc' ? '↑' : '↓') : '↕' }}</text>
  25. </view>
  26. <view class="header-item change-column" @click="sortByChange">
  27. <text class="header-text">涨幅</text>
  28. <text class="sort-icon">{{ sortType === 'change' ? (sortOrder === 'asc' ? '↑' : '↓') : '↕' }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 内容区域 -->
  33. <scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
  34. <!-- 股票列表 -->
  35. <view class="stock-list">
  36. <view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index"
  37. @click="viewStockDetail(stock)">
  38. <view class="stock-cell name-column">
  39. <view class="stock-name">{{ stock.name }}</view>
  40. <view class="stock-code">{{ stock.code }}</view>
  41. </view>
  42. <view class="stock-cell price-column">
  43. <text class="stock-price"
  44. :class="stock.isRising ? 'rising' : 'falling'">
  45. {{ typeof stock.price === 'number' ? stock.price.toFixed(2) : stock.price }}
  46. </text>
  47. </view>
  48. <view class="stock-cell change-column">
  49. <text class="stock-change"
  50. :class="stock.isRising ? 'rising' : 'falling'">
  51. {{ stock.change || stock.changePercent }}
  52. </text>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 底部安全区域 -->
  57. <!-- <view class="bottom-safe-area"></view> -->
  58. </scroll-view>
  59. </view>
  60. <!-- 底部导航栏 -->
  61. <!-- <footerBar class="static-footer" :type="'marketSituation'"></footerBar> -->
  62. </template>
  63. <script setup>
  64. import { ref, computed, onMounted, watch } from 'vue'
  65. import { onLoad } from '@dcloudio/uni-app'
  66. import footerBar from '@/components/footerBar.vue'
  67. // 响应式数据
  68. const iSMT = ref(0)
  69. const headerHeight = ref(80)
  70. const marketType = ref('america')
  71. const marketTitle = ref('美洲')
  72. const sortType = ref('') // 排序类型:'price' 或 'change'
  73. const sortOrder = ref('desc') // 排序顺序:'asc' 或 'desc'
  74. // 股票数据
  75. const stockList = ref([
  76. {
  77. name: 'Telecommunication',
  78. code: '888607',
  79. price: 1349.47,
  80. change: '+7.67%',
  81. isRising: true
  82. },
  83. {
  84. name: 'Other',
  85. code: '888607',
  86. price: 1349.47,
  87. change: '+6.67%',
  88. isRising: true
  89. },
  90. {
  91. name: 'Consumer Discretio...',
  92. code: '888610',
  93. price: 1349.47,
  94. change: '+5.67%',
  95. isRising: true
  96. },
  97. {
  98. name: 'Telecommunication',
  99. code: '888607',
  100. price: 1349.47,
  101. change: '+4.67%',
  102. isRising: true
  103. },
  104. {
  105. name: 'Other',
  106. code: '888611',
  107. price: 1359.47,
  108. change: '+3.67%',
  109. isRising: true
  110. },
  111. {
  112. name: 'Consumer Discretio...',
  113. code: '888610',
  114. price: 1349.47,
  115. change: '+2.67%',
  116. isRising: true
  117. },
  118. {
  119. name: 'Telecommunication',
  120. code: '888607',
  121. price: 1349.47,
  122. change: '+1.67%',
  123. isRising: true
  124. },
  125. {
  126. name: 'Other',
  127. code: '888611',
  128. price: 1009.98,
  129. change: '-1.67%',
  130. isRising: false
  131. },
  132. {
  133. name: 'Consumer Discretio...',
  134. code: '888610',
  135. price: 1009.98,
  136. change: '-0.67%',
  137. isRising: false
  138. },
  139. {
  140. name: 'Telecommunication',
  141. code: '888607',
  142. price: 1009.98,
  143. change: '-0.67%',
  144. isRising: false
  145. },
  146. {
  147. name: 'Other',
  148. code: '888611',
  149. price: 1009.98,
  150. change: '-1.67%',
  151. isRising: false
  152. },
  153. {
  154. name: 'Consumer Discretio...',
  155. code: '888610',
  156. price: 1009.98,
  157. change: '-4.67%',
  158. isRising: false
  159. },
  160. {
  161. name: 'Consumer Discretio...',
  162. code: '888610',
  163. price: 1009.98,
  164. change: '-3.67%',
  165. isRising: false
  166. },
  167. {
  168. name: 'Consumer Discretio...',
  169. code: '888610',
  170. price: 1009.98,
  171. change: '-3.67%',
  172. isRising: false
  173. }
  174. ])
  175. // 计算属性
  176. const contentTopPosition = computed(() => {
  177. return iSMT.value + headerHeight.value
  178. })
  179. const sortedStockList = computed(() => {
  180. console.log('计算sortedStockList,原始数据长度:', stockList.value.length);
  181. let list = [...stockList.value]
  182. if (sortType.value === 'price') {
  183. list.sort((a, b) => {
  184. return sortOrder.value === 'asc' ? a.price - b.price : b.price - a.price
  185. })
  186. } else if (sortType.value === 'change') {
  187. list.sort((a, b) => {
  188. const aChange = parseFloat(a.change.replace(/[+%-]/g, ''))
  189. const bChange = parseFloat(b.change.replace(/[+%-]/g, ''))
  190. return sortOrder.value === 'asc' ? aChange - bChange : bChange - aChange
  191. })
  192. }
  193. console.log('排序后数据长度:', list.length);
  194. return list
  195. })
  196. // 页面加载时接收参数
  197. onLoad((options) => {
  198. if (options && options.market) {
  199. marketType.value = options.market
  200. switch (options.market) {
  201. case 'america':
  202. marketTitle.value = '美洲'
  203. break
  204. case 'asia':
  205. marketTitle.value = '亚太'
  206. break
  207. case 'asia-china':
  208. marketTitle.value = '亚太-中华'
  209. break
  210. default:
  211. marketTitle.value = '全球指数'
  212. }
  213. }
  214. })
  215. // 方法
  216. const goBack = () => {
  217. uni.navigateBack()
  218. }
  219. const sortByPrice = () => {
  220. if (sortType.value === 'price') {
  221. sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
  222. } else {
  223. sortType.value = 'price'
  224. sortOrder.value = 'desc'
  225. }
  226. }
  227. const sortByChange = () => {
  228. if (sortType.value === 'change') {
  229. sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
  230. } else {
  231. sortType.value = 'change'
  232. sortOrder.value = 'desc'
  233. }
  234. }
  235. const viewStockDetail = (stock) => {
  236. console.log('查看股票详情:', stock)
  237. // 这里可以跳转到股票详情页面
  238. }
  239. onMounted(() => {
  240. // 获取状态栏高度
  241. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  242. // 动态计算header实际高度
  243. uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
  244. if (rect) {
  245. headerHeight.value = rect.height
  246. console.log('Header实际高度:', headerHeight.value, 'px')
  247. }
  248. }).exec()
  249. })
  250. // 监听headerHeight变化,重新计算contentHeight
  251. watch(headerHeight, (newHeight) => {
  252. if (newHeight > 0) {
  253. const systemInfo = uni.getSystemInfoSync()
  254. const windowHeight = systemInfo.windowHeight
  255. const statusBarHeight = systemInfo.statusBarHeight || 0
  256. const footerHeight = 100
  257. contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
  258. console.log('重新计算contentHeight:', contentHeight.value)
  259. }
  260. })
  261. </script>
  262. <style scoped>
  263. .main {
  264. width: 100%;
  265. height: 100vh;
  266. background-color: #f5f5f5;
  267. position: relative;
  268. }
  269. /* 自定义导航栏 */
  270. .header_fixed {
  271. position: fixed;
  272. top: 0;
  273. left: 0;
  274. right: 0;
  275. z-index: 1000;
  276. background-color: #ffffff;
  277. border-bottom: 1px solid #f0f0f0;
  278. }
  279. .header-content {
  280. display: flex;
  281. align-items: center;
  282. justify-content: space-between;
  283. height: 44px;
  284. padding: 0 15px;
  285. }
  286. .header-left,
  287. .header-right {
  288. width: 60px;
  289. display: flex;
  290. align-items: center;
  291. }
  292. .header-left {
  293. justify-content: flex-start;
  294. }
  295. .header-right {
  296. justify-content: flex-end;
  297. gap: 10px;
  298. }
  299. .back-text {
  300. font-size: 24px;
  301. color: #333333;
  302. font-weight: 500;
  303. line-height: 1;
  304. }
  305. .header-center {
  306. flex: 1;
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. }
  311. .header-title {
  312. font-size: 18px;
  313. font-weight: 600;
  314. color: #333333;
  315. }
  316. .header-icon {
  317. width: 20px;
  318. height: 20px;
  319. }
  320. .more-text {
  321. font-size: 20px;
  322. color: #666666;
  323. font-weight: bold;
  324. }
  325. /* 内容区域 */
  326. .content {
  327. position: fixed;
  328. left: 0;
  329. right: 0;
  330. bottom: 0;
  331. background-color: #ffffff;
  332. }
  333. /* 表头样式 */
  334. .table-header {
  335. display: flex;
  336. padding: 12px 15px;
  337. background-color: #f8f9fa;
  338. border-bottom: 1px solid #e9ecef;
  339. }
  340. .header-item {
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. cursor: pointer;
  345. }
  346. .header-item.name-column {
  347. flex: 2;
  348. justify-content: flex-start;
  349. }
  350. .header-item.price-column,
  351. .header-item.change-column {
  352. flex: 1;
  353. justify-content: center;
  354. }
  355. .header-text {
  356. font-size: 14px;
  357. color: #666666;
  358. font-weight: 500;
  359. }
  360. .sort-icon {
  361. margin-left: 4px;
  362. font-size: 12px;
  363. color: #999999;
  364. }
  365. /* 股票列表 */
  366. .stock-list {
  367. background-color: #ffffff;
  368. }
  369. .stock-row {
  370. display: flex;
  371. align-items: center;
  372. padding: 12px 15px;
  373. border-bottom: 1px solid #f5f5f5;
  374. }
  375. .stock-row:active {
  376. background-color: #f8f8f8;
  377. }
  378. .stock-cell {
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. }
  383. .stock-cell.name-column {
  384. flex: 2;
  385. align-items: flex-start;
  386. }
  387. .stock-cell.price-column,
  388. .stock-cell.change-column {
  389. flex: 1;
  390. align-items: center;
  391. }
  392. .stock-name {
  393. font-size: 15px;
  394. color: #333333;
  395. font-weight: 500;
  396. line-height: 1.2;
  397. margin-bottom: 2px;
  398. }
  399. .stock-code {
  400. font-size: 11px;
  401. color: #999999;
  402. line-height: 1.2;
  403. }
  404. .stock-price {
  405. font-size: 15px;
  406. font-weight: 600;
  407. line-height: 1.2;
  408. }
  409. .stock-change {
  410. font-size: 13px;
  411. font-weight: 500;
  412. line-height: 1.2;
  413. }
  414. .rising {
  415. color: #00C851;
  416. }
  417. .falling {
  418. color: #FF4444;
  419. }
  420. /* 底部安全区域 */
  421. /* .bottom-safe-area {
  422. height: 20px;
  423. } */
  424. /* 底部导航栏 */
  425. /* .static-footer {
  426. position: fixed;
  427. bottom: 0;
  428. left: 0;
  429. right: 0;
  430. z-index: 1000;
  431. } */
  432. </style>