Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

角色管理显示分组翻译,API管理显示原始分组字段 #149

Merged
merged 7 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions api/internal/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
"validationError": "Operation failed: Validation failed",
"notSingularError": "Operation failed: Data not unique"
},
"apiGroup":{
"member_rank": "Member Rank",
"member": "Member",
"tag": "Tag",
"file": "File",
"task_log": "Task Log",
"task": "Task",
"position": "Position",
"department": "Department",
"token": "Token",
"oauth": "Oauth",
"dictionary": "Dictionary",
"api": "API",
"authority": "Authority",
"captcha": "Captcha",
"menu": "Menu",
"role": "Role",
"user": "User"
},
"apiDesc": {
"createTag": "Create a tag",
"updateTag": "Update the tag",
Expand Down
19 changes: 19 additions & 0 deletions api/internal/i18n/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
"validationError": "操作失败: 校验失败",
"notSingularError": "操作失败: 数据不唯一"
},
"apiGroup":{
"member_rank": "等级管理",
"member": "会员管理",
"tag": "标签管理",
"file": "文件管理",
"task_log": "任务日志",
"task": "任务管理",
"position": "职位管理",
"department": "部门管理",
"token": "令牌管理",
"oauth": "认证管理",
"dictionary": "字典管理",
"api": "接口管理",
"authority": "授权管理",
"captcha": "验证代码",
"menu": "菜单管理",
"role": "角色管理",
"user": "用户管理"
},
"apiDesc": {
"createTag": "创建文件标签",
"updateTag": "更新文件标签",
Expand Down
15 changes: 14 additions & 1 deletion api/internal/logic/api/get_api_list_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiList
resp.Msg = l.svcCtx.Trans.Trans(l.ctx, i18n.Success)
resp.Data.Total = data.GetTotal()

// 接口分组翻译
var group = make(map[string]string)
for _, v := range data.Data {
// 在角色管理页面调用该接口时为了获取所有接口,每页大小被设置为10000
// 因此可以根据每页数据大小来判断,该请求是否为来自角色管理页面
// 如果是来自API管理的请求则不去获取分组翻译,直接显示原本字段
if req.PageSize > 1000 {
// 检测是否存在分组翻译,避免多次获取
if _, exist := group[*v.ApiGroup]; !exist {
group[*v.ApiGroup] = l.svcCtx.Trans.Trans(l.ctx, "apiGroup."+*v.ApiGroup)
}
// 直接将分组字段更新为分组翻译内容
*v.ApiGroup = group[*v.ApiGroup]
}
resp.Data.Data = append(resp.Data.Data,
types.ApiInfo{
BaseIDInfo: types.BaseIDInfo{
Expand All @@ -54,7 +67,7 @@ func (l *GetApiListLogic) GetApiList(req *types.ApiListReq) (resp *types.ApiList
Path: v.Path,
Trans: l.svcCtx.Trans.Trans(l.ctx, *v.Description),
Description: v.Description,
Group: v.ApiGroup,
Group: v.ApiGroup, // 根据页大小决定显示原本字段还是分组字段
Method: v.Method,
})
}
Expand Down
4 changes: 2 additions & 2 deletions api/internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.