提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<ContentWrap> |
|
3 |
<!-- 表单设计器 --> |
|
4 |
<FcDesigner ref="designer" height="780px"> |
|
5 |
<template #handle> |
|
6 |
<el-button round size="small" type="primary" @click="handleSave"> |
|
7 |
<Icon class="mr-5px" icon="ep:plus" /> |
|
8 |
保存 |
|
9 |
</el-button> |
|
10 |
</template> |
|
11 |
</FcDesigner> |
|
12 |
</ContentWrap> |
|
13 |
|
|
14 |
<!-- 表单保存的弹窗 --> |
|
15 |
<Dialog v-model="dialogVisible" title="保存表单" width="600"> |
|
16 |
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px"> |
|
17 |
<el-form-item label="表单名" prop="name"> |
|
18 |
<el-input v-model="formData.name" placeholder="请输入表单名" /> |
|
19 |
</el-form-item> |
|
20 |
<el-form-item label="状态" prop="status"> |
|
21 |
<el-radio-group v-model="formData.status"> |
|
22 |
<el-radio |
|
23 |
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" |
|
24 |
:key="dict.value" |
|
25 |
:label="dict.value" |
|
26 |
> |
|
27 |
{{ dict.label }} |
|
28 |
</el-radio> |
|
29 |
</el-radio-group> |
|
30 |
</el-form-item> |
|
31 |
<el-form-item label="备注" prop="remark"> |
|
32 |
<el-input v-model="formData.remark" placeholder="请输入备注" type="textarea" /> |
|
33 |
</el-form-item> |
|
34 |
</el-form> |
|
35 |
<template #footer> |
|
36 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
37 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
38 |
</template> |
|
39 |
</Dialog> |
|
40 |
</template> |
|
41 |
<script lang="ts" setup> |
|
42 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
43 |
import { CommonStatusEnum } from '@/utils/constants' |
|
44 |
import * as FormApi from '@/api/bpm/form' |
|
45 |
import FcDesigner from '@form-create/designer' |
|
46 |
import { encodeConf, encodeFields, setConfAndFields } from '@/utils/formCreate' |
|
47 |
import { useTagsViewStore } from '@/store/modules/tagsView' |
|
48 |
import { useFormCreateDesigner } from '@/components/FormCreate' |
|
49 |
|
|
50 |
defineOptions({ name: 'BpmFormEditor' }) |
|
51 |
|
|
52 |
const { t } = useI18n() // 国际化 |
|
53 |
const message = useMessage() // 消息 |
|
54 |
const { push, currentRoute } = useRouter() // 路由 |
|
55 |
const { query } = useRoute() // 路由信息 |
|
56 |
const { delView } = useTagsViewStore() // 视图操作 |
|
57 |
|
|
58 |
const designer = ref() // 表单设计器 |
|
59 |
useFormCreateDesigner(designer) // 表单设计器增强 |
|
60 |
const dialogVisible = ref(false) // 弹窗是否展示 |
|
61 |
const formLoading = ref(false) // 表单的加载中:提交的按钮禁用 |
|
62 |
const formData = ref({ |
|
63 |
name: '', |
|
64 |
status: CommonStatusEnum.ENABLE, |
|
65 |
remark: '' |
|
66 |
}) |
|
67 |
const formRules = reactive({ |
|
68 |
name: [{ required: true, message: '表单名不能为空', trigger: 'blur' }], |
|
69 |
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }] |
|
70 |
}) |
|
71 |
const formRef = ref() // 表单 Ref |
|
72 |
|
|
73 |
/** 处理保存按钮 */ |
|
74 |
const handleSave = () => { |
|
75 |
dialogVisible.value = true |
|
76 |
} |
|
77 |
|
|
78 |
/** 提交表单 */ |
|
79 |
const submitForm = async () => { |
|
80 |
// 校验表单 |
|
81 |
if (!formRef) return |
|
82 |
const valid = await formRef.value.validate() |
|
83 |
if (!valid) return |
|
84 |
// 提交请求 |
|
85 |
formLoading.value = true |
|
86 |
try { |
|
87 |
const data = formData.value as FormApi.FormVO |
|
88 |
data.conf = encodeConf(designer) // 表单配置 |
|
89 |
data.fields = encodeFields(designer) // 表单字段 |
|
90 |
if (!data.id) { |
|
91 |
await FormApi.createForm(data) |
|
92 |
message.success(t('common.createSuccess')) |
|
93 |
} else { |
|
94 |
await FormApi.updateForm(data) |
|
95 |
message.success(t('common.updateSuccess')) |
|
96 |
} |
|
97 |
dialogVisible.value = false |
|
98 |
close() |
|
99 |
} finally { |
|
100 |
formLoading.value = false |
|
101 |
} |
|
102 |
} |
|
103 |
/** 关闭按钮 */ |
|
104 |
const close = () => { |
|
105 |
delView(unref(currentRoute)) |
|
106 |
push('/bpm/manager/form') |
|
107 |
} |
|
108 |
|
|
109 |
/** 初始化 **/ |
|
110 |
onMounted(async () => { |
|
111 |
// 场景一:新增表单 |
|
112 |
const id = query.id as unknown as number |
|
113 |
if (!id) { |
|
114 |
return |
|
115 |
} |
|
116 |
// 场景二:修改表单 |
|
117 |
const data = await FormApi.getForm(id) |
|
118 |
formData.value = data |
|
119 |
setConfAndFields(designer, data.conf, data.fields) |
|
120 |
}) |
|
121 |
</script> |