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.

491 lines
10 KiB

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