import { useRef, useState } from 'react' import { Building2, Save, Upload, Sparkles } from 'lucide-react' import type { CompanyProfile } from '../types' import { extractProfileFromText } from '../lib/profileImport' import { useStore } from '../lib/store' import Pill from '../components/ui-ext/Pill' import { PrimaryButton, GhostButton } from '../components/ui-ext/AiButton' import { cn } from '@/lib/utils' interface FieldDef { key: keyof CompanyProfile label: string placeholder: string textarea?: boolean } const GROUPS: { title: string; desc: string; fields: FieldDef[] }[] = [ { title: '企业基本情况', desc: '明确研究主体和企业背景', fields: [ { key: 'companyName', label: '企业名称', placeholder: '请输入完整企业名称' }, { key: 'intro', label: '企业简介', placeholder: '简要介绍公司背景、规模与发展阶段', textarea: true }, ], }, { title: '业务与产品', desc: '帮助 AI 理解公司具体能做什么', fields: [ { key: 'mainBusiness', label: '主营业务', placeholder: '如:智慧水务平台建设、水质监测设备' }, { key: 'products', label: '产品与服务', placeholder: '如:DMA 分区计量系统、管网漏损分析平台', textarea: true }, { key: 'advantages', label: '核心优势', placeholder: '如:自研漏损算法、本地化交付团队', textarea: true }, ], }, { title: '目标市场', desc: '用于提供贴合公司的建议,不会自动限制检索范围', fields: [ { key: 'serviceRegions', label: '服务地区', placeholder: '如:浙江、江苏、上海;或 全国' }, { key: 'customerTypes', label: '客户类型', placeholder: '如:水务集团、住建局、园区管委会' }, { key: 'projectTypes', label: '项目类型偏好', placeholder: '如:软件平台、监测设备、运营服务' }, { key: 'amountPreference', label: '金额偏好', placeholder: '如:100-2000 万元' }, ], }, { title: '资质与认证', desc: '对照公告参与条件;没有的可填「暂无」,资料缺失与确实不具备应区分', fields: [ { key: 'qualifications', label: '资质与认证', placeholder: '如:电子与智能化工程专业承包二级(有效期至 2028-06);软件著作权 6 项', textarea: true }, ], }, { title: '代表业绩', desc: '对照公告同类业绩与实施经验要求', fields: [ { key: 'trackRecord', label: '代表业绩', placeholder: '如:2025 年某市供水管网漏损治理项目(540 万元,已通过验收)', textarea: true }, ], }, { title: '交付能力', desc: '解释实施和履约条件', fields: [ { key: 'delivery', label: '交付与售后', placeholder: '如:自有实施团队 12 人,支持驻场;提供 7×24 响应', textarea: true }, ], }, { title: '投标准备', desc: '用于提醒时间是否紧张', fields: [ { key: 'bidPreparation', label: '典型准备周期与限制', placeholder: '如:常规标书准备约 7 天,涉及现场勘察需 10 天以上' }, ], }, { title: '参与边界', desc: '明确不参与或需谨慎的项目类型', fields: [ { key: 'boundaries', label: '参与边界', placeholder: '如:不参与需要垫资的工程施工总承包项目', textarea: true }, ], }, ] // 最低填写要求(演示口径):企业名称 + 主营业务 const FIELD_LABELS: Record = Object.fromEntries( GROUPS.flatMap(g => g.fields.map(f => [f.key, f.label])), ) const inputCls = 'rounded-ctrl border border-line-soft bg-white px-3 py-2 text-[13px] text-ink-900 outline-none transition-shadow placeholder:text-ink-400 focus:border-brand-500/60 focus:ring-2 focus:ring-brand-500/10' export function ProfilePage() { const { profile, saveProfile } = useStore() const [busy, setBusy] = useState(false) const [error, setError] = useState('') const [form, setForm] = useState({ ...profile }) const [savedTip, setSavedTip] = useState(null) const fileRef = useRef(null) const [imported, setImported] = useState | null>(null) const [importError, setImportError] = useState('') const set = (key: keyof CompanyProfile, value: string) => { setForm(f => ({ ...f, [key]: value })) setSavedTip(null) } const onImportFile = async (e: React.ChangeEvent) => { const f = e.target.files?.[0] e.target.value = '' if (!f) return if (f.size > 2 * 1024 * 1024) { setImportError('介绍文件不能超过 2 MB,请精简后导入'); return } try { const text = await f.text() const extracted = extractProfileFromText(text) if (Object.keys(extracted).length === 0) { setImportError('没有从文件中识别到可填入的内容,可换一份更完整的介绍文件再试。') setImported(null) return } setImportError(''); setImported(extracted) } catch { setImportError('文件读取失败,请重新选择 TXT 或 Markdown 文件') } } const applyImport = () => { if (!imported) return setForm(f => ({ ...f, ...imported })) setImported(null) setSavedTip(null) } const save = async () => { if (busy) return setBusy(true); setError(''); setSavedTip(null) try { // 完善状态和版本必须使用服务端结果;保存失败时不显示成功或递增本地版本。 const saved = await saveProfile(form) setForm(saved) setSavedTip(saved.completed ? '档案已保存,已达到企业名称与主营业务的最低要求。' : '档案已保存;补充企业名称与主营业务后才能生成匹配度。') } catch (error) { setError(error instanceof Error ? error.message : '保存失败') } finally { setBusy(false) } } return (

公司档案

{profile.completed && ( v{profile.version} · 更新于 {profile.updatedAt ? new Intl.DateTimeFormat('zh-CN', { timeZone: 'Asia/Shanghai', dateStyle: 'short', timeStyle: 'short', hour12: false }).format(new Date(profile.updatedAt)) : '尚未保存'} )} fileRef.current?.click()} title="按关键词识别 TXT / Markdown 字段,核对后写入表单"> AI 导入 void save()} disabled={busy} loading={busy}> 保存档案
{error &&

{error}

} {importError && (
{importError}
)} {imported && (
已从文件抽取以下内容 请核对后写入,写入前不会改动当前表单
    {Object.entries(imported).map(([k, v]) => (
  • {FIELD_LABELS[k] ?? k}: {String(v)}
  • ))}
setImported(null)} className="!px-3 !py-1.5 text-xs">放弃 核对无误,写入表单
)} {savedTip && (
{savedTip}
)}
{GROUPS.map(g => (

{g.title}

{g.desc}

{g.fields.map(f => (
{f.textarea ? (