|
@@ -40,15 +40,15 @@
|
|
|
<div class="api-list-actions">
|
|
|
<el-button type="primary" size="small" @click="addSelectedApis">添加选中</el-button>
|
|
|
<el-button size="small" @click="selectAllVisible">选择当前页</el-button>
|
|
|
- <el-button size="small" @click="applyTemplate('readonly')">应用只读模板</el-button>
|
|
|
- <el-button size="small" @click="applyTemplate('fullaccess')">应用完全访问</el-button>
|
|
|
+ <!-- <el-button size="small" @click="applyTemplate('readonly')">应用只读模板</el-button>
|
|
|
+ <el-button size="small" @click="applyTemplate('fullaccess')">应用完全访问</el-button> -->
|
|
|
</div>
|
|
|
</div>
|
|
|
<el-table
|
|
|
ref="apiTable"
|
|
|
:data="availableApis"
|
|
|
style="width: 100%"
|
|
|
- height="500px"
|
|
|
+ height="450px"
|
|
|
v-loading="loading"
|
|
|
@selection-change="handleSelectionChange">
|
|
|
<el-table-column type="selection" width="55" />
|
|
@@ -145,6 +145,7 @@ import api from '/@/api/modules/apiHub';
|
|
|
interface ApiInfo {
|
|
|
id: number;
|
|
|
key: string;
|
|
|
+ apiKey: string; // 添加apiKey字段
|
|
|
name: string;
|
|
|
method: string;
|
|
|
path: string;
|
|
@@ -227,16 +228,20 @@ const getApiList = async () => {
|
|
|
|
|
|
const res = await api.list(params);
|
|
|
if (res) {
|
|
|
- availableApis.value = res.list.map((item: any) => ({
|
|
|
- id: item.id,
|
|
|
- key: item.key || `${item.id}`,
|
|
|
- name: item.name,
|
|
|
- method: item.method,
|
|
|
- path: item.path,
|
|
|
- status: item.status,
|
|
|
- groupId: item.groupId,
|
|
|
- groupName: item.groupName
|
|
|
- }));
|
|
|
+ availableApis.value = res.list.map((item: any) => {
|
|
|
+ // 使用APIKey作为唐一标识符
|
|
|
+ return {
|
|
|
+ id: item.id,
|
|
|
+ key: item.key || `${item.id}`,
|
|
|
+ apiKey: item.apiKey || item.key || `${item.id}`, // 使用apiKey或备选值
|
|
|
+ name: item.name,
|
|
|
+ method: item.method,
|
|
|
+ path: item.path,
|
|
|
+ status: item.status,
|
|
|
+ groupId: item.groupId,
|
|
|
+ groupName: item.groupName
|
|
|
+ };
|
|
|
+ });
|
|
|
total.value = res.total;
|
|
|
}
|
|
|
} catch (error) {
|
|
@@ -254,7 +259,8 @@ const getClientApis = async () => {
|
|
|
const res = await api.client.getApis(props.clientId);
|
|
|
if (res && Array.isArray(res)) {
|
|
|
selectedApis.value = res;
|
|
|
- selectedApiKeys.value = res.map(item => item.key);
|
|
|
+ // 使用apiKey字段或备选值
|
|
|
+ selectedApiKeys.value = res.map(item => item.apiKey || item.key || `${item.id}`);
|
|
|
}
|
|
|
} catch (error) {
|
|
|
ElMessage.error('获取客户端API失败');
|
|
@@ -318,11 +324,11 @@ const applyTemplate = async (templateId: string) => {
|
|
|
);
|
|
|
|
|
|
// 合并已有的API和模板中的API
|
|
|
- const existingKeys = new Set(selectedApiKeys.value);
|
|
|
- const newApis = filteredApis.filter(api => !existingKeys.has(api.key));
|
|
|
+ const existingApiIds = new Set(selectedApis.value.map(api => api.id));
|
|
|
+ const newApis = filteredApis.filter(api => !existingApiIds.has(api.id));
|
|
|
|
|
|
selectedApis.value = [...selectedApis.value, ...newApis];
|
|
|
- selectedApiKeys.value = selectedApis.value.map(api => api.key);
|
|
|
+ selectedApiKeys.value = selectedApis.value.map(api => api.apiKey);
|
|
|
|
|
|
ElMessage.success(`成功应用"${template.name}"模板,添加了${newApis.length}个API`);
|
|
|
}
|
|
@@ -343,8 +349,8 @@ const addSelectedApis = () => {
|
|
|
}
|
|
|
|
|
|
// 过滤掉已经选择的API
|
|
|
- const existingKeys = new Set(selectedApiKeys.value);
|
|
|
- const newApis = selectedRows.value.filter(api => !existingKeys.has(api.key));
|
|
|
+ const existingApiIds = new Set(selectedApis.value.map(api => api.id));
|
|
|
+ const newApis = selectedRows.value.filter(api => !existingApiIds.has(api.id));
|
|
|
|
|
|
if (newApis.length === 0) {
|
|
|
ElMessage.warning('所选API已经全部添加');
|
|
@@ -352,7 +358,7 @@ const addSelectedApis = () => {
|
|
|
}
|
|
|
|
|
|
selectedApis.value = [...selectedApis.value, ...newApis];
|
|
|
- selectedApiKeys.value = selectedApis.value.map(api => api.key);
|
|
|
+ selectedApiKeys.value = selectedApis.value.map(api => api.apiKey);
|
|
|
ElMessage.success(`成功添加${newApis.length}个API`);
|
|
|
|
|
|
// 清除表格选择
|
|
@@ -367,16 +373,16 @@ const addApi = (api: ApiInfo) => {
|
|
|
}
|
|
|
|
|
|
selectedApis.value.push(api);
|
|
|
- selectedApiKeys.value = selectedApis.value.map(item => item.key);
|
|
|
+ selectedApiKeys.value = selectedApis.value.map(item => item.apiKey);
|
|
|
ElMessage.success('添加成功');
|
|
|
};
|
|
|
|
|
|
// 移除单个API
|
|
|
const removeApi = (api: ApiInfo) => {
|
|
|
- const index = selectedApis.value.findIndex(item => item.key === api.key);
|
|
|
+ const index = selectedApis.value.findIndex(item => item.id === api.id);
|
|
|
if (index !== -1) {
|
|
|
selectedApis.value.splice(index, 1);
|
|
|
- selectedApiKeys.value = selectedApis.value.map(item => item.key);
|
|
|
+ selectedApiKeys.value = selectedApis.value.map(item => item.apiKey);
|
|
|
ElMessage.success('移除成功');
|
|
|
}
|
|
|
};
|
|
@@ -404,8 +410,10 @@ const removeAllSelected = async () => {
|
|
|
};
|
|
|
|
|
|
// 检查API是否已选中
|
|
|
-const isApiSelected = (apiKey: string) => {
|
|
|
- return selectedApiKeys.value.includes(apiKey);
|
|
|
+const isApiSelected = (key: string) => {
|
|
|
+ // 查找是否有包含此key的API
|
|
|
+ const api = selectedApis.value.find(api => api.key === key);
|
|
|
+ return !!api;
|
|
|
};
|
|
|
|
|
|
// 搜索API
|