myDocument.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="p-2">
  3. <el-row :gutter="20">
  4. <!-- 流程分类树 -->
  5. <el-col :lg="4" :xs="24" style="">
  6. <el-card shadow="hover">
  7. <el-input v-model="categoryName" placeholder="请输入流程分类名" prefix-icon="Search" clearable />
  8. <el-tree
  9. ref="categoryTreeRef"
  10. class="mt-2"
  11. node-key="id"
  12. :data="categoryOptions"
  13. :props="{ label: 'categoryName', children: 'children' }"
  14. :expand-on-click-node="false"
  15. :filter-node-method="filterNode"
  16. highlight-current
  17. default-expand-all
  18. @node-click="handleNodeClick"
  19. ></el-tree>
  20. </el-card>
  21. </el-col>
  22. <el-col :lg="20" :xs="24">
  23. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  24. <div v-show="showSearch" class="mb-[10px]">
  25. <el-card shadow="hover">
  26. <el-form v-show="showSearch" ref="queryFormRef" :model="queryParams" :inline="true" label-width="120px">
  27. <el-form-item label="流程定义名称" prop="name">
  28. <el-input v-model="queryParams.name" placeholder="请输入流程定义名称" @keyup.enter="handleQuery" />
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  32. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </el-card>
  36. </div>
  37. </transition>
  38. <el-card shadow="hover">
  39. <template #header>
  40. <el-row :gutter="10" class="mb8">
  41. <right-toolbar v-model:showSearch="showSearch" @query-table="handleQuery"></right-toolbar>
  42. </el-row>
  43. </template>
  44. <el-table v-loading="loading" :data="processInstanceList" @selection-change="handleSelectionChange">
  45. <el-table-column type="selection" width="55" align="center" />
  46. <el-table-column fixed align="center" type="index" label="序号" width="50"></el-table-column>
  47. <el-table-column v-if="false" fixed align="center" prop="id" label="id"></el-table-column>
  48. <el-table-column fixed align="center" prop="processDefinitionName" label="流程定义名称"></el-table-column>
  49. <el-table-column fixed align="center" prop="processDefinitionKey" label="流程定义KEY"></el-table-column>
  50. <el-table-column align="center" prop="processDefinitionVersion" label="版本号" width="90">
  51. <template #default="scope"> v{{ scope.row.processDefinitionVersion }}.0</template>
  52. </el-table-column>
  53. <el-table-column v-if="tab === 'running'" align="center" prop="isSuspended" label="状态" min-width="70">
  54. <template #default="scope">
  55. <el-tag v-if="!scope.row.isSuspended" type="success">激活</el-tag>
  56. <el-tag v-else type="danger">挂起</el-tag>
  57. </template>
  58. </el-table-column>
  59. <el-table-column align="center" prop="businessStatusName" label="流程状态" min-width="70">
  60. <template #default="scope">
  61. <el-tag type="success">{{ scope.row.businessStatusName }}</el-tag>
  62. </template>
  63. </el-table-column>
  64. <el-table-column align="center" prop="startTime" label="启动时间" width="160"></el-table-column>
  65. <el-table-column v-if="tab === 'finish'" align="center" prop="endTime" label="结束时间" width="160"></el-table-column>
  66. <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
  67. <template #default="scope">
  68. <el-row :gutter="10" class="mb8">
  69. <el-col :span="1.5">
  70. <el-button link type="primary" size="small" icon="Document" @click="handleApprovalRecord(scope.row.id)">审批记录</el-button>
  71. </el-col>
  72. <el-col
  73. v-if="scope.row.businessStatus === 'draft' || scope.row.businessStatus === 'cancel' || scope.row.businessStatus === 'back'"
  74. :span="1.5"
  75. >
  76. <el-button link type="primary" size="small" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  77. </el-col>
  78. <el-col v-if="scope.row.businessStatus === 'waiting'" :span="1.5">
  79. <el-button link type="primary" size="small" icon="Notification" @click="handleCancelProcessApply(scope.row.id)">撤销</el-button>
  80. </el-col>
  81. <el-col
  82. v-if="scope.row.businessStatus === 'draft' || scope.row.businessStatus === 'cancel' || scope.row.businessStatus === 'back'"
  83. :span="1.5"
  84. >
  85. <el-button link type="primary" size="small" icon="Edit" @click="submitVerifyOpen(scope.row.taskVoList[0].id)">提交</el-button>
  86. </el-col>
  87. </el-row>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <pagination
  92. v-show="total > 0"
  93. v-model:page="queryParams.pageNum"
  94. v-model:limit="queryParams.pageSize"
  95. :total="total"
  96. @pagination="getList"
  97. />
  98. </el-card>
  99. </el-col>
  100. </el-row>
  101. <!-- 审批记录 -->
  102. <approvalRecord ref="approvalRecordRef" />
  103. <!-- 提交组件 -->
  104. <submitVerify ref="submitVerifyRef" @submit-callback="getList" />
  105. </div>
  106. </template>
  107. <script lang="ts" setup>
  108. import { getPageByCurrent, deleteRunAndHisInstance, cancelProcessApply } from '@/api/workflow/processInstance';
  109. import ApprovalRecord from '@/components/Process/approvalRecord.vue';
  110. import SubmitVerify from '@/components/Process/submitVerify.vue';
  111. import { listCategory } from '@/api/workflow/category';
  112. import { CategoryVO } from '@/api/workflow/category/types';
  113. import { ProcessInstanceQuery, ProcessInstanceVO } from '@/api/workflow/processInstance/types';
  114. //提交组件
  115. const submitVerifyRef = ref<InstanceType<typeof SubmitVerify>>();
  116. //审批记录组件
  117. const approvalRecordRef = ref<InstanceType<typeof ApprovalRecord>>();
  118. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  119. const queryFormRef = ref<ElFormInstance>();
  120. const categoryTreeRef = ref<ElTreeInstance>();
  121. // 遮罩层
  122. const loading = ref(true);
  123. // 选中数组
  124. const ids = ref<Array<any>>([]);
  125. // 非单个禁用
  126. const single = ref(true);
  127. // 非多个禁用
  128. const multiple = ref(true);
  129. // 显示搜索条件
  130. const showSearch = ref(true);
  131. // 总条数
  132. const total = ref(0);
  133. // 模型定义表格数据
  134. const processInstanceList = ref<ProcessInstanceVO[]>([]);
  135. const categoryOptions = ref<CategoryOption[]>([]);
  136. const categoryName = ref('');
  137. interface CategoryOption {
  138. categoryCode: string;
  139. categoryName: string;
  140. children?: CategoryOption[];
  141. }
  142. const tab = ref('running');
  143. // 查询参数
  144. const queryParams = ref<ProcessInstanceQuery>({
  145. pageNum: 1,
  146. pageSize: 10,
  147. name: undefined,
  148. categoryCode: undefined
  149. });
  150. onMounted(() => {
  151. getList();
  152. getTreeselect();
  153. });
  154. /** 节点单击事件 */
  155. const handleNodeClick = (data: CategoryVO) => {
  156. queryParams.value.categoryCode = data.categoryCode;
  157. if (data.categoryCode === 'ALL') {
  158. queryParams.value.categoryCode = '';
  159. }
  160. handleQuery();
  161. };
  162. /** 通过条件过滤节点 */
  163. const filterNode = (value: string, data: any) => {
  164. if (!value) return true;
  165. return data.categoryName.indexOf(value) !== -1;
  166. };
  167. /** 根据名称筛选部门树 */
  168. watchEffect(
  169. () => {
  170. categoryTreeRef.value.filter(categoryName.value);
  171. },
  172. {
  173. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  174. }
  175. );
  176. /** 查询流程分类下拉树结构 */
  177. const getTreeselect = async () => {
  178. const res = await listCategory();
  179. categoryOptions.value = [];
  180. const data: CategoryOption = { categoryCode: 'ALL', categoryName: '顶级节点', children: [] };
  181. data.children = proxy?.handleTree<CategoryOption>(res.data, 'id', 'parentId');
  182. categoryOptions.value.push(data);
  183. };
  184. //审批记录
  185. const handleApprovalRecord = (processInstanceId: string) => {
  186. if (approvalRecordRef.value) {
  187. approvalRecordRef.value.init(processInstanceId);
  188. }
  189. };
  190. /** 搜索按钮操作 */
  191. const handleQuery = () => {
  192. getList();
  193. };
  194. /** 重置按钮操作 */
  195. const resetQuery = () => {
  196. queryFormRef.value?.resetFields();
  197. queryParams.value.categoryCode = '';
  198. queryParams.value.pageNum = 1;
  199. queryParams.value.pageSize = 10;
  200. handleQuery();
  201. };
  202. // 多选框选中数据
  203. const handleSelectionChange = (selection: ProcessInstanceVO[]) => {
  204. ids.value = selection.map((item: any) => item.id);
  205. single.value = selection.length !== 1;
  206. multiple.value = !selection.length;
  207. };
  208. //分页
  209. const getList = () => {
  210. loading.value = true;
  211. getPageByCurrent(queryParams.value).then((resp) => {
  212. processInstanceList.value = resp.rows;
  213. total.value = resp.total;
  214. loading.value = false;
  215. });
  216. };
  217. /** 删除按钮操作 */
  218. const handleDelete = async (row: ProcessInstanceVO) => {
  219. const id = row.id || ids.value;
  220. await proxy?.$modal.confirm('是否确认删除id为【' + id + '】的数据项?');
  221. loading.value = true;
  222. if ('running' === tab.value) {
  223. await deleteRunAndHisInstance(id).finally(() => (loading.value = false));
  224. getList();
  225. }
  226. proxy?.$modal.msgSuccess('删除成功');
  227. };
  228. /** 撤销按钮操作 */
  229. const handleCancelProcessApply = async (processInstanceId: string) => {
  230. await proxy?.$modal.confirm('是否确认撤销当前单据?');
  231. loading.value = true;
  232. if ('running' === tab.value) {
  233. await cancelProcessApply(processInstanceId).finally(() => (loading.value = false));
  234. getList();
  235. }
  236. proxy?.$modal.msgSuccess('撤销成功');
  237. };
  238. //提交
  239. const submitVerifyOpen = async (id: string) => {
  240. if (submitVerifyRef.value) {
  241. submitVerifyRef.value.openDialog(id);
  242. }
  243. };
  244. </script>