From da0b61b8e299da1fe835a4bec10c14cafdef8305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8?= Date: Thu, 28 May 2026 15:07:05 +0800 Subject: [PATCH] ct --- src/api/index.ts | 12 ++++++++---- src/stores/modules/transaction.ts | 23 +++++++++++++++++------ src/utils/mqttClient.ts | 8 ++++---- src/views/profile/business/index.vue | 14 ++++++++++++++ src/views/profile/business/options.ts | 2 +- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 3e3d694..703ab88 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -106,13 +106,17 @@ const responseInterceptor = (response: AxiosResponse removeStorage('userInfo') removeStorage('menusInfo') removeStorage('permissionsInfo') - window.location.href = '/user/login' - throw new Error(data.msg) + setTimeout(()=>{ + window.location.href = '/user/login' + }, 1000) + break case -101: data.msg = 'token错误!' removeStorage('token') - window.location.href = '/user/login' - throw new Error(data.msg) + setTimeout(()=>{ + window.location.href = '/user/login' + }, 1000) + break default: throw new Error(data.msg || '操作失败!') } diff --git a/src/stores/modules/transaction.ts b/src/stores/modules/transaction.ts index 2e8b27a..feed027 100644 --- a/src/stores/modules/transaction.ts +++ b/src/stores/modules/transaction.ts @@ -4,6 +4,7 @@ import { MQTTClient } from '@/utils/mqttClient' import { useUserStore } from './user' import { useOrderPositionStore } from '@/stores/modules/orderPosition.ts' import { formatDate } from '@/utils/timeUtils' +import { initMqttKeyApi } from '@/api/modules/user' // ============================================================ // 类型声明 @@ -47,6 +48,8 @@ export const useTransactionStore = defineStore('transaction', () => { const positionList = ref([]) /** 做市商浮动盈亏数据 Map */ const marketFloatProfitMap = ref>(new Map()) + /** 做市商平仓盈亏数据 Map */ + const marketCloseProfitMap = ref>(new Map()) // ------------------ 初始化 ------------------ @@ -61,6 +64,8 @@ export const useTransactionStore = defineStore('transaction', () => { try { // 先调用 initMqttKey 接口获取 MQTT key + const foreignDeviceNo = sessionStorage.getItem('foreign_device_no') || '' + const mqttKey = await initMqttKeyApi({ device_no: foreignDeviceNo }) // 使用 mqttKey 连接 await mqttClient.connect(import.meta.env.VITE_MQTT_TRANSACTION_HOST as string, { username: `${redis_key}`, @@ -87,7 +92,7 @@ export const useTransactionStore = defineStore('transaction', () => { mqttClient.onTopicMessages({ [topic]: (_topic: string, msg: string): void => { - // console.log(_topic, msg) + console.log(_topic, msg) let [type, data] = msg.split('|') switch (type) { @@ -112,22 +117,26 @@ export const useTransactionStore = defineStore('transaction', () => { /** * 处理做市商浮动盈亏数据 - * 格式:account_id:float_profit_loss (例:84:6992.730000) + * 格式:account_id:float_profit_loss:close_profit_loss (例:84:0.000000:0.000000) */ const handleMarketFloatProfit = (data: string): void => { if (!data) return const fields = data.split(':') - if (fields.length < 2) return + if (fields.length < 3) return const account_id = fields[0] - const float_profit_loss = fields[1] + const float_profit_loss = fields[1] as string + const close_profit_loss = fields[2] as string - // 更新 Map + // 更新浮动盈亏 Map marketFloatProfitMap.value.set(account_id, float_profit_loss) - // 触发响应式更新(创建新的 Map 实例) marketFloatProfitMap.value = new Map(marketFloatProfitMap.value) + + // 更新平仓盈亏 Map + marketCloseProfitMap.value.set(account_id, close_profit_loss) + marketCloseProfitMap.value = new Map(marketCloseProfitMap.value) } @@ -169,6 +178,7 @@ export const useTransactionStore = defineStore('transaction', () => { mqttClient?.disconnect() positionList.value = [] marketFloatProfitMap.value.clear() + marketCloseProfitMap.value.clear() } /** @@ -183,6 +193,7 @@ export const useTransactionStore = defineStore('transaction', () => { mqttClient, positionList, marketFloatProfitMap, + marketCloseProfitMap, initMarketConditionsMQTT, getPositionList, requestMarketFloatProfit, diff --git a/src/utils/mqttClient.ts b/src/utils/mqttClient.ts index 3f7c76b..69c7de0 100644 --- a/src/utils/mqttClient.ts +++ b/src/utils/mqttClient.ts @@ -1,7 +1,7 @@ import mqtt from 'mqtt' import type { MqttClient, IClientOptions, IClientPublishOptions } from 'mqtt' import type { QoS } from 'mqtt-packet' -import { initMqttKeyApi } from '@/api/modules/user' +// import { initMqttKeyApi } from '@/api/modules/user' /** * 消息处理器类型定义 * 接收主题名称和消息内容两个参数 @@ -100,9 +100,9 @@ class MQTTClient { * 触发时机:连接断开,客户端尝试自动重连时 */ this.client.on('reconnect',async () => { - const foreignDeviceNo = sessionStorage.getItem('foreign_device_no') || '' - const mqttKey = await initMqttKeyApi({ device_no: foreignDeviceNo }) - console.log("initMqttKey result:", mqttKey) + // const foreignDeviceNo = sessionStorage.getItem('foreign_device_no') || '' + // const mqttKey = await initMqttKeyApi({ device_no: foreignDeviceNo }) + // console.log("initMqttKey result:", mqttKey) console.log('🔄 MQTT 正在重连...') }) diff --git a/src/views/profile/business/index.vue b/src/views/profile/business/index.vue index bb8687b..0edd49d 100644 --- a/src/views/profile/business/index.vue +++ b/src/views/profile/business/index.vue @@ -35,6 +35,9 @@ + @@ -266,6 +269,17 @@ const getMarketFloatProfit = (accountId: string | number): string => { return parts[0] + '.' + (parts[1] + '00').slice(0, 2) } +/** + * @description 获取做市商的平仓盈亏值 + */ +const getMarketCloseProfit = (accountId: string | number): string => { + const profit = transactionStore.marketCloseProfitMap.get(String(accountId)) + if (!profit) return '--' + const parts = profit.split('.') + if (parts.length === 1) return profit + '.00' + return parts[0] + '.' + (parts[1] + '00').slice(0, 2) +} + /** * @description 获取浮动盈亏样式类 */ diff --git a/src/views/profile/business/options.ts b/src/views/profile/business/options.ts index 2700186..90b1a1f 100644 --- a/src/views/profile/business/options.ts +++ b/src/views/profile/business/options.ts @@ -49,7 +49,7 @@ export const marketTableColumns = [ //浮动盈亏 { label: '浮动盈亏', slotName: 'floatProfitLoss', align: 'center' as const, width: '100px', isNumber: true }, //平仓盈亏 - { label: '平仓盈亏', prop: 'closeProfitLoss', align: 'center' as const, width: '150px', isNumber: true }, + { label: '平仓盈亏', slotName: 'closeProfitLoss', align: 'center' as const, width: '150px', isNumber: true }, //风险金 { label: '风险金', prop: 'riskMargin', align: 'center' as const, width: '150px', isNumber: true }, //服务费