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 | <script lang="ts" setup> | 1 | <script lang="ts" setup> | 
| 2 | + import { ControlComponentValue } from './control.config'; | ||
| 3 | + | ||
| 2 | const props = defineProps<{ | 4 | const props = defineProps<{ | 
| 3 | - value?: boolean; | 5 | + value?: ControlComponentValue; | 
| 4 | }>(); | 6 | }>(); | 
| 5 | 7 | ||
| 6 | const emit = defineEmits(['update:value', 'change']); | 8 | const emit = defineEmits(['update:value', 'change']); | 
| @@ -14,7 +16,12 @@ | @@ -14,7 +16,12 @@ | ||
| 14 | 16 | ||
| 15 | <template> | 17 | <template> | 
| 16 | <label class="sliding-switch"> | 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 | <span class="slider"></span> | 25 | <span class="slider"></span> | 
| 19 | <span class="on">ON</span> | 26 | <span class="on">ON</span> | 
| 20 | <span class="off">OFF</span> | 27 | <span class="off">OFF</span> | 
| @@ -27,10 +27,10 @@ | @@ -27,10 +27,10 @@ | ||
| 27 | <div class="flex items-center w-full h-full p-4"> | 27 | <div class="flex items-center w-full h-full p-4"> | 
| 28 | <div class="flex-auto flex truncate"> | 28 | <div class="flex-auto flex truncate"> | 
| 29 | <SvgIcon | 29 | <SvgIcon | 
| 30 | - :name="props.value?.icon!" | 30 | + :name="props.value?.icon! || ControlComponentDefaultConfig.icon!" | 
| 31 | prefix="iconfont" | 31 | prefix="iconfont" | 
| 32 | :style="{ | 32 | :style="{ | 
| 33 | - color: props.value?.iconColor, | 33 | + color: props.value?.iconColor || ControlComponentDefaultConfig.iconColor, | 
| 34 | width: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }), | 34 | width: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }), | 
| 35 | height: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }), | 35 | height: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }), | 
| 36 | }" | 36 | }" | 
| 1 | <script lang="ts" setup> | 1 | <script lang="ts" setup> | 
| 2 | import { computed } from '@vue/reactivity'; | 2 | import { computed } from '@vue/reactivity'; | 
| 3 | import { DEFAULT_RADIO_RECORD, fontSize, RadioRecord } from '../../detail/config/util'; | 3 | import { DEFAULT_RADIO_RECORD, fontSize, RadioRecord } from '../../detail/config/util'; | 
| 4 | + import { ControlComponentValue } from './control.config'; | ||
| 4 | 5 | ||
| 5 | const props = defineProps<{ | 6 | const props = defineProps<{ | 
| 6 | - value?: boolean; | 7 | + value?: ControlComponentValue; | 
| 7 | layout?: Recordable; | 8 | layout?: Recordable; | 
| 8 | radio?: RadioRecord; | 9 | radio?: RadioRecord; | 
| 9 | }>(); | 10 | }>(); | 
| @@ -30,7 +31,12 @@ | @@ -30,7 +31,12 @@ | ||
| 30 | }" | 31 | }" | 
| 31 | > | 32 | > | 
| 32 | <label class="switch"> | 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 | <div class="button"> | 40 | <div class="button"> | 
| 35 | <div class="light"></div> | 41 | <div class="light"></div> | 
| 36 | <div class="dots"></div> | 42 | <div class="dots"></div> | 
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | import { FormActionType, useForm } from '/@/components/Form'; | 4 | import { FormActionType, useForm } from '/@/components/Form'; | 
| 5 | import { basicSchema } from '../config/basicConfiguration'; | 5 | import { basicSchema } from '../config/basicConfiguration'; | 
| 6 | import BasicForm from '/@/components/Form/src/BasicForm.vue'; | 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 | import VisualOptionsModal from './VisualOptionsModal.vue'; | 8 | import VisualOptionsModal from './VisualOptionsModal.vue'; | 
| 9 | import { useModal } from '/@/components/Modal'; | 9 | import { useModal } from '/@/components/Modal'; | 
| 10 | import { buildUUID } from '/@/utils/uuid'; | 10 | import { buildUUID } from '/@/utils/uuid'; | 
| @@ -12,8 +12,7 @@ | @@ -12,8 +12,7 @@ | ||
| 12 | import { useMessage } from '/@/hooks/web/useMessage'; | 12 | import { useMessage } from '/@/hooks/web/useMessage'; | 
| 13 | import { DataBoardLayoutInfo } from '../../types/type'; | 13 | import { DataBoardLayoutInfo } from '../../types/type'; | 
| 14 | import { FrontComponent } from '../../components/help'; | 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 | type DataSourceFormEL = { [key: string]: Nullable<FormActionType> }; | 17 | type DataSourceFormEL = { [key: string]: Nullable<FormActionType> }; | 
| 19 | 18 | ||
| @@ -21,7 +20,7 @@ | @@ -21,7 +20,7 @@ | ||
| 21 | 20 | ||
| 22 | const props = defineProps<{ | 21 | const props = defineProps<{ | 
| 23 | record: DataBoardLayoutInfo; | 22 | record: DataBoardLayoutInfo; | 
| 24 | - frontId?: string; | 23 | + frontId?: FrontComponent; | 
| 25 | defaultConfig?: Partial<ComponentInfo>; | 24 | defaultConfig?: Partial<ComponentInfo>; | 
| 26 | }>(); | 25 | }>(); | 
| 27 | 26 | ||
| @@ -40,7 +39,7 @@ | @@ -40,7 +39,7 @@ | ||
| 40 | const dataSourceEl = shallowReactive<DataSourceFormEL>({} as unknown as DataSourceFormEL); | 39 | const dataSourceEl = shallowReactive<DataSourceFormEL>({} as unknown as DataSourceFormEL); | 
| 41 | 40 | ||
| 42 | const setFormEl = (el: any, id: string) => { | 41 | const setFormEl = (el: any, id: string) => { | 
| 43 | - if (!dataSourceEl[id] && el) { | 42 | + if (id && el) { | 
| 44 | const { formActionType } = el as unknown as { formActionType: FormActionType }; | 43 | const { formActionType } = el as unknown as { formActionType: FormActionType }; | 
| 45 | dataSourceEl[id] = formActionType; | 44 | dataSourceEl[id] = formActionType; | 
| 46 | } | 45 | } | 
| @@ -176,6 +175,10 @@ | @@ -176,6 +175,10 @@ | ||
| 176 | ~index && (unref(dataSource)[index].componentInfo = value); | 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 | defineExpose({ | 182 | defineExpose({ | 
| 180 | getAllDataSourceFieldValue, | 183 | getAllDataSourceFieldValue, | 
| 181 | validate, | 184 | validate, | 
| @@ -197,7 +200,8 @@ | @@ -197,7 +200,8 @@ | ||
| 197 | 选择设备 | 200 | 选择设备 | 
| 198 | </div> | 201 | </div> | 
| 199 | <div class="pl-2 flex-auto"> | 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 | </div> | 205 | </div> | 
| 202 | <div class="flex justify-center gap-3 w-24"> | 206 | <div class="flex justify-center gap-3 w-24"> | 
| 203 | <Tooltip title="复制"> | 207 | <Tooltip title="复制"> | 
| @@ -71,6 +71,7 @@ | @@ -71,6 +71,7 @@ | ||
| 71 | resetForm(); | 71 | resetForm(); | 
| 72 | } catch (error: unknown) { | 72 | } catch (error: unknown) { | 
| 73 | if (unref(activeKey) !== 'basicConfig') activeKey.value = 'basicConfig'; | 73 | if (unref(activeKey) !== 'basicConfig') activeKey.value = 'basicConfig'; | 
| 74 | + throw error; | ||
| 74 | } | 75 | } | 
| 75 | }; | 76 | }; | 
| 76 | 77 | 
| 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,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 | +]; | 
| @@ -185,10 +185,6 @@ | @@ -185,10 +185,6 @@ | ||
| 185 | openModal(true, { isEdit: false }); | 185 | openModal(true, { isEdit: false }); | 
| 186 | }; | 186 | }; | 
| 187 | 187 | ||
| 188 | - onMounted(() => { | ||
| 189 | - handleOpenCreatePanel(); | ||
| 190 | - }); | ||
| 191 | - | ||
| 192 | const getLayoutInfo = () => { | 188 | const getLayoutInfo = () => { | 
| 193 | return unref(dataBoardList).map((item) => { | 189 | return unref(dataBoardList).map((item) => { | 
| 194 | return { | 190 | return { |