index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. title="新建流程"
  11. v-hasPermi="['bpm:model:create']"
  12. @click="handleCreate"
  13. />
  14. <!-- 操作:导入 -->
  15. <XButton
  16. type="warning"
  17. preIcon="ep:upload"
  18. :title="'导入流程'"
  19. @click="handleImport"
  20. style="margin-left: 10px"
  21. />
  22. </template>
  23. <!-- 流程名称 -->
  24. <template #name_default="{ row }">
  25. <XTextButton :title="row.name" @click="handleBpmnDetail(row.id)" />
  26. </template>
  27. <!-- 表单信息 -->
  28. <template #formId_default="{ row }">
  29. <XTextButton
  30. v-if="row.formType === 10"
  31. :title="forms.find((form) => form.id === row.formId)?.name || row.formId"
  32. @click="handleFormDetail(row)"
  33. />
  34. <XTextButton v-else :title="row.formCustomCreatePath" @click="handleFormDetail(row)" />
  35. </template>
  36. <!-- 流程版本 -->
  37. <template #version_default="{ row }">
  38. <el-tag v-if="row.processDefinition">v{{ row.processDefinition.version }}</el-tag>
  39. <el-tag type="warning" v-else>未部署</el-tag>
  40. </template>
  41. <!-- 激活状态 -->
  42. <template #status_default="{ row }">
  43. <el-switch
  44. v-if="row.processDefinition"
  45. v-model="row.processDefinition.suspensionState"
  46. :active-value="1"
  47. :inactive-value="2"
  48. @change="handleChangeState(row)"
  49. />
  50. </template>
  51. <!-- 操作 -->
  52. <template #actionbtns_default="{ row }">
  53. <XTextButton
  54. preIcon="ep:edit"
  55. title="修改流程"
  56. v-hasPermi="['bpm:model:update']"
  57. @click="handleUpdate(row.id)"
  58. />
  59. <XTextButton
  60. preIcon="ep:setting"
  61. title="设计流程"
  62. v-hasPermi="['bpm:model:update']"
  63. @click="handleDesign(row)"
  64. />
  65. <XTextButton
  66. preIcon="ep:user"
  67. title="分配规则"
  68. v-hasPermi="['bpm:task-assign-rule:query']"
  69. @click="handleAssignRule(row)"
  70. />
  71. <XTextButton
  72. preIcon="ep:position"
  73. title="发布流程"
  74. v-hasPermi="['bpm:model:deploy']"
  75. @click="handleDeploy(row)"
  76. />
  77. <XTextButton
  78. preIcon="ep:aim"
  79. title="流程定义"
  80. v-hasPermi="['bpm:process-definition:query']"
  81. @click="handleDefinitionList(row)"
  82. />
  83. <!-- 操作:删除 -->
  84. <XTextButton
  85. preIcon="ep:delete"
  86. :title="t('action.del')"
  87. v-hasPermi="['bpm:model:delete']"
  88. @click="handleDelete(row.id)"
  89. />
  90. </template>
  91. </XTable>
  92. <!-- 对话框(添加 / 修改流程) -->
  93. <XModal v-model="dialogVisible" :title="dialogTitle" width="600">
  94. <el-form
  95. :loading="dialogLoading"
  96. el-form
  97. ref="saveFormRef"
  98. :model="saveForm"
  99. :rules="rules"
  100. label-width="110px"
  101. >
  102. <el-form-item label="流程标识" prop="key">
  103. <el-input
  104. v-model="saveForm.key"
  105. placeholder="请输入流标标识"
  106. style="width: 330px"
  107. :disabled="!!saveForm.id"
  108. />
  109. <el-tooltip
  110. v-if="!saveForm.id"
  111. class="item"
  112. effect="light"
  113. content="新建后,流程标识不可修改!"
  114. placement="top"
  115. >
  116. <i style="padding-left: 5px" class="el-icon-question"></i>
  117. </el-tooltip>
  118. <el-tooltip
  119. v-else
  120. class="item"
  121. effect="light"
  122. content="流程标识不可修改!"
  123. placement="top"
  124. >
  125. <i style="padding-left: 5px" class="el-icon-question"></i>
  126. </el-tooltip>
  127. </el-form-item>
  128. <el-form-item label="流程名称" prop="name">
  129. <el-input
  130. v-model="saveForm.name"
  131. placeholder="请输入流程名称"
  132. :disabled="!!saveForm.id"
  133. clearable
  134. />
  135. </el-form-item>
  136. <el-form-item v-if="saveForm.id" label="流程分类" prop="category">
  137. <el-select
  138. v-model="saveForm.category"
  139. placeholder="请选择流程分类"
  140. clearable
  141. style="width: 100%"
  142. >
  143. <el-option
  144. v-for="dict in getDictOptions(DICT_TYPE.BPM_MODEL_CATEGORY)"
  145. :key="dict.value"
  146. :label="dict.label"
  147. :value="dict.value"
  148. />
  149. </el-select>
  150. </el-form-item>
  151. <el-form-item label="流程描述" prop="description">
  152. <el-input type="textarea" v-model="saveForm.description" clearable />
  153. </el-form-item>
  154. <div v-if="saveForm.id">
  155. <el-form-item label="表单类型" prop="formType">
  156. <el-radio-group v-model="saveForm.formType">
  157. <el-radio
  158. v-for="dict in getDictOptions(DICT_TYPE.BPM_MODEL_FORM_TYPE)"
  159. :key="parseInt(dict.value)"
  160. :label="parseInt(dict.value)"
  161. >
  162. {{ dict.label }}
  163. </el-radio>
  164. </el-radio-group>
  165. </el-form-item>
  166. <el-form-item v-if="saveForm.formType === 10" label="流程表单" prop="formId">
  167. <el-select v-model="saveForm.formId" clearable style="width: 100%">
  168. <el-option v-for="form in forms" :key="form.id" :label="form.name" :value="form.id" />
  169. </el-select>
  170. </el-form-item>
  171. <el-form-item
  172. v-if="saveForm.formType === 20"
  173. label="表单提交路由"
  174. prop="formCustomCreatePath"
  175. >
  176. <el-input
  177. v-model="saveForm.formCustomCreatePath"
  178. placeholder="请输入表单提交路由"
  179. style="width: 330px"
  180. />
  181. <el-tooltip
  182. class="item"
  183. effect="light"
  184. content="自定义表单的提交路径,使用 Vue 的路由地址,例如说:bpm/oa/leave/create"
  185. placement="top"
  186. >
  187. <i style="padding-left: 5px" class="el-icon-question"></i>
  188. </el-tooltip>
  189. </el-form-item>
  190. <el-form-item
  191. v-if="saveForm.formType === 20"
  192. label="表单查看路由"
  193. prop="formCustomViewPath"
  194. >
  195. <el-input
  196. v-model="saveForm.formCustomViewPath"
  197. placeholder="请输入表单查看路由"
  198. style="width: 330px"
  199. />
  200. <el-tooltip
  201. class="item"
  202. effect="light"
  203. content="自定义表单的查看路径,使用 Vue 的路由地址,例如说:bpm/oa/leave/view"
  204. placement="top"
  205. >
  206. <i style="padding-left: 5px" class="el-icon-question"></i>
  207. </el-tooltip>
  208. </el-form-item>
  209. </div>
  210. </el-form>
  211. <template #footer>
  212. <!-- 按钮:保存 -->
  213. <XButton
  214. type="primary"
  215. :loading="dialogLoading"
  216. @click="submitForm"
  217. :title="t('action.save')"
  218. />
  219. <!-- 按钮:关闭 -->
  220. <XButton
  221. :loading="dialogLoading"
  222. @click="dialogVisible = false"
  223. :title="t('dialog.close')"
  224. />
  225. </template>
  226. </XModal>
  227. <!-- 导入流程 -->
  228. <XModal v-model="importDialogVisible" width="400" title="导入流程">
  229. <div>
  230. <el-upload
  231. ref="uploadRef"
  232. :action="importUrl"
  233. :headers="uploadHeaders"
  234. :drag="true"
  235. :limit="1"
  236. :multiple="true"
  237. :show-file-list="true"
  238. :disabled="uploadDisabled"
  239. :on-exceed="handleExceed"
  240. :on-success="handleFileSuccess"
  241. :on-error="excelUploadError"
  242. :auto-upload="false"
  243. accept=".bpmn, .xml"
  244. name="bpmnFile"
  245. :data="importForm"
  246. >
  247. <el-icon class="el-icon--upload"><upload-filled /></el-icon>
  248. <div class="el-upload__text"> 将文件拖到此处,或 <em>点击上传</em> </div>
  249. <template #tip>
  250. <div class="el-upload__tip" style="color: red">
  251. 提示:仅允许导入“bpm”或“xml”格式文件!
  252. </div>
  253. <div>
  254. <el-form
  255. ref="importFormRef"
  256. :model="importForm"
  257. :rules="rules"
  258. label-width="120px"
  259. status-icon
  260. >
  261. <el-form-item label="流程标识" prop="key">
  262. <el-input
  263. v-model="importForm.key"
  264. placeholder="请输入流标标识"
  265. style="width: 250px"
  266. />
  267. </el-form-item>
  268. <el-form-item label="流程名称" prop="name">
  269. <el-input v-model="importForm.name" placeholder="请输入流程名称" clearable />
  270. </el-form-item>
  271. <el-form-item label="流程描述" prop="description">
  272. <el-input type="textarea" v-model="importForm.description" clearable />
  273. </el-form-item>
  274. </el-form>
  275. </div>
  276. </template>
  277. </el-upload>
  278. </div>
  279. <template #footer>
  280. <!-- 按钮:保存 -->
  281. <XButton
  282. type="warning"
  283. preIcon="ep:upload-filled"
  284. :title="t('action.save')"
  285. @click="submitFileForm"
  286. />
  287. <XButton title="取 消" @click="uploadClose" />
  288. </template>
  289. </XModal>
  290. <!-- 表单详情的弹窗 -->
  291. <XModal v-model="formDetailVisible" width="800" title="表单详情" :show-footer="false">
  292. <ViewForm
  293. :rule="formDetailPreview.rule"
  294. :option="formDetailPreview.option"
  295. v-if="formDetailVisible"
  296. />
  297. </XModal>
  298. </ContentWrap>
  299. </template>
  300. <script setup lang="ts">
  301. // 全局相关的 import
  302. import { onMounted, ref, unref } from 'vue'
  303. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  304. import { FormInstance, UploadInstance } from 'element-plus'
  305. // 业务相关的 import
  306. import { getAccessToken, getTenantId } from '@/utils/auth'
  307. import * as FormApi from '@/api/bpm/form'
  308. import * as ModelApi from '@/api/bpm/model'
  309. import { allSchemas, rules } from './model.data'
  310. const { t } = useI18n() // 国际化
  311. const message = useMessage() // 消息弹窗
  312. const router = useRouter() // 路由
  313. import viewForm from '@form-create/element-ui'
  314. const ViewForm = viewForm.$form()
  315. import { setConfAndFields2 } from '@/utils/formCreate'
  316. // ========== 列表相关 ==========
  317. const [registerTable, { reload }] = useXTable({
  318. allSchemas: allSchemas,
  319. getListApi: ModelApi.getModelPageApi
  320. })
  321. const forms = ref() // 流程表单的下拉框的数据
  322. // 设计流程
  323. const handleDesign = (row) => {
  324. console.log(row, '设计流程')
  325. router.push({
  326. name: 'modelEditor',
  327. query: {
  328. modelId: row.id
  329. }
  330. })
  331. }
  332. // 跳转到指定流程定义列表
  333. const handleDefinitionList = (row) => {
  334. router.push({
  335. name: 'BpmProcessDefinitionList',
  336. query: {
  337. key: row.key
  338. }
  339. })
  340. }
  341. // 流程表单的详情按钮操作
  342. const formDetailVisible = ref(false)
  343. const formDetailPreview = ref({
  344. rule: [],
  345. option: {}
  346. })
  347. const handleFormDetail = async (row) => {
  348. if (row.formType == 10) {
  349. // 设置表单
  350. const data = await FormApi.getFormApi(row.formId)
  351. setConfAndFields2(formDetailPreview, data.conf, data.fields)
  352. // 弹窗打开
  353. formDetailVisible.value = true
  354. } else {
  355. router.push({
  356. path: row.formCustomCreatePath
  357. })
  358. }
  359. }
  360. // 流程图的详情按钮操作
  361. const handleBpmnDetail = (row) => {
  362. // TODO 芋艿:流程组件开发中
  363. console.log(row)
  364. message.success('流程组件开发中,预计 2 月底完成')
  365. }
  366. // 点击任务分配按钮
  367. const handleAssignRule = (row) => {
  368. router.push({
  369. name: 'BpmTaskAssignRuleList',
  370. query: {
  371. modelId: row.id
  372. }
  373. })
  374. }
  375. // ========== 新建/修改流程 ==========
  376. const dialogVisible = ref(false)
  377. const dialogTitle = ref('新建模型')
  378. const dialogLoading = ref(false)
  379. const saveForm = ref({})
  380. const saveFormRef = ref<FormInstance>()
  381. // 设置标题
  382. const setDialogTile = async (type: string) => {
  383. dialogTitle.value = t('action.' + type)
  384. dialogVisible.value = true
  385. }
  386. // 新增操作
  387. const handleCreate = async () => {
  388. resetForm()
  389. await setDialogTile('create')
  390. }
  391. // 修改操作
  392. const handleUpdate = async (rowId: number) => {
  393. resetForm()
  394. await setDialogTile('create')
  395. // 设置数据
  396. saveForm.value = await ModelApi.getModelApi(rowId)
  397. }
  398. // 提交按钮
  399. const submitForm = async () => {
  400. // 参数校验
  401. const elForm = unref(saveFormRef)
  402. if (!elForm) return
  403. const valid = await elForm.validate()
  404. if (!valid) return
  405. // 提交请求
  406. dialogLoading.value = true
  407. try {
  408. const data = saveForm.value as ModelApi.ModelVO
  409. if (!data.id) {
  410. await ModelApi.createModelApi(data)
  411. message.success(t('common.createSuccess'))
  412. } else {
  413. await ModelApi.updateModelApi(data)
  414. message.success(t('common.updateSuccess'))
  415. }
  416. dialogVisible.value = false
  417. } finally {
  418. // 刷新列表
  419. await reload()
  420. dialogLoading.value = false
  421. }
  422. }
  423. // 重置表单
  424. const resetForm = () => {
  425. saveForm.value = {
  426. formType: 10,
  427. name: '',
  428. courseSort: '',
  429. description: '',
  430. formId: '',
  431. formCustomCreatePath: '',
  432. formCustomViewPath: ''
  433. }
  434. saveFormRef.value?.resetFields()
  435. }
  436. // ========== 删除 / 更新状态 / 发布流程 ==========
  437. // 删除流程
  438. const handleDelete = (rowId) => {
  439. message.delConfirm('是否删除该流程!!').then(async () => {
  440. await ModelApi.deleteModelApi(rowId)
  441. message.success(t('common.delSuccess'))
  442. // 刷新列表
  443. reload()
  444. })
  445. }
  446. // 更新状态操作
  447. const handleChangeState = (row) => {
  448. const id = row.id
  449. const state = row.processDefinition.suspensionState
  450. const statusState = state === 1 ? '激活' : '挂起'
  451. const content = '是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?'
  452. message
  453. .confirm(content)
  454. .then(async () => {
  455. await ModelApi.updateModelStateApi(id, state)
  456. message.success(t('部署成功'))
  457. // 刷新列表
  458. reload()
  459. })
  460. .catch(() => {
  461. // 取消后,进行恢复按钮
  462. row.processDefinition.suspensionState = state === 1 ? 2 : 1
  463. })
  464. }
  465. // 发布流程
  466. const handleDeploy = (row) => {
  467. message.confirm('是否部署该流程!!').then(async () => {
  468. await ModelApi.deployModelApi(row.id)
  469. message.success(t('部署成功'))
  470. // 刷新列表
  471. reload()
  472. })
  473. }
  474. // ========== 导入流程 ==========
  475. const uploadRef = ref<UploadInstance>()
  476. let importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/bpm/model/import'
  477. const uploadHeaders = ref()
  478. const importDialogVisible = ref(false)
  479. const uploadDisabled = ref(false)
  480. const importFormRef = ref<FormInstance>()
  481. const importForm = ref({
  482. key: '',
  483. name: '',
  484. description: ''
  485. })
  486. // 导入流程弹窗显示
  487. const handleImport = () => {
  488. importDialogVisible.value = true
  489. }
  490. // 文件数超出提示
  491. const handleExceed = (): void => {
  492. message.error('最多只能上传一个文件!')
  493. }
  494. // 上传错误提示
  495. const excelUploadError = (): void => {
  496. message.error('导入流程失败,请您重新上传!')
  497. }
  498. // 提交文件上传
  499. const submitFileForm = () => {
  500. uploadHeaders.value = {
  501. Authorization: 'Bearer ' + getAccessToken(),
  502. 'tenant-id': getTenantId()
  503. }
  504. uploadDisabled.value = true
  505. uploadRef.value!.submit()
  506. }
  507. // 文件上传成功
  508. const handleFileSuccess = async (response: any): Promise<void> => {
  509. if (response.code !== 0) {
  510. message.error(response.msg)
  511. return
  512. }
  513. // 重置表单
  514. uploadClose()
  515. // 提示,并刷新
  516. message.success('导入流程成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】')
  517. await reload()
  518. }
  519. // 关闭文件上传
  520. const uploadClose = () => {
  521. // 关闭弹窗
  522. importDialogVisible.value = false
  523. // 重置上传状态和文件
  524. uploadDisabled.value = false
  525. uploadRef.value!.clearFiles()
  526. // 重置表单
  527. importForm.value = {
  528. key: '',
  529. name: '',
  530. description: ''
  531. }
  532. importFormRef.value?.resetFields()
  533. }
  534. // ========== 初始化 ==========
  535. onMounted(() => {
  536. // 获得流程表单的下拉框的数据
  537. FormApi.getSimpleFormsApi().then((data) => {
  538. forms.value = data
  539. })
  540. })
  541. </script>