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.

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