This commit is contained in:
zwgczx committed 2026-03-13 18:27:42 +08:00
1 parent d5cae61861
commit eb415cd0d0
33 files changed
+2642 -382

No files matched your search

+112
View File
@@ -0,0 +1,112 @@
import {
getIndustryTypeValue,
getMajorDictEntries,
getServiceDictEntries,
isIndustryEnabledByType,
isMajorIdInIndustryScope
} from '@/sql'
interface KvStoreLike {
setItem: <T = unknown>(keyRaw: string | number, value: T) => Promise<void>
}
type DictItemLite = {
code?: string
name?: string
defCoe?: number | null
notshowByzxflxs?: boolean
}
type FactorPersistRow = {
id: string
code: string
name: string
standardFactor: number | null
budgetValue: number | null
remark: string
path: string[]
}
type FactorPersistState = {
detailRows: FactorPersistRow[]
}
const buildCodePath = (code: string, selfId: string, codeIdMap: Map<string, string>) => {
const parts = code.split('-').filter(Boolean)
if (!parts.length) return [selfId]
const path: string[] = []
let currentCode = parts[0]
const firstId = codeIdMap.get(currentCode)
if (firstId) path.push(firstId)
for (let index = 1; index < parts.length; index += 1) {
currentCode = `${currentCode}-${parts[index]}`
const id = codeIdMap.get(currentCode)
if (id) path.push(id)
}
if (!path.length || path[path.length - 1] !== selfId) path.push(selfId)
return path
}
const buildFactorRowsFromEntries = (entries: Array<{ id: string; item: DictItemLite }>): FactorPersistRow[] => {
const codeIdMap = new Map<string, string>()
for (const entry of entries) {
const code = String(entry.item?.code || '').trim()
if (!code) continue
codeIdMap.set(code, entry.id)
}
return entries
.map(entry => {
const code = String(entry.item?.code || '').trim()
const name = String(entry.item?.name || '').trim()
if (!code || !name) return null
const standardFactor =
typeof entry.item?.defCoe === 'number' && Number.isFinite(entry.item.defCoe)
? entry.item.defCoe
: null
return {
id: entry.id,
code,
name,
standardFactor,
budgetValue: standardFactor,
remark: '',
path: buildCodePath(code, entry.id, codeIdMap)
}
})
.filter((item): item is FactorPersistRow => Boolean(item))
}
export const initializeProjectFactorStates = async (
kvStore: KvStoreLike,
industry: string,
consultCategoryFactorKey: string,
majorFactorKey: string
) => {
const industryType = getIndustryTypeValue(industry)
const consultEntries = getServiceDictEntries()
.map(({ id, item }) => ({ id, item: item as DictItemLite }))
.filter(({ item }) => {
if (item.notshowByzxflxs === true) return false
return isIndustryEnabledByType(item as Record<string, unknown>, industryType)
})
const majorEntries = getMajorDictEntries()
.map(({ id, item }) => ({ id, item: item as DictItemLite }))
.filter(({ id, item }) => item.notshowByzxflxs !== true && isMajorIdInIndustryScope(id, industry))
const consultPayload: FactorPersistState = {
detailRows: buildFactorRowsFromEntries(consultEntries)
}
const majorPayload: FactorPersistState = {
detailRows: buildFactorRowsFromEntries(majorEntries)
}
await Promise.all([
kvStore.setItem(consultCategoryFactorKey, consultPayload),
kvStore.setItem(majorFactorKey, majorPayload)
])
}
+52
View File
@@ -0,0 +1,52 @@
export type WorkspaceMode = 'home' | 'project' | 'quick'
export const HOME_TAB_ID = 'HomeView'
export const PROJECT_TAB_ID = 'ProjectCalcView'
export const QUICK_TAB_ID = 'QuickCalcView'
export const LEGACY_PROJECT_TAB_ID = 'XmView'
export const FIXED_WORKSPACE_TAB_IDS = [PROJECT_TAB_ID, QUICK_TAB_ID] as const
export const WORKSPACE_MODE_STORAGE_KEY = 'jgjs-workspace-mode-v1'
export const QUICK_CONTRACT_ID = 'quick-contract-default'
export const QUICK_CONTRACT_META_KEY = 'quick-contract-meta-v1'
export const QUICK_CONTRACT_FALLBACK_NAME = '快速计算合同'
export const QUICK_CONTRACT_TAB_ID = `contract-${QUICK_CONTRACT_ID}`
export const QUICK_PROJECT_INFO_KEY = 'quick-xm-base-info-v1'
export const QUICK_PROJECT_SCALE_KEY = 'quick-xm-info-v3'
export const QUICK_CONSULT_CATEGORY_FACTOR_KEY = 'quick-xm-consult-category-factor-v1'
export const QUICK_MAJOR_FACTOR_KEY = 'quick-xm-major-factor-v1'
export interface QuickContractMeta {
id: string
name: string
updatedAt: string
}
export const normalizeWorkspaceMode = (value: unknown): WorkspaceMode => {
if (value === 'project' || value === 'quick' || value === 'home') return value
return 'home'
}
export const readWorkspaceMode = (): WorkspaceMode => {
try {
return normalizeWorkspaceMode(window.localStorage.getItem(WORKSPACE_MODE_STORAGE_KEY))
} catch {
return 'home'
}
}
export const writeWorkspaceMode = (mode: WorkspaceMode) => {
try {
window.localStorage.setItem(WORKSPACE_MODE_STORAGE_KEY, normalizeWorkspaceMode(mode))
} catch {
// 忽略只读或隐私模式下的写入失败。
}
}
export const createDefaultQuickContractMeta = (): QuickContractMeta => ({
id: QUICK_CONTRACT_ID,
name: QUICK_CONTRACT_FALLBACK_NAME,
updatedAt: new Date().toISOString()
})