index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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="80px">
  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-form-item>
  37. </el-form>
  38. </el-card>
  39. </div>
  40. </transition>
  41. <el-card shadow="hover">
  42. <template #header>
  43. <el-row :gutter="10" class="mb8">
  44. <el-col :span="1.5">
  45. <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()">修改</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()">删除</el-button>
  52. </el-col>
  53. <el-col :span="1.5">
  54. <el-button type="primary" plain :disabled="multiple" icon="Download" @click="clickExportZip()">导出</el-button>
  55. </el-col>
  56. <right-toolbar v-model:showSearch="showSearch" @query-table="getList"></right-toolbar>
  57. </el-row>
  58. </template>
  59. <el-table v-loading="loading" :data="modelList" @selection-change="handleSelectionChange">
  60. <el-table-column type="selection" width="55" align="center" />
  61. <el-table-column fixed align="center" type="index" label="序号" width="50"></el-table-column>
  62. <el-table-column fixed align="center" prop="name" label="模型名称"></el-table-column>
  63. <el-table-column align="center" prop="key" label="模型KEY"></el-table-column>
  64. <el-table-column align="center" prop="version" label="版本号" width="90">
  65. <template #default="scope"> v{{ scope.row.version }}.0</template>
  66. </el-table-column>
  67. <el-table-column align="center" prop="metaInfo" label="备注说明" min-width="130"></el-table-column>
  68. <el-table-column align="center" prop="createTime" label="创建时间" width="160"></el-table-column>
  69. <el-table-column align="center" prop="lastUpdateTime" label="更新时间" width="160"></el-table-column>
  70. <el-table-column fixed="right" label="操作" align="center" width="180" class-name="small-padding fixed-width">
  71. <template #default="scope">
  72. <el-row :gutter="10" class="mb8">
  73. <el-col :span="1.5">
  74. <el-button link type="primary" size="small" icon="Pointer" @click="clickDesign(scope.row.id)">设计流程</el-button>
  75. </el-col>
  76. <el-col :span="1.5">
  77. <el-button link type="primary" size="small" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  78. </el-col>
  79. </el-row>
  80. <el-row :gutter="10" class="mb8">
  81. <el-col :span="1.5">
  82. <el-button link type="primary" size="small" icon="ScaleToOriginal" @click="clickDeploy(scope.row.id, scope.row.key)">
  83. 流程部署
  84. </el-button>
  85. </el-col>
  86. </el-row>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <pagination
  91. v-show="total > 0"
  92. v-model:page="queryParams.pageNum"
  93. v-model:limit="queryParams.pageSize"
  94. :total="total"
  95. @pagination="getList"
  96. />
  97. </el-card>
  98. </el-col>
  99. </el-row>
  100. <!-- 设计流程开始 -->
  101. <Design ref="designRef" @close-call-back="handleQuery"></Design>
  102. <!-- 设计流程结束 -->
  103. <!-- 添加模型对话框 -->
  104. <el-dialog v-model="dialog.visible" :title="dialog.title" width="650px" append-to-body :close-on-click-modal="false">
  105. <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
  106. <el-form-item label="模型名称:" prop="name">
  107. <el-input v-model="form.name" :disabled="ids && ids.length > 0" maxlength="20" show-word-limit />
  108. </el-form-item>
  109. <el-form-item label="模型KEY:" prop="key">
  110. <el-input v-model="form.key" :disabled="ids && ids.length > 0" maxlength="20" show-word-limit />
  111. </el-form-item>
  112. <el-form-item label="流程分类" prop="categoryCode">
  113. <el-tree-select
  114. v-model="form.categoryCode"
  115. :data="categoryOptions"
  116. :props="{ value: 'categoryCode', label: 'categoryName', children: 'children' }"
  117. value-key="categoryCode"
  118. placeholder="请选择流程分类"
  119. check-strictly
  120. />
  121. </el-form-item>
  122. <el-form-item label="备注:" prop="description">
  123. <el-input v-model="form.description" type="textarea" maxlength="200" show-word-limit></el-input>
  124. </el-form-item>
  125. </el-form>
  126. <template #footer>
  127. <span class="dialog-footer">
  128. <el-button type="primary" @click="submitForm">确 定</el-button>
  129. <el-button @click="cancel">取 消</el-button>
  130. </span>
  131. </template>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script lang="ts" setup name="Model">
  136. import Design from './design.vue';
  137. import { listModel, addModel, delModel, modelDeploy, getInfo, update } from '@/api/workflow/model';
  138. import { ModelQuery, ModelForm, ModelVO } from '@/api/workflow/model/types';
  139. import { listCategory } from '@/api/workflow/category';
  140. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  141. const formRef = ref<ElFormInstance>();
  142. const queryFormRef = ref<ElFormInstance>();
  143. const categoryTreeRef = ref<ElTreeInstance>();
  144. const designRef = ref<InstanceType<typeof Design>>();
  145. type CategoryOption = {
  146. categoryCode: string;
  147. categoryName: string;
  148. children?: CategoryOption[];
  149. };
  150. const buttonLoading = ref(false);
  151. const loading = ref(true);
  152. const ids = ref<string[]>([]);
  153. const single = ref(true);
  154. const multiple = ref(true);
  155. const showSearch = ref(true);
  156. const total = ref(0);
  157. const modelList = ref<ModelVO[]>([]);
  158. const categoryOptions = ref<CategoryOption[]>([]);
  159. const categoryName = ref('');
  160. const modelId = ref<string>('');
  161. const dialog = reactive<DialogOption>({
  162. visible: false,
  163. title: ''
  164. });
  165. const initFormData: ModelForm = {
  166. id: '',
  167. name: '',
  168. key: '',
  169. categoryCode: '',
  170. xml: '',
  171. svg: '',
  172. description: ''
  173. };
  174. const data = reactive<PageData<ModelForm, ModelQuery>>({
  175. form: { ...initFormData },
  176. queryParams: {
  177. pageNum: 1,
  178. pageSize: 10,
  179. name: '',
  180. key: '',
  181. categoryCode: ''
  182. },
  183. rules: {
  184. name: [{ required: true, message: '模型不能为空', trigger: 'blur' }],
  185. key: [{ required: true, message: '模型KEY不能为空', trigger: 'blur' }],
  186. categoryCode: [{ required: true, message: '流程分类不能为空', trigger: 'blur' }]
  187. }
  188. });
  189. const { queryParams, form, rules } = toRefs(data);
  190. onMounted(() => {
  191. getList();
  192. getTreeselect();
  193. });
  194. /** 节点单击事件 */
  195. const handleNodeClick = (data: ModelForm) => {
  196. queryParams.value.categoryCode = data.categoryCode;
  197. if (data.categoryCode === 'ALL') {
  198. queryParams.value.categoryCode = '';
  199. }
  200. handleQuery();
  201. };
  202. /** 通过条件过滤节点 */
  203. const filterNode = (value: string, data: any) => {
  204. if (!value) return true;
  205. return data.categoryName.indexOf(value) !== -1;
  206. };
  207. /** 根据名称筛选部门树 */
  208. watchEffect(
  209. () => {
  210. categoryTreeRef.value?.filter(categoryName.value);
  211. },
  212. {
  213. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  214. }
  215. );
  216. /** 搜索按钮操作 */
  217. const handleQuery = () => {
  218. queryParams.value.pageNum = 1;
  219. getList();
  220. };
  221. /** 重置按钮操作 */
  222. const resetQuery = () => {
  223. queryFormRef.value?.resetFields();
  224. queryParams.value.categoryCode = '';
  225. queryParams.value.pageNum = 1;
  226. queryParams.value.pageSize = 10;
  227. handleQuery();
  228. };
  229. // 多选框选中数据
  230. const handleSelectionChange = (selection: ModelVO[]) => {
  231. ids.value = selection.map((item: ModelVO) => item.id);
  232. single.value = selection.length !== 1;
  233. multiple.value = !selection.length;
  234. };
  235. //分页
  236. const getList = async () => {
  237. loading.value = true;
  238. const resp = await listModel(queryParams.value);
  239. modelList.value = resp.rows;
  240. total.value = resp.total;
  241. loading.value = false;
  242. };
  243. /** 删除按钮操作 */
  244. const handleDelete = async (row?: ModelVO) => {
  245. const id = row?.id || ids.value;
  246. await proxy?.$modal.confirm('是否确认删除模型id为【' + id + '】的数据项?');
  247. loading.value = true;
  248. await delModel(id).finally(() => (loading.value = false));
  249. await getList();
  250. proxy?.$modal.msgSuccess('删除成功');
  251. };
  252. // 流程部署
  253. const clickDeploy = async (id: string, key: string) => {
  254. await proxy?.$modal.confirm('是否部署模型key为【' + key + '】流程?');
  255. loading.value = true;
  256. await modelDeploy(id).finally(() => (loading.value = false));
  257. await getList();
  258. proxy?.$modal.msgSuccess('部署成功');
  259. };
  260. const handleAdd = () => {
  261. ids.value = [];
  262. getTreeselect();
  263. form.value = { ...initFormData };
  264. dialog.visible = true;
  265. dialog.title = '新增模型';
  266. };
  267. const handleUpdate = () => {
  268. dialog.title = '修改模型';
  269. nextTick(async () => {
  270. await getTreeselect();
  271. const _id = ids.value[0];
  272. const res = await getInfo(_id);
  273. Object.assign(form.value, res.data);
  274. dialog.visible = true;
  275. });
  276. };
  277. /** 提交按钮 */
  278. const submitForm = () => {
  279. formRef.value.validate(async (valid: boolean) => {
  280. if (valid) {
  281. buttonLoading.value = true;
  282. if (ids.value && ids.value.length > 0) {
  283. form.value.id = ids.value[0];
  284. await update(form.value);
  285. proxy?.$modal.msgSuccess('新增成功');
  286. } else {
  287. initXml(form.value.key, form.value.name);
  288. form.value.xml = xml.value;
  289. await addModel(form.value);
  290. proxy?.$modal.msgSuccess('新增成功');
  291. }
  292. dialog.visible = false;
  293. await getList();
  294. }
  295. });
  296. };
  297. /** 取消按钮 */
  298. const cancel = () => {
  299. reset();
  300. dialog.visible = false;
  301. };
  302. /** 表单重置 */
  303. const reset = () => {
  304. form.value = { ...initFormData };
  305. formRef.value.resetFields();
  306. };
  307. // 打开设计流程
  308. const clickDesign = async (id: string) => {
  309. await designRef.value.open(id);
  310. };
  311. // 导出流程模型
  312. const clickExportZip = () => {
  313. proxy?.$download.zip('/workflow/model/export/zip/' + ids.value, "模型");
  314. };
  315. /** 查询流程分类下拉树结构 */
  316. const getTreeselect = async () => {
  317. const res = await listCategory();
  318. categoryOptions.value = [];
  319. const data: CategoryOption = { categoryCode: 'ALL', categoryName: '顶级节点', children: [] };
  320. data.children = proxy?.handleTree<CategoryOption>(res.data, 'id', 'parentId');
  321. categoryOptions.value.push(data);
  322. };
  323. const xml = ref<string>('');
  324. const initXml = async (key: string, name: string) => {
  325. xml.value = `<?xml version="1.0" encoding="UTF-8"?>
  326. <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" targetNamespace="http://www.flowable.org/processdef">
  327. <process id="${key}" name="${name}">
  328. <startEvent id="startNode1" name="开始" />
  329. </process>
  330. <bpmndi:BPMNDiagram id="BPMNDiagram_flow">
  331. <bpmndi:BPMNPlane id="BPMNPlane_flow" bpmnElement="T-2d89e7a3-ba79-4abd-9f64-ea59621c258c">
  332. <bpmndi:BPMNShape id="BPMNShape_startNode1" bpmnElement="startNode1" bioc:stroke="">
  333. <omgdc:Bounds x="240" y="200" width="30" height="30" />
  334. <bpmndi:BPMNLabel>
  335. <omgdc:Bounds x="242" y="237" width="23" height="14" />
  336. </bpmndi:BPMNLabel>
  337. </bpmndi:BPMNShape>
  338. </bpmndi:BPMNPlane>
  339. </bpmndi:BPMNDiagram>
  340. </definitions>`;
  341. return xml;
  342. };
  343. </script>