/** * 直播切片专用字段:直播日期 / 主播(可关联用户)/ 直播平台 */ 'use client' import Select from '@/components/ui/Select' import { useEffect, useState } from 'react' import { fieldControlClass, fieldHintClass, fieldLabelClass, } from '@/components/upload/upload-field-styles' import { getDefaultLiveDate, LIVE_CLIP_PLATFORMS, } from '@/lib/live-clip' export interface LiveClipFieldsProps { liveDate: string liveHost: string liveHostUserId: string livePlatform: string onLiveDateChange: (value: string) => void onLiveHostChange: (value: string) => void onLiveHostUserIdChange: (value: string) => void onLivePlatformChange: (value: string) => void } interface UserOption { id: string displayName: string username: string } export default function LiveClipFields({ liveDate, liveHost, liveHostUserId, livePlatform, onLiveDateChange, onLiveHostChange, onLiveHostUserIdChange, onLivePlatformChange, }: LiveClipFieldsProps) { const [users, setUsers] = useState([]) const [usersLoaded, setUsersLoaded] = useState(false) useEffect(() => { if (!liveDate) { onLiveDateChange(getDefaultLiveDate()) } // 仅在日期为空时补默认值,避免依赖回调导致循环 // eslint-disable-next-line react-hooks/exhaustive-deps }, []) useEffect(() => { let cancelled = false fetch('/api/users/list') .then((res) => (res.ok ? res.json() : [])) .then((data: UserOption[]) => { if (!cancelled && Array.isArray(data)) { setUsers(data) setUsersLoaded(true) } }) .catch(() => { if (!cancelled) setUsersLoaded(true) }) return () => { cancelled = true } }, []) return ( <>
onLiveDateChange(e.target.value)} className={fieldControlClass} max={getDefaultLiveDate()} />

默认上传当天,可按日历修改

onLiveHostChange(e.target.value)} className={fieldControlClass} maxLength={50} placeholder="填写主播昵称" />
) }