diff --git a/api/tcpConnection.js b/api/tcpConnection.js index a0306bf..62fb6bb 100644 --- a/api/tcpConnection.js +++ b/api/tcpConnection.js @@ -21,33 +21,33 @@ const TCP_CONFIG = { * TCP连接管理类 */ class TCPConnection { - constructor() { - this.channelConnections = new Map(); // 存储每个channel的连接状态 - this.connectionCallbacks = []; - this.messageCallbacks = []; - } + constructor() { + this.channelConnections = new Map(); // 存储每个channel的连接状态 + this.connectionCallbacks = []; + this.messageCallbacks = []; + } - /** - * TCP初始化连接 - * @param {Object} config - 连接配置 {ip, port, channel, charsetname} - * @param {Function} callback - 连接状态回调函数 - */ - connect(config = {}, callback = null) { - const channel = config.channel || TCP_CONFIG.channel; - - // 如果该channel已经连接,先断开现有连接 - if (this.channelConnections.get(channel)) { - console.log(`检测到channel ${channel}现有TCP连接,先断开...`); - this.disconnect(config); - // 等待断开完成后再连接 - setTimeout(() => { - this._performConnect(config, callback); - }, 300); - } else { - // 直接连接 - this._performConnect(config, callback); - } + /** + * TCP初始化连接 + * @param {Object} config - 连接配置 {ip, port, channel, charsetname} + * @param {Function} callback - 连接状态回调函数 + */ + connect(config = {}, callback = null) { + const channel = config.channel || TCP_CONFIG.channel; + + // 如果该channel已经连接,先断开现有连接 + if (this.channelConnections.get(channel)) { + console.log(`检测到channel ${channel}现有TCP连接,先断开...`); + this.disconnect(config); + // 等待断开完成后再连接 + setTimeout(() => { + this._performConnect(config, callback); + }, 300); + } else { + // 直接连接 + this._performConnect(config, callback); } + } /** * 执行TCP连接 @@ -66,33 +66,31 @@ class TCPConnection { connectionConfig.charsetname = config.charsetname || TCP_CONFIG.charsetname; } - console.log('开始建立TCP连接:', connectionConfig); - TCPSocket.connect( - connectionConfig, - result => { - /** - * status : 0 连接成功 - * status : 1 断开连接 - * receivedMsg : 服务器返回字符串(普通的字符串交互) - * receivedHexMsg : 服务器返回字节数组(单片机、智能家居等硬件数据交互) - */ - if (result.status == '0') { - // TCP连接成功 - this.channelConnections.set(connectionConfig.channel, true); - console.log(`TCP连接成功 - Channel ${connectionConfig.channel}`); - this._notifyConnectionCallbacks('connected', result, connectionConfig.channel); - } else if (result.status == '1') { - // TCP断开连接 - this.channelConnections.set(connectionConfig.channel, false); - console.log(`TCP断开连接 - Channel ${connectionConfig.channel}`); - this._notifyConnectionCallbacks('disconnected', result, connectionConfig.channel); - } + console.log("开始建立TCP连接:", connectionConfig); + TCPSocket.connect(connectionConfig, (result) => { + /** + * status : 0 连接成功 + * status : 1 断开连接 + * receivedMsg : 服务器返回字符串(普通的字符串交互) + * receivedHexMsg : 服务器返回字节数组(单片机、智能家居等硬件数据交互) + */ + if (result.status == "0") { + // TCP连接成功 + this.channelConnections.set(connectionConfig.channel, true); + console.log(`TCP连接成功 - Channel ${connectionConfig.channel}`); + this._notifyConnectionCallbacks("connected", result, connectionConfig.channel); + } else if (result.status == "1") { + // TCP断开连接 + this.channelConnections.set(connectionConfig.channel, false); + console.log(`TCP断开连接 - Channel ${connectionConfig.channel}`); + this._notifyConnectionCallbacks("disconnected", result, connectionConfig.channel); + } - if (result.receivedMsg) { - // 服务器返回字符串 - console.log('收到字符串消息:', result.receivedMsg); - this._notifyMessageCallbacks('string', result.receivedMsg, null, connectionConfig.channel); - } + if (result.receivedMsg) { + // 服务器返回字符串 + console.log("收到字符串消息:", result.receivedMsg); + this._notifyMessageCallbacks("string", result.receivedMsg, null, connectionConfig.channel); + } // if (result.receivedHexMsg) { // // 硬件服务器返回16进制数据 @@ -115,18 +113,18 @@ class TCPConnection { }); } - /** - * TCP发送消息(普通的字符串交互) - * @param {String|Object} message - 要发送的消息,如果是对象会自动转换为JSON字符串 - * @param {Object} config - 发送配置 {channel, charsetname} - */ - send(message, config = {}) { - const channel = config.channel || '1'; - - if (!this.channelConnections.get(channel)) { - console.warn(`TCP Channel ${channel}未连接,无法发送消息`); - return false; - } + /** + * TCP发送消息(普通的字符串交互) + * @param {String|Object} message - 要发送的消息,如果是对象会自动转换为JSON字符串 + * @param {Object} config - 发送配置 {channel, charsetname} + */ + send(message, config = {}) { + const channel = config.channel || "1"; + + if (!this.channelConnections.get(channel)) { + console.warn(`TCP Channel ${channel}未连接,无法发送消息`); + return false; + } // 如果message是对象,转换为JSON字符串 let messageStr = message; @@ -149,20 +147,20 @@ class TCPConnection { return true; } - /** - * TCP断开连接 - * @param {Object} config - 断开配置 {channel} - */ - disconnect(config = {}) { - const channel = config.channel || TCP_CONFIG.channel; - const disconnectConfig = { - channel: channel - }; + /** + * TCP断开连接 + * @param {Object} config - 断开配置 {channel} + */ + disconnect(config = {}) { + const channel = config.channel || TCP_CONFIG.channel; + const disconnectConfig = { + channel: channel, + }; - TCPSocket.disconnect(disconnectConfig); - this.channelConnections.set(channel, false); - console.log(`TCP连接已断开 - Channel ${channel}`, disconnectConfig); - } + TCPSocket.disconnect(disconnectConfig); + this.channelConnections.set(channel, false); + console.log(`TCP连接已断开 - Channel ${channel}`, disconnectConfig); + } /** * 添加连接状态监听器 @@ -206,50 +204,50 @@ class TCPConnection { } } - /** - * 获取连接状态 - * @param {String} channel - 要检查的channel,如果不指定则返回所有channel的连接状态 - * @returns {Boolean|Object} 连接状态 - */ - getConnectionStatus(channel = null) { - if (channel) { - return this.channelConnections.get(channel) || false; - } - // 返回所有channel的连接状态 - const allConnections = {}; - for (const [ch, status] of this.channelConnections) { - allConnections[ch] = status; - } - return allConnections; + /** + * 获取连接状态 + * @param {String} channel - 要检查的channel,如果不指定则返回所有channel的连接状态 + * @returns {Boolean|Object} 连接状态 + */ + getConnectionStatus(channel = null) { + if (channel) { + return this.channelConnections.get(channel) || false; } - - /** - * 通知连接状态回调 - * @private - */ - _notifyConnectionCallbacks(status, result, channel) { - this.connectionCallbacks.forEach(callback => { - try { - callback(status, result, channel); - } catch (error) { - console.error('连接状态回调执行错误:', error); - } - }); + // 返回所有channel的连接状态 + const allConnections = {}; + for (const [ch, status] of this.channelConnections) { + allConnections[ch] = status; } + return allConnections; + } - /** - * 通知消息回调 - * @private - */ - _notifyMessageCallbacks(type, message, parsedArray = null, channel = null) { - this.messageCallbacks.forEach(callback => { - try { - callback(type, message, parsedArray, channel); - } catch (error) { - console.error('消息回调执行错误:', error); - } - }); - } + /** + * 通知连接状态回调 + * @private + */ + _notifyConnectionCallbacks(status, result, channel) { + this.connectionCallbacks.forEach((callback) => { + try { + callback(status, result, channel); + } catch (error) { + console.error("连接状态回调执行错误:", error); + } + }); + } + + /** + * 通知消息回调 + * @private + */ + _notifyMessageCallbacks(type, message, parsedArray = null, channel = null) { + this.messageCallbacks.forEach((callback) => { + try { + callback(type, message, parsedArray, channel); + } catch (error) { + console.error("消息回调执行错误:", error); + } + }); + } } // 创建TCP连接实例 diff --git a/common/dailyData.js b/common/dailyData.js new file mode 100644 index 0000000..d77cc2e --- /dev/null +++ b/common/dailyData.js @@ -0,0 +1,59 @@ +function generateDailyPacket(stock_code, startDate, days, basePrice) { + const data = []; + let prevClose = Number(basePrice); + const toStrDate = (dateVal) => (typeof dateVal === 'number' ? String(dateVal) : dateVal); + const addDays = (yyyymmdd, delta) => { + const y = parseInt(yyyymmdd.slice(0, 4), 10); + const m = parseInt(yyyymmdd.slice(4, 6), 10) - 1; + const d = parseInt(yyyymmdd.slice(6, 8), 10); + const dt = new Date(y, m, d); + dt.setDate(dt.getDate() + delta); + const yyyy = dt.getFullYear(); + const mm = String(dt.getMonth() + 1).padStart(2, '0'); + const dd = String(dt.getDate()).padStart(2, '0'); + return `${yyyy}${mm}${dd}`; + }; + const randDrift = () => (Math.random() - 0.5) * 0.02; // 每日 ±1% 漂移 + const spread = 0.00050; // 买卖点差(可按需要调整) + + let date = toStrDate(startDate); + for (let i = 0; i < days; i++) { + const open = +(prevClose * (1 + randDrift())).toFixed(5); + const close = +(open * (1 + randDrift())).toFixed(5); + const highRaw = Math.max(open, close) * (1 + Math.random() * 0.01); + const lowRaw = Math.min(open, close) * (1 - Math.random() * 0.01); + const high = +highRaw.toFixed(5); + const low = +lowRaw.toFixed(5); + + const tick_qty = Math.floor(1000 + Math.random() * 5000); // 成交量 + const amount = +(close * tick_qty).toFixed(2); // 成交额 + + const item = { + ts_code: stock_code, + trade_date: date, + bid_open: open, + bid_high: high, + bid_low: low, + bid_close: close, + ask_open: +(open + spread).toFixed(5), + ask_high: +(high + spread).toFixed(5), + ask_low: +(low + spread).toFixed(5), + ask_close: +(close + spread).toFixed(5), + tick_qty, + amount, + }; + + data.push(item); + prevClose = close; + date = addDays(date, 1); + } + + return { stock_code, data }; +} +// ... existing code ... +export const dailyDataPackets = { + // 如已存在同名键,可合并或覆盖 + 'GBPAUD.FXCM': generateDailyPacket('GBPAUD.FXCM', '20240101', 3000, 2.03893), + 'EURUSD.FXCM': generateDailyPacket('EURUSD.FXCM', '20240101', 3000, 1.08350), + // 可按需继续添加更多代码 +}; \ No newline at end of file diff --git a/components/IndexCard.vue b/components/IndexCard.vue index ad1ae69..69a3de3 100644 --- a/components/IndexCard.vue +++ b/components/IndexCard.vue @@ -64,7 +64,6 @@ const props = defineProps({ }); const getMarketFlag = (market) => { - console.log("market", market); let imagePath; if (market === "cn") { @@ -86,8 +85,6 @@ const getMarketFlag = (market) => { } else { imagePath = "/static/marketSituation-image/country-flag/global.png"; } - - console.log("返回的图片路径:", imagePath); return imagePath; }; diff --git a/components/deepExploration_header.vue b/components/deepExploration_header.vue index 095ecf1..7ebb3fd 100644 --- a/components/deepExploration_header.vue +++ b/components/deepExploration_header.vue @@ -72,7 +72,7 @@ {{ item.stockName }} ({{ item.stockCode }}) - ({{ item.stockCode }}) + {{ modelType(item.model) }} {{ formatTimeForHistory(item.createdTime) @@ -99,12 +99,23 @@ const props = defineProps({ }, }); const showHistoryDrawer = ref(false); -const modelType = ref(''); const drawerOffsetY = ref(0); // const handleHistory = () => { // showHistoryDrawer.value = true; // }; +function modelType(model) { + switch (model) { + case 1: + return "主力追踪"; + case 2: + return "主力雷达"; + case 3: + return "主力解码"; + case 4: + return "主力资金流"; + } +} // 历史记录 const openHistoryDrawer = async () => { const res = await RecordListApi({ @@ -380,7 +391,7 @@ onMounted(() => {}); } .drawer-close { - background: url("../static/icons/关闭2.svg"); + background: url("../static/icons/close-two.svg"); width: 48rpx; height: 48rpx; border-radius: 24rpx; diff --git a/components/login-prompt.vue b/components/login-prompt.vue index 23dd653..a7d0783 100644 --- a/components/login-prompt.vue +++ b/components/login-prompt.vue @@ -28,7 +28,9 @@ const loginStore = useLoginStore(); // 初始化 onMounted(() => { if (!userStore.userInfo) { - show(); + setTimeout(() => { + show(); + }, 500); } }), // watch( @@ -45,11 +47,20 @@ onMounted(() => { loginStore.$subscribe(() => { if (loginStore.loginInfo === "false") { - console.log("登录失败"); - show(); + console.log("游客访问"); + setTimeout(() => { + show(); + }, 500); } }); +loginStore.$subscribe(() => { + if (loginStore.loginInfo === "true") { + console.log("用户登录"); + hide(); + } +}); + // 定义响应式数据 const showPrompt = ref(false); const showAnimation = ref(false); @@ -79,14 +90,17 @@ const goLogin = () => { uni.navigateTo({ url: "/pages/start/login/login", }); - hide(); + loginStore.setLoginInfo("true"); + // hide(); }; // 跳转到登录页面 const goRegister = () => { uni.navigateTo({ url: "/pages/start/Registration/Registration", }); - hide(); + loginStore.setLoginInfo("true"); + + // hide(); }; // 以访客身份继续 @@ -106,10 +120,10 @@ const continueAsVisitor = async () => { userStore.setUserInfo(res.data); console.log("0loginStore.loginInfo", loginStore.loginInfo); hide(); - + // 发送游客登录成功事件,通知首页重新加载 - uni.$emit('visitorLoginSuccess', { - userInfo: res.data + uni.$emit("visitorLoginSuccess", { + userInfo: res.data, }); } }; diff --git a/pages/blank/institutionalTrendsBriefing.vue b/pages/blank/institutionalTrendsBriefing.vue index d78c5b0..ca1133c 100644 --- a/pages/blank/institutionalTrendsBriefing.vue +++ b/pages/blank/institutionalTrendsBriefing.vue @@ -4,7 +4,7 @@ - + @@ -16,7 +16,7 @@ > - + 暂无内容~ diff --git a/pages/blank/notice.vue b/pages/blank/notice.vue index 713de07..f64f90d 100644 --- a/pages/blank/notice.vue +++ b/pages/blank/notice.vue @@ -4,7 +4,7 @@ - + @@ -16,7 +16,7 @@ > - + 暂无内容~ diff --git a/pages/customerServicePlatform/questionDetail.vue b/pages/customerServicePlatform/questionDetail.vue index bf45938..cedeecb 100644 --- a/pages/customerServicePlatform/questionDetail.vue +++ b/pages/customerServicePlatform/questionDetail.vue @@ -111,7 +111,7 @@ this.answerContent = ''; for (let i = 0; i < answer.length; i++) { this.answerContent += answer[i]; - await this.sleepTime(150); + await this.sleepTime(); } } else { this.answerContent = '获取回答失败,请重试'; diff --git a/pages/deepExploration/MainForceActions.vue b/pages/deepExploration/MainForceActions.vue index a4975e8..3838622 100644 --- a/pages/deepExploration/MainForceActions.vue +++ b/pages/deepExploration/MainForceActions.vue @@ -1,4 +1,5 @@