8e2c563b42
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import type { ConfigDisplayFields } from "../types/templateLibrary"
|
|
import {
|
|
TEMPLATE_TYPES,
|
|
CATEGORY_GRADIENT_MAP,
|
|
DEFAULT_GRADIENT,
|
|
MATERIAL_TYPE_LABELS,
|
|
} from "../constants/templateLibrary"
|
|
import type { TemplateSegment } from "@/api/templates"
|
|
|
|
/** 获取类型对应颜色 */
|
|
export const getTypeColor = (type: string): string => {
|
|
const found = TEMPLATE_TYPES.find((t) => t.type === type)
|
|
return found?.color ?? "#6366f1"
|
|
}
|
|
|
|
/** 根据 category 生成占位渐变色 */
|
|
export const gradientForCategory = (category: string): string => {
|
|
return CATEGORY_GRADIENT_MAP[category] ?? DEFAULT_GRADIENT
|
|
}
|
|
|
|
/** 格式化时长 */
|
|
export const formatDuration = (seconds: number | undefined | null): string => {
|
|
if (!seconds || seconds <= 0) return "0秒"
|
|
const totalSec = Math.round(seconds)
|
|
const m = Math.floor(totalSec / 60)
|
|
const s = totalSec % 60
|
|
if (m === 0) return `${s}秒`
|
|
return `${m}分${s > 0 ? `${s}秒` : ""}`
|
|
}
|
|
|
|
/** 格式化配置对象为可读文本 */
|
|
export const formatConfig = (config?: object): string => {
|
|
if (!config || Object.keys(config).length === 0) return "默认"
|
|
const c = config as ConfigDisplayFields
|
|
const parts: string[] = []
|
|
if (c.font_size) parts.push(`字号: ${c.font_size}`)
|
|
if (c.font_family) parts.push(`字体: ${c.font_family}`)
|
|
if (c.color) parts.push(`颜色: ${c.color}`)
|
|
if (c.position) parts.push(`位置: ${c.position}`)
|
|
if (c.volume !== undefined) parts.push(`音量: ${c.volume}%`)
|
|
if (c.name) parts.push(String(c.name))
|
|
return parts.length > 0 ? parts.join(" / ") : JSON.stringify(config)
|
|
}
|
|
|
|
/** 获取素材类型标签文本 */
|
|
export const getMaterialTypeLabel = (materialType: string | null | undefined): string => {
|
|
if (!materialType) return "不限"
|
|
return MATERIAL_TYPE_LABELS[materialType] ?? materialType
|
|
}
|
|
|
|
/** 计算片段总时长(取每个片段 min/max 的平均值) */
|
|
export const calcTotalSegmentDuration = (segments: TemplateSegment[]): number => {
|
|
return segments.reduce((sum, s) => sum + (s.duration_min + s.duration_max) / 2, 0)
|
|
}
|