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.

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