Commit 0ee50e508d4bea2ae0c22c9d6809c605ea64aaac

Authored by xp.Huang
2 parents 368beeb6 94d67d41

Merge branch 'fix/DEFECT-1718' into 'main_dev'

模板和组态创建添加字段

See merge request yunteng/thingskit-front!975
... ... @@ -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,24 @@
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 + transportType: item?.transportType,
  167 + deviceType: item?.deviceType,
  168 + }))
156 169 );
157 170 };
158 171 //
... ... @@ -170,7 +183,12 @@
170 183 const getCurrentAllProduct = async (products: string[]) => {
171 184 const resp = (await getDeviceProfile()) as any;
172 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 192 return values.filter((item) => products?.includes(item.profileId));
175 193 };
176 194
... ...
... ... @@ -152,14 +152,17 @@ export const formSchema: FormSchema[] = [
152 152 defaultValue: 0,
153 153 componentProps: ({ formActionType }) => {
154 154 const { setFieldsValue } = formActionType;
  155 +
155 156 return {
156 157 checkedValue: 1,
157 158 unCheckedValue: 0,
158 159 checkedChildren: '开',
159 160 unCheckedChildren: '关',
160   - onChange() {
  161 + onChange: () => {
161 162 setFieldsValue({
162 163 productIds: [],
  164 + templateId: null,
  165 + productId: undefined,
163 166 });
164 167 },
165 168 };
... ... @@ -180,6 +183,7 @@ export const formSchema: FormSchema[] = [
180 183 field: 'templateId', //暂且使用插槽形式
181 184 label: '模板',
182 185 component: 'Input',
  186 + required: true,
183 187 slot: 'templateId',
184 188 colProps: { span: 24 },
185 189 ifShow: ({ values }) => values['enableTemplate'] === 1,
... ... @@ -193,14 +197,6 @@ export const formSchema: FormSchema[] = [
193 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 200 field: 'productId',
205 201 label: '产品',
206 202 component: 'ApiSelect',
... ...
... ... @@ -53,6 +53,8 @@
53 53 dynamicInput.params.push({
54 54 name: props.value.label,
55 55 profileId: props.value.value,
  56 + deviceType: props.value?.deviceType,
  57 + transportType: props.value?.transportType,
56 58 deviceList: props.value.deviceList?.filter(Boolean)?.map((item) => item.deviceId),
57 59 });
58 60 }
... ... @@ -67,17 +69,20 @@
67 69
68 70 //chang改变
69 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 83 return {
79 84 ...dynamicInput.params[0],
80   - deviceList: findDeviceDict.filter(Boolean),
  85 + deviceList: tempDeviceList.filter(Boolean), // 过滤假值
81 86 };
82 87 };
83 88 defineExpose({
... ...
... ... @@ -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) => {
... ...
... ... @@ -71,7 +71,12 @@
71 71 const getCurrentAllProduct = async (products: string[]) => {
72 72 const resp = (await getDeviceProfile()) as any;
73 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 80 return values.filter((item) => products.includes(item.profileId));
76 81 };
77 82
... ...