WithAuthToPageBaseHandler.java
4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package cn.csbr.app.gui.handler;
import cn.csbr.app.auth.LoginService;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.LoginPage;
import cn.csbr.app.gui.page.MainPage;
import cn.csbr.app.gui.page.Page;
import cn.csbr.app.gui.page.WelcomePage;
import cn.csbr.app.gui.util.DialogUtils;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
/**
* 这个类实现eventhandler。
* 需要实现页面跳转的handler都要继承自这个类。
* 类中在跳转前会做权限查询。 并且提供了一个基础方法
* @param <T>
*/
public abstract class WithAuthToPageBaseHandler<T extends Page> implements EventHandler{
@Autowired
private GUIContext context;
@Autowired
private LoginService loginService;
@Autowired
private MainPage mainPage;
@Autowired
private WelcomePage welcomePage;
@Autowired
private FxConfigure fxConfigure;
@Autowired
private LoginPage loginPage;
@Value("${PiccMode}")
private String PiccMode;
@Override
public void handle(Event event) {
if(GUIContext.isreturn){
GUIContext.isreturn=false;
this.context.setCurrentPage(null);
T page = createPage();
toPre(page);
page.refresh();
context.updateMainContent(page.getContent());
toEnd(page);
return;
}
int i=0;
if (ifAuthCheck() && !fxConfigure.isNodatabase()) {
String menucode = getMenuCode();
// System.out.println(menucode);
if("h_zw".equals(menucode)||"h_card".equals(menucode)) {
if(GUIContext.isOK==1){
this.context.setCurrentPage(null);
T page = createPage();
toPre(page);
page.refresh();
context.updateMainContent(page.getContent());
toEnd(page);
}
return;
}
if ("h_reject".equals(menucode)||"h_query".equals(menucode)|| "h_setting".equals(menucode)||"h_banlance".equals(menucode)||"h_check".equals(menucode) ) {//退货设置操作
if ("h_reject".equals(menucode)||"h_query".equals(menucode) || "h_setting".equals(menucode)||"h_banlance".equals(menucode))
{
// if (context.getLoginUserVali() == null) {
loginPage.start(context.getPrimaryStage());
//}
}
else
{
if(PiccMode.equals("1")) {
if ("h_check".equals(menucode) || "h_query".equals(menucode)) {//退货设置操作
// if (context.getLoginUserVali() == null) {
loginPage.start(context.getPrimaryStage());
//}
}else {
GUIContext.isOK=1;
}
}
else {
GUIContext.isOK=1;
}
}
}else {
try {
boolean exist = loginService.menusExist(menucode);
if (!exist) {
Platform.runLater(() -> {
DialogUtils.showHeaderTextInformationAlert("您无此操作权限!", context.getPrimaryStage());
});
return;
}
} catch (Exception e) {
Platform.runLater(() -> {
DialogUtils.showAlert(e.getMessage(), v -> {
context.updateMainContent(welcomePage.getContent());
});
});
return;
}
}
}
if(GUIContext.isOK==1){
this.context.setCurrentPage(null);
T page = createPage();
toPre(page);
page.refresh();
context.updateMainContent(page.getContent());
toEnd(page);
}
}
protected boolean ifAuthCheck() {
return true;
}
abstract protected String getMenuCode();
abstract protected T createPage();
abstract protected void toPre(T page);
abstract protected void toEnd(T page);
public void setMenuCode(String code){
}
}