Files
cz-web/src/utils/bizTypeMeta.ts
2026-10-01 17:24:57 +08:00

52 lines
1.6 KiB
TypeScript

//
// label ← title
// desc ← subtitle
//
import type { BizIconKey, BizTypeOption, SubmissionBizTypeVo } from '@/types/business/demand'
import { toAssetUrl } from '@/utils/asset'
interface BizMeta {
desc: string
icon: BizIconKey
}
const BIZ_META: Record<string, BizMeta> = {
互联网软件: { desc: 'Web/小程序/APP/二次开发/桌面工具等', icon: 'code' },
硬件电路: { desc: '原理图设计/PCB设计/电气效验等', icon: 'chip' },
物联网全案: { desc: '软硬件开发+云端一体化/定制化开发等', icon: 'iot' },
生产制造: { desc: 'PCB制版/SMT/整机装配/定制生产等', icon: 'factory' },
其他: { desc: '若没有对应的服务内容请选择该选项', icon: 'other' },
}
export function toBizTypeOption(
vo: SubmissionBizTypeVo,
ossUrlById: Record<string, string> = {},
): BizTypeOption | null {
const value = (vo.businessType ?? '').trim() || (vo.title ?? '').trim()
if (!value) return null
const label = (vo.title ?? '').trim() || value
const meta = BIZ_META[value]
const subtitle = (vo.subtitle ?? '').trim()
const desc = subtitle && subtitle !== value && subtitle !== label
? subtitle
: (meta?.desc ?? '')
const logoRaw = (vo.logoUrl ?? '').trim()
return {
value,
label,
desc,
icon: meta?.icon ?? 'other',
iconUrl: toAssetUrl(logoRaw) || ossUrlById[logoRaw] || '',
}
}
export function toBizTypeOptionFromDict(value: string, label: string): BizTypeOption {
const meta = BIZ_META[value]
return {
value,
label,
desc: meta?.desc ?? '',
icon: meta?.icon ?? 'other',
}
}