Răsfoiți Sursa

feat: 优化 表单设计 校验

lanceJiang 1 an în urmă
părinte
comite
ef7a84cba0
1 a modificat fișierele cu 13 adăugiri și 6 ștergeri
  1. 13 6
      src/views/flow/create/components/FormDesign.vue

+ 13 - 6
src/views/flow/create/components/FormDesign.vue

@@ -21,12 +21,19 @@ const exportJson = async json => {
  * 1、拿到store中的值,然后循环判表单字段的Id是否唯一
  * 2、如果不唯一,提示用户需要重新填写表单字段Id
  */
-const validateOnlyEv = () => {
-	const finallyFormData = JSON.parse(processForm.value)
-	const fields = finallyFormData.map(item => item.field)
-	return fields.some((item, index) => fields.indexOf(item) !== index) // 如果发现重复项,返回true;否则,返回false
+const validate = () => {
+  // 根据后续的业务需求 调整 validate 的功能
+	return new Promise((resolve, reject) => {
+		const finallyFormData = JSON.parse(processForm.value)
+		const fields = finallyFormData.map(item => item.field)
+		const bool = fields.length === [...new Set(fields)].length
+		;[bool ? resolve : reject]()
+		/*if (bool) {
+      resolve(true)
+    } else {
+    }*/
+	})
 }
-
 // 初始化的时候,渲染当前组件的值
 onMounted(() => {
 	if (processForm.value) {
@@ -36,7 +43,7 @@ onMounted(() => {
 
 defineExpose({
 	exportJsonEv,
-	validateOnlyEv
+	validate
 })
 </script>