调整存储的逻辑

This commit is contained in:
zwgczx committed 2026-03-10 17:48:12 +08:00
1 parent bbc8777b74
commit 3ad7bae1a9
9 files changed
+285 -141

No files matched your search

+4 -43
View File
@@ -1,21 +1,6 @@
import localforage from 'localforage'
import { toFiniteNumberOrNull } from '@/lib/number'
import { useZxFwPricingStore, type ZxFwPricingField } from '@/pinia/zxFwPricing'
export type ZxFwPricingField = 'investScale' | 'landScale' | 'workload' | 'hourly'
interface ZxFwDetailRow {
id: string
investScale: number | null
landScale: number | null
workload: number | null
hourly: number | null
}
interface ZxFwState {
selectedIds?: string[]
selectedCodes?: string[]
detailRows: ZxFwDetailRow[]
}
export type { ZxFwPricingField } from '@/pinia/zxFwPricing'
export const ZXFW_RELOAD_SERVICE_KEY = 'zxfw-main'
@@ -25,30 +10,6 @@ export const syncPricingTotalToZxFw = async (params: {
field: ZxFwPricingField
value: number | null | undefined
}) => {
const dbKey = `zxFW-${params.contractId}`
const data = await localforage.getItem<ZxFwState>(dbKey)
if (!data?.detailRows?.length) return false
const targetServiceId = String(params.serviceId)
const nextValue = toFiniteNumberOrNull(params.value)
let changed = false
const nextRows = data.detailRows.map(row => {
if (String(row.id) !== targetServiceId) return row
const currentValue = toFiniteNumberOrNull(row[params.field])
if (currentValue === nextValue) return row
changed = true
return {
...row,
[params.field]: nextValue
}
})
if (!changed) return false
await localforage.setItem(dbKey, {
...data,
detailRows: nextRows
})
return true
const store = useZxFwPricingStore()
return store.updatePricingField(params)
}