|
@@ -1,18 +1,16 @@
|
|
|
<script setup>
|
|
|
-import { onMounted, ref } from 'vue'
|
|
|
+import { onBeforeUnmount, 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 { ElMessage } from 'element-plus'
|
|
|
const flowStore = useFlowStore()
|
|
|
const { processForm } = storeToRefs(flowStore)
|
|
|
|
|
|
const EReditorRef = ref()
|
|
|
|
|
|
-const handleListener = obj => {
|
|
|
- const { data } = obj
|
|
|
- console.log(data, '....')
|
|
|
-}
|
|
|
+const handleListener = obj => {}
|
|
|
|
|
|
// 保存当前的表单数据
|
|
|
const exportJsonEv = () => {
|
|
@@ -20,28 +18,26 @@ const exportJsonEv = () => {
|
|
|
processForm.value = JSON.stringify(formData)
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * 1、拿到store中的值,然后循环判表单字段的Key是否唯一
|
|
|
- * 2、如果不唯一,提示用户需要重新填写表单字段Key
|
|
|
- */
|
|
|
-const validateOnlyEv = () => {
|
|
|
- if (processForm.value === '{}') return false
|
|
|
- const finallyFormData = JSON.parse(processForm.value)
|
|
|
- const fields = finallyFormData.fields.map(item => item.key)
|
|
|
- return fields.some((item, index) => fields.indexOf(item) !== index) // 如果发现重复项,返回true;否则,返回false
|
|
|
-}
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ const formData = EReditorRef.value.getData()
|
|
|
+ if (formData.hasOwnProperty('fields')) {
|
|
|
+ // 离开前 做处理
|
|
|
+ // const { fields } = formData
|
|
|
+ // console.log(fields.length, '=======')
|
|
|
+ } else {
|
|
|
+ ElMessage.error(`表单设计有误,请重新配置`)
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
// 初始化的时候,渲染当前组件的值
|
|
|
onMounted(() => {
|
|
|
- console.log('onMounted....')
|
|
|
if (processForm.value) {
|
|
|
EReditorRef.value.setData(JSON.parse(processForm.value))
|
|
|
}
|
|
|
})
|
|
|
|
|
|
defineExpose({
|
|
|
- exportJsonEv,
|
|
|
- validateOnlyEv
|
|
|
+ exportJsonEv
|
|
|
})
|
|
|
</script>
|
|
|
<template>
|