فهرست منبع

优化任务报工代码

695593266@qq.com 5 ماه پیش
والد
کامیت
2817ba4df2
5فایلهای تغییر یافته به همراه163 افزوده شده و 76 حذف شده
  1. 16 5
      src/api/produce/workOrder.js
  2. 12 2
      src/api/workOrderList/index.js
  3. 2 0
      src/utils/request.js
  4. 0 6
      src/views/produce/components/footBtn.vue
  5. 133 63
      src/views/produce/index.vue

+ 16 - 5
src/api/produce/workOrder.js

@@ -19,12 +19,23 @@ export async function workorderPage(data) {
 }
 }
 
 
 // 工单列表
 // 工单列表
+// export async function workorderPage2(data, config = {}) {
+//   const res = await request.post(
+//     '/mes/workorder/taskReportPage2',
+//     data,
+//     config
+//   );
+//   if (res.data.code == 0) {
+//     return res.data.data;
+//   }
+//   return Promise.reject(new Error(res.data.message));
+// }
+
 export async function workorderPage2(data, config = {}) {
 export async function workorderPage2(data, config = {}) {
-  const res = await request.post(
-    '/mes/workorder/taskReportPage2',
-    data,
-    config
-  );
+  const res = await request.post('/mes/workorder/taskReportPage2', data, {
+    ...config,
+    signal: config.signal
+  });
   if (res.data.code == 0) {
   if (res.data.code == 0) {
     return res.data.data;
     return res.data.data;
   }
   }

+ 12 - 2
src/api/workOrderList/index.js

@@ -87,9 +87,19 @@ export async function pickorderList(params) {
 // }
 // }
 
 
 // 任务列表 pageByCurrentUser 我的任务
 // 任务列表 pageByCurrentUser 我的任务
-export async function pageByCurrentUser(data) {
+// export async function pageByCurrentUser(data) {
+//   const res = await request.get('/aps/assign/pageByCurrentUser/v2', {
+//     params: data
+//   });
+//   if (res.data.code == 0) {
+//     return res.data.data;
+//   }
+//   return Promise.reject(new Error(res.data.message));
+// }
+export async function pageByCurrentUser(data, config = {}) {
   const res = await request.get('/aps/assign/pageByCurrentUser/v2', {
   const res = await request.get('/aps/assign/pageByCurrentUser/v2', {
-    params: data
+    params: data,
+    signal: config.signal
   });
   });
   if (res.data.code == 0) {
   if (res.data.code == 0) {
     return res.data.data;
     return res.data.data;

+ 2 - 0
src/utils/request.js

@@ -79,6 +79,8 @@ service.interceptors.response.use(
       }
       }
       return Promise.reject(new Error(error.response.data?.message));
       return Promise.reject(new Error(error.response.data?.message));
     } else if (!error?.response?.status) {
     } else if (!error?.response?.status) {
+      console.log(error.message);
+      if (error.message == 'canceled') return;
       Message.error('服务器调用失败,请联系管理人员!');
       Message.error('服务器调用失败,请联系管理人员!');
     }
     }
     return Promise.reject(error);
     return Promise.reject(error);

+ 0 - 6
src/views/produce/components/footBtn.vue

@@ -290,12 +290,6 @@
             isShow: 'mes:workreport:save'
             isShow: 'mes:workreport:save'
           },
           },
 
 
-          {
-            name: '产后检查',
-            type: 'postpartumExamination',
-            bjColor: '#9955FF',
-            isShow: 'mes:producetaskrulerecord:save3'
-          },
           {
           {
             name: 'BOM',
             name: 'BOM',
             type: 'bom',
             type: 'bom',

+ 133 - 63
src/views/produce/index.vue

@@ -554,7 +554,8 @@
         chooseType: '1',
         chooseType: '1',
         isUpdataTask: false,
         isUpdataTask: false,
         treeKey: '1',
         treeKey: '1',
-        taskData: null
+        taskData: null,
+        taskRequestController: null
       };
       };
     },
     },
 
 
@@ -599,6 +600,7 @@
     },
     },
     methods: {
     methods: {
       tabClickValue() {
       tabClickValue() {
+        this.abortTaskRequest();
         this.isFinalCheckProduction = false;
         this.isFinalCheckProduction = false;
         this.operationType = '';
         this.operationType = '';
         this.getTaskList();
         this.getTaskList();
@@ -632,6 +634,13 @@
         };
         };
       },
       },
 
 
+      abortTaskRequest() {
+        if (this.taskRequestController) {
+          this.taskRequestController.abort();
+          this.taskRequestController = null;
+        }
+      },
+
       // 前端筛选
       // 前端筛选
       seekInput() {
       seekInput() {
         // console.log(activeName);
         // console.log(activeName);
@@ -719,85 +728,146 @@
           singleListTask(
           singleListTask(
             JSON.parse(localStorage.getItem('chooseUserInfo'))
             JSON.parse(localStorage.getItem('chooseUserInfo'))
           ).then((res) => {
           ).then((res) => {
-            res.map((v) => {
-              v.newName = `${v.workCenterName}-${v.name}`;
-            });
-            this.produceTaskList = res;
-            this.arr = JSON.parse(JSON.stringify(this.produceTaskList));
-            //默认选择第一个工序
-            if (this.produceTaskList?.length) {
-              this.$store.commit('user/setTaskObj', this.produceTaskList[0]);
-              this.$nextTick(() => {
-                this.$refs.taskListRef?.setCurrentKey(
-                  this.produceTaskList[0].id
-                );
-              });
-              this.produceTaskInfo = this.produceTaskList[0];
-            }
+            this.handleTaskList(res);
           });
           });
         } else {
         } else {
           listTask().then((res) => {
           listTask().then((res) => {
-            res.map((v) => {
-              v.newName = `${v.workCenterName}-${v.name}`;
-            });
-            this.produceTaskList = res;
-            this.taskDataList = res;
-            this.arr = JSON.parse(JSON.stringify(this.produceTaskList));
-            //默认选择第一个工序
-            if (this.produceTaskList?.length) {
-              this.$store.commit('user/setTaskObj', this.produceTaskList[0]);
-              this.$nextTick(() => {
-                this.$refs.taskListRef?.setCurrentKey(
-                  this.produceTaskList[0].id
-                );
-              });
-              this.produceTaskInfo = this.produceTaskList[0];
-            }
-            if (this.activeName == '0') {
+            this.handleTaskList(res);
+            if (this.activeName === '0') {
               this.getTaskWorkNumber();
               this.getTaskWorkNumber();
-            } else if (this.activeName == '1') {
+            } else if (this.activeName === '1') {
               this.getTaskWorkList();
               this.getTaskWorkList();
             }
             }
           });
           });
         }
         }
+        // if (localStorage.getItem('singleUserInfo') == '1') {
+        //   singleListTask(
+        //     JSON.parse(localStorage.getItem('chooseUserInfo'))
+        //   ).then((res) => {
+        //     res.map((v) => {
+        //       v.newName = `${v.workCenterName}-${v.name}`;
+        //     });
+        //     this.produceTaskList = res;
+        //     this.arr = JSON.parse(JSON.stringify(this.produceTaskList));
+        //     if (this.produceTaskList?.length) {
+        //       this.$store.commit('user/setTaskObj', this.produceTaskList[0]);
+        //       this.$nextTick(() => {
+        //         this.$refs.taskListRef?.setCurrentKey(
+        //           this.produceTaskList[0].id
+        //         );
+        //       });
+        //       this.produceTaskInfo = this.produceTaskList[0];
+        //     }
+        //   });
+        // } else {
+        //   listTask().then((res) => {
+        //     res.map((v) => {
+        //       v.newName = `${v.workCenterName}-${v.name}`;
+        //     });
+        //     this.produceTaskList = res;
+        //     this.taskDataList = res;
+        //     this.arr = JSON.parse(JSON.stringify(this.produceTaskList));
+        //     if (this.produceTaskList?.length) {
+        //       this.$store.commit('user/setTaskObj', this.produceTaskList[0]);
+        //       this.$nextTick(() => {
+        //         this.$refs.taskListRef?.setCurrentKey(
+        //           this.produceTaskList[0].id
+        //         );
+        //       });
+        //       this.produceTaskInfo = this.produceTaskList[0];
+        //     }
+        //     if (this.activeName == '0') {
+        //       this.getTaskWorkNumber();
+        //     } else if (this.activeName == '1') {
+        //       this.getTaskWorkList();
+        //     }
+        //   });
+        // }
       },
       },
 
 
-      createAbortSignal() {
-        const controller = new AbortController();
-        this.abortControllers.push(controller);
-        return controller.signal;
-      },
+      handleTaskList(res) {
+        res.forEach((v) => {
+          v.newName = `${v.workCenterName}-${v.name}`;
+        });
 
 
-      //获取工序下所有的工单集合
-      async getTaskWorkNumber() {
-        for (const [index, item] of this.taskDataList.entries()) {
-          await workorderPage2({
-            pageNum: 1,
-            size: 5000,
-            taskId: item.id
-          }).then((res) => {
-            this.taskDataList[index].number = res.count;
+        this.produceTaskList = res;
+        this.taskDataList = res;
+        this.arr = JSON.parse(JSON.stringify(res));
+
+        // 默认选中第一个
+        if (res?.length) {
+          this.$store.commit('user/setTaskObj', res[0]);
+          this.produceTaskInfo = res[0];
+          this.$nextTick(() => {
+            this.$refs.taskListRef?.setCurrentKey(res[0].id);
           });
           });
         }
         }
+      },
+
+      async fetchTaskWorkCount(apiFn) {
+        // 新的一轮请求,创建 controller
+        this.taskRequestController = new AbortController();
+        const signal = this.taskRequestController.signal;
+
+        try {
+          const requests = this.taskDataList.map((item) =>
+            apiFn(
+              {
+                pageNum: 1,
+                size: 5000,
+                taskId: item.id
+              },
+              { signal }
+            )
+          );
+
+          const results = await Promise.all(requests);
 
 
-        this.produceTaskList = this.taskDataList;
-        this.treeKey = Date.now();
+          this.taskDataList = this.taskDataList.map((item, index) => ({
+            ...item,
+            number: results[index]?.count || 0
+          }));
+
+          this.produceTaskList = this.taskDataList;
+          this.treeKey = Date.now();
+        } catch (err) {
+          if (err?.name == 'CanceledError' || err?.name == 'AbortError') {
+            return;
+          }
+          console.error(err);
+        }
+      },
+
+      //获取工序下所有的工单集合
+      async getTaskWorkNumber() {
+        await this.fetchTaskWorkCount(workorderPage2);
+        // for (const [index, item] of this.taskDataList.entries()) {
+        //   await workorderPage2({
+        //     pageNum: 1,
+        //     size: 5000,
+        //     taskId: item.id
+        //   }).then((res) => {
+        //     this.taskDataList[index].number = res.count;
+        //   });
+        // }
+        // this.produceTaskList = this.taskDataList;
+        // this.treeKey = Date.now();
       },
       },
 
 
       //获取工序下所有的任务集合
       //获取工序下所有的任务集合
       async getTaskWorkList() {
       async getTaskWorkList() {
-        for (const [index, item] of this.taskDataList.entries()) {
-          await pageByCurrentUser({
-            pageNum: 1,
-            size: 5000,
-            taskId: item.id
-          }).then((res) => {
-            this.taskDataList[index].number = res.count;
-          });
-        }
-
-        this.produceTaskList = this.taskDataList;
-        this.treeKey = Date.now();
+        await this.fetchTaskWorkCount(pageByCurrentUser);
+        // for (const [index, item] of this.taskDataList.entries()) {
+        //   await pageByCurrentUser({
+        //     pageNum: 1,
+        //     size: 5000,
+        //     taskId: item.id
+        //   }).then((res) => {
+        //     this.taskDataList[index].number = res.count;
+        //   });
+        // }
+        // this.produceTaskList = this.taskDataList;
+        // this.treeKey = Date.now();
       },
       },
 
 
       // 获取工位
       // 获取工位
@@ -1880,7 +1950,7 @@
           this.$refs.bomDrawer.open({
           this.$refs.bomDrawer.open({
             categoryId: row.categoryId,
             categoryId: row.categoryId,
             categoryName: row.bomCategoryName,
             categoryName: row.bomCategoryName,
-            code: row.code,
+            code: row.code ? row.code : '',
             versions: row.bomCategoryVersions,
             versions: row.bomCategoryVersions,
             rootPathIdParent: row.categoryLevelPathIdParent || '',
             rootPathIdParent: row.categoryLevelPathIdParent || '',
             isProduct: true,
             isProduct: true,