瀏覽代碼

优化运行逻辑,遇到错误不会阻止逻辑继续

xiaohaizhao 1 年之前
父節點
當前提交
caaaf993bc
共有 1 個文件被更改,包括 23 次插入12 次删除
  1. 23 12
      utils/tool.js

+ 23 - 12
utils/tool.js

@@ -62,19 +62,30 @@ function mount() {
             }
         })
     };
-    Vue.prototype.getControlItem = (nameList, funs, values, paramsList) => {
-        let list = nameList.map(v => funs[v])
+    Vue.prototype.getControlItem = (nameList, detail, specialType = {}) => {
+        let list = nameList.map(v => detail.function[v])
         for (const key in list) {
-            const name = Object.entries(list[key].params)[0][0]
-            list[key].paramName = name;
-            list[key].params = paramsList[name];
-            list[key].paramValue = values[name]
-            list[key].isfeedback = list[key].isfeedback && (list[key].paramValue != list[key].params.lastvalue)
-            if (list[key].params.datatype == "boolean") {
-                list[key].inputType = 'switch';
-                list[key].showValue = list[key].params.options.find(v => v.value == list[key].params.lastvalue).label
-            } else {
-                list[key].inputType = list[key].params.num_step ? 'step' : 'int';
+            try {
+                const name = Object.entries(list[key].params)[0][0]
+                list[key].paramName = name;
+                list[key].params = detail.params[name];
+                list[key].paramValue = detail.paramcmdvalues[name]
+                list[key].isfeedback = (detail.isfeedback == 1 && (detail.paramcmdvalues[name] != detail.paramvalues[name])) ? true : false;
+                if (list[key].params.datatype == "boolean") {
+                    list[key].inputType = 'switch';
+                    list[key].showValue = "";
+                    if (list[key].params.lastvalue + '') list[key].showValue = list[key].params.options.find(v => v.value == list[key].params.lastvalue).label || ""
+                } else if (specialType[nameList[key]] || false) {
+                    list[key].inputType = specialType[nameList[key]];
+                    if (["radio"].includes(specialType[nameList[key]])) {
+                        list[key].showValue = "";
+                        if (list[key].params.lastvalue + '') list[key].showValue = list[key].params.options.find(v => v.value == list[key].params.lastvalue).label || ""
+                    }
+                } else {
+                    list[key].inputType = list[key].params.num_step ? 'step' : 'int';
+                }
+            } catch (error) {
+                console.log("出错项", list[key].funcname, list[key])
             }
         }
         return list