ActivitiAdmin.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <h1> {{ $t("lang.ActivitiAdmin.workflowEditing") }}</h1>
  3. <a-space wrap style="margin-bottom: 16px">
  4. <a-button class="editable-add-btn" :loading="loading" @click="handleAdd"> {{ $t("lang.ActivitiAdmin.newlyAdded") }}</a-button>
  5. <a-button class="editable-add-btn" :loading="loading" @click="handleRequery"> {{ $t("lang.ActivitiAdmin.refresh") }}</a-button>
  6. <a-button type="default" :disabled="!hasSelected" :loading="loading" @click="downloadBpmns">
  7. {{ $t("lang.ActivitiAdmin.download") }}{{ `(${selectedRowKeys.length})` }}
  8. </a-button>
  9. <a-button type="primary" danger :disabled="!hasSelected" :loading="loading" @click="deleteBpmnModalVisible = true">
  10. {{ $t("lang.ActivitiAdmin.delete") }}{{ `(${selectedRowKeys.length})` }}
  11. </a-button>
  12. <a-upload
  13. v-model:file-list="fileList"
  14. name="files"
  15. :headers="headers"
  16. action="/api/modelResource/createModelByFile"
  17. @change="handleChange"
  18. >
  19. <a-button>
  20. <upload-outlined />
  21. {{ $t("lang.ActivitiAdmin.upload") }}
  22. </a-button>
  23. </a-upload>
  24. </a-space>
  25. <a-table
  26. :columns="columns"
  27. :row-key="(record) => record.id"
  28. :data-source="dataSource"
  29. :pagination="pagination"
  30. :loading="loading"
  31. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  32. @change="handleTableChange"
  33. >
  34. <template #bodyCell="{ column, record }">
  35. <template v-if="column.key === 'operation'">
  36. <a @click="editBpmn(record)"> {{ $t("lang.ActivitiAdmin.edit") }}</a>
  37. <a v-if="record.deploymentId == null" style="margin-left: 1rem;" @click="deployBpmn(record)">{{ $t("lang.ActivitiAdmin.deploy") }}</a>
  38. <a v-else style="margin-left: 1rem;" @click="deleteDeployBpmn(record)">{{ $t("lang.ActivitiAdmin.deleteDeployment") }}</a>
  39. </template>
  40. </template>
  41. <template
  42. #customFilterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
  43. >
  44. <div style="padding: 8px">
  45. <a-input
  46. ref="searchInput"
  47. :placeholder="`Search ${column.dataIndex}`"
  48. :value="selectedKeys[0]"
  49. style="width: 188px; margin-bottom: 8px; display: block"
  50. @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
  51. @press-enter="handleSearch(selectedKeys, confirm, column.dataIndex)"
  52. />
  53. <a-button
  54. type="primary"
  55. size="small"
  56. style="width: 90px; margin-right: 8px"
  57. @click="handleSearch(selectedKeys, confirm, column.dataIndex)"
  58. >
  59. <template #icon><SearchOutlined /></template>
  60. Search
  61. </a-button>
  62. <a-button size="small" style="width: 90px" @click="handleReset(clearFilters)">
  63. Reset
  64. </a-button>
  65. </div>
  66. </template>
  67. </a-table>
  68. <a-modal v-model:open="deleteBpmnModalVisible" title="请确认删除工作流" @ok="deleteBpmns">
  69. 您确定要删除选中的{{ ` ${selectedRowKeys.length} ` }}个流程定义吗?
  70. </a-modal>
  71. </template>
  72. <script>
  73. import { usePagination } from 'vue-request';
  74. import { ref, reactive, toRefs, computed, defineComponent } from 'vue';
  75. import ModelResources from '../api/base/ModelResource.js';
  76. import Common from '../common/Common.js';
  77. import { SearchOutlined , UploadOutlined} from '@ant-design/icons-vue';
  78. import { message } from 'ant-design-vue';
  79. export default defineComponent({
  80. components: {
  81. SearchOutlined,UploadOutlined,
  82. },
  83. setup() {
  84. const deleteBpmnModalVisible = ref(false);
  85. const queryData = params => {
  86. let firstResult = (params.current - 1) * params.pageSize;
  87. let maxResults = params.pageSize;
  88. let modelName = null, deploymentId = null;
  89. if(state.searchedColumn === 'name'){
  90. modelName = state.searchText;
  91. }
  92. if(state.searchedColumn === 'deploymentId'){
  93. deploymentId = state.searchText;
  94. }
  95. return ModelResources.listModel(firstResult, maxResults, modelName, deploymentId);
  96. };
  97. const columns = [
  98. {
  99. title: '名称',
  100. dataIndex: 'name',
  101. key: 'name',
  102. customFilterDropdown: true,
  103. onFilterDropdownVisibleChange: visible => {
  104. if (visible) {
  105. setTimeout(() => {
  106. searchInput.value.focus();
  107. }, 100);
  108. }
  109. },
  110. },
  111. {
  112. title: 'Key',
  113. dataIndex: 'key',
  114. },
  115. {
  116. title: 'Category',
  117. dataIndex: 'category',
  118. },
  119. {
  120. title: '创建时间',
  121. dataIndex: 'createTime',
  122. },
  123. {
  124. title: '更新时间',
  125. dataIndex: 'lastUpdateTime',
  126. },
  127. {
  128. title: '部署Id',
  129. dataIndex: 'deploymentId',
  130. key: 'deploymentId',
  131. customFilterDropdown: true,
  132. onFilterDropdownVisibleChange: visible => {
  133. if (visible) {
  134. setTimeout(() => {
  135. searchInput.value.focus();
  136. }, 100);
  137. }
  138. },
  139. },
  140. {
  141. title: '租户Id',
  142. dataIndex: 'tenantId',
  143. },{
  144. title: '操作',
  145. key: 'operation',
  146. fixed: 'right',
  147. width: 100,
  148. },
  149. ];
  150. const state = reactive({
  151. searchText: '',
  152. searchedColumn: '',
  153. selectedRowKeys: [],
  154. });
  155. const hasSelected = computed(() => state.selectedRowKeys.length > 0);
  156. const onSelectChange = selectedRowKeys => {
  157. console.log('selectedRowKeys changed: ', selectedRowKeys);
  158. state.selectedRowKeys = selectedRowKeys;
  159. };
  160. const searchInput = ref();
  161. const {
  162. data: dataSource,
  163. run,
  164. loading,
  165. current,
  166. pageSize,
  167. total,
  168. } = usePagination(queryData, {
  169. formatResult: res => res.datas,
  170. pagination: {
  171. currentKey: 'current',
  172. pageSizeKey: 'pageSize',
  173. totalKey: 'total',
  174. },
  175. });
  176. const pagination = computed(() => ({
  177. total: total,
  178. current: current.value,
  179. pageSize: pageSize.value,
  180. }));
  181. const handleTableChange = (pag, filters, sorter) => {
  182. run({
  183. pageSize: pag.pageSize,
  184. current: pag.current,
  185. sortField: sorter.field,
  186. sortOrder: sorter.order,
  187. ...filters,
  188. });
  189. };
  190. const handleRequery = () => {
  191. run({
  192. pageSize: pageSize.value,
  193. current: 1,
  194. });
  195. fileList.value = [];
  196. state.selectedRowKeys = [];
  197. };
  198. const handleAdd = () =>{
  199. ModelResources.create().then(successData => {
  200. handleRequery();
  201. }, errorData => {
  202. Common.processException(errorData);
  203. });
  204. };
  205. const handleSearch = (selectedKeys, confirm, dataIndex) => {
  206. confirm();
  207. state.searchText = selectedKeys[0];
  208. state.searchedColumn = dataIndex;
  209. handleRequery();
  210. };
  211. const handleReset = clearFilters => {
  212. clearFilters({
  213. confirm: true,
  214. });
  215. state.searchText = '';
  216. state.searchedColumn = null;
  217. handleRequery();
  218. };
  219. const editBpmn = record => {
  220. let url = '/wf-editor/modeler.html?modelId=' + record.id;
  221. window.open(url);
  222. };
  223. const deployBpmn = record => {
  224. ModelResources.deploy(record.id).then(successData => {
  225. if(successData.errorCode === 0){
  226. handleRequery();
  227. message.success('流程部署成功,部署id=' + successData.data);
  228. }else{
  229. message.error(successData.errorMessage);
  230. }
  231. }, errorData => {
  232. Common.processException(errorData);
  233. });
  234. };
  235. const deleteBpmns = () => {
  236. ModelResources.deleteModels(state.selectedRowKeys).then(successData => {
  237. if(successData.errorCode === 0){
  238. successData.datas.forEach(element => {
  239. if(element.errorCode !== 0){
  240. message.error(element.errorMessage);
  241. }
  242. });
  243. }else{
  244. message.error(successData.errorMessage);
  245. }
  246. deleteBpmnModalVisible.value = false;
  247. handleRequery();
  248. },errorData => {
  249. Common.processException(errorData);
  250. });
  251. };
  252. const downloadBpmns = () => {
  253. if(state.selectedRowKeys.length == 0){
  254. return;
  255. }
  256. state.selectedRowKeys.forEach(item => {
  257. let url = '/api/modelResource/export/' + item;
  258. window.open(url);
  259. });
  260. };
  261. const deleteDeployBpmn = record => {
  262. ModelResources.undeploy(record.id).then(successData => {
  263. if(successData.errorCode === 0){
  264. handleRequery();
  265. message.success('删除流程部署成功。');
  266. }else{
  267. message.error(successData.errorMessage);
  268. }
  269. }, errorData => {
  270. Common.processException(errorData);
  271. });
  272. };
  273. const handleChange = info => {
  274. if (info.file.status !== 'uploading') {
  275. console.log(info.file, info.fileList);
  276. }
  277. if (info.file.status === 'done') {
  278. message.success(`${info.file.name} 文件上传成功。`);
  279. handleRequery();
  280. } else if (info.file.status === 'error') {
  281. message.error(`${info.file.name} 文件上传失败。 ${info.file.response}`);
  282. }
  283. };
  284. const fileList = ref([]);
  285. const headers = {
  286. 'token': localStorage.getItem('#token'),
  287. };
  288. return {
  289. searchInput,
  290. dataSource,
  291. pagination,
  292. loading,
  293. columns,
  294. editBpmn,
  295. ...toRefs(state),
  296. handleTableChange,
  297. handleRequery,
  298. handleAdd,
  299. handleSearch,
  300. handleReset,
  301. handleChange,
  302. fileList,
  303. deployBpmn,
  304. deleteDeployBpmn,
  305. deleteBpmns,
  306. hasSelected,
  307. onSelectChange,
  308. deleteBpmnModalVisible,
  309. downloadBpmns,
  310. headers,
  311. };
  312. },
  313. });
  314. </script>