Skip to content

Commit c7030a3

Browse files
fix: 云 API 权限 - MCP Server 展示 title (#2918)
1 parent ed27e8d commit c7030a3

2 files changed

Lines changed: 64 additions & 28 deletions

File tree

webfe/package_vue/src/common/utils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,35 @@ export function processNavData(data) {
154154
};
155155
}
156156

157+
/**
158+
* 根据关键字过滤列表数据,支持通过 'a.b.c' 路径匹配嵌套字段
159+
*
160+
* @param {Array} data - 待过滤列表
161+
* @param {String} keyword - 搜索关键字
162+
* @param {Array<String>} fields - 参与匹配的字段路径
163+
* @returns {Array} 过滤后的列表
164+
*/
165+
export function filterListByKeywordInFields(data = [], keyword = '', fields = []) {
166+
if (!keyword) {
167+
return data;
168+
}
169+
170+
const normalizedKeyword = keyword.toLowerCase();
171+
return data.filter(item => fields.some((field) => {
172+
const value = getNestedValue(item, field);
173+
return String(value || '')
174+
.toLowerCase()
175+
.includes(normalizedKeyword);
176+
}));
177+
}
178+
179+
function getNestedValue(obj, path) {
180+
if (!path.includes('.')) {
181+
return obj[path];
182+
}
183+
return path.split('.').reduce((acc, key) => acc?.[key], obj);
184+
}
185+
157186
/**
158187
* 获取元素相对于页面的高度
159188
*

webfe/package_vue/src/views/dev-center/app/basic-config/cloud-api/comps/mcp-server.vue

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,20 @@
8484
{{ $t('复制审批链接') }}
8585
</bk-button>
8686
</span>
87-
<span v-else-if="['name', 'description'].includes(column.prop)">
88-
<a
89-
v-if="row.mcp_server?.doc_link && column.prop === 'name'"
90-
:href="row.mcp_server?.doc_link"
91-
target="_blank"
92-
v-dompurify-html="highlight(row.mcp_server?.name || '--')"
93-
></a>
94-
<span
95-
v-else
96-
v-dompurify-html="highlight(row.mcp_server?.[column.prop] || '--')"
97-
></span>
87+
<a
88+
v-else-if="column.prop === 'name' && row.mcp_server?.doc_link"
89+
:href="row.mcp_server?.doc_link"
90+
target="_blank"
91+
class="text-ellipsis"
92+
v-dompurify-html="highlight(getDisplayName(row))"
93+
></a>
94+
<div
95+
v-else-if="column.prop === 'name'"
96+
class="text-ellipsis"
97+
v-dompurify-html="highlight(getDisplayName(row))"
98+
></div>
99+
<span v-else-if="column.prop === 'description'">
100+
<span v-dompurify-html="highlight(row.mcp_server?.description || '--')"></span>
98101
</span>
99102
<template v-else>
100103
{{ row.mcp_server?.[column.prop] || '--' }}
@@ -141,7 +144,7 @@
141144

142145
<script>
143146
import BatchDialog from './batch-apply-dialog';
144-
import { paginationFun } from '@/common/utils';
147+
import { filterListByKeywordInFields, paginationFun } from '@/common/utils';
145148
import { MCP_SERVER_STATUS } from '@/common/constants';
146149
import { debounce } from 'lodash';
147150
import { copy } from '@/common/tools';
@@ -288,23 +291,18 @@ export default {
288291
289292
// 获取过滤后的数据(根据搜索条件)
290293
getFilteredData() {
291-
console.log('this.headerFilterField', this.headerFilterField);
292-
if (!this.searchQuery && !this.headerFilterField) {
293-
return this.allMcpServerList;
294+
const keywordFilteredData = filterListByKeywordInFields(this.allMcpServerList, this.searchQuery, [
295+
'mcp_server.title',
296+
'mcp_server.name',
297+
'mcp_server.description',
298+
]);
299+
300+
if (!this.headerFilterField) {
301+
return keywordFilteredData;
294302
}
295-
const keyword = this.searchQuery.toLowerCase();
296-
return this.allMcpServerList.filter((item) => {
297-
console.log('item', item);
298-
const name = item.mcp_server?.name?.toLowerCase() || '';
299-
const description = item.mcp_server?.description?.toLowerCase() || '';
300-
const status = item.permission?.status || '';
301-
// 关键字搜索条件
302-
const keywordMatch = !this.searchQuery || name.includes(keyword) || description.includes(keyword);
303-
// 状态筛选条件
304-
const statusMatch = !this.headerFilterField || status === this.headerFilterField;
305-
// 同时满足关键字搜索和状态筛选条件
306-
return keywordMatch && statusMatch;
307-
});
303+
304+
// 表头状态过滤
305+
return keywordFilteredData.filter((item) => item.permission?.status === this.headerFilterField);
308306
},
309307
310308
// 分页处理
@@ -401,6 +399,12 @@ export default {
401399
copy(url, this);
402400
},
403401
402+
// 获取展示名称:title (name)
403+
getDisplayName(row) {
404+
const mcp = row.mcp_server || {};
405+
return `${mcp.title || '--'} (${mcp.name || '--'})`;
406+
},
407+
404408
// 搜索关键词高亮
405409
highlight(text) {
406410
const keyword = this.searchQuery;
@@ -435,5 +439,8 @@ export default {
435439
border-color: #2caf5e;
436440
}
437441
}
442+
.text-ellipsis {
443+
display: block;
444+
}
438445
}
439446
</style>

0 commit comments

Comments
 (0)