|
@@ -1,4 +1,4 @@
|
|
|
-<template>
|
|
|
|
|
|
|
+<template>
|
|
|
<el-col
|
|
<el-col
|
|
|
v-if="!schema?.hide && schema.valueType !== 'dependency'"
|
|
v-if="!schema?.hide && schema.valueType !== 'dependency'"
|
|
|
:span="componentProps?.span ?? 24"
|
|
:span="componentProps?.span ?? 24"
|
|
@@ -9,6 +9,7 @@
|
|
|
:label="schema?.label"
|
|
:label="schema?.label"
|
|
|
:label-width="schema.label ? (schema?.labelWidth ?? '50px') : '0px'"
|
|
:label-width="schema.label ? (schema?.labelWidth ?? '50px') : '0px'"
|
|
|
:label-position="schema?.labelPosition"
|
|
:label-position="schema?.labelPosition"
|
|
|
|
|
+ :rules="formItemRules"
|
|
|
>
|
|
>
|
|
|
<VariableBindWrapper
|
|
<VariableBindWrapper
|
|
|
v-model="value"
|
|
v-model="value"
|
|
@@ -279,6 +280,7 @@
|
|
|
<script setup lang="tsx">
|
|
<script setup lang="tsx">
|
|
|
import type { ComponentSchema } from '@/lvgl-widgets/type'
|
|
import type { ComponentSchema } from '@/lvgl-widgets/type'
|
|
|
import type { CollapseModelValue } from 'element-plus'
|
|
import type { CollapseModelValue } from 'element-plus'
|
|
|
|
|
+import type { FormItemRule } from 'element-plus'
|
|
|
|
|
|
|
|
import { computed, defineComponent, nextTick, ref } from 'vue'
|
|
import { computed, defineComponent, nextTick, ref } from 'vue'
|
|
|
import { get, set } from 'lodash-es'
|
|
import { get, set } from 'lodash-es'
|
|
@@ -312,6 +314,8 @@ import StyleOther from './components/StyleOther.vue'
|
|
|
import LanguageSelectModal from './components/LanguageSelectModal.vue'
|
|
import LanguageSelectModal from './components/LanguageSelectModal.vue'
|
|
|
import { LuLanguages } from 'vue-icons-plus/lu'
|
|
import { LuLanguages } from 'vue-icons-plus/lu'
|
|
|
import VariableBindWrapper from './components/VariableBindWrapper.vue'
|
|
import VariableBindWrapper from './components/VariableBindWrapper.vue'
|
|
|
|
|
+import { useAllWidgets } from '@/hooks/useAllWidgets'
|
|
|
|
|
+import { isDuplicateWidgetName } from '@/utils/widgetName'
|
|
|
|
|
|
|
|
defineOptions({
|
|
defineOptions({
|
|
|
name: 'CusFormItem'
|
|
name: 'CusFormItem'
|
|
@@ -330,6 +334,7 @@ const props = defineProps<{
|
|
|
}>()
|
|
}>()
|
|
|
const key = v4()
|
|
const key = v4()
|
|
|
const projectStore = useProjectStore()
|
|
const projectStore = useProjectStore()
|
|
|
|
|
+const { allWidgets } = useAllWidgets()
|
|
|
const textInputRef = ref()
|
|
const textInputRef = ref()
|
|
|
const languageModalRef = ref<InstanceType<typeof LanguageSelectModal>>()
|
|
const languageModalRef = ref<InstanceType<typeof LanguageSelectModal>>()
|
|
|
const textSelection = ref({
|
|
const textSelection = ref({
|
|
@@ -342,6 +347,36 @@ const componentProps = computed(() => {
|
|
|
})
|
|
})
|
|
|
const expandStyle = ref(true)
|
|
const expandStyle = ref(true)
|
|
|
|
|
|
|
|
|
|
+const formItemRules = computed<FormItemRule[]>(() => {
|
|
|
|
|
+ const rules = [...(props.schema.rules || [])]
|
|
|
|
|
+ const isWidgetNameField =
|
|
|
|
|
+ props.schema.field === 'name' && !!props.formData?.id && props.formData?.type !== 'page'
|
|
|
|
|
+
|
|
|
|
|
+ if (!isWidgetNameField) {
|
|
|
|
|
+ return rules
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ rules.unshift({
|
|
|
|
|
+ validator: (_rule, fieldValue, callback) => {
|
|
|
|
|
+ const nextName = String(fieldValue || '').trim()
|
|
|
|
|
+ if (!nextName) {
|
|
|
|
|
+ callback(new Error('请输入名称'))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isDuplicateWidgetName(allWidgets.value, nextName, props.formData?.id)) {
|
|
|
|
|
+ callback(new Error('名称重复'))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ callback()
|
|
|
|
|
+ },
|
|
|
|
|
+ trigger: ['blur', 'change']
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ return rules
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
// 绑定数据
|
|
// 绑定数据
|
|
|
const value = computed({
|
|
const value = computed({
|
|
|
get() {
|
|
get() {
|
|
@@ -526,3 +561,4 @@ const dependencyFormItems = computed(() => {
|
|
|
margin-bottom: 8px;
|
|
margin-bottom: 8px;
|
|
|
}
|
|
}
|
|
|
</style>
|
|
</style>
|
|
|
|
|
+
|