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.

1114 lines
28 KiB

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