|
|
<!-- @format -->
<template> <view class="main"> <h-loading :loading="loading"></h-loading> <!-- 可滚动内容区域 --> <scroll-view class="content_scroll" scroll-y="true" :style="{ top: contentTopPosition + 'px' }"> <view class="content"> <view class="map"> <view class="INDU" >道琼斯<view :class="getSignClass(INDU.value)" @click="viewDetail(INDU)">{{ judgeSymbol(INDU.value) }}</view></view > <view class="NDX" >纳斯达克<view :class="getSignClass(NDX.value)" @click="viewDetail(NDX)">{{ judgeSymbol(NDX.value) }}</view></view > <view class="HSI" >恒生指数<view :class="getSignClass(HSI.value)" @click="viewDetail(HSI)">{{ judgeSymbol(HSI.value) }}</view></view > <view class="CN" >上证指数<view :class="getSignClass(CN.value)" @click="viewDetail(CN)">{{ judgeSymbol(CN.value) }}</view></view > <image src="/static/marketSituation-image/map.png" mode="widthFix"></image> </view> <view class="global_index"> <view class="global_index_title"> {{ $t("marketSituation.globalIndex") }} </view> <view class="global_index_more" @click="goToGlobalIndex"> <text>{{ $t("marketSituation.globalIndexMore") }}</text> <image src="/static/marketSituation-image/more.png" mode="aspectFit"></image> </view> </view>
<!-- 卡片网格 --> <view class="cards_grid"> <view v-for="(card, index) in marketSituationStore.cardData" :key="index" class="card_item"> <IndexCard :market="card.market" :stockName="card.stockName" :currentPrice="card.currentPrice" :changeAmount="card.changeAmount" :changePercent="card.changePercent" :isRising="card.isRising" @click="viewIndexDetail(card, index)" /> </view> </view> <view class="warn"> <image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image> <view class="warn_text_container"> <text :class="warnTextClass">{{ $t("marketSituation.warn") }}</text> </view> </view> <!-- 底部安全区域,防止被导航栏遮挡 --> <view class="bottom_safe_area"></view> </view> </scroll-view> </view></template>
<script setup>import { ref, onMounted, onUnmounted, watch, nextTick, computed } from "vue";import { onShow, onHide } from "@dcloudio/uni-app";import util from "../../common/util.js";import IndexCard from "../../components/IndexCard.vue";import hLoading from "@/components/h-loading.vue";import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";const marketSituationStore = useMarketSituationStore();import { getGlobalIndexAPI } from "../../api/marketSituation/marketSituation.js";
const iSMT = ref(0);const searchValue = ref("");const contentHeight = ref(0);const headerHeight = ref(0); // 动态计算的header高度
const isWarnTextOverflow = ref(false); // warn文字是否溢出
const loading = ref(false);
const INDU = ref({ stockName: "道琼斯", stockCode: "INDU", value: "" });const NDX = ref({ stockName: "纳斯达克", stockCode: "513300", value: "" });const HSI = ref({ stockName: "恒生指数", stockCode: "HSI", value: "" });const CN = ref({ stockName: "上证指数", stockCode: "1A0001", value: "" });
const pageIndex = ref(0);const scrollToView = ref("");
const viewDetail = (item) => { uni.navigateTo({ url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}&from=map`, });};
// 计算属性:精准计算content区域的top值
const contentTopPosition = computed(() => { const statusBarHeight = iSMT.value || 0; const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140; return statusBarHeight + currentHeaderHeight;});
// warn文字的class计算属性
const warnTextClass = computed(() => { return isWarnTextOverflow.value ? "warn_text scroll-active" : "warn_text";});
const globalIndexArray = ref([]);
const judgeSymbol = (num) => { return num[0] === "-" ? num : "+" + num;};
function getSignClass(value) { const s = typeof value === "string" ? value : String(value ?? ""); const trimmed = s.trim(); if (trimmed.startsWith("-")) return "index-down"; if (trimmed.startsWith("+")) return "index-up"; const n = parseFloat(trimmed); if (!isNaN(n)) return n >= 0 ? "index-up" : "index-down"; return "";}
// 搜索输入事件
const onSearchInput = (e) => { searchValue.value = e.detail.value;};
// 搜索确认事件
const onSearchConfirm = (e) => { console.log("搜索内容:", e.detail.value); // 这里可以添加搜索逻辑
performSearch(e.detail.value);};
// 搜索图标点击事件
const onSearchClick = () => { if (searchValue.value.trim()) { performSearch(searchValue.value); }};
// 执行搜索
const performSearch = (keyword) => { if (!keyword.trim()) { uni.showToast({ title: "请输入搜索内容", icon: "none", }); return; }
uni.showToast({ title: `搜索: ${keyword}`, icon: "none", }); // 这里添加实际的搜索逻辑
};
// 检测warn文字是否溢出
const checkWarnTextOverflow = () => { nextTick(() => { setTimeout(() => { const query = uni.createSelectorQuery();
// 同时查询容器和文字元素
query.select(".warn_text_container").boundingClientRect(); query.select(".warn_text").boundingClientRect(); query.exec((res) => { const containerRect = res[0]; const textRect = res[1];
if (!containerRect || !textRect) { return; }
// 判断文字是否超出容器(留一些余量)
const isOverflow = textRect.width > containerRect.width - 10;
isWarnTextOverflow.value = isOverflow; }); }, 500); });};
// 方法:查看指数详情
const viewIndexDetail = (item, index) => { console.log("查看指数详情:", item.stockName); // uni.showToast({
// title: `查看 ${item.stockName} 详情`,
// icon: 'none',
// duration: 2000
// })
// 这里可以跳转到具体的指数详情页面
uni.navigateTo({ url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}&index=${index}&from=marketOverview`, });};
// 跳转到全球指数页面
const goToGlobalIndex = () => { uni.navigateTo({ url: "/pages/marketSituation/globalIndex", });};
const getGlobalIndex = async () => { try { loading.value = true; const result = await getGlobalIndexAPI(); globalIndexArray.value = result.data; loading.value = false; } catch (e) { console.log("获取全球指数失败", e); loading.value = false; }};
// TCP相关响应式变量
import tcpConnection from "@/api/tcpConnection.js";const tcpConnected = ref(false);const connectionListener = ref(null);const messageListener = ref(null);// 初始化TCP监听器
const initTcpListeners = () => { // 创建连接状态监听器并保存引用
connectionListener.value = (status, result) => { tcpConnected.value = status === "connected"; console.log("TCP连接状态变化:", status, tcpConnected.value);
// 如果连接,发送获取批量数据
if (status === "connected") { sendTcpMessage("batch_real_time"); } };
// 创建消息监听器并保存引用
messageListener.value = (type, message, parsedArray) => { const messageObj = { type: type, content: message, parsedArray: parsedArray, timestamp: new Date().toLocaleTimeString(), direction: "received", };
// 解析股票数据
parseStockData(message); };
// 注册监听器
tcpConnection.onConnectionChange(connectionListener.value); tcpConnection.onMessage(messageListener.value);};
// 连接TCP服务器
const connectTcp = () => { console.log("开始连接TCP服务器..."); tcpConnection.connect();};
// 断开TCP连接
const disconnectTcp = () => { console.log("断开TCP连接..."); tcpConnection.disconnect(); tcpConnected.value = false;};
// 发送TCP消息
const sendTcpMessage = (command) => { let messageData; let messageDataArray = []; if (command == "batch_real_time") { messageDataArray = globalIndexArray.value.map((item) => item.stockCode); }
switch (command) { // 实时行情推送
case "real_time": messageData = { command: "real_time", stock_code: "SH.000001", }; break; // 初始化获取行情历史数据
case "init_real_time": messageData = { command: "init_real_time", stock_code: "SH.000001", }; break; case "stop_real_time": messageData = { command: "stop_real_time", }; break; // 股票列表
case "stock_list": messageData = { command: "stock_list", }; break; case "batch_real_time": messageData = { command: "batch_real_time", stock_codes: messageDataArray, }; break; case "help": messageData = { command: "help", }; break; } if (!messageData) { return; } else { try { // 发送消息
const success = tcpConnection.send(messageData); if (success) { console.log("home发送TCP消息:", messageData); } } catch (error) { console.error("发送TCP消息时出错:", error); } }};
// 获取TCP连接状态
const getTcpStatus = () => { const status = tcpConnection.getConnectionStatus(); uni.showModal({ title: "TCP连接状态", content: `当前状态: ${status ? "已连接" : "未连接"}`, showCancel: false, });};
let isMorePacket = { init_batch_real_time: false, batch_real_time: false,};let receivedMessage;
// 解析TCP股票数据
const parseStockData = (message) => { try { console.log("进入parseStockData, message类型:", typeof message);
let parsedMessage; // 如果isMorePacket是true,说明正在接受分包数据,无条件接收
// 如果message是字符串且以{开头,说明是JSON字符串,需要解析
// 如果不属于以上两种情况,说明是普通字符串,不预解析
if (message.includes("欢迎连接到股票数据服务器")) { console.log("服务器命令列表,不予处理"); return; } if ((typeof message === "string" && message.includes("batch_data_start")) || isMorePacket.init_batch_real_time) { if (typeof message === "string" && message.includes("batch_data_start")) { console.log("开始接受分包数据"); receivedMessage = ""; } else { console.log("接收分包数据过程中"); } isMorePacket.init_batch_real_time = true; receivedMessage += message; // 如果当前消息包含},说明收到JSON字符串结尾,结束接收,开始解析
if (receivedMessage.includes("batch_data_complete")) { console.log("接受分包数据结束"); isMorePacket.init_batch_real_time = false;
console.log("展示数据", receivedMessage); let startIndex = 0; let startCount = 0; let endIndex = receivedMessage.indexOf("batch_data_complete"); for (let i = 0; i < receivedMessage.length; ++i) { if (receivedMessage[i] == "{") { startCount++; if (startCount == 2) { startIndex = i; break; } } } for (let i = receivedMessage.indexOf("batch_data_complete"); i >= 0; --i) { if (receivedMessage[i] == "}" || startIndex == endIndex) { endIndex = i; break; } } if (startIndex >= endIndex) { throw new Error("JSON字符串格式错误"); } console.log("message", startIndex, endIndex, receivedMessage[endIndex], receivedMessage[startIndex]); parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data; marketSituationStore.cardData = globalIndexArray.value.map((item) => ({ market: item.market, stockCode: item.stockCode, stockName: item.stockName, currentPrice: stockDataArray[item.stockCode][0].current_price.toFixed(2), changeAmount: (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close).toFixed(2), changePercent: ((100 * (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close)) / stockDataArray[item.stockCode][0].pre_close).toFixed(2) + "%", isRising: stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close >= 0, }));
if (stockDataArray[INDU.value.stockCode][0]) { 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) + "%"; } else { console.log("INDU不存在"); } if (stockDataArray[NDX.value.stockCode][0]) { 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) + "%"; } else { console.log("NDX不存在"); } if (stockDataArray[HSI.value.stockCode][0]) { 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) + "%"; } else { console.log("HSI不存在"); } if (stockDataArray[CN.value.stockCode][0]) { 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) + "%"; } else { console.log("CN不存在"); } } } else if ((typeof message === "string" && message.includes('{"count')) || isMorePacket.batch_real_time) { if (typeof message === "string" && message.includes('{"count')) { console.log("开始接受分包数据"); receivedMessage = ""; } else { console.log("接收分包数据过程中"); } isMorePacket.batch_real_time = true; receivedMessage += message; // 如果当前消息包含},说明收到JSON字符串结尾,结束接收,开始解析
if (receivedMessage.includes("batch_realtime_data")) { console.log("接受分包数据结束"); isMorePacket.batch_real_time = false;
console.log("展示数据", receivedMessage); let startIndex = 0; let endIndex = receivedMessage.length - 1; for (let i = 0; i < receivedMessage.length; ++i) { if (receivedMessage[i] == "{") { startIndex = i; break; } } for (let i = receivedMessage.length - 1; i >= 0; --i) { if (receivedMessage[i] == "}" || startIndex == endIndex) { endIndex = i; break; } } if (startIndex >= endIndex) { throw new Error("JSON字符串格式错误"); } parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage); const stockDataArray = parsedMessage.data; marketSituationStore.cardData = globalIndexArray.value.map((item) => ({ market: item.market, stockCode: item.stockCode, stockName: item.stockName, currentPrice: stockDataArray[item.stockCode][0].current_price.toFixed(2), changeAmount: (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close).toFixed(2), changePercent: ((100 * (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close)) / stockDataArray[item.stockCode][0].pre_close).toFixed(2) + "%", isRising: stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close >= 0, }));
if (stockDataArray[INDU.value.stockCode][0]) { 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) + "%"; } else { console.log("INDU不存在"); } if (stockDataArray[NDX.value.stockCode][0]) { 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) + "%"; } else { console.log("NDX不存在"); } if (stockDataArray[HSI.value.stockCode][0]) { 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) + "%"; } else { console.log("HSI不存在"); } if (stockDataArray[CN.value.stockCode][0]) { 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) + "%"; } else { console.log("CN不存在"); } } } else { // 没有通过JSON解析判断,说明不是需要的数据
console.log("不是需要的数据,不做处理"); } } catch (error) { console.error("解析TCP股票数据失败:", error.message); console.error("错误详情:", error); }};
// 移除TCP监听器
const removeTcpListeners = () => { if (connectionListener.value) { tcpConnection.removeConnectionListener(connectionListener.value); connectionListener.value = null; console.log("已移除TCP连接状态监听器"); }
if (messageListener.value) { tcpConnection.removeMessageListener(messageListener.value); messageListener.value = null; console.log("已移除TCP消息监听器"); }};
const startTcp = () => { try { removeTcpListeners(); disconnectTcp(); initTcpListeners(); console.log("初始化完成,,,,,,,,,,,,,,,"); connectTcp(); } catch (error) { console.error("建立连接并设置监听出错:", error); }};
onShow(async () => { console.log("显示页面"); await getGlobalIndex(); initTcpListeners(); await nextTick(); // 开始连接
startTcp();});
onHide(() => { console.log("隐藏页面"); sendTcpMessage("stop_real_time"); removeTcpListeners(); disconnectTcp();});
onUnmounted(() => { console.log("卸载页面"); sendTcpMessage("stop_real_time"); removeTcpListeners(); disconnectTcp();});
onMounted(async () => { console.log("挂载页面"); // 状态栏高度
iSMT.value = uni.getSystemInfoSync().statusBarHeight;
// 确保DOM渲染完成后再查询高度
nextTick(() => { // 动态计算header实际高度
uni .createSelectorQuery() .select(".header_fixed") .boundingClientRect((rect) => { if (rect) { headerHeight.value = rect.height; console.log("Header实际高度:", headerHeight.value, "px"); } }) .exec();
// 检测warn文字是否溢出
checkWarnTextOverflow(); });});
// 监听headerHeight变化,重新计算contentHeight
watch(headerHeight, (newHeight) => { if (newHeight > 0) { const systemInfo = uni.getSystemInfoSync(); const windowHeight = systemInfo.windowHeight; const statusBarHeight = systemInfo.statusBarHeight || 0; const footerHeight = 100;
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight; console.log("重新计算contentHeight:", contentHeight.value); }});</script>
<style scoped>/* 状态栏占位 */.top { position: fixed; top: 0; left: 0; right: 0; z-index: 1001; background-color: #ffffff;}
/* 固定头部样式 */.header_fixed { position: fixed; left: 0; right: 0; z-index: 1000; background-color: #ffffff; padding: 20rpx 0 0 0; box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);}
/* 可滚动内容区域 */.content_scroll { position: fixed; left: 0; right: 0; bottom: 100rpx; /* 底部导航栏高度 */ overflow-y: auto;}
.header_content { display: flex; align-items: center; justify-content: space-between; height: 80rpx; padding: 0 20rpx; margin-bottom: 10rpx;}
.header_input_wrapper { display: flex; align-items: center; width: 100%; margin: 0 20rpx 0 0; height: 70rpx; border-radius: 35rpx; background-color: #ffffff; border: 1rpx solid #e9ecef; padding: 0 80rpx 0 30rpx; font-size: 28rpx; color: #5c5c5c; box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);}
.search_icon { width: 40rpx; height: 40rpx; opacity: 0.6;}
.header_input { margin-left: 10rpx;}
.header_icons { display: flex; align-items: center; gap: 15rpx;}
.header_icon { width: 40rpx; height: 40rpx; display: flex; align-items: center; justify-content: center;}
.header_icon image { width: 40rpx; height: 40rpx;}
/* Tab 栏样式 */.channel_li { display: flex; align-items: center; height: 80rpx; background-color: #ffffff; border-bottom: 1rpx solid #f0f0f0;}
.channel_wrap { width: calc(100% - 60rpx); height: 100%; overflow: hidden; flex-shrink: 0;}
.channel_innerWrap { display: flex; align-items: center; height: 100%; padding: 0 20rpx; white-space: nowrap;}
.channel_item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 60rpx; padding: 0 20rpx; border-radius: 30rpx; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; white-space: nowrap; flex-shrink: 0;}
.channel_item:active { transform: scale(0.98);}
.channel_item.active { color: #333; font-weight: bold;}
.channel_text { font-size: 28rpx; font-weight: 500; color: #666666; transition: color 0.3s ease; white-space: nowrap;}
.channel_item.active .channel_text { color: #333333; font-weight: 400; z-index: 2;}
.active_indicator { position: absolute; left: 50%; top: 60%; transform: translateX(-45%); width: calc(100% - 20rpx); min-width: 40rpx; max-width: 120rpx; height: 8rpx; background-image: url("/static/marketSituation-image/bg.png"); background-size: cover; background-position: center; background-repeat: no-repeat; animation: slideIn 0.1s ease; border-radius: 8rpx; z-index: 1;}
@keyframes slideIn { from { width: 0; opacity: 0; }
to { width: 40rpx; opacity: 1; }}
.scroll_indicator { border-left: 1rpx solid #b6b6b6; display: flex; align-items: center; justify-content: center; width: 60rpx; height: 30rpx; background-color: #ffffff; flex-shrink: 0;}
.scroll_indicator image { width: 20rpx; height: 20rpx; opacity: 0.5;}
.content { margin-top: 20rpx; background-color: white;}
.map { width: calc(100% - 60rpx); margin: 0 30rpx; display: flex; align-items: center; justify-content: center; background-color: #f3f3f3; border-radius: 30rpx; border: 1rpx solid #e0e0e0; padding: 30rpx 20rpx; box-sizing: border-box; /* 设置最小高度保护,但允许内容撑开 */ min-height: 200rpx;}
.NDX { position: absolute; top: 23vh; left: 17vw; transform: translate(-50%, -50%); font-size: 11rpx; color: #000000; padding: 5rpx 10rpx; border-radius: 10rpx; background-color: #ffffff; z-index: 10; display: flex; align-items: center; justify-content: center;}.INDU { position: absolute; top: 15vh; left: 35vw; transform: translate(-50%, -50%); font-size: 11rpx; color: #000000; padding: 5rpx 10rpx; border-radius: 10rpx; background-color: #ffffff; z-index: 10; display: flex; align-items: center; justify-content: center;}.HSI { position: absolute; top: 23vh; right: 4vw; transform: translate(-50%, -50%); font-size: 11rpx; color: #000000; padding: 5rpx 10rpx; border-radius: 10rpx; background-color: #ffffff; z-index: 10; display: flex; align-items: center; justify-content: center;}.CN { position: absolute; top: 16vh; right: 8vw; transform: translate(-50%, -50%); font-size: 11rpx; color: #000000; padding: 5rpx 10rpx; border-radius: 10rpx; background-color: #ffffff; z-index: 10; display: flex; align-items: center; justify-content: center;}
.map image { width: 100%; height: auto; max-width: 100%; display: block; /* widthFix模式下,高度会自动按比例调整 */ /* 设置最大高度避免图片过大 */ max-height: 60vh; /* 添加平滑过渡效果 */ transition: all 0.3s ease; max-height: 60vh;}
/* 响应式优化 */@media screen and (max-width: 750rpx) { .map { margin: 0 20rpx; width: calc(100% - 40rpx); padding: 20rpx 15rpx; }}
@media screen and (max-width: 480rpx) { .map { margin: 0 15rpx; width: calc(100% - 30rpx); padding: 15rpx 10rpx; }}
.static-footer { position: fixed; bottom: 0;}
/* 弹窗样式 */.modal_overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; z-index: 1000;}
.modal_content { width: 100%; background-color: #fff; border-radius: 20rpx 20rpx 0 0; max-height: 80vh; overflow: hidden;}
.modal_header { position: relative; display: flex; justify-content: center; align-items: center; padding: 30rpx 40rpx; border-bottom: 1rpx solid #f0f0f0;}
.modal_title { font-size: 32rpx; font-weight: bold; color: #333333; text-align: center;}
.modal_close { position: absolute; right: 40rpx; top: 50%; transform: translateY(-50%); width: 60rpx; height: 60rpx; display: flex; align-items: center; justify-content: center; font-size: 40rpx; color: #999;}
.modal_body { padding: 40rpx;}
.country_grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20rpx;}
.country_item { padding: 24rpx 30rpx; border-radius: 12rpx; background-color: #f8f8f8; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease;}
.country_item.selected { background-color: #ff4444; color: #fff;}
.country_text { font-size: 28rpx; color: #333;}
.country_item.selected .country_text { color: #fff;}
.global_index { margin: 30rpx 20rpx 0 20rpx; display: flex; justify-content: space-between;}
.global_index_title { margin-left: 20rpx; font-size: 40rpx; font-weight: bold; color: black; align-items: center;}
.global_index_more { display: flex; gap: 10rpx; font-size: 28rpx; color: #333333; align-items: center;}
.global_index_more image { width: 40rpx; height: 40rpx; align-items: center;}
/* 卡片网格样式 */.cards_grid { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; box-sizing: border-box; width: 100%; padding: 30rpx 0;}
.card_item { width: 100%; box-sizing: border-box; min-width: 0; /* 防止内容溢出 */}
/* 响应式布局 - 小屏幕时改为两列 */@media (max-width: 600rpx) { .cards_grid { grid-template-columns: repeat(2, 1fr); padding: 30rpx 0; }}
/* 超小屏幕时改为单列 */@media (max-width: 400rpx) { .cards_grid { grid-template-columns: 1fr; padding: 30rpx 0; }}
.warn { display: flex; align-items: center; justify-content: flex-start; gap: 10rpx; font-size: 28rpx; color: #666666; padding: 20rpx; max-width: 100%; overflow: hidden; position: relative;}
.warn image { width: 40rpx; height: 40rpx; flex-shrink: 0; /* 防止图片被压缩 */ position: relative; z-index: 2; /* 确保图片在最上层 */}
.warn_text_container { flex: 1; overflow: hidden; position: relative; min-width: 0; /* 允许容器收缩 */}
.warn_text { display: block; white-space: nowrap; will-change: transform; /* 优化动画性能 */}
/* 文字滚动动画 */@keyframes scrollText { 0% { transform: translateX(0); }
20% { transform: translateX(0); }
80% { transform: translateX(-85%); }
100% { transform: translateX(-85%); }}
/* 当文字超长时启用滚动动画 */.warn_text.scroll-active { animation: scrollText 12s linear infinite; animation-delay: 2s; /* 延迟2秒开始滚动,让用户先看到开头 */}
/* 底部安全区域 */.bottom_safe_area { height: 40rpx; background-color: transparent;}
/* 主容器样式调整 */.main { position: relative; height: 100vh; overflow: hidden; background-color: white;}
.index-up { color: #2fc25b !important;}
.index-down { color: #f04864 !important;}</style>
|