完善:完善菜单相关代码逻辑,优化部分细节
This commit is contained in:
parent
6d3ba478e9
commit
a09711c04e
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.util;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
/**
|
||||
* URL(Uniform Resource Locator)统一资源定位符相关工具类
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/3/20 21:27
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class URLUtils {
|
||||
|
||||
/**
|
||||
* 提供的 URL 是否为 HTTP URL(协议包括:"http","https")
|
||||
*
|
||||
* @param url
|
||||
* URL
|
||||
* @return 是否为 HTTP URL
|
||||
*/
|
||||
public static boolean isHttpUrl(String url) {
|
||||
return HttpUtil.isHttp(url) || HttpUtil.isHttps(url);
|
||||
}
|
||||
}
|
@ -47,4 +47,22 @@ public class MetaVO implements Serializable {
|
||||
*/
|
||||
@Schema(description = "菜单图标")
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 是否隐藏
|
||||
*/
|
||||
@Schema(description = "是否隐藏")
|
||||
private Boolean hideInMenu;
|
||||
|
||||
/**
|
||||
* 是否缓存
|
||||
*/
|
||||
@Schema(description = "是否缓存")
|
||||
private Boolean ignoreCache;
|
||||
|
||||
/**
|
||||
* 是否需要登录才能访问
|
||||
*/
|
||||
@Schema(description = "是否需要登录才能访问")
|
||||
private Boolean requiresAuth = true;
|
||||
}
|
||||
|
@ -121,6 +121,8 @@ public class LoginServiceImpl implements LoginService {
|
||||
MetaVO metaVO = new MetaVO();
|
||||
metaVO.setLocale(m.getTitle());
|
||||
metaVO.setIcon(m.getIcon());
|
||||
metaVO.setIgnoreCache(!m.getIsCache());
|
||||
metaVO.setHideInMenu(m.getIsHidden());
|
||||
tree.putExtra("meta", metaVO);
|
||||
});
|
||||
return BeanUtil.copyToList(treeList, RouteVO.class);
|
||||
|
@ -136,19 +136,19 @@
|
||||
</a-table-column>
|
||||
<a-table-column title="外链" align="center">
|
||||
<template #cell="{ record }">
|
||||
<a-tag v-if="record.isExternal" color="green">是</a-tag>
|
||||
<a-tag v-if="record.isExternal" color="arcoblue">是</a-tag>
|
||||
<a-tag v-else color="red">否</a-tag>
|
||||
</template>
|
||||
</a-table-column>
|
||||
<a-table-column title="缓存" align="center">
|
||||
<template #cell="{ record }">
|
||||
<a-tag v-if="record.isCache" color="green">是</a-tag>
|
||||
<a-tag v-if="record.isCache" color="arcoblue">是</a-tag>
|
||||
<a-tag v-else color="red">否</a-tag>
|
||||
</template>
|
||||
</a-table-column>
|
||||
<a-table-column title="隐藏" align="center">
|
||||
<template #cell="{ record }">
|
||||
<a-tag v-if="record.isHidden" color="green">是</a-tag>
|
||||
<a-tag v-if="record.isHidden" color="arcoblue">是</a-tag>
|
||||
<a-tag v-else color="red">否</a-tag>
|
||||
</template>
|
||||
</a-table-column>
|
||||
|
@ -20,10 +20,20 @@ import static top.charles7c.cnadmin.common.annotation.CrudRequestMapping.Api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.annotation.CrudRequestMapping;
|
||||
import top.charles7c.cnadmin.common.base.BaseController;
|
||||
import top.charles7c.cnadmin.common.base.BaseRequest;
|
||||
import top.charles7c.cnadmin.common.model.vo.R;
|
||||
import top.charles7c.cnadmin.common.util.URLUtils;
|
||||
import top.charles7c.cnadmin.common.util.validate.ValidationUtils;
|
||||
import top.charles7c.cnadmin.system.model.query.MenuQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.MenuRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.MenuVO;
|
||||
@ -38,4 +48,32 @@ import top.charles7c.cnadmin.system.service.MenuService;
|
||||
@Tag(name = "菜单管理 API")
|
||||
@RestController
|
||||
@CrudRequestMapping(value = "/system/menu", api = {Api.TREE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT})
|
||||
public class MenuController extends BaseController<MenuService, MenuVO, MenuVO, MenuQuery, MenuRequest> {}
|
||||
public class MenuController extends BaseController<MenuService, MenuVO, MenuVO, MenuQuery, MenuRequest> {
|
||||
|
||||
@Override
|
||||
@SaCheckPermission("system:menu:add")
|
||||
protected R<Long> add(@Validated(BaseRequest.Add.class) @RequestBody MenuRequest request) {
|
||||
this.checkPath(request);
|
||||
return super.add(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SaCheckPermission("system:menu:update")
|
||||
protected R update(@Validated(BaseRequest.Update.class) @RequestBody MenuRequest request, @PathVariable Long id) {
|
||||
this.checkPath(request);
|
||||
return super.update(request, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查路由地址格式
|
||||
*
|
||||
* @param request
|
||||
* 创建或修改信息
|
||||
*/
|
||||
private void checkPath(MenuRequest request) {
|
||||
Boolean isExternal = ObjectUtil.defaultIfNull(request.getIsExternal(), false);
|
||||
String path = request.getPath();
|
||||
ValidationUtils.throwIf(isExternal && !URLUtils.isHttpUrl(path), "路由地址格式错误,请以 http:// 或 https:// 开头");
|
||||
ValidationUtils.throwIf(!isExternal && URLUtils.isHttpUrl(path), "路由地址格式错误");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user