Commit 0ee50e508d4bea2ae0c22c9d6809c605ea64aaac
Merge branch 'fix/DEFECT-1718' into 'main_dev'
模板和组态创建添加字段 See merge request yunteng/thingskit-front!975
Showing
5 changed files
with
59 additions
and
39 deletions
@@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
26 | v-if="model['templateId']" | 26 | v-if="model['templateId']" |
27 | ref="selectDeviceProfileRef" | 27 | ref="selectDeviceProfileRef" |
28 | :selectOptions="selectOptions" | 28 | :selectOptions="selectOptions" |
29 | - :organizationId="model['organizationId']" | 29 | + :organizationId="model?.['organizationId']" |
30 | /> | 30 | /> |
31 | </template> | 31 | </template> |
32 | </BasicForm> | 32 | </BasicForm> |
@@ -71,12 +71,21 @@ | @@ -71,12 +71,21 @@ | ||
71 | }); | 71 | }); |
72 | await updateSchema({ | 72 | await updateSchema({ |
73 | field: 'enableTemplate', | 73 | field: 'enableTemplate', |
74 | - componentProps: { | ||
75 | - disabled, | ||
76 | - checkedValue: 1, | ||
77 | - unCheckedValue: 0, | ||
78 | - checkedChildren: '开', | ||
79 | - unCheckedChildren: '关', | 74 | + componentProps: ({ formActionType }) => { |
75 | + return { | ||
76 | + disabled, | ||
77 | + checkedValue: 1, | ||
78 | + unCheckedValue: 0, | ||
79 | + checkedChildren: '开', | ||
80 | + unCheckedChildren: '关', | ||
81 | + onChange: () => { | ||
82 | + formActionType.setFieldsValue({ | ||
83 | + productIds: [], | ||
84 | + templateId: null, | ||
85 | + productId: undefined, | ||
86 | + }); | ||
87 | + }, | ||
88 | + }; | ||
80 | }, | 89 | }, |
81 | }); | 90 | }); |
82 | }; | 91 | }; |
@@ -139,20 +148,24 @@ | @@ -139,20 +148,24 @@ | ||
139 | value: item.id, | 148 | value: item.id, |
140 | })); | 149 | })); |
141 | }; | 150 | }; |
142 | - | ||
143 | const selectOptions: Ref<any[]> = ref([]); | 151 | const selectOptions: Ref<any[]> = ref([]); |
144 | 152 | ||
145 | const handleTemplateChange = async (_, option) => { | 153 | const handleTemplateChange = async (_, option) => { |
146 | const { productAndDevice } = option; | 154 | const { productAndDevice } = option; |
147 | - if (!productAndDevice) return; | ||
148 | - selectOptions.value = productAndDevice.map((item) => ({ | ||
149 | - label: item.name, | ||
150 | - value: item.profileId, | ||
151 | - })); | 155 | + // if (!productAndDevice) return; |
156 | + // selectOptions.value = productAndDevice?.map((item) => ({ | ||
157 | + // label: item.profileName || item.name, | ||
158 | + // value: item.profileId, | ||
159 | + // })); | ||
152 | await nextTick(); | 160 | await nextTick(); |
153 | // 赋值 | 161 | // 赋值 |
154 | selectDeviceProfileRef.value?.setFieldsValue( | 162 | selectDeviceProfileRef.value?.setFieldsValue( |
155 | - productAndDevice.map((item) => ({ label: item.name, value: item.profileId })) | 163 | + productAndDevice?.map((item) => ({ |
164 | + label: item.profileName || item.name, | ||
165 | + value: item.profileId, | ||
166 | + transportType: item?.transportType, | ||
167 | + deviceType: item?.deviceType, | ||
168 | + })) | ||
156 | ); | 169 | ); |
157 | }; | 170 | }; |
158 | // | 171 | // |
@@ -170,7 +183,12 @@ | @@ -170,7 +183,12 @@ | ||
170 | const getCurrentAllProduct = async (products: string[]) => { | 183 | const getCurrentAllProduct = async (products: string[]) => { |
171 | const resp = (await getDeviceProfile()) as any; | 184 | const resp = (await getDeviceProfile()) as any; |
172 | if (!resp) return; | 185 | if (!resp) return; |
173 | - const values = resp?.map((item) => ({ name: item.name, profileId: item.id })); | 186 | + const values = resp?.map((item) => ({ |
187 | + name: item.name, | ||
188 | + profileId: item.id, | ||
189 | + deviceType: item.deviceType, | ||
190 | + transportType: item.transportType, | ||
191 | + })); | ||
174 | return values.filter((item) => products?.includes(item.profileId)); | 192 | return values.filter((item) => products?.includes(item.profileId)); |
175 | }; | 193 | }; |
176 | 194 |
@@ -152,14 +152,17 @@ export const formSchema: FormSchema[] = [ | @@ -152,14 +152,17 @@ export const formSchema: FormSchema[] = [ | ||
152 | defaultValue: 0, | 152 | defaultValue: 0, |
153 | componentProps: ({ formActionType }) => { | 153 | componentProps: ({ formActionType }) => { |
154 | const { setFieldsValue } = formActionType; | 154 | const { setFieldsValue } = formActionType; |
155 | + | ||
155 | return { | 156 | return { |
156 | checkedValue: 1, | 157 | checkedValue: 1, |
157 | unCheckedValue: 0, | 158 | unCheckedValue: 0, |
158 | checkedChildren: '开', | 159 | checkedChildren: '开', |
159 | unCheckedChildren: '关', | 160 | unCheckedChildren: '关', |
160 | - onChange() { | 161 | + onChange: () => { |
161 | setFieldsValue({ | 162 | setFieldsValue({ |
162 | productIds: [], | 163 | productIds: [], |
164 | + templateId: null, | ||
165 | + productId: undefined, | ||
163 | }); | 166 | }); |
164 | }, | 167 | }, |
165 | }; | 168 | }; |
@@ -180,6 +183,7 @@ export const formSchema: FormSchema[] = [ | @@ -180,6 +183,7 @@ export const formSchema: FormSchema[] = [ | ||
180 | field: 'templateId', //暂且使用插槽形式 | 183 | field: 'templateId', //暂且使用插槽形式 |
181 | label: '模板', | 184 | label: '模板', |
182 | component: 'Input', | 185 | component: 'Input', |
186 | + required: true, | ||
183 | slot: 'templateId', | 187 | slot: 'templateId', |
184 | colProps: { span: 24 }, | 188 | colProps: { span: 24 }, |
185 | ifShow: ({ values }) => values['enableTemplate'] === 1, | 189 | ifShow: ({ values }) => values['enableTemplate'] === 1, |
@@ -193,14 +197,6 @@ export const formSchema: FormSchema[] = [ | @@ -193,14 +197,6 @@ export const formSchema: FormSchema[] = [ | ||
193 | ifShow: ({ values }) => values['enableTemplate'] === 1 && values['templateId'], | 197 | ifShow: ({ values }) => values['enableTemplate'] === 1 && values['templateId'], |
194 | }, | 198 | }, |
195 | { | 199 | { |
196 | - field: 'deviceIds', //暂且使用插槽形式 | ||
197 | - label: '设备', | ||
198 | - component: 'Input', | ||
199 | - slot: 'deviceIds', | ||
200 | - colProps: { span: 24 }, | ||
201 | - ifShow: ({ values }) => values['enableTemplate'] === 1 && values['templateId'], | ||
202 | - }, | ||
203 | - { | ||
204 | field: 'productId', | 200 | field: 'productId', |
205 | label: '产品', | 201 | label: '产品', |
206 | component: 'ApiSelect', | 202 | component: 'ApiSelect', |
@@ -53,6 +53,8 @@ | @@ -53,6 +53,8 @@ | ||
53 | dynamicInput.params.push({ | 53 | dynamicInput.params.push({ |
54 | name: props.value.label, | 54 | name: props.value.label, |
55 | profileId: props.value.value, | 55 | profileId: props.value.value, |
56 | + deviceType: props.value?.deviceType, | ||
57 | + transportType: props.value?.transportType, | ||
56 | deviceList: props.value.deviceList?.filter(Boolean)?.map((item) => item.deviceId), | 58 | deviceList: props.value.deviceList?.filter(Boolean)?.map((item) => item.deviceId), |
57 | }); | 59 | }); |
58 | } | 60 | } |
@@ -67,17 +69,20 @@ | @@ -67,17 +69,20 @@ | ||
67 | 69 | ||
68 | //chang改变 | 70 | //chang改变 |
69 | const emitChange = () => { | 71 | const emitChange = () => { |
70 | - const findDeviceDict = selectOptions.value.map((item) => { | ||
71 | - if (dynamicInput.params[0].deviceList?.includes(item.value)) { | ||
72 | - return { | ||
73 | - name: item.label, | ||
74 | - deviceId: item.value, | ||
75 | - }; | ||
76 | - } | 72 | + const tempDeviceList: Recordable[] = []; // fix: 修改选择设备顺序问题 |
73 | + dynamicInput.params[0].deviceList?.forEach((item) => { | ||
74 | + selectOptions.value?.forEach((newItem) => { | ||
75 | + if (item === newItem.value) { | ||
76 | + tempDeviceList.push({ | ||
77 | + name: newItem.label, | ||
78 | + deviceId: newItem.value, | ||
79 | + }); | ||
80 | + } | ||
81 | + }); | ||
77 | }); | 82 | }); |
78 | return { | 83 | return { |
79 | ...dynamicInput.params[0], | 84 | ...dynamicInput.params[0], |
80 | - deviceList: findDeviceDict.filter(Boolean), | 85 | + deviceList: tempDeviceList.filter(Boolean), // 过滤假值 |
81 | }; | 86 | }; |
82 | }; | 87 | }; |
83 | defineExpose({ | 88 | defineExpose({ |
@@ -56,12 +56,8 @@ | @@ -56,12 +56,8 @@ | ||
56 | 56 | ||
57 | const setFieldsValue = async (productIds) => { | 57 | const setFieldsValue = async (productIds) => { |
58 | await nextTick(); | 58 | await nextTick(); |
59 | - if (!productIds && !productIds.length) { | ||
60 | - return; | ||
61 | - } | ||
62 | - selectValue.value = productIds; | ||
63 | - | ||
64 | - profileList.value = productIds; | 59 | + selectValue.value = productIds || []; |
60 | + profileList.value = productIds || []; | ||
65 | }; | 61 | }; |
66 | 62 | ||
67 | const setValue = (value: any) => { | 63 | const setValue = (value: any) => { |
@@ -71,7 +71,12 @@ | @@ -71,7 +71,12 @@ | ||
71 | const getCurrentAllProduct = async (products: string[]) => { | 71 | const getCurrentAllProduct = async (products: string[]) => { |
72 | const resp = (await getDeviceProfile()) as any; | 72 | const resp = (await getDeviceProfile()) as any; |
73 | if (!resp) return; | 73 | if (!resp) return; |
74 | - const values = resp.map((item) => ({ name: item.name, profileId: item.id })); | 74 | + const values = resp.map((item) => ({ |
75 | + name: item.name, | ||
76 | + profileId: item.id, | ||
77 | + deviceType: item.deviceType, | ||
78 | + transportType: item.transportType, | ||
79 | + })); | ||
75 | return values.filter((item) => products.includes(item.profileId)); | 80 | return values.filter((item) => products.includes(item.profileId)); |
76 | }; | 81 | }; |
77 | 82 |