unis-oa/frontend/src/components/oa/FlowNodeDetail.vue

249 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<section v-if="status" class="card p-5">
<div class="mb-3 flex flex-wrap items-center gap-2">
<h3 class="text-sm font-semibold text-gray-900 dark:text-white">{{ status.name }}</h3>
<span class="badge" :class="badge">{{ stateLabel }}</span>
<span v-if="status.rounds > 1" class="badge badge-warning">{{ t('flow.round', { n: status.rounds }) }}</span>
<button type="button" class="btn btn-ghost btn-sm" @click="emit('close')">
<Icon name="x" class="h-3.5 w-3.5" />
{{ t('common.close') }}
</button>
</div>
<p v-if="status.note" class="mb-3 text-xs text-amber-600 dark:text-amber-400">{{ status.note }}</p>
<p v-else-if="status.state === 'rejected'" class="mb-3 text-xs text-red-600 dark:text-red-400">
{{ t('flow.rejectedTo', { name: status.go_back_to || '--' }) }}
</p>
<ul v-if="status.waiting.length || status.handlers.length" class="space-y-2 text-sm">
<li
v-for="item in status.waiting"
:key="`w-${item.name}-${item.since}`"
class="flex flex-wrap items-center justify-between gap-2 rounded-lg bg-primary-50/60 px-3 py-2 dark:bg-primary-900/20"
>
<span class="min-w-0 font-medium text-gray-800 dark:text-dark-100">
{{ item.name }}
<span v-if="item.unit" class="ml-1 text-xs font-normal text-gray-400">{{ item.unit }}</span>
</span>
<span class="flex flex-wrap items-center gap-1 text-xs text-gray-500 dark:text-dark-400">
<span>{{ t('flow.waiting') }}</span>
<span v-if="item.since">· {{ formatDateTimeToMinute(item.since) }}</span>
<span v-if="item.expire_time">· {{ t('task.expireAt') }} {{ formatDateTimeToMinute(item.expire_time) }}</span>
<span v-if="item.press_count" class="badge badge-warning">{{ t('task.press') }} {{ item.press_count }}</span>
<span v-if="item.delegated" class="badge">{{ t('flow.delegated') }}</span>
<span v-if="item.expired" class="badge badge-danger">{{ t('task.expired') }}</span>
</span>
</li>
<li
v-for="(item, index) in status.handlers"
:key="`h-${item.name}-${item.time}-${index}`"
class="flex flex-wrap items-start justify-between gap-2 rounded-lg bg-gray-50 px-3 py-2 dark:bg-dark-900/50"
>
<span class="min-w-0">
<span class="font-medium text-gray-800 dark:text-dark-100">{{ item.name }}</span>
<span v-if="item.unit" class="ml-1 text-xs text-gray-400">{{ item.unit }}</span>
<span v-if="item.route" class="badge ml-1" :class="routeBadge(item)">{{ item.route }}</span>
<span v-if="item.auto" class="badge ml-1">{{ t('flow.autoPassed') }}</span>
<span v-if="item.retracted" class="badge badge-warning ml-1">{{ t('task.reset') }}</span>
<span v-if="item.opinion" class="mt-1 block whitespace-pre-wrap break-words text-xs text-gray-600 dark:text-dark-300">
{{ item.opinion }}
</span>
</span>
<span class="flex-shrink-0 text-xs text-gray-400">{{ item.time ? formatDateTimeToMinute(item.time) : '' }}</span>
</li>
</ul>
<p v-else class="text-sm text-gray-400">{{ emptyHint }}</p>
<!-- 抄送:这一环实际抄给了谁、看没看、要不要办,以及环节上配了哪几条抄送。
配置与实况是两件事——没走到的那一支也有配置,走到了也可能一条都没抄出去。 -->
<section v-if="cc.people.length || cc.rules.length" class="mt-4 border-t border-gray-100 pt-3 dark:border-dark-700">
<h4 class="mb-2 flex flex-wrap items-center gap-1.5 text-xs font-semibold text-gray-700 dark:text-dark-200">
<Icon name="mail" class="h-3.5 w-3.5 text-gray-400" />
{{ t('flow.cc') }}
<span v-if="cc.people.length" class="font-normal text-gray-500 dark:text-dark-400">{{ peopleCountLine }}</span>
</h4>
<ul v-if="cc.people.length" class="space-y-2 text-sm">
<li
v-for="(item, index) in cc.people"
:key="`cc-${item.identity || item.name}-${index}`"
class="flex flex-wrap items-start justify-between gap-2 rounded-lg bg-gray-50 px-3 py-2 dark:bg-dark-900/50"
>
<span class="min-w-0">
<span class="font-medium text-gray-800 dark:text-dark-100">{{ item.name || '--' }}</span>
<span v-if="item.unit" class="ml-1 text-xs text-gray-400">{{ item.unit }}</span>
<span v-if="item.requires_action" class="badge ml-1" :class="item.handled ? 'badge-success' : 'badge-warning'">
{{ item.handled ? t('flow.ccHandled') : t('flow.ccNeedAction') }}
</span>
<span v-else class="badge ml-1" :class="item.viewed ? 'badge-success' : 'badge-secondary'">
{{ item.viewed ? t('flow.ccViewed') : t('flow.ccUnreadOne') }}
</span>
<!-- 这人后来还在办结之后被转发过一次:同一行上说两句,不另起一段
(转发属整张单,整张单那一本账在轨迹图底下那条横幅里) -->
<span v-if="item.forwarded" class="badge badge-secondary ml-1" :title="t('flow.forwardTitle')">
{{ t('flow.ccAlsoForwarded') }}
</span>
<span v-if="item.sender" class="mt-1 block text-xs text-gray-400">{{ t('flow.ccSender', { name: item.sender }) }}</span>
<span v-if="item.opinion" class="mt-1 block whitespace-pre-wrap break-words text-xs text-gray-600 dark:text-dark-300">
{{ item.opinion }}
</span>
<!-- 他处理这条抄送时上传的图片与文件:卡上是看细节的地方,缩略图直接摆开 -->
<AttachmentGallery v-if="filesOf(item).length" :items="filesOf(item)" data-test="node-cc-files" />
</span>
<span class="flex-shrink-0 text-xs text-gray-400">
{{ item.time ? t('flow.ccSentAt', { time: formatDateTimeToMinute(item.time) }) : '' }}
</span>
</li>
</ul>
<p v-else class="text-xs text-gray-500 dark:text-dark-400">{{ noSendHint }}</p>
<div v-if="cc.rules.length" class="mt-3">
<p class="mb-1.5 text-xs font-medium text-gray-500 dark:text-dark-400">{{ t('flow.ccRulesTitle') }}</p>
<ul class="space-y-1.5 text-xs">
<li
v-for="(rule, index) in cc.rules"
:key="`ccr-${index}`"
class="flex flex-wrap items-baseline gap-x-1.5 gap-y-1 rounded-lg bg-gray-50/80 px-2.5 py-1.5 dark:bg-dark-900/40"
>
<span class="badge badge-secondary">{{ t('flow.ccRuleN', { n: index + 1 }) }}</span>
<span v-if="rule.name" class="text-gray-700 dark:text-dark-200">{{ rule.name }}</span>
<span class="text-gray-500 dark:text-dark-400">{{ whenOf(rule) }}</span>
<span class="text-gray-400">·</span>
<span class="text-gray-500 dark:text-dark-400">{{ t(rule.requires_action ? 'process.ccNeed' : 'process.ccNone') }}</span>
<span v-if="rule.conditional" class="text-amber-600 dark:text-amber-400">· {{ t('flow.ccConditional') }}</span>
<span class="w-full text-gray-600 dark:text-dark-300">
<span class="text-gray-400">{{ t('flow.ccTarget') }}:</span>
<span class="break-words">{{ targetsOf(rule) || t('common.noData') }}</span>
</span>
</li>
</ul>
</div>
</section>
<!-- 办结之后的转发不属某一个环节:归档件上那几条待阅压根没有环节可挂,所以这里
只作一句旁注,说这张单落定之后又被谁递给了谁。它自己站一段,不挤进抄送那一段,
免得「这一环抄给过他」与「办结后转给过他」混成一句话。 -->
<p
v-if="forwardLine"
class="mt-4 flex flex-wrap items-center gap-1.5 border-t border-gray-100 pt-3 text-xs text-gray-500 dark:border-dark-700 dark:text-dark-400"
data-test="node-forward"
>
<Icon name="paperAirplane" class="h-3.5 w-3.5 flex-shrink-0 text-gray-400" />
<span class="font-medium text-gray-700 dark:text-dark-200">{{ t('flow.forwardTitle') }}</span>
<span class="min-w-0 break-words">{{ forwardLine }}</span>
</p>
</section>
</template>
<script setup lang="ts">
/** 轨迹图上点中的环节:谁签了字、写了什么、谁还没办,都在这一张卡里。 */
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import Icon from '@/components/icons/Icon.vue'
import AttachmentGallery from '@/components/oa/AttachmentGallery.vue'
import { formatDateTimeToMinute } from '@/utils/format'
import { resultBadgeClass } from '@/utils/approvalRecord'
import { ccPersonAttachments, ccRuleTargets, ccWhenLabel, forwardBrief } from '@/utils/flowCc'
import { EMPTY_FORWARDS } from '@/utils/flowCc'
import type {
FlowNodeCc,
FlowNodeCcPerson,
FlowNodeCcRule,
FlowNodeHandler,
FlowNodeStatus,
WorkForwardBlock
} from '@/types'
const props = defineProps<{
status: FlowNodeStatus | null
/**
* 整张单的转发账(``detail.flow.forwards``)。
*
* 转发不属某一个环节——归档件上那几条待阅压根没有环节可挂(``oa_work_completed``
* 不落 ``activity``),所以它不能出现在 ``status.cc.people`` 里,只能作为一句旁注:
* 「这张单办结之后被转发给过谁」。不传就不摆这一行(试跑那趟也没有转发)。
*/
forwards?: WorkForwardBlock | null
}>()
const emit = defineEmits<{ (event: 'close'): void }>()
const { t } = useI18n()
/** 收到抄送的那个人处理时附的图与文件(口径见 utils/flowCc::ccPersonAttachments)。 */
function filesOf(person: FlowNodeCcPerson) {
return ccPersonAttachments(person)
}
/** 他点的那条出口:驳回红、同意绿。卡上只写着出口名,判据只能靠名字,与时间线同一套词表。 */
function routeBadge(item: FlowNodeHandler): string {
return resultBadgeClass({ route_name: item.route, processing_type: 'normal' })
}
const stateLabel = computed(() => {
const state = props.status?.state ?? 'pending'
return t(`flow.state${state.charAt(0).toUpperCase()}${state.slice(1)}`)
})
/** 没人签字时也要说清楚为什么是空的:等汇聚、没走到、被终止是三件不同的事。 */
const emptyHint = computed(() => {
switch (props.status?.state) {
case 'active':
return t('flow.waitingHere')
case 'pending':
return t('flow.notReached')
case 'stopped':
return t('flow.stoppedHint')
default:
return t('common.noData')
}
})
const EMPTY_CC: FlowNodeCc = { rules: [], people: [], sent: 0, unread: 0, unhandled: 0 }
/** 整张单的转发那一句话;一次都没转过就是空串,那一行不占地方。 */
const forwardLine = computed(() => forwardBrief(t, props.forwards ?? EMPTY_FORWARDS, { limit: 3 }))
const cc = computed<FlowNodeCc>(() => props.status?.cc ?? EMPTY_CC)
const peopleCountLine = computed(() => {
const info = cc.value
const bits = [t('flow.ccCount', { count: info.sent })]
if (info.unread) bits.push(t('flow.ccUnread', { count: info.unread }))
if (info.unhandled) bits.push(t('flow.ccUnhandled', { count: info.unhandled }))
return bits.join(' · ')
})
/** 配了规则却一个人都没抄到:把三种可能都摆出来,别让人以为是页面坏了。 */
const noSendHint = computed(() => {
if (props.status?.state === 'pending') return t('flow.ccPendingNode')
return cc.value.rules.length ? t('flow.ccRulesNoPeople') : t('flow.ccNoCcYet')
})
/**
* 抄送对象的来源行翻成人话:部门 / 岗位角色 / 发起人上级…
* 说法与审批记录、发起前的环节清单共用 ``utils/flowCc`` 那一份,不在这里另拼一遍。
*/
function targetsOf(rule: FlowNodeCcRule): string {
return ccRuleTargets(t, rule)
}
/** 时机那一句跟着环节类型走:结束 / 作废环节上的「到达」说的是办结那一刻。 */
function whenOf(rule: FlowNodeCcRule): string {
return ccWhenLabel(t, rule, props.status?.type ?? '')
}
const badge = computed(() => {
switch (props.status?.state) {
case 'done':
return 'badge-success'
case 'active':
return 'badge-primary'
case 'rejected':
case 'stopped':
return 'badge-danger'
default:
return 'badge-secondary'
}
})
</script>