2 天以前 1c1af9b0fc10778ae5ac13cc68fd4030affbcfe1
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
<script lang="ts" setup>
import { computed, ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import { message, Select } from 'ant-design-vue';
 
interface ProcessDefinition {
  id: string;
  name: string;
  key: string;
}
 
type ProcessSubmitFn = (id: number, processDefinitionKey: string) => Promise<unknown>;
 
const emit = defineEmits(['success']);
 
const bizId = ref<number>();
const processList = ref<ProcessDefinition[]>([]);
const selectedProcessKey = ref<string>('');
 
const processOptions = computed(() => {
  return processList.value.map((p) => ({
    label: p.name,
    value: p.key,
  }));
});
 
const [Modal, modalApi] = useVbenModal({
  async onConfirm() {
    if (!selectedProcessKey.value) {
      message.warning('请选择审批流程');
      return;
    }
    modalApi.lock();
    try {
      await modalApi.getData<{ submitFn: ProcessSubmitFn }>().submitFn(
        bizId.value!,
        selectedProcessKey.value,
      );
      await modalApi.close();
      emit('success');
      message.success('提交审批成功');
    } finally {
      modalApi.unlock();
    }
  },
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      bizId.value = undefined;
      selectedProcessKey.value = '';
      processList.value = [];
      return;
    }
    const data = modalApi.getData<{
      id: number;
      processList: ProcessDefinition[];
      submitFn: ProcessSubmitFn;
    }>();
    bizId.value = data.id;
    processList.value = data.processList || [];
    // 默认选择第一个流程
    const first = processList.value[0];
    if (first) {
      selectedProcessKey.value = first.key;
    }
  },
});
</script>
 
<template>
  <Modal title="选择审批流程" class="w-1/3">
    <div class="mb-4">
      <span class="mr-2">审批流程:</span>
      <Select
        v-model:value="selectedProcessKey"
        :options="processOptions"
        style="width: 200px"
        placeholder="请选择审批流程"
      />
    </div>
  </Modal>
</template>