Commit d85b5ced112518ecc717f0abe4ab07a61daae951

Authored by fengtao
1 parent 69358c3c

fix:重构后修复场景联动选择组织没设备问题

1 <template> 1 <template>
2 - <CollapseContainer title="执行条件" style="background-color: #eeeeee"> 2 + <CollapseContainer style="background-color: #eeeeee">
3 <div style="position: relative"> 3 <div style="position: relative">
4 <BasicForm 4 <BasicForm
5 :labelWidth="100" 5 :labelWidth="100"
1 <template> 1 <template>
2 - <CollapseContainer class="prefixRedDot" title="执行动作" style="background-color: #eeeeee"> 2 + <CollapseContainer class="prefixRedDot" style="background-color: #eeeeee">
3 <div style="position: relative"> 3 <div style="position: relative">
4 <BasicForm 4 <BasicForm
5 :labelWidth="100" 5 :labelWidth="100"
@@ -87,7 +87,7 @@ @@ -87,7 +87,7 @@
87 vertical-align: middle; 87 vertical-align: middle;
88 display: inline-block; 88 display: inline-block;
89 position: relative; 89 position: relative;
90 - top: 33px; 90 + top: 25px;
91 left: 5px; 91 left: 5px;
92 } 92 }
93 </style> 93 </style>
1 <template> 1 <template>
2 <div> 2 <div>
3 - <CollapseContainer title="触发器" style="background-color: #eeeeee"> 3 + <CollapseContainer style="background-color: #eeeeee">
4 <div> 4 <div>
5 <BasicForm 5 <BasicForm
6 :labelWidth="100" 6 :labelWidth="100"
@@ -38,9 +38,7 @@ @@ -38,9 +38,7 @@
38 watch( 38 watch(
39 () => props.deviceInfo, 39 () => props.deviceInfo,
40 async (newV) => { 40 async (newV) => {
41 - console.log(newV);  
42 const options = await screenLinkPageByDeptIdGetDevice({ organizationId: newV }); 41 const options = await screenLinkPageByDeptIdGetDevice({ organizationId: newV });
43 - console.log(options);  
44 options.items.forEach((v) => { 42 options.items.forEach((v) => {
45 return (v.value = v.id), (v.label = v.name); 43 return (v.value = v.id), (v.label = v.name);
46 }); 44 });
@@ -119,10 +119,14 @@ @@ -119,10 +119,14 @@
119 echoEditData = record; 119 echoEditData = record;
120 } 120 }
121 async function handleDelete(record: Recordable) { 121 async function handleDelete(record: Recordable) {
122 - let ids = [record.id];  
123 - await screenLinkPageDeleteApi(ids);  
124 - createMessage.success('删除成功');  
125 - reload(); 122 + try {
  123 + let ids = [record.id];
  124 + await screenLinkPageDeleteApi(ids);
  125 + createMessage.success('删除成功');
  126 + reload();
  127 + } catch (e) {
  128 + return e;
  129 + }
126 } 130 }
127 function handleSuccess() { 131 function handleSuccess() {
128 reload(); 132 reload();
@@ -11,6 +11,8 @@ @@ -11,6 +11,8 @@
11 <!-- 触发器 --> 11 <!-- 触发器 -->
12 <div> 12 <div>
13 <template v-for="(item, index) in addTriggerPushData" :key="index"> 13 <template v-for="(item, index) in addTriggerPushData" :key="index">
  14 + <span style="display: none">{{ item + index }}</span>
  15 + <span style="position: relative; top: 3.2vh; left: 0.3vw">触发器{{ index + 1 }}</span>
14 <div> 16 <div>
15 <AddTriggerForm :deviceInfo="getDeviceInfo" ref="refTriggerChild" /> 17 <AddTriggerForm :deviceInfo="getDeviceInfo" ref="refTriggerChild" />
16 </div> 18 </div>
@@ -19,7 +21,7 @@ @@ -19,7 +21,7 @@
19 <div 21 <div
20 style=" 22 style="
21 display: flex; 23 display: flex;
22 - width: 13vw; 24 + width: 11vw;
23 height: 4vh; 25 height: 4vh;
24 flex-direction: row; 26 flex-direction: row;
25 justify-content: space-between; 27 justify-content: space-between;
@@ -27,12 +29,17 @@ @@ -27,12 +29,17 @@
27 > 29 >
28 <div style="display: flex; width: 4vw; height: 4vh"> 30 <div style="display: flex; width: 4vw; height: 4vh">
29 <Button type="primary" style="border-radius: 10px" class="mt-5" @click="addTrigger" 31 <Button type="primary" style="border-radius: 10px" class="mt-5" @click="addTrigger"
30 - ><PlusCircleOutlined />新增触发器</Button 32 + >新增触发器</Button
31 > 33 >
32 </div> 34 </div>
33 <div style="display: flex; width: 4vw; height: 4vh"> 35 <div style="display: flex; width: 4vw; height: 4vh">
34 - <Button type="error" style="border-radius: 10px" class="mt-5" @click="removeTrigger"  
35 - ><PlusCircleOutlined />删除</Button 36 + <Button
  37 + type="default"
  38 + style="border-radius: 10px; background-color: rgba(237, 111, 111, 1)"
  39 + class="mt-5"
  40 + @click="removeTrigger"
  41 + >
  42 + <span style="color: white">删除</span></Button
36 > 43 >
37 </div> 44 </div>
38 </div> 45 </div>
@@ -41,6 +48,9 @@ @@ -41,6 +48,9 @@
41 <!-- 执行条件 --> 48 <!-- 执行条件 -->
42 <div> 49 <div>
43 <template v-for="(item, index) in addConditionPushData" :key="index"> 50 <template v-for="(item, index) in addConditionPushData" :key="index">
  51 + <span style="display: none">{{ item + index }}</span>
  52 + <span style="position: relative; top: 3.2vh; left: 0.3vw">执行条件{{ index + 1 }}</span>
  53 +
44 <div> 54 <div>
45 <AddConditiForm :deviceInfo1="getDeviceInfo1" ref="refConditionChild" /> 55 <AddConditiForm :deviceInfo1="getDeviceInfo1" ref="refConditionChild" />
46 </div> 56 </div>
@@ -49,7 +59,7 @@ @@ -49,7 +59,7 @@
49 <div 59 <div
50 style=" 60 style="
51 display: flex; 61 display: flex;
52 - width: 13vw; 62 + width: 11vw;
53 height: 4vh; 63 height: 4vh;
54 flex-direction: row; 64 flex-direction: row;
55 justify-content: space-between; 65 justify-content: space-between;
@@ -57,12 +67,17 @@ @@ -57,12 +67,17 @@
57 > 67 >
58 <div style="display: flex; width: 4vw; height: 4vh"> 68 <div style="display: flex; width: 4vw; height: 4vh">
59 <Button type="primary" style="border-radius: 10px" class="mt-5" @click="addCondition" 69 <Button type="primary" style="border-radius: 10px" class="mt-5" @click="addCondition"
60 - ><PlusCircleOutlined />新增执行条件</Button 70 + >新增执行条件</Button
61 > 71 >
62 </div> 72 </div>
63 <div style="display: flex; width: 4vw; height: 4vh"> 73 <div style="display: flex; width: 4vw; height: 4vh">
64 - <Button type="error" style="border-radius: 10px" class="mt-5" @click="removeCondition"  
65 - ><PlusCircleOutlined />删除</Button 74 + <Button
  75 + style="border-radius: 10px; background-color: rgba(237, 111, 111, 1)"
  76 + type="default"
  77 + class="mt-5"
  78 + @click="removeCondition"
  79 + >
  80 + <span style="color: white">删除</span></Button
66 > 81 >
67 </div> 82 </div>
68 </div> 83 </div>
@@ -71,6 +86,9 @@ @@ -71,6 +86,9 @@
71 <div style="height: 5vh"></div> 86 <div style="height: 5vh"></div>
72 <div> 87 <div>
73 <template v-for="(item, index) in addActionPushData" :key="index"> 88 <template v-for="(item, index) in addActionPushData" :key="index">
  89 + <span style="display: none">{{ item + index }}</span>
  90 + <span style="position: relative; top: 4.2vh; left: 0.65vw">执行动作{{ index + 1 }}</span>
  91 +
74 <div> 92 <div>
75 <AddActionForm :deviceInfo2="getDeviceInfo2" ref="refActionChild" /> 93 <AddActionForm :deviceInfo2="getDeviceInfo2" ref="refActionChild" />
76 </div> 94 </div>
@@ -79,7 +97,7 @@ @@ -79,7 +97,7 @@
79 <div 97 <div
80 style=" 98 style="
81 display: flex; 99 display: flex;
82 - width: 13vw; 100 + width: 11vw;
83 height: 4vh; 101 height: 4vh;
84 flex-direction: row; 102 flex-direction: row;
85 justify-content: space-between; 103 justify-content: space-between;
@@ -87,15 +105,21 @@ @@ -87,15 +105,21 @@
87 > 105 >
88 <div style="display: flex; width: 4vw; height: 4vh"> 106 <div style="display: flex; width: 4vw; height: 4vh">
89 <Button type="primary" style="border-radius: 10px" class="mt-5" @click="addAction" 107 <Button type="primary" style="border-radius: 10px" class="mt-5" @click="addAction"
90 - ><PlusCircleOutlined />新增执行动作</Button 108 + >新增执行动作</Button
91 > 109 >
92 </div> 110 </div>
93 <div style="display: flex; width: 4vw; height: 4vh"> 111 <div style="display: flex; width: 4vw; height: 4vh">
94 - <Button type="error" style="border-radius: 10px" class="mt-5" @click="removeAction"  
95 - ><PlusCircleOutlined />删除</Button 112 + <Button
  113 + style="border-radius: 10px; background-color: rgba(237, 111, 111, 1)"
  114 + type="default"
  115 + class="mt-5"
  116 + @click="removeAction"
  117 + >
  118 + <span style="color: white">删除</span></Button
96 > 119 >
97 </div> 120 </div>
98 </div> 121 </div>
  122 + <div style="height: 5vh"></div>
99 </div> 123 </div>
100 </BasicDrawer> 124 </BasicDrawer>
101 </template> 125 </template>
@@ -104,11 +128,7 @@ @@ -104,11 +128,7 @@
104 import { BasicForm, useForm } from '/@/components/Form'; 128 import { BasicForm, useForm } from '/@/components/Form';
105 import { formSchema, getData } from './config'; 129 import { formSchema, getData } from './config';
106 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; 130 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
107 - import {  
108 - screenLinkPageAddApi,  
109 - // screenLinkPageUpdateApi,  
110 - // screenLinkPageByDeptIdGetDevice,  
111 - } from '/@/api/ruleengine/ruleengineApi'; 131 + import { screenLinkPageAddApi, screenLinkPageUpdateApi } from '/@/api/ruleengine/ruleengineApi';
112 import { useMessage } from '/@/hooks/web/useMessage'; 132 import { useMessage } from '/@/hooks/web/useMessage';
113 import AddTriggerForm from './addForm/trigger.vue'; 133 import AddTriggerForm from './addForm/trigger.vue';
114 import AddConditiForm from './addForm/condition.vue'; 134 import AddConditiForm from './addForm/condition.vue';
@@ -118,9 +138,17 @@ @@ -118,9 +138,17 @@
118 138
119 export default defineComponent({ 139 export default defineComponent({
120 name: 'ConfigDrawer', 140 name: 'ConfigDrawer',
121 - components: { BasicDrawer, BasicForm, AddTriggerForm, AddConditiForm, AddActionForm, Button }, 141 + components: {
  142 + BasicDrawer,
  143 + BasicForm,
  144 + AddTriggerForm,
  145 + AddConditiForm,
  146 + AddActionForm,
  147 + Button,
  148 + },
122 emits: ['success', 'register', 'registerForm'], 149 emits: ['success', 'register', 'registerForm'],
123 setup(_, { emit }) { 150 setup(_, { emit }) {
  151 + const { proxy } = getCurrentInstance();
124 const lastRefTriggerChildDataArray = ref<[]>([]); 152 const lastRefTriggerChildDataArray = ref<[]>([]);
125 const lastRefConditionChildDataArray = ref<[]>([]); 153 const lastRefConditionChildDataArray = ref<[]>([]);
126 const lastRefActionChildDataArray = ref<[]>([]); 154 const lastRefActionChildDataArray = ref<[]>([]);
@@ -159,7 +187,6 @@ @@ -159,7 +187,6 @@
159 const addTriggerPushData = ref<[]>([]); 187 const addTriggerPushData = ref<[]>([]);
160 const addConditionPushData = ref<[]>([]); 188 const addConditionPushData = ref<[]>([]);
161 const addActionPushData = ref<[]>([]); 189 const addActionPushData = ref<[]>([]);
162 - const { proxy } = getCurrentInstance();  
163 const getChildData = ref(null); 190 const getChildData = ref(null);
164 const refTriggerChild = ref(null); 191 const refTriggerChild = ref(null);
165 const refConditionChild = ref(null); 192 const refConditionChild = ref(null);
@@ -167,13 +194,13 @@ @@ -167,13 +194,13 @@
167 const getConditionChildData = ref(null); 194 const getConditionChildData = ref(null);
168 const { createMessage } = useMessage(); 195 const { createMessage } = useMessage();
169 const isUpdate = ref(true); 196 const isUpdate = ref(true);
170 - let getAllFormData: any = reactive({}); 197 + const getAllFormData: any = reactive({});
171 let getValuesFormData: any = reactive({}); 198 let getValuesFormData: any = reactive({});
172 - let getId = ref('');  
173 - let getTenantId = ref('');  
174 - let getDeviceInfo = ref(null);  
175 - let getDeviceInfo1 = ref(null);  
176 - let getDeviceInfo2 = ref(null); 199 + const getId = ref('');
  200 + const getTenantId = ref('');
  201 + const getDeviceInfo = ref(null);
  202 + const getDeviceInfo1 = ref(null);
  203 + const getDeviceInfo2 = ref(null);
177 204
178 const [registerForm, { resetFields, setFieldsValue, validateFields }] = useForm({ 205 const [registerForm, { resetFields, setFieldsValue, validateFields }] = useForm({
179 labelWidth: 120, 206 labelWidth: 120,
@@ -194,9 +221,8 @@ @@ -194,9 +221,8 @@
194 } catch (e) { 221 } catch (e) {
195 return e; 222 return e;
196 } 223 }
197 - }  
198 - //编辑  
199 - if (unref(isUpdate)) { 224 + } else {
  225 + //编辑
200 getId.value = data.record.id; 226 getId.value = data.record.id;
201 getTenantId.value = data.record.tenantId; 227 getTenantId.value = data.record.tenantId;
202 await setFieldsValue({ 228 await setFieldsValue({
@@ -259,14 +285,17 @@ @@ -259,14 +285,17 @@
259 } 285 }
260 }; 286 };
261 287
262 - const getDefaultValue = async () => {  
263 - getValuesFormData = await validateFields(); 288 + const getDefaultValue = () => {
264 refTriggerChildDataFunc(); 289 refTriggerChildDataFunc();
265 refConditionChildDataFunc(); 290 refConditionChildDataFunc();
266 refActionChildDataFunc(); 291 refActionChildDataFunc();
267 - lastRefTriggerChildDataArray.value.push(refTriggerChildData.value);  
268 - lastRefConditionChildDataArray.value.push(refConditionChildData.value);  
269 - lastRefActionChildDataArray.value.push(refActionChildData.value); 292 + lastRefTriggerChildDataArray.value.push(refTriggerChildData.value as never);
  293 + lastRefConditionChildDataArray.value.push(refConditionChildData.value as never);
  294 + lastRefActionChildDataArray.value.push(refActionChildData.value as never);
  295 + //删除第一个
  296 + lastRefTriggerChildDataArray.value.shift();
  297 + lastRefConditionChildDataArray.value.shift();
  298 + lastRefActionChildDataArray.value.shift();
270 const triggersObj = { 299 const triggersObj = {
271 triggers: lastRefTriggerChildDataArray.value, 300 triggers: lastRefTriggerChildDataArray.value,
272 }; 301 };
@@ -276,52 +305,66 @@ @@ -276,52 +305,66 @@
276 const actionsObj = { 305 const actionsObj = {
277 actions: lastRefActionChildDataArray.value, 306 actions: lastRefActionChildDataArray.value,
278 }; 307 };
279 - Object.assign(getAllFormData, getValuesFormData, triggersObj, conditionsObj, actionsObj); 308 + Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj);
280 if (!unref(isUpdate)) { 309 if (!unref(isUpdate)) {
281 delete getAllFormData.id; 310 delete getAllFormData.id;
282 delete getAllFormData.getTenantId; 311 delete getAllFormData.getTenantId;
283 } 312 }
284 }; 313 };
285 314
286 - async function handleSubmit() { 315 + const handleSubmit = async () => {
287 if (!unref(isUpdate)) { 316 if (!unref(isUpdate)) {
288 getDefaultValue(); 317 getDefaultValue();
289 - console.log(getAllFormData); 318 + getValuesFormData = await validateFields();
  319 + if (!getValuesFormData) return;
  320 + Object.assign(getAllFormData, getValuesFormData);
290 await screenLinkPageAddApi(getAllFormData); 321 await screenLinkPageAddApi(getAllFormData);
291 createMessage.success('场景联动新增成功'); 322 createMessage.success('场景联动新增成功');
292 closeDrawer(); 323 closeDrawer();
293 emit('success'); 324 emit('success');
294 } else { 325 } else {
295 getDefaultValue(); 326 getDefaultValue();
  327 + getAllFormData.id = getId.value;
  328 + getAllFormData.tenantId = getTenantId.value;
  329 + await screenLinkPageUpdateApi(getAllFormData);
296 createMessage.success('场景联动编辑成功'); 330 createMessage.success('场景联动编辑成功');
297 closeDrawer(); 331 closeDrawer();
298 emit('success'); 332 emit('success');
299 } 333 }
300 - } 334 + };
  335 +
301 //新增触发器 336 //新增触发器
302 const addTrigger = () => { 337 const addTrigger = () => {
303 - unref(addTriggerPushData).push(addTriggerData); 338 + unref(addTriggerPushData).push(addTriggerData as never);
304 refTriggerChildDataFunc(); 339 refTriggerChildDataFunc();
305 lastRefTriggerChildData.value = refTriggerChildData.value; 340 lastRefTriggerChildData.value = refTriggerChildData.value;
306 - lastRefTriggerChildDataArray.value.push(lastRefTriggerChildData.value); 341 + lastRefTriggerChildDataArray.value.push(lastRefTriggerChildData.value as never);
307 }; 342 };
308 const removeTrigger = () => { 343 const removeTrigger = () => {
309 - unref(addTriggerPushData).splice(0, 1);  
310 - lastRefTriggerChildDataArray.value.splice(0, 1);  
311 - getAllFormData.triggers.splice(0, 1); 344 + try {
  345 + unref(addTriggerPushData).splice(0, 1);
  346 + lastRefTriggerChildDataArray.value.splice(0, 1);
  347 + getAllFormData.triggers.splice(0, 1);
  348 + } catch (e) {
  349 + return e;
  350 + }
312 }; 351 };
313 352
314 //新增执行条件 353 //新增执行条件
315 const addCondition = () => { 354 const addCondition = () => {
316 - unref(addConditionPushData).push(addConditionData); 355 + unref(addConditionPushData).push(addConditionData as never);
317 refConditionChildDataFunc(); 356 refConditionChildDataFunc();
318 lastRefConditionChildData.value = refConditionChildData.value; 357 lastRefConditionChildData.value = refConditionChildData.value;
319 - lastRefConditionChildDataArray.value.push(lastRefConditionChildData.value); 358 + lastRefConditionChildDataArray.value.push(lastRefConditionChildData.value as never);
320 }; 359 };
321 const removeCondition = () => { 360 const removeCondition = () => {
322 - unref(addConditionPushData).splice(0, 1);  
323 - lastRefConditionChildDataArray.value.splice(0, 1);  
324 - getAllFormData.conditions.splice(0, 1); 361 + try {
  362 + unref(addConditionPushData).splice(0, 1);
  363 + lastRefConditionChildDataArray.value.splice(0, 1);
  364 + getAllFormData.conditions.splice(0, 1);
  365 + } catch (e) {
  366 + return e;
  367 + }
325 }; 368 };
326 369
327 //新增执行动作 370 //新增执行动作
@@ -331,15 +374,19 @@ @@ -331,15 +374,19 @@
331 } 374 }
332 }; 375 };
333 const addAction = () => { 376 const addAction = () => {
334 - unref(addActionPushData).push(addActionData); 377 + unref(addActionPushData).push(addActionData as never);
335 refActionChildDataFunc(); 378 refActionChildDataFunc();
336 lastRefActionChildData.value = refActionChildData.value; 379 lastRefActionChildData.value = refActionChildData.value;
337 - lastRefActionChildDataArray.value.push(lastRefActionChildData.value); 380 + lastRefActionChildDataArray.value.push(lastRefActionChildData.value as never);
338 }; 381 };
339 const removeAction = () => { 382 const removeAction = () => {
340 - unref(addActionPushData).splice(0, 1);  
341 - lastRefActionChildDataArray.value.splice(0, 1);  
342 - getAllFormData.actions.splice(0, 1); 383 + try {
  384 + unref(addActionPushData).splice(0, 1);
  385 + lastRefActionChildDataArray.value.splice(0, 1);
  386 + getAllFormData.actions.splice(0, 1);
  387 + } catch (e) {
  388 + return e;
  389 + }
343 }; 390 };
344 391
345 return { 392 return {