提交 | 用户 | 时间
|
c9a6f7
|
1 |
<template> |
H |
2 |
<el-form ref="formRef" :model="modelData" :rules="rules" label-width="120px" class="mt-20px"> |
|
3 |
<el-form-item label="表单类型" prop="formType" class="mb-20px"> |
|
4 |
<el-radio-group v-model="modelData.formType"> |
|
5 |
<el-radio |
|
6 |
v-for="dict in getIntDictOptions(DICT_TYPE.BPM_MODEL_FORM_TYPE)" |
|
7 |
:key="dict.value" |
|
8 |
:value="dict.value" |
|
9 |
> |
|
10 |
{{ dict.label }} |
|
11 |
</el-radio> |
|
12 |
</el-radio-group> |
|
13 |
</el-form-item> |
|
14 |
<el-form-item v-if="modelData.formType === 10" label="流程表单" prop="formId"> |
|
15 |
<el-select v-model="modelData.formId" clearable style="width: 100%"> |
|
16 |
<el-option v-for="form in formList" :key="form.id" :label="form.name" :value="form.id" /> |
|
17 |
</el-select> |
|
18 |
</el-form-item> |
|
19 |
<el-form-item v-if="modelData.formType === 20" label="表单提交路由" prop="formCustomCreatePath"> |
|
20 |
<el-input |
|
21 |
v-model="modelData.formCustomCreatePath" |
|
22 |
placeholder="请输入表单提交路由" |
|
23 |
style="width: 330px" |
|
24 |
/> |
|
25 |
<el-tooltip |
|
26 |
class="item" |
|
27 |
content="自定义表单的提交路径,使用 Vue 的路由地址,例如说:bpm/oa/leave/create.vue" |
|
28 |
effect="light" |
|
29 |
placement="top" |
|
30 |
> |
|
31 |
<Icon icon="ep:question" class="ml-5px" /> |
|
32 |
</el-tooltip> |
|
33 |
</el-form-item> |
|
34 |
<el-form-item v-if="modelData.formType === 20" label="表单查看地址" prop="formCustomViewPath"> |
|
35 |
<el-input |
|
36 |
v-model="modelData.formCustomViewPath" |
|
37 |
placeholder="请输入表单查看的组件地址" |
|
38 |
style="width: 330px" |
|
39 |
/> |
|
40 |
<el-tooltip |
|
41 |
class="item" |
|
42 |
content="自定义表单的查看组件地址,使用 Vue 的组件地址,例如说:bpm/oa/leave/detail.vue" |
|
43 |
effect="light" |
|
44 |
placement="top" |
|
45 |
> |
|
46 |
<Icon icon="ep:question" class="ml-5px" /> |
|
47 |
</el-tooltip> |
|
48 |
</el-form-item> |
|
49 |
<!-- 表单预览 --> |
|
50 |
<div |
|
51 |
v-if="modelData.formType === 10 && modelData.formId && formPreview.rule.length > 0" |
|
52 |
class="mt-20px" |
|
53 |
> |
|
54 |
<div class="flex items-center mb-15px"> |
|
55 |
<div class="h-15px w-4px bg-[#1890ff] mr-10px"></div> |
|
56 |
<span class="text-15px font-bold">表单预览</span> |
|
57 |
</div> |
|
58 |
<form-create |
|
59 |
v-model="formPreview.formData" |
|
60 |
:rule="formPreview.rule" |
|
61 |
:option="formPreview.option" |
|
62 |
/> |
|
63 |
</div> |
|
64 |
</el-form> |
|
65 |
</template> |
|
66 |
|
|
67 |
<script lang="ts" setup> |
|
68 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
69 |
import * as FormApi from '@/api/bpm/form' |
|
70 |
import { setConfAndFields2 } from '@/utils/formCreate' |
|
71 |
|
|
72 |
const props = defineProps({ |
|
73 |
modelValue: { |
|
74 |
type: Object, |
|
75 |
required: true |
|
76 |
}, |
|
77 |
formList: { |
|
78 |
type: Array, |
|
79 |
required: true |
|
80 |
} |
|
81 |
}) |
|
82 |
|
|
83 |
const emit = defineEmits(['update:modelValue']) |
|
84 |
|
|
85 |
const formRef = ref() |
|
86 |
|
|
87 |
// 创建本地数据副本 |
|
88 |
const modelData = computed({ |
|
89 |
get: () => props.modelValue, |
|
90 |
set: (val) => emit('update:modelValue', val) |
|
91 |
}) |
|
92 |
|
|
93 |
// 表单预览数据 |
|
94 |
const formPreview = ref({ |
|
95 |
formData: {}, |
|
96 |
rule: [], |
|
97 |
option: { |
|
98 |
submitBtn: false, |
|
99 |
resetBtn: false, |
|
100 |
formData: {} |
|
101 |
} |
|
102 |
}) |
|
103 |
|
|
104 |
// 监听表单ID变化,加载表单数据 |
|
105 |
watch( |
|
106 |
() => modelData.value.formId, |
|
107 |
async (newFormId) => { |
|
108 |
if (newFormId && modelData.value.formType === 10) { |
|
109 |
const data = await FormApi.getForm(newFormId) |
|
110 |
setConfAndFields2(formPreview.value, data.conf, data.fields) |
|
111 |
// 设置只读 |
|
112 |
formPreview.value.rule.forEach((item: any) => { |
|
113 |
item.props = { ...item.props, disabled: true } |
|
114 |
}) |
|
115 |
} else { |
|
116 |
formPreview.value.rule = [] |
|
117 |
} |
|
118 |
}, |
|
119 |
{ immediate: true } |
|
120 |
) |
|
121 |
|
|
122 |
const rules = { |
|
123 |
formType: [{ required: true, message: '表单类型不能为空', trigger: 'blur' }], |
|
124 |
formId: [{ required: true, message: '流程表单不能为空', trigger: 'blur' }], |
|
125 |
formCustomCreatePath: [{ required: true, message: '表单提交路由不能为空', trigger: 'blur' }], |
|
126 |
formCustomViewPath: [{ required: true, message: '表单查看地址不能为空', trigger: 'blur' }] |
|
127 |
} |
|
128 |
|
|
129 |
/** 表单校验 */ |
|
130 |
const validate = async () => { |
|
131 |
await formRef.value?.validate() |
|
132 |
} |
|
133 |
|
|
134 |
defineExpose({ |
|
135 |
validate |
|
136 |
}) |
|
137 |
</script> |