Commit 9ed244e0147d3f7557923964baaeeef19c625f85

Authored by loveumiko
1 parent d15d96df

fix: 修复启用模版再选择模版,对应的产品会回显,但是再点开关,选择模版,产品未回显

... ... @@ -26,7 +26,7 @@
26 26 v-if="model['templateId']"
27 27 ref="selectDeviceProfileRef"
28 28 :selectOptions="selectOptions"
29   - :organizationId="model['organizationId']"
  29 + :organizationId="model?.['organizationId']"
30 30 />
31 31 </template>
32 32 </BasicForm>
... ... @@ -71,12 +71,21 @@
71 71 });
72 72 await updateSchema({
73 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,22 @@
139 148 value: item.id,
140 149 }));
141 150 };
142   -
143 151 const selectOptions: Ref<any[]> = ref([]);
144 152
145 153 const handleTemplateChange = async (_, option) => {
146 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 160 await nextTick();
153 161 // 赋值
154 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 + }))
156 167 );
157 168 };
158 169 //
... ...
... ... @@ -153,14 +153,17 @@ export const formSchema: FormSchema[] = [
153 153 defaultValue: 0,
154 154 componentProps: ({ formActionType }) => {
155 155 const { setFieldsValue } = formActionType;
  156 +
156 157 return {
157 158 checkedValue: 1,
158 159 unCheckedValue: 0,
159 160 checkedChildren: '开',
160 161 unCheckedChildren: '关',
161   - onChange() {
  162 + onChange: () => {
162 163 setFieldsValue({
163 164 productIds: [],
  165 + templateId: null,
  166 + productId: undefined,
164 167 });
165 168 },
166 169 };
... ... @@ -181,6 +184,7 @@ export const formSchema: FormSchema[] = [
181 184 field: 'templateId', //暂且使用插槽形式
182 185 label: '模板',
183 186 component: 'Input',
  187 + required: true,
184 188 slot: 'templateId',
185 189 colProps: { span: 24 },
186 190 ifShow: ({ values }) => values['enableTemplate'] === 1,
... ... @@ -193,14 +197,14 @@ export const formSchema: FormSchema[] = [
193 197 colProps: { span: 24 },
194 198 ifShow: ({ values }) => values['enableTemplate'] === 1 && values['templateId'],
195 199 },
196   - {
197   - field: 'deviceIds', //暂且使用插槽形式
198   - label: '设备',
199   - component: 'Input',
200   - slot: 'deviceIds',
201   - colProps: { span: 24 },
202   - ifShow: ({ values }) => values['enableTemplate'] === 1 && values['templateId'],
203   - },
  200 + // {
  201 + // field: 'deviceIds', //暂且使用插槽形式
  202 + // label: '设备',
  203 + // component: 'Input',
  204 + // slot: 'deviceIds',
  205 + // colProps: { span: 24 },
  206 + // ifShow: ({ values }) => values['enableTemplate'] === 1 && values['templateId'],
  207 + // },
204 208 {
205 209 field: 'productId',
206 210 label: '产品',
... ...
... ... @@ -56,12 +56,8 @@
56 56
57 57 const setFieldsValue = async (productIds) => {
58 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 63 const setValue = (value: any) => {
... ...