Cap the sticky footer at two primary actions and park the rest in a more sheet. Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
export type MpDetailActionKind =
|
|
| 'edit'
|
|
| 'arrange'
|
|
| 'copy'
|
|
| 'wait'
|
|
| 'cancel-wait'
|
|
| 'print'
|
|
| 'void'
|
|
|
|
export type MpDetailAction = {
|
|
kind: MpDetailActionKind
|
|
label: string
|
|
danger?: boolean
|
|
}
|
|
|
|
/** 主栏最多 2 个:优先 edit、arrange;其余进 more */
|
|
export function splitMpPlanDetailActions(input: {
|
|
canEdit: boolean
|
|
canArrange: boolean
|
|
arrangeLabel: string
|
|
canWait: boolean
|
|
canCancelWait: boolean
|
|
canVoid: boolean
|
|
}): { primary: MpDetailAction[]; more: MpDetailAction[] } {
|
|
const primary: MpDetailAction[] = []
|
|
const more: MpDetailAction[] = []
|
|
|
|
if (input.canEdit) primary.push({ kind: 'edit', label: '编辑' })
|
|
if (input.canArrange) {
|
|
primary.push({ kind: 'arrange', label: input.arrangeLabel })
|
|
}
|
|
|
|
more.push({ kind: 'copy', label: '复制' })
|
|
if (input.canWait) more.push({ kind: 'wait', label: '等客户通知' })
|
|
if (input.canCancelWait) more.push({ kind: 'cancel-wait', label: '取消等通知' })
|
|
more.push({ kind: 'print', label: '打印单据' })
|
|
if (input.canVoid) more.push({ kind: 'void', label: '作废', danger: true })
|
|
|
|
while (primary.length > 2) more.unshift(primary.pop()!)
|
|
while (primary.length < 2 && more.length) {
|
|
primary.push(more.shift()!)
|
|
}
|
|
return { primary, more }
|
|
}
|