import { useState } from 'react' import { useStore } from '../lib/store' import { defaultMatchDimNames } from '../types' import { message } from '../lib/day2' import { PrototypeDialog } from './PrototypeDialog' import { GhostButton, PrimaryButton } from './ui-ext/AiButton' /** 权重入口回到原型检索栏;继续使用服务端档案版本,失败时保留草稿和弹窗。 */ export function MatchWeightsDialog({ onClose }: { onClose: () => void }) { const { profile, saveProfile } = useStore() const [draft, setDraft] = useState({ ...profile.matchWeights }) const [busy, setBusy] = useState(false), [error, setError] = useState('') const total = Object.values(draft).reduce((sum, value) => sum + value, 0) const save = async () => { if (busy || !total) return setBusy(true); setError('') try { await saveProfile({ ...profile, matchWeights: draft }); onClose() } catch (e) { setError(message(e)) } finally { setBusy(false) } } return { if (!busy) onClose() }} title="匹配度权重">

拖动滑块调整各维度权重;合计不为 100 时按比例折算。

{(Object.keys(defaultMatchDimNames) as (keyof typeof draft)[]).map(key => )}
{total !== 100 &&

当前合计 {total}%,{total ? '保存后按比例折算为 100% 参与计分' : '至少设置一个非零权重'}

} {error &&

{error}

}
取消 void save()}>保存权重
}