bpm:完成流程表单

pull/2/head
YunaiV 2023-01-20 13:40:00 +08:00
parent a3f57a4424
commit fe6adf693b
7 changed files with 127 additions and 84 deletions

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.bpm.service.definition;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form.BpmFormCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form.BpmFormPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.form.BpmFormUpdateReqVO;
@ -107,17 +106,15 @@ public class BpmFormServiceImpl implements BpmFormService {
return null;
}
private void checkKeyNCName(String key) {
if (!ValidationUtils.isXmlNCName(key)) {
throw exception(MODEL_KEY_VALID);
}
}
/**
* Field field
*
* @param fields field
*/
private void checkFields(List<String> fields) {
if (true) { // TODO 芋艿:兼容 Vue3 工作流:因为采用了新的表单设计器,所以暂时不校验
return;
}
Map<String, String> fieldMap = new HashMap<>(); // key 是 vModelvalue 是 label
for (String field : fields) {
BpmFormFieldRespDTO fieldDTO = JsonUtils.parseObject(field, BpmFormFieldRespDTO.class);

View File

@ -1,5 +1,14 @@
import request from '@/config/axios'
import { FormVO } from './types'
export type FormVO = {
id: number
name: string
conf: string
fields: string[]
status: number
remark: string
createTime: string
}
// 创建工作流的表单定义
export const createFormApi = async (data: FormVO) => {

View File

@ -1,9 +0,0 @@
export type FormVO = {
id: number
name: string
conf: string
fields: string[]
status: number
remark: string
createTime: string
}

View File

@ -194,7 +194,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
noCache: true,
hidden: true,
canTo: true,
title: '流程表单',
title: '设计流程表单',
activeMenu: 'bpm/manager/form/formEditor'
}
},

View File

@ -0,0 +1,45 @@
/**
* https://github.com/xaboy/form-create-designer 封装的工具类
*/
// 编码表单 Conf
export const encodeConf = (designerRef: object) => {
// @ts-ignore
return JSON.stringify(designerRef.value.getOption())
}
// 编码表单 Fields
export const encodeFields = (designerRef: object) => {
// @ts-ignore
const rule = designerRef.value.getRule()
const fields: string[] = []
rule.forEach((item) => {
fields.push(JSON.stringify(item))
})
return fields
}
// 解码表单 Fields
export const decodeFields = (fields: string[]) => {
const rule: object[] = []
fields.forEach((item) => {
rule.push(JSON.parse(item))
})
return rule
}
// 设置表单的 Conf 和 Fields
export const setConfAndFields = (designerRef: object, conf: string, fields: string) => {
// @ts-ignore
designerRef.value.setOption(JSON.parse(conf))
// @ts-ignore
designerRef.value.setRule(decodeFields(fields))
}
// 设置表单的 Conf 和 Fields
export const setConfAndFields2 = (detailPreview: object, conf: string, fields: string) => {
// @ts-ignore
detailPreview.value.option = JSON.parse(conf)
// @ts-ignore
detailPreview.value.rule = decodeFields(fields)
}

View File

@ -8,7 +8,7 @@
</fc-designer>
<!-- 表单保存的弹窗 -->
<XModal v-model="dialogVisible" title="保存表单">
<el-form :model="formValues" :rules="formRules" label-width="80px">
<el-form ref="formRef" :model="formValues" :rules="formRules" label-width="80px">
<el-form-item label="表单名" prop="name">
<el-input v-model="formValues.name" placeholder="请输入表单名" />
</el-form-item>
@ -43,22 +43,26 @@
</ContentWrap>
</template>
<script setup lang="ts" name="BpmFormEditor">
import { reactive } from 'vue'
import { FormInstance } from 'element-plus'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { CommonStatusEnum } from '@/utils/constants'
import { reactive } from 'vue'
import * as FormApi from '@/api/bpm/form'
import { encodeConf, encodeFields, setConfAndFields } from '@/utils/formCreate'
const { t } = useI18n() //
// const message = useMessage() //
const message = useMessage() //
const { query } = useRoute() //
const designer = ref() //
const dialogVisible = ref(false)
const dialogLoading = ref(false)
const dialogVisible = ref(false) //
const dialogLoading = ref(false) //
const formRef = ref<FormInstance>()
const formRules = reactive({
name: [{ required: true, message: '表单名不能为空', trigger: 'blur' }],
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }]
})
const formValues = reactive({
const formValues = ref({
name: '',
status: CommonStatusEnum.ENABLE,
remark: ''
@ -71,9 +75,42 @@ const handleSave = () => {
//
const submitForm = async () => {
console.log('保存')
//
const elForm = unref(formRef)
if (!elForm) return
const valid = await elForm.validate()
if (!valid) return
//
dialogLoading.value = true
try {
const data = formValues.value as FormApi.FormVO
data.conf = encodeConf(designer) //
data.fields = encodeFields(designer) //
if (!data.id) {
await FormApi.createFormApi(data)
message.success(t('common.createSuccess'))
} else {
await FormApi.updateFormApi(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally {
dialogLoading.value = false
}
}
// formValue.value = designer.value.getOption()
// formValue.value = designer.value.getRule()
// ========== ==========
onMounted(() => {
//
const id = query.id as unknown as number
if (!id) {
return
}
//
FormApi.getFormApi(id).then((data) => {
formValues.value = data
setConfAndFields(designer, data.conf, data.fields)
})
})
</script>

View File

@ -37,12 +37,9 @@
/>
</template>
</XTable>
<!-- TODO 芋艿待完善 -->
<XModal v-model="detailOpen" width="400" title="表单详情">
<!-- <div class="test-form">
<parser :key="new Date().getTime()" :form-conf="detailForm" />
</div> -->
表单详情
<!-- 表单详情的弹窗 -->
<XModal v-model="detailOpen" width="800" title="表单详情">
<ViewForm :rule="detailPreview.rule" :option="detailPreview.option" v-if="detailOpen" />
</XModal>
</div>
</ContentWrap>
@ -50,21 +47,18 @@
<script setup lang="ts" name="BpmForm">
// import
// import { ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useXTable } from '@/hooks/web/useXTable'
// import { FormExpose } from '@/components/Form'
// import
import * as FormApi from '@/api/bpm/form'
import { allSchemas } from './form.data'
import { useRouter } from 'vue-router'
// import { decodeFields } from '@/utils/formGenerator' // TODO
const { t } = useI18n() //
const message = useMessage() //
const router = useRouter() //
// import
import viewForm from '@form-create/element-ui'
const ViewForm = viewForm.$form()
import { setConfAndFields2 } from '@/utils/formCreate'
//
const [registerTable, { deleteData }] = useXTable({
allSchemas: allSchemas,
@ -72,23 +66,6 @@ const [registerTable, { deleteData }] = useXTable({
deleteApi: FormApi.deleteFormApi
})
//
// const modelVisible = ref(false) //
// const modelTitle = ref('edit') //
// const modelLoading = ref(false) // loading
// const actionType = ref('') //
// const actionLoading = ref(false) // Loading
// const formRef = ref<FormExpose>() // Ref
// const detailData = ref() // Ref
//
// const setDialogTile = (type: string) => {
// modelLoading.value = true
// modelTitle.value = t('action.' + type)
// actionType.value = type
// modelVisible.value = true
// }
//
const handleCreate = () => {
router.push({
@ -98,38 +75,25 @@ const handleCreate = () => {
//
const handleUpdate = async (rowId: number) => {
console.log(rowId, '修改')
if (true) {
message.success('动态表单开发中,预计 2 月底完成')
return
}
await router.push({
path: '/bpm/manager/form/edit',
name: 'bpmFormEditor',
query: {
formId: rowId
id: rowId
}
})
}
// // TODO
// const detailForm = ref({
// fields: []
// })
//
// const detailOpen = ref(false)
//
const detailOpen = ref(false)
const detailPreview = ref({
rule: [],
option: {}
})
const handleDetail = async (rowId: number) => {
console.log(rowId, '详情')
message.success('动态表单开发中,预计 2 月底完成')
// FormApi.getFormApi(row.id).then((response) => {
// //
// const data = response.data
// detailForm.value = {
// ...JSON.parse(data.conf),
// fields: decodeFields([], data.fields)
// }
// //
// detailOpen.value = true
// })
//
const data = await FormApi.getFormApi(rowId)
setConfAndFields2(detailPreview, data.conf, data.fields)
//
detailOpen.value = true
}
</script>