fix:修改菜单管理兼容多系统

This commit is contained in:
zhangzhiqiang
2022-12-09 17:33:51 +08:00
parent db05e18cae
commit 79cf1955e5
8 changed files with 74 additions and 19 deletions

View File

@@ -23,6 +23,10 @@ import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.sso.system.service.MenuService;
import org.nl.sso.system.service.dto.MenuDto;
import org.nl.sso.tools.SecurityUtils;
@@ -33,6 +37,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;
@@ -51,10 +56,16 @@ public class MenuController {
@GetMapping(value = "/build")
@ApiOperation("根据用户获取菜单")
public ResponseEntity<Object> buildMenus() {
List<MenuDto> menuDtoList = menuService.findByUser(String.valueOf(SecurityUtils.getCurrentUserId()));
public ResponseEntity<Object> buildMenus(@Validated String system_type) {
//校验系统表是否存在该系统类型
JSONObject systemDict = WQLObject.getWQLObject("sys_dict").query("code = 'system_type' and value = '" + system_type + "'").uniqueResult(0);
if (systemDict == null || StringUtils.isEmpty(systemDict.getString("para1"))){
throw new BadRequestException("获取对应的系统菜单不存在");
}
String pid = systemDict.getString("para1");
List<MenuDto> menuDtoList = menuService.findByUser(String.valueOf(SecurityUtils.getCurrentUserId()),system_type);
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK);
return new ResponseEntity<>(menuService.buildMenus(menuDtos,pid),HttpStatus.OK);
}
@ApiOperation("返回全部的菜单")
@@ -89,6 +100,14 @@ public class MenuController {
@ApiOperation("查询菜单")
@SaCheckPermission("menu:list")
public ResponseEntity<Object> pageQuery(@RequestParam Map whereJson, Pageable page) throws Exception {
Object system_type = whereJson.get("system_type");
if (system_type!=null && whereJson.get("pid") == null){
JSONObject jsonObject = WQLObject.getWQLObject("sys_dict").query("code = 'system_type' and value = '" + system_type + "'").uniqueResult(0);
if (jsonObject==null || jsonObject.getString("para1") ==null){
throw new BadRequestException("字典表没有配置system_type系统相关参数");
}
whereJson.put("pid",jsonObject.getString("para1"));
}
JSONObject param = JSONObject.parseObject(JSON.toJSONString(whereJson));
JSONObject menuDtoList = menuService.queryAll(param, page);
return new ResponseEntity<>(menuDtoList, HttpStatus.OK);

View File

@@ -100,7 +100,7 @@ public interface MenuService {
* @param menuDtos /
* @return /
*/
Object buildMenus(List<MenuDto> menuDtos);
Object buildMenus(List<MenuDto> menuDtos,String pid);
/**
@@ -128,10 +128,10 @@ public interface MenuService {
List<MenuDto> getSuperior(MenuDto menuDto, List<MenuDto> objects);
/**
* 根据当前用户获取菜单
* 根据当前用户对应系统菜单
*
* @param currentUserId /
* @return /
*/
List<MenuDto> findByUser(String currentUserId);
List<MenuDto> findByUser(String currentUserId,String system_type);
}

View File

@@ -34,7 +34,7 @@ public class MenuServiceImpl implements MenuService {
@Override
public JSONObject queryAll(JSONObject param, Pageable page) throws Exception {
JSONObject json = WQL.getWO("QSYS_MENU01").addParam("flag", "1").addParam("pid", param.getString("pid")).pageQuery(WqlUtil.getHttpContext(page), "");
JSONObject json = WQL.getWO("QSYS_MENU01").addParam("flag", "1").addParam("system_type",param.getString("system_type")).addParam("pid", param.getString("pid")).pageQuery(WqlUtil.getHttpContext(page), "");
JSONArray content = json.getJSONArray("content");
JSONArray res = new JSONArray();
@@ -113,8 +113,8 @@ public class MenuServiceImpl implements MenuService {
* @return /
*/
@Override
public List<MenuDto> findByUser(String currentUserId) {
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "4").addParam("user_id", String.valueOf(currentUserId)).process().getResultJSONArray(0);
public List<MenuDto> findByUser(String currentUserId,String system_type) {
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "4").addParam("user_id", String.valueOf(currentUserId)).addParam("system_type",system_type).process().getResultJSONArray(0);
List<MenuDto> list = new ArrayList<>();
for (int i = 0; i < arr.size(); i++) {
JSONObject json = arr.getJSONObject(i);
@@ -316,7 +316,7 @@ public class MenuServiceImpl implements MenuService {
}
@Override
public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
public List<MenuVo> buildMenus(List<MenuDto> menuDtos,String pid) {
List<MenuVo> list = new LinkedList<>();
menuDtos.forEach(menuDTO -> {
if (menuDTO != null) {
@@ -324,13 +324,13 @@ public class MenuServiceImpl implements MenuService {
MenuVo menuVo = new MenuVo();
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponent_name()) ? menuDTO.getComponent_name() : menuDTO.getTitle());
// 一级目录需要加斜杠,不然会报警告
menuVo.setPath(StrUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
menuVo.setPath(pid.equals(menuDTO.getPid())? "/" + menuDTO.getPath() : menuDTO.getPath());
menuVo.setHidden(menuDTO.getHidden());
// 如果不是外链
if (!menuDTO.getI_frame()) {
if (StrUtil.isEmpty(menuDTO.getPid())) {
if (pid.equals(menuDTO.getPid())) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
} else if (!StrUtil.isEmpty(menuDTO.getPid()) && menuDTO.getType() == 0) {
} else if (!pid.equals(menuDTO.getPid()) && menuDTO.getType() == 0) {
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
@@ -341,7 +341,7 @@ public class MenuServiceImpl implements MenuService {
if (menuDtoList != null && menuDtoList.size() != 0) {
menuVo.setAlwaysShow(true);
menuVo.setRedirect("noredirect");
menuVo.setChildren(buildMenus(menuDtoList));
menuVo.setChildren(buildMenus(menuDtoList,pid));
// 处理是一级菜单并且没有子菜单的情况
} else if (StrUtil.isEmpty(menuDTO.getPid())) {
MenuVo menuVo1 = new MenuVo();

View File

@@ -16,6 +16,7 @@
输入.flag TYPEAS s_string
输入.system_type TYPEAS s_string
输入.category TYPEAS s_string
输入.system_type TYPEAS s_string
输入.user_id TYPEAS s_string
输入.pid TYPEAS s_string
@@ -51,6 +52,9 @@
FROM
sys_menu
where 1=1
OPTION 输入.system_type <> ""
system_type = 输入.system_type
ENDOPTION
OPTION 输入.pid <> ""
pid = 输入.pid
ENDOPTION
@@ -105,6 +109,7 @@
sys_menu
WHERE
type <> '2'
and system_type = 输入.system_type
and
menu_id IN (
SELECT

View File

@@ -49,4 +49,4 @@ export function edit(data) {
})
}
export default { add, edit, del }
export default { get, add, edit, del, getDictMap }

View File

@@ -42,9 +42,9 @@ export function getChild(id) {
})
}
export function buildMenus() {
export function buildMenus(data) {
return request({
url: 'api/menus/build',
url: 'api/menus/build?system_type=' + data,
method: 'get'
})
}
@@ -73,4 +73,4 @@ export function edit(data) {
})
}
export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus, getChild, getMenusByRole }
export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus, getChild, getMenusByRole }

View File

@@ -53,7 +53,8 @@ router.beforeEach((to, from, next) => {
})
export const loadMenus = (next, to) => {
buildMenus().then(res => {
// 配置字典数据库默认构建sso系统菜单
buildMenus(1).then(res => {
const sdata = JSON.parse(JSON.stringify(res))
const rdata = JSON.parse(JSON.stringify(res))
const sidebarRoutes = filterAsyncRouter(sdata)

View File

@@ -13,6 +13,18 @@
class="filter-item"
@keyup.enter.native="crud.toQuery"
/>
<el-select
v-model="query.system_type"
style="width: 150px"
placeholder="请选择系统"
@change="crud.toQuery"
>
<el-option
v-for="item in dict.system_type"
:label="item.label"
:value="item.value"
/>
</el-select>
<rrOperation />
</div>
<crudOperation :permission="permission" />
@@ -204,6 +216,7 @@ import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import DateRangePicker from '@/components/DateRangePicker'
import crudDictDetail from '@/api/system/dictDetail'
// crud交由presenter持有
const defaultForm = {
@@ -234,6 +247,8 @@ export default {
dicts: ['system_type'],
data() {
return {
typeList: [],
defaultType: '',
menus: [],
permission: {
add: ['admin', 'menu:add'],
@@ -257,7 +272,22 @@ export default {
}
}
},
beforeMount() {
// const _this=this
// crudDictDetail.get('system_type').then(data => {
// if (data.content.length > 0) {
// const shift = data.content.shift()
// _this.defaultType = shift.para1
// }
// })
},
methods: {
[CRUD.HOOK.beforeRefresh]() {
if (this.crud.query.system_type == null) {
this.crud.query.system_type = '1'
}
return true
},
// 新增与编辑前做的操作
[CRUD.HOOK.afterToCU](crud, form) {
console.log(this.dict)