bpm:增加流程模型的列表

This commit is contained in:
YunaiV 2023-01-20 20:11:24 +08:00
parent 8e29e42797
commit ec6a46a541
5 changed files with 639 additions and 283 deletions

View File

@ -1,5 +1,28 @@
import request from '@/config/axios' import request from '@/config/axios'
import { ModelVO } from './types'
export type ProcessDefinitionVO = {
id: string
version: number
deploymentTIme: string
suspensionState: number
}
export type ModelVO = {
id: number
formName: string
key: string
name: string
description: string
category: string
formType: number
formId: number
formCustomCreatePath: string
formCustomViewPath: string
processDefinition: ProcessDefinitionVO
status: number
remark: string
createTime: string
}
export const getModelPageApi = async (params) => { export const getModelPageApi = async (params) => {
return await request.get({ url: '/bpm/model/page', params }) return await request.get({ url: '/bpm/model/page', params })

View File

@ -1,23 +0,0 @@
export type ProcessDefinitionVO = {
id: string
version: number
deploymentTIme: string
suspensionState: number
}
export type ModelVO = {
id: number
formName: string
key: string
name: string
description: string
category: string
formType: number
formId: number
formCustomCreatePath: string
formCustomViewPath: string
processDefinition: ProcessDefinitionVO
status: number
remark: string
createTime: string
}

View File

@ -33,6 +33,9 @@ export default defineComponent({
if (!props.type) { if (!props.type) {
return null return null
} }
if (!props.value) {
return null
}
getDictObj(props.type, props.value.toString()) getDictObj(props.type, props.value.toString())
return ( return (
<ElTag <ElTag

View File

@ -1,149 +1,43 @@
<script setup lang="ts" name="Model">
import dayjs from 'dayjs'
import { DICT_TYPE } from '@/utils/dict'
import { useTable } from '@/hooks/web/useTable'
import type { FormExpose } from '@/components/Form'
import type { ModelVO } from '@/api/bpm/model/types'
import { rules, allSchemas } from './model.data'
import * as ModelApi from '@/api/bpm/model'
const { t } = useI18n() //
const message = useMessage()
// ========== ==========
const { register, tableObject, methods } = useTable<ModelVO>({
getListApi: ModelApi.getModelPageApi,
delListApi: ModelApi.deleteModelApi
})
const { getList, setSearchParams, delList } = methods
// ========== CRUD ==========
const actionLoading = ref(false) //
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const formRef = ref<FormExpose>() // Ref
//
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
//
const handleCreate = () => {
setDialogTile('create')
}
//
const handleUpdate = async (row: ModelVO) => {
setDialogTile('update')
//
const res = await ModelApi.getModelApi(row.id)
unref(formRef)?.setValues(res)
}
//
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true
//
try {
const data = unref(formRef)?.formModel as ModelVO
if (actionType.value === 'create') {
await ModelApi.createModelApi(data)
message.success(t('common.createSuccess'))
} else {
await ModelApi.updateModelApi(data)
message.success(t('common.updateSuccess'))
}
//
dialogVisible.value = false
await getList()
} finally {
actionLoading.value = false
}
}
})
}
/** 流程表单的详情按钮操作 */
const handleChangeState = async (row: ModelVO) => {
const state = row.processDefinition.suspensionState
const statusState = state === 1 ? '激活' : '挂起'
message
.confirm(
'是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?',
t('common.reminder')
)
.then(async () => {
ModelApi.updateModelStateApi(row.id, state).then(() => {
message.success(t('common.updateSuccess'))
getList()
})
})
.catch(() => {})
}
// ========== ==========
const detailData = ref() // Ref
//
const handleDetail = async (row: ModelVO) => {
//
detailData.value = row
setDialogTile('detail')
}
// ========== ==========
getList()
</script>
<template> <template>
<!-- 搜索工作区 -->
<ContentWrap> <ContentWrap>
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
</ContentWrap>
<ContentWrap>
<!-- 操作工具栏 -->
<div class="mb-10px">
<el-button type="primary" v-hasPermi="['bpm:model:create']" @click="handleCreate()">
<Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
</el-button>
</div>
<!-- 列表 --> <!-- 列表 -->
<Table <XTable @register="registerTable">
:columns="allSchemas.tableColumns" <template #toolbar_buttons>
:selection="false" <!-- 操作新增 -->
:data="tableObject.tableList" <XButton
:loading="tableObject.loading" type="primary"
:pagination="{ preIcon="ep:zoom-in"
total: tableObject.total title="新建流程"
}" v-hasPermi="['bpm:model:create']"
v-model:pageSize="tableObject.pageSize" @click="handleCreate"
v-model:currentPage="tableObject.currentPage" />
@register="register" <!-- 操作导入 -->
> <XButton
<template #category="{ row }"> type="warning"
<DictTag :type="DICT_TYPE.BPM_MODEL_CATEGORY" :value="row.category" /> preIcon="ep:upload"
:title="'导入流程'"
@click="handleImport"
style="margin-left: 10px"
/>
</template> </template>
<template #formId="{ row }"> <!-- 流程名称 -->
<span>{{ row.formName }}</span> <template #name_default="{ row }">
<XTextButton :title="row.name" @click="handleBpmnDetail(row.id)" />
</template> </template>
<template #processDefinition> <!-- 表单信息 -->
<el-table-column label="流程版本" prop="processDefinition.version"> <template #formId_default="{ row }">
<template #default="{ row }"> <XTextButton
<el-tag v-if="row.processDefinition"> :title="forms.find((form) => form.id === row.formId)?.name || row.formId"
{{ 'v' + row.processDefinition.version }} @click="handleFormDetail(row.id)"
</el-tag> />
</template>
<!-- 流程版本 -->
<template #version_default="{ row }">
<el-tag v-if="row.processDefinition">v{{ row.processDefinition.version }}</el-tag>
<el-tag type="warning" v-else>未部署</el-tag> <el-tag type="warning" v-else>未部署</el-tag>
</template> </template>
</el-table-column> <!-- 激活状态 -->
<el-table-column label="激活状态" prop="processDefinition.suspensionState"> <template #status_default="{ row }">
<template #default="{ row }">
<el-switch <el-switch
v-if="row.processDefinition" v-if="row.processDefinition"
v-model="row.processDefinition.suspensionState" v-model="row.processDefinition.suspensionState"
@ -152,63 +46,495 @@ getList()
@change="handleChangeState(row)" @change="handleChangeState(row)"
/> />
</template> </template>
</el-table-column> <!-- 操作 -->
<el-table-column label="部署时间" prop="processDefinition.deploymentTime"> <template #actionbtns_default="{ row }">
<template #default="{ row }"> <XTextButton
<span> preIcon="ep:edit"
{{ dayjs(row.processDefinition.deploymentTime).format('YYYY-MM-DD HH:mm:ss') }} title="修改流程"
</span> v-hasPermi="['bpm:model:update']"
</template> @click="handleUpdate(row.id)"
</el-table-column> />
</template> <XTextButton
<template #createTime="{ row }"> preIcon="ep:setting"
<span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span> title="设计流程"
</template> v-hasPermi="['bpm:model:update']"
<template #action="{ row }"> @click="handleDesign(row)"
<el-button link type="primary" v-hasPermi="['bpm:model:update']" @click="handleUpdate(row)"> />
<Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }} <XTextButton
</el-button> preIcon="ep:user"
<el-button link type="primary" v-hasPermi="['bpm:model:update']" @click="handleDetail(row)"> title="分配规则"
<Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }} v-hasPermi="['bpm:task-assign-rule:query']"
</el-button> @click="handleAssignRule(row)"
<el-button />
link <XTextButton
type="primary" preIcon="ep:position"
title="发布流程"
v-hasPermi="['bpm:model:deploy']"
@click="handleDeploy(row)"
/>
<XTextButton
preIcon="ep:aim"
title="流程定义"
v-hasPermi="['bpm:process-definition:query']"
@click="handleDefinitionList(row.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['bpm:model:delete']" v-hasPermi="['bpm:model:delete']"
@click="delList(row.id, false)" @click="handleDelete(row.id)"
> />
<Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
</el-button>
</template> </template>
</Table> </XTable>
</ContentWrap>
<XModal v-model="dialogVisible" :title="dialogTitle"> <!-- 对话框(添加 / 修改流程) -->
<!-- 对话框(添加 / 修改) --> <XModal v-model="dialogVisible" :title="dialogTitle" width="600">
<Form <el-form
v-if="['create', 'update'].includes(actionType)" :loading="dialogLoading"
:schema="allSchemas.formSchema" el-form
ref="saveFormRef"
:model="saveForm"
:rules="rules" :rules="rules"
ref="formRef" label-width="110px"
>
<el-form-item label="流程标识" prop="key">
<el-input
v-model="saveForm.key"
placeholder="请输入流标标识"
style="width: 330px"
:disabled="!!saveForm.id"
/> />
<!-- 对话框(详情) --> <el-tooltip
<Descriptions v-if="!saveForm.id"
v-if="actionType === 'detail'" class="item"
:schema="allSchemas.detailSchema" effect="light"
:data="detailData" content="新建后,流程标识不可修改!"
placement="top"
>
<i style="padding-left: 5px" class="el-icon-question"></i>
</el-tooltip>
<el-tooltip
v-else
class="item"
effect="light"
content="流程标识不可修改!"
placement="top"
>
<i style="padding-left: 5px" class="el-icon-question"></i>
</el-tooltip>
</el-form-item>
<el-form-item label="流程名称" prop="name">
<el-input
v-model="saveForm.name"
placeholder="请输入流程名称"
:disabled="!!saveForm.id"
clearable
/> />
<!-- 操作按钮 --> </el-form-item>
<el-form-item v-if="saveForm.id" label="流程分类" prop="category">
<el-select
v-model="saveForm.category"
placeholder="请选择流程分类"
clearable
style="width: 100%"
>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.BPM_MODEL_CATEGORY)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="流程描述" prop="description">
<el-input type="textarea" v-model="saveForm.description" clearable />
</el-form-item>
<div v-if="saveForm.id">
<el-form-item label="表单类型" prop="formType">
<el-radio-group v-model="saveForm.formType">
<el-radio
v-for="dict in getDictOptions(DICT_TYPE.BPM_MODEL_FORM_TYPE)"
:key="parseInt(dict.value)"
:label="parseInt(dict.value)"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="saveForm.formType === 10" label="流程表单" prop="formId">
<el-select v-model="saveForm.formId" clearable style="width: 100%">
<el-option v-for="form in forms" :key="form.id" :label="form.name" :value="form.id" />
</el-select>
</el-form-item>
<el-form-item
v-if="saveForm.formType === 20"
label="表单提交路由"
prop="formCustomCreatePath"
>
<el-input
v-model="saveForm.formCustomCreatePath"
placeholder="请输入表单提交路由"
style="width: 330px"
/>
<el-tooltip
class="item"
effect="light"
content="自定义表单的提交路径,使用 Vue 的路由地址例如说bpm/oa/leave/create"
placement="top"
>
<i style="padding-left: 5px" class="el-icon-question"></i>
</el-tooltip>
</el-form-item>
<el-form-item
v-if="saveForm.formType === 20"
label="表单查看路由"
prop="formCustomViewPath"
>
<el-input
v-model="saveForm.formCustomViewPath"
placeholder="请输入表单查看路由"
style="width: 330px"
/>
<el-tooltip
class="item"
effect="light"
content="自定义表单的查看路径,使用 Vue 的路由地址例如说bpm/oa/leave/view"
placement="top"
>
<i style="padding-left: 5px" class="el-icon-question"></i>
</el-tooltip>
</el-form-item>
</div>
</el-form>
<template #footer> <template #footer>
<!-- 按钮保存 --> <!-- 按钮保存 -->
<XButton <XButton
v-if="['create', 'update'].includes(actionType)"
type="primary" type="primary"
:title="t('action.save')" :loading="dialogLoading"
:loading="actionLoading"
@click="submitForm()" @click="submitForm()"
:title="t('action.save')"
/> />
<!-- 按钮关闭 --> <!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" /> <XButton
:loading="dialogLoading"
@click="dialogVisible = false"
:title="t('dialog.close')"
/>
</template> </template>
</XModal> </XModal>
<!-- 导入流程 -->
<XModal v-model="importDialogVisible" width="400" title="导入流程">
<div>
<el-upload
ref="uploadRef"
:action="importUrl"
:headers="uploadHeaders"
:drag="true"
:limit="1"
:multiple="true"
:show-file-list="true"
:disabled="uploadDisabled"
:on-exceed="handleExceed"
:on-success="handleFileSuccess"
:on-error="excelUploadError"
:auto-upload="false"
accept=".bpmn, .xml"
name="bpmnFile"
:data="importForm"
>
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
<div class="el-upload__text"> 将文件拖到此处 <em>点击上传</em> </div>
<template #tip>
<div class="el-upload__tip" style="color: red">
提示仅允许导入bpmxml格式文件
</div>
<div>
<el-form
ref="importFormRef"
:model="importForm"
:rules="rules"
label-width="120px"
status-icon
>
<el-form-item label="流程标识" prop="key">
<el-input
v-model="importForm.key"
placeholder="请输入流标标识"
style="width: 250px"
/>
</el-form-item>
<el-form-item label="流程名称" prop="name">
<el-input v-model="importForm.name" placeholder="请输入流程名称" clearable />
</el-form-item>
<el-form-item label="流程描述" prop="description">
<el-input type="textarea" v-model="importForm.description" clearable />
</el-form-item>
</el-form>
</div>
</template> </template>
</el-upload>
</div>
<template #footer>
<!-- 按钮保存 -->
<XButton
type="warning"
preIcon="ep:upload-filled"
:title="t('action.save')"
@click="submitFileForm"
/>
<XButton title="取 消" @click="uploadClose" />
</template>
</XModal>
</ContentWrap>
</template>
<script setup lang="ts">
// import
import { onMounted, ref, unref } from 'vue'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import { FormInstance, UploadInstance } from 'element-plus'
// import
import { getAccessToken, getTenantId } from '@/utils/auth'
import * as FormApi from '@/api/bpm/form'
import * as ModelApi from '@/api/bpm/model'
import { allSchemas, rules } from './model.data'
const { t } = useI18n() //
const message = useMessage() //
const router = useRouter() //
// ========== ==========
const [registerTable, { reload }] = useXTable({
allSchemas: allSchemas,
getListApi: ModelApi.getModelPageApi
})
const forms = ref() //
//
const handleDesign = (row) => {
console.log(row, '设计流程')
router.push({
name: 'modelEditor',
query: {
modelId: row.id
}
})
}
//
const handleDefinitionList = (row) => {
router.push({
name: 'BpmProcessDefinitionList',
query: {
modelId: row.id
}
})
}
//
const handleFormDetail = (row) => {
// TODO
console.log(row)
message.success('动态表单开发中,预计 2 月底完成')
}
//
const handleBpmnDetail = (row) => {
// TODO
console.log(row)
message.success('流程组件开发中,预计 2 月底完成')
}
//
const handleAssignRule = (row) => {
router.push({
name: 'BpmTaskAssignRuleList',
query: {
modelId: row.id
}
})
}
// ========== / ==========
const dialogVisible = ref(false)
const dialogTitle = ref('新建模型')
const dialogLoading = ref(false)
const saveForm = ref({})
const saveFormRef = ref<FormInstance>()
//
const setDialogTile = async (type: string) => {
dialogTitle.value = t('action.' + type)
dialogVisible.value = true
}
//
const handleCreate = async () => {
resetForm()
await setDialogTile('create')
}
//
const handleUpdate = async (rowId: number) => {
resetForm()
await setDialogTile('create')
//
saveForm.value = await ModelApi.getModelApi(rowId)
}
//
const submitForm = async () => {
//
const elForm = unref(saveFormRef)
if (!elForm) return
const valid = await elForm.validate()
if (!valid) return
//
dialogLoading.value = true
try {
const data = saveForm.value as ModelApi.ModelVO
if (!data.id) {
await ModelApi.createModelApi(data)
message.success(t('common.createSuccess'))
} else {
await ModelApi.updateModelApi(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally {
//
await reload()
dialogLoading.value = false
}
}
//
const resetForm = () => {
saveForm.value = {
formType: 10,
name: '',
courseSort: '',
description: '',
formId: '',
formCustomCreatePath: '',
formCustomViewPath: ''
}
saveFormRef.value?.resetFields()
}
// ========== / / ==========
//
const handleDelete = (rowId) => {
message.delConfirm('是否删除该流程!!').then(async () => {
await ModelApi.deleteModelApi(rowId)
message.success(t('common.delSuccess'))
//
reload()
})
}
//
const handleChangeState = (row) => {
const id = row.id
const state = row.processDefinition.suspensionState
const statusState = state === 1 ? '激活' : '挂起'
const content = '是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?'
message
.confirm(content)
.then(async () => {
await ModelApi.updateModelStateApi(id, state)
message.success(t('部署成功'))
//
reload()
})
.catch(() => {
//
row.processDefinition.suspensionState = state === 1 ? 2 : 1
})
}
//
const handleDeploy = (row) => {
message.confirm('是否部署该流程!!').then(async () => {
await ModelApi.deployModelApi(row.id)
message.success(t('部署成功'))
//
reload()
})
}
// ========== ==========
const uploadRef = ref<UploadInstance>()
let importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/bpm/model/import'
const uploadHeaders = ref()
const importDialogVisible = ref(false)
const uploadDisabled = ref(false)
const importFormRef = ref<FormInstance>()
const importForm = ref({
key: '',
name: '',
description: ''
})
//
const handleImport = () => {
importDialogVisible.value = true
}
//
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
//
const excelUploadError = (): void => {
message.error('导入流程失败,请您重新上传!')
}
//
const submitFileForm = () => {
uploadHeaders.value = {
Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId()
}
uploadDisabled.value = true
uploadRef.value!.submit()
}
//
const handleFileSuccess = async (response: any): Promise<void> => {
if (response.code !== 0) {
message.error(response.msg)
return
}
//
uploadClose()
//
message.success('导入流程成功!请点击【设计流程】按钮,进行编辑保存后,才可以进行【发布流程】')
await reload()
}
//
const uploadClose = () => {
//
importDialogVisible.value = false
//
uploadDisabled.value = false
uploadRef.value!.clearFiles()
//
importForm.value = {
key: '',
name: '',
description: ''
}
importFormRef.value?.resetFields()
}
// ========== ==========
onMounted(() => {
//
FormApi.getSimpleFormsApi().then((data) => {
forms.value = data
})
})
</script>

View File

@ -1,78 +1,105 @@
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas' import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
import { DICT_TYPE } from '@/utils/dict'
const { t } = useI18n() // 国际化 const { t } = useI18n() // 国际化
// 表单校验 // 表单校验
export const rules = reactive({ export const rules = reactive({
name: [required] key: [required],
name: [required],
category: [required],
formType: [required],
formId: [required],
formCustomCreatePath: [required],
formCustomViewPath: [required]
}) })
// CrudSchema // CrudSchema
const crudSchemas = reactive<CrudSchema[]>([ const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'key',
primaryType: null,
action: true,
actionWidth: '540px',
columns: [
{ {
label: t('common.index'), title: '流程标识',
field: 'id',
type: 'index',
form: {
show: false
},
detail: {
show: false
}
},
{
label: '流程标识',
field: 'key', field: 'key',
search: { isSearch: true,
show: true table: {
width: 120
} }
}, },
{ {
label: '流程名称', title: '流程名称',
field: 'name', field: 'name',
search: { isSearch: true,
show: true table: {
width: 120,
slots: {
default: 'name_default'
}
} }
}, },
{ {
label: '流程分类', title: '流程分类',
field: 'category', field: 'category',
dictType: DICT_TYPE.BPM_MODEL_CATEGORY, dictType: DICT_TYPE.BPM_MODEL_CATEGORY,
dictClass: 'number', dictClass: 'number',
search: { isSearch: true
show: true },
{
title: '表单信息',
field: 'formId',
table: {
width: 120,
slots: {
default: 'formId_default'
}
} }
}, },
{ {
label: '表单信息', title: '最新部署的流程定义',
field: 'formId'
},
{
label: '最新部署的流程定义',
field: 'processDefinition', field: 'processDefinition',
form: { isForm: false,
show: false table: {
children: [
{
title: '流程版本',
field: 'version',
slots: {
default: 'version_default'
}, },
detail: { width: 80
show: false },
{
title: '激活状态',
field: 'status',
slots: {
default: 'status_default'
},
width: 80
},
{
title: '部署时间',
field: 'processDefinition.deploymentTime',
formatter: 'formatDate',
width: 180
}
]
} }
}, },
{ {
label: t('common.createTime'), title: t('common.createTime'),
field: 'createTime', field: 'createTime',
form: { isForm: false,
show: false formatter: 'formatDate',
} table: {
}, width: 180
{
label: t('table.action'),
field: 'action',
width: '240px',
form: {
show: false
},
detail: {
show: false
} }
} }
]) ]
export const { allSchemas } = useCrudSchemas(crudSchemas) })
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)