Build business demand registration workspace from SOP
This commit is contained in:
commit
2149aeb6ed
126 files changed
+25399
No files matched your search
@@ -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>
|
||||
}
|
||||
Reference in new issue
Block a user