Browse Source

Merge branch 'milestone-20251031-简版功能开发' of http://39.101.133.168:8807/qimaohong/deepChartVueApp into wangyi/feature-20251026183100-deepmate王毅

lihuilin/feature-20251024095243-我的
wangyi 4 weeks ago
parent
commit
6612c67eaf
  1. 15
      api/setting/share.js
  2. 228
      api/tcpConnection.js
  3. 3
      components/IndexCard.vue
  4. 8
      components/MarketOverview.vue
  5. 190
      components/SharePopup.vue
  6. 9
      manifest.json
  7. 30
      pages.json
  8. 55
      pages/analysisInstitutionalTrends/analysisInstitutionalTrends.vue
  9. 147
      pages/customStockList/customStockList.vue
  10. 57
      pages/home/home.vue
  11. 307
      pages/marketSituation/globalIndex.vue
  12. 159
      pages/marketSituation/marketCondition.vue
  13. 340
      pages/marketSituation/marketDetail.vue
  14. 290
      pages/marketSituation/marketOverview.vue
  15. 37
      pages/morningMarketAnalysis/morningMarketAnalysis.vue
  16. 394
      pages/setting/share.vue
  17. BIN
      static/my/share/KakaoTalk.png
  18. BIN
      static/my/share/Line.png
  19. BIN
      static/my/share/WeChat.png
  20. BIN
      static/my/share/WhatsApp.png
  21. BIN
      static/my/share/share.png
  22. BIN
      static/my/share/success.png
  23. 55
      stores/modules/marketSituation.js
  24. 5
      utils/http.js

15
api/setting/share.js

@ -0,0 +1,15 @@
import { http } from '../../utils/http'
/**
* 分享接口获取dccode
* @param data
* @returns {*}
*/
export const Share = (data) => {
return http({
method: 'POST',
url: '/api/my/share',
data: data,
})
}

228
api/tcpConnection.js

@ -21,33 +21,33 @@ const TCP_CONFIG = {
* TCP连接管理类
*/
class TCPConnection {
constructor() {
this.channelConnections = new Map(); // 存储每个channel的连接状态
this.connectionCallbacks = [];
this.messageCallbacks = [];
}
constructor() {
this.channelConnections = new Map(); // 存储每个channel的连接状态
this.connectionCallbacks = [];
this.messageCallbacks = [];
}
/**
* TCP初始化连接
* @param {Object} config - 连接配置 {ip, port, channel, charsetname}
* @param {Function} callback - 连接状态回调函数
*/
connect(config = {}, callback = null) {
const channel = config.channel || TCP_CONFIG.channel;
/**
* TCP初始化连接
* @param {Object} config - 连接配置 {ip, port, channel, charsetname}
* @param {Function} callback - 连接状态回调函数
*/
connect(config = {}, callback = null) {
const channel = config.channel || TCP_CONFIG.channel;
// 如果该channel已经连接,先断开现有连接
if (this.channelConnections.get(channel)) {
console.log(`检测到channel ${channel}现有TCP连接,先断开...`);
this.disconnect(config);
// 等待断开完成后再连接
setTimeout(() => {
this._performConnect(config, callback);
}, 300);
} else {
// 直接连接
this._performConnect(config, callback);
}
// 如果该channel已经连接,先断开现有连接
if (this.channelConnections.get(channel)) {
console.log(`检测到channel ${channel}现有TCP连接,先断开...`);
this.disconnect(config);
// 等待断开完成后再连接
setTimeout(() => {
this._performConnect(config, callback);
}, 300);
} else {
// 直接连接
this._performConnect(config, callback);
}
}
/**
* 执行TCP连接
@ -66,33 +66,31 @@ class TCPConnection {
connectionConfig.charsetname = config.charsetname || TCP_CONFIG.charsetname;
}
console.log('开始建立TCP连接:', connectionConfig);
TCPSocket.connect(
connectionConfig,
result => {
/**
* status : 0 连接成功
* status : 1 断开连接
* receivedMsg : 服务器返回字符串(普通的字符串交互)
* receivedHexMsg : 服务器返回字节数组(单片机智能家居等硬件数据交互)
*/
if (result.status == '0') {
// TCP连接成功
this.channelConnections.set(connectionConfig.channel, true);
console.log(`TCP连接成功 - Channel ${connectionConfig.channel}`);
this._notifyConnectionCallbacks('connected', result, connectionConfig.channel);
} else if (result.status == '1') {
// TCP断开连接
this.channelConnections.set(connectionConfig.channel, false);
console.log(`TCP断开连接 - Channel ${connectionConfig.channel}`);
this._notifyConnectionCallbacks('disconnected', result, connectionConfig.channel);
}
console.log("开始建立TCP连接:", connectionConfig);
TCPSocket.connect(connectionConfig, (result) => {
/**
* status : 0 连接成功
* status : 1 断开连接
* receivedMsg : 服务器返回字符串(普通的字符串交互)
* receivedHexMsg : 服务器返回字节数组(单片机智能家居等硬件数据交互)
*/
if (result.status == "0") {
// TCP连接成功
this.channelConnections.set(connectionConfig.channel, true);
console.log(`TCP连接成功 - Channel ${connectionConfig.channel}`);
this._notifyConnectionCallbacks("connected", result, connectionConfig.channel);
} else if (result.status == "1") {
// TCP断开连接
this.channelConnections.set(connectionConfig.channel, false);
console.log(`TCP断开连接 - Channel ${connectionConfig.channel}`);
this._notifyConnectionCallbacks("disconnected", result, connectionConfig.channel);
}
if (result.receivedMsg) {
// 服务器返回字符串
console.log('收到字符串消息:', result.receivedMsg);
this._notifyMessageCallbacks('string', result.receivedMsg, null, connectionConfig.channel);
}
if (result.receivedMsg) {
// 服务器返回字符串
console.log("收到字符串消息:", result.receivedMsg);
this._notifyMessageCallbacks("string", result.receivedMsg, null, connectionConfig.channel);
}
// if (result.receivedHexMsg) {
// // 硬件服务器返回16进制数据
@ -115,18 +113,18 @@ class TCPConnection {
});
}
/**
* TCP发送消息(普通的字符串交互)
* @param {String|Object} message - 要发送的消息如果是对象会自动转换为JSON字符串
* @param {Object} config - 发送配置 {channel, charsetname}
*/
send(message, config = {}) {
const channel = config.channel || '1';
/**
* TCP发送消息(普通的字符串交互)
* @param {String|Object} message - 要发送的消息如果是对象会自动转换为JSON字符串
* @param {Object} config - 发送配置 {channel, charsetname}
*/
send(message, config = {}) {
const channel = config.channel || "1";
if (!this.channelConnections.get(channel)) {
console.warn(`TCP Channel ${channel}未连接,无法发送消息`);
return false;
}
if (!this.channelConnections.get(channel)) {
console.warn(`TCP Channel ${channel}未连接,无法发送消息`);
return false;
}
// 如果message是对象,转换为JSON字符串
let messageStr = message;
@ -149,20 +147,20 @@ class TCPConnection {
return true;
}
/**
* TCP断开连接
* @param {Object} config - 断开配置 {channel}
*/
disconnect(config = {}) {
const channel = config.channel || TCP_CONFIG.channel;
const disconnectConfig = {
channel: channel
};
/**
* TCP断开连接
* @param {Object} config - 断开配置 {channel}
*/
disconnect(config = {}) {
const channel = config.channel || TCP_CONFIG.channel;
const disconnectConfig = {
channel: channel,
};
TCPSocket.disconnect(disconnectConfig);
this.channelConnections.set(channel, false);
console.log(`TCP连接已断开 - Channel ${channel}`, disconnectConfig);
}
TCPSocket.disconnect(disconnectConfig);
this.channelConnections.set(channel, false);
console.log(`TCP连接已断开 - Channel ${channel}`, disconnectConfig);
}
/**
* 添加连接状态监听器
@ -206,50 +204,50 @@ class TCPConnection {
}
}
/**
* 获取连接状态
* @param {String} channel - 要检查的channel如果不指定则返回所有channel的连接状态
* @returns {Boolean|Object} 连接状态
*/
getConnectionStatus(channel = null) {
if (channel) {
return this.channelConnections.get(channel) || false;
}
// 返回所有channel的连接状态
const allConnections = {};
for (const [ch, status] of this.channelConnections) {
allConnections[ch] = status;
}
return allConnections;
/**
* 获取连接状态
* @param {String} channel - 要检查的channel如果不指定则返回所有channel的连接状态
* @returns {Boolean|Object} 连接状态
*/
getConnectionStatus(channel = null) {
if (channel) {
return this.channelConnections.get(channel) || false;
}
/**
* 通知连接状态回调
* @private
*/
_notifyConnectionCallbacks(status, result, channel) {
this.connectionCallbacks.forEach(callback => {
try {
callback(status, result, channel);
} catch (error) {
console.error('连接状态回调执行错误:', error);
}
});
// 返回所有channel的连接状态
const allConnections = {};
for (const [ch, status] of this.channelConnections) {
allConnections[ch] = status;
}
return allConnections;
}
/**
* 通知消息回调
* @private
*/
_notifyMessageCallbacks(type, message, parsedArray = null, channel = null) {
this.messageCallbacks.forEach(callback => {
try {
callback(type, message, parsedArray, channel);
} catch (error) {
console.error('消息回调执行错误:', error);
}
});
}
/**
* 通知连接状态回调
* @private
*/
_notifyConnectionCallbacks(status, result, channel) {
this.connectionCallbacks.forEach((callback) => {
try {
callback(status, result, channel);
} catch (error) {
console.error("连接状态回调执行错误:", error);
}
});
}
/**
* 通知消息回调
* @private
*/
_notifyMessageCallbacks(type, message, parsedArray = null, channel = null) {
this.messageCallbacks.forEach((callback) => {
try {
callback(type, message, parsedArray, channel);
} catch (error) {
console.error("消息回调执行错误:", error);
}
});
}
}
// 创建TCP连接实例

3
components/IndexCard.vue

@ -64,7 +64,6 @@ const props = defineProps({
});
const getMarketFlag = (market) => {
console.log("market", market);
let imagePath;
if (market === "cn") {
@ -86,8 +85,6 @@ const getMarketFlag = (market) => {
} else {
imagePath = "/static/marketSituation-image/country-flag/global.png";
}
console.log("返回的图片路径:", imagePath);
return imagePath;
};

8
components/MarketOverview.vue

@ -47,7 +47,7 @@
<text class="analysis-dot blue"></text>
<text class="analysis-text">市场风险评级: 需警惕潜在风险</text>
</view>
<view class="analysis-item">
<view class="analysis-item" @click="goToMorningAnalysis">
<text class="analysis-dot green"></text>
<text class="analysis-text">早盘解析: 今日高开, 芯片稀土公共</text>
</view>
@ -142,6 +142,12 @@ export default {
}
},
methods: {
//
goToMorningAnalysis() {
uni.navigateTo({
url: '/pages/morningMarketAnalysis/morningMarketAnalysis'
})
},
showMarketSelector() {
//
this.showForexMarket = !this.showForexMarket;

190
components/SharePopup.vue

@ -0,0 +1,190 @@
<!--自定义分享弹窗 使用uni的更改-->
<template>
<view class="uni-popup-share">
<!-- <view class="uni-share-title">-->
<!-- <text class="uni-share-title-text">{{ shareTitleText }}</text>-->
<!-- </view>-->
<view class="uni-share-content">
<view class="uni-share-content-box">
<view class="uni-share-content-item" v-for="(item,index) in bottomData" :key="index"
@click.stop="select(item,index)">
<image class="uni-share-image" :src="item.icon" mode="aspectFill"></image>
<text class="uni-share-text">{{ item.text }}</text>
</view>
</view>
</view>
<view class="uni-share-button-box">
<button class="uni-share-button" @click="close">{{ cancelText }}</button>
</view>
</view>
</template>
<script>
import popup from '../uni_modules/uni-popup/components/uni-popup/popup.js'
// import popup from '../uni-popup/popup.js'
import {initVueI18n} from '@dcloudio/uni-i18n'
import messages from '../uni_modules/uni-popup/components/uni-popup/i18n/index.js'
const {t} = initVueI18n(messages)
export default {
name: 'SharePopup',
mixins: [popup],
emits: ['select'],
props: {
title: {
type: String,
default: ''
},
beforeClose: {
type: Boolean,
default: false
}
},
data() {
return {
bottomData: [{
text: 'WhatsApp',
icon: '/static/my/share/WhatsApp.png',
name: 'WhatsApp'
},
{
text: 'Line',
icon: '/static/my/share/Line.png',
name: 'Line'
},
{
text: 'KakaoTalk',
icon: '/static/my/share/KakaoTalk.png',
name: 'KakaoTalk'
},
{
text: 'WeChat',
icon: '/static/my/share/WeChat.png',
name: 'WeChat'
},
{
text: '复制链接',
icon: '/static/my/share/share.png',
name: '复制链接'
},
]
}
},
created() {
},
computed: {
cancelText() {
return t("uni-popup.cancel")
},
shareTitleText() {
return this.title || t("uni-popup.shareTitle")
}
},
methods: {
/**
* 选择内容
*/
select(item, index) {
this.$emit('select', {
item,
index
})
// this.close()
},
/**
* 关闭窗口
*/
close() {
if (this.beforeClose) return
this.popup.close()
}
}
}
</script>
<style lang="scss">
.uni-popup-share {
background-color: #fff;
border-top-left-radius: 11px;
border-top-right-radius: 11px;
}
.uni-share-title {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
justify-content: center;
height: 40px;
}
.uni-share-title-text {
font-size: 14px;
color: #666;
}
.uni-share-content {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: center;
padding-top: 10px;
}
.uni-share-content-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
flex-wrap: wrap;
width: 360px;
}
.uni-share-content-item {
width: 72px;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
padding: 10px 0;
align-items: center;
}
.uni-share-content-item:active {
background-color: #f5f5f5;
}
.uni-share-image {
width: 42px;
height: 42px;
}
.uni-share-text {
margin-top: 10px;
font-size: 14px;
color: #3B4144;
}
.uni-share-button-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
padding: 10px 15px;
}
.uni-share-button {
flex: 1;
border-radius: 50px;
color: #666;
font-size: 16px;
}
.uni-share-button::after {
border-radius: 50px;
}
</style>

9
manifest.json

@ -17,7 +17,8 @@
"delay" : 0
},
"modules" : {
"OAuth" : {}
"OAuth" : {},
"Share" : {}
},
/* */
"distribute" : {
@ -53,6 +54,12 @@
"google" : {
"clientid" : "135"
}
},
"share" : {
"weixin" : {
"appid" : "wx6143d111fc5c9ba3",
"UniversalLinks" : ""
}
}
}
},

30
pages.json

@ -88,6 +88,13 @@
}
},
{
"path" : "pages/morningMarketAnalysis/morningMarketAnalysis",
"style" :
{
"navigationBarTitleText" : "早盘解析"
}
},
{
"path": "pages/marketSituation/marketSituation",
"style": {
"navigationStyle": "custom",
@ -331,6 +338,29 @@
"titleNView": false,
"bounce": false
}
},
{
"path" : "pages/analysisInstitutionalTrends/analysisInstitutionalTrends",
"style" :
{
"navigationBarTitleText" : "机构动向解析 "
}
},
{
"path" : "pages/customStockList/customStockList",
"style" :
{
"navigationBarTitleText" : "我的自选",
"app-plus": {
"titleNView": false
},
"h5": {
"titleNView": false
},
"mp-weixin": {
"navigationStyle": "custom"
}
}
}
],

55
pages/analysisInstitutionalTrends/analysisInstitutionalTrends.vue

@ -0,0 +1,55 @@
<template>
<view class="container">
<view class="content">
<image
class="no-data-image"
src="https://d31zlh4on95l9h.cloudfront.net/images/f5a9bd32c81bc7cca47252b51357c12f.png"
mode="aspectFit"
></image>
<text class="no-data-text">暂无数据~</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
.container {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f5f5;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.no-data-image {
width: 200px;
height: 200px;
margin-bottom: 20px;
}
.no-data-text {
font-size: 16px;
color: #999999;
text-align: center;
}
</style>

147
pages/customStockList/customStockList.vue

@ -0,0 +1,147 @@
<!-- 自选股页面 -->
<template>
<view class="container">
<!-- 自定义导航栏 -->
<view class="custom-navbar">
<view class="navbar-content">
<view class="navbar-left">
<view class="back-btn" @click="goBack">
<text class="back-icon"></text>
</view>
</view>
<view class="navbar-center">
<text class="navbar-title">我的自选</text>
</view>
<view class="navbar-right">
<image
class="navbar-btn"
src="https://d31zlh4on95l9h.cloudfront.net/images/ba5c8a2eda065274e868bcd9b2d7d914.png"
@click="onFirstButtonClick"
mode="aspectFit"
></image>
<image
class="navbar-btn"
src="https://d31zlh4on95l9h.cloudfront.net/images/a4ae8952aeae90dac6d2b4c221c65fa9.png"
@click="onSecondButtonClick"
mode="aspectFit"
></image>
</view>
</view>
</view>
<!-- 页面内容 -->
<view class="page-content">
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
//
goBack() {
uni.navigateBack()
},
//
onFirstButtonClick() {
console.log('第一个按钮被点击')
//
},
//
onSecondButtonClick() {
console.log('第二个按钮被点击')
//
}
}
}
</script>
<style>
.container {
width: 100%;
height: 100vh;
background-color: #f5f5f5;
}
/* 自定义导航栏 */
.custom-navbar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 999;
background-color: #ffffff;
border-bottom: 1px solid #e5e5e5;
}
.navbar-content {
display: flex;
align-items: center;
justify-content: space-between;
height: 44px;
padding: 0 15px;
/* 适配状态栏高度 */
padding-top: var(--status-bar-height, 20px);
min-height: calc(44px + var(--status-bar-height, 20px));
}
.navbar-left {
flex: 0 0 auto;
display: flex;
align-items: center;
}
.back-btn {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
}
.back-icon {
font-size: 24px;
color: #333333;
font-weight: bold;
}
.navbar-center {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
.navbar-title {
font-size: 18px;
font-weight: 500;
color: #333333;
}
.navbar-right {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 10px;
}
.navbar-btn {
width: 24px;
height: 24px;
}
/* 页面内容 */
.page-content {
padding-top: calc(44px + var(--status-bar-height, 20px) + 1px);
min-height: calc(100vh - 44px - var(--status-bar-height, 20px) - 1px);
}
</style>

57
pages/home/home.vue

@ -81,7 +81,7 @@
<view class="section-header-container">
<view class="section-header">
<text class="section-title">我的自选</text>
<text class="more-btn">添加自选股</text>
<text class="more-btn" @click="goToMarketSituation">添加自选股</text>
</view>
<!-- 我的自选TCP连接状态和控制 -->
<!-- <view class="my-stocks-tcp-control">
@ -128,7 +128,7 @@
<view class="report-stock">{{report.stock}}</view>
<view class="report-status">{{report.status}}</view>
</view>
<view class="view-more">
<view class="view-more" @click="goToCustomStockList">
<text>查看更多 >></text>
</view>
</view>
@ -175,7 +175,7 @@
<view class="section-header highlights-title-container">
<text class="section-title">今日市场核心看点</text>
</view>
<view class="highlights-image-container">
<view class="highlights-image-container" @click="goToAnalysisInstitutionalTrends">
<image src="https://d31zlh4on95l9h.cloudfront.net/images/8d5365af968402a18cedb120c09460b0.png" mode="aspectFit" class="highlights-image"></image>
</view>
@ -373,21 +373,21 @@ export default {
uni.$on('visitorLoginSuccess', this.handleVisitorLoginSuccess)
// TCP
this.$nextTick(() => {
console.log('页面渲染完成,开始自动连接TCP服务器...')
//
setTimeout(() => {
// TCPchannel 1
console.log('连接今日市场概览TCP(channel 1)...')
this.connectTcp()
// TCPchannel 2
setTimeout(() => {
console.log('连接我的自选TCP(channel 2)...')
this.connectMyStocksTcp()
}, 500)
}, 1000)
})
// this.$nextTick(() => {
// console.log('TCP...')
// //
// setTimeout(() => {
// // TCPchannel 1
// console.log('TCPchannel 1...')
// this.connectTcp()
// // TCPchannel 2
// setTimeout(() => {
// console.log('TCPchannel 2...')
// this.connectMyStocksTcp()
// }, 500)
// }, 1000)
// })
},
//
@ -430,6 +430,27 @@ export default {
},
methods: {
//
goToCustomStockList() {
uni.navigateTo({
url: '/pages/customStockList/customStockList'
})
},
//
goToMarketSituation() {
uni.navigateTo({
url: '/pages/marketSituation/marketSituation'
})
},
//
goToAnalysisInstitutionalTrends() {
uni.navigateTo({
url: '/pages/analysisInstitutionalTrends/analysisInstitutionalTrends'
})
},
//
goToDeepExploration() {
uni.navigateTo({

307
pages/marketSituation/globalIndex.vue

@ -32,7 +32,7 @@
<!-- 内容区域 -->
<scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
<!-- 亚太-中华 -->
<view class="market-section" v-for="item in globalIndexArray" :key="item">
<view class="market-section" v-for="(item, parentIndex) in marketSituationStore.gloablCardData" :key="item">
<view class="market-header">
<text class="market-title">{{ item.ac }}</text>
<view class="market-more" @click="viewMore(item.ac)">
@ -41,7 +41,7 @@
</view>
</view>
<view class="cards-grid-three">
<view v-for="iitem in item.list" :key="iitem" class="card-item">
<view v-for="(iitem, index) in item.list" :key="iitem" class="card-item">
<IndexCard
:market="iitem.market"
:stockName="iitem.name"
@ -49,7 +49,7 @@
:changeAmount="iitem.changeAmount"
:changePercent="iitem.changePercent"
:isRising="iitem.isRising"
@click="viewIndexDetail(iitem)"
@click="viewIndexDetail(iitem, parentIndex, index)"
/>
</view>
</view>
@ -65,11 +65,12 @@
</template>
<script setup>
import { ref, onMounted, computed, nextTick, watch } from "vue";
import { ref, onMounted, onUnmounted, computed, nextTick, watch } from "vue";
import footerBar from "../../components/footerBar.vue";
import IndexCard from "../../components/IndexCard.vue";
import { getRegionalGroupAPI } from "../../api/marketSituation/marketSituation.js";
import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";
const marketSituationStore = useMarketSituationStore();
//
const iSMT = ref(0); //
const contentHeight = ref(0);
@ -259,7 +260,7 @@ const viewMore = (market) => {
};
//
const viewIndexDetail = (item) => {
const viewIndexDetail = (item, parentIndex, index) => {
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
@ -268,7 +269,7 @@ const viewIndexDetail = (item) => {
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}&parentIndex=${parentIndex}&index=${index}&from=globalIndex`,
});
};
@ -276,14 +277,306 @@ const getRegionalGroup = async () => {
try {
const result = await getRegionalGroupAPI();
globalIndexArray.value = result.data;
marketSituationStore.gloablCardData = result.data;
} catch (e) {
console.log("获取区域指数失败", e);
}
};
// TCP
import tcpConnection, { TCPConnection, TCP_CONFIG } from "@/api/tcpConnection.js";
const tcpConnected = ref(false);
const connectionListener = ref(null);
const messageListener = ref(null);
// TCP
const initTcpListeners = () => {
//
connectionListener.value = (status, result) => {
tcpConnected.value = status === "connected";
console.log("TCP连接状态变化:", status, tcpConnected.value);
//
//
if (status === "connected") {
sendTcpMessage("batch_real_time");
}
};
//
messageListener.value = (type, message, parsedArray) => {
const messageObj = {
type: type,
content: message,
parsedArray: parsedArray,
timestamp: new Date().toLocaleTimeString(),
direction: "received",
};
//
parseStockData(message);
};
//
tcpConnection.onConnectionChange(connectionListener.value);
tcpConnection.onMessage(messageListener.value);
};
// TCP
const connectTcp = () => {
console.log("开始连接TCP服务器...");
tcpConnection.connect();
};
// TCP
const disconnectTcp = () => {
console.log("断开TCP连接...");
tcpConnection.disconnect();
tcpConnected.value = false;
};
// TCP
const sendTcpMessage = (command) => {
let messageData;
let messageDataArray = [];
if (command == "batch_real_time") {
for (let i = 0; i < globalIndexArray.value.length; ++i) {
for (let j = 0; j < globalIndexArray.value[i].list.length; ++j) {
messageDataArray.push(globalIndexArray.value[i].list[j].code);
}
}
}
console.log(messageDataArray);
switch (command) {
//
case "real_time":
messageData = {
command: "real_time",
stock_code: "SH.000001",
};
break;
//
case "init_real_time":
messageData = {
command: "init_real_time",
stock_code: "SH.000001",
};
break;
case "stop_real_time":
messageData = {
command: "stop_real_time",
};
break;
//
case "stock_list":
messageData = {
command: "stock_list",
};
break;
case "batch_real_time":
messageData = {
command: "batch_real_time",
stock_codes: messageDataArray,
};
break;
case "help":
messageData = {
command: "help",
};
break;
}
if (!messageData) {
return;
} else {
try {
//
const success = tcpConnection.send(messageData);
if (success) {
console.log("home发送TCP消息:", messageData);
}
} catch (error) {
console.error("发送TCP消息时出错:", error);
}
}
};
// TCP
const getTcpStatus = () => {
const status = tcpConnection.getConnectionStatus();
uni.showModal({
title: "TCP连接状态",
content: `当前状态: ${status ? "已连接" : "未连接"}`,
showCancel: false,
});
};
let isMorePacket = {
init_batch_real_time: false,
batch_real_time: false,
};
let receivedMessage;
// TCP
const parseStockData = (message) => {
try {
console.log("进入parseStockData, message类型:", typeof message);
let parsedMessage;
// isMorePackettrue
// message{JSON
//
if (message.includes("欢迎连接到股票数据服务器")) {
console.log("服务器命令列表,不予处理");
return;
}
if ((typeof message === "string" && message.includes("batch_data_start")) || isMorePacket.init_batch_real_time) {
if (typeof message === "string" && message.includes("batch_data_start")) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket.init_batch_real_time = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("batch_data_complete")) {
console.log("接受分包数据结束");
isMorePacket.init_batch_real_time = false;
console.log("展示数据", receivedMessage);
let startIndex = 0;
let startCount = 0;
let endIndex = receivedMessage.indexOf("batch_data_complete");
for (let i = 0; i < receivedMessage.length; ++i) {
if (receivedMessage[i] == "{") {
startCount++;
if (startCount == 2) {
startIndex = i;
break;
}
}
}
for (let i = receivedMessage.indexOf("batch_data_complete"); i >= 0; --i) {
if (receivedMessage[i] == "}" || startIndex == endIndex) {
endIndex = i;
break;
}
}
if (startIndex >= endIndex) {
throw new Error("JSON字符串格式错误");
}
console.log("message", startIndex, endIndex, receivedMessage[endIndex], receivedMessage[startIndex]);
parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data;
for (let i = 0; i < globalIndexArray.value.length; ++i) {
for (let j = 0; j < globalIndexArray.value[i].list.length; ++j) {
const stockCode = globalIndexArray.value[i].list[j].code;
marketSituationStore.gloablCardData[i].list[j].currentPrice = stockDataArray[stockCode][0].current_price.toFixed(2);
marketSituationStore.gloablCardData[i].list[j].changeAmount = (stockDataArray[stockCode][0].current_price - stockDataArray[stockCode][0].pre_close).toFixed(2);
marketSituationStore.gloablCardData[i].list[j].changePercent = ((100 * (stockDataArray[stockCode][0].current_price - stockDataArray[stockCode][0].pre_close)) / stockDataArray[stockCode][0].pre_close).toFixed(2) + "%";
marketSituationStore.gloablCardData[i].list[j].isRising = stockDataArray[stockCode][0].current_price - stockDataArray[stockCode][0].pre_close >= 0;
}
}
}
} else if ((typeof message === "string" && message.includes('{"count')) || isMorePacket.batch_real_time) {
if (typeof message === "string" && message.includes('{"count')) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket.batch_real_time = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("batch_realtime_data")) {
console.log("接受分包数据结束");
isMorePacket.batch_real_time = false;
console.log("展示数据", receivedMessage);
let startIndex = 0;
let endIndex = receivedMessage.length - 1;
for (let i = 0; i < receivedMessage.length; ++i) {
if (receivedMessage[i] == "{") {
startIndex = i;
break;
}
}
for (let i = receivedMessage.length - 1; i >= 0; --i) {
if (receivedMessage[i] == "}" || startIndex == endIndex) {
endIndex = i;
break;
}
}
if (startIndex >= endIndex) {
throw new Error("JSON字符串格式错误");
}
parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data;
for (let i = 0; i < globalIndexArray.value.length; ++i) {
for (let j = 0; j < globalIndexArray.value[i].list.length; ++j) {
const stockCode = globalIndexArray.value[i].list[j].code;
marketSituationStore.gloablCardData[i].list[j].currentPrice = stockDataArray[stockCode][0].current_price.toFixed(2);
marketSituationStore.gloablCardData[i].list[j].changeAmount = (stockDataArray[stockCode][0].current_price - stockDataArray[stockCode][0].pre_close).toFixed(2);
marketSituationStore.gloablCardData[i].list[j].changePercent = ((100 * (stockDataArray[stockCode][0].current_price - stockDataArray[stockCode][0].pre_close)) / stockDataArray[stockCode][0].pre_close).toFixed(2) + "%";
marketSituationStore.gloablCardData[i].list[j].isRising = stockDataArray[stockCode][0].current_price - stockDataArray[stockCode][0].pre_close >= 0;
}
}
}
} else {
// JSON
console.log("不是需要的数据,不做处理");
}
} catch (error) {
console.error("解析TCP股票数据失败:", error.message);
console.error("错误详情:", error);
}
};
// TCP
const removeTcpListeners = () => {
if (connectionListener.value) {
tcpConnection.removeConnectionListener(connectionListener.value);
connectionListener.value = null;
console.log("已移除TCP连接状态监听器");
}
if (messageListener.value) {
tcpConnection.removeMessageListener(messageListener.value);
messageListener.value = null;
console.log("已移除TCP消息监听器");
}
};
const startTcp = () => {
try {
removeTcpListeners();
disconnectTcp();
initTcpListeners();
connectTcp();
} catch (error) {
console.error("建立连接并设置监听出错:", error);
}
};
onUnmounted(() => {
sendTcpMessage("stop_real_time");
removeTcpListeners();
disconnectTcp();
});
//
onMounted(async () => {
await getRegionalGroup();
initTcpListeners();
await nextTick();
//
startTcp();
//
const systemInfo = uni.getSystemInfoSync();
iSMT.value = systemInfo.statusBarHeight || 0;

159
pages/marketSituation/marketCondition.vue

@ -210,15 +210,15 @@
</view>
<view class="bottomTool">
<view class="index">
<view class="index" @click="goToIndexRepository">
<image class="icon" src="/static/marketSituation-image/marketCondition-image/index.png" mode="指标仓库图标"> </image>
指标仓库
</view>
<view class="function">
<view class="function" @click="goToFunction">
<image class="icon" src="/static/marketSituation-image/marketCondition-image/function.png" mode="功能图标"> </image>
功能
</view>
<view class="favorites">
<view class="favorites" @click="goToFavorites">
<image class="icon" src="/static/marketSituation-image/marketCondition-image/favorites.png" mode="加自选图标"></image>
加自选
</view>
@ -233,8 +233,9 @@ const instance = getCurrentInstance();
import { prevClosePrice, timeData as testTimeData, klineData as testKlineData } from "@/common/stockTimeInformation.js";
import { throttle } from "@/common/util.js";
import { HCharts } from "@/common/canvasMethod.js";
import tcpConnection, { TCPConnection, TCP_CONFIG } from "@/api/tcpConnection.js";
import tcpConnection, { TCPConnection, TCP_CONFIG } from "../../api/tcpConnection";
import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";
const marketSituationStore = useMarketSituationStore();
// TCP
const tcpConnected = ref(false);
const connectionListener = ref(null);
@ -244,6 +245,7 @@ const messageListener = ref(null);
const currentStockFrom = ref();
//
const currentStockIndex = ref(-1);
const currentStockParentIndex = ref(-1);
//
const stockInformation = ref({
stockName: "----", //
@ -413,12 +415,7 @@ const startTcp = () => {
initTcpListeners();
connectTcp();
} catch (error) {
console.error("建立连接并设置监听:", error);
uni.showToast({
title: "建立连接并设置监听",
icon: "none",
duration: 1500,
});
console.error("建立连接并设置监听出错:", error);
}
};
@ -516,25 +513,75 @@ const backToHomepage = () => {
};
const toLeftPage = () => {
if(currentStockFrom.value == "marketOverview"){
return;
}
if (currentStockIndex.value > 0) {
currentStockIndex.value--;
// updateStockInformation();
} else {
if (currentStockIndex.value == 0) {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
return;
} else {
currentStockIndex.value--;
let nextStockInformation;
if (currentStockFrom.value == "marketOverview") {
nextStockInformation = marketSituationStore.cardData[currentStockIndex.value];
} else if (currentStockFrom.value == "marketDetail") {
nextStockInformation = marketSituationStore.marketDetailCardData[currentStockIndex.value];
} else if (currentStockFrom.value == "globalIndex") {
nextStockInformation = marketSituationStore.gloablCardData[currentStockParentIndex.value].list[currentStockIndex.value];
} else {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
return;
}
updateStockInformation(nextStockInformation);
}
};
const toRightPage = () => {
if (currentStockIndex.value < stockList.length - 1) {
currentStockIndex.value++;
// updateStockInformation();
let nextStockInformation;
if (currentStockFrom.value == "marketOverview") {
if (currentStockIndex.value == marketSituationStore.cardData.length) {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
return;
} else {
currentStockIndex.value++;
nextStockInformation = marketSituationStore.cardData[currentStockIndex.value];
updateStockInformation(nextStockInformation);
}
} else if (currentStockFrom.value == "marketDetail") {
if (currentStockIndex.value == marketSituationStore.marketDetailCardData.length) {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
return;
} else {
currentStockIndex.value++;
nextStockInformation = marketSituationStore.marketDetailCardData[currentStockIndex.value];
updateStockInformation(nextStockInformation);
}
} else if (currentStockFrom.value == "globalIndex") {
if (currentStockIndex.value == marketSituationStore.gloablCardData[currentStockParentIndex.value].list.length) {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
return;
} else {
currentStockIndex.value++;
nextStockInformation = marketSituationStore.gloablCardData[currentStockParentIndex.value].list[currentStockIndex.value];
updateStockInformation(nextStockInformation);
}
} else {
uni.showToast({
title: "没有更多股票了",
@ -544,6 +591,38 @@ const toRightPage = () => {
}
};
const updateStockInformation = (stock) => {
klineTab.value = 1;
stockInformation.value.stockName = stock.stockName||stock.name;
stockInformation.value.stockCode = stock.stockCode||stock.code;
sendTcpMessage("stop_real_time");
sendTcpMessage("init_real_time");
};
const goToIndexRepository = () => {
uni.showToast({
title: "指标仓库",
icon: "none",
duration: 1000,
});
};
const goToFunction = () => {
uni.showToast({
title: "功能",
icon: "none",
duration: 1000,
});
};
const goToFavorites = () => {
uni.showToast({
title: "加自选",
icon: "none",
duration: 1000,
});
};
const openStockDetail = () => {
isStockDetail.value = true;
};
@ -1451,11 +1530,6 @@ const initTcpListeners = () => {
console.log("TCP连接状态变化:", status, tcpConnected.value);
//
uni.showToast({
title: status === "connected" ? "TCP连接成功" : "TCP连接断开",
icon: status === "connected" ? "success" : "none",
duration: 2000,
});
if (status === "connected") {
if (klineTab.value == 1) {
@ -1600,11 +1674,6 @@ const sendTcpMessage = (command) => {
break;
}
if (!messageData) {
uni.showToast({
title: "命令不存在",
icon: "none",
duration: 1000,
});
return;
} else {
try {
@ -1612,19 +1681,9 @@ const sendTcpMessage = (command) => {
const success = tcpConnection.send(messageData);
if (success) {
console.log("home发送TCP消息:", messageData);
uni.showToast({
title: "消息发送成功",
icon: "success",
duration: 1000,
});
}
} catch (error) {
console.error("发送TCP消息时出错:", error);
uni.showToast({
title: "消息发送失败",
icon: "none",
duration: 1000,
});
}
}
};
@ -2177,8 +2236,8 @@ onLoad((options) => {
// stockInformation
if (stockData) {
stockInformation.value.stockName = stockData.stockName;
stockInformation.value.stockCode = stockData.stockCode;
stockInformation.value.stockName = stockData.stockName||stockData.name;
stockInformation.value.stockCode = stockData.stockCode||stockData.code;
}
} catch (error) {
console.error("解析股票数据失败:", error);
@ -2193,16 +2252,24 @@ onLoad((options) => {
currentStockIndex.value = stockIndex;
}
// index
if (options.parentIndex) {
const stockParentIndex = parseInt(options.parentIndex);
console.log("股票在列表中的父索引:", stockParentIndex);
// index
currentStockParentIndex.value = stockParentIndex;
}
// stockFrom
if (options.stockFrom) {
currentStockFrom.value = options.stockFrom;
if (options.from) {
currentStockFrom.value = options.from;
}
});
//
onUnmounted(() => {
removeTcpListeners();
disconnect();
disconnectTcp();
if (timer) {
console.log("卸载定时器");
clearInterval(timer);

340
pages/marketSituation/marketDetail.vue

@ -36,19 +36,19 @@
<scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
<!-- 股票列表 -->
<view class="stock-list">
<view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index" @click="viewIndexDetail(stock)">
<view class="stock-row" v-for="(item,index) in sortedStockList" :key="item" @click="viewIndexDetail(item,index)">
<view class="stock-cell name-column">
<view class="stock-name">{{ stock.stockName }}</view>
<view class="stock-code">{{ stock.stockCode }}</view>
<view class="stock-name">{{ item.stockName }}</view>
<view class="stock-code">{{ item.stockCode }}</view>
</view>
<view class="stock-cell price-column">
<text class="stock-price" :class="stock.isRising ? 'rising' : 'falling'">
{{ typeof stock.price === "number" ? stock.price.toFixed(2) : stock.price }}
<text class="stock-price" :class="item.isRising ? 'rising' : 'falling'">
{{ typeof item.currentPrice === "number" ? item.currentPrice.toFixed(2) : item.currentPrice }}
</text>
</view>
<view class="stock-cell change-column">
<text class="stock-change" :class="stock.isRising ? 'rising' : 'falling'">
{{ stock.change || stock.changePercent }}
<text class="stock-change" :class="item.isRising ? 'rising' : 'falling'">
{{ item.changePercent }}
</text>
</view>
</view>
@ -64,10 +64,12 @@
</template>
<script setup>
import { ref, computed, onMounted, watch } from "vue";
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import footerBar from "@/components/footerBar.vue";
import { getRegionalGroupListAPI } from "../../api/marketSituation/marketSituation.js";
import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";
const marketSituationStore = useMarketSituationStore();
//
const iSMT = ref(0);
const contentHeight = ref(0);
@ -185,8 +187,8 @@ const contentTopPosition = computed(() => {
});
const sortedStockList = computed(() => {
console.log("计算sortedStockList,原始数据长度:", stockList.value.length);
let list = [...stockList.value];
console.log("计算sortedStockList,原始数据长度:", marketSituationStore.marketDetailCardData.length);
let list = [...marketSituationStore.marketDetailCardData];
if (sortType.value === "price") {
list.sort((a, b) => {
@ -194,8 +196,8 @@ const sortedStockList = computed(() => {
});
} else if (sortType.value === "change") {
list.sort((a, b) => {
const aChange = parseFloat(a.change.replace(/[+%-]/g, ""));
const bChange = parseFloat(b.change.replace(/[+%-]/g, ""));
const aChange = parseFloat(a.changePercent.replace(/[+%-]/g, ""));
const bChange = parseFloat(b.changePercent.replace(/[+%-]/g, ""));
return sortOrder.value === "asc" ? aChange - bChange : bChange - aChange;
});
}
@ -210,35 +212,23 @@ const getRegionalGroupList = async () => {
name: marketTitle.value,
});
regionalGroupArray.value = result.data;
marketSituationStore.marketDetailCardData = result.data;
} catch (e) {
console.error("获取区域分组列表失败:", e);
}
};
//
onLoad(async (options) => {
if (options && options.market) {
marketTitle.value = options.market;
await getRegionalGroupList();
}
});
//
const goBack = () => {
uni.navigateBack();
};
//
const viewIndexDetail = (item) => {
const viewIndexDetail = (item,index) => {
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
// duration: 2000
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}&index=${index}&from=marketDetail`,
});
};
@ -260,6 +250,302 @@ const sortByChange = () => {
}
};
// TCP
import tcpConnection, { TCPConnection, TCP_CONFIG } from "@/api/tcpConnection.js";
const tcpConnected = ref(false);
const connectionListener = ref(null);
const messageListener = ref(null);
// TCP
const initTcpListeners = () => {
//
connectionListener.value = (status, result) => {
tcpConnected.value = status === "connected";
console.log("TCP连接状态变化:", status, tcpConnected.value);
//
if (status === "connected") {
sendTcpMessage("batch_real_time");
}
};
//
messageListener.value = (type, message, parsedArray) => {
const messageObj = {
type: type,
content: message,
parsedArray: parsedArray,
timestamp: new Date().toLocaleTimeString(),
direction: "received",
};
//
parseStockData(message);
};
//
tcpConnection.onConnectionChange(connectionListener.value);
tcpConnection.onMessage(messageListener.value);
};
// TCP
const connectTcp = () => {
console.log("开始连接TCP服务器...");
tcpConnection.connect();
};
// TCP
const disconnectTcp = () => {
console.log("断开TCP连接...");
tcpConnection.disconnect();
tcpConnected.value = false;
};
// TCP
const sendTcpMessage = (command) => {
let messageData;
let messageDataArray = [];
if (command == "batch_real_time") {
messageDataArray = regionalGroupArray.value.map((item) => item.code);
}
console.log(messageDataArray);
switch (command) {
//
case "real_time":
messageData = {
command: "real_time",
stock_code: "SH.000001",
};
break;
//
case "init_real_time":
messageData = {
command: "init_real_time",
stock_code: "SH.000001",
};
break;
case "stop_real_time":
messageData = {
command: "stop_real_time",
};
break;
//
case "stock_list":
messageData = {
command: "stock_list",
};
break;
case "batch_real_time":
messageData = {
command: "batch_real_time",
stock_codes: messageDataArray,
};
break;
case "help":
messageData = {
command: "help",
};
break;
}
if (!messageData) {
return;
} else {
try {
//
const success = tcpConnection.send(messageData);
if (success) {
console.log("home发送TCP消息:", messageData);
}
} catch (error) {
console.error("发送TCP消息时出错:", error);
}
}
};
// TCP
const getTcpStatus = () => {
const status = tcpConnection.getConnectionStatus();
uni.showModal({
title: "TCP连接状态",
content: `当前状态: ${status ? "已连接" : "未连接"}`,
showCancel: false,
});
};
let isMorePacket = {
init_batch_real_time: false,
batch_real_time: false,
};
let receivedMessage;
// TCP
const parseStockData = (message) => {
try {
console.log("进入parseStockData, message类型:", typeof message);
let parsedMessage;
// isMorePackettrue
// message{JSON
//
if (message.includes("欢迎连接到股票数据服务器")) {
console.log("服务器命令列表,不予处理");
return;
}
if ((typeof message === "string" && message.includes("batch_data_start")) || isMorePacket.init_batch_real_time) {
if (typeof message === "string" && message.includes("batch_data_start")) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket.init_batch_real_time = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("batch_data_complete")) {
console.log("接受分包数据结束");
isMorePacket.init_batch_real_time = false;
console.log("展示数据", receivedMessage);
let startIndex = 0;
let startCount = 0;
let endIndex = receivedMessage.indexOf("batch_data_complete");
for (let i = 0; i < receivedMessage.length; ++i) {
if (receivedMessage[i] == "{") {
startCount++;
if (startCount == 2) {
startIndex = i;
break;
}
}
}
for (let i = receivedMessage.indexOf("batch_data_complete"); i >= 0; --i) {
if (receivedMessage[i] == "}" || startIndex == endIndex) {
endIndex = i;
break;
}
}
if (startIndex >= endIndex) {
throw new Error("JSON字符串格式错误");
}
console.log("message", startIndex, endIndex, receivedMessage[endIndex], receivedMessage[startIndex]);
parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data;
marketSituationStore.marketDetailCardData = regionalGroupArray.value.map((item) => ({
market: item.market,
stockCode: item.code,
stockName: item.name,
id: item.id,
currentPrice: stockDataArray[item.code][0].current_price.toFixed(2),
changeAmount: (stockDataArray[item.code][0].current_price - stockDataArray[item.code][0].pre_close).toFixed(2),
changePercent: ((100 * (stockDataArray[item.code][0].current_price - stockDataArray[item.code][0].pre_close)) / stockDataArray[item.code][0].pre_close).toFixed(2) + "%",
isRising: stockDataArray[item.code][0].current_price - stockDataArray[item.code][0].pre_close >= 0,
}));
}
} else if ((typeof message === "string" && message.includes('{"count')) || isMorePacket.batch_real_time) {
if (typeof message === "string" && message.includes('{"count')) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket.batch_real_time = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("batch_realtime_data")) {
console.log("接受分包数据结束");
isMorePacket.batch_real_time = false;
console.log("展示数据", receivedMessage);
let startIndex = 0;
let endIndex = receivedMessage.length - 1;
for (let i = 0; i < receivedMessage.length; ++i) {
if (receivedMessage[i] == "{") {
startIndex = i;
break;
}
}
for (let i = receivedMessage.length - 1; i >= 0; --i) {
if (receivedMessage[i] == "}" || startIndex == endIndex) {
endIndex = i;
break;
}
}
if (startIndex >= endIndex) {
throw new Error("JSON字符串格式错误");
}
parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data;
marketSituationStore.marketDetailCardData = regionalGroupArray.value.map((item) => ({
market: item.market,
stockCode: item.code,
stockName: item.name,
id: item.id,
currentPrice: stockDataArray[item.code][0].current_price.toFixed(2),
changeAmount: (stockDataArray[item.code][0].current_price - stockDataArray[item.code][0].pre_close).toFixed(2),
changePercent: ((100 * (stockDataArray[item.code][0].current_price - stockDataArray[item.code][0].pre_close)) / stockDataArray[item.code][0].pre_close).toFixed(2) + "%",
isRising: stockDataArray[item.code][0].current_price - stockDataArray[item.code][0].pre_close >= 0,
}));
}
} else {
// JSON
console.log("不是需要的数据,不做处理");
}
} catch (error) {
console.error("解析TCP股票数据失败:", error.message);
console.error("错误详情:", error);
}
};
// TCP
const removeTcpListeners = () => {
if (connectionListener.value) {
tcpConnection.removeConnectionListener(connectionListener.value);
connectionListener.value = null;
console.log("已移除TCP连接状态监听器");
}
if (messageListener.value) {
tcpConnection.removeMessageListener(messageListener.value);
messageListener.value = null;
console.log("已移除TCP消息监听器");
}
};
const startTcp = () => {
try {
removeTcpListeners();
disconnectTcp();
initTcpListeners();
connectTcp();
} catch (error) {
console.error("建立连接并设置监听出错:", error);
}
};
//
onLoad(async (options) => {
if (options && options.market) {
marketTitle.value = options.market;
await getRegionalGroupList();
initTcpListeners();
await nextTick();
//
startTcp();
}
});
onUnmounted(() => {
sendTcpMessage("stop_real_time");
removeTcpListeners();
disconnectTcp();
});
onMounted(() => {
//
iSMT.value = uni.getSystemInfoSync().statusBarHeight;

290
pages/marketSituation/marketOverview.vue

@ -46,7 +46,7 @@
</template>
<script setup>
import { ref, onMounted, watch, nextTick, computed } from "vue";
import { ref, onMounted, onUnmounted, watch, nextTick, computed } from "vue";
import util from "../../common/util.js";
import IndexCard from "../../components/IndexCard.vue";
import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";
@ -168,8 +168,296 @@ const getGlobalIndex = async () => {
}
};
// TCP
import tcpConnection, { TCPConnection, TCP_CONFIG } from "@/api/tcpConnection.js";
const tcpConnected = ref(false);
const connectionListener = ref(null);
const messageListener = ref(null);
// TCP
const initTcpListeners = () => {
//
connectionListener.value = (status, result) => {
tcpConnected.value = status === "connected";
console.log("TCP连接状态变化:", status, tcpConnected.value);
//
if (status === "connected") {
sendTcpMessage("batch_real_time");
}
};
//
messageListener.value = (type, message, parsedArray) => {
const messageObj = {
type: type,
content: message,
parsedArray: parsedArray,
timestamp: new Date().toLocaleTimeString(),
direction: "received",
};
//
parseStockData(message);
};
//
tcpConnection.onConnectionChange(connectionListener.value);
tcpConnection.onMessage(messageListener.value);
};
// TCP
const connectTcp = () => {
console.log("开始连接TCP服务器...");
tcpConnection.connect();
};
// TCP
const disconnectTcp = () => {
console.log("断开TCP连接...");
tcpConnection.disconnect();
tcpConnected.value = false;
};
// TCP
const sendTcpMessage = (command) => {
let messageData;
let messageDataArray = [];
if (command == "batch_real_time") {
messageDataArray = globalIndexArray.value.map((item) => item.stockCode);
}
console.log(messageDataArray);
switch (command) {
//
case "real_time":
messageData = {
command: "real_time",
stock_code: "SH.000001",
};
break;
//
case "init_real_time":
messageData = {
command: "init_real_time",
stock_code: "SH.000001",
};
break;
case "stop_real_time":
messageData = {
command: "stop_real_time",
};
break;
//
case "stock_list":
messageData = {
command: "stock_list",
};
break;
case "batch_real_time":
messageData = {
command: "batch_real_time",
stock_codes: messageDataArray,
};
break;
case "help":
messageData = {
command: "help",
};
break;
}
if (!messageData) {
return;
} else {
try {
//
const success = tcpConnection.send(messageData);
if (success) {
console.log("home发送TCP消息:", messageData);
}
} catch (error) {
console.error("发送TCP消息时出错:", error);
}
}
};
// TCP
const getTcpStatus = () => {
const status = tcpConnection.getConnectionStatus();
uni.showModal({
title: "TCP连接状态",
content: `当前状态: ${status ? "已连接" : "未连接"}`,
showCancel: false,
});
};
let isMorePacket = {
init_batch_real_time: false,
batch_real_time: false,
};
let receivedMessage;
// TCP
const parseStockData = (message) => {
try {
console.log("进入parseStockData, message类型:", typeof message);
let parsedMessage;
// isMorePackettrue
// message{JSON
//
if (message.includes("欢迎连接到股票数据服务器")) {
console.log("服务器命令列表,不予处理");
return;
}
if ((typeof message === "string" && message.includes("batch_data_start")) || isMorePacket.init_batch_real_time) {
if (typeof message === "string" && message.includes("batch_data_start")) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket.init_batch_real_time = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("batch_data_complete")) {
console.log("接受分包数据结束");
isMorePacket.init_batch_real_time = false;
console.log("展示数据", receivedMessage);
let startIndex = 0;
let startCount = 0;
let endIndex = receivedMessage.indexOf("batch_data_complete");
for (let i = 0; i < receivedMessage.length; ++i) {
if (receivedMessage[i] == "{") {
startCount++;
if (startCount == 2) {
startIndex = i;
break;
}
}
}
for (let i = receivedMessage.indexOf("batch_data_complete"); i >= 0; --i) {
if (receivedMessage[i] == "}" || startIndex == endIndex) {
endIndex = i;
break;
}
}
if (startIndex >= endIndex) {
throw new Error("JSON字符串格式错误");
}
console.log("message", startIndex, endIndex, receivedMessage[endIndex], receivedMessage[startIndex]);
parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data;
marketSituationStore.cardData = globalIndexArray.value.map((item) => ({
market: item.market,
stockCode: item.stockCode,
stockName: item.stockName,
currentPrice: stockDataArray[item.stockCode][0].current_price.toFixed(2),
changeAmount: (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close).toFixed(2),
changePercent: ((100 * (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close)) / stockDataArray[item.stockCode][0].pre_close).toFixed(2) + "%",
isRising: stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close >= 0,
}));
}
} else if ((typeof message === "string" && message.includes('{"count')) || isMorePacket.batch_real_time) {
if (typeof message === "string" && message.includes('{"count')) {
console.log("开始接受分包数据");
receivedMessage = "";
} else {
console.log("接收分包数据过程中");
}
isMorePacket.batch_real_time = true;
receivedMessage += message;
// }JSON
if (receivedMessage.includes("batch_realtime_data")) {
console.log("接受分包数据结束");
isMorePacket.batch_real_time = false;
console.log("展示数据", receivedMessage);
let startIndex = 0;
let endIndex = receivedMessage.length - 1;
for (let i = 0; i < receivedMessage.length; ++i) {
if (receivedMessage[i] == "{") {
startIndex = i;
break;
}
}
for (let i = receivedMessage.length - 1; i >= 0; --i) {
if (receivedMessage[i] == "}" || startIndex == endIndex) {
endIndex = i;
break;
}
}
if (startIndex >= endIndex) {
throw new Error("JSON字符串格式错误");
}
parsedMessage = JSON.parse(receivedMessage.substring(startIndex, endIndex + 1));
console.log("JSON解析成功,解析后类型:", typeof parsedMessage, parsedMessage);
const stockDataArray = parsedMessage.data;
marketSituationStore.cardData = globalIndexArray.value.map((item) => ({
market: item.market,
stockCode: item.stockCode,
stockName: item.stockName,
currentPrice: stockDataArray[item.stockCode][0].current_price.toFixed(2),
changeAmount: (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close).toFixed(2),
changePercent: ((100 * (stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close)) / stockDataArray[item.stockCode][0].pre_close).toFixed(2) + "%",
isRising: stockDataArray[item.stockCode][0].current_price - stockDataArray[item.stockCode][0].pre_close >= 0,
}));
}
} else {
// JSON
console.log("不是需要的数据,不做处理");
}
} catch (error) {
console.error("解析TCP股票数据失败:", error.message);
console.error("错误详情:", error);
}
};
// TCP
const removeTcpListeners = () => {
if (connectionListener.value) {
tcpConnection.removeConnectionListener(connectionListener.value);
connectionListener.value = null;
console.log("已移除TCP连接状态监听器");
}
if (messageListener.value) {
tcpConnection.removeMessageListener(messageListener.value);
messageListener.value = null;
console.log("已移除TCP消息监听器");
}
};
const startTcp = () => {
try {
removeTcpListeners();
disconnectTcp();
initTcpListeners();
connectTcp();
} catch (error) {
console.error("建立连接并设置监听出错:", error);
}
};
onUnmounted(() => {
sendTcpMessage("stop_real_time");
removeTcpListeners();
disconnectTcp();
});
onMounted(async () => {
await getGlobalIndex();
initTcpListeners();
await nextTick();
//
startTcp();
//
iSMT.value = uni.getSystemInfoSync().statusBarHeight;

37
pages/morningMarketAnalysis/morningMarketAnalysis.vue

@ -1,6 +1,13 @@
<template>
<view>
早盘解析页面
<view class="container">
<view class="content">
<image
class="no-data-image"
src="https://d31zlh4on95l9h.cloudfront.net/images/f5a9bd32c81bc7cca47252b51357c12f.png"
mode="aspectFit"
></image>
<text class="no-data-text">暂无数据~</text>
</view>
</view>
</template>
@ -18,5 +25,31 @@
</script>
<style>
.container {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f5f5;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.no-data-image {
width: 200px;
height: 200px;
margin-bottom: 20px;
}
.no-data-text {
font-size: 16px;
color: #999999;
text-align: center;
}
</style>

394
pages/setting/share.vue

@ -1,111 +1,299 @@
<template>
<view class="all">
<img class="img-share" src="/static/my/shareBackground.png" />
<img class="img-greenBack" src="/static/my/greenBackground.png" />
<img class="img-QRcode" src="/static/my/QRcode.png" />
<img class="img-award" src="/static/my/award.png" />
<img class="img-myFriends" src="/static/my/myFriends.png" />
<img class="img-friends" src="/static/my/shareFriends.png" />
<text class="jwcode">{{ jwcode }}</text>
<button class="invite">立即邀请</button>
</view>
<view class="all">
<!-- 背景图部分 -->
<image class="img-share" src="/static/my/shareBackground.png"/>
<image class="img-greenBack" src="/static/my/greenBackground.png"/>
<!-- todo 这里给我个码-->
<image class="img-QRcode" src="/static/my/QRcode.png"/>
<image class="img-award" src="/static/my/award.png"/>
<image class="img-myFriends" src="/static/my/myFriends.png"/>
<image class="img-friends" src="/static/my/shareFriends.png"/>
<!-- dccode -->
<text class="jwcode">{{ dccode }}</text>
<!-- 邀请按钮 -->
<button class="invite" @click="openShare">立即邀请</button>
<!-- 分享弹窗 -->
<uni-popup ref="shareRef" type="share" safeArea>
<SharePopup @select="onShareSelect" @close="closeShare" title=" "/>
</uni-popup>
<!-- 二次弹窗 -->
<uni-popup ref="secondPopup" type="share">
<view class="second-popup">
<view style=" display: flex;justify-content: center;align-items: center; font-size: 17px">
<image style="width: 16px; height: 16px; margin-right: 8rpx" src="/static/my/share/success.png"/>
<text>已复制</text>
</view>
<view class="popup-msg-box">
<text>{{ popupMsg }}</text>
</view>
<view style="justify-content: center; align-items: center;">
<!-- 二次弹窗中的按钮图标 -->
<button
style="border-radius: 40rpx; background-color: black; color: white; display: flex; align-items: center; justify-content: center; padding: 12rpx 24rpx;"
@click="closeSecondPopup">
<image style="width: 25px; height: 25px; margin-right: 8rpx;"
:src="platformIconMap[selectedPlatform]"/>
去粘贴给好友
</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script setup>
import {
ref
} from 'vue'
import {ref} from 'vue'
import SharePopup from '@/components/SharePopup.vue'
import {getUserInfo} from "@/api/member";
import {Share} from "@/api/setting/share";
/* =============== 数据与引用 =============== */
const shareRef = ref(null)
const secondPopup = ref(null)
const popupMsg = ref('')
// const jwcode = ref('90047681')
//
const selectedPlatform = ref('')
// dccode
const dccode = ref('')
// token
const token = ref('1ab8f83f391ca866191385d0e5048938')
//
const deviceId = ref(100)
//
const version = ref(100)
//
const client = ref('android')
//
const platformIconMap = ref({
'WeChat': '/static/my/share/WeChat.png',
'WhatsApp': '/static/my/share/WhatsApp.png',
'Line': '/static/my/share/Line.png',
'KakaoTalk': '/static/my/share/KakaoTalk.png',
'复制链接': '/static/my/share/share.png'
})
//
const userInfoRes = ref()
// dccode
const shareLink = ref('')
/* =============== 方法 =============== */
userInfoRes.value = getUserInfo()
userInfoRes.value.then(res => {
dccode.value = res.data.dccode
console.log('用户信息', res.data)
})
const ShareRes = ref()
ShareRes.value = Share()
ShareRes.value.then(res => {
if (res.code === 200){
shareLink.value = res.message
console.log('分享接口返回', res.data)
}else {
console.log('分享接口返回失败', res.data)
}
})
//
function openShare() {
Share()
shareRef.value.open()
}
//
function closeShare() {
shareRef.value.close()
}
//
//
function onShareSelect({item}) {
console.log('选择了:', item.name)
selectedPlatform.value = item.name //
// //
// const baseUrl = 'https:'
// // const shareLink = `${baseUrl}?token=${encodeURIComponent(token.value)}&deviceId=${encodeURIComponent(deviceId.value)}&version=${encodeURIComponent(version.value)}&client=${encodeURIComponent(client.value)}`
// const shareLink = `$ `
//
shareRef.value.close()
popupMsg.value = `【DeepChart】邀请你加入,点击链接帮我助力: ${shareLink.value}`
uni.setClipboardData({
data: popupMsg.value,
showToast: false
});
/* // 根据分享选项显示不同提示
if (item.name === '复制链接') {
popupMsg.value = '链接已复制,快去分享给好友吧~'
} else if (item.name === 'WeChat') {
popupMsg.value = '请在微信中分享~'
} else {
popupMsg.value = `你选择了 ${item.name}`
}*/
//
secondPopup.value.open()
}
//
function closeSecondPopup() {
if (selectedPlatform.value === 'WeChat') {
uni.share({
provider: "weixin",
scene: "WXSceneSession",
type: 1,
summary: popupMsg.value,
success: function (res) {
console.log("success:" + JSON.stringify(res));
},
fail: function (err) {
console.log("fail:" + JSON.stringify(err));
}
});
secondPopup.value.close()
}
//
else if (selectedPlatform.value === 'WhatsApp' || selectedPlatform.value === 'Line' || selectedPlatform.value === 'KakaoTalk') {
secondPopup.value.close()
uni.showToast({title: '开发中……', icon: 'none'})
} else if (selectedPlatform.value === '复制链接') {
uni.showToast({title: '已复制', icon: 'success'})
secondPopup.value.close()
}
}
const jwcode = ref('90047681')
</script>
<style>
.all {
position: relative;
width: 750rpx;
height: auto;
}
.img-share {
width: 750rpx;
height: 2118rpx;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.img-QRcode{
width:320rpx;
height:320rpx;
position:absolute;
top:26vh;
left:215rpx;
z-index: 3;
}
.img-greenBack {
width: 670rpx;
height: 1740rpx;
position: absolute;
top: 16vh;
/* 为什么要用这个替代 margin-top */
left: 40rpx;
/* 还有 padding-left */
z-index: 2;
}
.img-friends {
width: 602rpx;
height: 840rpx;
position: absolute;
top: 68vh;
left: 74rpx;
z-index: 3;
}
.img-award {
width: 300rpx;
height: 120rpx;
position: absolute;
top: 61vh;
left: 75rpx;
z-index: 3;
}
.img-myFriends {
width: 300rpx;
height: 88rpx;
position: absolute;
top: 61vh;
right: 75rpx;
z-index: 3;
}
.jwcode {
width: 320rpx;
height: 38rpx;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 19vh;
left: 212rpx;
z-index: 999;
}
.invite {
width: 320rpx;
height: 80rpx;
border-radius: 40rpx;
background-color: black;
color:white;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 50.7vh;
left: 212rpx;
z-index: 999;
}
<style scoped>
.all {
position: relative;
width: 750rpx;
height: auto;
}
/* 背景图片部分 */
.img-share {
width: 750rpx;
height: 2118rpx;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.img-greenBack {
width: 670rpx;
height: 1740rpx;
position: absolute;
top: 16vh;
left: 40rpx;
z-index: 2;
}
.img-QRcode {
width: 320rpx;
height: 320rpx;
position: absolute;
top: 26vh;
left: 215rpx;
z-index: 3;
}
.img-award {
width: 300rpx;
height: 120rpx;
position: absolute;
top: 61vh;
left: 75rpx;
z-index: 3;
}
.img-myFriends {
width: 300rpx;
height: 88rpx;
position: absolute;
top: 61vh;
right: 75rpx;
z-index: 3;
}
.img-friends {
width: 602rpx;
height: 840rpx;
position: absolute;
top: 68vh;
left: 74rpx;
z-index: 3;
}
/* 邀请码与按钮 */
.jwcode {
width: 320rpx;
height: 38rpx;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 19vh;
left: 212rpx;
z-index: 999;
}
.invite {
width: 320rpx;
height: 80rpx;
border-radius: 40rpx;
background-color: black;
color: white;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 50.7vh;
left: 212rpx;
z-index: 999;
}
/* 第二个弹窗样式 */
.second-popup {
background-color: #fff;
border-radius: 12px;
padding: 30rpx;
text-align: center;
}
.popup-msg-box {
background-color: #F3F3F3;
border-radius: 8px;
padding: 12px 16px;
margin: 10px;
align-items: center;
justify-content: center;
overflow: hidden; /* 隐藏溢出内容 */
text-overflow: ellipsis; /* 溢出部分显示... */
}
</style>

BIN
static/my/share/KakaoTalk.png

After

Width: 42  |  Height: 42  |  Size: 2.5 KiB

BIN
static/my/share/Line.png

After

Width: 42  |  Height: 42  |  Size: 2.2 KiB

BIN
static/my/share/WeChat.png

After

Width: 42  |  Height: 42  |  Size: 2.4 KiB

BIN
static/my/share/WhatsApp.png

After

Width: 42  |  Height: 42  |  Size: 3.6 KiB

BIN
static/my/share/share.png

After

Width: 42  |  Height: 42  |  Size: 1.3 KiB

BIN
static/my/share/success.png

After

Width: 32  |  Height: 32  |  Size: 1.6 KiB

55
stores/modules/marketSituation.js

@ -6,57 +6,14 @@ import { ref } from "vue";
export const useMarketSituationStore = defineStore(
"marketSituation",
() => {
const cardData = ref([
{
market: "usa",
stockName: "道琼斯",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "-125.22",
changePercent: "-0.27%",
isRising: false,
},
{
market: "usa",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "22333.96",
changeAmount: "+125.22",
changePercent: "+0.47%",
isRising: true,
},
{
market: "usa",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "6606.08",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
market: "cn",
stockName: "上证指数",
stockCode: "noCode",
currentPrice: "3333.96",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
market: "cn",
stockName: "科创50",
stockCode: "noCode",
currentPrice: "757.90",
changeAmount: "-25.22",
changePercent: "-0.27%",
isRising: false,
},
]);
const cardData = ref([]);
const gloablCardData = ref([]);
const marketDetailCardData = ref([]);
// 记得 return
return {
cardData
cardData,
gloablCardData,
marketDetailCardData,
};
},
// TODO: 持久化

5
utils/http.js

@ -3,7 +3,7 @@ import { useDeviceStore } from "../stores/modules/deviceInfo"
import { useLoginStore } from "../stores/modules/login"
const baseURL = "https://dbqb.nfdxy.net/testApi"
// const baseURL = "http://192.168.40.8:9000"
const httpInterceptor = {
// 拦截前触发
@ -44,7 +44,8 @@ const httpInterceptor = {
//4 添加token,优先用store,没有则回退到body中的token,保持与Apifox一致
const memberStore = useUserStore()
const token = memberStore.userInfo?.token || options.data?.token
// const token = 'a72cf584af42525f214670cb47443820'
// const token = '2d0b5654409646713cdd40ec0d0bb56c'
// const token = '1b3a58424c5324e40d4bf4d085e18047'
if (token) {
options.header.token = token
}

Loading…
Cancel
Save