index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <template>
  2. <div class="p-2">
  3. <el-row>
  4. <!-- 流程分类树 -->
  5. <el-col :lg="4" :xs="24">
  6. <el-card shadow="hover" style="height: calc(100vh - 63px);">
  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" :style="{ marginTop: '10px', height: '60px' }">
  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="请输入流程定义名称" clearable @keyup.enter="handleQuery"/>
  29. </el-form-item>
  30. <el-form-item label="流程定义KEY" prop="key">
  31. <el-input v-model="queryParams.key" placeholder="请输入流程定义KEY" clearable @keyup.enter="handleQuery"/>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  35. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  36. <el-button type="primary" icon="UploadFilled" @click="uploadDialog.visible = true">部署流程文件</el-button>
  37. </el-form-item>
  38. </el-form>
  39. </el-card>
  40. </div>
  41. </transition>
  42. <el-card shadow="hover" style="border: none">
  43. <div class="table-content" style="height: calc(100vh - 225px)">
  44. <el-table v-loading="loading" :data="processDefinitionList" @selection-change="handleSelectionChange">
  45. <el-table-column align="center" type="index" label="序号" width="60"></el-table-column>
  46. <el-table-column align="left" prop="name" label="流程定义名称"
  47. :show-overflow-tooltip="true"></el-table-column>
  48. <el-table-column align="left" prop="key" label="标识KEY" width="140"></el-table-column>
  49. <el-table-column align="left" prop="version" label="版本号" width="80">
  50. <template #default="scope"> v{{ scope.row.version }}.0</template>
  51. </el-table-column>
  52. <el-table-column align="left" prop="resourceName" label="流程XML" width="140"
  53. :show-overflow-tooltip="true">
  54. <template #default="scope">
  55. <el-link type="primary" @click="clickPreview(scope.row.id, 'xml')">{{
  56. scope.row.resourceName
  57. }}
  58. </el-link>
  59. </template>
  60. </el-table-column>
  61. <el-table-column align="left" prop="diagramResourceName" label="流程图片" width="140" :show-overflow-tooltip="true">
  62. <template #default="scope">
  63. <el-link type="primary" @click="clickPreview(scope.row.id, 'bpmn')">{{ scope.row.diagramResourceName }}</el-link>
  64. </template>
  65. </el-table-column>
  66. <el-table-column align="center" prop="suspensionState" label="状态" width="80">
  67. <template #default="scope">
  68. <el-tag v-if="scope.row.suspensionState == 1" type="success">激活</el-tag>
  69. <el-tag v-else type="danger">挂起</el-tag>
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="left" prop="deploymentTime" label="部署时间" width="160" :show-overflow-tooltip="true"></el-table-column>
  73. <el-table-column align="left" label="表名/表单KEY" width="135" :show-overflow-tooltip="true">
  74. <template #default="scope">
  75. <span v-if="scope.row.wfDefinitionConfigVo">
  76. {{ scope.row.wfDefinitionConfigVo.tableName }}
  77. </span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column fixed="right" label="操作" align="center" width="220" class-name="small-padding fixed-width">
  81. <template #default="scope">
  82. <el-row :gutter="10" class="mb8">
  83. <el-col :span="1.5">
  84. <el-button
  85. link
  86. type="primary"
  87. size="small"
  88. :icon="scope.row.suspensionState === 1 ? 'Lock' : 'Unlock'"
  89. @click="handleProcessDefState(scope.row)"
  90. >
  91. {{ scope.row.suspensionState === 1 ? '挂起流程' : '激活流程' }}
  92. </el-button>
  93. </el-col>
  94. <el-col :span="1.5">
  95. <el-button link type="primary" size="small" icon="Document" @click="getProcessDefinitionHitoryList(scope.row.id, scope.row.key)">
  96. 历史版本
  97. </el-button>
  98. </el-col>
  99. <el-col :span="1.5">
  100. <el-button link type="primary" size="small" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  101. </el-col>
  102. </el-row>
  103. <el-row :gutter="10" class="mb8">
  104. <el-col :span="1.5">
  105. <el-button link type="primary" size="small" icon="Sort" @click="handleConvertToModel(scope.row)">
  106. 转换模型
  107. </el-button>
  108. </el-col>
  109. <el-col :span="1.5">
  110. <el-button link type="primary" size="small" icon="Tickets"
  111. @click="handleDefinitionConfigOpen(scope.row)">绑定业务
  112. </el-button>
  113. </el-col>
  114. </el-row>
  115. </template>
  116. </el-table-column>
  117. </el-table>
  118. </div>
  119. <pagination
  120. v-show="total > 0"
  121. v-model:page="queryParams.pageNum"
  122. v-model:limit="queryParams.pageSize"
  123. :total="total"
  124. @pagination="getList"
  125. />
  126. </el-card>
  127. </el-col>
  128. </el-row>
  129. <!-- 预览图片或xml -->
  130. <process-preview ref="previewRef" />
  131. <!-- 部署文件 -->
  132. <el-dialog v-if="uploadDialog.visible" v-model="uploadDialog.visible" :title="uploadDialog.title" width="40%">
  133. <div v-loading="uploadDialogLoading">
  134. <div class="mb5">
  135. <el-text class="mx-1" size="large"><span class="text-danger">*</span>请选择部署流程分类:</el-text>
  136. <el-tree-select
  137. v-model="selectCategory"
  138. :data="categoryOptions"
  139. :props="{ value: 'categoryCode', label: 'categoryName', children: 'children' }"
  140. filterable
  141. value-key="categoryCode"
  142. :render-after-expand="false"
  143. check-strictly
  144. style="width: 240px"
  145. :default-expand-all="true"
  146. />
  147. </div>
  148. <el-upload
  149. class="upload-demo"
  150. drag
  151. multiple
  152. accept="application/zip,application/xml,.bpmn"
  153. :before-upload="handlerBeforeUpload"
  154. :http-request="handerDeployProcessFile"
  155. >
  156. <el-icon class="UploadFilled"><upload-filled /></el-icon>
  157. <div class="el-upload__text"><em>点击上传,选择BPMN流程文件</em></div>
  158. <div class="el-upload__text">仅支持 .zip、.bpmn20.xml、bpmn 格式文件</div>
  159. <div class="el-upload__text">PS:如若部署请部署从本项目模型管理导出的数据</div>
  160. </el-upload>
  161. </div>
  162. </el-dialog>
  163. <!-- 历史版本 -->
  164. <el-dialog v-if="processDefinitionDialog.visible" v-model="processDefinitionDialog.visible" :title="processDefinitionDialog.title" width="70%">
  165. <el-table border v-loading="loading" :data="processDefinitionHistoryList" @selection-change="handleSelectionChange">
  166. <!--
  167. <el-table-column type="selection" width="55" align="center" />
  168. -->
  169. <el-table-column align="center" type="index" label="序号" width="60"></el-table-column>
  170. <el-table-column align="left" prop="name" label="流程定义名称" :show-overflow-tooltip="true" min-width="80"></el-table-column>
  171. <el-table-column align="left" prop="key" label="标识KEY"></el-table-column>
  172. <el-table-column align="left" prop="version" label="版本号" width="80">
  173. <template #default="scope"> v{{ scope.row.version }}.0</template>
  174. </el-table-column>
  175. <el-table-column align="left" prop="resourceName" label="流程XML" min-width="80" :show-overflow-tooltip="true">
  176. <template #default="scope">
  177. <el-link type="primary" @click="clickPreviewXML(scope.row.id)">{{ scope.row.resourceName }}</el-link>
  178. </template>
  179. </el-table-column>
  180. <el-table-column align="left" prop="diagramResourceName" label="流程图片" min-width="80" :show-overflow-tooltip="true">
  181. <template #default="scope">
  182. <el-link type="primary" @click="clickPreviewImg(scope.row.id)">{{ scope.row.diagramResourceName }}</el-link>
  183. </template>
  184. </el-table-column>
  185. <el-table-column align="center" prop="suspensionState" label="状态" min-width="60">
  186. <template #default="scope">
  187. <el-tag v-if="scope.row.suspensionState == 1" type="success">激活</el-tag>
  188. <el-tag v-else type="danger">挂起</el-tag>
  189. </template>
  190. </el-table-column>
  191. <el-table-column align="left" prop="deploymentTime" label="部署时间" width="160" :show-overflow-tooltip="true"></el-table-column>
  192. <el-table-column fixed="right" label="操作" align="center" width="180" class-name="small-padding fixed-width">
  193. <template #default="scope">
  194. <el-row :gutter="10" class="mb8">
  195. <el-col :span="1.5">
  196. <el-button
  197. link
  198. type="primary"
  199. size="small"
  200. :icon="scope.row.suspensionState === 1 ? 'Lock' : 'Unlock'"
  201. @click="handleProcessDefState(scope.row)"
  202. >
  203. {{ scope.row.suspensionState === 1 ? '挂起流程' : '激活流程' }}
  204. </el-button>
  205. </el-col>
  206. <el-col :span="1.5">
  207. <el-button type="text" size="small" icon="Tickets" @click="handleDefinitionConfigOpen(scope.row)">绑定业务</el-button>
  208. </el-col>
  209. </el-row>
  210. <el-row :gutter="10" class="mb8">
  211. <el-col :span="1.5">
  212. <el-button link type="primary" icon="Sort" size="small" @click="handleConvertToModel(scope.row)"> 转换模型 </el-button>
  213. </el-col>
  214. <el-col :span="1.5">
  215. <el-button link type="primary" icon="Delete" size="small" @click="handleDelete(scope.row)">删除</el-button>
  216. </el-col>
  217. </el-row>
  218. </template>
  219. </el-table-column>
  220. </el-table>
  221. </el-dialog>
  222. <!-- 表单配置 -->
  223. <el-dialog
  224. v-model="definitionConfigDialog.visible"
  225. :title="definitionConfigDialog.title"
  226. width="650px"
  227. append-to-body
  228. :close-on-click-modal="false"
  229. >
  230. <el-form :model="definitionConfigForm" label-width="40">
  231. <el-form-item label="KEY">
  232. <el-input v-model="definitionConfigForm.processKey" disabled />
  233. </el-form-item>
  234. <el-form-item label="表名" prop="formId">
  235. <el-input v-model="definitionConfigForm.tableName" placeholder="示例:test_leave" />
  236. </el-form-item>
  237. <el-form-item label="备注">
  238. <el-input v-model="definitionConfigForm.remark" :rows="3" type="textarea" resize="none" />
  239. </el-form-item>
  240. </el-form>
  241. <template #footer>
  242. <div class="dialog-footer">
  243. <el-button @click="definitionConfigDialog.visible = false">取消</el-button>
  244. <el-button type="primary" @click="handlerSaveForm">保存</el-button>
  245. </div>
  246. </template>
  247. </el-dialog>
  248. </div>
  249. </template>
  250. <script lang="ts" setup name="processDefinition">
  251. import {
  252. convertToModel,
  253. definitionXml,
  254. deleteProcessDefinition,
  255. deployProcessFile,
  256. getListByKey,
  257. listProcessDefinition,
  258. updateDefinitionState
  259. } from '@/api/workflow/processDefinition';
  260. import {getByDefId, getByTableNameNotDefId, saveOrUpdate} from '@/api/workflow/definitionConfig';
  261. import ProcessPreview from './components/processPreview.vue';
  262. import {listCategory} from '@/api/workflow/category';
  263. import {CategoryVO} from '@/api/workflow/category/types';
  264. import {ProcessDefinitionQuery, ProcessDefinitionVO} from '@/api/workflow/processDefinition/types';
  265. import {DefinitionConfigForm} from '@/api/workflow/definitionConfig/types';
  266. import {ElMessageBox, UploadRequestOptions} from 'element-plus';
  267. const {proxy} = getCurrentInstance() as ComponentInternalInstance;
  268. const previewRef = ref<InstanceType<typeof ProcessPreview>>();
  269. const queryFormRef = ref<ElFormInstance>();
  270. const categoryTreeRef = ref<ElTreeInstance>();
  271. const definitionConfigForm = ref<DefinitionConfigForm>({});
  272. type CategoryOption = {
  273. categoryCode: string;
  274. categoryName: string;
  275. children?: CategoryOption[];
  276. };
  277. const loading = ref(true);
  278. const ids = ref<Array<any>>([]);
  279. const deploymentIds = ref<Array<any>>([]);
  280. const keys = ref<Array<any>>([]);
  281. const single = ref(true);
  282. const multiple = ref(true);
  283. const showSearch = ref(true);
  284. const total = ref(0);
  285. const uploadDialogLoading = ref(false);
  286. const processDefinitionList = ref<ProcessDefinitionVO[]>([]);
  287. const processDefinitionHistoryList = ref<ProcessDefinitionVO[]>([]);
  288. const categoryOptions = ref<CategoryOption[]>([]);
  289. const categoryName = ref('');
  290. /** 部署文件分类选择 */
  291. const selectCategory = ref();
  292. const uploadDialog = reactive<DialogOption>({
  293. visible: false,
  294. title: '部署流程文件'
  295. });
  296. const processDefinitionDialog = reactive<DialogOption>({
  297. visible: false,
  298. title: '历史版本'
  299. });
  300. const definitionConfigDialog = reactive<DialogOption>({
  301. visible: false,
  302. title: '流程定义配置'
  303. });
  304. // 查询参数
  305. const queryParams = ref<ProcessDefinitionQuery>({
  306. pageNum: 1,
  307. pageSize: 10,
  308. name: undefined,
  309. key: undefined,
  310. categoryCode: undefined
  311. });
  312. onMounted(() => {
  313. getList();
  314. getTreeselect();
  315. });
  316. /** 节点单击事件 */
  317. const handleNodeClick = (data: CategoryVO) => {
  318. queryParams.value.categoryCode = data.categoryCode;
  319. if (data.categoryCode === 'ALL') {
  320. queryParams.value.categoryCode = '';
  321. }
  322. handleQuery();
  323. };
  324. /** 通过条件过滤节点 */
  325. const filterNode = (value: string, data: any) => {
  326. if (!value) return true;
  327. return data.categoryName.indexOf(value) !== -1;
  328. };
  329. /** 根据名称筛选部门树 */
  330. watchEffect(
  331. () => {
  332. categoryTreeRef.value.filter(categoryName.value);
  333. },
  334. {
  335. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  336. }
  337. );
  338. /** 查询流程分类下拉树结构 */
  339. const getTreeselect = async () => {
  340. const res = await listCategory();
  341. categoryOptions.value = [];
  342. const data: CategoryOption = { categoryCode: 'ALL', categoryName: '顶级节点', children: [] };
  343. data.children = proxy?.handleTree<CategoryOption>(res.data, 'id', 'parentId');
  344. categoryOptions.value.push(data);
  345. };
  346. /** 搜索按钮操作 */
  347. const handleQuery = () => {
  348. queryParams.value.pageNum = 1;
  349. getList();
  350. };
  351. /** 重置按钮操作 */
  352. const resetQuery = () => {
  353. queryFormRef.value?.resetFields();
  354. queryParams.value.categoryCode = '';
  355. queryParams.value.pageNum = 1;
  356. queryParams.value.pageSize = 10;
  357. handleQuery();
  358. };
  359. // 多选框选中数据
  360. const handleSelectionChange = (selection: any) => {
  361. ids.value = selection.map((item: any) => item.id);
  362. deploymentIds.value = selection.map((item: any) => item.deploymentId);
  363. keys.value = selection.map((item: any) => item.key);
  364. single.value = selection.length !== 1;
  365. multiple.value = !selection.length;
  366. };
  367. //分页
  368. const getList = async () => {
  369. loading.value = true;
  370. const resp = await listProcessDefinition(queryParams.value);
  371. processDefinitionList.value = resp.rows;
  372. total.value = resp.total;
  373. loading.value = false;
  374. };
  375. //获取历史流程定义
  376. const getProcessDefinitionHitoryList = async (id: string, key: string) => {
  377. processDefinitionDialog.visible = true;
  378. loading.value = true;
  379. const resp = await getListByKey(key);
  380. if (resp.data && resp.data.length > 0) {
  381. processDefinitionHistoryList.value = resp.data.filter((item: any) => item.id !== id);
  382. }
  383. loading.value = false;
  384. };
  385. type PreviewType = 'xml' | 'bpmn';
  386. //预览 公共方法
  387. const clickPreview = async (id: string, type: PreviewType) => {
  388. loading.value = true;
  389. const resp = await definitionXml(id);
  390. if (previewRef.value) {
  391. const xmlStr = resp.data.xmlStr;
  392. loading.value = false;
  393. previewRef.value.openDialog(xmlStr, type);
  394. }
  395. };
  396. /** 删除按钮操作 */
  397. const handleDelete = async (row?: ProcessDefinitionVO) => {
  398. const id = row?.id || ids.value;
  399. const deployIds = row?.deploymentId || deploymentIds.value;
  400. const defKeys = row?.key || keys.value;
  401. await proxy?.$modal.confirm('是否确认删除已选择的数据项?');
  402. loading.value = true;
  403. await deleteProcessDefinition(deployIds, id).finally(() => (loading.value = false));
  404. await getList();
  405. proxy?.$modal.msgSuccess('删除成功');
  406. };
  407. /** 挂起/激活 */
  408. const handleProcessDefState = async (row: ProcessDefinitionVO) => {
  409. let msg: string;
  410. if (row.suspensionState === 1) {
  411. msg = `暂停后,此流程下的所有任务都不允许往后流转,您确定挂起【${row.name || row.key}】吗?`;
  412. } else {
  413. msg = `启动后,此流程下的所有任务都允许往后流转,您确定激活【${row.name || row.key}】吗?`;
  414. }
  415. await proxy?.$modal.confirm(msg);
  416. loading.value = true;
  417. await updateDefinitionState(row.id).finally(() => (loading.value = false));
  418. await getList();
  419. proxy?.$modal.msgSuccess('操作成功');
  420. };
  421. /** 流程定义转换为模型 */
  422. const handleConvertToModel = async (row: ProcessDefinitionVO) => {
  423. await proxy?.$modal.confirm('是否确认转换流程定义key为【' + row.key + '】的数据项?');
  424. await convertToModel(row.id).finally(() => (loading.value = false));
  425. getList();
  426. proxy?.$modal.msgSuccess('操作成功');
  427. };
  428. //上传文件前的钩子
  429. const handlerBeforeUpload = () => {
  430. if (selectCategory.value === 'ALL') {
  431. proxy?.$modal.msgError('顶级节点不可作为分类!');
  432. return false;
  433. }
  434. if (!selectCategory.value) {
  435. proxy?.$modal.msgError('请选择左侧要上传的分类!');
  436. return false;
  437. }
  438. };
  439. //部署文件
  440. const handerDeployProcessFile = (data: UploadRequestOptions): XMLHttpRequest => {
  441. let formData = new FormData();
  442. uploadDialogLoading.value = true;
  443. formData.append('file', data.file);
  444. formData.append('categoryCode', selectCategory.value);
  445. deployProcessFile(formData)
  446. .then(() => {
  447. uploadDialog.visible = false;
  448. proxy?.$modal.msgSuccess('部署成功');
  449. handleQuery();
  450. })
  451. .finally(() => {
  452. uploadDialogLoading.value = false;
  453. });
  454. return;
  455. };
  456. //打开流程定义配置
  457. const handleDefinitionConfigOpen = async (row: ProcessDefinitionVO) => {
  458. definitionConfigDialog.visible = true;
  459. definitionConfigForm.value.processKey = row.key;
  460. definitionConfigForm.value.definitionId = row.id;
  461. definitionConfigForm.value.version = row.version;
  462. const resp = await getByDefId(row.id);
  463. if (resp.data) {
  464. definitionConfigForm.value = resp.data;
  465. } else {
  466. definitionConfigForm.value.tableName = undefined;
  467. definitionConfigForm.value.remark = undefined;
  468. }
  469. };
  470. //保存表单
  471. const handlerSaveForm = async () => {
  472. getByTableNameNotDefId(definitionConfigForm.value.tableName, definitionConfigForm.value.definitionId).then((res) => {
  473. if (res.data && res.data.length > 0) {
  474. ElMessageBox.confirm('表名已被【' + res.data[0].processKey + '】版本v' + res.data[0].version + '.0绑定确认后将会删除绑定的流程KEY!', '提示', {
  475. confirmButtonText: '确认',
  476. cancelButtonText: '取消',
  477. type: 'warning'
  478. }).then(() => {
  479. saveOrUpdate(definitionConfigForm.value).then((resp) => {
  480. if (resp.code === 200) {
  481. proxy?.$modal.msgSuccess('操作成功');
  482. definitionConfigDialog.visible = false;
  483. getList();
  484. }
  485. });
  486. });
  487. } else {
  488. saveOrUpdate(definitionConfigForm.value).then((resp) => {
  489. if (resp.code === 200) {
  490. proxy?.$modal.msgSuccess('操作成功');
  491. definitionConfigDialog.visible = false;
  492. getList();
  493. }
  494. });
  495. }
  496. });
  497. };
  498. </script>