|
@@ -1,36 +1,43 @@
|
|
|
-<script setup name="FormDesign">
|
|
|
-import FcDesigner from '@/components/FormCreateDesigner/FcDesigner.vue'
|
|
|
+<script setup>
|
|
|
+import { onMounted, ref } from 'vue'
|
|
|
+import { erFormEditor } from 'everright-formeditor'
|
|
|
+import 'Everright-formEditor/dist/style.css'
|
|
|
import useFlowStore from '@/store/modules/flow'
|
|
|
import { storeToRefs } from 'pinia'
|
|
|
-import { onMounted, ref } from 'vue'
|
|
|
-
|
|
|
const flowStore = useFlowStore()
|
|
|
const { processForm } = storeToRefs(flowStore)
|
|
|
-const designer = ref()
|
|
|
|
|
|
-const exportJsonEv = async json => {
|
|
|
- designer.value.saveAsForm()
|
|
|
+const EReditorRef = ref()
|
|
|
+
|
|
|
+const handleListener = obj => {
|
|
|
+ const { data } = obj
|
|
|
+ console.log(data, '....')
|
|
|
}
|
|
|
|
|
|
// 保存当前的表单数据
|
|
|
-const exportJson = async json => {
|
|
|
- processForm.value = JSON.stringify(json)
|
|
|
+const exportJsonEv = () => {
|
|
|
+ const formData = EReditorRef.value.getData()
|
|
|
+ processForm.value = JSON.stringify(formData)
|
|
|
+ debugger
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 1、拿到store中的值,然后循环判表单字段的Id是否唯一
|
|
|
- * 2、如果不唯一,提示用户需要重新填写表单字段Id
|
|
|
+ * 1、拿到store中的值,然后循环判表单字段的Key是否唯一
|
|
|
+ * 2、如果不唯一,提示用户需要重新填写表单字段Key
|
|
|
*/
|
|
|
const validateOnlyEv = () => {
|
|
|
+ console.log(processForm.value, '======')
|
|
|
+ if (processForm.value === '{}') return false
|
|
|
const finallyFormData = JSON.parse(processForm.value)
|
|
|
- const fields = finallyFormData.map(item => item.field)
|
|
|
+ const fields = finallyFormData.fields.map(item => item.key)
|
|
|
return fields.some((item, index) => fields.indexOf(item) !== index) // 如果发现重复项,返回true;否则,返回false
|
|
|
}
|
|
|
|
|
|
// 初始化的时候,渲染当前组件的值
|
|
|
onMounted(() => {
|
|
|
+ console.log('onMounted....')
|
|
|
if (processForm.value) {
|
|
|
- designer.value.initForm(processForm.value || [])
|
|
|
+ EReditorRef.value.setData(JSON.parse(processForm.value))
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -39,9 +46,6 @@ defineExpose({
|
|
|
validateOnlyEv
|
|
|
})
|
|
|
</script>
|
|
|
-
|
|
|
<template>
|
|
|
- <fc-designer ref="designer" @export-json="exportJson" />
|
|
|
+ <er-form-editor ref="EReditorRef" :is-show-i18n="false" @listener="handleListener" />
|
|
|
</template>
|
|
|
-
|
|
|
-<style scoped lang="scss"></style>
|