import { useRef, useState } from 'react' import { Building2, Save, Upload, Sparkles } from 'lucide-react' import type { CompanyProfile } from '../types' 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 }, ], }, ] // 最低填写要求(演示口径):企业名称 + 主营业务 function meetsMinimum(p: CompanyProfile): boolean { return p.companyName.trim() !== '' && p.mainBusiness.trim() !== '' } // 演示环境的 AI 导入抽取:基于关键词的启发式匹配,正式接入后由 AI 模型从文件中抽取 function extractProfileFromText(text: string): Partial { const lines = text.split(/\r?\n/).map(l => l.trim()).filter(Boolean) const pick = (re: RegExp) => { const line = lines.find(l => re.test(l)) return line ? line.replace(/^[-*•\d.、\s]+/, '').slice(0, 300) : undefined } const out: Partial = {} const put = (key: keyof CompanyProfile, v?: string) => { if (v) (out as Record)[key] = v } put('companyName', pick(/有限公司|股份公司|集团/)) put('intro', pick(/简介|成立于|是一家/)) put('mainBusiness', pick(/主营|主营业务|专注于|从事/)) put('products', pick(/产品|服务包括|解决方案/)) put('advantages', pick(/优势|擅长|自研/)) put('serviceRegions', pick(/地区|区域|覆盖|浙江|江苏|上海|安徽|华东|全国/)) put('customerTypes', pick(/客户/)) put('projectTypes', pick(/项目类型|偏好/)) put('amountPreference', pick(/\d+\s*[-~至]\s*\d+\s*万/)) put('qualifications', pick(/资质|认证|证书|软著|专利/)) put('trackRecord', pick(/业绩|案例|验收|中标/)) put('delivery', pick(/交付|售后|驻场|响应/)) put('bidPreparation', pick(/标书|准备周期|投标准备/)) put('boundaries', pick(/不参与|边界|谨慎/)) return out } 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 [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 const text = await f.text() const extracted = extractProfileFromText(text) if (Object.keys(extracted).length === 0) { setImportError('没有从文件中识别到可填入的内容,可换一份更完整的介绍文件再试。') setImported(null) return } setImportError('') setImported(extracted) } const applyImport = () => { if (!imported) return setForm(f => ({ ...f, ...imported })) setImported(null) setSavedTip(null) } const save = () => { const completed = meetsMinimum(form) saveProfile({ ...form, completed }) setForm(f => ({ ...f, completed })) setSavedTip(completed ? '档案已保存并标记为「已完善」,项目分析将结合公司情况给出有依据的建议。' : '已保存,但尚未达到「已完善」的最低要求(需填写企业名称与主营业务),匹配度暂不生成。') } return (

公司档案

{profile.completed && ( v{profile.version} · 更新于 {profile.updatedAt} )} fileRef.current?.click()}> AI 导入 保存档案
{importError && (
{importError}
)} {imported && (
AI 已从文件抽取以下内容 请核对后写入,写入前不会改动当前表单
    {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 ? (