Browse Source

Merge branch 'hongxilin/feature-20251023103318-行情数据及页面' into milestone-20251031-简版功能开发

zhaowenkang/feature-20251028181547-行情页面
no99 4 weeks ago
parent
commit
b1e5cc586c
  1. 71
      api/tcpConnection.js
  2. 2
      manifest.json
  3. 60
      pages/marketSituation/globalIndex.vue
  4. 538
      pages/marketSituation/marketCondition.vue
  5. 81
      pages/marketSituation/marketDetail.vue
  6. 292
      pages/marketSituation/marketOverview.vue

71
api/tcpConnection.js

@ -1,17 +1,19 @@
/** /**
* TCP连接工具类 * TCP连接工具类
* 用于处理TCP连接发送消息和断开连接 * 用于处理TCP连接发送消息和断开连接
*
* @format
*/ */
// 引用TCP插件 // 引用TCP插件
const TCPSocket = uni.requireNativePlugin('Aimer-TCPPlugin');
const TCPSocket = uni.requireNativePlugin("Aimer-TCPPlugin");
// TCP连接配置 // TCP连接配置
const TCP_CONFIG = { const TCP_CONFIG = {
ip: '192.168.1.9',
port: '8080',
channel: '1', // 可选 1~20
charsetname: 'UTF-8' // 默认UTF-8,可选GBK
ip: "192.168.1.9",
port: "8080",
channel: "1", // 可选 1~20
charsetname: "UTF-8", // 默认UTF-8,可选GBK
}; };
/** /**
@ -32,7 +34,7 @@ class TCPConnection {
connect(config = {}, callback = null) { connect(config = {}, callback = null) {
// 如果已经连接,先断开现有连接 // 如果已经连接,先断开现有连接
if (this.isConnected) { if (this.isConnected) {
console.log('检测到现有TCP连接,先断开...');
console.log("检测到现有TCP连接,先断开...");
this.disconnect(config); this.disconnect(config);
// 等待断开完成后再连接 // 等待断开完成后再连接
setTimeout(() => { setTimeout(() => {
@ -53,7 +55,7 @@ class TCPConnection {
const connectionConfig = { const connectionConfig = {
channel: config.channel || TCP_CONFIG.channel, channel: config.channel || TCP_CONFIG.channel,
ip: config.ip || TCP_CONFIG.ip, ip: config.ip || TCP_CONFIG.ip,
port: config.port || TCP_CONFIG.port
port: config.port || TCP_CONFIG.port,
}; };
// 如果指定了字符集,添加到配置中 // 如果指定了字符集,添加到配置中
@ -61,32 +63,30 @@ class TCPConnection {
connectionConfig.charsetname = config.charsetname || TCP_CONFIG.charsetname; connectionConfig.charsetname = config.charsetname || TCP_CONFIG.charsetname;
} }
console.log('开始建立TCP连接:', connectionConfig);
TCPSocket.connect(
connectionConfig,
result => {
console.log("开始建立TCP连接:", connectionConfig);
TCPSocket.connect(connectionConfig, (result) => {
/** /**
* status : 0 连接成功 * status : 0 连接成功
* status : 1 断开连接 * status : 1 断开连接
* receivedMsg : 服务器返回字符串(普通的字符串交互) * receivedMsg : 服务器返回字符串(普通的字符串交互)
* receivedHexMsg : 服务器返回字节数组(单片机智能家居等硬件数据交互) * receivedHexMsg : 服务器返回字节数组(单片机智能家居等硬件数据交互)
*/ */
if (result.status == '0') {
if (result.status == "0") {
// TCP连接成功 // TCP连接成功
this.isConnected = true; this.isConnected = true;
console.log('TCP连接成功');
this._notifyConnectionCallbacks('connected', result);
} else if (result.status == '1') {
console.log("TCP连接成功");
this._notifyConnectionCallbacks("connected", result);
} else if (result.status == "1") {
// TCP断开连接 // TCP断开连接
this.isConnected = false; this.isConnected = false;
console.log('TCP断开连接');
this._notifyConnectionCallbacks('disconnected', result);
console.log("TCP断开连接");
this._notifyConnectionCallbacks("disconnected", result);
} }
if (result.receivedMsg) { if (result.receivedMsg) {
// 服务器返回字符串 // 服务器返回字符串
console.log('收到字符串消息:', result.receivedMsg);
this._notifyMessageCallbacks('string', result.receivedMsg);
console.log("收到字符串消息:", result.receivedMsg);
this._notifyMessageCallbacks("string", result.receivedMsg);
} }
// if (result.receivedHexMsg) { // if (result.receivedHexMsg) {
@ -104,11 +104,10 @@ class TCPConnection {
// } // }
// 执行回调函数 // 执行回调函数
if (callback && typeof callback === 'function') {
if (callback && typeof callback === "function") {
callback(result); callback(result);
} }
}
);
});
} }
/** /**
@ -118,19 +117,19 @@ class TCPConnection {
*/ */
send(message, config = {}) { send(message, config = {}) {
if (!this.isConnected) { if (!this.isConnected) {
console.warn('TCP未连接,无法发送消息');
console.warn("TCP未连接,无法发送消息");
return false; return false;
} }
// 如果message是对象,转换为JSON字符串 // 如果message是对象,转换为JSON字符串
let messageStr = message; let messageStr = message;
if (typeof message === 'object') {
messageStr = JSON.stringify(message) + '\n';
if (typeof message === "object") {
messageStr = JSON.stringify(message) + "\n";
} }
const sendConfig = { const sendConfig = {
channel: config.channel || '1', // 注意:channel应该是字符串
message: messageStr
channel: config.channel || "1", // 注意:channel应该是字符串
message: messageStr,
}; };
// 如果指定了字符编码,添加到配置中 // 如果指定了字符编码,添加到配置中
@ -139,7 +138,7 @@ class TCPConnection {
} }
TCPSocket.send(sendConfig); TCPSocket.send(sendConfig);
console.log('js成功发送TCP消息:', messageStr);
console.log("js成功发送TCP消息:", messageStr);
return true; return true;
} }
@ -149,12 +148,12 @@ class TCPConnection {
*/ */
disconnect(config = {}) { disconnect(config = {}) {
const disconnectConfig = { const disconnectConfig = {
channel: config.channel || TCP_CONFIG.channel
channel: config.channel || TCP_CONFIG.channel,
}; };
TCPSocket.disconnect(disconnectConfig); TCPSocket.disconnect(disconnectConfig);
this.isConnected = false; this.isConnected = false;
console.log('TCP连接已断开', disconnectConfig);
console.log("TCP连接已断开", disconnectConfig);
} }
/** /**
@ -162,7 +161,7 @@ class TCPConnection {
* @param {Function} callback - 回调函数 (status, result) => {} * @param {Function} callback - 回调函数 (status, result) => {}
*/ */
onConnectionChange(callback) { onConnectionChange(callback) {
if (typeof callback === 'function') {
if (typeof callback === "function") {
this.connectionCallbacks.push(callback); this.connectionCallbacks.push(callback);
} }
} }
@ -172,7 +171,7 @@ class TCPConnection {
* @param {Function} callback - 回调函数 (type, message, parsedArray) => {} * @param {Function} callback - 回调函数 (type, message, parsedArray) => {}
*/ */
onMessage(callback) { onMessage(callback) {
if (typeof callback === 'function') {
if (typeof callback === "function") {
this.messageCallbacks.push(callback); this.messageCallbacks.push(callback);
} }
} }
@ -212,11 +211,11 @@ class TCPConnection {
* @private * @private
*/ */
_notifyConnectionCallbacks(status, result) { _notifyConnectionCallbacks(status, result) {
this.connectionCallbacks.forEach(callback => {
this.connectionCallbacks.forEach((callback) => {
try { try {
callback(status, result); callback(status, result);
} catch (error) { } catch (error) {
console.error('连接状态回调执行错误:', error);
console.error("连接状态回调执行错误:", error);
} }
}); });
} }
@ -226,11 +225,11 @@ class TCPConnection {
* @private * @private
*/ */
_notifyMessageCallbacks(type, message, parsedArray = null) { _notifyMessageCallbacks(type, message, parsedArray = null) {
this.messageCallbacks.forEach(callback => {
this.messageCallbacks.forEach((callback) => {
try { try {
callback(type, message, parsedArray); callback(type, message, parsedArray);
} catch (error) { } catch (error) {
console.error('消息回调执行错误:', error);
console.error("消息回调执行错误:", error);
} }
}); });
} }

2
manifest.json

@ -1,6 +1,6 @@
{ {
"name" : "DeepChartApp", "name" : "DeepChartApp",
"appid" : "__UNI__2646D0B",
"appid" : "__UNI__9C9AB28",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",

60
pages/marketSituation/globalIndex.vue

@ -43,7 +43,7 @@
</view> </view>
<view class="cards-grid-three"> <view class="cards-grid-three">
<view v-for="(item, index) in asiachinaIndexes" :key="index" class="card-item"> <view v-for="(item, index) in asiachinaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount" :currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising" :changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" /> @click="viewIndexDetail(item)" />
@ -62,7 +62,7 @@
</view> </view>
<view class="cards-grid-three"> <view class="cards-grid-three">
<view v-for="(item, index) in asiaIndexes" :key="index" class="card-item"> <view v-for="(item, index) in asiaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount" :currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising" :changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" /> @click="viewIndexDetail(item)" />
@ -81,7 +81,7 @@
</view> </view>
<view class="cards-grid-three"> <view class="cards-grid-three">
<view v-for="(item, index) in americaIndexes" :key="index" class="card-item"> <view v-for="(item, index) in americaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount" :currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising" :changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" /> @click="viewIndexDetail(item)" />
@ -145,7 +145,8 @@ const checkWarnTextOverflow = () => {
const asiachinaIndexes = ref([ const asiachinaIndexes = ref([
{ {
flagIcon: '/static/c1.png', flagIcon: '/static/c1.png',
indexName: '上证指数',
stockName: '上证指数',
stockCode:'noCode',
currentPrice: '3933.96', currentPrice: '3933.96',
changeAmount: '+24.32', changeAmount: '+24.32',
changePercent: '+0.62%', changePercent: '+0.62%',
@ -153,7 +154,8 @@ const asiachinaIndexes = ref([
}, },
{ {
flagIcon: '/static/c2.png', flagIcon: '/static/c2.png',
indexName: '深证成指',
stockName: '深证成指',
stockCode:'noCode',
currentPrice: '45757.90', currentPrice: '45757.90',
changeAmount: '-123.45', changeAmount: '-123.45',
changePercent: '-0.27%', changePercent: '-0.27%',
@ -161,7 +163,8 @@ const asiachinaIndexes = ref([
}, },
{ {
flagIcon: '/static/c3.png', flagIcon: '/static/c3.png',
indexName: '创业板指',
stockName: '创业板指',
stockCode:'noCode',
currentPrice: '6606.08', currentPrice: '6606.08',
changeAmount: '+89.76', changeAmount: '+89.76',
changePercent: '+1.38%', changePercent: '+1.38%',
@ -169,7 +172,8 @@ const asiachinaIndexes = ref([
}, },
{ {
flagIcon: '/static/c4.png', flagIcon: '/static/c4.png',
indexName: 'HSI50',
stockName: 'HSI50',
stockCode:'noCode',
currentPrice: '22333.96', currentPrice: '22333.96',
changeAmount: '+156.78', changeAmount: '+156.78',
changePercent: '+0.71%', changePercent: '+0.71%',
@ -177,7 +181,8 @@ const asiachinaIndexes = ref([
}, },
{ {
flagIcon: '/static/c5.png', flagIcon: '/static/c5.png',
indexName: '沪深300',
stockName: '沪深300',
stockCode:'noCode',
currentPrice: '45757.90', currentPrice: '45757.90',
changeAmount: '-89.12', changeAmount: '-89.12',
changePercent: '-0.19%', changePercent: '-0.19%',
@ -185,7 +190,8 @@ const asiachinaIndexes = ref([
}, },
{ {
flagIcon: '/static/c6.png', flagIcon: '/static/c6.png',
indexName: '上证50',
stockName: '上证50',
stockCode:'noCode',
currentPrice: '45757.90', currentPrice: '45757.90',
changeAmount: '+234.56', changeAmount: '+234.56',
changePercent: '+0.52%', changePercent: '+0.52%',
@ -197,7 +203,8 @@ const asiachinaIndexes = ref([
const asiaIndexes = ref([ const asiaIndexes = ref([
{ {
flagIcon: '/static/c7.png', flagIcon: '/static/c7.png',
indexName: '日经225',
stockName: '日经225',
stockCode:'noCode',
currentPrice: '28456.78', currentPrice: '28456.78',
changeAmount: '+234.56', changeAmount: '+234.56',
changePercent: '+0.83%', changePercent: '+0.83%',
@ -205,7 +212,8 @@ const asiaIndexes = ref([
}, },
{ {
flagIcon: '/static/c8.png', flagIcon: '/static/c8.png',
indexName: '韩国KOSPI',
stockName: '韩国KOSPI',
stockCode:'noCode',
currentPrice: '2567.89', currentPrice: '2567.89',
changeAmount: '-12.34', changeAmount: '-12.34',
changePercent: '-0.48%', changePercent: '-0.48%',
@ -213,7 +221,8 @@ const asiaIndexes = ref([
}, },
{ {
flagIcon: '/static/c9.png', flagIcon: '/static/c9.png',
indexName: '印度孟买',
stockName: '印度孟买',
stockCode:'noCode',
currentPrice: '65432.10', currentPrice: '65432.10',
changeAmount: '+456.78', changeAmount: '+456.78',
changePercent: '+0.70%', changePercent: '+0.70%',
@ -225,7 +234,8 @@ const asiaIndexes = ref([
const americaIndexes = ref([ const americaIndexes = ref([
{ {
flagIcon: '/static/c7.png', flagIcon: '/static/c7.png',
indexName: '道琼斯指数',
stockName: '道琼斯指数',
stockCode:'noCode',
currentPrice: '34567.89', currentPrice: '34567.89',
changeAmount: '+123.45', changeAmount: '+123.45',
changePercent: '+0.36%', changePercent: '+0.36%',
@ -233,7 +243,8 @@ const americaIndexes = ref([
}, },
{ {
flagIcon: '/static/c8.png', flagIcon: '/static/c8.png',
indexName: '纳斯达克',
stockName: '纳斯达克',
stockCode:'noCode',
currentPrice: '13456.78', currentPrice: '13456.78',
changeAmount: '-67.89', changeAmount: '-67.89',
changePercent: '-0.50%', changePercent: '-0.50%',
@ -241,7 +252,8 @@ const americaIndexes = ref([
}, },
{ {
flagIcon: '/static/c9.png', flagIcon: '/static/c9.png',
indexName: '标普500',
stockName: '标普500',
stockCode:'noCode',
currentPrice: '4234.56', currentPrice: '4234.56',
changeAmount: '+23.45', changeAmount: '+23.45',
changePercent: '+0.56%', changePercent: '+0.56%',
@ -281,16 +293,16 @@ const viewMore = (market) => {
// //
const viewIndexDetail = (item) => { const viewIndexDetail = (item) => {
console.log('查看指数详情:', item.indexName)
uni.showToast({
title: `查看 ${item.indexName} 详情`,
icon: 'none',
duration: 2000
})
//
// uni.navigateTo({
// url: `/pages/detail/indexDetail?id=${item.id}`
console.log('查看指数详情:', item.stockName)
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
// duration: 2000
// }) // })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`
})
} }
// //

538
pages/marketSituation/marketCondition.vue

@ -15,8 +15,8 @@
</view> </view>
<view class="arrow-right"> </view> <view class="arrow-right"> </view>
</view> </view>
<image class="search" src="/static/marketSituation-image/search.png" mode="搜索" @click="startTcp()"> </image>
<view class="more" @click="disconnect()">···</view>
<image class="search" src="/static/marketSituation-image/search.png" mode="搜索" @click="search()"> </image>
<view class="more" @click="getMore()">···</view>
</view> </view>
</view> </view>
@ -196,8 +196,14 @@
</view> </view>
<!-- K线图区域 --> <!-- K线图区域 -->
<view class="test" v-else-if="klineTab === 3"> <view class="test" v-else-if="klineTab === 3">
<button @click="sendGetTimeData()">接收消息</button>
<button @click="startTcp()">接收消息</button>
<button @click="sendStopTimeData()">停止消息</button> <button @click="sendStopTimeData()">停止消息</button>
<button @click="sendTcpMessage('real_time')">实时行情推送</button>
<button @click="sendTcpMessage('init_real_time')">初始化获取行情历史数据</button>
<button @click="sendTcpMessage('stop_real_time')">停止实时推送</button>
<view class="tcpMsg" v-for="item in tcpMessages" :key="item">
{{ item }}
</view>
</view> </view>
<view v-else class="kline-chart-container"> <view v-else class="kline-chart-container">
<text>K线图开发中...</text> <text>K线图开发中...</text>
@ -230,15 +236,27 @@ const instance = getCurrentInstance();
import { prevClosePrice, timeData as testTimeData, klineData as testKlineData } from "@/common/stockTimeInformation.js"; import { prevClosePrice, timeData as testTimeData, klineData as testKlineData } from "@/common/stockTimeInformation.js";
import { throttle } from "@/common/util.js"; import { throttle } from "@/common/util.js";
import { HCharts } from "@/common/canvasMethod.js"; import { HCharts } from "@/common/canvasMethod.js";
// const TCPSocket = uni.requireNativePlugin("Aimer-TCPPlugin");
const tcpObject = {
ip: "192.168.1.9",
port: 8080,
reconnectInterval: 3000,
isConnected: false,
};
const TIME_OUT = 1000 * 5;
const resultR = ref([]);
import tcpConnection, { TCPConnection, TCP_CONFIG } from "@/api/tcpConnection.js";
// TCP
const tcpConnected = ref(false);
const tcpMessages = ref([]);
const tcpStockData = ref({
count: 0,
data: {},
stock_count: 0,
timestamp: "",
type: "",
});
const currentStockInfo = ref({
stock_name: "未知股票",
current_price: "0.00",
change: "0.00%",
change_value: 0,
change_percent: 0,
});
const connectionListener = ref(null);
const messageListener = ref(null);
// //
const stockInformation = ref({ const stockInformation = ref({
@ -401,29 +419,26 @@ const moreTabsData = ref([
// K线Tab // K线Tab
// 1: 2:K 3:K 4:K // 1: 2:K 3:K 4:K
const klineTab = ref(2);
const sendGetTimeData = () => {
console.log("执行发送消息的方法");
const klineTab = ref(1);
const startTcp = () => {
try { try {
TCPSocket.send({
channel: "1",
message: '{"command": "real_time", "stock_code": "SH.000001"}',
removeTcpListeners();
disconnectTcp();
initTcpListeners();
connectTcp();
} catch (error) {
console.error("建立连接并设置监听:", error);
uni.showToast({
title: "建立连接并设置监听",
icon: "none",
duration: 1500,
}); });
} catch (e) {
console.log("error", e);
} }
}; };
const sendStopTimeData = () => { const sendStopTimeData = () => {
try {
TCPSocket.send({
channel: "1",
message: '{"command": "stop_real_time"}',
});
} catch (e) {
console.log("error", e);
}
disconnectTcp();
removeTcpListeners();
}; };
// //
@ -450,9 +465,11 @@ const confirmStockColor = (price, lastDayStockClosePrice) => {
// K线 // K线
const selectKlineTab = (tabId) => { const selectKlineTab = (tabId) => {
klineTab.value = tabId; klineTab.value = tabId;
if (tabId === 1) {
stockInformation.value.lastDayStockClosePrice = prevClosePrice;
if (klineTab.value == 1) {
sendTcpMessage("init_real_time");
} }
initCanvas(); initCanvas();
// startAddDataTimer(); // startAddDataTimer();
}; };
@ -929,6 +946,7 @@ const drawChart = () => {
// //
if (klineTab.value == 1) { if (klineTab.value == 1) {
console.log("stockInfomaton.lastDayStockClosePrice", stockInformation.value.lastDayStockClosePrice);
// //
const label = [ const label = [
{ {
@ -1364,151 +1382,341 @@ watch(klineTab, () => {
console.log("标签页变化"); console.log("标签页变化");
drawChart(); drawChart();
}); });
/*
const connectTcp = (ip, port) => {
console.log(`🚀 正在连接TCP服务器 ${ip}:${port}...`);
TCPSocket.connect(
{
channel: "1",
ip: ip,
port: port,
},
(result) => {
console.log(result);
if (result.status == 0) {
tcpObject.isConnected = true;
console.log("tcp连接成功");
} else if (result.status == 1) {
tcpObject.isConnected = false;
console.log("tcp断开连接");
}
if (result.receivedMsg) {
console.log("收到服务器发送的数据", result.receivedMsg);
if (result.receivedMsg.length == 0 || result.receivedMsg.includes("欢迎")) {
resultR.value = [];
} else {
const msgPacket = JSON.parse(result.receivedMsg);
resultR.value.push(msgPacket);
//
if (msgPacket.stock_code) {
stockInformation.value.stockCode = msgPacket.stock_code;
// TCP
const initTcpListeners = () => {
//
connectionListener.value = (status, result) => {
tcpConnected.value = status === "connected";
console.log("TCP连接状态变化:", status, tcpConnected.value);
//
uni.showToast({
title: status === "connected" ? "TCP连接成功" : "TCP连接断开",
icon: status === "connected" ? "success" : "none",
duration: 2000,
});
if (status === "connected") {
if (klineTab.value == 1) {
sendTcpMessage("init_real_time");
} }
//
if (msgPacket.stock_name) {
stockInformation.value.stockName = msgPacket.stock_name;
} }
//
if (msgPacket.pre_close) {
stockInformation.value.lastDayStockClosePrice = msgPacket.pre_close;
};
//
messageListener.value = (type, message, parsedArray) => {
const messageObj = {
type: type,
content: message,
parsedArray: parsedArray,
timestamp: new Date().toLocaleTimeString(),
direction: "received",
};
console.log("0000");
tcpMessages.value.push(messageObj);
// console.log('TCP:', messageObj)
console.log("home开始调用parseStockData", messageObj);
//
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;
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 "daily_data":
messageData = {
command: "daily_data",
stock_code: "GBPAUD.FXCM",
start_date: "20251001",
end_date: "20251023",
};
break;
case "weekly_data":
messageData = {
command: "weekly_data",
stock_code: "000001.SZ",
start_date: "20251001",
end_date: "20251023",
};
break;
case "daily_one_minutes_data":
messageData = {
command: "daily_one_minutes_data",
stock_code: "000001.SZ",
};
break;
case "daily_five_minutes_data":
messageData = {
command: "daily_five_minutes_data",
stock_code: "000001.SZ",
};
break;
case "daily_fifteen_minutes_data":
messageData = {
command: "daily_fifteen_minutes_data",
stock_code: "000001.SZ",
};
break;
case "daily_thirty_minutes_data":
messageData = {
command: "daily_thirty_minutes_data",
stock_code: "000001.SZ",
};
break;
case "daily_sixty_minutes_data":
messageData = {
command: "daily_sixty_minutes_data",
stock_code: "000001.SZ",
};
break;
case "batch_real_time":
messageData = {
command: "batch_real_time",
stock_codes: ["SH.000001", "SH.000002", "SH.000003", "SH.000004", "SH.000005"],
};
break;
case "help":
messageData = {
command: "help",
};
break;
} }
//
if (msgPacket.current_price) {
stockInformation.value.currentPrice = msgPacket.current_price;
if (!messageData) {
uni.showToast({
title: "命令不存在",
icon: "none",
duration: 1500,
});
return;
} else {
try {
//
const success = tcpConnection.send(messageData);
if (success) {
console.log("home发送TCP消息:", messageData);
uni.showToast({
title: "消息发送成功",
icon: "success",
duration: 1500,
});
}
} catch (error) {
console.error("发送TCP消息时出错:", error);
uni.showToast({
title: "消息发送失败",
icon: "none",
duration: 1500,
});
} }
//
if (msgPacket.current_price && msgPacket.pre_close) {
stockInformation.value.currentValue = msgPacket.current_price - msgPacket.pre_close;
stockInformation.value.currentRatio = ((msgPacket.current_price - msgPacket.pre_close) / msgPacket.pre_close) * 100;
} }
};
//
const clearTcpMessages = () => {
tcpMessages.value = [];
uni.showToast({
title: "消息记录已清空",
icon: "success",
duration: 1500,
});
};
// TCP
const getTcpStatus = () => {
const status = tcpConnection.getConnectionStatus();
uni.showModal({
title: "TCP连接状态",
content: `当前状态: ${status ? "已连接" : "未连接"}\n消息数量: ${tcpMessages.value.length}`,
showCancel: false,
});
};
//
if (msgPacket.high_price) {
stockInformation.value.highPrice = msgPacket.high_price;
let isMorePacket = false;
let receivedMessage;
// TCP
const parseStockData = (message) => {
try {
console.log("进入parseStockData, message类型:", typeof message);
let parsedMessage;
// isMorePackettrue
// message{JSON
//
if (message.includes("欢迎连接到股票数据服务器")) {
console.log("服务器命令列表,不予处理");
return;
}
if ((typeof message === "string" && message.includes("init_real_data_start")) || isMorePacket) {
if (typeof message === "string" && message.includes("init_real_data_start")) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("init_real_data_complete")) {
console.log("接受分包数据结束");
isMorePacket = false;
console.log("展示数据", receivedMessage);
// JSON
let jsonStartIndex = 0;
let jsonEndIndex = receivedMessage.indexOf("init_real_data_complete");
let jsonStartCount = 0;
let jsonEndCount = 0;
for (let i = 0; i < receivedMessage.length - 1; ++i) {
if (receivedMessage[i] == "{") {
jsonStartCount++;
if (jsonStartCount == 2) {
jsonStartIndex = i;
break;
} }
//
if (msgPacket.close_price) {
stockInformation.value.lowPrice = msgPacket.close_price;
} }
//
if (msgPacket.open_price) {
stockInformation.value.openPrice = msgPacket.open_price;
} }
//
if (msgPacket.low_price) {
stockInformation.value.lowPrice = msgPacket.low_price;
for (let i = receivedMessage.indexOf("init_real_data_complete"); i >= 0; --i) {
if (receivedMessage[i] == "}" || i == jsonStartIndex) {
jsonEndCount++;
if (jsonEndCount == 1) {
jsonEndIndex = i;
break;
} }
//
if (msgPacket.current_price) {
stockInformation.value.closePrice = msgPacket.current_price;
} }
//
if (msgPacket.volume) {
stockInformation.value.volume = msgPacket.volume;
} }
//
if (msgPacket.volume_ratio) {
stockInformation.value.volumeRatio = msgPacket.volume_ratio;
// JSON
if (jsonStartIndex >= jsonEndIndex) {
throw new Error("JSON字符串格式错误");
} }
//
if (msgPacket.amount) {
stockInformation.value.amount = msgPacket.amount;
console.log("检测到JSON字符串,开始解析");
parsedMessage = JSON.parse(receivedMessage.substring(jsonStartIndex, jsonEndIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
if (parsedMessage.type === "daily_data") {
timeData.value = parsedMessage.data;
stockInformation.value.lastDayStockClosePrice = parsedMessage.pre_close;
console.log("lastDayStockClosePrice", stockInformation.value.lastDayStockClosePrice);
drawChart();
} }
//
if (msgPacket.market_earn) {
stockInformation.value.marketEarn = msgPacket.market_earn;
} }
//
if (msgPacket.turnover_ratio) {
stockInformation.value.turnoverRatio = msgPacket.turnover_ratio;
// JSON
console.log("开始处理解析后的数据");
// batch_data_chunkbatch_realtime_data
if ((parsedMessage.type === "batch_data_chunk" || parsedMessage.type === "batch_realtime_data") && parsedMessage.data) {
console.log("开始更新TCP股票数据存储");
// TCP
tcpStockData.value = {
count: parsedMessage.count || 0,
data: parsedMessage.data || {},
stock_count: parsedMessage.stock_count || 0,
timestamp: parsedMessage.timestamp || "",
type: parsedMessage.type || "",
};
//
const stockCodes = Object.keys(parsedMessage.data);
if (stockCodes.length > 0) {
const firstStockCode = stockCodes[0];
//
if (parsedMessage.data[firstStockCode] && Array.isArray(parsedMessage.data[firstStockCode]) && parsedMessage.data[firstStockCode].length > 0) {
const stockData = parsedMessage.data[firstStockCode][0]; //
if (stockData && stockData.current_price !== undefined && stockData.pre_close !== undefined) {
//
const changeValue = stockData.current_price - stockData.pre_close;
const changePercent = ((changeValue / stockData.pre_close) * 100).toFixed(2);
const changeSign = changeValue >= 0 ? "+" : "";
//
currentStockInfo.value = {
stock_name: stockData.stock_name || "未知股票",
current_price: stockData.current_price ? stockData.current_price.toFixed(2) : "0.00",
change: `${changeSign}${changePercent}%`,
change_value: changeValue,
change_percent: parseFloat(changePercent),
};
console.log("股票数据更新成功:", currentStockInfo.value);
} }
//
if (msgPacket.total_market_value) {
stockInformation.value.marketValue = msgPacket.total_market_value;
} }
} }
} else {
console.log("不是batch_data_chunk或batch_realtime_data类型的消息,跳过处理");
} }
// if (result.receivedHexMsg) {
// //16
// console.log("📥 16:", result.receivedHexMsg);
// let msg = result.receivedHexMsg;
// let sum = msg.length / 2;
// let arr = [];
// for (let k = 0; k < sum; k++) {
// let i = msg.substring(k * 2, k * 2 + 2);
// arr.push(i);
// }
// console.log("16:", arr);
// if (tcpObject.responseCallback) {
// tcpObject.responseCallback({
// data: arr,
// });
// }
// }
//
setTimeout(() => {
if (!tcpObject.isConnected) {
throw new Error("连接超时");
return;
} else {
// JSON
console.log("不是需要的数据,不做处理");
} }
}, TIME_OUT);
} catch (error) {
console.error("解析TCP股票数据失败:", error.message);
console.error("错误详情:", error);
} }
);
}; };
//
const disconnect = () => {
try {
TCPSocket.disconnect({
channel: "1",
});
tcpObject.isConnected = false;
console.log("✅ 连接已关闭");
} catch (e) {
console.log("⚠️ 断开连接时发生错误:", e.message);
// TCP
const removeTcpListeners = () => {
if (connectionListener.value) {
tcpConnection.removeConnectionListener(connectionListener.value);
connectionListener.value = null;
console.log("已移除TCP连接状态监听器");
} }
};
const startTcp = async () => {
console.log("🚀 TCP客户端启动");
console.log(`目标服务器: ${tcpObject.ip}:${tcpObject.port}`);
try {
//
await connectTcp(tcpObject.ip, tcpObject.port);
} catch (e) {
console.log("error", e);
if (messageListener.value) {
tcpConnection.removeMessageListener(messageListener.value);
messageListener.value = null;
console.log("已移除TCP消息监听器");
} }
}; };
*/
// //
let timer = null; let timer = null;
let index = 0; let index = 0;
@ -1562,7 +1770,7 @@ onLoad((options) => {
if (stockData) { if (stockData) {
stockInformation.value = { stockInformation.value = {
...stockInformation.value, ...stockInformation.value,
...stockData
...stockData,
}; };
} }
} catch (error) { } catch (error) {
@ -1589,7 +1797,8 @@ onUnmounted(() => {
}); });
onMounted(async () => { onMounted(async () => {
//
try {
console.log("步骤1: 初始化系统信息");
const systemInfo = uni.getSystemInfoSync(); const systemInfo = uni.getSystemInfoSync();
pixelRatio.value = systemInfo.pixelRatio; pixelRatio.value = systemInfo.pixelRatio;
// CanvaspixelRatio // CanvaspixelRatio
@ -1599,14 +1808,13 @@ onMounted(async () => {
const calculatedHeight = systemInfo.windowHeight - offsetHeight; const calculatedHeight = systemInfo.windowHeight - offsetHeight;
canvasWidth.value = systemInfo.windowWidth; canvasWidth.value = systemInfo.windowWidth;
canvasHeight.value = Math.max(calculatedHeight, canvasHeight.value); canvasHeight.value = Math.max(calculatedHeight, canvasHeight.value);
// startTcp();
// timeData.value = testTimeData;
timeData.value = testTimeData.slice(0, 100);
klineData.value = testKlineData;
// klineData.value = testKlineData.slice(-touchState.baseVisibleCount);
//
let prevClosePrice = timeData.value[timeData.value.length - 2].price || stockInformation.value.closePrice;
stockInformation.value.lastDayStockClosePrice = prevClosePrice;
initTcpListeners();
await nextTick();
//
startTcp();
if (timeData.value && timeData.value.length > 0) {
// //
stockInformation.value.currentPrice = timeData.value[timeData.value.length - 1].price; stockInformation.value.currentPrice = timeData.value[timeData.value.length - 1].price;
// //
@ -1617,11 +1825,15 @@ onMounted(async () => {
stockInformation.value.volume = timeData.value[timeData.value.length - 1].volume; stockInformation.value.volume = timeData.value[timeData.value.length - 1].volume;
text[0][1].value = utils.formatPrice(stockInformation.value.currentPrice); text[0][1].value = utils.formatPrice(stockInformation.value.currentPrice);
text[1][0].value = utils.formatStockNumber(stockInformation.value.volume); text[1][0].value = utils.formatStockNumber(stockInformation.value.volume);
} else {
console.warn("没有时间数据,跳过股票信息计算");
}
await nextTick(); await nextTick();
setTimeout(() => {
initCanvas(); initCanvas();
}, 200);
console.log("所有初始化步骤完成");
} catch (error) {
console.error("初始化过程中出现错误:", error);
}
}); });
</script> </script>

81
pages/marketSituation/marketDetail.vue

@ -37,10 +37,10 @@
<!-- 股票列表 --> <!-- 股票列表 -->
<view class="stock-list"> <view class="stock-list">
<view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index" <view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index"
@click="viewStockDetail(stock)">
@click="viewIndexDetail(stock)">
<view class="stock-cell name-column"> <view class="stock-cell name-column">
<view class="stock-name">{{ stock.name }}</view>
<view class="stock-code">{{ stock.code }}</view>
<view class="stock-name">{{ stock.stockName }}</view>
<view class="stock-code">{{ stock.stockCode }}</view>
</view> </view>
<view class="stock-cell price-column"> <view class="stock-cell price-column">
<text class="stock-price" <text class="stock-price"
@ -83,99 +83,99 @@ const sortOrder = ref('desc') // 排序顺序:'asc' 或 'desc'
// //
const stockList = ref([ const stockList = ref([
{ {
name: 'Telecommunication',
code: '888607',
stockName: 'Telecommunication',
stockCode: '888607',
price: 1349.47, price: 1349.47,
change: '+7.67%', change: '+7.67%',
isRising: true isRising: true
}, },
{ {
name: 'Other',
code: '888607',
stockName: 'Other',
stockCode: '888607',
price: 1349.47, price: 1349.47,
change: '+6.67%', change: '+6.67%',
isRising: true isRising: true
}, },
{ {
name: 'Consumer Discretio...',
code: '888610',
stockName: 'Consumer Discretio...',
stockCode: '888610',
price: 1349.47, price: 1349.47,
change: '+5.67%', change: '+5.67%',
isRising: true isRising: true
}, },
{ {
name: 'Telecommunication',
code: '888607',
stockName: 'Telecommunication',
stockCode: '888607',
price: 1349.47, price: 1349.47,
change: '+4.67%', change: '+4.67%',
isRising: true isRising: true
}, },
{ {
name: 'Other',
code: '888611',
stockName: 'Other',
stockCode: '888611',
price: 1359.47, price: 1359.47,
change: '+3.67%', change: '+3.67%',
isRising: true isRising: true
}, },
{ {
name: 'Consumer Discretio...',
code: '888610',
stockName: 'Consumer Discretio...',
stockCode: '888610',
price: 1349.47, price: 1349.47,
change: '+2.67%', change: '+2.67%',
isRising: true isRising: true
}, },
{ {
name: 'Telecommunication',
code: '888607',
stockName: 'Telecommunication',
stockCode: '888607',
price: 1349.47, price: 1349.47,
change: '+1.67%', change: '+1.67%',
isRising: true isRising: true
}, },
{ {
name: 'Other',
code: '888611',
stockName: 'Other',
stockCode: '888611',
price: 1009.98, price: 1009.98,
change: '-1.67%', change: '-1.67%',
isRising: false isRising: false
}, },
{ {
name: 'Consumer Discretio...',
code: '888610',
stockName: 'Consumer Discretio...',
stockCode: '888610',
price: 1009.98, price: 1009.98,
change: '-0.67%', change: '-0.67%',
isRising: false isRising: false
}, },
{ {
name: 'Telecommunication',
code: '888607',
stockName: 'Telecommunication',
stockCode: '888607',
price: 1009.98, price: 1009.98,
change: '-0.67%', change: '-0.67%',
isRising: false isRising: false
}, },
{ {
name: 'Other',
code: '888611',
stockName: 'Other',
stockCode: '888611',
price: 1009.98, price: 1009.98,
change: '-1.67%', change: '-1.67%',
isRising: false isRising: false
}, },
{ {
name: 'Consumer Discretio...',
code: '888610',
stockName: 'Consumer Discretio...',
stockCode: '888610',
price: 1009.98, price: 1009.98,
change: '-4.67%', change: '-4.67%',
isRising: false isRising: false
}, },
{ {
name: 'Consumer Discretio...',
code: '888610',
stockName: 'Consumer Discretio...',
stockCode: '888610',
price: 1009.98, price: 1009.98,
change: '-3.67%', change: '-3.67%',
isRising: false isRising: false
}, },
{ {
name: 'Consumer Discretio...',
code: '888610',
stockName: 'Consumer Discretio...',
stockCode: '888610',
price: 1009.98, price: 1009.98,
change: '-3.67%', change: '-3.67%',
isRising: false isRising: false
@ -232,6 +232,20 @@ const goBack = () => {
uni.navigateBack() uni.navigateBack()
} }
//
const viewIndexDetail = (item) => {
console.log('查看指数详情:', item.stockName)
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
// duration: 2000
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`
})
}
const sortByPrice = () => { const sortByPrice = () => {
if (sortType.value === 'price') { if (sortType.value === 'price') {
sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc' sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
@ -250,11 +264,6 @@ const sortByChange = () => {
} }
} }
const viewStockDetail = (stock) => {
console.log('查看股票详情:', stock)
//
}
onMounted(() => { onMounted(() => {
// //
iSMT.value = uni.getSystemInfoSync().statusBarHeight; iSMT.value = uni.getSystemInfoSync().statusBarHeight;

292
pages/marketSituation/marketOverview.vue

@ -1,3 +1,5 @@
<!-- @format -->
<template> <template>
<view class="main"> <view class="main">
<!-- 可滚动内容区域 --> <!-- 可滚动内容区域 -->
@ -9,10 +11,10 @@
</view> </view>
<view class="global_index"> <view class="global_index">
<view class="global_index_title"> <view class="global_index_title">
{{ $t('marketSituation.globalIndex') }}
{{ $t("marketSituation.globalIndex") }}
</view> </view>
<view class="global_index_more" @click="goToGlobalIndex"> <view class="global_index_more" @click="goToGlobalIndex">
<text>{{ $t('marketSituation.globalIndexMore') }}</text>
<text>{{ $t("marketSituation.globalIndexMore") }}</text>
<image src="/static/marketSituation-image/more.png" mode="aspectFit"></image> <image src="/static/marketSituation-image/more.png" mode="aspectFit"></image>
</view> </view>
</view> </view>
@ -20,15 +22,13 @@
<!-- 卡片网格 --> <!-- 卡片网格 -->
<view class="cards_grid"> <view class="cards_grid">
<view v-for="(card, index) in cardData" :key="index" class="card_item"> <view v-for="(card, index) in cardData" :key="index" class="card_item">
<IndexCard :flagIcon="card.flagIcon" :indexName="card.indexName"
:currentPrice="card.currentPrice" :changeAmount="card.changeAmount"
:changePercent="card.changePercent" :isRising="card.isRising" />
<IndexCard :flagIcon="card.flagIcon" :stockName="card.stockName" :currentPrice="card.currentPrice" :changeAmount="card.changeAmount" :changePercent="card.changePercent" :isRising="card.isRising" @click="viewIndexDetail(card)" />
</view> </view>
</view> </view>
<view class="warn"> <view class="warn">
<image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image> <image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image>
<view class="warn_text_container"> <view class="warn_text_container">
<text :class="warnTextClass">{{ $t('marketSituation.warn') }}</text>
<text :class="warnTextClass">{{ $t("marketSituation.warn") }}</text>
</view> </view>
</view> </view>
<!-- 底部安全区域防止被导航栏遮挡 --> <!-- 底部安全区域防止被导航栏遮挡 -->
@ -39,190 +39,210 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, watch, nextTick, computed } from 'vue'
import util from '../../common/util.js'
import IndexCard from '../../components/IndexCard.vue'
import { ref, onMounted, watch, nextTick, computed } from "vue";
import util from "../../common/util.js";
import IndexCard from "../../components/IndexCard.vue";
const iSMT = ref(0)
const searchValue = ref('')
const contentHeight = ref(0)
const headerHeight = ref(0) // header
const isWarnTextOverflow = ref(false) // warn
const iSMT = ref(0);
const searchValue = ref("");
const contentHeight = ref(0);
const headerHeight = ref(0); // header
const isWarnTextOverflow = ref(false); // warn
const pageIndex = ref(0)
const scrollToView = ref('')
const pageIndex = ref(0);
const scrollToView = ref("");
// //
const goToChartExample = () => { const goToChartExample = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages/marketSituation/chartExample'
})
}
url: "/pages/marketSituation/chartExample",
});
};
// contenttop // contenttop
const contentTopPosition = computed(() => { const contentTopPosition = computed(() => {
const statusBarHeight = iSMT.value || 0
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140
return statusBarHeight + currentHeaderHeight
})
const statusBarHeight = iSMT.value || 0;
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140;
return statusBarHeight + currentHeaderHeight;
});
// warnclass // warnclass
const warnTextClass = computed(() => { const warnTextClass = computed(() => {
return isWarnTextOverflow.value ? 'warn_text scroll-active' : 'warn_text'
})
return isWarnTextOverflow.value ? "warn_text scroll-active" : "warn_text";
});
// //
const showCountryModal = ref(false)
const selectedCountry = ref('概况')
const countryList = ref([
'概况', '新加坡', '马来西亚', '印度尼西亚', '美国', '中国香港',
'泰国', '中国', '加拿大', '越南', '外汇', '贵金属'
])
const showCountryModal = ref(false);
const selectedCountry = ref("概况");
const countryList = ref(["概况", "新加坡", "马来西亚", "印度尼西亚", "美国", "中国香港", "泰国", "中国", "加拿大", "越南", "外汇", "贵金属"]);
// //
const cardData = ref([ const cardData = ref([
{ {
flagIcon: '🇺🇸',
indexName: '道琼斯',
currentPrice: '45757.90',
changeAmount: '-125.22',
changePercent: '-0.27%',
isRising: false
flagIcon: "🇺🇸",
stockName: "道琼斯",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "-125.22",
changePercent: "-0.27%",
isRising: false,
}, },
{ {
flagIcon: '🇺🇸',
indexName: '纳斯达克',
currentPrice: '22333.96',
changeAmount: '+125.22',
changePercent: '+0.47%',
isRising: true
flagIcon: "🇺🇸",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "22333.96",
changeAmount: "+125.22",
changePercent: "+0.47%",
isRising: true,
}, },
{ {
flagIcon: '🇺🇸',
indexName: '标普500',
currentPrice: '6606.08',
changeAmount: '+125.22',
changePercent: '+0.27%',
isRising: true
flagIcon: "🇺🇸",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "6606.08",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
}, },
{ {
flagIcon: '🇨🇳',
indexName: '上证指数',
currentPrice: '3333.96',
changeAmount: '+125.22',
changePercent: '+0.27%',
isRising: true
flagIcon: "🇨🇳",
stockName: "上证指数",
stockCode: "noCode",
currentPrice: "3333.96",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
}, },
{ {
flagIcon: '🇨🇳',
indexName: '科创50',
currentPrice: '757.90',
changeAmount: '-25.22',
changePercent: '-0.27%',
isRising: false
flagIcon: "🇨🇳",
stockName: "科创50",
stockCode: "noCode",
currentPrice: "757.90",
changeAmount: "-25.22",
changePercent: "-0.27%",
isRising: false,
}, },
{ {
flagIcon: '🇭🇰',
indexName: '恒生指数',
currentPrice: '19757.90',
changeAmount: '-125.22',
changePercent: '-0.63%',
isRising: false
flagIcon: "🇭🇰",
stockName: "恒生指数",
stockCode: "noCode",
currentPrice: "19757.90",
changeAmount: "-125.22",
changePercent: "-0.63%",
isRising: false,
}, },
{ {
flagIcon: '🇸🇬',
indexName: '道琼斯',
currentPrice: '3757.90',
changeAmount: '+85.22',
changePercent: '+2.31%',
isRising: true
flagIcon: "🇸🇬",
stockName: "道琼斯",
stockCode: "noCode",
currentPrice: "3757.90",
changeAmount: "+85.22",
changePercent: "+2.31%",
isRising: true,
}, },
{ {
flagIcon: '🇲🇾',
indexName: '纳斯达克',
currentPrice: '1657.90',
changeAmount: '-15.22',
changePercent: '-0.91%',
isRising: false
flagIcon: "🇲🇾",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "1657.90",
changeAmount: "-15.22",
changePercent: "-0.91%",
isRising: false,
}, },
{ {
flagIcon: '🇹🇭',
indexName: '标普500',
currentPrice: '1457.90',
changeAmount: '+35.22',
changePercent: '+2.48%',
isRising: true
}
])
flagIcon: "🇹🇭",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "1457.90",
changeAmount: "+35.22",
changePercent: "+2.48%",
isRising: true,
},
]);
// //
const onSearchInput = (e) => { const onSearchInput = (e) => {
searchValue.value = e.detail.value
}
searchValue.value = e.detail.value;
};
// //
const onSearchConfirm = (e) => { const onSearchConfirm = (e) => {
console.log('搜索内容:', e.detail.value)
console.log("搜索内容:", e.detail.value);
// //
performSearch(e.detail.value)
}
performSearch(e.detail.value);
};
// //
const onSearchClick = () => { const onSearchClick = () => {
if (searchValue.value.trim()) { if (searchValue.value.trim()) {
performSearch(searchValue.value)
}
performSearch(searchValue.value);
} }
};
// //
const performSearch = (keyword) => { const performSearch = (keyword) => {
if (!keyword.trim()) { if (!keyword.trim()) {
uni.showToast({ uni.showToast({
title: '请输入搜索内容',
icon: 'none'
})
return
title: "请输入搜索内容",
icon: "none",
});
return;
} }
uni.showToast({ uni.showToast({
title: `搜索: ${keyword}`, title: `搜索: ${keyword}`,
icon: 'none'
})
icon: "none",
});
// //
}
};
// warn // warn
const checkWarnTextOverflow = () => { const checkWarnTextOverflow = () => {
nextTick(() => { nextTick(() => {
setTimeout(() => { setTimeout(() => {
const query = uni.createSelectorQuery()
const query = uni.createSelectorQuery();
// //
query.select('.warn_text_container').boundingClientRect()
query.select('.warn_text').boundingClientRect()
query.select(".warn_text_container").boundingClientRect();
query.select(".warn_text").boundingClientRect();
query.exec((res) => { query.exec((res) => {
const containerRect = res[0]
const textRect = res[1]
const containerRect = res[0];
const textRect = res[1];
if (!containerRect || !textRect) { if (!containerRect || !textRect) {
return
return;
} }
// //
const isOverflow = textRect.width > (containerRect.width - 10)
isWarnTextOverflow.value = isOverflow
})
}, 500)
})
}
const isOverflow = textRect.width > containerRect.width - 10;
isWarnTextOverflow.value = isOverflow;
});
}, 500);
});
};
//
const viewIndexDetail = (item) => {
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
// duration: 2000
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
});
};
// //
const goToGlobalIndex = () => { const goToGlobalIndex = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages/marketSituation/globalIndex'
})
}
url: "/pages/marketSituation/globalIndex",
});
};
onMounted(() => { onMounted(() => {
// //
@ -231,30 +251,34 @@ onMounted(() => {
// DOM // DOM
nextTick(() => { nextTick(() => {
// header // header
uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
uni
.createSelectorQuery()
.select(".header_fixed")
.boundingClientRect((rect) => {
if (rect) { if (rect) {
headerHeight.value = rect.height
console.log('Header实际高度:', headerHeight.value, 'px')
headerHeight.value = rect.height;
console.log("Header实际高度:", headerHeight.value, "px");
} }
}).exec()
})
.exec();
// warn // warn
checkWarnTextOverflow()
})
})
checkWarnTextOverflow();
});
});
// headerHeightcontentHeight // headerHeightcontentHeight
watch(headerHeight, (newHeight) => { watch(headerHeight, (newHeight) => {
if (newHeight > 0) { if (newHeight > 0) {
const systemInfo = uni.getSystemInfoSync()
const windowHeight = systemInfo.windowHeight
const statusBarHeight = systemInfo.statusBarHeight || 0
const footerHeight = 100
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)
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight;
console.log("重新计算contentHeight:", contentHeight.value);
} }
})
});
</script> </script>
<style scoped> <style scoped>
@ -413,7 +437,7 @@ watch(headerHeight, (newHeight) => {
min-width: 40rpx; min-width: 40rpx;
max-width: 120rpx; max-width: 120rpx;
height: 8rpx; height: 8rpx;
background-image: url('/static/marketSituation-image/bg.png');
background-image: url("/static/marketSituation-image/bg.png");
background-size: cover; background-size: cover;
background-position: center; background-position: center;
background-repeat: no-repeat; background-repeat: no-repeat;
@ -462,9 +486,9 @@ watch(headerHeight, (newHeight) => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background-color: #F3F3F3;
background-color: #f3f3f3;
border-radius: 30rpx; border-radius: 30rpx;
border: 1rpx solid #E0E0E0;
border: 1rpx solid #e0e0e0;
padding: 30rpx 20rpx; padding: 30rpx 20rpx;
box-sizing: border-box; box-sizing: border-box;
/* 设置最小高度保护,但允许内容撑开 */ /* 设置最小高度保护,但允许内容撑开 */

Loading…
Cancel
Save