index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <doc-alert title="流程设计器(BPMN)" url="https://doc.iocoder.cn/bpm/model-designer-dingding/" />
  3. <doc-alert
  4. title="流程设计器(钉钉、飞书)"
  5. url="https://doc.iocoder.cn/bpm/model-designer-bpmn/"
  6. />
  7. <doc-alert title="选择审批人、发起人自选" url="https://doc.iocoder.cn/bpm/assignee/" />
  8. <doc-alert title="会签、或签、依次审批" url="https://doc.iocoder.cn/bpm/multi-instance/" />
  9. <ContentWrap>
  10. <!-- 搜索工作栏 -->
  11. <el-form
  12. class="-mb-15px"
  13. :model="queryParams"
  14. ref="queryFormRef"
  15. :inline="true"
  16. label-width="68px"
  17. >
  18. <el-form-item label="流程标识" prop="key">
  19. <el-input
  20. v-model="queryParams.key"
  21. placeholder="请输入流程标识"
  22. clearable
  23. @keyup.enter="handleQuery"
  24. class="!w-240px"
  25. />
  26. </el-form-item>
  27. <el-form-item label="流程名称" prop="name">
  28. <el-input
  29. v-model="queryParams.name"
  30. placeholder="请输入流程名称"
  31. clearable
  32. @keyup.enter="handleQuery"
  33. class="!w-240px"
  34. />
  35. </el-form-item>
  36. <el-form-item label="流程分类" prop="category">
  37. <el-select
  38. v-model="queryParams.category"
  39. placeholder="请选择流程分类"
  40. clearable
  41. class="!w-240px"
  42. >
  43. <el-option
  44. v-for="category in categoryList"
  45. :key="category.code"
  46. :label="category.name"
  47. :value="category.code"
  48. />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item>
  52. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  53. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  54. <el-button
  55. type="primary"
  56. plain
  57. @click="openForm('create')"
  58. v-hasPermi="['bpm:model:create']"
  59. >
  60. <Icon icon="ep:plus" class="mr-5px" /> 新建流程
  61. </el-button>
  62. </el-form-item>
  63. </el-form>
  64. </ContentWrap>
  65. <!-- 列表 -->
  66. <ContentWrap>
  67. <el-table v-loading="loading" :data="list">
  68. <el-table-column label="流程标识" align="center" prop="key" width="200" />
  69. <el-table-column label="流程名称" align="center" prop="name" width="200">
  70. <template #default="scope">
  71. <el-button type="primary" link @click="handleBpmnDetail(scope.row)">
  72. <span>{{ scope.row.name }}</span>
  73. </el-button>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="流程图标" align="center" prop="icon" width="100">
  77. <template #default="scope">
  78. <el-image :src="scope.row.icon" class="h-32px w-32px" />
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="流程分类" align="center" prop="categoryName" width="100" />
  82. <el-table-column label="表单信息" align="center" prop="formType" width="200">
  83. <template #default="scope">
  84. <el-button
  85. v-if="scope.row.formType === 10"
  86. type="primary"
  87. link
  88. @click="handleFormDetail(scope.row)"
  89. >
  90. <span>{{ scope.row.formName }}</span>
  91. </el-button>
  92. <el-button
  93. v-else-if="scope.row.formType === 20"
  94. type="primary"
  95. link
  96. @click="handleFormDetail(scope.row)"
  97. >
  98. <span>{{ scope.row.formCustomCreatePath }}</span>
  99. </el-button>
  100. <label v-else>暂无表单</label>
  101. </template>
  102. </el-table-column>
  103. <el-table-column
  104. label="创建时间"
  105. align="center"
  106. prop="createTime"
  107. width="180"
  108. :formatter="dateFormatter"
  109. />
  110. <el-table-column label="最新部署的流程定义" align="center">
  111. <el-table-column
  112. label="流程版本"
  113. align="center"
  114. prop="processDefinition.version"
  115. width="100"
  116. >
  117. <template #default="scope">
  118. <el-tag v-if="scope.row.processDefinition">
  119. v{{ scope.row.processDefinition.version }}
  120. </el-tag>
  121. <el-tag v-else type="warning">未部署</el-tag>
  122. </template>
  123. </el-table-column>
  124. <el-table-column
  125. label="激活状态"
  126. align="center"
  127. prop="processDefinition.version"
  128. width="85"
  129. >
  130. <template #default="scope">
  131. <el-switch
  132. v-if="scope.row.processDefinition"
  133. v-model="scope.row.processDefinition.suspensionState"
  134. :active-value="1"
  135. :inactive-value="2"
  136. @change="handleChangeState(scope.row)"
  137. />
  138. </template>
  139. </el-table-column>
  140. <el-table-column label="部署时间" align="center" prop="deploymentTime" width="180">
  141. <template #default="scope">
  142. <span v-if="scope.row.processDefinition">
  143. {{ formatDate(scope.row.processDefinition.deploymentTime) }}
  144. </span>
  145. </template>
  146. </el-table-column>
  147. </el-table-column>
  148. <el-table-column label="操作" align="center" width="240" fixed="right">
  149. <template #default="scope">
  150. <el-button
  151. link
  152. type="primary"
  153. @click="openForm('update', scope.row.id)"
  154. v-hasPermi="['bpm:model:update']"
  155. >
  156. 修改流程
  157. </el-button>
  158. <el-button
  159. link
  160. type="primary"
  161. @click="handleDesign(scope.row)"
  162. v-hasPermi="['bpm:model:update']"
  163. >
  164. 设计流程
  165. </el-button>
  166. <el-button
  167. link
  168. type="primary"
  169. @click="handleSimpleDesign(scope.row)"
  170. v-hasPermi="['bpm:model:update']"
  171. >
  172. 仿钉钉设计流程
  173. </el-button>
  174. <el-button
  175. link
  176. type="primary"
  177. @click="handleDeploy(scope.row)"
  178. v-hasPermi="['bpm:model:deploy']"
  179. >
  180. 发布流程
  181. </el-button>
  182. <el-button
  183. link
  184. type="primary"
  185. v-hasPermi="['bpm:process-definition:query']"
  186. @click="handleDefinitionList(scope.row)"
  187. >
  188. 流程定义
  189. </el-button>
  190. <el-button
  191. link
  192. type="danger"
  193. @click="handleDelete(scope.row.id)"
  194. v-hasPermi="['bpm:model:delete']"
  195. >
  196. 删除
  197. </el-button>
  198. </template>
  199. </el-table-column>
  200. </el-table>
  201. <!-- 分页 -->
  202. <Pagination
  203. :total="total"
  204. v-model:page="queryParams.pageNo"
  205. v-model:limit="queryParams.pageSize"
  206. @pagination="getList"
  207. />
  208. </ContentWrap>
  209. <!-- 表单弹窗:添加/修改流程 -->
  210. <ModelForm ref="formRef" @success="getList" />
  211. <!-- 弹窗:表单详情 -->
  212. <Dialog title="表单详情" v-model="formDetailVisible" width="800">
  213. <form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
  214. </Dialog>
  215. <!-- 弹窗:流程模型图的预览 -->
  216. <Dialog title="流程图" v-model="bpmnDetailVisible" width="800">
  217. <MyProcessViewer
  218. key="designer"
  219. v-model="bpmnXML"
  220. :value="bpmnXML as any"
  221. v-bind="bpmnControlForm"
  222. :prefix="bpmnControlForm.prefix"
  223. />
  224. </Dialog>
  225. </template>
  226. <script lang="ts" setup>
  227. import { dateFormatter, formatDate } from '@/utils/formatTime'
  228. import { MyProcessViewer } from '@/components/bpmnProcessDesigner/package'
  229. import * as ModelApi from '@/api/bpm/model'
  230. import * as FormApi from '@/api/bpm/form'
  231. import ModelForm from './ModelForm.vue'
  232. import { setConfAndFields2 } from '@/utils/formCreate'
  233. import { CategoryApi } from '@/api/bpm/category'
  234. defineOptions({ name: 'BpmModel' })
  235. const message = useMessage() // 消息弹窗
  236. const { t } = useI18n() // 国际化
  237. const { push } = useRouter() // 路由
  238. const loading = ref(true) // 列表的加载中
  239. const total = ref(0) // 列表的总页数
  240. const list = ref([]) // 列表的数据
  241. const queryParams = reactive({
  242. pageNo: 1,
  243. pageSize: 10,
  244. key: undefined,
  245. name: undefined,
  246. category: undefined
  247. })
  248. const queryFormRef = ref() // 搜索的表单
  249. const categoryList = ref([]) // 流程分类列表
  250. /** 查询列表 */
  251. const getList = async () => {
  252. loading.value = true
  253. try {
  254. const data = await ModelApi.getModelPage(queryParams)
  255. list.value = data.list
  256. total.value = data.total
  257. } finally {
  258. loading.value = false
  259. }
  260. }
  261. /** 搜索按钮操作 */
  262. const handleQuery = () => {
  263. queryParams.pageNo = 1
  264. getList()
  265. }
  266. /** 重置按钮操作 */
  267. const resetQuery = () => {
  268. queryFormRef.value.resetFields()
  269. handleQuery()
  270. }
  271. /** 添加/修改操作 */
  272. const formRef = ref()
  273. const openForm = (type: string, id?: number) => {
  274. formRef.value.open(type, id)
  275. }
  276. /** 删除按钮操作 */
  277. const handleDelete = async (id: number) => {
  278. try {
  279. // 删除的二次确认
  280. await message.delConfirm()
  281. // 发起删除
  282. await ModelApi.deleteModel(id)
  283. message.success(t('common.delSuccess'))
  284. // 刷新列表
  285. await getList()
  286. } catch {}
  287. }
  288. /** 更新状态操作 */
  289. const handleChangeState = async (row) => {
  290. const state = row.processDefinition.suspensionState
  291. try {
  292. // 修改状态的二次确认
  293. const id = row.id
  294. const statusState = state === 1 ? '激活' : '挂起'
  295. const content = '是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?'
  296. await message.confirm(content)
  297. // 发起修改状态
  298. await ModelApi.updateModelState(id, state)
  299. // 刷新列表
  300. await getList()
  301. } catch {
  302. // 取消后,进行恢复按钮
  303. row.processDefinition.suspensionState = state === 1 ? 2 : 1
  304. }
  305. }
  306. /** 设计流程 */
  307. const handleDesign = (row) => {
  308. push({
  309. name: 'BpmModelEditor',
  310. query: {
  311. modelId: row.id
  312. }
  313. })
  314. }
  315. const handleSimpleDesign = (row) => {
  316. push({
  317. name: 'SimpleWorkflowDesignEditor',
  318. query: {
  319. modelId: row.id
  320. }
  321. })
  322. }
  323. /** 发布流程 */
  324. const handleDeploy = async (row) => {
  325. try {
  326. // 删除的二次确认
  327. await message.confirm('是否部署该流程!!')
  328. // 发起部署
  329. await ModelApi.deployModel(row.id)
  330. message.success(t('部署成功'))
  331. // 刷新列表
  332. await getList()
  333. } catch {}
  334. }
  335. /** 跳转到指定流程定义列表 */
  336. const handleDefinitionList = (row) => {
  337. push({
  338. name: 'BpmProcessDefinition',
  339. query: {
  340. key: row.key
  341. }
  342. })
  343. }
  344. /** 流程表单的详情按钮操作 */
  345. const formDetailVisible = ref(false)
  346. const formDetailPreview = ref({
  347. rule: [],
  348. option: {}
  349. })
  350. const handleFormDetail = async (row) => {
  351. if (row.formType == 10) {
  352. // 设置表单
  353. const data = await FormApi.getForm(row.formId)
  354. setConfAndFields2(formDetailPreview, data.conf, data.fields)
  355. // 弹窗打开
  356. formDetailVisible.value = true
  357. } else {
  358. await push({
  359. path: row.formCustomCreatePath
  360. })
  361. }
  362. }
  363. /** 流程图的详情按钮操作 */
  364. const bpmnDetailVisible = ref(false)
  365. const bpmnXML = ref(null)
  366. const bpmnControlForm = ref({
  367. prefix: 'flowable'
  368. })
  369. const handleBpmnDetail = async (row) => {
  370. const data = await ModelApi.getModel(row.id)
  371. bpmnXML.value = data.bpmnXml || ''
  372. bpmnDetailVisible.value = true
  373. }
  374. /** 初始化 **/
  375. onMounted(async () => {
  376. await getList()
  377. // 查询流程分类列表
  378. categoryList.value = await CategoryApi.getCategorySimpleList()
  379. })
  380. </script>