提交 | 用户 | 时间
820397 1 <template>
H 2   <ContentWrap>
3     <!-- 搜索工作栏 -->
4     <el-form
5       class="-mb-15px"
6       :model="queryParams"
7       ref="queryFormRef"
8       :inline="true"
9       label-width="68px"
10     >
11       <el-form-item label="流程标识" prop="key">
12         <el-input
13           v-model="queryParams.key"
14           placeholder="请输入流程标识"
15           clearable
16           @keyup.enter="handleQuery"
17           class="!w-240px"
18         />
19       </el-form-item>
20       <el-form-item label="流程名称" prop="name">
21         <el-input
22           v-model="queryParams.name"
23           placeholder="请输入流程名称"
24           clearable
25           @keyup.enter="handleQuery"
26           class="!w-240px"
27         />
28       </el-form-item>
29       <el-form-item label="流程分类" prop="category">
30         <el-select
31           v-model="queryParams.category"
32           placeholder="请选择流程分类"
33           clearable
34           class="!w-240px"
35         >
36           <el-option
37             v-for="category in categoryList"
38             :key="category.code"
39             :label="category.name"
40             :value="category.code"
41           />
42         </el-select>
43       </el-form-item>
44       <el-form-item>
45         <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
46         <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
47         <el-button
48           type="primary"
49           plain
50           @click="openForm('create')"
51           v-hasPermi="['bpm:model:create']"
52         >
53           <Icon icon="ep:plus" class="mr-5px" /> 新建流程
54         </el-button>
55         <el-button type="success" plain @click="openImportForm" v-hasPermi="['bpm:model:import']">
56           <Icon icon="ep:upload" class="mr-5px" /> 导入流程
57         </el-button>
58       </el-form-item>
59     </el-form>
60   </ContentWrap>
61
62   <!-- 列表 -->
63   <ContentWrap>
64     <el-table v-loading="loading" :data="list">
65       <el-table-column label="流程标识" align="center" prop="key" width="200" />
66       <el-table-column label="流程名称" align="center" prop="name" width="200">
67         <template #default="scope">
68           <el-button type="primary" link @click="handleBpmnDetail(scope.row)">
69             <span>{{ scope.row.name }}</span>
70           </el-button>
71         </template>
72       </el-table-column>
73       <el-table-column label="流程图标" align="center" prop="icon" width="100">
74         <template #default="scope">
75           <el-image :src="scope.row.icon" class="w-32px h-32px" />
76         </template>
77       </el-table-column>
78       <el-table-column label="流程分类" align="center" prop="categoryName" width="100" />
79       <el-table-column label="表单信息" align="center" prop="formType" width="200">
80         <template #default="scope">
81           <el-button
82             v-if="scope.row.formType === 10"
83             type="primary"
84             link
85             @click="handleFormDetail(scope.row)"
86           >
87             <span>{{ scope.row.formName }}</span>
88           </el-button>
89           <el-button
90             v-else-if="scope.row.formType === 20"
91             type="primary"
92             link
93             @click="handleFormDetail(scope.row)"
94           >
95             <span>{{ scope.row.formCustomCreatePath }}</span>
96           </el-button>
97           <label v-else>暂无表单</label>
98         </template>
99       </el-table-column>
100       <el-table-column
101         label="创建时间"
102         align="center"
103         prop="createTime"
104         width="180"
105         :formatter="dateFormatter"
106       />
107       <el-table-column label="最新部署的流程定义" align="center">
108         <el-table-column
109           label="流程版本"
110           align="center"
111           prop="processDefinition.version"
112           width="100"
113         >
114           <template #default="scope">
115             <el-tag v-if="scope.row.processDefinition">
116               v{{ scope.row.processDefinition.version }}
117             </el-tag>
118             <el-tag v-else type="warning">未部署</el-tag>
119           </template>
120         </el-table-column>
121         <el-table-column
122           label="激活状态"
123           align="center"
124           prop="processDefinition.version"
125           width="85"
126         >
127           <template #default="scope">
128             <el-switch
129               v-if="scope.row.processDefinition"
130               v-model="scope.row.processDefinition.suspensionState"
131               :active-value="1"
132               :inactive-value="2"
133               @change="handleChangeState(scope.row)"
134             />
135           </template>
136         </el-table-column>
137         <el-table-column label="部署时间" align="center" prop="deploymentTime" width="180">
138           <template #default="scope">
139             <span v-if="scope.row.processDefinition">
140               {{ formatDate(scope.row.processDefinition.deploymentTime) }}
141             </span>
142           </template>
143         </el-table-column>
144       </el-table-column>
145       <el-table-column label="操作" align="center" width="240" fixed="right">
146         <template #default="scope">
147           <el-button
148             link
149             type="primary"
150             @click="openForm('update', scope.row.id)"
151             v-hasPermi="['bpm:model:update']"
152           >
153             修改流程
154           </el-button>
155           <el-button
156             link
157             type="primary"
158             @click="handleDesign(scope.row)"
159             v-hasPermi="['bpm:model:update']"
160           >
161             设计流程
162           </el-button>
163           <el-button
164             link
165             type="primary"
166             @click="handleSimpleDesign(scope.row.id)"
167             v-hasPermi="['bpm:model:update']"
168           >
169             仿钉钉设计流程
170           </el-button>
171           <el-button
172             link
173             type="primary"
174             @click="handleDeploy(scope.row)"
175             v-hasPermi="['bpm:model:deploy']"
176           >
177             发布流程
178           </el-button>
179           <el-button
180             link
181             type="primary"
182             v-hasPermi="['bpm:process-definition:query']"
183             @click="handleDefinitionList(scope.row)"
184           >
185             流程定义
186           </el-button>
187           <el-button
188             link
189             type="danger"
190             @click="handleDelete(scope.row.id)"
191             v-hasPermi="['bpm:model:delete']"
192           >
193             删除
194           </el-button>
195         </template>
196       </el-table-column>
197     </el-table>
198     <!-- 分页 -->
199     <Pagination
200       :total="total"
201       v-model:page="queryParams.pageNo"
202       v-model:limit="queryParams.pageSize"
203       @pagination="getList"
204     />
205   </ContentWrap>
206
207   <!-- 表单弹窗:添加/修改流程 -->
208   <ModelForm ref="formRef" @success="getList" />
209
210   <!-- 表单弹窗:导入流程 -->
211   <ModelImportForm ref="importFormRef" @success="getList" />
212
213   <!-- 弹窗:表单详情 -->
214   <Dialog title="表单详情" v-model="formDetailVisible" width="800">
215     <form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
216   </Dialog>
217
218   <!-- 弹窗:流程模型图的预览 -->
219   <Dialog title="流程图" v-model="bpmnDetailVisible" width="800">
220     <MyProcessViewer
221       key="designer"
222       v-model="bpmnXML"
223       :value="bpmnXML as any"
224       v-bind="bpmnControlForm"
225       :prefix="bpmnControlForm.prefix"
226     />
227   </Dialog>
228 </template>
229
230 <script lang="ts" setup>
231 import { dateFormatter, formatDate } from '@/utils/formatTime'
232 import { MyProcessViewer } from '@/components/bpmnProcessDesigner/package'
233 import * as ModelApi from '@/api/bpm/model'
234 import * as FormApi from '@/api/bpm/form'
235 import ModelForm from './ModelForm.vue'
236 import ModelImportForm from '@/views/bpm/model/ModelImportForm.vue'
237 import { setConfAndFields2 } from '@/utils/formCreate'
238 import { CategoryApi } from '@/api/bpm/category'
239
240 defineOptions({ name: 'BpmModel' })
241
242 const message = useMessage() // 消息弹窗
243 const { t } = useI18n() // 国际化
244 const { push } = useRouter() // 路由
245
246 const loading = ref(true) // 列表的加载中
247 const total = ref(0) // 列表的总页数
248 const list = ref([]) // 列表的数据
249 const queryParams = reactive({
250   pageNo: 1,
251   pageSize: 10,
252   key: undefined,
253   name: undefined,
254   category: undefined
255 })
256 const queryFormRef = ref() // 搜索的表单
257 const categoryList = ref([]) // 流程分类列表
258
259 /** 查询列表 */
260 const getList = async () => {
261   loading.value = true
262   try {
263     const data = await ModelApi.getModelPage(queryParams)
264     list.value = data.list
265     total.value = data.total
266   } finally {
267     loading.value = false
268   }
269 }
270
271 /** 搜索按钮操作 */
272 const handleQuery = () => {
273   queryParams.pageNo = 1
274   getList()
275 }
276
277 /** 重置按钮操作 */
278 const resetQuery = () => {
279   queryFormRef.value.resetFields()
280   handleQuery()
281 }
282
283 /** 添加/修改操作 */
284 const formRef = ref()
285 const openForm = (type: string, id?: number) => {
286   formRef.value.open(type, id)
287 }
288
289 /** 添加/修改操作 */
290 const importFormRef = ref()
291 const openImportForm = () => {
292   importFormRef.value.open()
293 }
294
295 /** 删除按钮操作 */
296 const handleDelete = async (id: number) => {
297   try {
298     // 删除的二次确认
299     await message.delConfirm()
300     // 发起删除
301     await ModelApi.deleteModel(id)
302     message.success(t('common.delSuccess'))
303     // 刷新列表
304     await getList()
305   } catch {}
306 }
307
308 /** 更新状态操作 */
309 const handleChangeState = async (row) => {
310   const state = row.processDefinition.suspensionState
311   try {
312     // 修改状态的二次确认
313     const id = row.id
314     const statusState = state === 1 ? '激活' : '挂起'
315     const content = '是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?'
316     await message.confirm(content)
317     // 发起修改状态
318     await ModelApi.updateModelState(id, state)
319     // 刷新列表
320     await getList()
321   } catch {
322     // 取消后,进行恢复按钮
323     row.processDefinition.suspensionState = state === 1 ? 2 : 1
324   }
325 }
326
327 /** 设计流程 */
328 const handleDesign = (row) => {
329   push({
330     name: 'BpmModelEditor',
331     query: {
332       modelId: row.id
333     }
334   })
335 }
336
337 const handleSimpleDesign = (row) => {
338   push({
339     name: 'SimpleWorkflowDesignEditor',
340     query: {
341       modelId: row.id
342     }
343   })
344 }
345
346 /** 发布流程 */
347 const handleDeploy = async (row) => {
348   try {
349     // 删除的二次确认
350     await message.confirm('是否部署该流程!!')
351     // 发起部署
352     await ModelApi.deployModel(row.id)
353     message.success(t('部署成功'))
354     // 刷新列表
355     await getList()
356   } catch {}
357 }
358
359 /** 跳转到指定流程定义列表 */
360 const handleDefinitionList = (row) => {
361   push({
362     name: 'BpmProcessDefinition',
363     query: {
364       key: row.key
365     }
366   })
367 }
368
369 /** 流程表单的详情按钮操作 */
370 const formDetailVisible = ref(false)
371 const formDetailPreview = ref({
372   rule: [],
373   option: {}
374 })
375 const handleFormDetail = async (row) => {
376   if (row.formType == 10) {
377     // 设置表单
378     const data = await FormApi.getForm(row.formId)
379     setConfAndFields2(formDetailPreview, data.conf, data.fields)
380     // 弹窗打开
381     formDetailVisible.value = true
382   } else {
383     await push({
384       path: row.formCustomCreatePath
385     })
386   }
387 }
388
389 /** 流程图的详情按钮操作 */
390 const bpmnDetailVisible = ref(false)
391 const bpmnXML = ref(null)
392 const bpmnControlForm = ref({
393   prefix: 'flowable'
394 })
395 const handleBpmnDetail = async (row) => {
396   const data = await ModelApi.getModel(row.id)
397   bpmnXML.value = data.bpmnXml || ''
398   bpmnDetailVisible.value = true
399 }
400
401 /** 初始化 **/
402 onMounted(async () => {
403   await getList()
404   // 查询流程分类列表
405   categoryList.value = await CategoryApi.getCategorySimpleList()
406 })
407 </script>