|
|
@@ -1,13 +1,17 @@
|
|
|
package cn.reghao.devops.manager.account.controller;
|
|
|
|
|
|
+import cn.reghao.devops.manager.account.model.po.Menu;
|
|
|
+import cn.reghao.devops.manager.account.model.po.User;
|
|
|
+import cn.reghao.devops.manager.account.service.IndexService;
|
|
|
+import cn.reghao.devops.manager.util.UserContext;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.boot.web.servlet.error.ErrorController;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -16,34 +20,30 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
@Slf4j
|
|
|
@Api(tags = "登录页和首页")
|
|
|
@Controller
|
|
|
-public class AccountAuthController /*implements ErrorController*/ {
|
|
|
+public class AccountAuthController {
|
|
|
+ private final IndexService indexService;
|
|
|
+
|
|
|
+ public AccountAuthController(IndexService indexService) {
|
|
|
+ this.indexService = indexService;
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/login")
|
|
|
public String toLogin(Model model) {
|
|
|
model.addAttribute("isCaptcha", false);
|
|
|
return "/login";
|
|
|
}
|
|
|
|
|
|
- /*@Override
|
|
|
- public String getErrorPath() {
|
|
|
- return "/error";
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/error")
|
|
|
- public String handleError(Model model, HttpServletRequest request) {
|
|
|
- Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
|
|
- log.error("http status code: " + statusCode);
|
|
|
- if (statusCode == 404) {
|
|
|
- model.addAttribute("statusCode", statusCode);
|
|
|
- model.addAttribute("msg", "页面去火星啦~");
|
|
|
- return "/404";
|
|
|
- } else if (statusCode == 400) {
|
|
|
- return "参数错误";
|
|
|
- } else if (statusCode == 500) {
|
|
|
- return "服务器内部错误";
|
|
|
+ @GetMapping("/")
|
|
|
+ public String index(Model model) throws Exception {
|
|
|
+ User user = UserContext.getUser();
|
|
|
+ if (user == null) {
|
|
|
+ throw new Exception("未登录");
|
|
|
}
|
|
|
|
|
|
- model.addAttribute("statusCode", statusCode);
|
|
|
- model.addAttribute("msg", "页面去火星啦~");
|
|
|
- return "/404";
|
|
|
- }*/
|
|
|
+ List<Menu> menus = indexService.userMenus(user.getRole());
|
|
|
+ Map<Integer, Menu> treeMenu = indexService.treeMenu(menus);
|
|
|
+ model.addAttribute("user", user);
|
|
|
+ model.addAttribute("treeMenu", treeMenu);
|
|
|
+ return "/main";
|
|
|
+ }
|
|
|
}
|