瀏覽代碼

feat(setting): 实现设备配置排序功能

- 启用排序按钮并完善其交互逻辑
- 引入 sortDeviceConfig 接口用于保存排序结果- 更新排序字段名称为 action_index
- 移除旧的 IPC 排序事件监听与调用方式
- 新增排序成功后的提示信息及列表刷新逻辑- 在 setting.ts 中添加 sortDeviceConfig 方法实现前后端同步排序
- 删除冗余代码和无用的条件分支
panqiuyao 2 月之前
父節點
當前提交
c012c81cb6
共有 3 個文件被更改,包括 36 次插入32 次删除
  1. 24 0
      frontend/src/apis/setting.ts
  2. 0 1
      frontend/src/utils/ipc.ts
  3. 12 31
      frontend/src/views/Setting/components/action_config.vue

+ 24 - 0
frontend/src/apis/setting.ts

@@ -92,6 +92,30 @@ export async function restConfig(data){
 }
 
 
+
+//排序
+export async function sortDeviceConfig(data){
+    console.log(data);
+    const result = await POST('/api/ai_image/camera_machine/sort_device_config',data);
+
+    // 同步到Python
+    try {
+        const clientStore = client();
+        const tokenInfoStore = tokenInfo();
+        const token = tokenInfoStore.getToken;
+        await clientStore.ipc.invoke(icpList.setting.syncActions, {
+            token: token || '',
+            action: 'sort',
+        });
+    } catch (error) {
+        console.error('同步重置配置到Python失败:', error);
+        // 同步失败不影响主流程
+    }
+
+    return result;
+}
+
+
 //更新顶部TOP
 export async function setTabName(data){
     const result = await POST('/api/ai_image/camera_machine/update_tab_name',data);

+ 0 - 1
frontend/src/utils/ipc.ts

@@ -34,7 +34,6 @@ const icpList = {
         getSysConfig: 'controller.setting.getSysConfig',
         updateSysConfigs: 'controller.setting.updateSysConfigs',
         updateTabName: 'controller.setting.updateTabName',
-        updateDeviceConfigSort: 'controller.setting.updateDeviceConfigSort',
         syncSysConfigs: 'controller.setting.syncSysConfigs',
         syncActions: 'controller.setting.syncActions'
     },

+ 12 - 31
frontend/src/views/Setting/components/action_config.vue

@@ -23,9 +23,9 @@
       <div class="primary-btn" @click="addRow" v-log="{ describe: { action: '点击新增一行' } }" :class="{ disabled: isSortMode }" :style="{ opacity: isSortMode ? 0.5 : 1, cursor: isSortMode ? 'not-allowed' : 'pointer' }">新增一行</div>
       <div class="primary-btn" @click="resetConfig" v-log="{ describe: { action: '点击重新初始化', tab: topsTab } }" :class="{ disabled: isSortMode }" :style="{ opacity: isSortMode ? 0.5 : 1, cursor: isSortMode ? 'not-allowed' : 'pointer' }">重新初始化</div>
       <div class="primary-btn" @click="reName" v-log="{ describe: { action: '点击重命名配置' } }" :class="{ disabled: isSortMode }" :style="{ opacity: isSortMode ? 0.5 : 1, cursor: isSortMode ? 'not-allowed' : 'pointer' }">重命名配置</div>
-<!--      <div class="primary-btn" @click="toggleSortMode" v-log="{ describe: { action: isSortMode ? '点击保存排序' : '点击排序' } }">
+      <div class="primary-btn" @click="toggleSortMode" v-log="{ describe: { action: isSortMode ? '点击保存排序' : '点击排序' } }">
         {{ isSortMode ? '保存排序' : '排序' }}
-      </div>-->
+      </div>
       <div v-if="isSortMode" class="normal-btn" @click="cancelSort" v-log="{ describe: { action: '点击取消排序' } }">
         取消排序
       </div>
@@ -101,7 +101,7 @@ import socket from "@/stores/modules/socket";
 const socketStore = socket(); // WebSocket状态管理实例
 const tokenInfoStore = tokenInfo();
 
-import  { getTopTabs, getDeviceConfigs,setLeftRightConfig,restConfig,setTabName,delDviceConfig } from '@/apis/setting'
+import  { getTopTabs, getDeviceConfigs,setLeftRightConfig,restConfig,sortDeviceConfig,setTabName,delDviceConfig } from '@/apis/setting'
 
 // 表格数据和对话框状态
 const tableData = ref([]); // 配置表格数据
@@ -233,7 +233,6 @@ const getList = async () => {
     if(calibration.length >= 1){
       calibrationId.value = calibration[0].id
     }else{
-
       calibrationId.value = tableData.value[0].id
     }
   }
@@ -504,39 +503,21 @@ const initSortable = () => {
 /**
  * 保存排序
  */
-const saveSortOrder = () => {
+const saveSortOrder = async () => {
   // 准备排序数据
   const sortData = tableData.value.map((item, index) => ({
     id: item.id,
-    sort: index + 1
+    action_index: index + 1
   }));
 
-  console.log("sort_data",{
-    tab_id: activeTab.value.id,
-    sort_data: sortData
+  console.log("sort_data",sortData)
+  const result =  await sortDeviceConfig({
+    sorts: sortData
   })
-  // 调用后端接口保存排序
-  clientStore.ipc.removeAllListeners(icpList.setting.updateDeviceConfigSort);
-  clientStore.ipc.send(icpList.setting.updateDeviceConfigSort, {
-    tab_id: activeTab.value.id,
-    sort_data: sortData
-  });
-
-  clientStore.ipc.on(icpList.setting.updateDeviceConfigSort, (event, result) => {
-    if (result.code == 0) {
-      ElMessage.success('排序保存成功');
-      isSortMode.value = false;
-      // 重新获取列表以更新数据
-      getList();
-    } else if (result.mssg) {
-      ElMessage.error(result.mssg);
-    } else {
-      ElMessage.error('排序保存失败');
-      // 保存失败时退出排序模式
-      exitSortMode();
-    }
-    clientStore.ipc.removeAllListeners(icpList.setting.updateDeviceConfigSort);
-  });
+  if (result.code == 0) {
+    getList();
+    ElMessage.success('排序成功');
+  }
 };
 
 /**