This commit is contained in:
2026-06-25 17:52:12 +08:00
parent 8d83be7cb3
commit cf6de1d1d7
2 changed files with 74 additions and 100 deletions

View File

@ -279,15 +279,26 @@ const emit = defineEmits<{
(e: 'filter-change', filters: { [key: string]: any }): void (e: 'filter-change', filters: { [key: string]: any }): void
}>() }>()
// Store
const route = useRoute() const route = useRoute()
const userStore = useUserStore() const userStore = useUserStore()
// key 使
const CACHE_VERSION = 'v1'
// key // key
const getCacheKey = () => { const getCacheKey = () => {
const baseKey = props.columnSettingStorageKey || String(route.name || route.path) const baseKey = props.columnSettingStorageKey
const userId = String(userStore.userInfo?.id || 'guest') || String((route.name as string) || route.path || 'default')
return `table-column-setting-${baseKey}-${userId}` const userId = String((userStore.userInfo as any)?.id || 'guest')
return `table-column-setting-${CACHE_VERSION}-${baseKey}-${userId}`
}
//
const getColumnKey = (col: TableColumn): string => {
if (col.prop) return `prop:${col.prop}`
if (col.slotName) return `slot:${col.slotName}`
if (col.type) return `type:${col.type}`
return `label:${col.label}`
} }
// //
@ -306,63 +317,59 @@ const finalColumns = computed(() => {
}) })
// //
// props.columns
// - visible / sortOrder
// - visible true
// -
const initColumns = () => { const initColumns = () => {
if (!props.columns || props.columns.length === 0) { if (!props.columns || props.columns.length === 0) {
localColumns.value = [] localColumns.value = []
return return
} }
//
const cacheKey = getCacheKey() const cacheKey = getCacheKey()
let cachedConfig: any[] = []
const cached = localStorage.getItem(cacheKey) const cached = localStorage.getItem(cacheKey)
if (cached) { if (cached) {
try { try {
const cachedConfig = JSON.parse(cached) const parsed = JSON.parse(cached)
// sortOrder if (Array.isArray(parsed)) cachedConfig = parsed
cachedConfig.sort((a: any, b: any) => (a.sortOrder || 0) - (b.sortOrder || 0))
//
localColumns.value = cachedConfig.map((cached: any) => {
// prop
const originalCol = props.columns?.find((c) => c.prop === cached.prop)
if (originalCol) {
return { ...originalCol, ...cached }
}
// prop slotName
if (cached.slotName) {
const slotCol = props.columns?.find((c) => c.slotName === cached.slotName)
if (slotCol) {
return { ...slotCol, ...cached }
}
}
return null
}).filter(Boolean)
} catch { } catch {
// 使 cachedConfig = []
localColumns.value = props.columns.map((col) => ({
...col,
visible: col.visible !== false,
fixed: col.fixed || false,
}))
} }
} else {
// 使
localColumns.value = props.columns.map((col) => ({
...col,
visible: col.visible !== false,
fixed: col.fixed || false,
}))
} }
// key -> { visible, sortOrder }
const cachedMap = new Map<string, { visible: boolean; sortOrder: number }>()
cachedConfig.forEach((c, idx) => {
cachedMap.set(c.key || getColumnKey(c), {
visible: c.visible !== false,
sortOrder: typeof c.sortOrder === 'number' ? c.sortOrder : idx,
})
})
// visible / sortOrder
const maxOrder = Math.max(-1, ...Array.from(cachedMap.values()).map((v) => v.sortOrder))
let nextOrder = maxOrder + 1
localColumns.value = props.columns.map((col) => {
const hit = cachedMap.get(getColumnKey(col))
if (hit) {
return { ...col, visible: hit.visible, sortOrder: hit.sortOrder }
}
return { ...col, visible: col.visible !== false, sortOrder: nextOrder++ }
})
// sortOrder
localColumns.value.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
} }
// localStorage // localStorage key / visible / sortOrder
const saveToStorage = () => { const saveToStorage = () => {
const config = localColumns.value.map((col, index) => ({ const config = localColumns.value.map((col, index) => ({
prop: col.prop, key: getColumnKey(col),
visible: col.visible, visible: col.visible !== false,
label: col.label,
width: col.width,
slotName: col.slotName,
sortOrder: index, sortOrder: index,
})) }))
localStorage.setItem(getCacheKey(), JSON.stringify(config)) localStorage.setItem(getCacheKey(), JSON.stringify(config))
@ -390,48 +397,33 @@ const handleReset = () => {
} }
// columns // columns
// columns /
//
let lastColumnsKey = ''
watch( watch(
() => props.columns, () => props.columns,
(newColumns) => { (newColumns) => {
if (newColumns && newColumns.length > 0) { if (!newColumns || newColumns.length === 0) return
// // + key
if (localColumns.value.length === 0) { const newKey = newColumns.map((c) => getColumnKey(c)).join('|')
initColumns() if (newKey === lastColumnsKey && localColumns.value.length > 0) return
} lastColumnsKey = newKey
} initColumns()
}, },
{ immediate: true } { immediate: true, deep: true }
) )
// //
onMounted(() => { onMounted(() => {
// props.columns if (props.columns && props.columns.length > 0 && localColumns.value.length === 0) {
setTimeout(() => { initColumns()
if (props.columns && props.columns.length > 0 && localColumns.value.length === 0) { }
initColumns()
}
}, 100)
}) })
// tableData const tableRef = ref<TableInstance>()
watch(
() => props.tableData,
() => {
if (props.singleSelect) {
selectedRadioRow.value = null
}
}
)
// tableData //
watch( const selectedRow = ref<any>(null)
() => props.tableData,
() => {
if (props.singleSelect) {
selectedRadioRow.value = null
}
}
)
// //
const handleSelectionChange = (rows: any[]) => { const handleSelectionChange = (rows: any[]) => {
@ -444,11 +436,6 @@ const handleCurrentChange = (row: any) => {
emit('current-change', row) emit('current-change', row)
} }
const tableRef = ref<TableInstance>()
//
const selectedRow = ref<any>(null)
// //
const handleRowClick = (row: any) => { const handleRowClick = (row: any) => {
if (!row) return if (!row) return
@ -467,23 +454,17 @@ const handleRowContextmenu = (row: any, column: any, event: MouseEvent) => {
emit('row-contextmenu', row, column, event) emit('row-contextmenu', row, column, event)
} }
// tableData // tableData /
watch( watch(
() => props.tableData, () => props.tableData,
() => { () => {
if (props.singleSelect) { if (props.singleSelect) {
selectedRadioRow.value = null selectedRadioRow.value = null
} }
}
)
// tableData
watch(
() => props.tableData,
() => {
selectedRow.value = null selectedRow.value = null
tableRef.value?.setCurrentRow(null) tableRef.value?.setCurrentRow(null)
}, },
{ deep: true }, { deep: true }
) )
// //

View File

@ -48,8 +48,6 @@ 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())
// ------------------ 初始化 ------------------ // ------------------ 初始化 ------------------
@ -120,24 +118,21 @@ export const useTransactionStore = defineStore('transaction', () => {
* account_id:float_profit_loss:close_profit_loss (84:0.000000:0.000000) * account_id:float_profit_loss:close_profit_loss (84:0.000000:0.000000)
*/ */
const handleMarketFloatProfit = (data: string): void => { const handleMarketFloatProfit = (data: string): void => {
console.log('data:', data);
if (!data) return if (!data) return
const fields = data.split(':') const fields = data.split(':')
if (fields.length < 3) return if (fields.length < 2) return
const account_id = fields[0] const account_id = fields[0]
const float_profit_loss = fields[1] as string 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)
console.log('marketFloatProfitMap.value:', marketFloatProfitMap.value);
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)
} }
// ------------------ 持仓列表 ------------------ // ------------------ 持仓列表 ------------------
@ -178,7 +173,6 @@ export const useTransactionStore = defineStore('transaction', () => {
mqttClient?.disconnect() mqttClient?.disconnect()
positionList.value = [] positionList.value = []
marketFloatProfitMap.value.clear() marketFloatProfitMap.value.clear()
marketCloseProfitMap.value.clear()
} }
/** /**
@ -193,7 +187,6 @@ export const useTransactionStore = defineStore('transaction', () => {
mqttClient, mqttClient,
positionList, positionList,
marketFloatProfitMap, marketFloatProfitMap,
marketCloseProfitMap,
initMarketConditionsMQTT, initMarketConditionsMQTT,
getPositionList, getPositionList,
requestMarketFloatProfit, requestMarketFloatProfit,