LogoutActionHandler.java 1.04 KB
package cn.csbr.app.gui.handler;

import cn.csbr.app.FxApp;
import cn.csbr.app.auth.LoginService;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.page.WelcomePage;
import cn.csbr.app.gui.util.DialogUtils;
import javafx.event.Event;
import javafx.event.EventHandler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 登出
 */
@Component
public class LogoutActionHandler implements EventHandler {
    @Autowired
    private LoginService loginService;

    @Autowired
    private GUIContext context;

    @Autowired
    private WelcomePage welcomePage;

    @Override
    public void handle(Event event) {
        DialogUtils.showConfirm("是否退出系统?", v -> {
            loginService.logout();
            try {
              new  FxApp().stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.exit(0);
            context.updateMainContent(welcomePage.getContent());
        }, context.getPrimaryStage());
    }
}