This commit is contained in:
parent
9954a73543
commit
da0b61b8e2
|
|
@ -106,13 +106,17 @@ const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>
|
||||||
removeStorage('userInfo')
|
removeStorage('userInfo')
|
||||||
removeStorage('menusInfo')
|
removeStorage('menusInfo')
|
||||||
removeStorage('permissionsInfo')
|
removeStorage('permissionsInfo')
|
||||||
window.location.href = '/user/login'
|
setTimeout(()=>{
|
||||||
throw new Error(data.msg)
|
window.location.href = '/user/login'
|
||||||
|
}, 1000)
|
||||||
|
break
|
||||||
case -101:
|
case -101:
|
||||||
data.msg = 'token错误!'
|
data.msg = 'token错误!'
|
||||||
removeStorage('token')
|
removeStorage('token')
|
||||||
window.location.href = '/user/login'
|
setTimeout(()=>{
|
||||||
throw new Error(data.msg)
|
window.location.href = '/user/login'
|
||||||
|
}, 1000)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(data.msg || '操作失败!')
|
throw new Error(data.msg || '操作失败!')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { MQTTClient } from '@/utils/mqttClient'
|
||||||
import { useUserStore } from './user'
|
import { useUserStore } from './user'
|
||||||
import { useOrderPositionStore } from '@/stores/modules/orderPosition.ts'
|
import { useOrderPositionStore } from '@/stores/modules/orderPosition.ts'
|
||||||
import { formatDate } from '@/utils/timeUtils'
|
import { formatDate } from '@/utils/timeUtils'
|
||||||
|
import { initMqttKeyApi } from '@/api/modules/user'
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// 类型声明
|
// 类型声明
|
||||||
|
|
@ -47,6 +48,8 @@ export const useTransactionStore = defineStore('transaction', () => {
|
||||||
const positionList = ref<PositionItem[]>([])
|
const positionList = ref<PositionItem[]>([])
|
||||||
/** 做市商浮动盈亏数据 Map<account_id, float_profit_loss> */
|
/** 做市商浮动盈亏数据 Map<account_id, float_profit_loss> */
|
||||||
const marketFloatProfitMap = ref<Map<string, string>>(new Map())
|
const marketFloatProfitMap = ref<Map<string, string>>(new Map())
|
||||||
|
/** 做市商平仓盈亏数据 Map<account_id, close_profit_loss> */
|
||||||
|
const marketCloseProfitMap = ref<Map<string, string>>(new Map())
|
||||||
|
|
||||||
// ------------------ 初始化 ------------------
|
// ------------------ 初始化 ------------------
|
||||||
|
|
||||||
|
|
@ -61,6 +64,8 @@ export const useTransactionStore = defineStore('transaction', () => {
|
||||||
try {
|
try {
|
||||||
// 先调用 initMqttKey 接口获取 MQTT key
|
// 先调用 initMqttKey 接口获取 MQTT key
|
||||||
|
|
||||||
|
const foreignDeviceNo = sessionStorage.getItem('foreign_device_no') || ''
|
||||||
|
const mqttKey = await initMqttKeyApi({ device_no: foreignDeviceNo })
|
||||||
// 使用 mqttKey 连接
|
// 使用 mqttKey 连接
|
||||||
await mqttClient.connect(import.meta.env.VITE_MQTT_TRANSACTION_HOST as string, {
|
await mqttClient.connect(import.meta.env.VITE_MQTT_TRANSACTION_HOST as string, {
|
||||||
username: `${redis_key}`,
|
username: `${redis_key}`,
|
||||||
|
|
@ -87,7 +92,7 @@ export const useTransactionStore = defineStore('transaction', () => {
|
||||||
|
|
||||||
mqttClient.onTopicMessages({
|
mqttClient.onTopicMessages({
|
||||||
[topic]: (_topic: string, msg: string): void => {
|
[topic]: (_topic: string, msg: string): void => {
|
||||||
// console.log(_topic, msg)
|
console.log(_topic, msg)
|
||||||
|
|
||||||
let [type, data] = msg.split('|')
|
let [type, data] = msg.split('|')
|
||||||
switch (type) {
|
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 => {
|
const handleMarketFloatProfit = (data: string): void => {
|
||||||
|
|
||||||
if (!data) return
|
if (!data) return
|
||||||
|
|
||||||
const fields = data.split(':')
|
const fields = data.split(':')
|
||||||
if (fields.length < 2) return
|
if (fields.length < 3) return
|
||||||
|
|
||||||
const account_id = fields[0]
|
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)
|
marketFloatProfitMap.value.set(account_id, float_profit_loss)
|
||||||
// 触发响应式更新(创建新的 Map 实例)
|
|
||||||
marketFloatProfitMap.value = new Map(marketFloatProfitMap.value)
|
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()
|
mqttClient?.disconnect()
|
||||||
positionList.value = []
|
positionList.value = []
|
||||||
marketFloatProfitMap.value.clear()
|
marketFloatProfitMap.value.clear()
|
||||||
|
marketCloseProfitMap.value.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -183,6 +193,7 @@ export const useTransactionStore = defineStore('transaction', () => {
|
||||||
mqttClient,
|
mqttClient,
|
||||||
positionList,
|
positionList,
|
||||||
marketFloatProfitMap,
|
marketFloatProfitMap,
|
||||||
|
marketCloseProfitMap,
|
||||||
initMarketConditionsMQTT,
|
initMarketConditionsMQTT,
|
||||||
getPositionList,
|
getPositionList,
|
||||||
requestMarketFloatProfit,
|
requestMarketFloatProfit,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import mqtt from 'mqtt'
|
import mqtt from 'mqtt'
|
||||||
import type { MqttClient, IClientOptions, IClientPublishOptions } from 'mqtt'
|
import type { MqttClient, IClientOptions, IClientPublishOptions } from 'mqtt'
|
||||||
import type { QoS } from 'mqtt-packet'
|
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 () => {
|
this.client.on('reconnect',async () => {
|
||||||
const foreignDeviceNo = sessionStorage.getItem('foreign_device_no') || ''
|
// const foreignDeviceNo = sessionStorage.getItem('foreign_device_no') || ''
|
||||||
const mqttKey = await initMqttKeyApi({ device_no: foreignDeviceNo })
|
// const mqttKey = await initMqttKeyApi({ device_no: foreignDeviceNo })
|
||||||
console.log("initMqttKey result:", mqttKey)
|
// console.log("initMqttKey result:", mqttKey)
|
||||||
console.log('🔄 MQTT 正在重连...')
|
console.log('🔄 MQTT 正在重连...')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@
|
||||||
<template #floatProfitLoss="{ row }">
|
<template #floatProfitLoss="{ row }">
|
||||||
<span>{{ getMarketFloatProfit(row.id) }}</span>
|
<span>{{ getMarketFloatProfit(row.id) }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
<template #closeProfitLoss="{ row }">
|
||||||
|
<span>{{ getMarketCloseProfit(row.id) }}</span>
|
||||||
|
</template>
|
||||||
<template #pointSpread="{ row }">
|
<template #pointSpread="{ row }">
|
||||||
<el-button type="primary" size="small" @click="handleViewPointDiff(row)"> 查看 </el-button>
|
<el-button type="primary" size="small" @click="handleViewPointDiff(row)"> 查看 </el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -266,6 +269,17 @@ const getMarketFloatProfit = (accountId: string | number): string => {
|
||||||
return parts[0] + '.' + (parts[1] + '00').slice(0, 2)
|
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 获取浮动盈亏样式类
|
* @description 获取浮动盈亏样式类
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export const marketTableColumns = [
|
||||||
//浮动盈亏
|
//浮动盈亏
|
||||||
{ label: '浮动盈亏', slotName: 'floatProfitLoss', align: 'center' as const, width: '100px', isNumber: true },
|
{ 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 },
|
{ label: '风险金', prop: 'riskMargin', align: 'center' as const, width: '150px', isNumber: true },
|
||||||
//服务费
|
//服务费
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue