gaoluyang
2026-06-24 c0cb161bb52ce0fbdce5c66ec391d107c75e2452
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
<script lang="ts" setup>
import type { formCreate } from '@form-create/antd-designer';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BpmTaskApi } from '#/api/bpm/task';
 
import { nextTick, ref } from 'vue';
 
import { useVbenModal } from '..\..\..\..\..\packages\effects\common-ui\src';
import { DICT_TYPE } from '..\..\..\..\..\packages\constants\src';
import { IconifyIcon } from '..\..\..\..\..\packages\icons\src';
 
import { Button } from 'ant-design-vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getTaskListByProcessInstanceId } from '#/api/bpm/task';
import { setConfAndFields2 } from '#/components/form-create';
 
defineOptions({
  name: 'BpmProcessInstanceTaskList',
});
 
const props = defineProps<{
  id: string;
  loading: boolean;
}>();
 
/** 表单类型定义 */
interface TaskForm {
  rule: any[];
  option: Record<string, any>;
  value: Record<string, any>;
}
 
/** 获取表格列配置 */
function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'name',
      title: '审批节点',
      minWidth: 150,
    },
    {
      field: 'approver',
      title: '审批人',
      slots: {
        default: ({ row }: { row: BpmTaskApi.Task }) => {
          return row.assigneeUser?.nickname || row.ownerUser?.nickname;
        },
      },
      minWidth: 180,
    },
    {
      field: 'createTime',
      title: '开始时间',
      formatter: 'formatDateTime',
      minWidth: 180,
    },
    {
      field: 'endTime',
      title: '结束时间',
      formatter: 'formatDateTime',
      minWidth: 180,
    },
    {
      field: 'status',
      title: '审批状态',
      minWidth: 150,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.BPM_TASK_STATUS },
      },
    },
    {
      field: 'reason',
      title: '审批建议',
      slots: {
        default: 'slot-reason',
      },
      minWidth: 200,
    },
    {
      field: 'durationInMillis',
      title: '耗时',
      minWidth: 180,
      formatter: 'formatPast2',
    },
  ];
}
 
const formRef = ref<formCreate>();
const taskForm = ref<TaskForm>({
  rule: [],
  option: {},
  value: {},
});
 
const [Modal, modalApi] = useVbenModal({
  title: '查看表单',
  footer: false,
});
 
/** 刷新表格 */
function handleRefresh() {
  gridApi.query();
}
 
/** 显示表单详情 */
async function handleShowFormDetail(row: BpmTaskApi.Task) {
  // 设置表单配置和表单字段
  taskForm.value = {
    rule: [],
    option: {},
    value: row,
  };
  setConfAndFields2(
    taskForm,
    row.formConf,
    row.formFields || [],
    row.formVariables || {},
  );
 
  // 打开弹窗
  modalApi.open();
  // 等待表单渲染
  await nextTick();
  // 获取表单 API 实例
  const formApi = formRef.value?.fapi;
  if (!formApi) {
    return;
  }
  // 设置表单不可编辑
  formApi.btn.show(false);
  formApi.resetBtn.show(false);
  formApi.disabled(true);
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useGridColumns(),
    keepSource: true,
    showFooter: true,
    border: true,
    proxyConfig: {
      ajax: {
        query: async () => {
          return await getTaskListByProcessInstanceId(props.id);
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    pagerConfig: {
      enabled: false,
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions<BpmTaskApi.Task>,
});
 
defineExpose({
  refresh: handleRefresh,
});
</script>
 
<template>
  <div>
    <Grid>
      <template #slot-reason="{ row }">
        <div class="flex flex-wrap items-center justify-center">
          <span v-if="row.reason">{{ row.reason }}</span>
          <span v-else>-</span>
          <Button
            v-if="row.formId > 0"
            type="primary"
            size="small"
            ghost
            class="ml-1"
            @click="handleShowFormDetail(row)"
          >
            <IconifyIcon icon="lucide:file-text" />
            <span class="!ml-0.5 text-xs">查看表单</span>
          </Button>
        </div>
      </template>
    </Grid>
  </div>
  <Modal class="w-3/5">
    <form-create
      ref="formRef"
      v-model="taskForm.value"
      :option="taskForm.option"
      :rule="taskForm.rule"
    />
  </Modal>
</template>