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.

493 lines
9.9 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
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="viewIndexDetail(stock)">
  38. <view class="stock-cell name-column">
  39. <view class="stock-name">{{ stock.stockName }}</view>
  40. <view class="stock-code">{{ stock.stockCode }}</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. stockName: 'Telecommunication',
  79. stockCode: '888607',
  80. price: 1349.47,
  81. change: '+7.67%',
  82. isRising: true
  83. },
  84. {
  85. stockName: 'Other',
  86. stockCode: '888607',
  87. price: 1349.47,
  88. change: '+6.67%',
  89. isRising: true
  90. },
  91. {
  92. stockName: 'Consumer Discretio...',
  93. stockCode: '888610',
  94. price: 1349.47,
  95. change: '+5.67%',
  96. isRising: true
  97. },
  98. {
  99. stockName: 'Telecommunication',
  100. stockCode: '888607',
  101. price: 1349.47,
  102. change: '+4.67%',
  103. isRising: true
  104. },
  105. {
  106. stockName: 'Other',
  107. stockCode: '888611',
  108. price: 1359.47,
  109. change: '+3.67%',
  110. isRising: true
  111. },
  112. {
  113. stockName: 'Consumer Discretio...',
  114. stockCode: '888610',
  115. price: 1349.47,
  116. change: '+2.67%',
  117. isRising: true
  118. },
  119. {
  120. stockName: 'Telecommunication',
  121. stockCode: '888607',
  122. price: 1349.47,
  123. change: '+1.67%',
  124. isRising: true
  125. },
  126. {
  127. stockName: 'Other',
  128. stockCode: '888611',
  129. price: 1009.98,
  130. change: '-1.67%',
  131. isRising: false
  132. },
  133. {
  134. stockName: 'Consumer Discretio...',
  135. stockCode: '888610',
  136. price: 1009.98,
  137. change: '-0.67%',
  138. isRising: false
  139. },
  140. {
  141. stockName: 'Telecommunication',
  142. stockCode: '888607',
  143. price: 1009.98,
  144. change: '-0.67%',
  145. isRising: false
  146. },
  147. {
  148. stockName: 'Other',
  149. stockCode: '888611',
  150. price: 1009.98,
  151. change: '-1.67%',
  152. isRising: false
  153. },
  154. {
  155. stockName: 'Consumer Discretio...',
  156. stockCode: '888610',
  157. price: 1009.98,
  158. change: '-4.67%',
  159. isRising: false
  160. },
  161. {
  162. stockName: 'Consumer Discretio...',
  163. stockCode: '888610',
  164. price: 1009.98,
  165. change: '-3.67%',
  166. isRising: false
  167. },
  168. {
  169. stockName: 'Consumer Discretio...',
  170. stockCode: '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. // 方法:查看指数详情
  221. const viewIndexDetail = (item) => {
  222. console.log('查看指数详情:', item.stockName)
  223. // uni.showToast({
  224. // title: `查看 ${item.stockName} 详情`,
  225. // icon: 'none',
  226. // duration: 2000
  227. // })
  228. // 这里可以跳转到具体的指数详情页面
  229. uni.navigateTo({
  230. url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`
  231. })
  232. }
  233. const sortByPrice = () => {
  234. if (sortType.value === 'price') {
  235. sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
  236. } else {
  237. sortType.value = 'price'
  238. sortOrder.value = 'desc'
  239. }
  240. }
  241. const sortByChange = () => {
  242. if (sortType.value === 'change') {
  243. sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
  244. } else {
  245. sortType.value = 'change'
  246. sortOrder.value = 'desc'
  247. }
  248. }
  249. onMounted(() => {
  250. // 获取状态栏高度
  251. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  252. // 动态计算header实际高度
  253. uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
  254. if (rect) {
  255. headerHeight.value = rect.height
  256. console.log('Header实际高度:', headerHeight.value, 'px')
  257. }
  258. }).exec()
  259. })
  260. // 监听headerHeight变化,重新计算contentHeight
  261. watch(headerHeight, (newHeight) => {
  262. if (newHeight > 0) {
  263. const systemInfo = uni.getSystemInfoSync()
  264. const windowHeight = systemInfo.windowHeight
  265. const statusBarHeight = systemInfo.statusBarHeight || 0
  266. const footerHeight = 100
  267. contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
  268. console.log('重新计算contentHeight:', contentHeight.value)
  269. }
  270. })
  271. </script>
  272. <style scoped>
  273. .main {
  274. width: 100%;
  275. height: 100vh;
  276. background-color: #f5f5f5;
  277. position: relative;
  278. }
  279. /* 自定义导航栏 */
  280. .header_fixed {
  281. position: fixed;
  282. top: 0;
  283. left: 0;
  284. right: 0;
  285. z-index: 1000;
  286. background-color: #ffffff;
  287. border-bottom: 1px solid #f0f0f0;
  288. }
  289. .header-content {
  290. display: flex;
  291. align-items: center;
  292. justify-content: space-between;
  293. height: 44px;
  294. padding: 0 15px;
  295. }
  296. .header-left,
  297. .header-right {
  298. width: 60px;
  299. display: flex;
  300. align-items: center;
  301. }
  302. .header-left {
  303. justify-content: flex-start;
  304. }
  305. .header-right {
  306. justify-content: flex-end;
  307. gap: 10px;
  308. }
  309. .back-text {
  310. font-size: 24px;
  311. color: #333333;
  312. font-weight: 500;
  313. line-height: 1;
  314. }
  315. .header-center {
  316. flex: 1;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. }
  321. .header-title {
  322. font-size: 18px;
  323. font-weight: 600;
  324. color: #333333;
  325. }
  326. .header-icon {
  327. width: 20px;
  328. height: 20px;
  329. }
  330. .more-text {
  331. font-size: 20px;
  332. color: #666666;
  333. font-weight: bold;
  334. }
  335. /* 内容区域 */
  336. .content {
  337. position: fixed;
  338. left: 0;
  339. right: 0;
  340. bottom: 0;
  341. background-color: #ffffff;
  342. }
  343. /* 表头样式 */
  344. .table-header {
  345. display: flex;
  346. padding: 12px 15px;
  347. background-color: #f8f9fa;
  348. border-bottom: 1px solid #e9ecef;
  349. }
  350. .header-item {
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. cursor: pointer;
  355. }
  356. .header-item.name-column {
  357. flex: 2;
  358. justify-content: flex-start;
  359. }
  360. .header-item.price-column,
  361. .header-item.change-column {
  362. flex: 1;
  363. justify-content: center;
  364. }
  365. .header-text {
  366. font-size: 14px;
  367. color: #666666;
  368. font-weight: 500;
  369. }
  370. .sort-icon {
  371. margin-left: 4px;
  372. font-size: 12px;
  373. color: #999999;
  374. }
  375. /* 股票列表 */
  376. .stock-list {
  377. background-color: #ffffff;
  378. }
  379. .stock-row {
  380. display: flex;
  381. align-items: center;
  382. padding: 12px 15px;
  383. border-bottom: 1px solid #f5f5f5;
  384. }
  385. .stock-row:active {
  386. background-color: #f8f8f8;
  387. }
  388. .stock-cell {
  389. display: flex;
  390. flex-direction: column;
  391. align-items: center;
  392. }
  393. .stock-cell.name-column {
  394. flex: 2;
  395. align-items: flex-start;
  396. }
  397. .stock-cell.price-column,
  398. .stock-cell.change-column {
  399. flex: 1;
  400. align-items: center;
  401. }
  402. .stock-name {
  403. font-size: 15px;
  404. color: #333333;
  405. font-weight: 500;
  406. line-height: 1.2;
  407. margin-bottom: 2px;
  408. }
  409. .stock-code {
  410. font-size: 11px;
  411. color: #999999;
  412. line-height: 1.2;
  413. }
  414. .stock-price {
  415. font-size: 15px;
  416. font-weight: 600;
  417. line-height: 1.2;
  418. }
  419. .stock-change {
  420. font-size: 13px;
  421. font-weight: 500;
  422. line-height: 1.2;
  423. }
  424. .rising {
  425. color: #00C851;
  426. }
  427. .falling {
  428. color: #FF4444;
  429. }
  430. /* 底部安全区域 */
  431. /* .bottom-safe-area {
  432. height: 20px;
  433. } */
  434. /* 底部导航栏 */
  435. /* .static-footer {
  436. position: fixed;
  437. bottom: 0;
  438. left: 0;
  439. right: 0;
  440. z-index: 1000;
  441. } */
  442. </style>