Files
zkxw/web-admin/src/utils/project-management.ts
T
zlwuandCursor a598b17ab9 fix(web-admin): 项目业务类型下拉去掉中试服务可选 (#162)
新建不可选中试;旧项目已含 pilot_service 时编辑仍展示该选项。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 15:15:54 +08:00

88 lines
2.6 KiB
TypeScript

import type { BizType, ProjectRecord } from '@/api/project-management'
/**
* 项目新建/编辑弹窗「业务类型」选项。
* 中试服务已下线:默认不可选;若旧项目已含 pilot_service 则保留展示。
*/
export function projectBizTypeSelectLabels(
allLabels: Record<string, string>,
selectedBizTypes?: string[] | null
): Record<string, string> {
const selected = new Set((selectedBizTypes || []).filter(Boolean))
return Object.fromEntries(
Object.entries(allLabels).filter(([key]) => {
if (key === 'presign') return false
if (key === 'pilot_service') return selected.has('pilot_service')
return true
})
)
}
/** Drill-down uses the last successful statistics query, never unsaved filter edits. */
export function buildDrillFilters(
applied: ProjectRecord,
row: ProjectRecord,
bizType: BizType
): ProjectRecord {
const { groupBy, ...filters } = applied
const result = { ...filters, bizType, unassigned: row.id === 'unassigned' } as ProjectRecord
if (!result.unassigned && row.id !== 'total') {
result[groupBy === 'team' ? 'teamId' : 'projectId'] = row.id
}
return result
}
export function assignmentSnapshot(records: ProjectRecord[]) {
return records.map(({ bizType, id, projectId }) => ({
bizType,
id,
projectId: projectId ?? null
}))
}
/** Write bodies intentionally exclude response-only labels and timestamps. */
export function managementPayload(kind: 'teams' | 'projects', form: ProjectRecord): ProjectRecord {
const fields =
kind === 'teams'
? ['teamName', 'leaderUserId', 'enabled', 'remark']
: [
'projectName',
'projectNo',
'teamId',
'leaderUserId',
'bizTypes',
'startDate',
'endDate',
'status',
'remark'
]
const data = Object.fromEntries(
fields.filter((key) => form[key] !== undefined).map((key) => [key, form[key]])
)
if (kind === 'teams') {
for (const [key, field] of [
['members', 'userId'],
['regions', 'regionId'],
['hospitals', 'hospitalId']
]) {
data[key] = (form[key] || []).map((row: ProjectRecord) => ({
...(row.id ? { id: row.id } : {}),
[field]: row[field]
}))
}
}
return data
}
export function projectOptionsParams(bizType: BizType, filter = false) {
return filter ? { bizType, usage: 'filter' as const } : { bizType }
}
/** List cells join child display names; empty entries are dropped. */
export function joinChildNames(items?: ProjectRecord[]) {
return (items || [])
.map((item) => item?.name)
.filter(Boolean)
.join('、')
}