dengzedong
5 天以前 3357b5f0f0919f7a52cd32a6d6de0acb14e0daaf
提交 | 用户 | 时间
820397 1 <template>
H 2
3   <ContentWrap>
4     <!-- 搜索工作栏 -->
5     <el-form
6       class="-mb-15px"
7       :model="queryParams"
8       ref="queryFormRef"
9       :inline="true"
10       label-width="68px"
11     >
12       <el-form-item label="发起人" prop="startUserId">
13         <el-select v-model="queryParams.startUserId" placeholder="请选择发起人" class="!w-240px">
14           <el-option
15             v-for="user in userList"
16             :key="user.id"
17             :label="user.nickname"
18             :value="user.id"
19           />
20         </el-select>
21       </el-form-item>
22       <el-form-item label="流程名称" prop="name">
23         <el-input
24           v-model="queryParams.name"
25           placeholder="请输入流程名称"
26           clearable
27           @keyup.enter="handleQuery"
28           class="!w-240px"
29         />
30       </el-form-item>
31       <el-form-item label="所属流程" prop="processDefinitionId">
32         <el-input
33           v-model="queryParams.processDefinitionId"
34           placeholder="请输入流程定义的编号"
35           clearable
36           @keyup.enter="handleQuery"
37           class="!w-240px"
38         />
39       </el-form-item>
40       <el-form-item label="流程分类" prop="category">
41         <el-select
42           v-model="queryParams.category"
43           placeholder="请选择流程分类"
44           clearable
45           class="!w-240px"
46         >
47           <el-option
48             v-for="category in categoryList"
49             :key="category.code"
50             :label="category.name"
51             :value="category.code"
52           />
53         </el-select>
54       </el-form-item>
55       <el-form-item label="流程状态" prop="status">
56         <el-select
57           v-model="queryParams.status"
58           placeholder="请选择流程状态"
59           clearable
60           class="!w-240px"
61         >
62           <el-option
63             v-for="dict in getIntDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS)"
64             :key="dict.value"
65             :label="dict.label"
66             :value="dict.value"
67           />
68         </el-select>
69       </el-form-item>
70       <el-form-item label="发起时间" prop="createTime">
71         <el-date-picker
72           v-model="queryParams.createTime"
73           value-format="YYYY-MM-DD HH:mm:ss"
74           type="daterange"
75           start-placeholder="开始日期"
76           end-placeholder="结束日期"
77           :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
3e359e 78           class="!w-240px"
820397 79         />
H 80       </el-form-item>
3e359e 81       <el-form-item>
H 82         <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
83         <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
84       </el-form-item>
820397 85     </el-form>
H 86   </ContentWrap>
87
88   <!-- 列表 -->
89   <ContentWrap>
90     <el-table v-loading="loading" :data="list">
91       <el-table-column label="流程名称" align="center" prop="name" min-width="200px" fixed="left" />
92       <el-table-column
93         label="流程分类"
94         align="center"
95         prop="categoryName"
96         min-width="100"
97         fixed="left"
98       />
99       <el-table-column label="流程发起人" align="center" prop="startUser.nickname" width="120" />
100       <el-table-column label="发起部门" align="center" prop="startUser.deptName" width="120" />
101       <el-table-column label="流程状态" prop="status" width="120">
102         <template #default="scope">
103           <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS" :value="scope.row.status" />
104         </template>
105       </el-table-column>
106       <el-table-column
107         label="发起时间"
108         align="center"
109         prop="startTime"
110         width="180"
111         :formatter="dateFormatter"
112       />
113       <el-table-column
114         label="结束时间"
115         align="center"
116         prop="endTime"
117         width="180"
118         :formatter="dateFormatter"
119       />
120       <el-table-column align="center" label="耗时" prop="durationInMillis" width="169">
121         <template #default="scope">
122           {{ scope.row.durationInMillis > 0 ? formatPast2(scope.row.durationInMillis) : '-' }}
123         </template>
124       </el-table-column>
125       <el-table-column label="当前审批任务" align="center" prop="tasks" min-width="120px">
126         <template #default="scope">
127           <el-button type="primary" v-for="task in scope.row.tasks" :key="task.id" link>
128             <span>{{ task.name }}</span>
129           </el-button>
130         </template>
131       </el-table-column>
132       <el-table-column label="流程编号" align="center" prop="id" min-width="320px" />
133       <el-table-column label="操作" align="center" fixed="right" width="180">
134         <template #default="scope">
135           <el-button
136             link
137             type="primary"
138             v-hasPermi="['bpm:process-instance:cancel']"
139             @click="handleDetail(scope.row)"
140           >
141             详情
142           </el-button>
143           <el-button
144             link
145             type="primary"
146             v-if="scope.row.status === 1"
147             v-hasPermi="['bpm:process-instance:query']"
148             @click="handleCancel(scope.row)"
149           >
150             取消
151           </el-button>
152         </template>
153       </el-table-column>
154     </el-table>
155     <!-- 分页 -->
156     <Pagination
157       :total="total"
158       v-model:page="queryParams.pageNo"
159       v-model:limit="queryParams.pageSize"
160       @pagination="getList"
161     />
162   </ContentWrap>
163 </template>
164 <script lang="ts" setup>
165 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
166 import { dateFormatter, formatPast2 } from '@/utils/formatTime'
167 import { ElMessageBox } from 'element-plus'
168 import * as ProcessInstanceApi from '@/api/bpm/processInstance'
169 import { CategoryApi } from '@/api/bpm/category'
170 import * as UserApi from '@/api/system/user'
171 import { cancelProcessInstanceByAdmin } from '@/api/bpm/processInstance'
172
173 // 它和【我的流程】的差异是,该菜单可以看全部的流程实例
174 defineOptions({ name: 'BpmProcessInstanceManager' })
175
176 const router = useRouter() // 路由
177 const message = useMessage() // 消息弹窗
178 const { t } = useI18n() // 国际化
179
180 const loading = ref(true) // 列表的加载中
181 const total = ref(0) // 列表的总页数
182 const list = ref([]) // 列表的数据
183 const queryParams = reactive({
184   pageNo: 1,
185   pageSize: 10,
186   startUserId: undefined,
187   name: '',
188   processDefinitionId: undefined,
189   category: undefined,
190   status: undefined,
191   createTime: []
192 })
193 const queryFormRef = ref() // 搜索的表单
194 const categoryList = ref([]) // 流程分类列表
195 const userList = ref<any[]>([]) // 用户列表
196
197 /** 查询列表 */
198 const getList = async () => {
199   loading.value = true
200   try {
201     const data = await ProcessInstanceApi.getProcessInstanceManagerPage(queryParams)
202     list.value = data.list
203     total.value = data.total
204   } finally {
205     loading.value = false
206   }
207 }
208
209 /** 搜索按钮操作 */
210 const handleQuery = () => {
211   queryParams.pageNo = 1
212   getList()
213 }
214
215 /** 重置按钮操作 */
216 const resetQuery = () => {
217   queryFormRef.value.resetFields()
218   handleQuery()
219 }
220
221 /** 查看详情 */
222 const handleDetail = (row) => {
223   router.push({
224     name: 'BpmProcessInstanceDetail',
225     query: {
226       id: row.id
227     }
228   })
229 }
230
231 /** 取消按钮操作 */
232 const handleCancel = async (row) => {
233   // 二次确认
234   const { value } = await ElMessageBox.prompt('请输入取消原因', '取消流程', {
235     confirmButtonText: t('common.ok'),
236     cancelButtonText: t('common.cancel'),
237     inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
238     inputErrorMessage: '取消原因不能为空'
239   })
240   // 发起取消
241   await ProcessInstanceApi.cancelProcessInstanceByAdmin(row.id, value)
242   message.success('取消成功')
243   // 刷新列表
244   await getList()
245 }
246
247 /** 激活时 **/
248 onActivated(() => {
249   getList()
250 })
251
252 /** 初始化 **/
253 onMounted(async () => {
254   await getList()
255   categoryList.value = await CategoryApi.getCategorySimpleList()
256   userList.value = await UserApi.getSimpleUserList()
257 })
258 </script>