Commit 376b1b075384b15acc9b166338f0b64193473c2e
1 parent
8ee7a7c4
fix: visual board dynamic data source can not get fields value
Showing
9 changed files
with
110 additions
and
16 deletions
| 1 | 1 | <script lang="ts" setup> |
| 2 | + import { ControlComponentValue } from './control.config'; | |
| 3 | + | |
| 2 | 4 | const props = defineProps<{ |
| 3 | - value?: boolean; | |
| 5 | + value?: ControlComponentValue; | |
| 4 | 6 | }>(); |
| 5 | 7 | |
| 6 | 8 | const emit = defineEmits(['update:value', 'change']); |
| ... | ... | @@ -14,7 +16,12 @@ |
| 14 | 16 | |
| 15 | 17 | <template> |
| 16 | 18 | <label class="sliding-switch"> |
| 17 | - <input :value="props.value" type="checkbox" :checked="props.value" @change="handleChange" /> | |
| 19 | + <input | |
| 20 | + :value="props.value?.value" | |
| 21 | + type="checkbox" | |
| 22 | + :checked="props.value?.value" | |
| 23 | + @change="handleChange" | |
| 24 | + /> | |
| 18 | 25 | <span class="slider"></span> |
| 19 | 26 | <span class="on">ON</span> |
| 20 | 27 | <span class="off">OFF</span> | ... | ... |
| ... | ... | @@ -27,10 +27,10 @@ |
| 27 | 27 | <div class="flex items-center w-full h-full p-4"> |
| 28 | 28 | <div class="flex-auto flex truncate"> |
| 29 | 29 | <SvgIcon |
| 30 | - :name="props.value?.icon!" | |
| 30 | + :name="props.value?.icon! || ControlComponentDefaultConfig.icon!" | |
| 31 | 31 | prefix="iconfont" |
| 32 | 32 | :style="{ |
| 33 | - color: props.value?.iconColor, | |
| 33 | + color: props.value?.iconColor || ControlComponentDefaultConfig.iconColor, | |
| 34 | 34 | width: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }), |
| 35 | 35 | height: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }), |
| 36 | 36 | }" | ... | ... |
| 1 | 1 | <script lang="ts" setup> |
| 2 | 2 | import { computed } from '@vue/reactivity'; |
| 3 | 3 | import { DEFAULT_RADIO_RECORD, fontSize, RadioRecord } from '../../detail/config/util'; |
| 4 | + import { ControlComponentValue } from './control.config'; | |
| 4 | 5 | |
| 5 | 6 | const props = defineProps<{ |
| 6 | - value?: boolean; | |
| 7 | + value?: ControlComponentValue; | |
| 7 | 8 | layout?: Recordable; |
| 8 | 9 | radio?: RadioRecord; |
| 9 | 10 | }>(); |
| ... | ... | @@ -30,7 +31,12 @@ |
| 30 | 31 | }" |
| 31 | 32 | > |
| 32 | 33 | <label class="switch"> |
| 33 | - <input :value="props.value" type="checkbox" :checked="props.value" @change="handleChange" /> | |
| 34 | + <input | |
| 35 | + :value="props.value?.value" | |
| 36 | + type="checkbox" | |
| 37 | + :checked="props.value?.value" | |
| 38 | + @change="handleChange" | |
| 39 | + /> | |
| 34 | 40 | <div class="button"> |
| 35 | 41 | <div class="light"></div> |
| 36 | 42 | <div class="dots"></div> | ... | ... |
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | import { FormActionType, useForm } from '/@/components/Form'; |
| 5 | 5 | import { basicSchema } from '../config/basicConfiguration'; |
| 6 | 6 | import BasicForm from '/@/components/Form/src/BasicForm.vue'; |
| 7 | - import { ref, shallowReactive, unref, nextTick, watch } from 'vue'; | |
| 7 | + import { ref, shallowReactive, unref, nextTick, watch, computed } from 'vue'; | |
| 8 | 8 | import VisualOptionsModal from './VisualOptionsModal.vue'; |
| 9 | 9 | import { useModal } from '/@/components/Modal'; |
| 10 | 10 | import { buildUUID } from '/@/utils/uuid'; |
| ... | ... | @@ -12,8 +12,7 @@ |
| 12 | 12 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 13 | 13 | import { DataBoardLayoutInfo } from '../../types/type'; |
| 14 | 14 | import { FrontComponent } from '../../components/help'; |
| 15 | - import { computed } from '@vue/reactivity'; | |
| 16 | - import BasicDataSourceForm from './DataSourceForm/BasicDataSourceForm.vue'; | |
| 15 | + import { getDataSourceComponent } from './DataSourceForm/help'; | |
| 17 | 16 | |
| 18 | 17 | type DataSourceFormEL = { [key: string]: Nullable<FormActionType> }; |
| 19 | 18 | |
| ... | ... | @@ -21,7 +20,7 @@ |
| 21 | 20 | |
| 22 | 21 | const props = defineProps<{ |
| 23 | 22 | record: DataBoardLayoutInfo; |
| 24 | - frontId?: string; | |
| 23 | + frontId?: FrontComponent; | |
| 25 | 24 | defaultConfig?: Partial<ComponentInfo>; |
| 26 | 25 | }>(); |
| 27 | 26 | |
| ... | ... | @@ -40,7 +39,7 @@ |
| 40 | 39 | const dataSourceEl = shallowReactive<DataSourceFormEL>({} as unknown as DataSourceFormEL); |
| 41 | 40 | |
| 42 | 41 | const setFormEl = (el: any, id: string) => { |
| 43 | - if (!dataSourceEl[id] && el) { | |
| 42 | + if (id && el) { | |
| 44 | 43 | const { formActionType } = el as unknown as { formActionType: FormActionType }; |
| 45 | 44 | dataSourceEl[id] = formActionType; |
| 46 | 45 | } |
| ... | ... | @@ -176,6 +175,10 @@ |
| 176 | 175 | ~index && (unref(dataSource)[index].componentInfo = value); |
| 177 | 176 | }; |
| 178 | 177 | |
| 178 | + const dataSourceComponent = computed(() => { | |
| 179 | + return getDataSourceComponent(props.frontId as FrontComponent); | |
| 180 | + }); | |
| 181 | + | |
| 179 | 182 | defineExpose({ |
| 180 | 183 | getAllDataSourceFieldValue, |
| 181 | 184 | validate, |
| ... | ... | @@ -197,7 +200,8 @@ |
| 197 | 200 | 选择设备 |
| 198 | 201 | </div> |
| 199 | 202 | <div class="pl-2 flex-auto"> |
| 200 | - <BasicDataSourceForm :ref="(el) => setFormEl(el, item.id)" /> | |
| 203 | + <!-- <BasicDataSourceForm /> --> | |
| 204 | + <component :is="dataSourceComponent" :ref="(el) => setFormEl(el, item.id)" /> | |
| 201 | 205 | </div> |
| 202 | 206 | <div class="flex justify-center gap-3 w-24"> |
| 203 | 207 | <Tooltip title="复制"> | ... | ... |
| 1 | +<script lang="ts" setup> | |
| 2 | + import { ref, unref } from 'vue'; | |
| 3 | + import { BasicForm, FormActionType } from '/@/components/Form'; | |
| 4 | + import { controlFormSchema } from '../../config/basicConfiguration'; | |
| 5 | + | |
| 6 | + const formEl = ref<Nullable<FormActionType>>(); | |
| 7 | + | |
| 8 | + const setFormEl = (el: any) => { | |
| 9 | + formEl.value = el; | |
| 10 | + }; | |
| 11 | + | |
| 12 | + const getFieldsValue = () => { | |
| 13 | + return unref(formEl)!.getFieldsValue(); | |
| 14 | + }; | |
| 15 | + | |
| 16 | + const validate = async () => { | |
| 17 | + await unref(formEl)!.validate(); | |
| 18 | + }; | |
| 19 | + | |
| 20 | + const setFieldsValue = async (record: Recordable) => { | |
| 21 | + await unref(formEl)!.setFieldsValue(record); | |
| 22 | + }; | |
| 23 | + | |
| 24 | + const clearValidate = async (name?: string | string[]) => { | |
| 25 | + await unref(formEl)!.clearValidate(name); | |
| 26 | + }; | |
| 27 | + defineExpose({ | |
| 28 | + formActionType: { getFieldsValue, validate, setFieldsValue, clearValidate }, | |
| 29 | + }); | |
| 30 | +</script> | |
| 31 | + | |
| 32 | +<template> | |
| 33 | + <div class="w-full flex-1"> | |
| 34 | + <BasicForm | |
| 35 | + :ref="(el) => setFormEl(el)" | |
| 36 | + :schemas="controlFormSchema" | |
| 37 | + class="w-full flex-1 data-source-form" | |
| 38 | + :show-action-button-group="false" | |
| 39 | + :row-props="{ | |
| 40 | + gutter: 10, | |
| 41 | + }" | |
| 42 | + layout="inline" | |
| 43 | + :label-col="{ span: 0 }" | |
| 44 | + /> | |
| 45 | + </div> | |
| 46 | +</template> | ... | ... |
| 1 | +import { Component } from 'vue'; | |
| 2 | +import { FrontComponent } from '../../../components/help'; | |
| 3 | +import BasicDataSourceForm from './BasicDataSourceForm.vue'; | |
| 4 | +import ControlDataSourceForm from './ControlDataSourceForm.vue'; | |
| 5 | + | |
| 6 | +const dataSourceComponentMap = new Map<FrontComponent, Component>(); | |
| 7 | + | |
| 8 | +dataSourceComponentMap.set(FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH, ControlDataSourceForm); | |
| 9 | + | |
| 10 | +export const getDataSourceComponent = (frontId: FrontComponent) => { | |
| 11 | + if (dataSourceComponentMap.has(frontId)) return dataSourceComponentMap.get(frontId)!; | |
| 12 | + return BasicDataSourceForm; | |
| 13 | +}; | ... | ... |
| ... | ... | @@ -217,3 +217,24 @@ export const dataSourceSchema: FormSchema[] = [ |
| 217 | 217 | }, |
| 218 | 218 | }, |
| 219 | 219 | ]; |
| 220 | + | |
| 221 | +export const controlFormSchema: FormSchema[] = [ | |
| 222 | + { | |
| 223 | + field: DataSourceField.DEVICE_RENAME, | |
| 224 | + component: 'Input', | |
| 225 | + label: '设备', | |
| 226 | + colProps: { span: 8 }, | |
| 227 | + componentProps: { | |
| 228 | + placeholder: '设备重命名', | |
| 229 | + }, | |
| 230 | + }, | |
| 231 | + { | |
| 232 | + field: DataSourceField.ATTRIBUTE_RENAME, | |
| 233 | + component: 'Input', | |
| 234 | + label: '属性', | |
| 235 | + colProps: { span: 8 }, | |
| 236 | + componentProps: { | |
| 237 | + placeholder: '属性重命名', | |
| 238 | + }, | |
| 239 | + }, | |
| 240 | +]; | ... | ... |