gaoluyang
2026-11-03 2d8b1a28fa5c8b852f0d0078bac4894bfb4abed5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<script setup lang="ts">
  /**
   * 审批流程展示(对应 web 端 processInstance/detail/modules/time-line.vue)
   *
   * 用于「发起流程」的节点预测 与「审批详情」的审批流。
   * 移动端不渲染 bpmn-js 流程图,这里用竖向节点流替代,信息与 web 端一致:
   * 节点类型图标 + 节点状态色 + 人员 + 时间 + 审批意见。
   */
  import {
    CANDIDATE_STRATEGY_START_USER_SELECT,
    dateTimeText,
    NODE_STATUS_META,
    NODE_TYPE,
  } from "../shared";
  import type { BpmApprovalNode } from "../../../api/bpm";
 
  const props = withDefaults(
    defineProps<{
      /** 审批节点(来自 get-approval-detail 的 activityNodes) */
      nodes?: BpmApprovalNode[];
      /** 是否显示状态文案(发起页只做预测,节点都未开始,可不显示) */
      showStatus?: boolean;
      /** 是否允许选择审批人(发起人自选节点) */
      selectable?: boolean;
      /** 已选审批人:activityId -> 文案 */
      pickedText?: Record<string, string>;
      /** 空态文案 */
      emptyText?: string;
    }>(),
    {
      nodes: () => [],
      showStatus: true,
      selectable: false,
      pickedText: () => ({}),
      emptyText: "暂无审批节点",
    },
  );
 
  const emit = defineEmits<{
    /** 点击某个需要自选审批人的节点 */
    (e: "pickUser", node: BpmApprovalNode): void;
  }>();
 
  /** 节点类型 -> 图标字符(沿用 web 端 nodeTypeSvgMap 语义,移动端用字符表示) */
  const NODE_ICON: Record<number, string> = {
    [NODE_TYPE.START_USER_NODE]: "起",
    [NODE_TYPE.USER_TASK_NODE]: "审",
    [NODE_TYPE.TRANSACTOR_NODE]: "办",
    [NODE_TYPE.COPY_TASK_NODE]: "抄",
    [NODE_TYPE.CONDITION_NODE]: "条",
    [NODE_TYPE.PARALLEL_BRANCH_NODE]: "并",
    [NODE_TYPE.INCLUSIVE_BRANCH_NODE]: "或",
    [NODE_TYPE.ROUTER_BRANCH_NODE]: "路",
    [NODE_TYPE.CHILD_PROCESS_NODE]: "子",
    [NODE_TYPE.END_EVENT_NODE]: "终",
  };
 
  function nodeIcon(node: BpmApprovalNode) {
    return NODE_ICON[Number(node.nodeType)] ?? "·";
  }
 
  function nodeColor(node: BpmApprovalNode) {
    return (NODE_STATUS_META[Number(node.status)] ?? { color: "#909398" }).color;
  }
 
  function nodeStatusLabel(node: BpmApprovalNode) {
    return (NODE_STATUS_META[Number(node.status)] ?? { label: "--" }).label;
  }
 
  /** 节点时间:开始节点只显示 startTime,其余优先 endTime(与 web 端一致) */
  function nodeTime(node: BpmApprovalNode) {
    if (Number(node.nodeType) === NODE_TYPE.START_USER_NODE && node.startTime) {
      return dateTimeText(node.startTime);
    }
    if (node.endTime) return dateTimeText(node.endTime);
    if (node.startTime) return dateTimeText(node.startTime);
    return "";
  }
 
  /** web 端只在节点已开始(status !== -1)时显示时间 */
  function showNodeTime(node: BpmApprovalNode) {
    return Number(node.status) !== -1 && Boolean(nodeTime(node));
  }
 
  /** 人员昵称:优先 assigneeUser,其次 ownerUser,最后候选人员 */
  function nodeUserNames(node: BpmApprovalNode) {
    const names: string[] = [];
    (node.tasks || []).forEach(task => {
      const name = task.assigneeUser?.nickname || task.ownerUser?.nickname;
      if (name && !names.includes(name)) names.push(name);
    });
    if (!names.length) {
      (node.candidateUsers || []).forEach(user => {
        if (user.nickname && !names.includes(user.nickname)) names.push(user.nickname);
      });
    }
    return names;
  }
 
  /** 审批意见(去重) */
  function nodeReasons(node: BpmApprovalNode) {
    const reasons: string[] = [];
    (node.tasks || []).forEach(task => {
      if (task.reason && !reasons.includes(task.reason)) reasons.push(task.reason);
    });
    return reasons;
  }
 
  /** 是否需要展示「自选审批人」入口 */
  function needPickUser(node: BpmApprovalNode) {
    if (!props.selectable) return false;
    // 发起人自选策略(35)+ 无候选人时由用户自己挑(与 web 端 shouldShowCustomUserSelect 一致)
    return (
      Number(node.candidateStrategy) === CANDIDATE_STRATEGY_START_USER_SELECT &&
      !nodeUserNames(node).length
    );
  }
</script>
 
<template>
  <view class="flow">
    <view v-if="!nodes.length" class="flow-empty">{{ emptyText }}</view>
 
    <view v-for="(node, index) in nodes" :key="node.id || index" class="node">
      <!-- 左侧:节点图标 + 连接线 -->
      <view class="node-rail">
        <view class="node-icon" :style="{ background: nodeColor(node) }">
          {{ nodeIcon(node) }}
        </view>
        <view v-if="index !== nodes.length - 1" class="node-line" />
      </view>
 
      <!-- 右侧:节点内容 -->
      <view class="node-body">
        <view class="node-head">
          <text class="node-name">
            {{ node.name || "--" }}
            <text v-if="Number(node.status) === -2" class="node-skip">【跳过】</text>
          </text>
          <text v-if="showStatus" class="node-status" :style="{ color: nodeColor(node) }">
            {{ nodeStatusLabel(node) }}
          </text>
        </view>
 
        <text v-if="showNodeTime(node)" class="node-time">
          {{ nodeTime(node) }}
        </text>
 
        <!-- 人员 -->
        <view v-if="nodeUserNames(node).length" class="node-users">
          <text
            v-for="name in nodeUserNames(node)"
            :key="name"
            class="node-user"
          >
            {{ name }}
          </text>
        </view>
 
        <!-- 自选审批人入口 -->
        <view v-if="needPickUser(node)" class="node-pick" @click="emit('pickUser', node)">
          <text class="node-pick-text">
            {{ pickedText[String(node.id)] || "请选择审批人" }}
          </text>
          <text class="node-pick-arrow">›</text>
        </view>
        <view v-else-if="pickedText[String(node.id)]" class="node-users">
          <text class="node-user picked">{{ pickedText[String(node.id)] }}</text>
        </view>
 
        <!-- 审批意见 -->
        <view v-for="reason in nodeReasons(node)" :key="reason" class="node-reason">
          审批意见:{{ reason }}
        </view>
      </view>
    </view>
  </view>
</template>
 
<style scoped lang="scss">
  .flow {
    padding: 4rpx 0;
  }
 
  .flow-empty {
    padding: 30rpx 0;
    color: #9aa8ba;
    font-size: 25rpx;
    text-align: center;
  }
 
  .node {
    display: flex;
    gap: 20rpx;
  }
 
  .node-rail {
    display: flex;
    flex: none;
    flex-direction: column;
    align-items: center;
    width: 56rpx;
  }
 
  .node-icon {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44rpx;
    height: 44rpx;
    color: #fff;
    font-size: 22rpx;
    border-radius: 50%;
  }
 
  .node-line {
    flex: 1;
    width: 2rpx;
    min-height: 24rpx;
    margin: 6rpx 0;
    background: #e6ecf4;
  }
 
  .node-body {
    flex: 1;
    min-width: 0;
    padding-bottom: 26rpx;
  }
 
  .node-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14rpx;
  }
 
  .node-name {
    color: #20334c;
    font-size: 27rpx;
    font-weight: 500;
  }
 
  .node-skip {
    color: #909398;
    font-size: 23rpx;
  }
 
  .node-status {
    flex: none;
    font-size: 23rpx;
  }
 
  .node-time {
    display: block;
    margin-top: 6rpx;
    color: #93a1b3;
    font-size: 22rpx;
  }
 
  .node-users {
    display: flex;
    flex-wrap: wrap;
    gap: 12rpx;
    margin-top: 10rpx;
  }
 
  .node-user {
    padding: 6rpx 18rpx;
    color: #3d5069;
    font-size: 23rpx;
    background: #f2f5f9;
    border-radius: 999rpx;
  }
 
  .node-user.picked {
    color: var(--color-primary, #1769d8);
    background: #eef4fd;
  }
 
  .node-pick {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12rpx;
    padding: 16rpx 22rpx;
    margin-top: 12rpx;
    background: #f7f8fa;
    border: 1rpx solid #e2e8f1;
    border-radius: 12rpx;
  }
 
  .node-pick-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: #b3bcc9;
    font-size: 25rpx;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
 
  .node-pick-arrow {
    flex: none;
    color: #c2cad6;
    font-size: 32rpx;
    line-height: 1;
  }
 
  .node-reason {
    padding: 12rpx 16rpx;
    margin-top: 10rpx;
    color: #78879b;
    font-size: 23rpx;
    line-height: 1.6;
    background: #f7f9fc;
    border-radius: 10rpx;
  }
</style>