Commit 3742f3caa6d8a2e11add7bd14795598c6bc9c287
1 parent
7b53f85e
perf: data board component info modal add validate
Showing
4 changed files
with
29 additions
and
7 deletions
@@ -111,7 +111,6 @@ | @@ -111,7 +111,6 @@ | ||
111 | initChart(); | 111 | initChart(); |
112 | props.add && props.add(props.value.id, update); | 112 | props.add && props.add(props.value.id, update); |
113 | if (props.random) timeout = setInterval(handleRandomValue, 2000) as unknown as number; | 113 | if (props.random) timeout = setInterval(handleRandomValue, 2000) as unknown as number; |
114 | - console.log(unref(chartRef)); | ||
115 | }); | 114 | }); |
116 | 115 | ||
117 | onUnmounted(() => { | 116 | onUnmounted(() => { |
@@ -26,10 +26,6 @@ | @@ -26,10 +26,6 @@ | ||
26 | 26 | ||
27 | const { createMessage } = useMessage(); | 27 | const { createMessage } = useMessage(); |
28 | 28 | ||
29 | - // const componentRecord = reactive<DataBoardLayoutInfo>({ | ||
30 | - // ...props.record, | ||
31 | - // } as unknown as DataBoardLayoutInfo); | ||
32 | - | ||
33 | const dataSource = ref<DataSourceEl[]>([ | 29 | const dataSource = ref<DataSourceEl[]>([ |
34 | { id: buildUUID(), componentInfo: props.defaultConfig || {} } as unknown as DataSourceEl, | 30 | { id: buildUUID(), componentInfo: props.defaultConfig || {} } as unknown as DataSourceEl, |
35 | ]); | 31 | ]); |
@@ -49,6 +45,11 @@ | @@ -49,6 +45,11 @@ | ||
49 | } | 45 | } |
50 | }; | 46 | }; |
51 | 47 | ||
48 | + const validate = async () => { | ||
49 | + await basicMethod.validate(); | ||
50 | + await validateDataSourceField(); | ||
51 | + }; | ||
52 | + | ||
52 | const getAllDataSourceFieldValue = () => { | 53 | const getAllDataSourceFieldValue = () => { |
53 | const _dataSource = getDataSourceField(); | 54 | const _dataSource = getDataSourceField(); |
54 | const basicInfo = basicMethod.getFieldsValue(); | 55 | const basicInfo = basicMethod.getFieldsValue(); |
@@ -58,6 +59,16 @@ | @@ -58,6 +59,16 @@ | ||
58 | }; | 59 | }; |
59 | }; | 60 | }; |
60 | 61 | ||
62 | + const validateDataSourceField = async () => { | ||
63 | + const hasExistEl = Object.keys(dataSourceEl).filter((key) => dataSourceEl[key]); | ||
64 | + const _dataSource: boolean[] = []; | ||
65 | + for (const id of hasExistEl) { | ||
66 | + const flag = (await (dataSourceEl[id] as FormActionType).validate()) as boolean; | ||
67 | + _dataSource.push(flag); | ||
68 | + } | ||
69 | + return _dataSource; | ||
70 | + }; | ||
71 | + | ||
61 | const getDataSourceField = () => { | 72 | const getDataSourceField = () => { |
62 | const hasExistEl = Object.keys(dataSourceEl).filter((key) => dataSourceEl[key]); | 73 | const hasExistEl = Object.keys(dataSourceEl).filter((key) => dataSourceEl[key]); |
63 | const _dataSource: DataSource[] = []; | 74 | const _dataSource: DataSource[] = []; |
@@ -90,6 +101,7 @@ | @@ -90,6 +101,7 @@ | ||
90 | }); | 101 | }); |
91 | await nextTick(); | 102 | await nextTick(); |
92 | (dataSourceEl[copyRecordId] as FormActionType).setFieldsValue(value); | 103 | (dataSourceEl[copyRecordId] as FormActionType).setFieldsValue(value); |
104 | + (dataSourceEl[copyRecordId] as FormActionType).clearValidate(); | ||
93 | }; | 105 | }; |
94 | 106 | ||
95 | const [registerVisualOptionModal, { openModal }] = useModal(); | 107 | const [registerVisualOptionModal, { openModal }] = useModal(); |
@@ -128,6 +140,7 @@ | @@ -128,6 +140,7 @@ | ||
128 | 140 | ||
129 | const echoDataSource = () => { | 141 | const echoDataSource = () => { |
130 | basicMethod.setFieldsValue(props.record.record); | 142 | basicMethod.setFieldsValue(props.record.record); |
143 | + basicMethod.clearValidate(); | ||
131 | dataSource.value = []; | 144 | dataSource.value = []; |
132 | dataSource.value = props.record.record.dataSource.map((item) => { | 145 | dataSource.value = props.record.record.dataSource.map((item) => { |
133 | const id = buildUUID(); | 146 | const id = buildUUID(); |
@@ -139,6 +152,7 @@ | @@ -139,6 +152,7 @@ | ||
139 | 152 | ||
140 | nextTick(() => { | 153 | nextTick(() => { |
141 | (dataSourceEl[id] as FormActionType).setFieldsValue(item); | 154 | (dataSourceEl[id] as FormActionType).setFieldsValue(item); |
155 | + (dataSourceEl[id] as FormActionType).clearValidate(); | ||
142 | }); | 156 | }); |
143 | return { | 157 | return { |
144 | id, | 158 | id, |
@@ -165,6 +179,7 @@ | @@ -165,6 +179,7 @@ | ||
165 | 179 | ||
166 | defineExpose({ | 180 | defineExpose({ |
167 | getAllDataSourceFieldValue, | 181 | getAllDataSourceFieldValue, |
182 | + validate, | ||
168 | }); | 183 | }); |
169 | </script> | 184 | </script> |
170 | 185 |
@@ -44,6 +44,7 @@ | @@ -44,6 +44,7 @@ | ||
44 | 44 | ||
45 | const basicConfigurationEl = ref<{ | 45 | const basicConfigurationEl = ref<{ |
46 | getAllDataSourceFieldValue: Fn<any, Recordable>; | 46 | getAllDataSourceFieldValue: Fn<any, Recordable>; |
47 | + validate: Fn; | ||
47 | }>(); | 48 | }>(); |
48 | 49 | ||
49 | const resetForm = () => { | 50 | const resetForm = () => { |
@@ -53,8 +54,9 @@ | @@ -53,8 +54,9 @@ | ||
53 | componentDefaultConfig.value = {}; | 54 | componentDefaultConfig.value = {}; |
54 | }; | 55 | }; |
55 | 56 | ||
56 | - const handleSubmit = () => { | ||
57 | - const { getAllDataSourceFieldValue } = unref(basicConfigurationEl)!; | 57 | + const handleSubmit = async () => { |
58 | + const { getAllDataSourceFieldValue, validate } = unref(basicConfigurationEl)!; | ||
59 | + await validate(); | ||
58 | const value = getAllDataSourceFieldValue(); | 60 | const value = getAllDataSourceFieldValue(); |
59 | unref(isEdit) ? handleUpdateComponent(value) : handleAddComponent(value); | 61 | unref(isEdit) ? handleUpdateComponent(value) : handleAddComponent(value); |
60 | resetForm(); | 62 | resetForm(); |
@@ -32,6 +32,7 @@ export const basicSchema: FormSchema[] = [ | @@ -32,6 +32,7 @@ export const basicSchema: FormSchema[] = [ | ||
32 | field: BasicConfigField.NAME, | 32 | field: BasicConfigField.NAME, |
33 | label: '组件名称', | 33 | label: '组件名称', |
34 | component: 'Input', | 34 | component: 'Input', |
35 | + rules: [{ required: true, message: '组件名称为必填项' }], | ||
35 | componentProps: { | 36 | componentProps: { |
36 | placeholder: '请输入组件名称', | 37 | placeholder: '请输入组件名称', |
37 | }, | 38 | }, |
@@ -40,6 +41,7 @@ export const basicSchema: FormSchema[] = [ | @@ -40,6 +41,7 @@ export const basicSchema: FormSchema[] = [ | ||
40 | field: BasicConfigField.REMARK, | 41 | field: BasicConfigField.REMARK, |
41 | label: '组件备注', | 42 | label: '组件备注', |
42 | component: 'InputTextArea', | 43 | component: 'InputTextArea', |
44 | + // rules: [{ required: true, message: '组件备注为必填项' }], | ||
43 | componentProps: { | 45 | componentProps: { |
44 | placeholder: '请输入组件备注', | 46 | placeholder: '请输入组件备注', |
45 | }, | 47 | }, |
@@ -64,6 +66,7 @@ export const dataSourceSchema: FormSchema[] = [ | @@ -64,6 +66,7 @@ export const dataSourceSchema: FormSchema[] = [ | ||
64 | component: 'ApiTreeSelect', | 66 | component: 'ApiTreeSelect', |
65 | label: '组织', | 67 | label: '组织', |
66 | colProps: { span: 8 }, | 68 | colProps: { span: 8 }, |
69 | + rules: [{ required: true, message: '组织为必填项' }], | ||
67 | componentProps({ formActionType }) { | 70 | componentProps({ formActionType }) { |
68 | const { setFieldsValue } = formActionType; | 71 | const { setFieldsValue } = formActionType; |
69 | return { | 72 | return { |
@@ -90,6 +93,7 @@ export const dataSourceSchema: FormSchema[] = [ | @@ -90,6 +93,7 @@ export const dataSourceSchema: FormSchema[] = [ | ||
90 | component: 'ApiSelect', | 93 | component: 'ApiSelect', |
91 | label: '设备', | 94 | label: '设备', |
92 | colProps: { span: 8 }, | 95 | colProps: { span: 8 }, |
96 | + rules: [{ required: true, message: '设备名称为必填项' }], | ||
93 | componentProps({ formModel, formActionType }) { | 97 | componentProps({ formModel, formActionType }) { |
94 | const { setFieldsValue } = formActionType; | 98 | const { setFieldsValue } = formActionType; |
95 | const organizationId = formModel[DataSourceField.ORIGINATION_ID]; | 99 | const organizationId = formModel[DataSourceField.ORIGINATION_ID]; |
@@ -126,6 +130,7 @@ export const dataSourceSchema: FormSchema[] = [ | @@ -126,6 +130,7 @@ export const dataSourceSchema: FormSchema[] = [ | ||
126 | label: '网关子设备', | 130 | label: '网关子设备', |
127 | component: 'ApiSelect', | 131 | component: 'ApiSelect', |
128 | colProps: { span: 8 }, | 132 | colProps: { span: 8 }, |
133 | + rules: [{ required: true, message: '网关子设备为必填项' }], | ||
129 | ifShow({ model }) { | 134 | ifShow({ model }) { |
130 | return model[DataSourceField.IS_GATEWAY_DEVICE]; | 135 | return model[DataSourceField.IS_GATEWAY_DEVICE]; |
131 | }, | 136 | }, |
@@ -168,6 +173,7 @@ export const dataSourceSchema: FormSchema[] = [ | @@ -168,6 +173,7 @@ export const dataSourceSchema: FormSchema[] = [ | ||
168 | component: 'ApiSelect', | 173 | component: 'ApiSelect', |
169 | label: '属性', | 174 | label: '属性', |
170 | colProps: { span: 8 }, | 175 | colProps: { span: 8 }, |
176 | + rules: [{ required: true, message: '属性为必填项' }], | ||
171 | componentProps({ formModel }) { | 177 | componentProps({ formModel }) { |
172 | const organizationId = formModel[DataSourceField.ORIGINATION_ID]; | 178 | const organizationId = formModel[DataSourceField.ORIGINATION_ID]; |
173 | const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE]; | 179 | const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE]; |