2026-05-24 01:48:04 +08:00
|
|
|
|
import type { MediaPlatform } from '@geo/shared-types'
|
2026-04-25 22:45:29 +08:00
|
|
|
|
|
2026-04-18 00:47:57 +08:00
|
|
|
|
export interface KolPlatformOption {
|
2026-05-01 20:39:09 +08:00
|
|
|
|
label: string
|
|
|
|
|
|
value: string
|
2026-05-24 01:48:04 +08:00
|
|
|
|
disabled?: boolean
|
2026-04-18 00:47:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-24 01:48:04 +08:00
|
|
|
|
export const KOL_PLATFORM_HINT_DEFAULT = '通用'
|
|
|
|
|
|
|
|
|
|
|
|
export function buildKolPlatformOptions(
|
|
|
|
|
|
defaultLabel: string,
|
|
|
|
|
|
platforms: MediaPlatform[] = [],
|
|
|
|
|
|
selectedValues: string[] = [],
|
|
|
|
|
|
): KolPlatformOption[] {
|
|
|
|
|
|
const defaultSelected = selectedValues.includes(KOL_PLATFORM_HINT_DEFAULT)
|
|
|
|
|
|
const options = [
|
2026-05-01 20:39:09 +08:00
|
|
|
|
{ label: defaultLabel, value: '通用' },
|
2026-05-24 01:48:04 +08:00
|
|
|
|
...platforms.map((item) => ({
|
|
|
|
|
|
label: item.name,
|
|
|
|
|
|
value: item.name,
|
|
|
|
|
|
disabled: defaultSelected,
|
|
|
|
|
|
})),
|
2026-05-01 20:39:09 +08:00
|
|
|
|
]
|
2026-05-24 01:48:04 +08:00
|
|
|
|
const knownValues = new Set(options.map((item) => item.value))
|
|
|
|
|
|
const customOptions = normalizeKolPlatformHints(selectedValues)
|
|
|
|
|
|
.filter((value) => !knownValues.has(value))
|
|
|
|
|
|
.map((value) => ({ label: value, value }))
|
|
|
|
|
|
|
|
|
|
|
|
return [...customOptions, ...options]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function parseKolPlatformHints(value?: string | null): string[] {
|
|
|
|
|
|
return normalizeKolPlatformHints(String(value ?? '').split(/[、,,;\n]+/))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function normalizeKolPlatformHints(values?: Array<string | null | undefined>): string[] {
|
|
|
|
|
|
const next = Array.from(
|
|
|
|
|
|
new Set((values ?? []).map((item) => String(item ?? '').trim()).filter(Boolean)),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if (next.includes(KOL_PLATFORM_HINT_DEFAULT)) {
|
|
|
|
|
|
return [KOL_PLATFORM_HINT_DEFAULT]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return next
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function serializeKolPlatformHints(values?: Array<string | null | undefined>): string {
|
|
|
|
|
|
return normalizeKolPlatformHints(values).join('、')
|
2026-04-18 00:47:57 +08:00
|
|
|
|
}
|