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.

2218 lines
62 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
3 weeks ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="main">
  3. <!-- 顶部状态栏占位 -->
  4. <view class="top" :style="{height:iSMT+'px'}"></view>
  5. <!-- 登录的提示 -->
  6. <LoginPrompt ref="loginPrompt"></LoginPrompt>
  7. <!-- 头部导航 -->
  8. <view class="header">
  9. <view class="headphone-icon" @click="goToCustomerService">
  10. <image src="https://d31zlh4on95l9h.cloudfront.net/images/bef2edba6cc0c85671fde07cfab5270d.png" class="header-icon-image"></image>
  11. </view>
  12. <view class="title">DeepChart</view>
  13. <view class="notification-icon" @click="goToNotificationCenter">
  14. <image src="https://d31zlh4on95l9h.cloudfront.net/images/2554c84b91712d2a6cb6b00380e63bac.png" class="header-icon-image"></image>
  15. </view>
  16. </view>
  17. <!-- 内容区域 - 使用滚动视图 -->
  18. <scroll-view scroll-y class="content-container">
  19. <!-- 1. 今日市场概览 -->
  20. <market-overview :stock-info-list="currentStockInfoList"></market-overview>
  21. <!-- 间隔 -->
  22. <view class="section-gap"></view>
  23. <!-- 新增欢迎部分 -->
  24. <view class="section welcome-section">
  25. <!-- 轮播图 -->
  26. <swiper class="welcome-swiper" circular autoplay interval="3000" duration="500" indicator-dots indicator-active-color="#4080ff">
  27. <swiper-item v-for="(imageUrl, index) in swiperImages" :key="index">
  28. <image class="swiper-image" :src="imageUrl" mode="aspectFill"></image>
  29. </swiper-item>
  30. </swiper>
  31. </view>
  32. <!-- 2. DeepMate -->
  33. <view class="section deepmate-section">
  34. <DeepMate />
  35. </view>
  36. <!-- 3. 深度探索 -->
  37. <view class="section deep-exploration">
  38. <!-- 上部分标题和查看更多按钮 -->
  39. <view class="section-header-container">
  40. <view class="section-header">
  41. <view class="header-left">
  42. <text class="section-title">深度探索</text>
  43. </view>
  44. <view class="header-right">
  45. <text class="more-btn" @click="goToDeepExploration">查看更多</text>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 下部分四个图标 -->
  50. <view class="exploration-container">
  51. <view class="exploration-content">
  52. <view class="exploration-item" @click="goToMainForceActions(1)">
  53. <image class="exploration-icon" src="https://d31zlh4on95l9h.cloudfront.net/images/199472b0ee90a1c897f7c87b85accd84.png" mode="aspectFit" lazy-load="true"></image>
  54. <text class="exploration-text">主力追踪</text>
  55. </view>
  56. <view class="exploration-item" @click="goToMainForceActions(2)">
  57. <image class="exploration-icon" src="https://d31zlh4on95l9h.cloudfront.net/images/c25ca5e176efc961dabfa5d0d1b486b0.png" mode="aspectFit" lazy-load="true"></image>
  58. <text class="exploration-text">主力雷达</text>
  59. </view>
  60. <view class="exploration-item" @click="goToMainForceActions(3)">
  61. <image class="exploration-icon" src="https://d31zlh4on95l9h.cloudfront.net/images/c064d7066dc8129a7df7b052762f82cf.png" mode="aspectFit" lazy-load="true"></image>
  62. <text class="exploration-text">主力解码</text>
  63. </view>
  64. <view class="exploration-item" @click="goToMainForceActions(4)">
  65. <image class="exploration-icon" src="https://d31zlh4on95l9h.cloudfront.net/images/9d69cceee9c515911477078af6f68d88.png" mode="aspectFit" lazy-load="true"></image>
  66. <text class="exploration-text">主力资金流</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 4. 我的自选 -->
  72. <view class="section my-selection">
  73. <!-- 上部分标题和查看更多按钮 -->
  74. <view class="section-header-container">
  75. <view class="section-header">
  76. <text class="section-title">我的自选</text>
  77. <text class="more-btn" @click="goToMarketSituation">添加自选股</text>
  78. </view>
  79. <!-- 我的自选TCP连接状态和控制 -->
  80. <!-- <view class="my-stocks-tcp-control">
  81. <view class="tcp-status" :class="{'connected': myStocksTcpConnected, 'disconnected': !myStocksTcpConnected}">
  82. <text class="status-text">{{myStocksTcpConnected ? '自选已连接' : '自选未连接'}}</text>
  83. </view>
  84. <view class="tcp-buttons">
  85. <button class="tcp-btn connect-btn" @click="connectMyStocksTcp" :disabled="myStocksTcpConnected">连接</button>
  86. <button class="tcp-btn disconnect-btn" @click="disconnectMyStocksTcp" :disabled="!myStocksTcpConnected">断开</button>
  87. </view>
  88. </view> -->
  89. </view>
  90. <!-- 下部分股票列表 -->
  91. <view class="stock-container">
  92. <view class="stock-list">
  93. <!-- 如果有TCP数据显示实时数据否则显示静态数据 -->
  94. <view class="stock-item" v-for="(item, index) in (myStocksInfoList.length > 0 ? myStocksInfoList : myStocks)" :key="item.code || item.stock_code">
  95. <view class="stock-info">
  96. <view class="name-container">
  97. <text class="stock-name">{{item.name || item.stock_name}}</text>
  98. <text class="stock-code-label">{{item.code || item.stock_code}}</text>
  99. </view>
  100. <view class="price-container">
  101. <text class="stock-price">{{item.price || item.current_price}}</text>
  102. <text class="stock-change" :class="{'stock-up': (item.change_percent || item.change || item.change_amount || 0) > 0, 'stock-down': (item.change_percent || item.change || item.change_amount || 0) < 0}">
  103. {{(item.change_percent || item.change || item.change_amount || 0) > 0 ? '+' : ''}}{{(parseFloat(item.change_percent || item.change || item.change_amount || 0)).toFixed(2)}}%
  104. </text>
  105. </view>
  106. </view>
  107. <view class="stock-chart">
  108. <image :src="getChartImage(item)" mode="aspectFit" class="chart-image"></image>
  109. </view>
  110. </view>
  111. </view>
  112. <!-- 机构动向简报数据 -->
  113. <view class="institutional-reports">
  114. <view class="section-title-container">
  115. <text class="section-title-text">机构动向简报</text>
  116. </view>
  117. <view class="text-gap"></view>
  118. <view class="report-item" v-for="(report, index) in institutionalReports" :key="index" @click="goToNotFoundBriefing(report)">
  119. <view class="report-stock">{{report.stock}}</view>
  120. <view class="report-status">{{report.status}}</view>
  121. </view>
  122. <view class="view-more" @click="goToCustomStockList">
  123. <text>查看更多 >></text>
  124. </view>
  125. </view>
  126. </view>
  127. <view class="disclaimer">
  128. <text class="disclaimer-text">以上数据由AI生成不作为最终投资建议决策需独立</text>
  129. </view>
  130. </view>
  131. <!-- 5. TCP连接测试 -->
  132. <!-- <view class="section tcp-test-section">
  133. <view class="section-header">
  134. <text class="section-title">TCP连接测试</text>
  135. <view class="tcp-status" :class="{'connected': tcpConnected, 'disconnected': !tcpConnected}">
  136. <text class="status-text">{{tcpConnected ? '已连接' : '未连接'}}</text>
  137. </view>
  138. </view> -->
  139. <!-- TCP控制按钮 -->
  140. <!-- <view class="tcp-controls">
  141. <button class="tcp-btn connect-btn" @click="connectTcp" :disabled="tcpConnected">连接</button>
  142. <button class="tcp-btn disconnect-btn" @click="disconnectTcp" :disabled="!tcpConnected">断开</button>
  143. <button class="tcp-btn send-btn" @click="sendTcpMessage" :disabled="!tcpConnected">发送测试消息</button>
  144. <button class="tcp-btn status-btn" @click="getTcpStatus">查看状态</button>
  145. </view> -->
  146. <!-- 消息记录 -->
  147. <!-- <view class="tcp-messages" v-if="tcpMessages.length > 0">
  148. <view class="messages-header">
  149. <text class="messages-title">消息记录 ({{tcpMessages.length}})</text>
  150. <button class="clear-btn" @click="clearTcpMessages">清空</button>
  151. </view>
  152. <scroll-view scroll-y class="messages-list" scroll-top="{{tcpMessages.length * 50}}">
  153. <view class="message-item" v-for="(msg, index) in tcpMessages" :key="index"
  154. :class="{'sent': msg.direction === 'sent', 'received': msg.direction === 'received'}">
  155. <view class="message-info">
  156. <text class="message-direction">{{msg.direction === 'sent' ? '发送' : '接收'}}</text>
  157. <text class="message-time">{{msg.timestamp}}</text>
  158. </view>
  159. <text class="message-content">{{msg.content}}</text>
  160. </view>
  161. </scroll-view>
  162. </view>
  163. </view> -->
  164. <!-- 6. 今日市场看点 -->
  165. <view class="section-header highlights-title-container">
  166. <text class="section-title">今日市场核心看点</text>
  167. </view>
  168. <view class="highlights-image-container" @click="goToAnalysisInstitutionalTrends">
  169. <image src="https://d31zlh4on95l9h.cloudfront.net/images/8d5365af968402a18cedb120c09460b0.png" mode="aspectFit" class="highlights-image"></image>
  170. </view>
  171. <!-- 底部空间 - 为底部导航腾出空间 -->
  172. <view class="bottom-space"></view>
  173. </scroll-view>
  174. <!-- 底部导航 -->
  175. <footerBar class="static-footer" :type="type"></footerBar>
  176. </view>
  177. </template>
  178. <script>
  179. import footerBar from '../../components/footerBar.vue'
  180. import MarketOverview from '../../components/MarketOverview.vue'
  181. import DeepMate from '../../components/DeepMate.vue'
  182. import tcpConnection from '../../api/tcpConnection.js'
  183. import th from '../../static/language/th'
  184. import MySelectionsAPI from '../../api/home/mySelections.js'
  185. import { useUserStore } from '../../stores/modules/userInfo'
  186. export default {
  187. components: {
  188. footerBar,
  189. MarketOverview,
  190. DeepMate
  191. },
  192. data() {
  193. return {
  194. type: 'home',
  195. iSMT: 0,
  196. // 用户信息 store
  197. userStore: null,
  198. // 深度探索数据
  199. explorationItems: [
  200. { title: '主力追踪', icon: '/static/c1.png' },
  201. { title: '主力资金', icon: '/static/c2.png' },
  202. { title: '主力解码', icon: '/static/c3.png' },
  203. { title: '主力资金流', icon: '/static/c4.png' }
  204. ],
  205. // 轮播图片数据
  206. swiperImages: [
  207. 'https://d31zlh4on95l9h.cloudfront.net/images/893a55bc0de424a1c9abf9f0d3eb2bb0.png',
  208. 'https://d31zlh4on95l9h.cloudfront.net/images/35b413c98b2f3b6f67f99beb29dc9017.png',
  209. 'https://d31zlh4on95l9h.cloudfront.net/images/413bd37201f13e04bb491f285b553d03.png',
  210. 'https://d31zlh4on95l9h.cloudfront.net/images/f3dde163daa842ff5818d521ce674c16.png',
  211. 'https://d31zlh4on95l9h.cloudfront.net/images/b1dae32cf36055c1c626df1eea29e6b6.png'
  212. ],
  213. // 我的自选股票数据
  214. myStocks: [
  215. { name: '特斯拉', code: 'TSLA', price: '482.00', change: 2.80 },
  216. { name: '英伟达', code: 'NVDA', price: '189.800', change: -2.92 },
  217. { name: '苹果', code: 'AAPL', price: '256.430', change: 2.60 }
  218. ],
  219. // 机构动向简报数据
  220. institutionalReports: [
  221. { stock: '特斯拉', status: '当前市场多头资金占比,且多头资金持续流入。' },
  222. { stock: '英伟达', status: '当前市场多头资金占比,且多头资金持续流入。' },
  223. { stock: '苹果', status: '当前市场多头资金占比,且多头资金持续流入。' }
  224. ],
  225. // 防抖定时器
  226. debounceTimer: null,
  227. // TCP连接相关状态
  228. tcpConnected: false,
  229. tcpMessages: [],
  230. lastSentMessage: '',
  231. // 我的自选TCP连接状态
  232. myStocksTcpConnected: false,
  233. // TCP监听器引用,用于移除监听器
  234. connectionListener: null,
  235. messageListener: null,
  236. // TCP股票数据存储
  237. tcpStockData: {
  238. count: 0,
  239. data: {},
  240. stock_count: 0,
  241. timestamp: '',
  242. type: ''
  243. },
  244. // 当前TCP使用的股票代码
  245. currentStockCodes: ['SH.000001', 'SH.000002', 'SH.000003'],
  246. // 我的自选TCP股票数据存储
  247. myStocksTcpData: {
  248. count: 0,
  249. data: {},
  250. stock_count: 0,
  251. timestamp: '',
  252. type: ''
  253. },
  254. // TCP数据缓存机制,用于处理分片数据
  255. tcpDataCache: {
  256. isCollecting: false, // 是否正在收集数据片段
  257. expectedCount: 0, // 期望的数据总数
  258. collectedData: {}, // 已收集的数据对象(用于对象级拼接)
  259. timestamp: '', // 数据时间戳
  260. type: '', // 数据类型
  261. // 新增:字符串片段缓存
  262. firstPartData: '', // 前半部分数据字符串
  263. isWaitingSecondPart: false // 是否正在等待后半部分数据
  264. },
  265. // 我的自选TCP数据缓存机制,用于处理分片数据
  266. myStocksTcpDataCache: {
  267. isCollecting: false, // 是否正在收集数据片段
  268. expectedCount: 0, // 期望的数据总数
  269. collectedData: {}, // 已收集的数据对象(用于对象级拼接)
  270. timestamp: '', // 数据时间戳
  271. type: '', // 数据类型
  272. // 字符串片段缓存
  273. firstPartData: '', // 前半部分数据字符串
  274. isWaitingSecondPart: false // 是否正在等待后半部分数据
  275. },
  276. // 当前显示的3个股票数据(用于MarketOverview组件)
  277. currentStockInfoList: [
  278. {
  279. stock_name: '美元/日元',
  280. current_price: '151.13',
  281. change: '+1.62%',
  282. change_value: 0,
  283. change_percent: 0
  284. },
  285. {
  286. stock_name: '美元/韩元',
  287. current_price: '1424.900',
  288. change: '-2.92%',
  289. change_value: 0,
  290. change_percent: 0
  291. },
  292. {
  293. stock_name: '美元/英镑',
  294. current_price: '0.730',
  295. change: '+2.92%',
  296. change_value: 0,
  297. change_percent: 0
  298. }
  299. ],
  300. // 我的自选处理后的股票信息列表
  301. myStocksInfoList: []
  302. }
  303. },
  304. // Vue 2生命周期方法
  305. mounted() {
  306. // 状态栏高度
  307. this.iSMT = uni.getSystemInfoSync().statusBarHeight;
  308. // 初始化用户信息 store
  309. this.userStore = useUserStore();
  310. // 预加载图片资源
  311. this.myStocks.forEach(stock => {
  312. // 使用getChartImage方法获取正确的图片路径
  313. const imageSrc = this.getChartImage(stock);
  314. // 使用uni.getImageInfo替代Image对象
  315. uni.getImageInfo({
  316. src: imageSrc,
  317. success: function(res) {
  318. // 图片加载成功
  319. console.log('图片预加载成功:', stock.name, imageSrc)
  320. },
  321. fail: function(err) {
  322. console.log('图片预加载失败:', err, imageSrc)
  323. }
  324. })
  325. })
  326. // 检查用户登录状态,只有已登录并且不是游客才加载自选股数据
  327. if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) {
  328. console.log('是用户登录,加载自选股数据', this.userStore.userInfo)
  329. this.loadMySelectionsData()
  330. } else if (this.userStore.userInfo && this.userStore.userInfo.isVisitor){
  331. console.log('是游客登录,加载默认自选股',this.userStore.userInfo)
  332. this.loadGuestDefaultStocks()
  333. }else {
  334. console.log('用户未登录',this.userStore.userInfo)
  335. }
  336. // 初始化TCP连接监听器
  337. this.initTcpListeners()
  338. // 监听游客登录成功事件
  339. uni.$on('visitorLoginSuccess', this.handleVisitorLoginSuccess)
  340. // 页面渲染完成后自动连接两个TCP连接
  341. // this.$nextTick(() => {
  342. // console.log('页面渲染完成,开始自动连接TCP服务器...')
  343. // // 延迟一小段时间确保页面完全加载后再连接
  344. // setTimeout(() => {
  345. // // 连接今日市场概览TCP(channel 1)
  346. // console.log('连接今日市场概览TCP(channel 1)...')
  347. // this.connectTcp()
  348. // // 稍微延迟后连接我的自选TCP(channel 2)
  349. // setTimeout(() => {
  350. // console.log('连接我的自选TCP(channel 2)...')
  351. // this.connectMyStocksTcp()
  352. // }, 500)
  353. // }, 1000)
  354. // })
  355. },
  356. // 页面销毁前的清理工作
  357. onUnload() {
  358. // 自动关闭主TCP连接
  359. if (this.tcpConnected) {
  360. console.log('页面销毁,自动关闭主TCP连接')
  361. tcpConnection.disconnect({
  362. ip: '39.102.136.61',
  363. port: '8080',
  364. channel: '1',
  365. charsetname: 'UTF-8'
  366. })
  367. this.tcpConnected = false
  368. }
  369. // 自动关闭我的自选TCP连接
  370. if (this.myStocksTcpConnected) {
  371. console.log('页面销毁,自动关闭我的自选TCP连接')
  372. tcpConnection.disconnect({
  373. ip: '39.102.136.61',
  374. port: '8088',
  375. channel: '2',
  376. charsetname: 'UTF-8'
  377. })
  378. this.myStocksTcpConnected = false
  379. }
  380. // 清理防抖定时器
  381. if (this.debounceTimer) {
  382. clearTimeout(this.debounceTimer)
  383. this.debounceTimer = null
  384. }
  385. // 移除TCP监听器,防止内存泄漏
  386. this.removeTcpListeners()
  387. // 移除游客登录成功事件监听器
  388. uni.$off('visitorLoginSuccess', this.handleVisitorLoginSuccess)
  389. },
  390. methods: {
  391. // 根据涨跌情况获取图表图片
  392. getChartImage(item) {
  393. // 获取涨跌值,支持多种字段名
  394. const changeValue = item.change_percent || item.change || item.change_amount || 0;
  395. // 如果有自定义图片,优先使用
  396. if (item.chartImg) {
  397. return item.chartImg;
  398. }
  399. // 根据涨跌情况返回对应图片
  400. if (parseFloat(changeValue) >= 0) {
  401. // 上涨时使用上涨图片
  402. return '/static/marketSituation-image/upTimeChart.png';
  403. } else if (parseFloat(changeValue) < 0) {
  404. // 下跌时使用下跌图片
  405. return '/static/marketSituation-image/downTimeChart.png';
  406. }
  407. },
  408. // 跳转到客服中台
  409. goToCustomerService() {
  410. uni.navigateTo({
  411. url: '/pages/customerServicePlatform/csPlatformIndex'
  412. })
  413. },
  414. // 跳转到通知中心
  415. goToNotificationCenter() {
  416. uni.navigateTo({
  417. url: '/pages/blank/notice'
  418. })
  419. },
  420. // 跳转到自定义股票列表页面
  421. goToCustomStockList() {
  422. uni.navigateTo({
  423. url: '/pages/customStockList/customStockList'
  424. })
  425. },
  426. // 跳转到行情页面
  427. goToMarketSituation() {
  428. uni.navigateTo({
  429. url: '/pages/marketSituation/marketSituation'
  430. })
  431. },
  432. // 跳转到机构动向解析页面
  433. goToAnalysisInstitutionalTrends() {
  434. uni.navigateTo({
  435. url: '/pages/analysisInstitutionalTrends/analysisInstitutionalTrends'
  436. })
  437. },
  438. // 跳转到深度探索页面
  439. goToDeepExploration() {
  440. uni.navigateTo({
  441. url: '/pages/deepExploration/deepExploration'
  442. })
  443. },
  444. // 跳转到缺省页面(机构动向简报点击)
  445. goToNotFoundBriefing(report) {
  446. uni.navigateTo({
  447. url: '/pages/notFoundBriefing/notFoundBriefing'
  448. })
  449. },
  450. // 跳转到主力行动页面(深度探索点击)
  451. goToMainForceActions(index) {
  452. uni.navigateTo({
  453. url: `/pages/deepExploration/MainForceActions?index=${index}`
  454. })
  455. },
  456. // 处理游客登录成功事件
  457. handleVisitorLoginSuccess(data) {
  458. console.log('收到游客登录成功事件:', data)
  459. // 重新加载页面数据
  460. this.reloadPageData()
  461. },
  462. // 重新加载页面数据
  463. reloadPageData() {
  464. console.log('重新加载页面数据...')
  465. // 更新用户信息store
  466. this.userStore = useUserStore()
  467. // 根据新的用户状态加载相应的数据
  468. if (this.userStore.userInfo && this.userStore.userInfo.isVisitor) {
  469. console.log('游客登录成功,加载默认自选股')
  470. this.loadGuestDefaultStocks()
  471. } else if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) {
  472. console.log('用户登录,加载自选股数据')
  473. this.loadMySelectionsData()
  474. }
  475. },
  476. // 防抖函数
  477. debounce(fn, delay = 300) {
  478. if (this.debounceTimer) clearTimeout(this.debounceTimer)
  479. this.debounceTimer = setTimeout(() => {
  480. fn()
  481. this.debounceTimer = null
  482. }, delay)
  483. },
  484. // 自选股数据加载相关方法
  485. // 加载自选股数据的主方法
  486. async loadMySelectionsData() {
  487. try {
  488. console.log('开始加载自选股数据...')
  489. // 调用checkExist判断用户是否存在自选股
  490. const checkResult = await MySelectionsAPI.checkExist()
  491. console.log('检查用户自选股存在性结果:', checkResult)
  492. if (checkResult.code === 200) {
  493. const isHave = checkResult.data.is_have
  494. if (isHave === 1) {
  495. // 用户有自选股,查询所有分组
  496. console.log('用户存在自选股,查询所有分组...')
  497. await this.loadUserStockGroups()
  498. } else {
  499. // 用户没有自选股,查询默认自选股
  500. console.log('用户不存在自选股,查询默认自选股...')
  501. await this.loadDefaultStocks()
  502. }
  503. } else {
  504. console.error('检查用户自选股存在性失败:', checkResult.message)
  505. // 失败时也尝试加载默认自选股
  506. // await this.loadDefaultStocks()
  507. }
  508. } catch (error) {
  509. console.error('加载自选股数据失败:', error)
  510. // 出错时尝试加载默认自选股
  511. await this.loadDefaultStocks()
  512. }
  513. },
  514. // 加载用户自选股分组
  515. async loadUserStockGroups() {
  516. try {
  517. const groupResult = await MySelectionsAPI.getUserStockGroupList()
  518. console.log('查询用户自选股分组结果:', groupResult)
  519. if (groupResult.code === 200 && groupResult.data && groupResult.data.length > 0) {
  520. // 找到id最小的分组
  521. const minIdGroup = groupResult.data.reduce((min, current) => {
  522. return current.id < min.id ? current : min
  523. })
  524. console.log('找到最小id分组:', minIdGroup)
  525. // 查询该分组下的股票
  526. await this.loadGroupStocks(minIdGroup.id)
  527. } else {
  528. console.log('没有找到用户自选股分组,加载默认自选股')
  529. await this.loadDefaultStocks()
  530. }
  531. } catch (error) {
  532. console.error('加载用户自选股分组失败:', error)
  533. await this.loadDefaultStocks()
  534. }
  535. },
  536. // 加载指定分组下的股票
  537. async loadGroupStocks(groupId) {
  538. try {
  539. const stockResult = await MySelectionsAPI.getUserStockList(null, null, {
  540. groupId: groupId,
  541. pageNum: 1,
  542. pageSize: 20
  543. })
  544. console.log('查询分组自选股结果:', stockResult)
  545. if (stockResult.code === 200 && stockResult.data) {
  546. this.processStockData(stockResult.data)
  547. } else {
  548. console.log('分组下没有股票数据,加载默认自选股')
  549. await this.loadDefaultStocks()
  550. }
  551. } catch (error) {
  552. console.error('加载分组股票失败:', error)
  553. await this.loadDefaultStocks()
  554. }
  555. },
  556. // 加载默认自选股
  557. async loadDefaultStocks() {
  558. try {
  559. const defaultResult = await MySelectionsAPI.getUserOrDefault()
  560. console.log('查询默认自选股结果:', defaultResult)
  561. if (defaultResult.code === 200 && defaultResult.data) {
  562. this.processStockData(defaultResult.data)
  563. } else {
  564. console.log('没有默认自选股数据')
  565. }
  566. } catch (error) {
  567. console.error('加载默认自选股失败:', error)
  568. }
  569. },
  570. // 游客加载默认自选股
  571. async loadGuestDefaultStocks() {
  572. try {
  573. console.log('游客开始加载默认自选股...')
  574. const guestResult = await MySelectionsAPI.getDefaultStocks()
  575. console.log('游客查询默认自选股结果:', guestResult)
  576. if (guestResult.code === 200 && guestResult.data) {
  577. this.processStockData(guestResult.data)
  578. } else {
  579. console.log('游客没有默认自选股数据')
  580. }
  581. } catch (error) {
  582. console.error('游客加载默认自选股失败:', error)
  583. }
  584. },
  585. // 处理股票数据
  586. processStockData(stockData) {
  587. console.log('处理股票数据:', stockData)
  588. // 根据返回的数据结构更新myStocks数组
  589. // 这里需要根据实际API返回的数据结构进行调整
  590. if (Array.isArray(stockData)) {
  591. // 如果是数组格式
  592. this.myStocks = stockData.map(stock => ({
  593. name: stock.name || stock.stock_name || '',
  594. code: stock.code || stock.stock_code || '',
  595. price: stock.price || stock.current_price || '0.00',
  596. change: stock.change || stock.change_percent || 0,
  597. change_percent: stock.change_percent || 0,
  598. change_amount: stock.change_amount || 0
  599. // 移除固定的chartImg设置,让getChartImage方法根据涨跌情况动态选择
  600. }))
  601. //重新赋值机构动向简报
  602. this.institutionalReports = stockData.map(stock => ({
  603. stock: stock.name || stock.stock_name || '',
  604. status: stock.code || stock.stock_code || '',
  605. }))
  606. } else if (stockData.list && Array.isArray(stockData.list)) {
  607. // 如果是分页格式
  608. this.myStocks = stockData.list.map(stock => ({
  609. name: stock.name || stock.stock_name || '',
  610. code: stock.code || stock.stock_code || '',
  611. price: stock.price || stock.current_price || '0.00',
  612. change: stock.change || stock.change_percent || 0,
  613. change_percent: stock.change_percent || 0,
  614. change_amount: stock.change_amount || 0
  615. // 移除固定的chartImg设置,让getChartImage方法根据涨跌情况动态选择
  616. }))
  617. //重新赋值机构动向简报
  618. //重新赋值机构动向简报
  619. this.institutionalReports = stockData.list.map(stock => ({
  620. stock: stock.name || stock.stock_name || '',
  621. status: stock.code || stock.stock_code || '',
  622. }))
  623. }
  624. console.log('更新后的自选股数据:', this.myStocks)
  625. // 更新TCP消息中的股票代码
  626. this.updateTcpStockCodes()
  627. },
  628. // 更新TCP消息中的股票代码
  629. updateTcpStockCodes() {
  630. // 从myStocks中提取前3个股票代码
  631. const stockCodes = this.myStocks.slice(0, 3).map(stock => stock.code).filter(code => code)
  632. console.log('更新TCP消息股票代码:', stockCodes)
  633. // 如果有股票代码,更新TCP消息
  634. if (stockCodes.length > 0) {
  635. // 补充到3个代码(如果不足3个,用默认代码补充)
  636. while (stockCodes.length < 3) {
  637. stockCodes.push('SH.000001') // 默认代码
  638. }
  639. // 保存到组件数据中,供TCP方法使用
  640. this.currentStockCodes = stockCodes
  641. console.log('当前TCP使用的股票代码:', this.currentStockCodes)
  642. }
  643. },
  644. // TCP连接相关方法
  645. // 初始化TCP监听器
  646. initTcpListeners() {
  647. // 创建连接状态监听器并保存引用
  648. this.connectionListener = (status, result, channel) => {
  649. console.log('TCP连接状态变化:', status, 'channel:', channel)
  650. // 根据channel更新对应的连接状态
  651. if (channel === '1') {
  652. // 主TCP连接
  653. this.tcpConnected = (status === 'connected')
  654. console.log('主TCP连接状态:', this.tcpConnected)
  655. // 显示连接状态提示
  656. uni.showToast({
  657. title: status === 'connected' ? '主连接服务器成功' : '主服务器连接断开',
  658. icon: status === 'connected' ? 'success' : 'none',
  659. duration: 1000
  660. })
  661. // 连接成功后自动发送股票数据请求命令
  662. if (status === 'connected') {
  663. console.log('主TCP连接成功,自动发送股票数据请求...')
  664. // 延迟一小段时间确保连接稳定后再发送命令
  665. setTimeout(() => {
  666. this.sendTcpMessage()
  667. }, 500)
  668. }
  669. } else if (channel === '2') {
  670. // 我的自选TCP连接
  671. this.myStocksTcpConnected = (status === 'connected')
  672. console.log('我的自选TCP连接状态:', this.myStocksTcpConnected)
  673. // 显示连接状态提示
  674. uni.showToast({
  675. title: status === 'connected' ? '我的自选连接成功' : '我的自选连接断开',
  676. icon: status === 'connected' ? 'success' : 'none',
  677. duration: 1000
  678. })
  679. // 连接成功后自动发送我的自选股票数据请求
  680. if (status === 'connected') {
  681. console.log('我的自选TCP连接成功,自动发送自选股票数据请求...')
  682. // 延迟一小段时间确保连接稳定后再发送命令
  683. setTimeout(() => {
  684. this.sendMyStocksTcpMessage()
  685. }, 500)
  686. }
  687. }
  688. }
  689. // 创建消息监听器并保存引用
  690. this.messageListener = (type, message, parsedArray, channel) => {
  691. const messageObj = {
  692. type: type,
  693. content: message,
  694. parsedArray: parsedArray,
  695. channel: channel,
  696. timestamp: new Date().toLocaleTimeString(),
  697. direction: 'received'
  698. }
  699. this.tcpMessages.push(messageObj)
  700. console.log('收到TCP消息:', messageObj)
  701. console.log('消息来源channel:', channel)
  702. // 根据channel调用相应的数据处理方法
  703. if (channel === '1') {
  704. // 主TCP连接 - 今日市场概览数据
  705. // console.log('处理今日市场概览数据')
  706. this.parseStockData(message)
  707. } else if (channel === '2') {
  708. // 我的自选TCP连接 - 我的自选数据
  709. console.log('处理我的自选数据')
  710. this.parseMyStocksData(message)
  711. } else {
  712. console.warn('未知的channel:', channel)
  713. }
  714. }
  715. // 注册监听器
  716. tcpConnection.onConnectionChange(this.connectionListener)
  717. tcpConnection.onMessage(this.messageListener)
  718. },
  719. // 连接TCP服务器
  720. connectTcp() {
  721. // console.log('开始连接TCP服务器...')
  722. // 先断开现有连接(如果存在)
  723. if (this.tcpConnected) {
  724. // console.log('检测到现有连接,先断开...')
  725. this.disconnectTcp()
  726. // 等待断开完成后再连接
  727. setTimeout(() => {
  728. this.performTcpConnect()
  729. }, 500)
  730. } else {
  731. // 直接连接
  732. this.performTcpConnect()
  733. }
  734. },
  735. // 执行TCP连接
  736. performTcpConnect() {
  737. // console.log('执行TCP连接...')
  738. tcpConnection.connect(
  739. {
  740. ip: '39.102.136.61',
  741. port: '8088',
  742. channel: '1', // 可选 1~20
  743. charsetname: 'UTF-8' // 默认UTF-8,可选GBK
  744. }
  745. )
  746. },
  747. // 断开TCP连接
  748. disconnectTcp() {
  749. // console.log('断开TCP连接...')
  750. tcpConnection.disconnect(
  751. {
  752. ip: '39.102.136.61',
  753. port: '8088',
  754. channel: '1', // 可选 1~20
  755. charsetname: 'UTF-8' // 默认UTF-8,可选GBK
  756. }
  757. )
  758. this.tcpConnected = false
  759. },
  760. // 连接我的自选TCP服务器
  761. connectMyStocksTcp() {
  762. console.log('开始连接我的自选TCP服务器...')
  763. // 先断开现有连接(如果存在)
  764. if (this.myStocksTcpConnected) {
  765. console.log('检测到我的自选现有连接,先断开...')
  766. this.disconnectMyStocksTcp()
  767. // 等待断开完成后再连接
  768. setTimeout(() => {
  769. this.performMyStocksTcpConnect()
  770. }, 500)
  771. } else {
  772. // 直接连接
  773. this.performMyStocksTcpConnect()
  774. }
  775. },
  776. // 执行我的自选TCP连接
  777. performMyStocksTcpConnect() {
  778. console.log('执行我的自选TCP连接...')
  779. tcpConnection.connect(
  780. {
  781. ip: '39.102.136.61',
  782. port: '8088',
  783. channel: '2', // 我的自选使用channel 2
  784. charsetname: 'UTF-8' // 默认UTF-8,可选GBK
  785. }
  786. )
  787. },
  788. // 断开我的自选TCP连接
  789. disconnectMyStocksTcp() {
  790. console.log('断开我的自选TCP连接...')
  791. tcpConnection.disconnect(
  792. {
  793. ip: '39.102.136.61',
  794. port: '8088',
  795. channel: '2', // 我的自选使用channel 2
  796. charsetname: 'UTF-8' // 默认UTF-8,可选GBK
  797. }
  798. )
  799. this.myStocksTcpConnected = false
  800. },
  801. // 解析我的自选TCP股票数据
  802. parseMyStocksData(message) {
  803. try {
  804. console.log('进入parseMyStocksData, message类型:', typeof message, '长度:', message.length)
  805. // 第一步:检查数据状态(完整、前半部分、后半部分)
  806. const dataStatus = this.getMyStocksDataStatus(message)
  807. let completeMessage = ''
  808. switch (dataStatus) {
  809. case 'complete':
  810. // 完整数据,直接处理
  811. console.log('我的自选:检测到完整数据,直接处理')
  812. completeMessage = message
  813. break
  814. case 'first_part':
  815. // 前半部分数据,缓存并等待后半部分
  816. console.log('我的自选:检测到前半部分数据,开始缓存')
  817. this.cacheMyStocksFirstPartData(message)
  818. return // 等待后半部分数据
  819. case 'second_part':
  820. // 后半部分数据,检查是否有缓存的前半部分
  821. if (this.myStocksTcpDataCache.isWaitingSecondPart) {
  822. console.log('我的自选:检测到后半部分数据,开始拼接')
  823. completeMessage = this.concatenateMyStocksDataParts(message)
  824. } else {
  825. console.log('我的自选:收到后半部分数据,但没有缓存的前半部分,跳过处理')
  826. return
  827. }
  828. break
  829. case 'invalid':
  830. default:
  831. console.log('我的自选:数据格式无效,跳过处理')
  832. return
  833. }
  834. // 第二步:解析完整的JSON数据
  835. let parsedMessage
  836. try {
  837. console.log('我的自选:开始解析完整JSON数据,长度:', completeMessage.length)
  838. parsedMessage = JSON.parse(completeMessage)
  839. console.log('我的自选:JSON解析成功,解析后类型:', typeof parsedMessage, parsedMessage)
  840. } catch (parseError) {
  841. console.error('我的自选:JSON解析失败:', parseError.message)
  842. // 清空字符串片段缓存
  843. this.clearMyStocksStringFragmentCache()
  844. return
  845. }
  846. // 第三步:检查是否是股票数据类型
  847. if (!((parsedMessage.type === 'batch_data_chunk' || parsedMessage.type === 'batch_realtime_data') && parsedMessage.data)) {
  848. console.log('我的自选:不是batch_data_chunk或batch_realtime_data类型的消息,跳过处理')
  849. return
  850. }
  851. console.log('我的自选:开始处理股票数据')
  852. // 第四步:验证数据完整性(对象级别的完整性检查)
  853. // 注意:batch_data_chunk类型的数据不需要验证完整性,直接处理
  854. if (parsedMessage.type === 'batch_data_chunk') {
  855. console.log('我的自选:batch_data_chunk类型数据,跳过完整性验证,直接处理')
  856. this.processCompleteMyStocksData(parsedMessage)
  857. } else {
  858. const isDataComplete = this.validateMyStocksDataIntegrity(parsedMessage)
  859. if (isDataComplete) {
  860. // 数据完整,直接处理
  861. console.log('我的自选:对象级数据完整,直接处理')
  862. this.processCompleteMyStocksData(parsedMessage)
  863. } else {
  864. // 数据不完整,需要拼接(对象级别的拼接)
  865. console.log('我的自选:对象级数据不完整,开始拼接处理')
  866. // 将当前数据合并到缓存中
  867. this.mergeMyStocksDataToCache(parsedMessage)
  868. // 检查缓存中的数据是否已经完整
  869. if (this.isMyStocksCacheDataComplete()) {
  870. console.log('我的自选:缓存数据已完整,开始处理')
  871. const completeData = this.getCompleteMyStocksDataFromCache()
  872. this.processCompleteMyStocksData(completeData)
  873. } else {
  874. console.log('我的自选:缓存数据仍不完整,等待更多数据片段')
  875. }
  876. }
  877. }
  878. } catch (error) {
  879. console.error('我的自选:解析TCP股票数据失败:', error.message)
  880. console.error('我的自选:错误详情:', error)
  881. // 发生错误时清空所有缓存
  882. this.clearMyStocksStringFragmentCache()
  883. if (this.myStocksTcpDataCache.isCollecting) {
  884. console.log('我的自选:发生错误,清空对象级数据缓存')
  885. this.myStocksTcpDataCache.isCollecting = false
  886. this.myStocksTcpDataCache.expectedCount = 0
  887. this.myStocksTcpDataCache.collectedData = {}
  888. this.myStocksTcpDataCache.timestamp = ''
  889. this.myStocksTcpDataCache.type = ''
  890. }
  891. }
  892. },
  893. // 验证我的自选数据完整性
  894. validateMyStocksDataIntegrity(parsedMessage) {
  895. if (!parsedMessage.count || !parsedMessage.data) {
  896. return false
  897. }
  898. const dataObjectCount = Object.keys(parsedMessage.data).length
  899. const expectedCount = parsedMessage.count
  900. console.log(`我的自选数据完整性验证: 期望${expectedCount}个对象,实际${dataObjectCount}个对象`)
  901. return dataObjectCount === expectedCount
  902. },
  903. // 检查我的自选数据状态(完整数据、前半部分数据、后半部分数据)
  904. getMyStocksDataStatus(message) {
  905. if (typeof message !== 'string') {
  906. return 'invalid'
  907. }
  908. const trimmedMessage = message.trim()
  909. const startsWithBrace = trimmedMessage.startsWith('{')
  910. const endsWithBrace = trimmedMessage.endsWith('}')
  911. if (startsWithBrace && endsWithBrace) {
  912. // 以{开头,以}结尾 - 完整数据
  913. console.log('我的自选:检测到完整数据格式')
  914. return 'complete'
  915. } else if (startsWithBrace && !endsWithBrace) {
  916. // 以{开头,不以}结尾 - 前半部分数据
  917. console.log('我的自选:检测到前半部分数据')
  918. return 'first_part'
  919. } else if (!startsWithBrace && endsWithBrace) {
  920. // 不以{开头,以}结尾 - 后半部分数据
  921. console.log('我的自选:检测到后半部分数据')
  922. return 'second_part'
  923. } else {
  924. // 其他情况 - 无效数据
  925. console.log('我的自选:检测到无效数据格式')
  926. return 'invalid'
  927. }
  928. },
  929. // 缓存我的自选前半部分数据
  930. cacheMyStocksFirstPartData(message) {
  931. this.myStocksTcpDataCache.firstPartData = message.trim()
  932. this.myStocksTcpDataCache.isWaitingSecondPart = true
  933. console.log('我的自选:已缓存前半部分数据,长度:', this.myStocksTcpDataCache.firstPartData.length)
  934. },
  935. // 拼接我的自选前后两部分数据
  936. concatenateMyStocksDataParts(secondPartMessage) {
  937. const completeMessage = this.myStocksTcpDataCache.firstPartData + secondPartMessage.trim()
  938. console.log('我的自选:数据拼接完成,完整数据长度:', completeMessage.length)
  939. // 清空缓存
  940. this.clearMyStocksStringFragmentCache()
  941. return completeMessage
  942. },
  943. // 清空我的自选字符串片段缓存
  944. clearMyStocksStringFragmentCache() {
  945. this.myStocksTcpDataCache.firstPartData = ''
  946. this.myStocksTcpDataCache.isWaitingSecondPart = false
  947. console.log('我的自选:字符串片段缓存已清空')
  948. },
  949. // 合并我的自选数据到缓存中
  950. mergeMyStocksDataToCache(parsedMessage) {
  951. // 如果是第一次收集数据,初始化缓存
  952. if (!this.myStocksTcpDataCache.isCollecting) {
  953. this.myStocksTcpDataCache.isCollecting = true
  954. this.myStocksTcpDataCache.expectedCount = parsedMessage.count
  955. this.myStocksTcpDataCache.collectedData = {}
  956. this.myStocksTcpDataCache.timestamp = parsedMessage.timestamp
  957. this.myStocksTcpDataCache.type = parsedMessage.type
  958. console.log('我的自选:开始收集数据片段,期望总数:', parsedMessage.count)
  959. }
  960. // 合并新数据到缓存中
  961. if (parsedMessage.data) {
  962. Object.assign(this.myStocksTcpDataCache.collectedData, parsedMessage.data)
  963. console.log('我的自选:数据片段已合并,当前已收集:', Object.keys(this.myStocksTcpDataCache.collectedData).length, '个对象')
  964. }
  965. },
  966. // 检查我的自选缓存数据是否完整
  967. isMyStocksCacheDataComplete() {
  968. const collectedCount = Object.keys(this.myStocksTcpDataCache.collectedData).length
  969. const expectedCount = this.myStocksTcpDataCache.expectedCount
  970. console.log(`我的自选缓存数据检查: 已收集${collectedCount}个,期望${expectedCount}`)
  971. return collectedCount === expectedCount && collectedCount > 0
  972. },
  973. // 获取我的自选完整的缓存数据并清空缓存
  974. getCompleteMyStocksDataFromCache() {
  975. const completeData = {
  976. count: this.myStocksTcpDataCache.expectedCount,
  977. data: { ...this.myStocksTcpDataCache.collectedData },
  978. stock_count: this.myStocksTcpDataCache.expectedCount,
  979. timestamp: this.myStocksTcpDataCache.timestamp,
  980. type: this.myStocksTcpDataCache.type
  981. }
  982. // 清空缓存
  983. this.myStocksTcpDataCache.isCollecting = false
  984. this.myStocksTcpDataCache.expectedCount = 0
  985. this.myStocksTcpDataCache.collectedData = {}
  986. this.myStocksTcpDataCache.timestamp = ''
  987. this.myStocksTcpDataCache.type = ''
  988. console.log('我的自选:获取完整数据并清空缓存,数据对象数:', Object.keys(completeData.data).length)
  989. return completeData
  990. },
  991. // 处理我的自选完整的股票数据
  992. processCompleteMyStocksData(completeData) {
  993. console.log("我的自选:开始更新我的自选TCP股票数据存储")
  994. // 更新我的自选TCP股票数据存储
  995. this.myStocksTcpData = {
  996. count: completeData.count || 0,
  997. data: completeData.data || {},
  998. stock_count: completeData.stock_count || 0,
  999. timestamp: completeData.timestamp || '',
  1000. type: completeData.type || ''
  1001. }
  1002. // 获取所有股票的数据用于显示
  1003. const stockCodes = Object.keys(completeData.data)
  1004. const newMyStocksInfoList = []
  1005. // 只处理前3条股票数据
  1006. const maxStocks = Math.min(3, stockCodes.length)
  1007. for (let i = 0; i < maxStocks; i++) {
  1008. const stockCode = stockCodes[i]
  1009. // 检查数据结构
  1010. if (completeData.data[stockCode] && Array.isArray(completeData.data[stockCode]) && completeData.data[stockCode].length > 0) {
  1011. const stockData = completeData.data[stockCode][0] // 取第一条数据
  1012. console.log('遍历的数据:', stockCode, stockData)
  1013. if (stockData && stockData.current_price !== undefined) {
  1014. // 直接使用返回的数据,不重新计算
  1015. newMyStocksInfoList.push({
  1016. stock_code: stockCode,
  1017. stock_name: stockData.stock_name || '未知股票',
  1018. current_price: parseFloat(stockData.current_price).toFixed(2),
  1019. change: stockData.change || '0.00%',
  1020. change_value: stockData.change_value || 0,
  1021. change_percent: parseFloat(stockData.change) || 0
  1022. })
  1023. }
  1024. }
  1025. }
  1026. // 更新我的自选股票信息列表
  1027. if (newMyStocksInfoList.length > 0) {
  1028. this.myStocksInfoList = newMyStocksInfoList
  1029. console.log('我的自选:股票数据更新成功,共', newMyStocksInfoList.length, '个股票:', this.myStocksInfoList)
  1030. }
  1031. },
  1032. // 发送TCP消息
  1033. sendTcpMessage() {
  1034. // 构造要发送的消息对象
  1035. const messageData =
  1036. // {
  1037. // command: "real_time",
  1038. // stock_code: "SH.000001"
  1039. // }
  1040. // {"command": "stock_list"}
  1041. // {"command": "batch_real_time", "stock_codes": ["SH.000001"]}
  1042. {"command": "batch_real_time", "stock_codes": this.currentStockCodes}
  1043. // 发送消息
  1044. const success = tcpConnection.send(messageData)
  1045. if (success) {
  1046. // console.log('home发送TCP消息:', messageData)
  1047. uni.showToast({
  1048. title: '服务器连接成功',
  1049. icon: 'success',
  1050. duration: 1500
  1051. })
  1052. }
  1053. },
  1054. // 发送我的自选TCP消息
  1055. sendMyStocksTcpMessage() {
  1056. // 构造要发送的消息对象 - 我的自选股票数据请求
  1057. const messageData = {"command": "batch_real_time", "stock_codes": this.currentStockCodes}
  1058. // 发送消息到channel 2(我的自选TCP连接)
  1059. const success = tcpConnection.send(messageData, { channel: '2' })
  1060. if (success) {
  1061. console.log('我的自选:发送TCP消息成功:', messageData)
  1062. uni.showToast({
  1063. title: '我的自选数据请求已发送',
  1064. icon: 'success',
  1065. duration: 1500
  1066. })
  1067. } else {
  1068. console.error('我的自选:发送TCP消息失败')
  1069. uni.showToast({
  1070. title: '我的自选连接失败',
  1071. icon: 'error',
  1072. duration: 1500
  1073. })
  1074. }
  1075. },
  1076. // 清空消息记录
  1077. clearTcpMessages() {
  1078. this.tcpMessages = []
  1079. uni.showToast({
  1080. title: '消息记录已清空',
  1081. icon: 'success',
  1082. duration: 1500
  1083. })
  1084. },
  1085. // 获取TCP连接状态
  1086. getTcpStatus() {
  1087. const status = tcpConnection.getConnectionStatus()
  1088. uni.showModal({
  1089. title: 'TCP连接状态',
  1090. content: `当前状态: ${status ? '已连接' : '未连接'}\n消息数量: ${this.tcpMessages.length}`,
  1091. showCancel: false
  1092. })
  1093. },
  1094. // 验证数据完整性(检查count值与data对象个数是否相等)
  1095. validateDataIntegrity(parsedMessage) {
  1096. if (!parsedMessage.count || !parsedMessage.data) {
  1097. return false
  1098. }
  1099. const dataObjectCount = Object.keys(parsedMessage.data).length
  1100. const expectedCount = parsedMessage.count
  1101. // console.log(`数据完整性验证: 期望${expectedCount}个对象,实际${dataObjectCount}个对象`)
  1102. return dataObjectCount === expectedCount
  1103. },
  1104. // 检查数据状态(完整数据、前半部分数据、后半部分数据)
  1105. getDataStatus(message) {
  1106. if (typeof message !== 'string') {
  1107. return 'invalid'
  1108. }
  1109. const trimmedMessage = message.trim()
  1110. const startsWithBrace = trimmedMessage.startsWith('{')
  1111. const endsWithBrace = trimmedMessage.endsWith('}')
  1112. if (startsWithBrace && endsWithBrace) {
  1113. // 以{开头,以}结尾 - 完整数据
  1114. // console.log('检测到完整数据格式')
  1115. return 'complete'
  1116. } else if (startsWithBrace && !endsWithBrace) {
  1117. // 以{开头,不以}结尾 - 前半部分数据
  1118. // console.log('检测到前半部分数据')
  1119. return 'first_part'
  1120. } else if (!startsWithBrace && endsWithBrace) {
  1121. // 不以{开头,以}结尾 - 后半部分数据
  1122. // console.log('检测到后半部分数据')
  1123. return 'second_part'
  1124. } else {
  1125. // 其他情况 - 无效数据
  1126. // console.log('检测到无效数据格式')
  1127. return 'invalid'
  1128. }
  1129. },
  1130. // 缓存前半部分数据
  1131. cacheFirstPartData(message) {
  1132. this.tcpDataCache.firstPartData = message.trim()
  1133. this.tcpDataCache.isWaitingSecondPart = true
  1134. // console.log('已缓存前半部分数据,长度:', this.tcpDataCache.firstPartData.length)
  1135. },
  1136. // 拼接前后两部分数据
  1137. concatenateDataParts(secondPartMessage) {
  1138. const completeMessage = this.tcpDataCache.firstPartData + secondPartMessage.trim()
  1139. // console.log('数据拼接完成,完整数据长度:', completeMessage.length)
  1140. // 清空缓存
  1141. this.clearStringFragmentCache()
  1142. return completeMessage
  1143. },
  1144. // 清空字符串片段缓存
  1145. clearStringFragmentCache() {
  1146. this.tcpDataCache.firstPartData = ''
  1147. this.tcpDataCache.isWaitingSecondPart = false
  1148. // console.log('字符串片段缓存已清空')
  1149. },
  1150. // 合并数据到缓存中
  1151. mergeDataToCache(parsedMessage) {
  1152. // 如果是第一次收集数据,初始化缓存
  1153. if (!this.tcpDataCache.isCollecting) {
  1154. this.tcpDataCache.isCollecting = true
  1155. this.tcpDataCache.expectedCount = parsedMessage.count
  1156. this.tcpDataCache.collectedData = {}
  1157. this.tcpDataCache.timestamp = parsedMessage.timestamp
  1158. this.tcpDataCache.type = parsedMessage.type
  1159. // console.log('开始收集数据片段,期望总数:', parsedMessage.count)
  1160. }
  1161. // 合并新数据到缓存中
  1162. if (parsedMessage.data) {
  1163. Object.assign(this.tcpDataCache.collectedData, parsedMessage.data)
  1164. // console.log('数据片段已合并,当前已收集:', Object.keys(this.tcpDataCache.collectedData).length, '个对象')
  1165. }
  1166. },
  1167. // 检查缓存数据是否完整
  1168. isCacheDataComplete() {
  1169. const collectedCount = Object.keys(this.tcpDataCache.collectedData).length
  1170. const expectedCount = this.tcpDataCache.expectedCount
  1171. // console.log(`缓存数据检查: 已收集${collectedCount}个,期望${expectedCount}个`)
  1172. return collectedCount === expectedCount && collectedCount > 0
  1173. },
  1174. // 获取完整的缓存数据并清空缓存
  1175. getCompleteDataFromCache() {
  1176. const completeData = {
  1177. count: this.tcpDataCache.expectedCount,
  1178. data: { ...this.tcpDataCache.collectedData },
  1179. stock_count: this.tcpDataCache.expectedCount,
  1180. timestamp: this.tcpDataCache.timestamp,
  1181. type: this.tcpDataCache.type
  1182. }
  1183. // 清空缓存
  1184. this.tcpDataCache.isCollecting = false
  1185. this.tcpDataCache.expectedCount = 0
  1186. this.tcpDataCache.collectedData = {}
  1187. this.tcpDataCache.timestamp = ''
  1188. this.tcpDataCache.type = ''
  1189. // console.log('获取完整数据并清空缓存,数据对象数:', Object.keys(completeData.data).length)
  1190. return completeData
  1191. },
  1192. // 解析TCP股票数据
  1193. parseStockData(message) {
  1194. try {
  1195. // console.log('进入parseStockData, message类型:', typeof message, '长度:', message.length)
  1196. // 第一步:检查数据状态(完整、前半部分、后半部分)
  1197. const dataStatus = this.getDataStatus(message)
  1198. let completeMessage = ''
  1199. switch (dataStatus) {
  1200. case 'complete':
  1201. // 完整数据,直接处理
  1202. // console.log('检测到完整数据,直接处理')
  1203. completeMessage = message
  1204. break
  1205. case 'first_part':
  1206. // 前半部分数据,缓存并等待后半部分
  1207. // console.log('检测到前半部分数据,开始缓存')
  1208. this.cacheFirstPartData(message)
  1209. return // 等待后半部分数据
  1210. case 'second_part':
  1211. // 后半部分数据,检查是否有缓存的前半部分
  1212. if (this.tcpDataCache.isWaitingSecondPart) {
  1213. // console.log('检测到后半部分数据,开始拼接')
  1214. completeMessage = this.concatenateDataParts(message)
  1215. } else {
  1216. // console.log('收到后半部分数据,但没有缓存的前半部分,跳过处理')
  1217. return
  1218. }
  1219. break
  1220. case 'invalid':
  1221. default:
  1222. // console.log('数据格式无效,跳过处理')
  1223. return
  1224. }
  1225. // 第二步:解析完整的JSON数据
  1226. let parsedMessage
  1227. try {
  1228. // console.log('开始解析完整JSON数据,长度:', completeMessage.length)
  1229. parsedMessage = JSON.parse(completeMessage)
  1230. // console.log('JSON解析成功,解析后类型:', typeof parsedMessage, parsedMessage)
  1231. } catch (parseError) {
  1232. // console.error('JSON解析失败:', parseError.message)
  1233. // 清空字符串片段缓存
  1234. this.clearStringFragmentCache()
  1235. return
  1236. }
  1237. // 第三步:检查是否是股票数据类型
  1238. if (!((parsedMessage.type === 'batch_data_chunk' || parsedMessage.type === 'batch_realtime_data') && parsedMessage.data)) {
  1239. // console.log('不是batch_data_chunk或batch_realtime_data类型的消息,跳过处理')
  1240. return
  1241. }
  1242. // console.log('开始处理股票数据')
  1243. // 第四步:验证数据完整性(对象级别的完整性检查)
  1244. // 注意:batch_data_chunk类型的数据不需要验证完整性,直接处理
  1245. if (parsedMessage.type === 'batch_data_chunk') {
  1246. // console.log('batch_data_chunk类型数据,跳过完整性验证,直接处理')
  1247. this.processCompleteStockData(parsedMessage)
  1248. } else {
  1249. const isDataComplete = this.validateDataIntegrity(parsedMessage)
  1250. if (isDataComplete) {
  1251. // 数据完整,直接处理
  1252. // console.log('对象级数据完整,直接处理')
  1253. this.processCompleteStockData(parsedMessage)
  1254. } else {
  1255. // 数据不完整,需要拼接(对象级别的拼接)
  1256. // console.log('对象级数据不完整,开始拼接处理')
  1257. // 将当前数据合并到缓存中
  1258. this.mergeDataToCache(parsedMessage)
  1259. // 检查缓存中的数据是否已经完整
  1260. if (this.isCacheDataComplete()) {
  1261. // console.log('缓存数据已完整,开始处理')
  1262. const completeData = this.getCompleteDataFromCache()
  1263. this.processCompleteStockData(completeData)
  1264. } else {
  1265. // console.log('缓存数据仍不完整,等待更多数据片段')
  1266. }
  1267. }
  1268. }
  1269. } catch (error) {
  1270. // console.error('解析TCP股票数据失败:', error.message)
  1271. // console.error('错误详情:', error)
  1272. // 发生错误时清空所有缓存
  1273. this.clearStringFragmentCache()
  1274. if (this.tcpDataCache.isCollecting) {
  1275. // console.log('发生错误,清空对象级数据缓存')
  1276. this.tcpDataCache.isCollecting = false
  1277. this.tcpDataCache.expectedCount = 0
  1278. this.tcpDataCache.collectedData = {}
  1279. this.tcpDataCache.timestamp = ''
  1280. this.tcpDataCache.type = ''
  1281. }
  1282. }
  1283. },
  1284. // 处理完整的股票数据
  1285. processCompleteStockData(completeData) {
  1286. // console.log("开始更新TCP股票数据存储")
  1287. // 更新TCP股票数据存储
  1288. this.tcpStockData = {
  1289. count: completeData.count || 0,
  1290. data: completeData.data || {},
  1291. stock_count: completeData.stock_count || 0,
  1292. timestamp: completeData.timestamp || '',
  1293. type: completeData.type || ''
  1294. }
  1295. // 获取所有股票的数据用于显示(最多3个)
  1296. const stockCodes = Object.keys(completeData.data)
  1297. const newStockInfoList = []
  1298. // 处理最多3个股票数据
  1299. for (let i = 0; i < Math.min(stockCodes.length, 3); i++) {
  1300. const stockCode = stockCodes[i]
  1301. // 检查数据结构
  1302. if (completeData.data[stockCode] && Array.isArray(completeData.data[stockCode]) && completeData.data[stockCode].length > 0) {
  1303. const stockData = completeData.data[stockCode][0] // 取第一条数据
  1304. if (stockData && stockData.current_price !== undefined && stockData.pre_close !== undefined) {
  1305. // 计算涨跌幅
  1306. const changeValue = stockData.current_price - stockData.pre_close
  1307. const changePercent = ((changeValue / stockData.pre_close) * 100).toFixed(2)
  1308. const changeSign = changeValue >= 0 ? '+' : ''
  1309. // 添加到股票信息列表
  1310. newStockInfoList.push({
  1311. stock_name: stockData.stock_name || '未知股票',
  1312. current_price: stockData.current_price ? stockData.current_price.toFixed(2) : '0.00',
  1313. change: `${changeSign}${changePercent}%`,
  1314. change_value: changeValue,
  1315. change_percent: parseFloat(changePercent)
  1316. })
  1317. }
  1318. }
  1319. }
  1320. // 更新当前显示的股票信息列表
  1321. if (newStockInfoList.length > 0) {
  1322. this.currentStockInfoList = newStockInfoList
  1323. // console.log('股票数据更新成功,共', newStockInfoList.length, '个股票:', this.currentStockInfoList)
  1324. }
  1325. },
  1326. // 移除TCP监听器
  1327. removeTcpListeners() {
  1328. if (this.connectionListener) {
  1329. tcpConnection.removeConnectionListener(this.connectionListener)
  1330. this.connectionListener = null
  1331. // console.log('已移除TCP连接状态监听器')
  1332. }
  1333. if (this.messageListener) {
  1334. tcpConnection.removeMessageListener(this.messageListener)
  1335. this.messageListener = null
  1336. // console.log('已移除TCP消息监听器')
  1337. }
  1338. }
  1339. }
  1340. }
  1341. </script>
  1342. <style scoped>
  1343. .main {
  1344. display: flex;
  1345. flex-direction: column;
  1346. height: 100vh;
  1347. background-color: #ffffff;
  1348. }
  1349. .header {
  1350. display: flex;
  1351. justify-content: space-between;
  1352. align-items: center;
  1353. padding: 10px 15px;
  1354. background-color: #ffffff;
  1355. }
  1356. .title {
  1357. font-size: 22px;
  1358. font-weight: bold;
  1359. text-align: center;
  1360. flex: 1;
  1361. }
  1362. .headphone-icon, .notification-icon {
  1363. width: 40px;
  1364. display: flex;
  1365. align-items: center;
  1366. justify-content: center;
  1367. }
  1368. .header-icon-image {
  1369. width: 24px;
  1370. height: 24px;
  1371. object-fit: contain;
  1372. }
  1373. .content-container {
  1374. flex: 1;
  1375. padding: 10px;
  1376. width: 100%;
  1377. box-sizing: border-box;
  1378. overflow-x: hidden;
  1379. }
  1380. .section {
  1381. margin-bottom: 15px;
  1382. /* background-color: #f5f5f5; */
  1383. background-color: #ffffff;
  1384. border-radius: 8px;
  1385. padding: 15px;
  1386. }
  1387. .section-header {
  1388. display: flex;
  1389. justify-content: space-between;
  1390. align-items: center;
  1391. margin-bottom: 15px;
  1392. padding-bottom: 10px;
  1393. }
  1394. .section-title {
  1395. font-size: 18px;
  1396. font-weight: bold;
  1397. color: #000000;
  1398. }
  1399. .section-title-text{
  1400. font-size: 14px;
  1401. }
  1402. .text-gap{
  1403. height: 10px;
  1404. }
  1405. .more-btn {
  1406. font-size: 12px;
  1407. font-weight: bold;
  1408. color: #ffffff;
  1409. background-color: #000000;
  1410. padding: 4px 8px;
  1411. border-radius: 4px;
  1412. }
  1413. /* 市场概览样式 */
  1414. .market-header {
  1415. display: flex;
  1416. justify-content: space-between;
  1417. align-items: center;
  1418. padding: 10px 15px;
  1419. background-color: #ffffff;
  1420. margin-bottom: 10px;
  1421. }
  1422. .market-content {
  1423. background-color: #f5f5f5;
  1424. border-radius: 8px;
  1425. padding: 15px;
  1426. margin: 0 15px;
  1427. }
  1428. .market-image {
  1429. margin-bottom: 15px;
  1430. display: flex;
  1431. justify-content: center;
  1432. }
  1433. .overview-image {
  1434. width: 100%;
  1435. border-radius: 8px;
  1436. }
  1437. .market-data {
  1438. display: flex;
  1439. flex-direction: column;
  1440. gap: 10px;
  1441. }
  1442. /* 间隔样式 */
  1443. .section-gap {
  1444. height: 20px;
  1445. }
  1446. .market-item {
  1447. display: flex;
  1448. justify-content: space-between;
  1449. padding: 8px 0;
  1450. border-bottom: 1px solid #f0f0f0;
  1451. }
  1452. .down {
  1453. color: #ff4d4f;
  1454. }
  1455. .up {
  1456. color: #52c41a;
  1457. }
  1458. /* DeepMate样式 */
  1459. .deepmate-container {
  1460. background-color: #ffe6e6;
  1461. border-radius: 10px;
  1462. padding: 15px;
  1463. margin: 0 15px;
  1464. }
  1465. .deepmate-header {
  1466. margin-bottom: 10px;
  1467. }
  1468. .title-container {
  1469. display: flex;
  1470. align-items: center;
  1471. justify-content: space-between;
  1472. width: 100%;
  1473. }
  1474. .title-left {
  1475. width: 50%;
  1476. }
  1477. .title-right {
  1478. width: 50%;
  1479. display: flex;
  1480. justify-content: flex-end;
  1481. }
  1482. .deepmate-title {
  1483. font-size: 18px;
  1484. font-weight: bold;
  1485. color: #ff4d4f;
  1486. }
  1487. .deepmate-icon {
  1488. width: 60px;
  1489. height: 60px;
  1490. margin-left: 0;
  1491. }
  1492. .deepmate-subtitle {
  1493. font-size: 12px;
  1494. color: #666;
  1495. margin-left: 5px;
  1496. }
  1497. .deepmate-hotspots {
  1498. margin: 10px 0;
  1499. }
  1500. .hotspot-item {
  1501. background-color: #f5f5f5;
  1502. padding: 8px 12px;
  1503. border-radius: 6px;
  1504. margin-bottom: 8px;
  1505. }
  1506. .hotspot-item text {
  1507. font-size: 14px;
  1508. color: #333;
  1509. }
  1510. .deepmate-action {
  1511. display: flex;
  1512. justify-content: center;
  1513. align-items: center;
  1514. background-color: #ffffff;
  1515. border-radius: 20px;
  1516. padding: 10px;
  1517. margin-top: 10px;
  1518. }
  1519. /* 欢迎部分样式 */
  1520. .welcome-section {
  1521. margin-bottom: 15px;
  1522. padding: 0;
  1523. }
  1524. .welcome-swiper {
  1525. width: 100%;
  1526. height: 110px;
  1527. border-radius: 0;
  1528. overflow: hidden;
  1529. }
  1530. .deepmate-section {
  1531. padding: 0;
  1532. }
  1533. .swiper-image {
  1534. width: 100%;
  1535. height: 100%;
  1536. border-radius: 8px;
  1537. object-fit: contain;
  1538. }
  1539. /* 深度探索样式 */
  1540. .deep-exploration {
  1541. margin-top: 15px;
  1542. padding: 0; /* 移除内边距,让子容器自己控制 */
  1543. }
  1544. .section-header-container {
  1545. margin-bottom: 10px;
  1546. }
  1547. .section-header {
  1548. display: flex;
  1549. justify-content: space-between;
  1550. align-items: center;
  1551. padding: 10px 15px;
  1552. background-color: #ffffff;
  1553. }
  1554. .header-left {
  1555. display: flex;
  1556. align-items: center;
  1557. }
  1558. .header-right {
  1559. display: flex;
  1560. align-items: center;
  1561. }
  1562. .section-title {
  1563. font-size: 16px;
  1564. font-weight: bold;
  1565. color: #333;
  1566. }
  1567. .more-btn {
  1568. font-size: 12px;
  1569. color: #ffffff;
  1570. }
  1571. .exploration-container {
  1572. border-radius: 8px;
  1573. overflow: hidden;
  1574. }
  1575. .exploration-content {
  1576. display: flex;
  1577. justify-content: space-between;
  1578. padding: 15px;
  1579. background-color: #f5f5f5;
  1580. border-radius: 8px;
  1581. }
  1582. .exploration-item {
  1583. display: flex;
  1584. flex-direction: column;
  1585. align-items: center;
  1586. width: 22%;
  1587. background-color: #ffffff;
  1588. border-radius: 8px;
  1589. padding: 10px 0;
  1590. }
  1591. .exploration-icon {
  1592. width: 50px;
  1593. height: 50px;
  1594. margin-bottom: 8px;
  1595. }
  1596. .exploration-text {
  1597. font-size: 12px;
  1598. color: #333;
  1599. }
  1600. .icon-text {
  1601. font-size: 12px;
  1602. }
  1603. /* 我的自选样式 */
  1604. .my-selection {
  1605. padding: 0; /* 移除内边距,让子容器自己控制 */
  1606. }
  1607. .stock-container {
  1608. border-radius: 8px;
  1609. overflow: hidden;
  1610. background-color: #f5f5f5;
  1611. padding: 15px;
  1612. box-sizing: border-box;
  1613. }
  1614. .stock-list {
  1615. display: flex;
  1616. flex-direction: row;
  1617. justify-content: center;
  1618. background-color: #f8f8f8;
  1619. border-radius: 8px;
  1620. padding: 15px;
  1621. gap: 10px; /* 添加卡片之间的间距 */
  1622. }
  1623. .stock-item {
  1624. display: flex;
  1625. flex-direction: column;
  1626. justify-content: space-between;
  1627. padding: 3px;
  1628. background-color: #ffffff;
  1629. border-radius: 8px;
  1630. width: 30%;
  1631. box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  1632. will-change: transform;
  1633. transform: translateZ(0);
  1634. }
  1635. .stock-info {
  1636. display: flex;
  1637. flex-direction: column;
  1638. align-items: center;
  1639. margin-bottom: 5px;
  1640. }
  1641. .stock-chart {
  1642. display: flex;
  1643. align-items: center;
  1644. justify-content: center;
  1645. }
  1646. .name-container {
  1647. display: flex;
  1648. align-items: center;
  1649. gap: 5px;
  1650. }
  1651. .stock-name {
  1652. font-size: 12px;
  1653. font-weight: bold;
  1654. color: #333;
  1655. }
  1656. .stock-code-label {
  1657. font-size: 12px;
  1658. color: #666;
  1659. background-color: #f5f5f5;
  1660. padding: 0 4px;
  1661. border-radius: 3px;
  1662. }
  1663. .stock-price {
  1664. font-size: 12px;
  1665. color: #666;
  1666. }
  1667. .price-container {
  1668. display: flex;
  1669. align-items: center;
  1670. gap: 5px;
  1671. }
  1672. .stock-change {
  1673. font-size: 12px;
  1674. }
  1675. .stock-up {
  1676. color: #4cd964;
  1677. }
  1678. .stock-down {
  1679. color: #ff3b30;
  1680. }
  1681. .chart-image {
  1682. width: 100px;
  1683. height: 40px;
  1684. }
  1685. /* 市场看点样式 */
  1686. .highlights-title-container {
  1687. background-color: #ffffff;
  1688. margin-bottom: 10px;
  1689. }
  1690. .highlights-image-container {
  1691. background-color: #f5f5f5;
  1692. border-radius: 8px;
  1693. padding: 10px;
  1694. margin-bottom: 15px;
  1695. }
  1696. .highlights-image {
  1697. width: 100%;
  1698. height: 150px;
  1699. border-radius: 4px;
  1700. }
  1701. /* 机构动向简报样式 */
  1702. .institutional-reports {
  1703. margin-top: 15px;
  1704. background-color: #f8f8f8;
  1705. border-radius: 8px;
  1706. padding: 10px;
  1707. }
  1708. .section-title-container {
  1709. position: relative;
  1710. padding-left: 10px;
  1711. margin-bottom: 5px;
  1712. }
  1713. .section-title-container:before {
  1714. content: "";
  1715. position: absolute;
  1716. left: 0;
  1717. top: 0;
  1718. bottom: 0;
  1719. width: 4px;
  1720. background-color: #ff4d4f;
  1721. border-radius: 2px;
  1722. }
  1723. .report-item {
  1724. background-color: #ffffff;
  1725. border-radius: 8px;
  1726. padding: 10px;
  1727. margin-bottom: 8px;
  1728. }
  1729. .report-stock {
  1730. font-size: 14px;
  1731. font-weight: bold;
  1732. color: #e74c3c;
  1733. margin-bottom: 5px;
  1734. }
  1735. .report-status {
  1736. font-size: 12px;
  1737. color: #333;
  1738. }
  1739. .view-more {
  1740. text-align: center;
  1741. color: #1890ff;
  1742. font-size: 12px;
  1743. padding: 5px;
  1744. }
  1745. .disclaimer {
  1746. text-align: center;
  1747. padding: 8px 10px;
  1748. margin-top: 5px;
  1749. border-radius: 4px;
  1750. }
  1751. .disclaimer-text {
  1752. font-size: 11px;
  1753. color: grey;
  1754. line-height: 1.4;
  1755. }
  1756. /* 底部空间 */
  1757. .bottom-space {
  1758. height: 60px;
  1759. }
  1760. /* 底部导航 */
  1761. .static-footer {
  1762. position: fixed;
  1763. bottom: 0;
  1764. width: 100%;
  1765. }
  1766. /* TCP测试区域样式 */
  1767. .tcp-test-section {
  1768. border: 1px solid #e0e0e0;
  1769. background-color: #f9f9f9;
  1770. }
  1771. .tcp-status {
  1772. padding: 4px 12px;
  1773. border-radius: 12px;
  1774. font-size: 12px;
  1775. }
  1776. .tcp-status.connected {
  1777. background-color: #e8f5e8;
  1778. color: #4caf50;
  1779. border: 1px solid #4caf50;
  1780. }
  1781. .tcp-status.disconnected {
  1782. background-color: #ffeaea;
  1783. color: #f44336;
  1784. border: 1px solid #f44336;
  1785. }
  1786. .status-text {
  1787. font-size: 12px;
  1788. font-weight: bold;
  1789. }
  1790. .tcp-controls {
  1791. display: flex;
  1792. flex-wrap: wrap;
  1793. gap: 8px;
  1794. margin-bottom: 15px;
  1795. }
  1796. .tcp-btn {
  1797. flex: 1;
  1798. min-width: 80px;
  1799. height: 36px;
  1800. border-radius: 6px;
  1801. font-size: 12px;
  1802. border: none;
  1803. color: white;
  1804. font-weight: bold;
  1805. }
  1806. .connect-btn {
  1807. background-color: #4caf50;
  1808. }
  1809. .connect-btn:disabled {
  1810. background-color: #cccccc;
  1811. }
  1812. .disconnect-btn {
  1813. background-color: #f44336;
  1814. }
  1815. .disconnect-btn:disabled {
  1816. background-color: #cccccc;
  1817. }
  1818. .send-btn {
  1819. background-color: #2196f3;
  1820. }
  1821. .send-btn:disabled {
  1822. background-color: #cccccc;
  1823. }
  1824. .status-btn {
  1825. background-color: #ff9800;
  1826. }
  1827. .tcp-messages {
  1828. margin-top: 15px;
  1829. border-top: 1px solid #e0e0e0;
  1830. padding-top: 15px;
  1831. }
  1832. .messages-header {
  1833. display: flex;
  1834. justify-content: space-between;
  1835. align-items: center;
  1836. margin-bottom: 10px;
  1837. }
  1838. .messages-title {
  1839. font-size: 14px;
  1840. font-weight: bold;
  1841. color: #333;
  1842. }
  1843. .clear-btn {
  1844. padding: 4px 8px;
  1845. background-color: #f44336;
  1846. color: white;
  1847. border: none;
  1848. border-radius: 4px;
  1849. font-size: 10px;
  1850. }
  1851. .messages-list {
  1852. max-height: 200px;
  1853. border: 1px solid #e0e0e0;
  1854. border-radius: 6px;
  1855. padding: 8px;
  1856. background-color: white;
  1857. }
  1858. .message-item {
  1859. margin-bottom: 8px;
  1860. padding: 8px;
  1861. border-radius: 6px;
  1862. border-left: 3px solid #ccc;
  1863. }
  1864. .message-item.sent {
  1865. background-color: #e3f2fd;
  1866. border-left-color: #2196f3;
  1867. }
  1868. .message-item.received {
  1869. background-color: #f1f8e9;
  1870. border-left-color: #4caf50;
  1871. }
  1872. .message-info {
  1873. display: flex;
  1874. justify-content: space-between;
  1875. margin-bottom: 4px;
  1876. }
  1877. .message-direction {
  1878. font-size: 10px;
  1879. font-weight: bold;
  1880. color: #666;
  1881. }
  1882. .message-time {
  1883. font-size: 10px;
  1884. color: #999;
  1885. }
  1886. .message-content {
  1887. font-size: 12px;
  1888. color: #333;
  1889. word-break: break-all;
  1890. }
  1891. /* 我的自选TCP控制样式 */
  1892. .my-stocks-tcp-control {
  1893. display: flex;
  1894. align-items: center;
  1895. justify-content: space-between;
  1896. margin-top: 8px;
  1897. padding: 8px 12px;
  1898. background-color: #f8f9fa;
  1899. border-radius: 8px;
  1900. border: 1px solid #e9ecef;
  1901. }
  1902. .tcp-buttons {
  1903. display: flex;
  1904. gap: 6px;
  1905. }
  1906. .my-stocks-tcp-control .tcp-btn {
  1907. flex: none;
  1908. min-width: 50px;
  1909. height: 28px;
  1910. border-radius: 4px;
  1911. font-size: 11px;
  1912. border: none;
  1913. color: white;
  1914. font-weight: bold;
  1915. }
  1916. </style>