Skip to content

Commit

Permalink
feat: 添加 API 时根据所选服务提供 url 建议
Browse files Browse the repository at this point in the history
  • Loading branch information
cadecode committed Aug 19, 2023
1 parent 5d34a40 commit 82b80f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/api/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ export function removeRoleApi(data) {
});
}

export function listApiSwaggerVo(data) {
export function listSwaggerDescVo(serviceUrl, data) {
return request({
url: '/framework/system/api/list_swagger_vo',
url: serviceUrl + '/plugin/swagger/list_desc_vo',
method: 'post',
data
});
Expand Down
34 changes: 31 additions & 3 deletions src/view/System/Api/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
:model="addApiForm.data"
:rules="addApiForm.rule"
>
<el-form-item label="服务" prop="serviceUrl">
<el-select v-model="addApiForm.data.serviceUrl" filterable placeholder="请选择" @change="handleServiceUrlChange">
<el-option
v-for="item in addApiForm.option.serviceUrl"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="接口路径" prop="url">
<el-autocomplete v-model="addApiForm.data.url" :fetch-suggestions="listUrlSuggest" @select="handleUrlSelect" />
</el-form-item>
Expand All @@ -127,7 +137,7 @@ import {
addRoleApi,
deleteApi,
listApiRolesVoByApiIds,
listApiSwaggerVo,
listSwaggerDescVo, listDictByType,
listRole,
pageApiRolesVo,
removeRoleApi,
Expand Down Expand Up @@ -178,23 +188,38 @@ export default {
},
addApiForm: {
data: {
serviceUrl: null,
url: null,
description: null
},
showDialog: false,
urlSuggestList: null,
rule: {
url: [{required: true, message: '请输入接口路径', trigger: 'blur'}],
description: [{required: true, message: '请输入描述', trigger: 'blur'}]
description: [{required: true, message: '请输入描述', trigger: 'blur'}],
serviceUrl: [{required: true, message: '请选择服务', trigger: 'blur'}]
},
option: {
serviceUrl: []
}
}
};
},
created() {
this.listServiceUrl();
this.pageApis(1);
this.loadRoleTree();
},
methods: {
listServiceUrl() {
listDictByType('serviceUrl').then(res => {
this.addApiForm.option.serviceUrl = res.data;
const defaultUrl = this.addApiForm.option.serviceUrl.filter(o => o.defaultFlag)[0];
if (defaultUrl) {
this.addApiForm.data.serviceUrl = defaultUrl.value;
}
});
},
pageApis(currPage) {
// 分页插件回调传递当前页号
const data = {
Expand Down Expand Up @@ -301,7 +326,7 @@ export default {
cb(this.addApiForm.urlSuggestList.filter(o => o.value.includes(queryString)));
return;
}
listApiSwaggerVo().then(res => {
listSwaggerDescVo(this.addApiForm.data.serviceUrl).then(res => {
res.data.forEach(o => { o.value = o.description ? `${o.url} | ${o.description}` : o.url; });
this.addApiForm.urlSuggestList = res.data;
cb(res.data);
Expand All @@ -310,6 +335,9 @@ export default {
handleUrlSelect(item) {
this.addApiForm.data.url = item.url;
this.addApiForm.data.description = item.description;
},
handleServiceUrlChange() {
this.addApiForm.urlSuggestList = null;
}
}
};
Expand Down

0 comments on commit 82b80f0

Please sign in to comment.