提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle" width="600"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="110px" |
|
9 |
> |
|
10 |
<el-form-item label="流程标识" prop="key"> |
|
11 |
<el-input |
|
12 |
v-model="formData.key" |
|
13 |
:disabled="!!formData.id" |
|
14 |
placeholder="请输入流标标识" |
|
15 |
style="width: 330px" |
|
16 |
/> |
|
17 |
<el-tooltip |
|
18 |
v-if="!formData.id" |
|
19 |
class="item" |
|
20 |
content="新建后,流程标识不可修改!" |
|
21 |
effect="light" |
|
22 |
placement="top" |
|
23 |
> |
|
24 |
<i class="el-icon-question" style="padding-left: 5px"></i> |
|
25 |
</el-tooltip> |
|
26 |
<el-tooltip v-else class="item" content="流程标识不可修改!" effect="light" placement="top"> |
|
27 |
<i class="el-icon-question" style="padding-left: 5px"></i> |
|
28 |
</el-tooltip> |
|
29 |
</el-form-item> |
|
30 |
<el-form-item label="流程名称" prop="name"> |
|
31 |
<el-input |
|
32 |
v-model="formData.name" |
|
33 |
:disabled="!!formData.id" |
|
34 |
clearable |
|
35 |
placeholder="请输入流程名称" |
|
36 |
/> |
|
37 |
</el-form-item> |
|
38 |
<el-form-item v-if="formData.id" label="流程分类" prop="category"> |
|
39 |
<el-select |
|
40 |
v-model="formData.category" |
|
41 |
clearable |
|
42 |
placeholder="请选择流程分类" |
|
43 |
style="width: 100%" |
|
44 |
> |
|
45 |
<el-option |
|
46 |
v-for="category in categoryList" |
|
47 |
:key="category.code" |
|
48 |
:label="category.name" |
|
49 |
:value="category.code" |
|
50 |
/> |
|
51 |
</el-select> |
|
52 |
</el-form-item> |
|
53 |
<el-form-item v-if="formData.id" label="流程图标" prop="icon"> |
|
54 |
<UploadImg v-model="formData.icon" :limit="1" height="128px" width="128px" /> |
|
55 |
</el-form-item> |
|
56 |
<el-form-item label="流程描述" prop="description"> |
|
57 |
<el-input v-model="formData.description" clearable type="textarea" /> |
|
58 |
</el-form-item> |
|
59 |
<div v-if="formData.id"> |
|
60 |
<el-form-item label="表单类型" prop="formType"> |
|
61 |
<el-radio-group v-model="formData.formType"> |
|
62 |
<el-radio |
|
63 |
v-for="dict in getIntDictOptions(DICT_TYPE.BPM_MODEL_FORM_TYPE)" |
|
64 |
:key="dict.value" |
|
65 |
:label="dict.value" |
|
66 |
> |
|
67 |
{{ dict.label }} |
|
68 |
</el-radio> |
|
69 |
</el-radio-group> |
|
70 |
</el-form-item> |
|
71 |
<el-form-item v-if="formData.formType === 10" label="流程表单" prop="formId"> |
|
72 |
<el-select v-model="formData.formId" clearable style="width: 100%"> |
|
73 |
<el-option |
|
74 |
v-for="form in formList" |
|
75 |
:key="form.id" |
|
76 |
:label="form.name" |
|
77 |
:value="form.id" |
|
78 |
/> |
|
79 |
</el-select> |
|
80 |
</el-form-item> |
|
81 |
<el-form-item |
|
82 |
v-if="formData.formType === 20" |
|
83 |
label="表单提交路由" |
|
84 |
prop="formCustomCreatePath" |
|
85 |
> |
|
86 |
<el-input |
|
87 |
v-model="formData.formCustomCreatePath" |
|
88 |
placeholder="请输入表单提交路由" |
|
89 |
style="width: 330px" |
|
90 |
/> |
|
91 |
<el-tooltip |
|
92 |
class="item" |
|
93 |
content="自定义表单的提交路径,使用 Vue 的路由地址,例如说:bpm/oa/leave/create" |
|
94 |
effect="light" |
|
95 |
placement="top" |
|
96 |
> |
|
97 |
<i class="el-icon-question" style="padding-left: 5px"></i> |
|
98 |
</el-tooltip> |
|
99 |
</el-form-item> |
|
100 |
<el-form-item |
|
101 |
v-if="formData.formType === 20" |
|
102 |
label="表单查看地址" |
|
103 |
prop="formCustomViewPath" |
|
104 |
> |
|
105 |
<el-input |
|
106 |
v-model="formData.formCustomViewPath" |
|
107 |
placeholder="请输入表单查看的组件地址" |
|
108 |
style="width: 330px" |
|
109 |
/> |
|
110 |
<el-tooltip |
|
111 |
class="item" |
|
112 |
content="自定义表单的查看组件地址,使用 Vue 的组件地址,例如说:bpm/oa/leave/detail" |
|
113 |
effect="light" |
|
114 |
placement="top" |
|
115 |
> |
|
116 |
<i class="el-icon-question" style="padding-left: 5px"></i> |
|
117 |
</el-tooltip> |
|
118 |
</el-form-item> |
|
119 |
</div> |
|
120 |
</el-form> |
|
121 |
<template #footer> |
|
122 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
123 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
124 |
</template> |
|
125 |
</Dialog> |
|
126 |
</template> |
|
127 |
<script lang="ts" setup> |
|
128 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
129 |
import { ElMessageBox } from 'element-plus' |
|
130 |
import * as ModelApi from '@/api/bpm/model' |
|
131 |
import * as FormApi from '@/api/bpm/form' |
|
132 |
import { CategoryApi } from '@/api/bpm/category' |
|
133 |
|
|
134 |
defineOptions({ name: 'ModelForm' }) |
|
135 |
|
|
136 |
const { t } = useI18n() // 国际化 |
|
137 |
const message = useMessage() // 消息弹窗 |
|
138 |
|
|
139 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
140 |
const dialogTitle = ref('') // 弹窗的标题 |
|
141 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
142 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
143 |
const formData = ref({ |
|
144 |
formType: 10, |
|
145 |
name: '', |
|
146 |
category: undefined, |
|
147 |
icon: undefined, |
|
148 |
description: '', |
|
149 |
formId: '', |
|
150 |
formCustomCreatePath: '', |
|
151 |
formCustomViewPath: '' |
|
152 |
}) |
|
153 |
const formRules = reactive({ |
|
154 |
name: [{ required: true, message: '参数名称不能为空', trigger: 'blur' }], |
|
155 |
key: [{ required: true, message: '参数键名不能为空', trigger: 'blur' }], |
|
156 |
category: [{ required: true, message: '参数分类不能为空', trigger: 'blur' }], |
|
157 |
icon: [{ required: true, message: '参数图标不能为空', trigger: 'blur' }], |
|
158 |
value: [{ required: true, message: '参数键值不能为空', trigger: 'blur' }], |
|
159 |
visible: [{ required: true, message: '是否可见不能为空', trigger: 'blur' }] |
|
160 |
}) |
|
161 |
const formRef = ref() // 表单 Ref |
|
162 |
const formList = ref([]) // 流程表单的下拉框的数据 |
|
163 |
const categoryList = ref([]) // 流程分类列表 |
|
164 |
|
|
165 |
/** 打开弹窗 */ |
|
166 |
const open = async (type: string, id?: number) => { |
|
167 |
dialogVisible.value = true |
|
168 |
dialogTitle.value = t('action.' + type) |
|
169 |
formType.value = type |
|
170 |
resetForm() |
|
171 |
// 修改时,设置数据 |
|
172 |
if (id) { |
|
173 |
formLoading.value = true |
|
174 |
try { |
|
175 |
formData.value = await ModelApi.getModel(id) |
|
176 |
} finally { |
|
177 |
formLoading.value = false |
|
178 |
} |
|
179 |
} |
|
180 |
// 获得流程表单的下拉框的数据 |
|
181 |
formList.value = await FormApi.getFormSimpleList() |
|
182 |
// 查询流程分类列表 |
|
183 |
categoryList.value = await CategoryApi.getCategorySimpleList() |
|
184 |
} |
|
185 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
186 |
|
|
187 |
/** 提交表单 */ |
|
188 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
189 |
const submitForm = async () => { |
|
190 |
// 校验表单 |
|
191 |
if (!formRef) return |
|
192 |
const valid = await formRef.value.validate() |
|
193 |
if (!valid) return |
|
194 |
// 提交请求 |
|
195 |
formLoading.value = true |
|
196 |
try { |
|
197 |
const data = formData.value as unknown as ModelApi.ModelVO |
|
198 |
if (formType.value === 'create') { |
|
199 |
await ModelApi.createModel(data) |
|
200 |
// 提示,引导用户做后续的操作 |
|
201 |
await ElMessageBox.alert( |
|
202 |
'<strong>新建模型成功!</strong>后续需要执行如下 3 个步骤:' + |
|
203 |
'<div>1. 点击【修改流程】按钮,配置流程的分类、表单信息</div>' + |
|
204 |
'<div>2. 点击【设计流程】按钮,绘制流程图</div>' + |
|
205 |
'<div>3. 点击【发布流程】按钮,完成流程的最终发布</div>' + |
|
206 |
'另外,每次流程修改后,都需要点击【发布流程】按钮,才能正式生效!!!', |
|
207 |
'重要提示', |
|
208 |
{ |
|
209 |
dangerouslyUseHTMLString: true, |
|
210 |
type: 'success' |
|
211 |
} |
|
212 |
) |
|
213 |
} else { |
|
214 |
await ModelApi.updateModel(data) |
|
215 |
message.success(t('common.updateSuccess')) |
|
216 |
} |
|
217 |
dialogVisible.value = false |
|
218 |
// 发送操作成功的事件 |
|
219 |
emit('success') |
|
220 |
} finally { |
|
221 |
formLoading.value = false |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
/** 重置表单 */ |
|
226 |
const resetForm = () => { |
|
227 |
formData.value = { |
|
228 |
formType: 10, |
|
229 |
name: '', |
|
230 |
category: undefined, |
|
231 |
icon: '', |
|
232 |
description: '', |
|
233 |
formId: '', |
|
234 |
formCustomCreatePath: '', |
|
235 |
formCustomViewPath: '' |
|
236 |
} |
|
237 |
formRef.value?.resetFields() |
|
238 |
} |
|
239 |
</script> |