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.

488 lines
10 KiB

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