diff --git a/ui/src/components/dynamics-form/DemoConstructor.vue b/ui/src/components/dynamics-form/DemoConstructor.vue
index a575cbde7..aceecb503 100644
--- a/ui/src/components/dynamics-form/DemoConstructor.vue
+++ b/ui/src/components/dynamics-form/DemoConstructor.vue
@@ -21,8 +21,10 @@
:render_data="form_item_list"
ref="dynamicsFormRef"
>
-
+
+ 校验
+
diff --git a/ui/src/components/dynamics-form/FormItem.vue b/ui/src/components/dynamics-form/FormItem.vue
index 30b834848..fbf26b188 100644
--- a/ui/src/components/dynamics-form/FormItem.vue
+++ b/ui/src/components/dynamics-form/FormItem.vue
@@ -114,6 +114,7 @@ const errMsg = computed(() => {
const to_rule = (rule: any) => {
if (rule.validator) {
let validator = (rule: any, value: string, callback: any) => {}
+ eval(rule.validator)
return { ...rule, validator }
}
return rule
diff --git a/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue b/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue
index 5a7d442b6..e69ca2f66 100644
--- a/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue
+++ b/ui/src/components/dynamics-form/constructor/items/JsonInputConstructor.vue
@@ -5,15 +5,16 @@
prop="default_value"
:rules="[default_value_rule]"
>
-
+
diff --git a/ui/src/components/dynamics-form/items/JsonInput.vue b/ui/src/components/dynamics-form/items/JsonInput.vue
index e4bd6fa45..661feeff2 100644
--- a/ui/src/components/dynamics-form/items/JsonInput.vue
+++ b/ui/src/components/dynamics-form/items/JsonInput.vue
@@ -43,46 +43,76 @@ import { oneDark } from '@codemirror/theme-one-dark'
import { Codemirror } from 'vue-codemirror'
import { linter } from '@codemirror/lint'
import { computed, ref } from 'vue'
-const props = withDefaults(defineProps<{ modelValue?: string }>(), { modelValue: '{}' })
+const props = withDefaults(defineProps<{ modelValue?: any }>(), { modelValue: () => {} })
const emit = defineEmits(['update:modelValue'])
+
+const cache_model_value_str = ref()
+
const model_value = computed({
get: () => {
- if (!props.modelValue) {
- emit('update:modelValue', '{}')
+ if (cache_model_value_str.value) {
+ return cache_model_value_str.value
}
- return props.modelValue
+ return JSON.stringify(props.modelValue, null, 4)
},
set: (v: string) => {
if (!v) {
- emit('update:modelValue', '{}')
+ emit('update:modelValue', JSON.parse('{}'))
} else {
- emit('update:modelValue', v)
+ try {
+ cache_model_value_str.value = v
+ const result = JSON.parse(v)
+ emit('update:modelValue', result)
+ } catch (e) {}
}
}
})
const extensions = [json(), linter(jsonParseLinter()), oneDark]
+
const codemirrorStyle = {
height: '210px!important',
width: '100%'
}
+
// 弹出框相关代码
const dialogVisible = ref(false)
+
const cloneContent = ref('')
+
const openCodemirrorDialog = () => {
cloneContent.value = model_value.value
dialogVisible.value = true
}
+
const format = () => {
try {
const json_str = JSON.parse(model_value.value)
model_value.value = JSON.stringify(json_str, null, 4)
} catch (e) {}
}
+
function submitDialog() {
model_value.value = cloneContent.value
dialogVisible.value = false
}
+/**
+ * 校验格式
+ * @param rule
+ * @param value
+ * @param callback
+ */
+const validate_rules = (rule: any, value: any, callback: any) => {
+ if (model_value.value) {
+ try {
+ JSON.parse(model_value.value)
+ } catch (e) {
+ callback(new Error('JSON格式不正确'))
+ }
+ }
+}
+
+defineExpose({ validate_rules: validate_rules })