Build business demand registration workspace from SOP
This commit is contained in:
commit
4556a5b483
126 files changed
+25398
No files matched your search
@@ -0,0 +1,36 @@
|
||||
'use client';
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { House, Files, SquareCheck, Folder, BookOpen, CalendarDays, ChevronRight, UserRound, CheckCircle2, CircleAlert, RotateCw } from 'lucide-react';
|
||||
import { Dashboard } from './dashboard';
|
||||
import { DemandForm, type SaveInput } from './form';
|
||||
import { DemandDetail } from './detail';
|
||||
import { Guide } from './guide';
|
||||
import { demoDemands } from '@/lib/demo';
|
||||
import { type Demand, needsAction } from '@/lib/demand';
|
||||
const navItems=[{icon:House,label:'我的工作台'},{icon:Files,label:'我的需求'},{icon:SquareCheck,label:'待我处理'},{icon:Folder,label:'草稿箱'}];
|
||||
export default function DemandApp({userName,today}:{userName:string;today:string}){
|
||||
const [view,setView]=useState('我的工作台');const [actual,setActual]=useState<Demand[]>([]);const [examples,setExamples]=useState<Demand[]>(demoDemands);const [demo,setDemo]=useState(true);const [loading,setLoading]=useState(true);const [loadError,setLoadError]=useState('');const [actionError,setActionError]=useState('');const [busy,setBusy]=useState(false);const [toast,setToast]=useState('');const [selected,setSelected]=useState<Demand|null>(null);const [form,setForm]=useState<{initial?:Demand}|null>(null);const [dashboardKey,setDashboardKey]=useState(0);
|
||||
const demands=demo?examples:actual;const latest=useRef(demands);latest.current=demands;
|
||||
const load=useCallback(async()=>{setLoading(true);setLoadError('');try{const response=await fetch('/api/demands',{cache:'no-store'});const data=await response.json() as {error?:string;demands:Demand[]};if(!response.ok)throw new Error(data.error);setActual(data.demands);if(data.demands.length)setDemo(false);}catch(e){setLoadError(e instanceof Error?e.message:'无法加载需求,请重试。');}finally{setLoading(false)}},[]);
|
||||
useEffect(()=>{void load()},[load]);
|
||||
useEffect(()=>{if(!toast)return;const t=setTimeout(()=>setToast(''),4500);return()=>clearTimeout(t)},[toast]);
|
||||
useEffect(()=>{const mc=(document as unknown as {modelContext?:{registerTool:(tool:unknown,options:unknown)=>Promise<void>|void}}).modelContext;if(!mc?.registerTool)return;const lifecycle=new AbortController();const tools=[{name:'search_demands',title:'搜索当前工作空间需求',description:'Read demands currently visible in this workspace, including explicit demo flags. Does not change records.',inputSchema:{type:'object',properties:{query:{type:'string'}},required:['query'],additionalProperties:false},annotations:{readOnlyHint:true,untrustedContentHint:true},execute(input:unknown){if(!input||typeof (input as {query:unknown}).query!=='string')throw new Error('query must be a string');const query=(input as {query:string}).query.toLowerCase();return latest.current.filter(d=>(d.id+d.fields.title).toLowerCase().includes(query)).map(d=>({id:d.id,title:d.fields.title,status:d.status,demo:!!d.demo}));}},{name:'start_demand_registration',title:'打开需求登记表',description:'Open the registration form. This does not save or submit a demand.',inputSchema:{type:'object',properties:{},additionalProperties:false},annotations:{readOnlyHint:false,untrustedContentHint:false},execute(input:unknown){if(!input||typeof input!=='object'||Object.keys(input).length)throw new Error('Expected an empty object');setActionError('');setForm({});return {opened:true,saved:false};}}];for(const tool of tools){try{Promise.resolve(mc.registerTool(tool,{signal:lifecycle.signal})).catch(()=>{})}catch{}}return()=>lifecycle.abort()},[]);
|
||||
function navigate(v:string){setView(v);setDashboardKey(k=>k+1);setSelected(null);setActionError('')}
|
||||
function startNew(){setActionError('');setForm({})}
|
||||
async function save(body:SaveInput){setBusy(true);setActionError('');try{const response=await fetch('/api/demands',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});const data=await response.json() as {error?:string;demand:Demand};if(!response.ok)throw new Error(data.error||'保存失败,请稍后重试。');const updated=data.demand as Demand;setActual(prev=>[updated,...prev.filter(d=>d.id!==updated.id)]);setDemo(false);setForm(null);setSelected(updated);setToast(body.mode==='draft'?'草稿已保存,可随时继续填写':body.mode==='review'?'需求已提交评审,等待负责人确认':'需求已保存');setView(updated.status==='草稿'?'草稿箱':'我的需求');setDashboardKey(k=>k+1);return;}catch(e){setActionError(e instanceof Error?e.message:'保存失败,请重试。');throw e;}finally{setBusy(false)}}
|
||||
async function action(body:SaveInput){setActionError('');if(!selected)return;if(!selected.demo){await save(body);return;}
|
||||
const now=new Date().toISOString();const next=structuredClone(selected);next.revision++;next.updatedAt=now;let label='';let detail='';
|
||||
if(body.action==='cancel'){next.status='已取消';label='取消需求';detail=String(body.reason)}
|
||||
if(body.action==='change'){next.changes.push({time:now,actor:'业务用户(示例)',content:String(body.content),reason:String(body.reason),status:'待开发评估与双方确认',originalVersion:next.fields.version,originalFields:structuredClone(next.fields)});label='提出需求变更';detail=String(body.content)+';原因:'+String(body.reason)}
|
||||
if(body.action==='accept'){const results=body.results as string[];if(!next.acceptance||results.some(r=>!['通过','不通过'].includes(r))||!body.confirm||!String(body.notes).trim()){setActionError('请完成清单并确认结论。');return;}const passed=results.every(r=>r==='通过');next.status=passed?'待发布':'开发中';next.acceptanceRecords??=[];next.acceptanceRecords.push({time:now,actor:'业务用户(示例)',version:next.fields.version,testVersion:next.acceptance.testVersion,results,notes:String(body.notes),passed,items:next.acceptance.items.map((item,i)=>({...item,result:results[i]})),environment:next.acceptance.environment});label=passed?'业务验收通过':'业务验收未通过';detail=String(body.notes)}
|
||||
next.history.push({time:now,actor:'业务用户(示例)',action:label,detail});setExamples(prev=>prev.map(d=>d.id===next.id?next:d));setSelected(next);setToast('示例操作完成:'+label);
|
||||
}
|
||||
return <div className="app-shell">{loading&&<div className="loading-bar" role="progressbar" aria-label="正在加载需求"/>}<aside className="sidebar"><div className="brand"><div className="brand-mark"><i/><i/><i/><i/></div><div><strong>需有序</strong><span>需求协作平台</span></div></div><nav aria-label="主导航">{navItems.map(({icon:Icon,label})=><button key={label} title={label} aria-label={label} className={view===label?'active':''} onClick={()=>navigate(label)}><Icon size={21}/><span>{label}</span>{label==='待我处理'&&demands.filter(needsAction).length>0&&<b className="nav-count alert">{demands.filter(needsAction).length}</b>}{label==='草稿箱'&&demands.filter(d=>d.status==='草稿').length>0&&<b className="nav-count">{demands.filter(d=>d.status==='草稿').length}</b>}</button>)}</nav><div className="sidebar-bottom"><button className={'guide-nav '+(view==='流程与规范'?'guide-active':'')} onClick={()=>navigate('流程与规范')}><BookOpen size={21}/>流程与规范</button><div className="profile" title={userName}><span className="avatar"><UserRound size={21}/></span><strong>{demo?'业务用户':userName}</strong><span className="profile-label">业务方</span></div></div></aside><div className="main-shell"><header className="topbar"><span>工作空间<ChevronRight size={14}/><strong>{view}</strong></span><span className="top-date"><CalendarDays size={17}/>{today}</span></header><main>
|
||||
{loadError&&<div className="error-banner page-error" role="alert"><CircleAlert size={18}/><span>{loadError}{demo?' 当前展示示例数据。':''}</span><button className="text-button" onClick={load}><RotateCw size={14}/>重新加载</button></div>}
|
||||
{view==='流程与规范'?<Guide onNew={startNew}/>:<Dashboard key={dashboardKey} demands={demands} view={view} onView={setView} onOpen={d=>{setSelected(d);setActionError('')}} onNew={startNew} onGuide={()=>navigate('流程与规范')} demo={demo} onMode={()=>{setDemo(!demo);setDashboardKey(k=>k+1)}}/>}
|
||||
</main></div>
|
||||
{selected&&!form&&<DemandDetail key={selected.id+'-'+selected.revision} d={selected} onClose={()=>setSelected(null)} onEdit={d=>{setForm({initial:d});setActionError('')}} onAction={action} busy={busy} error={actionError}/>}
|
||||
{form&&<DemandForm initial={form.initial} onSave={async body=>{try{await save(body)}catch{}}} onClose={()=>setForm(null)} busy={busy} error={actionError} userName={userName==='seedy@sites.test'?'业务用户':userName} existing={actual}/>}
|
||||
{toast&&<div className="toast" role="status"><CheckCircle2 size={18}/>{toast}</div>}
|
||||
</div>;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { ArrowRight, Bell, ChevronRight, Search, SlidersHorizontal, FileText, Lightbulb } from 'lucide-react';
|
||||
import { type Demand, needsAction } from '@/lib/demand';
|
||||
export function Status({d}:{d:Demand}){const style=d.status==='待验收'?'purple':d.status==='开发中'?'blue':d.status==='已完成'?'green':d.status==='待发布'||d.status==='已上线'?'teal':d.status==='已取消'?'gray':d.status==='草稿'?'gray':'neutral';return <span className={'status '+style}>{d.status}</span>}
|
||||
export function Dashboard({demands,view,onView,onOpen,onNew,onGuide,demo,onMode}:{demands:Demand[];view:string;onView:(v:string)=>void;onOpen:(d:Demand)=>void;onNew:()=>void;onGuide:()=>void;demo:boolean;onMode:()=>void}){
|
||||
const [tab,setTab]=useState('全部需求');const [query,setQuery]=useState('');const [filterOpen,setFilterOpen]=useState(false);const [priority,setPriority]=useState('全部优先级');const [project,setProject]=useState('全部项目');
|
||||
const submitted=demands.filter(d=>d.status!=='草稿');const inProgress=submitted.filter(d=>['已排期','开发中'].includes(d.status));const todos=demands.filter(needsAction);const completed=demands.filter(d=>d.status==='已完成');
|
||||
const base=view==='草稿箱'?demands.filter(d=>d.status==='草稿'):view==='待我处理'?todos:submitted;
|
||||
const filtered=base.filter(d=>(tab==='全部需求'||view==='草稿箱'||(tab==='进行中'?['已排期','开发中'].includes(d.status):d.status===tab))&&(priority==='全部优先级'||d.fields.priority===priority)&&(project==='全部项目'||d.fields.project===project)&&(d.fields.title+d.id+d.fields.department+d.fields.owner).toLowerCase().includes(query.toLowerCase()));
|
||||
const recent=view==='我的工作台'&&!query&&tab==='全部需求'&&priority==='全部优先级'&&project==='全部项目';const rows=recent?filtered.slice(0,5):filtered;
|
||||
return <>
|
||||
<div className="page-heading"><div><h1>{view}</h1><p>{view==='我的工作台'?'一起让每一个好需求,有序落地。':view==='草稿箱'?'还没写完的想法,在这里继续。':view==='待我处理'?'补齐业务信息、确认结果,让需求继续向前。':'从业务诉求到交付完成,进展都在这里。'}</p></div><button className="btn primary" onClick={onNew}><span className="plus">+</span>登记新需求</button></div>
|
||||
{view==='我的工作台'&&<><div className="stats">{[['我的需求',submitted.length,'我的需求'],['进行中',inProgress.length,'进行中'],['待我处理',todos.length,'待我处理'],['已完成',completed.length,'已完成']].map(([label,value,to])=><button key={label} onClick={()=>{if(to==='进行中'||to==='已完成'){setTab(String(to));onView('我的需求')}else onView(String(to))}}><span>{label}</span><strong>{value}</strong></button>)}</div><div className="reminder"><Bell size={20}/><strong>待办提醒</strong><span className="reminder-divider"/><span>{todos.length?`你有 ${todos.filter(d=>d.status==='待评审').length} 项需求待补充,${todos.filter(d=>d.status==='待验收').length} 项待验收`:'当前没有待办,需求进展尽在掌握。'}</span><button className="text-button" onClick={()=>{setTab('全部需求');onView('待我处理')}}>查看待办<ArrowRight size={17}/></button></div></>}
|
||||
<div className={'workspace-grid '+(view!=='我的工作台'?'full-width':'')}><section className="panel demand-panel"><div className="panel-heading"><h2>{view==='我的工作台'?'最近需求':view==='待我处理'?'需要你处理':view==='草稿箱'?'未提交的草稿':'需求列表'}</h2>{view==='我的工作台'?<button className="text-button" onClick={()=>onView('我的需求')}>查看全部<ArrowRight size={16}/></button>:<span className="muted">{filtered.length} 条需求</span>}</div>
|
||||
{view!=='草稿箱'&&<div className="tabs" role="tablist" aria-label="需求状态">{['全部需求','进行中','待验收','已完成'].map(t=><button key={t} role="tab" aria-selected={tab===t} className={tab===t?'selected':''} onClick={()=>setTab(t)}>{t}</button>)}</div>}
|
||||
<div className="table-toolbar"><label className="search-field"><Search size={18}/><input aria-label="搜索需求" value={query} onChange={e=>setQuery(e.target.value)} placeholder="搜索需求名称或编号"/></label><button className={'btn filter-button '+(filterOpen?'pressed':'')} onClick={()=>setFilterOpen(!filterOpen)} aria-expanded={filterOpen}><SlidersHorizontal size={17}/>筛选</button></div>
|
||||
{filterOpen&&<div className="filters"><label>优先级<select value={priority} onChange={e=>setPriority(e.target.value)}>{['全部优先级','P0','P1','P2'].map(p=><option key={p}>{p}</option>)}</select></label><label>项目<select value={project} onChange={e=>setProject(e.target.value)}>{['全部项目',...new Set(demands.map(d=>d.fields.project).filter(Boolean))].map(p=><option key={p}>{p}</option>)}</select></label><button className="text-button" onClick={()=>{setPriority('全部优先级');setProject('全部项目');setQuery('');setTab('全部需求')}}>重置</button></div>}
|
||||
<div className="table-wrap"><table><thead><tr><th>需求名称</th><th>状态</th><th>优先级</th><th>期望上线</th></tr></thead><tbody>{rows.map(d=><tr key={d.id}><td><button className="demand-title" onClick={()=>onOpen(d)}>{d.fields.title}<ChevronRight size={15}/></button><div className="row-meta">{d.id}<span>·</span>{d.fields.department||'未填写部门'}</div></td><td><Status d={d}/>{d.status==='待评审'&&!d.reviewReady&&<span className="supplement">资料待补充</span>}{d.blocked&&<span className="supplement">阻塞</span>}</td><td><span className={'priority p'+d.fields.priority.slice(1)}><i/>{d.fields.priority} {d.fields.priority==='P0'?'紧急':d.fields.priority==='P1'?'高':'普通'}</span></td><td className="date-cell">{d.fields.noFixedDate?'无固定日期':d.fields.expectedDate?d.fields.expectedDate.slice(5):'待填写'}</td></tr>)}</tbody></table></div>
|
||||
{!rows.length&&<div className="empty-state">{query?<Search size={32}/>:<FileText size={32}/>}<h3>{query||priority!=='全部优先级'?'没有匹配的需求':view==='待我处理'?'所有待办都处理好了':view==='草稿箱'?'还没有草稿':'从第一个需求开始'}</h3><p>{query?'试试其他关键词或调整筛选条件。':'把业务问题写下来,让每一步都有据可循。'}</p><button className="btn" onClick={onNew}>登记新需求<ArrowRight size={16}/></button></div>}
|
||||
{view!=='我的工作台'&&rows.length>0&&<div className="table-footer">共 {rows.length} 条,已显示全部结果</div>}</section>
|
||||
{view==='我的工作台'&&<aside className="right-rail"><section className="panel tips-panel"><h2><Lightbulb size={20}/>需求提交小贴士</h2>{[['说清业务问题','描述背景、现状与痛点'],['明确预期结果','说明希望达到的目标和价值'],['准备验收标准','给出可衡量、可验收的标准']].map(([title,desc],i)=><div className="tip" key={title}><span>{i+1}</span><div><h3>{title}</h3><p>{desc}</p></div></div>)}<button className="text-button tips-link" onClick={onGuide}>查看填写指引<ArrowRight size={16}/></button></section><section className="panel process-panel"><h2>流程一览</h2><ol>{['需求登记','评审排期','设计开发','业务验收','上线完成'].map((s,i)=><li key={s}><span className={i===0?'current':''}>{i+1}</span>{s}</li>)}</ol></section></aside>}</div>
|
||||
<div className="workspace-footer"><span>{demo?'当前展示示例数据,登记后将进入你的工作空间。':'期望上线为业务期望,正式交付时间以评审计划为准。'}</span><button onClick={onMode}>{demo?'查看我的数据':'体验示例'}<ArrowRight size={14}/></button></div>
|
||||
</>;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { X, PencilLine, GitBranch, Download, ArrowRight, CircleAlert, CheckCircle2, Clock3, Info } from 'lucide-react';
|
||||
import { Dialog, DialogContent, DialogTitle, DialogDescription } from '@/components/ui/dialog';
|
||||
import { type Demand, statuses } from '@/lib/demand';
|
||||
import { Status } from './dashboard';
|
||||
import { type SaveInput } from './form';
|
||||
const date=(s:string)=>new Date(s).toLocaleString('zh-CN',{year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',hour12:false,timeZone:'Asia/Shanghai'});
|
||||
function FieldView({label,value}:{label:string;value:string}){return <div className="detail-field"><span>{label}</span><p>{value||'待补充'}</p></div>}
|
||||
export function DemandDetail({d,onClose,onEdit,onAction,busy,error}:{d:Demand;onClose:()=>void;onEdit:(d:Demand)=>void;onAction:(body:SaveInput)=>Promise<void>;busy:boolean;error:string}){
|
||||
const [tab,setTab]=useState('需求详情');const [mode,setMode]=useState('');const [content,setContent]=useState('');const [reason,setReason]=useState('');const [results,setResults]=useState<string[]>(d.acceptance?.items.map(()=> '待测')??[]);const [notes,setNotes]=useState('');const [confirm,setConfirm]=useState(false);const [localError,setLocalError]=useState('');
|
||||
const f=d.fields;const current=statuses.indexOf(d.status as typeof statuses[number]);
|
||||
async function submit(){setLocalError('');if(mode==='change'&&(!content.trim()||!reason.trim())){setLocalError('请填写变更内容与原因。');return;}if(mode==='cancel'&&!reason.trim()){setLocalError('请填写取消需求的原因。');return;}if(mode==='accept'&&(results.some(r=>r==='待测')||!notes.trim()||!confirm)){setLocalError('请逐项完成验收、填写遗留问题及处理计划,并明确确认结论。');return;}
|
||||
try{await onAction({action:mode,id:d.id,revision:d.revision,content,reason,results,notes,confirm,testVersion:d.acceptance?.testVersion,version:f.version});setMode('');setContent('');setReason('');}catch{}}
|
||||
function exportRecord(){const lines=[`# ${d.id} · ${f.title}`,`状态:${d.status} | 文档版本:${f.version}`,`需求负责人:${f.owner} | 登记人:${f.proposer}`,`\n## 需求内容`,...Object.entries(f).map(([k,v])=>`${k}: ${v}`),'\n## 过程记录',...d.history.map(h=>`${date(h.time)} ${h.actor} ${h.action}\n${h.detail}`),'\n## 完整记录(含验收与变更)','```json',JSON.stringify(d,null,2),'```'];const url=URL.createObjectURL(new Blob([lines.join('\n')],{type:'text/markdown;charset=utf-8'}));const a=document.createElement('a');a.href=url;a.download=d.id+'.md';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);}
|
||||
return <Dialog open onOpenChange={open=>{if(!open&&!mode&&!busy)onClose()}}><DialogContent className="demand-modal detail-modal" showCloseButton={false} onInteractOutside={e=>{if(mode)e.preventDefault()}}><div className="detail-heading"><div className="detail-eyeline"><span>{d.id}</span><Status d={d}/>{d.demo&&<span className="demo-tag">示例</span>}<button className="icon-button" aria-label="关闭需求详情" onClick={()=>{if(mode){setMode('');setLocalError('')}else onClose()}} disabled={busy}><X size={20}/></button></div><DialogTitle className="detail-title">{f.title}</DialogTitle><DialogDescription className="detail-description">{f.project} / {f.module} <span>·</span>{f.department} <span>·</span>负责人:{f.owner}</DialogDescription></div>
|
||||
<div className="detail-progress">{statuses.map((s,i)=><div key={s} className={i===current?'current':i<current?'done':''}><span>{i<current?<CheckCircle2 size={15}/>:i+1}</span><b>{s}</b></div>)}</div>
|
||||
<div className="tabs detail-tabs" role="tablist" aria-label="需求详情栏目">{['需求详情','进度记录','需求变更','业务验收'].map(t=><button role="tab" aria-selected={tab===t} className={tab===t?'selected':''} key={t} onClick={()=>{setTab(t);setMode('');setLocalError('')}}>{t}{t==='需求变更'&&d.changes.length>0&&<small>{d.changes.length}</small>}</button>)}</div>
|
||||
<div className="modal-scroll"><div className="detail-content">
|
||||
{(error||localError)&&<div role="alert" className="error-banner"><CircleAlert size={17}/>{error||localError}</div>}
|
||||
{d.demo&&<div className="info-banner detail-info"><Info size={17}/>当前为示例需求,验收和变更操作只用于体验,不影响实际业务数据。</div>}
|
||||
{mode==='change'||mode==='cancel'?<div className="action-form"><h2>{mode==='change'?'提出需求变更':'确认取消需求'}</h2><p>{mode==='change'?'记录希望调整的内容,开发负责人评估影响、双方确认后,再更新范围与计划。':'取消后会保留需求及过程记录。请填写明确的业务原因。'}</p>{mode==='change'&&<label className="form-field"><span>变更内容<em>*</em></span><textarea rows={4} value={content} onChange={e=>setContent(e.target.value)} maxLength={5000} placeholder="当前内容是什么?希望调整为什么?"/></label>}<label className="form-field"><span>{mode==='change'?'变更原因':'取消原因'}<em>*</em></span><textarea rows={3} value={reason} onChange={e=>setReason(e.target.value)} maxLength={3000} placeholder="请说明业务背景及必要性"/></label></div>:<>
|
||||
{tab==='需求详情'&&<><div className="detail-overview"><FieldView label="建议优先级" value={f.priority+' · '+(f.priority==='P0'?'紧急':f.priority==='P1'?'高':'普通')}/><FieldView label="期望上线" value={f.noFixedDate?'无固定日期':f.expectedDate}/><FieldView label="文档版本" value={f.version}/><FieldView label="登记日期" value={d.createdAt.slice(0,10)}/></div>{d.plan&&<section className="plan-strip"><h3><Clock3 size={17}/>已确认交付计划</h3><div><FieldView label="开发负责人" value={d.plan.developer}/><FieldView label="计划提测" value={d.plan.testDate}/><FieldView label="计划上线" value={d.plan.releaseDate}/></div></section>}
|
||||
<section className="detail-section"><h2>业务背景与目标</h2><FieldView label="业务背景及现有处理方式" value={f.background}/><FieldView label="影响对象及业务依据" value={f.impact}/><FieldView label="预期目标" value={f.goal}/><FieldView label="期望日期依据" value={f.noFixedDate?'无固定日期':f.dateReason}/></section>
|
||||
<section className="detail-section"><h2>范围与验收标准</h2><FieldView label="实施范围及功能说明" value={f.scope}/><FieldView label="范围外事项" value={f.outOfScope}/><FieldView label="验收标准" value={f.criteria}/><FieldView label="优先级依据" value={f.priorityReason}/></section>
|
||||
<section className="detail-section"><h2>数据与参考材料</h2><FieldView label="数据来源" value={f.noData?'本需求不涉及数据来源':f.dataSource}/>{!f.noData&&<FieldView label="数据提供人" value={f.dataContact}/>}<FieldView label="依赖与风险" value={f.risk}/><FieldView label="待确认事项" value={f.pending}/><FieldView label="参考材料" value={f.references||'暂无参考材料'}/><FieldView label="提出人及来源" value={f.proposer+' · '+f.source}/></section></>}
|
||||
{tab==='进度记录'&&<div className="timeline">{[...d.history].reverse().map((h,i)=><article key={i}><div className="timeline-dot"/><div className="timeline-meta"><h3>{h.action}</h3><time>{date(h.time)}</time></div><p>{h.detail}</p><span>{h.actor}</span></article>)}</div>}
|
||||
{tab==='需求变更'&&<>{!d.changes.length?<div className="empty-state"><GitBranch size={31}/><h3>暂无需求变更</h3><p>已确认需求的范围调整,会在这里保留记录。</p>{['已排期','开发中','待验收','待发布','已上线'].includes(d.status)&&<button className="btn" onClick={()=>setMode('change')}>提出变更<ArrowRight size={16}/></button>}</div>:d.changes.map((c,i)=><article className="change-record" key={i}><div><h3>变更 {String(i+1).padStart(2,'0')}</h3><span className="status neutral">{c.status}</span></div><FieldView label="变更内容" value={c.content}/><FieldView label="变更原因" value={c.reason}/><p className="muted">基于 {c.originalVersion} · {c.actor} · {date(c.time)}</p></article>)}</>}
|
||||
{tab==='业务验收'&&<>{d.acceptance?<><div className="acceptance-intro"><h2>验收清单</h2><p>文档版本 {f.version} <span>·</span>测试版本 {d.acceptance.testVersion}</p><FieldView label="测试环境" value={d.acceptance.environment}/><FieldView label="操作与测试数据说明" value={d.acceptance.instructions}/><div className="deadline"><Clock3 size={15}/>反馈截止时间:{d.acceptance.deadline};超时不会自动通过。</div></div>
|
||||
{d.acceptance.items.map((item,i)=><div className="acceptance-item" key={item.id}><div className="acceptance-item-top"><span>{item.id}</span><strong>{item.feature}</strong>{d.status==='待验收'&&<select aria-label={item.id+' 验收结果'} value={results[i]} onChange={e=>setResults(prev=>prev.map((r,j)=>i===j?e.target.value:r))}><option>待测</option><option>通过</option><option>不通过</option></select>}</div><p><span>场景/操作</span>{item.scenario}</p><p><span>预期结果</span>{item.expected}</p></div>)}
|
||||
{d.status==='待验收'&&<div className="acceptance-confirm"><label className="form-field"><span>遗留问题、证据/缺陷及处理计划<em>*</em></span><textarea rows={3} value={notes} onChange={e=>setNotes(e.target.value)} maxLength={5000} placeholder="无问题请填“无”。有问题请注明验收项、复现步骤、实际结果、证据及处理计划。"/></label><label className="check-field"><input type="checkbox" checked={confirm} onChange={e=>setConfirm(e.target.checked)}/><span>我已逐项核对以上版本并确认验收结果;全部通过后,同意按约定发布计划上线。</span></label><button className="btn primary" disabled={busy} onClick={()=>{if(results.some(r=>r==='待测')||!notes.trim()||!confirm){setLocalError('请逐项完成验收、填写遗留问题及处理计划,并明确确认结论。');return;}onAction({action:'accept',id:d.id,revision:d.revision,results,notes,confirm,testVersion:d.acceptance?.testVersion,version:f.version}).catch(()=>{})}}><CheckCircle2 size={17}/>{busy?'提交中…':'提交验收结论'}</button></div>}
|
||||
</>:<div className="empty-state"><CheckCircle2 size={32}/><h3>还未进入业务验收</h3><p>完成技术验证并提供测试版本后,即可逐项验收。</p></div>}
|
||||
{d.acceptanceRecords?.map((r,i)=><div className="acceptance-record" key={i}><h3>{r.passed?'业务验收通过':'业务验收未通过'}</h3><p>文档 {r.version} · 测试 {r.testVersion}</p><p>遗留问题及处理计划:{r.notes}</p><span>{r.actor} · {date(r.time)}</span></div>)}</>}
|
||||
</>}
|
||||
</div></div>
|
||||
<footer className="modal-footer"><div className="footer-left"><button className="text-button muted" onClick={exportRecord}><Download size={16}/>导出记录</button>{!['已上线','已完成','已取消'].includes(d.status)&&!mode&&<button className="text-button danger-text" onClick={()=>{setMode('cancel');setReason('')}}>取消需求</button>}</div><div className="footer-right">{mode==='change'||mode==='cancel'?<><button className="btn" onClick={()=>{setMode('');setLocalError('')}} disabled={busy}>返回详情</button><button className={'btn '+(mode==='change'?'primary':'danger-button')} onClick={submit} disabled={busy}>{busy?'保存中…':mode==='change'?'提交变更':'确认取消'}</button></>:<>{['草稿','待评审'].includes(d.status)&&<button className="btn primary" onClick={()=>onEdit(d)}><PencilLine size={16}/>{d.status==='草稿'?'继续填写':'补充信息'}</button>}{['已排期','开发中','待验收','待发布','已上线'].includes(d.status)&&<button className="btn" onClick={()=>{setMode('change');setReason('')}}><GitBranch size={16}/>提出变更</button>}{d.status==='待验收'&&tab!=='业务验收'&&<button className="btn primary" onClick={()=>setTab('业务验收')}>开始验收<ArrowRight size={16}/></button>}</>}</div></footer>
|
||||
</DialogContent></Dialog>
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { X, ArrowLeft, ArrowRight, Save, Send, Info, Check, CircleAlert, FilePenLine } from 'lucide-react';
|
||||
import { Dialog, DialogContent, DialogTitle, DialogDescription } from '@/components/ui/dialog';
|
||||
import { emptyFields, missingFields, type Fields, type Demand } from '@/lib/demand';
|
||||
export type SaveInput={action:string;id?:string;revision?:number;fields?:Fields;mode?:string;[key:string]:unknown};
|
||||
export function DemandForm({initial,onSave,onClose,busy,error,userName,existing}:{initial?:Demand;onSave:(body:SaveInput)=>Promise<void>;onClose:()=>void;busy:boolean;error:string;userName:string;existing:Demand[]}){
|
||||
const [f,setF]=useState<Fields>(initial?.fields??{...emptyFields,proposer:userName,owner:userName});const [step,setStep]=useState(0);const [invalid,setInvalid]=useState<string[]>([]);const [exit,setExit]=useState(false);
|
||||
const set=(k:keyof Fields,v:string|boolean)=>setF(prev=>({...prev,[k]:v}));
|
||||
const duplicate=existing.find(d=>d.id!==initial?.id&&f.title.trim().length>3&&d.fields.title.includes(f.title.trim()));
|
||||
const field=(k:keyof Fields,label:string,placeholder:string,opts:{large?:boolean;full?:boolean;required?:boolean;type?:string;hint?:string;max?:number}={})=><label className={'form-field '+(opts.full?'span-two':'')} key={k}><span>{label}{opts.required&&<em>*</em>}</span>{opts.large?<textarea value={String(f[k])} onChange={e=>set(k,e.target.value)} placeholder={placeholder} rows={3} maxLength={opts.max??3000}/>:<input type={opts.type??'text'} value={String(f[k])} onChange={e=>set(k,e.target.value)} placeholder={placeholder} maxLength={opts.max??100}/>} {opts.hint&&<small>{opts.hint}</small>}</label>;
|
||||
async function save(mode:string){const m=mode==='draft'?(f.title.trim()?[]:['需求标题']):missingFields(f,mode==='review');setInvalid(m);if(m.length){setStep(mode==='review'?step:m.some(x=>['需求标题','所属项目','业务模块','提出人','所属部门','需求来源','需求负责人'].includes(x))?0:1);return;}await onSave({action:initial&&!initial.demo?'update':'create',id:initial?.demo?undefined:initial?.id,revision:initial?.revision,fields:f,mode});}
|
||||
return <Dialog open onOpenChange={open=>{if(!open&&!busy)setExit(true)}}><DialogContent className="demand-modal form-modal" showCloseButton={false} onInteractOutside={e=>e.preventDefault()}><div className="modal-heading"><div className="modal-icon"><FilePenLine size={23}/></div><div><DialogTitle className="modal-title">{initial?'完善需求信息':'登记新需求'}</DialogTitle><DialogDescription className="modal-subtitle">一个独立业务目标,对应一条需求。先登记,再逐步完善。</DialogDescription></div><button className="icon-button" aria-label="关闭登记窗口" onClick={()=>setExit(true)} disabled={busy}><X size={20}/></button></div>
|
||||
<div className="form-steps">{['基本信息','业务背景与目标','范围与验收','数据与参考材料'].map((s,i)=><button key={s} className={i===step?'current':i<step?'done':''} onClick={()=>setStep(i)}><span>{i<step?<Check size={14}/>:i+1}</span><b>{s}</b></button>)}</div>
|
||||
<div className="modal-scroll"><div className="form-content">
|
||||
{initial?.demo&&<div className="info-banner"><Info size={17}/>你正在参考示例填写,保存将创建一条属于你的新需求。</div>}
|
||||
{exit&&<div className="exit-banner"><div><strong>本次编辑尚未保存</strong><p>你可以继续填写,或保存为草稿后离开。</p></div><button className="btn" onClick={()=>setExit(false)}>继续填写</button><button className="text-button danger-text" onClick={onClose}>放弃本次编辑</button></div>}
|
||||
{(error||invalid.length>0)&&<div className="error-banner" role="alert"><CircleAlert size={18}/><span>{error||'请补充:'+invalid.join('、')}</span></div>}
|
||||
<div className="form-section-heading"><h2>{['这是什么需求?','希望解决什么业务问题?','怎样才算做好了?','开发前,还需要哪些信息?'][step]}</h2><p>{['基本信息用于明确需求归属和联系人员。','用熟悉的业务语言描述,不需要填写技术实现方案。','这一部分可在登记后补充,提交评审前需填写完整。','材料可通过链接关联;简单需求可直接使用本表单作为需求正文。'][step]}</p></div>
|
||||
<div className="form-grid">
|
||||
{step===0&&<>
|
||||
{field('title','需求标题','例如:订单管理—支持按订单状态导出',{full:true,required:true,hint:'建议使用“业务模块 + 动作或能力”,避免“页面优化”等笼统标题。'})}
|
||||
{duplicate&&<div className="span-two info-banner"><Info size={16}/>已有相似需求「{duplicate.fields.title}」,请核对是否为同一目标。</div>}
|
||||
{field('project','所属项目','例如:企业业务平台',{required:true})}{field('module','业务模块','例如:订单管理',{required:true})}
|
||||
<label className="form-field"><span>需求类型<em>*</em></span><select value={f.type} onChange={e=>set('type',e.target.value)}>{['新增功能','功能优化','缺陷修复','配置/数据变更'].map(t=><option key={t}>{t}</option>)}</select></label>
|
||||
{field('department','所属部门','例如:销售部',{required:true})}{field('proposer','提出人','填写实际提出人',{required:true})}{field('owner','需求负责人','负责确认范围和业务验收的人',{required:true})}{field('source','需求来源','例如:销售周会、客户反馈、日常操作问题',{full:true,required:true,max:200})}
|
||||
</>}
|
||||
{step===1&&<>
|
||||
{field('background','业务背景与现有处理方式','现在怎么做?具体遇到了什么问题?请补充实际案例或数据依据。',{large:true,full:true,required:true,max:6000})}
|
||||
{field('impact','影响对象与业务依据','哪些用户或岗位受影响?影响范围有多大?依据是什么?',{large:true,full:true,required:true})}
|
||||
{field('goal','预期目标','完成后希望达到什么结果?有量化依据时,请说明目标值与统计口径。',{large:true,full:true,required:true})}
|
||||
<label className="check-field span-two"><input type="checkbox" checked={f.noFixedDate} onChange={e=>set('noFixedDate',e.target.checked)}/>没有固定的上线日期</label>
|
||||
{!f.noFixedDate&&<>{field('expectedDate','期望上线日期','',{type:'date',required:true})}{field('dateReason','期望日期依据','例如:9 月经营分析会前使用',{required:true,max:1000})}</>}
|
||||
<div className="info-banner span-two"><Info size={17}/>这是业务期望时间,正式交付计划由需求负责人和开发负责人评审确认。</div>
|
||||
</>}
|
||||
{step===2&&<>
|
||||
{field('scope','实施范围与功能说明','F-01:本次需要支持的功能、操作步骤和业务规则。\nF-02:另一项相关功能。',{large:true,full:true,required:true,max:6000})}
|
||||
{field('outOfScope','范围外事项','明确这次不做什么,无相关事项可填写“无”。',{large:true,full:true,required:true})}
|
||||
{field('criteria','验收标准','AC-01 / F-01:在什么场景下执行什么操作,应得到什么结果。\n请覆盖正常流程、空数据、非法输入等关键异常。',{large:true,full:true,required:true,max:6000,hint:'每一项都应能实际验证,避免仅写“使用正常”“体验良好”。'})}
|
||||
<label className="form-field"><span>建议优先级<em>*</em></span><select value={f.priority} onChange={e=>set('priority',e.target.value)}><option value="P2">P2 · 常规优化或储备</option><option value="P1">P1 · 近期业务目标</option><option value="P0">P0 · 业务阻塞或关键节点</option></select><small>最终优先级以评审结论为准。</small></label>
|
||||
{field('priorityReason','优先级依据','说明业务影响、时间要求及依赖',{required:true,max:1000})}
|
||||
</>}
|
||||
{step===3&&<>
|
||||
<label className="check-field span-two"><input type="checkbox" checked={f.noData} onChange={e=>set('noData',e.target.checked)}/>本需求不涉及数据来源</label>
|
||||
{!f.noData&&<>{field('dataSource','数据来自哪里','平时从哪个系统、页面、报表或文件获取?需要哪些内容、多久更新?多个来源不一致时以谁为准?',{large:true,full:true,required:true})}{field('dataContact','由谁提供数据','提供人、部门及联系方式',{full:true,required:true,max:300})}</>}
|
||||
{field('risk','依赖与风险','需要哪些系统或人员配合?有无风险及应对方式?无则填“无”。',{large:true,full:true,required:true})}
|
||||
{field('pending','待确认事项','待确认问题 + 责任人 + 计划确认时间;无则填“无”。',{large:true,full:true,required:true})}
|
||||
{field('version','需求文档版本','例如:v1.0',{required:true})}
|
||||
{field('references','参考材料与链接','可填写 PRD、原型、截图或业务规则的受限共享链接,每行一条。',{large:true,full:true,max:5000,hint:'复杂需求请关联独立 PRD;账号密码等敏感信息通过约定受限渠道提供。'})}
|
||||
</>}
|
||||
</div></div></div>
|
||||
<footer className="modal-footer"><div className="footer-left">{(!initial||initial.status==='草稿'||initial.demo)&&<button className="btn" onClick={()=>save('draft')} disabled={busy}><Save size={16}/>保存草稿</button>}{step>0&&<button className="text-button back-button" onClick={()=>setStep(step-1)} disabled={busy}><ArrowLeft size={15}/>上一步</button>}</div><div className="footer-right">{step>=1&&<button className="btn" onClick={()=>save('register')} disabled={busy}>{busy?'保存中…':'先登记,稍后补充'}</button>}{step<3?<button className="btn primary" onClick={()=>setStep(step+1)} disabled={busy}>下一步<ArrowRight size={16}/></button>:<button className="btn primary" onClick={()=>save('review')} disabled={busy}><Send size={16}/>{busy?'提交中…':'提交评审'}</button>}</div></footer>
|
||||
</DialogContent></Dialog>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
'use client';
|
||||
import { ArrowRight, BookOpen, Download, CheckCircle2, Info } from 'lucide-react';
|
||||
const templates=['需求登记','需求文档','数据来源填写','验收记录','需求变更记录','缺陷记录','发布记录'];
|
||||
export function Guide({onNew}:{onNew:()=>void}){return <><div className="page-heading"><div><h1>流程与规范</h1><p>把业务问题说清楚,让协作有共同依据。</p></div><button className="btn primary" onClick={onNew}>登记新需求<ArrowRight size={16}/></button></div><div className="guide-grid"><section className="panel guide-main"><h2>从想法到交付,你需要做什么?</h2>{[
|
||||
['01','先查询,再登记','登记前搜索已有需求。同一业务目标合并维护;可以独立评审和验收的目标分别登记。','填写标题、归属、提出人、需求负责人、业务背景、影响对象、目标及期望日期。'],
|
||||
['02','补齐材料,提交评审','讲清楚“这次做什么、不做什么、怎样算完成”,让开发负责人可以评估。','补充范围、功能说明、验收标准、优先级依据、数据来源、依赖风险及文档版本。'],
|
||||
['03','确认方案,跟进进度','设计定稿需明确对应设计版本,并由需求负责人确认“同意按此版本实施”。','业务期望上线日期不是交付承诺;正式排期由需求负责人和开发负责人评审确认。'],
|
||||
['04','实际操作,逐项验收','使用测试环境和测试数据,按验收清单核对主要流程及异常结果。','记录文档版本、测试版本、每项结果、证据、遗留问题和处理计划,明确确认结论。'],
|
||||
['05','确认上线,交付归档','业务验收通过后进入待发布;上线后仍需完成生产验证、观察和交接。','“已上线”不等于“已完成”。只有完成生产验证和约定观察,才结束需求。'],
|
||||
].map(([n,title,desc,note])=><article className="guide-step" key={n}><span>{n}</span><div><h3>{title}</h3><p>{desc}</p><small>{note}</small></div></article>)}<div className="info-banner"><Info size={18}/>业务方说明业务来源和预期结果即可;数据库结构、接口和技术选型由开发负责人补充。</div></section><aside><section className="panel guide-docs"><h2><BookOpen size={20}/>配套规范与模板</h2><a href="/docs/开发SOP_公示版.md" download>软件开发流程管理规范<Download size={16}/></a>{templates.map((name,i)=><a href={'/docs/附件'+String(i+1).padStart(2,'0')+'_'+name+'模板.md'} download key={name}><span><small>{String(i+1).padStart(2,'0')}</small>{name}模板</span><Download size={15}/></a>)}</section><section className="panel guide-rules"><h2>几条重要约定</h2>{['草稿是填写辅助,不属于正式流程。','阻塞时保留当前状态,注明原因、责任人与跟进时间。','已确认范围需要调整时,提出变更并等待双方确认。','未达到原验收标准的问题,按缺陷处理。','验收不能以口头认可或超时未反馈替代。'].map(t=><p key={t}><CheckCircle2 size={16}/>{t}</p>)}</section></aside></div></>}
|
||||
Reference in new issue
Block a user