Selaa lähdekoodia

Merge branch 'refs/heads/xinyan' into test

xinyan 9 kuukautta sitten
vanhempi
commit
bfedf47f5f
1 muutettua tiedostoa jossa 72 lisäystä ja 18 poistoa
  1. 72 18
      src/views/reportManage/TaskManage/index.vue

+ 72 - 18
src/views/reportManage/TaskManage/index.vue

@@ -6,7 +6,8 @@ import {
   exportTaskData,
   getCurrencyCodeSelect,
   getOperationSelect,
-  getTasks, postCreateTask,
+  getTasks,
+  postCreateTask,
   postDeleteTask,
   postSendMessage,
   postUpdateManyTask,
@@ -276,6 +277,22 @@ const handleEditClosed = ({ row, column }) => {
   }
 };
 
+// 禁用自动退出编辑模式
+const disableAutoExitEdit = () => {
+  const $grid = xGrid.value;
+  if ($grid) {
+    gridOptions.editConfig.autoClear = false; // 手动模式,禁止点击其他地方退出编辑模式
+  }
+};
+
+// 启用自动退出编辑模式
+const enableAutoExitEdit = () => {
+  const $grid = xGrid.value;
+  if ($grid) {
+    gridOptions.editConfig.autoClear = true; // 点击触发退出编辑模式
+  }
+};
+
 // 将 user 数组转换为 user_name 字符串
 function userToUserName(user: string[]): string {
   return operationList.value
@@ -340,7 +357,7 @@ function filteredDataChange(newList) {
 
 // 全部保存按钮
 async function saveEvent(row) {
-  clearRowEvent(row)
+  clearRowEvent(row);
   const $grid = xGrid.value;
   if ($grid) {
     try {
@@ -352,24 +369,57 @@ async function saveEvent(row) {
         if (!originalRecord) return null;
 
         const updatedFields = {};
+
         // 比较字段并记录变化
         for (const key in record) {
-          if (record[key] !== originalRecord[key]) {
-            updatedFields[key] = record[key];
+          // 针对 operater 字段的特殊处理
+          if (key === 'operater') {
+            // 如果 operater 是字符串,将其转换为数组
+            let recordOperater = Array.isArray(record.operater)
+                ? record.operater
+                : record.operater.split(',').map(item => item.trim()); // 中文逗号分割并去除空格
+
+            // 如果 originalRecord.operater 是字符串,也转换为数组
+            let originalOperater = Array.isArray(originalRecord.operater)
+                ? originalRecord.operater
+                : originalRecord.operater.split(',').map(item => item.trim());
+
+            // 比较两个数组,确保它们不相等时才记录变化
+            if (JSON.stringify(recordOperater) !== JSON.stringify(originalOperater)) {
+              updatedFields[key] = recordOperater; // 存储更新后的 operater 数组
+            }
+          } else {
+            // 对于非 operater 字段,进行普通的比较
+            if (record[key] !== originalRecord[key]) {
+              updatedFields[key] = record[key];
+            }
           }
         }
 
-        return {
-          id: record.id,
-          ...updatedFields
-        };
+        // 如果有变化字段,返回该记录,否则跳过
+        if (Object.keys(updatedFields).length > 0) {
+          return {
+            id: record.id,
+            ...updatedFields
+          };
+        }
+        return null;
       }).filter(record => record); // 过滤掉值为 null 的记录
-      await postUpdateManyTask(updatedRecords);
-      await getTaskList();
-      await VXETable.modal.message({
-        content: `更新 ${ updatedRecords.length } 条`,
-        status: 'success',
-      });
+
+      if (updatedRecords.length > 0) {
+        // 调用接口提交更新
+        await postUpdateManyTask(updatedRecords);
+        await getTaskList();
+        await VXETable.modal.message({
+          content: `更新 ${ updatedRecords.length } 条`,
+          status: 'success',
+        });
+      } else {
+        await VXETable.modal.message({
+          content: '没有检测到变化',
+          status: 'info',
+        });
+      }
 
     } catch (e) {
       console.log('error', e);
@@ -535,10 +585,10 @@ const saveRowEvent = async (row: RowVO) => {
     await $grid.clearEdit();
     await updateRow(row);
     await getTaskList();
-    gridOptions.loading = true;
-    setTimeout(() => {
-      gridOptions.loading = false;
-    }, 300);
+    //gridOptions.loading = true;
+    //setTimeout(() => {
+    //  gridOptions.loading = false;
+    //}, 300);
   }
 };
 
@@ -830,6 +880,8 @@ onMounted(() => {
               :fetch-suggestions="querySearch"
               :trigger-on-focus="false"
               clearable
+              @blur="enableAutoExitEdit"
+              @focus="disableAutoExitEdit"
               @select="item => handleRowSelect(item, row)"
           >
             <template v-slot="{ item }">
@@ -844,6 +896,8 @@ onMounted(() => {
               :fetch-suggestions="querySearch"
               :trigger-on-focus="false"
               clearable
+              @blur="enableAutoExitEdit"
+              @focus="disableAutoExitEdit"
               @select="item => handelRowCurrencyCodePlatformSelect(item,row)"
           >
             <template v-slot="{ item }">