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.

1128 lines
29 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
3 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 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
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 weeks ago
3 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
3 weeks ago
4 weeks ago
  1. <!-- @format -->
  2. <template>
  3. <view class="main">
  4. <h-loading :loading="loading"></h-loading>
  5. <!-- 可滚动内容区域 -->
  6. <scroll-view class="content_scroll" scroll-y="true" :style="{ top: contentTopPosition + 'px' }">
  7. <view class="content">
  8. <view class="map">
  9. <view class="INDU"
  10. >道琼斯<view :class="getSignClass(INDU.value)">{{ judgeSymbol(INDU.value) }}</view></view
  11. >
  12. <view class="NDX"
  13. >纳斯达克<view :class="getSignClass(NDX.value)">{{ judgeSymbol(NDX.value) }}</view></view
  14. >
  15. <view class="HSI"
  16. >恒生指数<view :class="getSignClass(HSI.value)">{{ judgeSymbol(HSI.value) }}</view></view
  17. >
  18. <view class="CN"
  19. >上证指数<view :class="getSignClass(CN.value)">{{ judgeSymbol(CN.value) }}</view></view
  20. >
  21. <image src="/static/marketSituation-image/map.png" mode="widthFix"></image>
  22. </view>
  23. <view class="global_index">
  24. <view class="global_index_title">
  25. {{ $t("marketSituation.globalIndex") }}
  26. </view>
  27. <view class="global_index_more" @click="goToGlobalIndex">
  28. <text>{{ $t("marketSituation.globalIndexMore") }}</text>
  29. <image src="/static/marketSituation-image/more.png" mode="aspectFit"></image>
  30. </view>
  31. </view>
  32. <!-- 卡片网格 -->
  33. <view class="cards_grid">
  34. <view v-for="(card, index) in marketSituationStore.cardData" :key="index" class="card_item">
  35. <IndexCard
  36. :market="card.market"
  37. :stockName="card.stockName"
  38. :currentPrice="card.currentPrice"
  39. :changeAmount="card.changeAmount"
  40. :changePercent="card.changePercent"
  41. :isRising="card.isRising"
  42. @click="viewIndexDetail(card, index)"
  43. />
  44. </view>
  45. </view>
  46. <view class="warn">
  47. <image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image>
  48. <view class="warn_text_container">
  49. <text :class="warnTextClass">{{ $t("marketSituation.warn") }}</text>
  50. </view>
  51. </view>
  52. <!-- 底部安全区域防止被导航栏遮挡 -->
  53. <view class="bottom_safe_area"></view>
  54. </view>
  55. </scroll-view>
  56. </view>
  57. </template>
  58. <script setup>
  59. import { ref, onMounted, onUnmounted, watch, nextTick, computed } from "vue";
  60. import { onShow, onHide } from "@dcloudio/uni-app";
  61. import util from "../../common/util.js";
  62. import IndexCard from "../../components/IndexCard.vue";
  63. import hLoading from "@/components/h-loading.vue";
  64. import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";
  65. const marketSituationStore = useMarketSituationStore();
  66. import { getGlobalIndexAPI } from "../../api/marketSituation/marketSituation.js";
  67. const iSMT = ref(0);
  68. const searchValue = ref("");
  69. const contentHeight = ref(0);
  70. const headerHeight = ref(0); // 动态计算的header高度
  71. const isWarnTextOverflow = ref(false); // warn文字是否溢出
  72. const loading = ref(false);
  73. const INDU = ref({ stockName: "道琼斯", stockCode: "INDU", value: "" });
  74. const NDX = ref({ stockName: "纳斯达克", stockCode: "513300", value: "" });
  75. const HSI = ref({ stockName: "恒生指数", stockCode: "HSI", value: "" });
  76. const CN = ref({ stockName: "上证指数", stockCode: "1A0001", value: "" });
  77. const pageIndex = ref(0);
  78. const scrollToView = ref("");
  79. // 计算属性:精准计算content区域的top值
  80. const contentTopPosition = computed(() => {
  81. const statusBarHeight = iSMT.value || 0;
  82. const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140;
  83. return statusBarHeight + currentHeaderHeight;
  84. });
  85. // warn文字的class计算属性
  86. const warnTextClass = computed(() => {
  87. return isWarnTextOverflow.value ? "warn_text scroll-active" : "warn_text";
  88. });
  89. const globalIndexArray = ref([]);
  90. const judgeSymbol = (num) => {
  91. return num[0] === "-" ? num : "+" + num;
  92. };
  93. function getSignClass(value) {
  94. const s = typeof value === "string" ? value : String(value ?? "");
  95. const trimmed = s.trim();
  96. if (trimmed.startsWith("-")) return "index-down";
  97. if (trimmed.startsWith("+")) return "index-up";
  98. const n = parseFloat(trimmed);
  99. if (!isNaN(n)) return n >= 0 ? "index-up" : "index-down";
  100. return "";
  101. }
  102. // 搜索输入事件
  103. const onSearchInput = (e) => {
  104. searchValue.value = e.detail.value;
  105. };
  106. // 搜索确认事件
  107. const onSearchConfirm = (e) => {
  108. console.log("搜索内容:", e.detail.value);
  109. // 这里可以添加搜索逻辑
  110. performSearch(e.detail.value);
  111. };
  112. // 搜索图标点击事件
  113. const onSearchClick = () => {
  114. if (searchValue.value.trim()) {
  115. performSearch(searchValue.value);
  116. }
  117. };
  118. // 执行搜索
  119. const performSearch = (keyword) => {
  120. if (!keyword.trim()) {
  121. uni.showToast({
  122. title: "请输入搜索内容",
  123. icon: "none",
  124. });
  125. return;
  126. }
  127. uni.showToast({
  128. title: `搜索: ${keyword}`,
  129. icon: "none",
  130. });
  131. // 这里添加实际的搜索逻辑
  132. };
  133. // 检测warn文字是否溢出
  134. const checkWarnTextOverflow = () => {
  135. nextTick(() => {
  136. setTimeout(() => {
  137. const query = uni.createSelectorQuery();
  138. // 同时查询容器和文字元素
  139. query.select(".warn_text_container").boundingClientRect();
  140. query.select(".warn_text").boundingClientRect();
  141. query.exec((res) => {
  142. const containerRect = res[0];
  143. const textRect = res[1];
  144. if (!containerRect || !textRect) {
  145. return;
  146. }
  147. // 判断文字是否超出容器(留一些余量)
  148. const isOverflow = textRect.width > containerRect.width - 10;
  149. isWarnTextOverflow.value = isOverflow;
  150. });
  151. }, 500);
  152. });
  153. };
  154. // 方法:查看指数详情
  155. const viewIndexDetail = (item, index) => {
  156. console.log("查看指数详情:", item.stockName);
  157. // uni.showToast({
  158. // title: `查看 ${item.stockName} 详情`,
  159. // icon: 'none',
  160. // duration: 2000
  161. // })
  162. // 这里可以跳转到具体的指数详情页面
  163. uni.navigateTo({
  164. url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}&index=${index}&from=marketOverview`,
  165. });
  166. };
  167. // 跳转到全球指数页面
  168. const goToGlobalIndex = () => {
  169. uni.navigateTo({
  170. url: "/pages/marketSituation/globalIndex",
  171. });
  172. };
  173. const getGlobalIndex = async () => {
  174. try {
  175. loading.value = true;
  176. const result = await getGlobalIndexAPI();
  177. globalIndexArray.value = result.data;
  178. loading.value = false;
  179. } catch (e) {
  180. console.log("获取全球指数失败", e);
  181. loading.value = false;
  182. }
  183. };
  184. // TCP相关响应式变量
  185. import tcpConnection from "@/api/tcpConnection.js";
  186. const tcpConnected = ref(false);
  187. const connectionListener = ref(null);
  188. const messageListener = ref(null);
  189. // 初始化TCP监听器
  190. const initTcpListeners = () => {
  191. // 创建连接状态监听器并保存引用
  192. connectionListener.value = (status, result) => {
  193. tcpConnected.value = status === "connected";
  194. console.log("TCP连接状态变化:", status, tcpConnected.value);
  195. // 如果连接,发送获取批量数据
  196. if (status === "connected") {
  197. sendTcpMessage("batch_real_time");
  198. }
  199. };
  200. // 创建消息监听器并保存引用
  201. messageListener.value = (type, message, parsedArray) => {
  202. const messageObj = {
  203. type: type,
  204. content: message,
  205. parsedArray: parsedArray,
  206. timestamp: new Date().toLocaleTimeString(),
  207. direction: "received",
  208. };
  209. // 解析股票数据
  210. parseStockData(message);
  211. };
  212. // 注册监听器
  213. tcpConnection.onConnectionChange(connectionListener.value);
  214. tcpConnection.onMessage(messageListener.value);
  215. };
  216. // 连接TCP服务器
  217. const connectTcp = () => {
  218. console.log("开始连接TCP服务器...");
  219. tcpConnection.connect();
  220. };
  221. // 断开TCP连接
  222. const disconnectTcp = () => {
  223. console.log("断开TCP连接...");
  224. tcpConnection.disconnect();
  225. tcpConnected.value = false;
  226. };
  227. // 发送TCP消息
  228. const sendTcpMessage = (command) => {
  229. let messageData;
  230. let messageDataArray = [];
  231. if (command == "batch_real_time") {
  232. messageDataArray = globalIndexArray.value.map((item) => item.stockCode);
  233. }
  234. switch (command) {
  235. // 实时行情推送
  236. case "real_time":
  237. messageData = {
  238. command: "real_time",
  239. stock_code: "SH.000001",
  240. };
  241. break;
  242. // 初始化获取行情历史数据
  243. case "init_real_time":
  244. messageData = {
  245. command: "init_real_time",
  246. stock_code: "SH.000001",
  247. };
  248. break;
  249. case "stop_real_time":
  250. messageData = {
  251. command: "stop_real_time",
  252. };
  253. break;
  254. // 股票列表
  255. case "stock_list":
  256. messageData = {
  257. command: "stock_list",
  258. };
  259. break;
  260. case "batch_real_time":
  261. messageData = {
  262. command: "batch_real_time",
  263. stock_codes: messageDataArray,
  264. };
  265. break;
  266. case "help":
  267. messageData = {
  268. command: "help",
  269. };
  270. break;
  271. }
  272. if (!messageData) {
  273. return;
  274. } else {
  275. try {
  276. // 发送消息
  277. const success = tcpConnection.send(messageData);
  278. if (success) {
  279. console.log("home发送TCP消息:", messageData);
  280. }
  281. } catch (error) {
  282. console.error("发送TCP消息时出错:", error);
  283. }
  284. }
  285. };
  286. // 获取TCP连接状态
  287. const getTcpStatus = () => {
  288. const status = tcpConnection.getConnectionStatus();
  289. uni.showModal({
  290. title: "TCP连接状态",
  291. content: `当前状态: ${status ? "已连接" : "未连接"}`,
  292. showCancel: false,
  293. });
  294. };
  295. let isMorePacket = {
  296. init_batch_real_time: false,
  297. batch_real_time: false,
  298. };
  299. let receivedMessage;
  300. // 解析TCP股票数据
  301. const parseStockData = (message) => {
  302. try {
  303. console.log("进入parseStockData, message类型:", typeof message);
  304. let parsedMessage;
  305. // 如果isMorePacket是true,说明正在接受分包数据,无条件接收
  306. // 如果message是字符串且以{开头,说明是JSON字符串,需要解析
  307. // 如果不属于以上两种情况,说明是普通字符串,不预解析
  308. if (message.includes("欢迎连接到股票数据服务器")) {
  309. console.log("服务器命令列表,不予处理");
  310. return;
  311. }
  312. if ((typeof message === "string" && message.includes("batch_data_start")) || isMorePacket.init_batch_real_time) {
  313. if (typeof message === "string" && message.includes("batch_data_start")) {
  314. console.log("开始接受分包数据");
  315. receivedMessage = "";
  316. } else {
  317. console.log("接收分包数据过程中");
  318. }
  319. isMorePacket.init_batch_real_time = true;
  320. receivedMessage += message;
  321. // 如果当前消息包含},说明收到JSON字符串结尾,结束接收,开始解析
  322. if (receivedMessage.includes("batch_data_complete")) {
  323. console.log("接受分包数据结束");
  324. isMorePacket.init_batch_real_time = false;
  325. console.log("展示数据", receivedMessage);
  326. let startIndex = 0;
  327. let startCount = 0;
  328. let endIndex = receivedMessage.indexOf("batch_data_complete");
  329. for (let i = 0; i < receivedMessage.length; ++i) {
  330. if (receivedMessage[i] == "{") {
  331. startCount++;
  332. if (startCount == 2) {
  333. startIndex = i;
  334. break;
  335. }
  336. }
  337. }
  338. for (let i = receivedMessage.indexOf("batch_data_complete"); i >= 0; --i) {
  339. if (receivedMessage[i] == "}" || startIndex == endIndex) {
  340. endIndex = i;
  341. break;
  342. }
  343. }
  344. if (startIndex >= endIndex) {
  345. throw new Error("JSON字符串格式错误");
  346. }
  347. console.log("message", startIndex, endIndex, receivedMessage[endIndex], receivedMessage[startIndex]);
  348. parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
  349. console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
  350. const stockDataArray = parsedMessage.data;
  351. marketSituationStore.cardData = globalIndexArray.value.map((item) => ({
  352. market: item.market,
  353. stockCode: item.stockCode,
  354. stockName: item.stockName,
  355. currentPrice: stockDataArray[item.stockCode][0].current_price.toFixed(2),
  356. changeAmount: (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close).toFixed(2),
  357. changePercent: ((100 * (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close)) / stockDataArray[item.stockCode][0].pre_close).toFixed(2) + "%",
  358. isRising: stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close >= 0,
  359. }));
  360. if (stockDataArray[INDU.value.stockCode][0]) {
  361. INDU.value.value = ((100 * (stockDataArray[INDU.value.stockCode][0].current_price - stockDataArray[INDU.value.stockCode][0].pre_close)) / stockDataArray[INDU.value.stockCode][0].pre_close).toFixed(2) + "%";
  362. } else {
  363. console.log("INDU不存在");
  364. }
  365. if (stockDataArray[NDX.value.stockCode][0]) {
  366. NDX.value.value = ((100 * (stockDataArray[NDX.value.stockCode][0].current_price - stockDataArray[NDX.value.stockCode][0].pre_close)) / stockDataArray[NDX.value.stockCode][0].pre_close).toFixed(2) + "%";
  367. } else {
  368. console.log("NDX不存在");
  369. }
  370. if (stockDataArray[HSI.value.stockCode][0]) {
  371. HSI.value.value = ((100 * (stockDataArray[HSI.value.stockCode][0].current_price - stockDataArray[HSI.value.stockCode][0].pre_close)) / stockDataArray[HSI.value.stockCode][0].pre_close).toFixed(2) + "%";
  372. } else {
  373. console.log("HSI不存在");
  374. }
  375. if (stockDataArray[CN.value.stockCode][0]) {
  376. CN.value.value = ((100 * (stockDataArray[CN.value.stockCode][0].current_price - stockDataArray[CN.value.stockCode][0].pre_close)) / stockDataArray[CN.value.stockCode][0].pre_close).toFixed(2) + "%";
  377. } else {
  378. console.log("CN不存在");
  379. }
  380. }
  381. } else if ((typeof message === "string" && message.includes('{"count')) || isMorePacket.batch_real_time) {
  382. if (typeof message === "string" && message.includes('{"count')) {
  383. console.log("开始接受分包数据");
  384. receivedMessage = "";
  385. } else {
  386. console.log("接收分包数据过程中");
  387. }
  388. isMorePacket.batch_real_time = true;
  389. receivedMessage += message;
  390. // 如果当前消息包含},说明收到JSON字符串结尾,结束接收,开始解析
  391. if (receivedMessage.includes("batch_realtime_data")) {
  392. console.log("接受分包数据结束");
  393. isMorePacket.batch_real_time = false;
  394. console.log("展示数据", receivedMessage);
  395. let startIndex = 0;
  396. let endIndex = receivedMessage.length - 1;
  397. for (let i = 0; i < receivedMessage.length; ++i) {
  398. if (receivedMessage[i] == "{") {
  399. startIndex = i;
  400. break;
  401. }
  402. }
  403. for (let i = receivedMessage.length - 1; i >= 0; --i) {
  404. if (receivedMessage[i] == "}" || startIndex == endIndex) {
  405. endIndex = i;
  406. break;
  407. }
  408. }
  409. if (startIndex >= endIndex) {
  410. throw new Error("JSON字符串格式错误");
  411. }
  412. parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
  413. console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
  414. const stockDataArray = parsedMessage.data;
  415. marketSituationStore.cardData = globalIndexArray.value.map((item) => ({
  416. market: item.market,
  417. stockCode: item.stockCode,
  418. stockName: item.stockName,
  419. currentPrice: stockDataArray[item.stockCode][0].current_price.toFixed(2),
  420. changeAmount: (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close).toFixed(2),
  421. changePercent: ((100 * (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close)) / stockDataArray[item.stockCode][0].pre_close).toFixed(2) + "%",
  422. isRising: stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close >= 0,
  423. }));
  424. if (stockDataArray[INDU.value.stockCode][0]) {
  425. INDU.value.value = ((100 * (stockDataArray[INDU.value.stockCode][0].current_price - stockDataArray[INDU.value.stockCode][0].pre_close)) / stockDataArray[INDU.value.stockCode][0].pre_close).toFixed(2) + "%";
  426. } else {
  427. console.log("INDU不存在");
  428. }
  429. if (stockDataArray[NDX.value.stockCode][0]) {
  430. NDX.value.value = ((100 * (stockDataArray[NDX.value.stockCode][0].current_price - stockDataArray[NDX.value.stockCode][0].pre_close)) / stockDataArray[NDX.value.stockCode][0].pre_close).toFixed(2) + "%";
  431. } else {
  432. console.log("NDX不存在");
  433. }
  434. if (stockDataArray[HSI.value.stockCode][0]) {
  435. HSI.value.value = ((100 * (stockDataArray[HSI.value.stockCode][0].current_price - stockDataArray[HSI.value.stockCode][0].pre_close)) / stockDataArray[HSI.value.stockCode][0].pre_close).toFixed(2) + "%";
  436. } else {
  437. console.log("HSI不存在");
  438. }
  439. if (stockDataArray[CN.value.stockCode][0]) {
  440. CN.value.value = ((100 * (stockDataArray[CN.value.stockCode][0].current_price - stockDataArray[CN.value.stockCode][0].pre_close)) / stockDataArray[CN.value.stockCode][0].pre_close).toFixed(2) + "%";
  441. } else {
  442. console.log("CN不存在");
  443. }
  444. }
  445. } else {
  446. // 没有通过JSON解析判断,说明不是需要的数据
  447. console.log("不是需要的数据,不做处理");
  448. }
  449. } catch (error) {
  450. console.error("解析TCP股票数据失败:", error.message);
  451. console.error("错误详情:", error);
  452. }
  453. };
  454. // 移除TCP监听器
  455. const removeTcpListeners = () => {
  456. if (connectionListener.value) {
  457. tcpConnection.removeConnectionListener(connectionListener.value);
  458. connectionListener.value = null;
  459. console.log("已移除TCP连接状态监听器");
  460. }
  461. if (messageListener.value) {
  462. tcpConnection.removeMessageListener(messageListener.value);
  463. messageListener.value = null;
  464. console.log("已移除TCP消息监听器");
  465. }
  466. };
  467. const startTcp = () => {
  468. try {
  469. removeTcpListeners();
  470. disconnectTcp();
  471. initTcpListeners();
  472. console.log("初始化完成,,,,,,,,,,,,,,,");
  473. connectTcp();
  474. } catch (error) {
  475. console.error("建立连接并设置监听出错:", error);
  476. }
  477. };
  478. onShow(async () => {
  479. console.log("显示页面");
  480. await getGlobalIndex();
  481. initTcpListeners();
  482. await nextTick();
  483. // 开始连接
  484. startTcp();
  485. });
  486. onHide(() => {
  487. console.log("隐藏页面");
  488. sendTcpMessage("stop_real_time");
  489. removeTcpListeners();
  490. disconnectTcp();
  491. });
  492. onUnmounted(() => {
  493. console.log("卸载页面");
  494. sendTcpMessage("stop_real_time");
  495. removeTcpListeners();
  496. disconnectTcp();
  497. });
  498. onMounted(async () => {
  499. console.log("挂载页面");
  500. // 状态栏高度
  501. iSMT.value = uni.getSystemInfoSync().statusBarHeight;
  502. // 确保DOM渲染完成后再查询高度
  503. nextTick(() => {
  504. // 动态计算header实际高度
  505. uni
  506. .createSelectorQuery()
  507. .select(".header_fixed")
  508. .boundingClientRect((rect) => {
  509. if (rect) {
  510. headerHeight.value = rect.height;
  511. console.log("Header实际高度:", headerHeight.value, "px");
  512. }
  513. })
  514. .exec();
  515. // 检测warn文字是否溢出
  516. checkWarnTextOverflow();
  517. });
  518. });
  519. // 监听headerHeight变化,重新计算contentHeight
  520. watch(headerHeight, (newHeight) => {
  521. if (newHeight > 0) {
  522. const systemInfo = uni.getSystemInfoSync();
  523. const windowHeight = systemInfo.windowHeight;
  524. const statusBarHeight = systemInfo.statusBarHeight || 0;
  525. const footerHeight = 100;
  526. contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight;
  527. console.log("重新计算contentHeight:", contentHeight.value);
  528. }
  529. });
  530. </script>
  531. <style scoped>
  532. /* 状态栏占位 */
  533. .top {
  534. position: fixed;
  535. top: 0;
  536. left: 0;
  537. right: 0;
  538. z-index: 1001;
  539. background-color: #ffffff;
  540. }
  541. /* 固定头部样式 */
  542. .header_fixed {
  543. position: fixed;
  544. left: 0;
  545. right: 0;
  546. z-index: 1000;
  547. background-color: #ffffff;
  548. padding: 20rpx 0 0 0;
  549. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  550. }
  551. /* 可滚动内容区域 */
  552. .content_scroll {
  553. position: fixed;
  554. left: 0;
  555. right: 0;
  556. bottom: 100rpx;
  557. /* 底部导航栏高度 */
  558. overflow-y: auto;
  559. }
  560. .header_content {
  561. display: flex;
  562. align-items: center;
  563. justify-content: space-between;
  564. height: 80rpx;
  565. padding: 0 20rpx;
  566. margin-bottom: 10rpx;
  567. }
  568. .header_input_wrapper {
  569. display: flex;
  570. align-items: center;
  571. width: 100%;
  572. margin: 0 20rpx 0 0;
  573. height: 70rpx;
  574. border-radius: 35rpx;
  575. background-color: #ffffff;
  576. border: 1rpx solid #e9ecef;
  577. padding: 0 80rpx 0 30rpx;
  578. font-size: 28rpx;
  579. color: #5c5c5c;
  580. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  581. }
  582. .search_icon {
  583. width: 40rpx;
  584. height: 40rpx;
  585. opacity: 0.6;
  586. }
  587. .header_input {
  588. margin-left: 10rpx;
  589. }
  590. .header_icons {
  591. display: flex;
  592. align-items: center;
  593. gap: 15rpx;
  594. }
  595. .header_icon {
  596. width: 40rpx;
  597. height: 40rpx;
  598. display: flex;
  599. align-items: center;
  600. justify-content: center;
  601. }
  602. .header_icon image {
  603. width: 40rpx;
  604. height: 40rpx;
  605. }
  606. /* Tab 栏样式 */
  607. .channel_li {
  608. display: flex;
  609. align-items: center;
  610. height: 80rpx;
  611. background-color: #ffffff;
  612. border-bottom: 1rpx solid #f0f0f0;
  613. }
  614. .channel_wrap {
  615. width: calc(100% - 60rpx);
  616. height: 100%;
  617. overflow: hidden;
  618. flex-shrink: 0;
  619. }
  620. .channel_innerWrap {
  621. display: flex;
  622. align-items: center;
  623. height: 100%;
  624. padding: 0 20rpx;
  625. white-space: nowrap;
  626. }
  627. .channel_item {
  628. position: relative;
  629. display: flex;
  630. flex-direction: column;
  631. align-items: center;
  632. justify-content: center;
  633. height: 60rpx;
  634. padding: 0 20rpx;
  635. border-radius: 30rpx;
  636. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  637. cursor: pointer;
  638. white-space: nowrap;
  639. flex-shrink: 0;
  640. }
  641. .channel_item:active {
  642. transform: scale(0.98);
  643. }
  644. .channel_item.active {
  645. color: #333;
  646. font-weight: bold;
  647. }
  648. .channel_text {
  649. font-size: 28rpx;
  650. font-weight: 500;
  651. color: #666666;
  652. transition: color 0.3s ease;
  653. white-space: nowrap;
  654. }
  655. .channel_item.active .channel_text {
  656. color: #333333;
  657. font-weight: 400;
  658. z-index: 2;
  659. }
  660. .active_indicator {
  661. position: absolute;
  662. left: 50%;
  663. top: 60%;
  664. transform: translateX(-45%);
  665. width: calc(100% - 20rpx);
  666. min-width: 40rpx;
  667. max-width: 120rpx;
  668. height: 8rpx;
  669. background-image: url("/static/marketSituation-image/bg.png");
  670. background-size: cover;
  671. background-position: center;
  672. background-repeat: no-repeat;
  673. animation: slideIn 0.1s ease;
  674. border-radius: 8rpx;
  675. z-index: 1;
  676. }
  677. @keyframes slideIn {
  678. from {
  679. width: 0;
  680. opacity: 0;
  681. }
  682. to {
  683. width: 40rpx;
  684. opacity: 1;
  685. }
  686. }
  687. .scroll_indicator {
  688. border-left: 1rpx solid #b6b6b6;
  689. display: flex;
  690. align-items: center;
  691. justify-content: center;
  692. width: 60rpx;
  693. height: 30rpx;
  694. background-color: #ffffff;
  695. flex-shrink: 0;
  696. }
  697. .scroll_indicator image {
  698. width: 20rpx;
  699. height: 20rpx;
  700. opacity: 0.5;
  701. }
  702. .content {
  703. margin-top: 20rpx;
  704. background-color: white;
  705. }
  706. .map {
  707. width: calc(100% - 60rpx);
  708. margin: 0 30rpx;
  709. display: flex;
  710. align-items: center;
  711. justify-content: center;
  712. background-color: #f3f3f3;
  713. border-radius: 30rpx;
  714. border: 1rpx solid #e0e0e0;
  715. padding: 30rpx 20rpx;
  716. box-sizing: border-box;
  717. /* 设置最小高度保护,但允许内容撑开 */
  718. min-height: 200rpx;
  719. }
  720. .NDX {
  721. position: absolute;
  722. top: 23vh;
  723. left: 17vw;
  724. transform: translate(-50%, -50%);
  725. font-size: 11rpx;
  726. color: #000000;
  727. padding: 5rpx 10rpx;
  728. border-radius: 10rpx;
  729. background-color: #ffffff;
  730. z-index: 10;
  731. display: flex;
  732. align-items: center;
  733. justify-content: center;
  734. }
  735. .INDU {
  736. position: absolute;
  737. top: 15vh;
  738. left: 35vw;
  739. transform: translate(-50%, -50%);
  740. font-size: 11rpx;
  741. color: #000000;
  742. padding: 5rpx 10rpx;
  743. border-radius: 10rpx;
  744. background-color: #ffffff;
  745. z-index: 10;
  746. display: flex;
  747. align-items: center;
  748. justify-content: center;
  749. }
  750. .HSI {
  751. position: absolute;
  752. top: 23vh;
  753. right: 4vw;
  754. transform: translate(-50%, -50%);
  755. font-size: 11rpx;
  756. color: #000000;
  757. padding: 5rpx 10rpx;
  758. border-radius: 10rpx;
  759. background-color: #ffffff;
  760. z-index: 10;
  761. display: flex;
  762. align-items: center;
  763. justify-content: center;
  764. }
  765. .CN {
  766. position: absolute;
  767. top: 16vh;
  768. right: 8vw;
  769. transform: translate(-50%, -50%);
  770. font-size: 11rpx;
  771. color: #000000;
  772. padding: 5rpx 10rpx;
  773. border-radius: 10rpx;
  774. background-color: #ffffff;
  775. z-index: 10;
  776. display: flex;
  777. align-items: center;
  778. justify-content: center;
  779. }
  780. .map image {
  781. width: 100%;
  782. height: auto;
  783. max-width: 100%;
  784. display: block;
  785. /* widthFix模式下,高度会自动按比例调整 */
  786. /* 设置最大高度避免图片过大 */
  787. max-height: 60vh;
  788. /* 添加平滑过渡效果 */
  789. transition: all 0.3s ease;
  790. max-height: 60vh;
  791. }
  792. /* 响应式优化 */
  793. @media screen and (max-width: 750rpx) {
  794. .map {
  795. margin: 0 20rpx;
  796. width: calc(100% - 40rpx);
  797. padding: 20rpx 15rpx;
  798. }
  799. }
  800. @media screen and (max-width: 480rpx) {
  801. .map {
  802. margin: 0 15rpx;
  803. width: calc(100% - 30rpx);
  804. padding: 15rpx 10rpx;
  805. }
  806. }
  807. .static-footer {
  808. position: fixed;
  809. bottom: 0;
  810. }
  811. /* 弹窗样式 */
  812. .modal_overlay {
  813. position: fixed;
  814. top: 0;
  815. left: 0;
  816. right: 0;
  817. bottom: 0;
  818. background-color: rgba(0, 0, 0, 0.5);
  819. display: flex;
  820. align-items: flex-end;
  821. z-index: 1000;
  822. }
  823. .modal_content {
  824. width: 100%;
  825. background-color: #fff;
  826. border-radius: 20rpx 20rpx 0 0;
  827. max-height: 80vh;
  828. overflow: hidden;
  829. }
  830. .modal_header {
  831. position: relative;
  832. display: flex;
  833. justify-content: center;
  834. align-items: center;
  835. padding: 30rpx 40rpx;
  836. border-bottom: 1rpx solid #f0f0f0;
  837. }
  838. .modal_title {
  839. font-size: 32rpx;
  840. font-weight: bold;
  841. color: #333333;
  842. text-align: center;
  843. }
  844. .modal_close {
  845. position: absolute;
  846. right: 40rpx;
  847. top: 50%;
  848. transform: translateY(-50%);
  849. width: 60rpx;
  850. height: 60rpx;
  851. display: flex;
  852. align-items: center;
  853. justify-content: center;
  854. font-size: 40rpx;
  855. color: #999;
  856. }
  857. .modal_body {
  858. padding: 40rpx;
  859. }
  860. .country_grid {
  861. display: grid;
  862. grid-template-columns: 1fr 1fr;
  863. gap: 20rpx;
  864. }
  865. .country_item {
  866. padding: 24rpx 30rpx;
  867. border-radius: 12rpx;
  868. background-color: #f8f8f8;
  869. display: flex;
  870. align-items: center;
  871. justify-content: center;
  872. transition: all 0.3s ease;
  873. }
  874. .country_item.selected {
  875. background-color: #ff4444;
  876. color: #fff;
  877. }
  878. .country_text {
  879. font-size: 28rpx;
  880. color: #333;
  881. }
  882. .country_item.selected .country_text {
  883. color: #fff;
  884. }
  885. .global_index {
  886. margin: 30rpx 20rpx 0 20rpx;
  887. display: flex;
  888. justify-content: space-between;
  889. }
  890. .global_index_title {
  891. margin-left: 20rpx;
  892. font-size: 40rpx;
  893. font-weight: bold;
  894. color: black;
  895. align-items: center;
  896. }
  897. .global_index_more {
  898. display: flex;
  899. gap: 10rpx;
  900. font-size: 28rpx;
  901. color: #333333;
  902. align-items: center;
  903. }
  904. .global_index_more image {
  905. width: 40rpx;
  906. height: 40rpx;
  907. align-items: center;
  908. }
  909. /* 卡片网格样式 */
  910. .cards_grid {
  911. display: grid;
  912. grid-template-columns: repeat(3, 1fr);
  913. margin: 0;
  914. box-sizing: border-box;
  915. width: 100%;
  916. padding: 30rpx 0;
  917. }
  918. .card_item {
  919. width: 100%;
  920. box-sizing: border-box;
  921. min-width: 0;
  922. /* 防止内容溢出 */
  923. }
  924. /* 响应式布局 - 小屏幕时改为两列 */
  925. @media (max-width: 600rpx) {
  926. .cards_grid {
  927. grid-template-columns: repeat(2, 1fr);
  928. padding: 30rpx 0;
  929. }
  930. }
  931. /* 超小屏幕时改为单列 */
  932. @media (max-width: 400rpx) {
  933. .cards_grid {
  934. grid-template-columns: 1fr;
  935. padding: 30rpx 0;
  936. }
  937. }
  938. .warn {
  939. display: flex;
  940. align-items: center;
  941. justify-content: flex-start;
  942. gap: 10rpx;
  943. font-size: 28rpx;
  944. color: #666666;
  945. padding: 20rpx;
  946. max-width: 100%;
  947. overflow: hidden;
  948. position: relative;
  949. }
  950. .warn image {
  951. width: 40rpx;
  952. height: 40rpx;
  953. flex-shrink: 0;
  954. /* 防止图片被压缩 */
  955. position: relative;
  956. z-index: 2;
  957. /* 确保图片在最上层 */
  958. }
  959. .warn_text_container {
  960. flex: 1;
  961. overflow: hidden;
  962. position: relative;
  963. min-width: 0;
  964. /* 允许容器收缩 */
  965. }
  966. .warn_text {
  967. display: block;
  968. white-space: nowrap;
  969. will-change: transform;
  970. /* 优化动画性能 */
  971. }
  972. /* 文字滚动动画 */
  973. @keyframes scrollText {
  974. 0% {
  975. transform: translateX(0);
  976. }
  977. 20% {
  978. transform: translateX(0);
  979. }
  980. 80% {
  981. transform: translateX(-85%);
  982. }
  983. 100% {
  984. transform: translateX(-85%);
  985. }
  986. }
  987. /* 当文字超长时启用滚动动画 */
  988. .warn_text.scroll-active {
  989. animation: scrollText 12s linear infinite;
  990. animation-delay: 2s;
  991. /* 延迟2秒开始滚动,让用户先看到开头 */
  992. }
  993. /* 底部安全区域 */
  994. .bottom_safe_area {
  995. height: 40rpx;
  996. background-color: transparent;
  997. }
  998. /* 主容器样式调整 */
  999. .main {
  1000. position: relative;
  1001. height: 100vh;
  1002. overflow: hidden;
  1003. background-color: white;
  1004. }
  1005. .index-up {
  1006. color: #2fc25b !important;
  1007. }
  1008. .index-down {
  1009. color: #f04864 !important;
  1010. }
  1011. </style>