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
}>()
// Store
const route = useRoute()
const userStore = useUserStore()
// key 使
const CACHE_VERSION = 'v1'
// key
const getCacheKey = () => {
const baseKey = props.columnSettingStorageKey || String(route.name || route.path)
const userId = String(userStore.userInfo?.id || 'guest')
return `table-column-setting-${baseKey}-${userId}`
const baseKey = props.columnSettingStorageKey
|| String((route.name as string) || route.path || 'default')
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 = () => {
if (!props.columns || props.columns.length === 0) {
localColumns.value = []
return
}
//
const cacheKey = getCacheKey()
let cachedConfig: any[] = []
const cached = localStorage.getItem(cacheKey)
if (cached) {
try {
const cachedConfig = JSON.parse(cached)
// sortOrder
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)
const parsed = JSON.parse(cached)
if (Array.isArray(parsed)) cachedConfig = parsed
} catch {
// 使
localColumns.value = props.columns.map((col) => ({
...col,
visible: col.visible !== false,
fixed: col.fixed || false,
}))
cachedConfig = []
}
} 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 config = localColumns.value.map((col, index) => ({
prop: col.prop,
visible: col.visible,
label: col.label,
width: col.width,
slotName: col.slotName,
key: getColumnKey(col),
visible: col.visible !== false,
sortOrder: index,
}))
localStorage.setItem(getCacheKey(), JSON.stringify(config))
@ -390,48 +397,33 @@ const handleReset = () => {
}
// columns
// columns /
//
let lastColumnsKey = ''
watch(
() => props.columns,
(newColumns) => {
if (newColumns && newColumns.length > 0) {
//
if (localColumns.value.length === 0) {
initColumns()
}
}
if (!newColumns || newColumns.length === 0) return
// + key
const newKey = newColumns.map((c) => getColumnKey(c)).join('|')
if (newKey === lastColumnsKey && localColumns.value.length > 0) return
lastColumnsKey = newKey
initColumns()
},
{ immediate: true }
{ immediate: true, deep: true }
)
//
//
onMounted(() => {
// props.columns
setTimeout(() => {
if (props.columns && props.columns.length > 0 && localColumns.value.length === 0) {
initColumns()
}
}, 100)
if (props.columns && props.columns.length > 0 && localColumns.value.length === 0) {
initColumns()
}
})
// tableData
watch(
() => props.tableData,
() => {
if (props.singleSelect) {
selectedRadioRow.value = null
}
}
)
const tableRef = ref<TableInstance>()
// tableData
watch(
() => props.tableData,
() => {
if (props.singleSelect) {
selectedRadioRow.value = null
}
}
)
//
const selectedRow = ref<any>(null)
//
const handleSelectionChange = (rows: any[]) => {
@ -444,11 +436,6 @@ const handleCurrentChange = (row: any) => {
emit('current-change', row)
}
const tableRef = ref<TableInstance>()
//
const selectedRow = ref<any>(null)
//
const handleRowClick = (row: any) => {
if (!row) return
@ -467,23 +454,17 @@ const handleRowContextmenu = (row: any, column: any, event: MouseEvent) => {
emit('row-contextmenu', row, column, event)
}
// tableData
// tableData /
watch(
() => props.tableData,
() => {
if (props.singleSelect) {
selectedRadioRow.value = null
}
}
)
// tableData
watch(
() => props.tableData,
() => {
selectedRow.value = null
tableRef.value?.setCurrentRow(null)
},
{ deep: true },
{ deep: true }
)
//

View File

@ -48,8 +48,6 @@ export const useTransactionStore = defineStore('transaction', () => {
const positionList = ref<PositionItem[]>([])
/** 做市商浮动盈亏数据 Map<account_id, float_profit_loss> */
const marketFloatProfitMap = ref<Map<string, string>>(new Map())
/** 做市商平仓盈亏数据 Map<account_id, close_profit_loss> */
const marketCloseProfitMap = ref<Map<string, string>>(new Map())
// ------------------ 初始化 ------------------
@ -120,23 +118,20 @@ export const useTransactionStore = defineStore('transaction', () => {
* account_id:float_profit_loss:close_profit_loss (84:0.000000:0.000000)
*/
const handleMarketFloatProfit = (data: string): void => {
console.log('data:', data);
if (!data) return
const fields = data.split(':')
if (fields.length < 3) return
if (fields.length < 2) return
const account_id = fields[0]
const float_profit_loss = fields[1] as string
const close_profit_loss = fields[2] as string
const float_profit_loss = fields[1] as string
// 更新浮动盈亏 Map
marketFloatProfitMap.value.set(account_id, float_profit_loss)
console.log('marketFloatProfitMap.value:', 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()
positionList.value = []
marketFloatProfitMap.value.clear()
marketCloseProfitMap.value.clear()
}
/**
@ -193,7 +187,6 @@ export const useTransactionStore = defineStore('transaction', () => {
mqttClient,
positionList,
marketFloatProfitMap,
marketCloseProfitMap,
initMarketConditionsMQTT,
getPositionList,
requestMarketFloatProfit,