Browse Source

feat:优化APIHUB客户端权限保存

microrain 5 months ago
parent
commit
485cfa18f6
2 changed files with 11 additions and 7 deletions
  1. 1 1
      src/views/apihub/client.vue
  2. 10 6
      src/views/apihub/component/ClientApiRelation.vue

+ 1 - 1
src/views/apihub/client.vue

@@ -52,7 +52,7 @@
               <span v-else>{{ scope.row.status }}</span>
             </template>
           </el-table-column>
-          <el-table-column prop="createdAt" label="创建时间" width="160" align="center"></el-table-column>
+<!--          <el-table-column prop="createdAt" label="创建时间" width="160" align="center"></el-table-column>-->
           <el-table-column label="操作" width="300" align="center" fixed="right">
             <template #default="scope">
               <div class="flex-row">

+ 10 - 6
src/views/apihub/component/ClientApiRelation.vue

@@ -78,7 +78,7 @@
                     type="primary" 
                     size="small" 
                     @click="addApi(scope.row)"
-                    :disabled="isApiSelected(scope.row.key)">
+                    :disabled="isApiSelected(scope.row)">
                     添加
                   </el-button>
                 </template>
@@ -367,7 +367,7 @@ const addSelectedApis = () => {
 
 // 添加单个API
 const addApi = (api: ApiInfo) => {
-  if (isApiSelected(api.key)) {
+  if (isApiSelected(api)) {
     ElMessage.warning('该API已添加');
     return;
   }
@@ -410,10 +410,14 @@ const removeAllSelected = async () => {
 };
 
 // 检查API是否已选中
-const isApiSelected = (key: string) => {
-  // 查找是否有包含此key的API
-  const api = selectedApis.value.find(api => api.key === key);
-  return !!api;
+const isApiSelected = (api: ApiInfo) => {
+  // 获取API的apiKey或备选标识符
+  const apiIdentifier = api.apiKey || api.key || `${api.id}`;
+  // 遍历已选中的API数组,检查是否已存在相同的apiKey
+  return selectedApis.value.some(selectedApi => {
+    const selectedApiIdentifier = selectedApi.apiKey || selectedApi.key || `${selectedApi.id}`;
+    return apiIdentifier === selectedApiIdentifier;
+  });
 };
 
 // 搜索API