提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" title="导入流程" width="400"> |
|
3 |
<div> |
|
4 |
<el-upload |
|
5 |
ref="uploadRef" |
|
6 |
v-model:file-list="fileList" |
|
7 |
:action="importUrl" |
|
8 |
:auto-upload="false" |
|
9 |
:data="formData" |
|
10 |
:disabled="formLoading" |
|
11 |
:headers="uploadHeaders" |
|
12 |
:limit="1" |
|
13 |
:on-error="submitFormError" |
|
14 |
:on-exceed="handleExceed" |
|
15 |
:on-success="submitFormSuccess" |
|
16 |
accept=".bpmn, .xml" |
|
17 |
drag |
|
18 |
name="bpmnFile" |
|
19 |
> |
|
20 |
<Icon class="el-icon--upload" icon="ep:upload-filled" /> |
|
21 |
<div class="el-upload__text"> 将文件拖到此处,或 <em>点击上传</em></div> |
|
22 |
<template #tip> |
|
23 |
<div class="el-upload__tip" style="color: red"> |
|
24 |
提示:仅允许导入“bpm”或“xml”格式文件! |
|
25 |
</div> |
|
26 |
<div> |
|
27 |
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px"> |
|
28 |
<el-form-item label="流程标识" prop="key"> |
|
29 |
<el-input |
|
30 |
v-model="formData.key" |
|
31 |
placeholder="请输入流标标识" |
|
32 |
style="width: 250px" |
|
33 |
/> |
|
34 |
</el-form-item> |
|
35 |
<el-form-item label="流程名称" prop="name"> |
|
36 |
<el-input v-model="formData.name" clearable placeholder="请输入流程名称" /> |
|
37 |
</el-form-item> |
|
38 |
<el-form-item label="流程描述" prop="description"> |
|
39 |
<el-input v-model="formData.description" clearable type="textarea" /> |
|
40 |
</el-form-item> |
|
41 |
</el-form> |
|
42 |
</div> |
|
43 |
</template> |
|
44 |
</el-upload> |
|
45 |
</div> |
|
46 |
<template #footer> |
|
47 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
48 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
49 |
</template> |
|
50 |
</Dialog> |
|
51 |
</template> |
|
52 |
<script lang="ts" setup> |
|
53 |
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
54 |
|
|
55 |
defineOptions({ name: 'ModelImportForm' }) |
|
56 |
|
|
57 |
const message = useMessage() // 消息弹窗 |
|
58 |
|
|
59 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
60 |
const formLoading = ref(false) // 表单的加载中 |
|
61 |
const formData = ref({ |
|
62 |
key: '', |
|
63 |
name: '', |
|
64 |
description: '' |
|
65 |
}) |
|
66 |
const formRules = reactive({ |
|
67 |
key: [{ required: true, message: '流程标识不能为空', trigger: 'blur' }], |
|
68 |
name: [{ required: true, message: '流程名称不能为空', trigger: 'blur' }] |
|
69 |
}) |
|
70 |
const formRef = ref() // 表单 Ref |
|
71 |
const uploadRef = ref() // 上传 Ref |
|
72 |
const importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/bpm/model/import' |
|
73 |
const uploadHeaders = ref() // 上传 Header 头 |
|
74 |
const fileList = ref([]) // 文件列表 |
|
75 |
|
|
76 |
/** 打开弹窗 */ |
|
77 |
const open = async () => { |
|
78 |
dialogVisible.value = true |
|
79 |
resetForm() |
|
80 |
} |
|
81 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
82 |
|
|
83 |
/** 提交表单 */ |
|
84 |
const submitForm = async () => { |
|
85 |
// 校验表单 |
|
86 |
if (!formRef) return |
|
87 |
const valid = await formRef.value.validate() |
|
88 |
if (!valid) return |
|
89 |
if (fileList.value.length == 0) { |
|
90 |
message.error('请上传文件') |
|
91 |
return |
|
92 |
} |
|
93 |
// 提交请求 |
|
94 |
uploadHeaders.value = { |
|
95 |
Authorization: 'Bearer ' + getAccessToken(), |
|
96 |
'tenant-id': getTenantId() |
|
97 |
} |
|
98 |
formLoading.value = true |
|
99 |
uploadRef.value!.submit() |
|
100 |
} |
|
101 |
|
|
102 |
/** 文件上传成功 */ |
|
103 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
104 |
const submitFormSuccess = async (response: any) => { |
|
105 |
if (response.code !== 0) { |
|
106 |
message.error(response.msg) |
|
107 |
formLoading.value = false |
|
108 |
return |
|
109 |
} |
|
110 |
// 提示成功 |
|
111 |
message.success('导入流程成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】') |
|
112 |
dialogVisible.value = false |
|
113 |
// 发送操作成功的事件 |
|
114 |
emit('success') |
|
115 |
} |
|
116 |
|
|
117 |
/** 上传错误提示 */ |
|
118 |
const submitFormError = (): void => { |
|
119 |
message.error('导入流程失败,请您重新上传!') |
|
120 |
formLoading.value = false |
|
121 |
} |
|
122 |
|
|
123 |
/** 重置表单 */ |
|
124 |
const resetForm = () => { |
|
125 |
// 重置上传状态和文件 |
|
126 |
formLoading.value = false |
|
127 |
uploadRef.value?.clearFiles() |
|
128 |
// 重置表单 |
|
129 |
formData.value = { |
|
130 |
key: '', |
|
131 |
name: '', |
|
132 |
description: '' |
|
133 |
} |
|
134 |
formRef.value?.resetFields() |
|
135 |
} |
|
136 |
|
|
137 |
/** 文件数超出提示 */ |
|
138 |
const handleExceed = (): void => { |
|
139 |
message.error('最多只能上传一个文件!') |
|
140 |
} |
|
141 |
</script> |