Răsfoiți Sursa

隔离点排序修改新的方法

pm 1 an în urmă
părinte
comite
7f44eba817

+ 13 - 2
src/views/mes/job/jobm/NewOperations.vue

@@ -971,10 +971,21 @@ export default {
     },
     // 定义一个排序函数,根据 orderTableData 中 pointName 的顺序对 tableData 进行排序
     sortTableDataByOrder(tableData, orderTableData) {
-      const orderMap = new Map(orderTableData.map((item, index) => [item.pointName, index]));
+      // 构建 orderMap,使用 pointId 作为键,索引作为值
+      const orderMap = new Map(orderTableData.map((item, index) => [item.pointId, index]));
 
       return tableData.sort((a, b) => {
-        return (orderMap.get(a.pointName) || Infinity) - (orderMap.get(b.pointName) || Infinity);
+        // 如果 pointId 在 orderMap 中,按 orderMap 的索引排序
+        // 如果 pointId 不在 orderMap 中,排在最后,并按 pointId 的自然顺序排列
+        const indexA = orderMap.has(a.pointId) ? orderMap.get(a.pointId) : Infinity;
+        const indexB = orderMap.has(b.pointId) ? orderMap.get(b.pointId) : Infinity;
+
+        if (indexA === indexB) {
+          // 当两者都不在 orderMap 中时,按 pointId 的自然顺序排列
+          return a.pointId - b.pointId;
+        }
+
+        return indexA - indexB;
       });
     },
     // 子组件逆向传递选中的隔离点

+ 13 - 2
src/views/mes/job/jobm/lookWork.vue

@@ -1077,10 +1077,21 @@ export default {
     },
     // 定义一个排序函数,根据 orderTableData 中 pointName 的顺序对 tableData 进行排序
     sortTableDataByOrder(tableData, orderTableData) {
-      const orderMap = new Map(orderTableData.map((item, index) => [item.pointName, index]));
+      // 构建 orderMap,使用 pointId 作为键,索引作为值
+      const orderMap = new Map(orderTableData.map((item, index) => [item.pointId, index]));
 
       return tableData.sort((a, b) => {
-        return (orderMap.get(a.pointName) || Infinity) - (orderMap.get(b.pointName) || Infinity);
+        // 如果 pointId 在 orderMap 中,按 orderMap 的索引排序
+        // 如果 pointId 不在 orderMap 中,排在最后,并按 pointId 的自然顺序排列
+        const indexA = orderMap.has(a.pointId) ? orderMap.get(a.pointId) : Infinity;
+        const indexB = orderMap.has(b.pointId) ? orderMap.get(b.pointId) : Infinity;
+
+        if (indexA === indexB) {
+          // 当两者都不在 orderMap 中时,按 pointId 的自然顺序排列
+          return a.pointId - b.pointId;
+        }
+
+        return indexA - indexB;
       });
     },
     // 子组件逆向传递选中的隔离点

+ 13 - 2
src/views/mes/sop/sopm/NewSop.vue

@@ -845,10 +845,21 @@ export default {
     },
 // 定义一个排序函数,根据 orderTableData 中 pointName 的顺序对 tableData 进行排序
     sortTableDataByOrder(tableData, orderTableData) {
-      const orderMap = new Map(orderTableData.map((item, index) => [item.pointName, index]));
+      // 构建 orderMap,使用 pointId 作为键,索引作为值
+      const orderMap = new Map(orderTableData.map((item, index) => [item.pointId, index]));
 
       return tableData.sort((a, b) => {
-        return (orderMap.get(a.pointName) || Infinity) - (orderMap.get(b.pointName) || Infinity);
+        // 如果 pointId 在 orderMap 中,按 orderMap 的索引排序
+        // 如果 pointId 不在 orderMap 中,排在最后,并按 pointId 的自然顺序排列
+        const indexA = orderMap.has(a.pointId) ? orderMap.get(a.pointId) : Infinity;
+        const indexB = orderMap.has(b.pointId) ? orderMap.get(b.pointId) : Infinity;
+
+        if (indexA === indexB) {
+          // 当两者都不在 orderMap 中时,按 pointId 的自然顺序排列
+          return a.pointId - b.pointId;
+        }
+
+        return indexA - indexB;
       });
     },
     // 子组件选中的隔离点逆传递拿到的数据

+ 15 - 2
src/views/mes/sop/sopm/sopmLook.vue

@@ -950,12 +950,25 @@ export default {
     },
     // 定义一个排序函数,根据 orderTableData 中 pointName 的顺序对 tableData 进行排序
     sortTableDataByOrder(tableData, orderTableData) {
-      const orderMap = new Map(orderTableData.map((item, index) => [item.pointName, index]));
+      // 构建 orderMap,使用 pointId 作为键,索引作为值
+      const orderMap = new Map(orderTableData.map((item, index) => [item.pointId, index]));
 
       return tableData.sort((a, b) => {
-        return (orderMap.get(a.pointName) || Infinity) - (orderMap.get(b.pointName) || Infinity);
+        // 如果 pointId 在 orderMap 中,按 orderMap 的索引排序
+        // 如果 pointId 不在 orderMap 中,排在最后,并按 pointId 的自然顺序排列
+        const indexA = orderMap.has(a.pointId) ? orderMap.get(a.pointId) : Infinity;
+        const indexB = orderMap.has(b.pointId) ? orderMap.get(b.pointId) : Infinity;
+
+        if (indexA === indexB) {
+          // 当两者都不在 orderMap 中时,按 pointId 的自然顺序排列
+          return a.pointId - b.pointId;
+        }
+
+        return indexA - indexB;
       });
     },
+
+
     // 子组件选中的隔离点逆传递拿到的数据
     handleSelectPoint(points) {
       console.log(points, "父组件接收逆向传递选中的隔离点");