feat(web-admin): add OA progress person-line formatter for or/and sign
Provide shared plain-text lines (name opinion time) used by progress UI and PDF. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f951c12071
commit
043e69f818
2 files changed
+175
No files matched your search
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 或签/会签进度人员行格式化
|
||||
* Spec: docs/superpowers/specs/2026-07-23-oa-or-and-sign-display-design.md
|
||||
*/
|
||||
|
||||
export type ProgressPersonInput = {
|
||||
id?: string
|
||||
nickName?: string
|
||||
status?: string
|
||||
timestamp?: string
|
||||
commentText?: string
|
||||
}
|
||||
|
||||
export type PersonLineTone = 'ok' | 'pending' | 'danger' | 'mute' | ''
|
||||
|
||||
export type ProgressPersonLine = {
|
||||
text: string
|
||||
tone: PersonLineTone
|
||||
}
|
||||
|
||||
const ACTED_STATUS = new Set(['approved', 'rejected', 'returned', 'completed'])
|
||||
|
||||
function displayName(p: ProgressPersonInput): string {
|
||||
return String(p.nickName || p.id || '').trim()
|
||||
}
|
||||
|
||||
function statusFallbackLabel(status: string): string {
|
||||
const s = (status || '').trim()
|
||||
if (s === 'approved') return '已同意'
|
||||
if (s === 'rejected') return '已拒绝'
|
||||
if (s === 'returned') return '已打回'
|
||||
if (s === 'completed') return '已完成'
|
||||
return s || '已处理'
|
||||
}
|
||||
|
||||
function toneForStatus(status: string): PersonLineTone {
|
||||
const s = (status || '').trim()
|
||||
if (s === 'approved' || s === 'completed') return 'ok'
|
||||
if (s === 'pending' || s === 'running' || s === 'not_reached') return 'pending'
|
||||
if (s === 'rejected' || s === 'returned' || s === 'cancelled') return 'danger'
|
||||
if (s === 'done') return 'mute'
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 将 progress.people 格式化为「姓名 意见/状态 时间」纯文本行 */
|
||||
export function formatProgressPersonLines(
|
||||
people: ProgressPersonInput[] | null | undefined
|
||||
): ProgressPersonLine[] {
|
||||
const list = Array.isArray(people) ? people : []
|
||||
const out: ProgressPersonLine[] = []
|
||||
for (const p of list) {
|
||||
const name = displayName(p)
|
||||
if (!name) continue
|
||||
const status = String(p.status || '').trim()
|
||||
const comment = String(p.commentText || '').trim()
|
||||
const ts = String(p.timestamp || '').trim()
|
||||
const tone = toneForStatus(status)
|
||||
|
||||
if (status === 'done') {
|
||||
out.push({ text: `${name} 无需处理`, tone: 'mute' })
|
||||
continue
|
||||
}
|
||||
if (status === 'pending' || status === 'running' || status === 'not_reached' || !status) {
|
||||
// 无 status 时:若有意见/时间仍按已处理拼;否则待处理
|
||||
if (!status && (comment || ts)) {
|
||||
const mid = comment || statusFallbackLabel('approved')
|
||||
out.push({
|
||||
text: ts ? `${name} ${mid} ${ts}` : `${name} ${mid}`,
|
||||
tone: 'ok'
|
||||
})
|
||||
continue
|
||||
}
|
||||
out.push({ text: `${name} 待处理`, tone: 'pending' })
|
||||
continue
|
||||
}
|
||||
if (ACTED_STATUS.has(status) || comment || ts) {
|
||||
const mid = comment || statusFallbackLabel(status)
|
||||
out.push({
|
||||
text: ts ? `${name} ${mid} ${ts}` : `${name} ${mid}`,
|
||||
tone: tone || 'ok'
|
||||
})
|
||||
continue
|
||||
}
|
||||
out.push({ text: `${name} 待处理`, tone: 'pending' })
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in new issue
Block a user