2026-10-15 04:29:44 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 环节配置的分组成人。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 右侧那一栏过去把一个环节的所有开关从上到下摊平,人工环节要滚好几屏才看完。
|
|
|
|
|
|
* 这里把"同一件事的配置"并成一格(处理人 / 表单与字段权限 / 流转与超时 / 抄送与写回……),
|
|
|
|
|
|
* 右栏只留摘要与入口,展开与弹窗读的是同一份分组定义,两处不会各说一套。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 纯计算、不碰 DOM:摘要口径要能被测试钉住,免得以后又变成"只有画布知道自己在配什么"。
|
|
|
|
|
|
*/
|
|
|
|
|
|
import type { Activity } from '@/types'
|
|
|
|
|
|
import { formModeOf } from './formBinding'
|
|
|
|
|
|
import { permsOf } from './formRuntime'
|
|
|
|
|
|
|
|
|
|
|
|
export type NodeGroupKey =
|
|
|
|
|
|
| 'basics'
|
|
|
|
|
|
| 'approver'
|
|
|
|
|
|
| 'form'
|
|
|
|
|
|
| 'collab'
|
|
|
|
|
|
| 'cc'
|
|
|
|
|
|
| 'quota'
|
|
|
|
|
|
| 'routes'
|
|
|
|
|
|
| 'payload'
|
|
|
|
|
|
|
|
|
|
|
|
/** 分组标题:``process.`` 下的 i18n 键。 */
|
|
|
|
|
|
export const NODE_GROUP_LABEL_KEYS: Record<NodeGroupKey, string> = {
|
|
|
|
|
|
basics: 'groupBasics',
|
|
|
|
|
|
approver: 'groupApprover',
|
|
|
|
|
|
form: 'groupForm',
|
|
|
|
|
|
collab: 'groupCollab',
|
|
|
|
|
|
cc: 'groupCc',
|
|
|
|
|
|
quota: 'groupQuota',
|
|
|
|
|
|
routes: 'groupRoutes',
|
|
|
|
|
|
payload: 'groupPayload'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 每种环节有哪几格;顺序就是弹窗里那一列 tab 的顺序。 */
|
|
|
|
|
|
const GROUPS_BY_TYPE: Record<string, NodeGroupKey[]> = {
|
|
|
|
|
|
begin: ['basics'],
|
|
|
|
|
|
manual: ['basics', 'approver', 'form', 'collab', 'cc'],
|
|
|
|
|
|
choice: ['basics', 'routes'],
|
|
|
|
|
|
parallel: ['basics'],
|
|
|
|
|
|
merge: ['basics', 'quota'],
|
|
|
|
|
|
split: ['basics', 'routes'],
|
|
|
|
|
|
script: ['basics', 'payload'],
|
|
|
|
|
|
invoke: ['basics', 'payload'],
|
|
|
|
|
|
embed: ['basics', 'payload'],
|
|
|
|
|
|
delay: ['basics', 'payload'],
|
|
|
|
|
|
end: ['basics', 'cc'],
|
|
|
|
|
|
cancel: ['basics', 'cc']
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 认不出的类型至少要有「基本信息」,别让弹窗开出一个空壳。 */
|
|
|
|
|
|
export function nodeGroups(type: string): NodeGroupKey[] {
|
|
|
|
|
|
return GROUPS_BY_TYPE[type] ?? ['basics']
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 「执行内容」这一格在四种环节上叫不同名字,别让人对着四个字猜。 */
|
|
|
|
|
|
export function groupLabelKey(group: NodeGroupKey, type: string): string {
|
|
|
|
|
|
if (group !== 'payload') return NODE_GROUP_LABEL_KEYS[group]
|
|
|
|
|
|
if (type === 'script') return 'groupPayloadScript'
|
|
|
|
|
|
if (type === 'invoke') return 'groupPayloadInvoke'
|
|
|
|
|
|
if (type === 'embed') return 'groupPayloadEmbed'
|
|
|
|
|
|
if (type === 'delay') return 'groupPayloadDelay'
|
|
|
|
|
|
return NODE_GROUP_LABEL_KEYS.payload
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 协作开关:与环节面板上那一排复选框同一份清单(含单列的退回 / 加签)。 */
|
|
|
|
|
|
export const COLLAB_FLAG_KEYS = [
|
|
|
|
|
|
'allowGoBack',
|
|
|
|
|
|
'allowAddTask',
|
|
|
|
|
|
'allowCc',
|
|
|
|
|
|
'allowShare',
|
|
|
|
|
|
'allowComment',
|
|
|
|
|
|
'allowTransfer',
|
|
|
|
|
|
'allowRecall',
|
|
|
|
|
|
'allowPress'
|
|
|
|
|
|
] as const
|
|
|
|
|
|
|
|
|
|
|
|
export interface GroupDigest {
|
|
|
|
|
|
/** 一行摘要;空串表示这一格没什么可说。 */
|
|
|
|
|
|
text: string
|
|
|
|
|
|
/** warn 用琥珀色:不是错,但多半不是设计者想要的现状。 */
|
|
|
|
|
|
tone?: 'default' | 'warn'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DigestContext {
|
|
|
|
|
|
/** 表单 id → 表单名。 */
|
|
|
|
|
|
formName: (id: string) => string
|
|
|
|
|
|
/** 流程默认表单 id / 名。 */
|
|
|
|
|
|
defaultForm?: string
|
|
|
|
|
|
defaultFormName?: string
|
|
|
|
|
|
/** 子流程 id → 流程名。 */
|
|
|
|
|
|
processName?: (id: string) => string
|
|
|
|
|
|
/** 本环节的出口路由条数:分支那一格要说"现在连成了什么样"。 */
|
|
|
|
|
|
outboundCount?: number
|
|
|
|
|
|
/** 带参数的文案由调用方用 i18n 渲染。 */
|
|
|
|
|
|
fmt: (key: string, params?: Record<string, string | number>) => string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 审批方式那四档的名字,与环节面板上的下拉一致。 */
|
|
|
|
|
|
const MODE_LABEL_KEYS: Record<string, string> = {
|
|
|
|
|
|
any: 'modeAny',
|
|
|
|
|
|
all: 'modeAll',
|
|
|
|
|
|
ratio: 'modeRatio',
|
|
|
|
|
|
serial: 'modeSerial'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const TIMEOUT_LABEL_KEYS: Record<string, string> = {
|
|
|
|
|
|
notify: 'timeoutNotify',
|
|
|
|
|
|
autoPass: 'timeoutPass',
|
|
|
|
|
|
autoReject: 'timeoutReject'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 没写过的开关按"开"算,与运行时默认一致(见 NodeInspector 的 flag())。 */
|
|
|
|
|
|
function flagOn(config: Record<string, unknown>, key: string): boolean {
|
|
|
|
|
|
return Boolean(config[key] ?? true)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function hostOf(url: string): string {
|
|
|
|
|
|
return url.replace(/^[a-z]+:\/\//i, '').split('/')[0] || url
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function approverDigest(node: Activity, fmt: DigestContext['fmt']): GroupDigest {
|
|
|
|
|
|
const config = (node.config ?? {}) as Record<string, unknown>
|
|
|
|
|
|
const modeLabel = fmt(MODE_LABEL_KEYS[String(config.mode ?? 'any')] ?? 'modeAny')
|
|
|
|
|
|
const rows = Array.isArray(config.taskValues) ? (config.taskValues as unknown[]) : []
|
2026-10-19 01:21:20 +00:00
|
|
|
|
// 免审规则只在配了的时候占位:常态是零条,没必要每格都多缀一句「免审 0 条」
|
|
|
|
|
|
const skip = Array.isArray(config.skipRules) ? (config.skipRules as unknown[]) : []
|
|
|
|
|
|
const must = Array.isArray(config.mustRules) ? (config.mustRules as unknown[]) : []
|
|
|
|
|
|
// 两套规则各报各的条数,右栏一行就能看出这一环的条件有多重
|
|
|
|
|
|
const suffix =
|
|
|
|
|
|
(skip.length ? ` · ${fmt('digestSkip', { count: skip.length })}` : '') +
|
|
|
|
|
|
(must.length ? ` · ${fmt('digestMust', { count: must.length })}` : '')
|
|
|
|
|
|
if (String(config.taskScript ?? '').trim()) return { text: `${modeLabel} · ${fmt('digestApproverScript')}${suffix}` }
|
2026-10-15 04:29:44 +00:00
|
|
|
|
if (!rows.length) return { text: fmt('digestApproverEmpty'), tone: 'warn' }
|
2026-10-19 01:21:20 +00:00
|
|
|
|
return { text: `${modeLabel} · ${fmt('digestApproverCount', { count: rows.length })}${suffix}` }
|
2026-10-15 04:29:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formDigest(node: Activity, ctx: DigestContext): GroupDigest {
|
|
|
|
|
|
const { fmt, defaultForm, defaultFormName } = ctx
|
|
|
|
|
|
const own = formModeOf(node) === 'own'
|
|
|
|
|
|
const id = own ? node.form || '' : defaultForm || ''
|
|
|
|
|
|
const name = ctx.formName(id) || (own ? '' : defaultFormName || '')
|
|
|
|
|
|
if (!id) return { text: fmt('digestFormNone'), tone: 'warn' }
|
|
|
|
|
|
return { text: fmt(own ? 'digestOwnForm' : 'digestInheritForm', { name }) }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function collabDigest(node: Activity, fmt: DigestContext['fmt']): GroupDigest {
|
|
|
|
|
|
const config = (node.config ?? {}) as Record<string, unknown>
|
|
|
|
|
|
const touched = COLLAB_FLAG_KEYS.filter((key) => key in config).length
|
|
|
|
|
|
const on = COLLAB_FLAG_KEYS.filter((key) => flagOn(config, key)).length
|
|
|
|
|
|
const parts = [touched ? fmt('digestCollabOn', { on, total: COLLAB_FLAG_KEYS.length }) : fmt('digestCollabDefault')]
|
|
|
|
|
|
const minutes = Number(config.expireValue ?? 0)
|
|
|
|
|
|
if (minutes > 0) {
|
|
|
|
|
|
const action = String(config.timeoutAction ?? 'notify')
|
|
|
|
|
|
parts.push(fmt('digestTimeout', { n: minutes, action: fmt(TIMEOUT_LABEL_KEYS[action] ?? 'timeoutNotify') }))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
parts.push(fmt('digestNoTimer'))
|
|
|
|
|
|
}
|
|
|
|
|
|
return { text: parts.join(' · ') }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ccDigest(node: Activity, fmt: DigestContext['fmt']): GroupDigest {
|
|
|
|
|
|
const config = (node.config ?? {}) as Record<string, unknown>
|
2026-10-19 01:21:20 +00:00
|
|
|
|
const rules = Array.isArray(config.ccRules) ? (config.ccRules as { expression?: string }[]) : []
|
2026-10-15 04:29:44 +00:00
|
|
|
|
const writeback = config.writeback as { integrations?: unknown[] } | undefined
|
|
|
|
|
|
const mounted = Array.isArray(writeback?.integrations) ? writeback.integrations.length : 0
|
2026-10-19 01:21:20 +00:00
|
|
|
|
// 带条件的抄送只在部分单子上发,右栏先说清有几条不是每次都抄
|
|
|
|
|
|
const conditional = rules.filter((rule) => String(rule?.expression ?? '').trim()).length
|
2026-10-15 04:29:44 +00:00
|
|
|
|
const parts = [rules.length ? fmt('digestCc', { count: rules.length }) : fmt('digestCcNone')]
|
2026-10-19 01:21:20 +00:00
|
|
|
|
if (conditional) parts.push(fmt('digestCcCondition', { count: conditional }))
|
2026-10-15 04:29:44 +00:00
|
|
|
|
if (mounted) parts.push(fmt('digestWriteback', { count: mounted }))
|
|
|
|
|
|
return { text: parts.join(' · ') }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function quotaDigest(node: Activity, fmt: DigestContext['fmt']): GroupDigest {
|
|
|
|
|
|
const config = (node.config ?? {}) as Record<string, unknown>
|
|
|
|
|
|
const count = Number(config.passCount ?? 0)
|
|
|
|
|
|
const ratio = Number(config.passRatio ?? 0)
|
|
|
|
|
|
if (count) return { text: fmt('digestQuotaCount', { n: count }) }
|
|
|
|
|
|
if (ratio) return { text: fmt('digestQuotaRatio', { n: ratio }) }
|
|
|
|
|
|
return { text: fmt('digestQuotaNone'), tone: 'warn' }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function routesDigest(node: Activity, ctx: DigestContext): GroupDigest {
|
|
|
|
|
|
const { fmt, outboundCount = 0 } = ctx
|
|
|
|
|
|
if (node.type === 'split') {
|
|
|
|
|
|
const path = String(node.config?.dataPath ?? '').trim()
|
|
|
|
|
|
return path
|
|
|
|
|
|
? { text: `${fmt('digestSplitPath', { path })} · ${fmt('digestRoutes', { count: outboundCount })}` }
|
|
|
|
|
|
: { text: fmt('digestSplitNone'), tone: 'warn' }
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!outboundCount) return { text: fmt('digestRoutesNone'), tone: 'warn' }
|
|
|
|
|
|
return { text: fmt('digestRoutes', { count: outboundCount }) }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function payloadDigest(node: Activity, ctx: DigestContext): GroupDigest {
|
|
|
|
|
|
const { fmt } = ctx
|
|
|
|
|
|
const config = (node.config ?? {}) as Record<string, unknown>
|
|
|
|
|
|
if (node.type === 'script') {
|
|
|
|
|
|
return String(config.script ?? '').trim()
|
|
|
|
|
|
? { text: fmt('digestScriptDone') }
|
|
|
|
|
|
: { text: fmt('digestScriptNone'), tone: 'warn' }
|
|
|
|
|
|
}
|
|
|
|
|
|
if (node.type === 'invoke') {
|
|
|
|
|
|
const url = String(config.url ?? '').trim()
|
|
|
|
|
|
return url ? { text: hostOf(url) } : { text: fmt('digestInvokeNone'), tone: 'warn' }
|
|
|
|
|
|
}
|
|
|
|
|
|
if (node.type === 'embed') {
|
|
|
|
|
|
const id = String(config.process ?? '').trim()
|
|
|
|
|
|
if (!id) return { text: fmt('digestEmbedNone'), tone: 'warn' }
|
|
|
|
|
|
return { text: ctx.processName?.(id) || id }
|
|
|
|
|
|
}
|
|
|
|
|
|
const minutes = Number(config.minutes ?? 0)
|
|
|
|
|
|
return minutes > 0 ? { text: fmt('digestDelay', { n: minutes }) } : { text: fmt('digestDelayNone'), tone: 'warn' }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 字段权限改了几项:右栏要在"表单"那一格下面再说一行。 */
|
|
|
|
|
|
export function permsDigest(node: Activity, fmt: DigestContext['fmt']): GroupDigest {
|
|
|
|
|
|
const count = Object.keys(permsOf(node.config as Record<string, unknown> | null)).length
|
|
|
|
|
|
return { text: count ? fmt('digestPerms', { count }) : fmt('digestPermsNone') }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 一格的摘要:右栏那一行和弹窗里分组标题下的小字都用它。 */
|
|
|
|
|
|
export function groupDigest(group: NodeGroupKey, node: Activity, ctx: DigestContext): GroupDigest {
|
|
|
|
|
|
if (group === 'basics') return { text: String(node.description ?? '').trim() }
|
|
|
|
|
|
if (group === 'approver') return approverDigest(node, ctx.fmt)
|
|
|
|
|
|
if (group === 'form') {
|
|
|
|
|
|
const form = formDigest(node, ctx)
|
|
|
|
|
|
const perms = permsDigest(node, ctx.fmt)
|
|
|
|
|
|
return { text: [form.text, perms.text].filter(Boolean).join(' · '), tone: form.tone }
|
|
|
|
|
|
}
|
|
|
|
|
|
if (group === 'collab') return collabDigest(node, ctx.fmt)
|
|
|
|
|
|
if (group === 'cc') return ccDigest(node, ctx.fmt)
|
|
|
|
|
|
if (group === 'quota') return quotaDigest(node, ctx.fmt)
|
|
|
|
|
|
if (group === 'routes') return routesDigest(node, ctx)
|
|
|
|
|
|
return payloadDigest(node, ctx)
|
|
|
|
|
|
}
|