diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java index 2845ccece3..f9369928e1 100644 --- a/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java @@ -75,7 +75,6 @@ public class BBSLoginDialog extends UIDialog { // 用户登录状态label private UserInfoLabel userInfoLabel; - public UILabel getTipLabel() { return tipLabel; } @@ -84,7 +83,6 @@ public class BBSLoginDialog extends UIDialog { this.tipLabel = tipLabel; } - /** * 构造函数 * @@ -213,7 +211,6 @@ public class BBSLoginDialog extends UIDialog { DesignerEnvManager.getEnvManager().setBBSPassword(String.valueOf(passField.getPassword())); userInfoLabel.setUserName(nameField.getText()); userInfoLabel.getUserInfoPane().markSignIn(nameField.getText()); - userInfoLabel.getUserInfoPane().getSwitchAccountLabel().setVisible(true); BBSLoginDialog.this.setVisible(false); } diff --git a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java b/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java new file mode 100644 index 0000000000..1d1926bf9e --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java @@ -0,0 +1,35 @@ +package com.fr.design.mainframe.bbs; + +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.general.SiteCenter; +import com.fr.general.http.HttpClient; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; + +/** + * Created by zhaohehe on 16/7/26. + */ +public class LoginDialog extends UIDialog { + private static final Dimension DEFAULT_SHOP = new Dimension(404, 234); + + public LoginDialog(Frame frame, BasicPane pane) { + super(frame); + setUndecorated(true); + JPanel panel = (JPanel) getContentPane(); + panel.setLayout(new BorderLayout()); + add(pane, BorderLayout.CENTER); + setSize(DEFAULT_SHOP); + GUICoreUtils.centerWindow(this); + setResizable(false); + setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); + } + + @Override + public void checkValid() throws Exception { + } +} diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java index 712bba5ebe..a2e0946c53 100644 --- a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java @@ -5,12 +5,16 @@ package com.fr.design.mainframe.bbs; import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; -import com.fr.design.extra.LoginCheckContext; -import com.fr.design.extra.LoginCheckListener; +import com.fr.design.dialog.UIDialog; +import com.fr.design.extra.*; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.DateUtils; +import com.fr.general.Inter; import com.fr.general.SiteCenter; import com.fr.general.http.HttpClient; import com.fr.stable.EncodeConstants; @@ -41,7 +45,7 @@ public class UserInfoLabel extends UILabel{ private static final String MESSAGE_KEY = "messageCount"; private static final int MIN_MESSAGE_COUNT = 1; - + private static final int MENU_HEIGHT = 20; //用户名 private String userName; @@ -87,6 +91,19 @@ public class UserInfoLabel extends UILabel{ bbsLoginDialog.showWindow(); } }); + + UserLoginContext.addLoginContextListener(new LoginContextListener() { + @Override + public void showLoginContext() { + LoginPane managerPane = new LoginPane(); + UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(),managerPane); + LoginWebBridge.getHelper().setDialogHandle(qqdlg); + LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this); + QQLoginWebBridge.getHelper().setLoginlabel(); + qqdlg.setVisible(true); + } + }); + } /** @@ -242,22 +259,41 @@ public class UserInfoLabel extends UILabel{ @Override public void mouseClicked(MouseEvent e) { - if(StringUtils.isNotEmpty(userName)){ - try { - Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); - } catch (Exception exp) { + if(StringUtils.isNotEmpty(userName)) { + UIPopupMenu menu = new UIPopupMenu(); + menu.setOnlyText(true); + menu.setPopupSize(userInfoPane.getWidth(),userInfoPane.getHeight()*3); + + //私人消息 + UIMenuItem priviteMessage = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Privite-Message")); + priviteMessage.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + if(StringUtils.isNotEmpty(userName)){ + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); + } catch (Exception exp) { + FRContext.getLogger().info(exp.getMessage()); + } + return; + } + } - } - return; + }); + //切换账号 + UIMenuItem closeOther = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")); + closeOther.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + UserLoginContext.fireLoginContextListener(); + } + + }); + menu.add(priviteMessage); + menu.add(closeOther); + GUICoreUtils.showPopupMenu(menu, UserInfoLabel.this, 0, MENU_HEIGHT); + } else { + UserLoginContext.fireLoginContextListener(); } - if(bbsLoginDialog == null){ - bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(),UserInfoLabel.this); - } - bbsLoginDialog.clearLoginInformation(); - bbsLoginDialog.setModal(true); - bbsLoginDialog.showWindow(); } - }; } \ No newline at end of file diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java index 45593f2a6d..b73ac67179 100644 --- a/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java @@ -40,8 +40,6 @@ public class UserInfoPane extends BasicPane{ private static final int WAIT_TIME = 10000; private UserInfoLabel userInfoLabel; - private ExitLabel switchAccountLabel; - public UserInfoLabel getUserInfoLabel() { return userInfoLabel; @@ -51,13 +49,6 @@ public class UserInfoPane extends BasicPane{ this.userInfoLabel = userInfoLabel; } - public ExitLabel getSwitchAccountLabel() { - return switchAccountLabel; - } - - public void setSwitchAccountLabel(ExitLabel switchAccountLabel) { - this.switchAccountLabel = switchAccountLabel; - } /** * 构造函数 @@ -67,14 +58,12 @@ public class UserInfoPane extends BasicPane{ this.setLayout(new BorderLayout()); this.userInfoLabel = new UserInfoLabel(this); - this.switchAccountLabel = new ExitLabel(this); - + this.markUnSignIn(); autoLogin(); autoPushLoginDialog(); this.add(userInfoLabel, BorderLayout.CENTER); - this.add(switchAccountLabel, BorderLayout.EAST); } // 后台自动登录 @@ -149,7 +138,7 @@ public class UserInfoPane extends BasicPane{ bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(),userInfoLabel); userInfoLabel.setBbsLoginDialog(bbsLoginDialog); } - + bbsLoginDialog.showWindow(); DesignerEnvManager.getEnvManager().setLastShowBBSTime(DateUtils.DATEFORMAT2.format(new Date())); } @@ -164,11 +153,9 @@ public class UserInfoPane extends BasicPane{ */ public void markUnSignIn(){ this.userInfoLabel.setText(Inter.getLocText("FR-Base_UnSignIn")); - this.switchAccountLabel.setVisible(false); this.userInfoLabel.setOpaque(true); this.userInfoLabel.setBackground(UN_LOGIN_BACKGROUND); this.userInfoLabel.resetUserName(); - } /** @@ -179,11 +166,8 @@ public class UserInfoPane extends BasicPane{ public void markSignIn(String userName){ this.userInfoLabel.setText(userName); this.userInfoLabel.setUserName(userName); - this.switchAccountLabel.setVisible(true); this.userInfoLabel.setOpaque(true); this.userInfoLabel.setBackground(LOGIN_BACKGROUND); - this.switchAccountLabel.setOpaque(true); - this.switchAccountLabel.setBackground(LOGIN_BACKGROUND); } @Override @@ -191,5 +175,4 @@ public class UserInfoPane extends BasicPane{ return StringUtils.EMPTY; } - } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginContextListener.java b/designer_base/src/com/fr/design/extra/LoginContextListener.java new file mode 100644 index 0000000000..ca13544432 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/LoginContextListener.java @@ -0,0 +1,8 @@ +package com.fr.design.extra; + +/** + * Created by lp on 2016/8/16. + */ +public interface LoginContextListener { + void showLoginContext(); +} diff --git a/designer_base/src/com/fr/design/extra/LoginPane.java b/designer_base/src/com/fr/design/extra/LoginPane.java new file mode 100644 index 0000000000..f49088af20 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/LoginPane.java @@ -0,0 +1,43 @@ +package com.fr.design.extra; + +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.stable.StableUtils; + +import java.awt.*; +import java.io.File; +import java.net.URL; + +/** + * Created by zhaohehe on 16/7/27. + */ +public class LoginPane extends BasicPane { + private static final String LATEST = "latest"; + + public LoginPane() { + setLayout(new BorderLayout()); + if (StableUtils.getMajorJavaVersion() == 8) { + String installHome; + if (StableUtils.isDebug()) { + URL url = ClassLoader.getSystemResource(""); + installHome = url.getPath(); + addPane(installHome); + } else { + installHome = StableUtils.getInstallHome(); + File file = new File(StableUtils.pathJoin(installHome, "scripts")); + } + } else { + } + } + + private void addPane(String installHome) { + LoginWebPane webPane = new LoginWebPane(new File(installHome).getAbsolutePath(),LoginPane.this); + add(webPane, BorderLayout.CENTER); + } + + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer-Plugin_Manager"); + } +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebBridge.java b/designer_base/src/com/fr/design/extra/LoginWebBridge.java new file mode 100644 index 0000000000..5149676937 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/LoginWebBridge.java @@ -0,0 +1,188 @@ +package com.fr.design.extra; + +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.dialog.UIDialog; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.FRLogger; +import com.fr.general.SiteCenter; +import com.fr.general.http.HttpClient; +import com.fr.stable.EncodeConstants; +import com.fr.stable.StringUtils; +import javafx.scene.web.WebEngine; + +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URI; +import javax.swing.*; +import java.awt.*; +import java.net.URLEncoder; + +/** + * Created by zhaohehe on 16/8/1. + */ +public class LoginWebBridge { + + private static final String LOGIN_SUCCESS_FLAG = "http://bbs.finereport.com"; + private static final String LOGININ = "0"; + private static final String LOGIN_INFO_EMPTY = "-1"; + private static final String DISCONNECTED = "-2"; + private static final String UNKNOWN_ERROR = "-3"; + private static final int TIME_OUT = 10000; + + private static com.fr.design.extra.LoginWebBridge helper; + private UIDialog uiDialog; + private UILabel uiLabel; + + private boolean testConnection() { + HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test")); + return client.isServerAlive(); + } + + public static com.fr.design.extra.LoginWebBridge getHelper() { + if (helper != null) { + return helper; + } + synchronized (com.fr.design.extra.LoginWebBridge.class) { + if (helper == null) { + helper = new com.fr.design.extra.LoginWebBridge(); + } + return helper; + } + } + + public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) { + getHelper(); + helper.setEngine(webEngine); + return helper; + } + + private WebEngine webEngine; + + private LoginWebBridge() { + } + + public void setEngine(WebEngine webEngine) { + this.webEngine = webEngine; + } + + public void setDialogHandle(UIDialog uiDialog) { + this.uiDialog = uiDialog; + } + + public void setUILabel(UILabel uiLabel) { + this.uiLabel = uiLabel; + } + + /** + * 注册页面 + */ + public void registerHref() { + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); + }catch (Exception e) { + FRContext.getLogger().info(e.getMessage()); + } + } + + /** + * 忘记密码 + */ + public void forgetHref() { + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); + }catch (Exception e) { + FRContext.getLogger().info(e.getMessage()); + } + } + + /** + * 登录操作的回调 + * @param username + * @param password + * @return + */ + public String defaultLogin(String username, String password) { + if (!StringUtils.isNotBlank(username) && !StringUtils.isNotBlank(password)) { + return LOGIN_INFO_EMPTY; + } + if (!testConnection()) { + return DISCONNECTED; + } + if (login(username, password)) { + updateUserInfo(username, password); + loginSuccess(username); + return LOGININ; + }else { + return UNKNOWN_ERROR; + } + } + + /** + * 关闭窗口 + */ + public void closeWindow() { + if (uiDialog != null) { + uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + uiDialog.setVisible(false); + } + } + + public void updateUserInfo(String username,String password) { + DesignerEnvManager.getEnvManager().setBBSName(username); + DesignerEnvManager.getEnvManager().setBBSPassword(password); + } + + /** + * 关闭窗口并且重新赋值 + * @param username + */ + public void loginSuccess(String username) { + closeWindow(); + uiLabel.setText(username); + } + + /** + * 弹出QQ授权页面 + */ + public void showQQ() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + //弹出qq登录的窗口 + QQLoginPane managerPane = new QQLoginPane(); + UIDialog qqlog = new QQLoginDialog(DesignerContext.getDesignerFrame(),managerPane); + QQLoginWebBridge.getHelper().setDialogHandle(uiDialog); + QQLoginWebBridge.getHelper().setQQDialogHandle(qqlog); + QQLoginWebBridge.getHelper().setUILabel(uiLabel); + qqlog.setVisible(true); + } + }); + } + + public boolean login(String username, String password) { + if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { + try { + username = URLEncoder.encode(username, EncodeConstants.ENCODING_GBK); + password = URLEncoder.encode(password, EncodeConstants.ENCODING_GBK); + } catch (UnsupportedEncodingException e) { + FRLogger.getLogger().error(e.getMessage()); + } + String url = SiteCenter.getInstance().acquireUrlByKind("bbs.login") + "&username=" + username + "&password=" + password; + HttpClient client = new HttpClient(url); + client.setTimeout(TIME_OUT); + if (client.getResponseCodeNoException() == HttpURLConnection.HTTP_OK) { + try { + String res = client.getResponseText(EncodeConstants.ENCODING_GBK); + if (res.contains(LOGIN_SUCCESS_FLAG)) { + return true; + } + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } + } + return false; + } +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebPane.java b/designer_base/src/com/fr/design/extra/LoginWebPane.java new file mode 100644 index 0000000000..f31889c28c --- /dev/null +++ b/designer_base/src/com/fr/design/extra/LoginWebPane.java @@ -0,0 +1,61 @@ +package com.fr.design.extra; + +import javafx.application.Platform; +import javafx.embed.swing.JFXPanel; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.layout.BorderPane; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebEvent; +import javafx.scene.web.WebView; +import netscape.javascript.JSObject; + +import javax.swing.*; + +/** + * Created by zhaohehe on 16/7/26. + */ +public class LoginWebPane extends JFXPanel { + + private WebEngine webEngine; + private LoginPane loginPane; + + public LoginWebPane(final String installHome,LoginPane loginPane) { + this.loginPane = loginPane; + Platform.setImplicitExit(false); + Platform.runLater(new Runnable() { + @Override + public void run() { + BorderPane root = new BorderPane(); + Scene scene = new Scene(root); + LoginWebPane.this.setScene(scene); + WebView webView = new WebView(); + webEngine = webView.getEngine(); + webEngine.load("file:///" + installHome + "/scripts/store/web/login.html"); + webEngine.setOnAlert(new EventHandler>() { + @Override + public void handle(WebEvent event) { + showAlert(event.getData()); + } + }); + JSObject obj = (JSObject) webEngine.executeScript("window"); + obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine)); + webView.setContextMenuEnabled(false);//屏蔽右键 + root.setCenter(webView); + } + }); + } + + public void setEngine(WebEngine webEngine) { + this.webEngine = webEngine; + } + + private void showAlert(final String message) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + JOptionPane.showMessageDialog(LoginWebPane.this, message); + } + }); + } +} diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 144f913da5..82dd4cf356 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -6,6 +6,7 @@ import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.general.FRLogger; import com.fr.general.Inter; +import com.fr.general.SiteCenter; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLicense; import com.fr.plugin.PluginLicenseManager; @@ -361,6 +362,42 @@ public class PluginWebBridge { return false; } + /** + * 获取系统登录的用户名 + * @param callback + */ + public void getLoginInfo(final JSObject callback) { + Task task = new PluginTask<>(webEngine, callback, new GetLoginInfoExecutor()); + new Thread(task).start(); + } + + /** + * 打开论坛消息界面 + */ + public void getPriviteMessage() { + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); + }catch (Exception exp) { + FRContext.getLogger().info(exp.getMessage()); + } + } + + /** + * 打开登录页面 + */ + public void loginContent() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + UserLoginContext.fireLoginContextListener(); + } + }); + } + + public void getUsername() { + + } + /** * 在本地浏览器里打开url * tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑) diff --git a/designer_base/src/com/fr/design/extra/QQLoginDialog.java b/designer_base/src/com/fr/design/extra/QQLoginDialog.java new file mode 100644 index 0000000000..1a64161741 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/QQLoginDialog.java @@ -0,0 +1,34 @@ +package com.fr.design.extra; + +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import java.awt.*; + +/** + * Created by zhaohehe on 16/7/28. + */ +public class QQLoginDialog extends UIDialog { + private static final Dimension DEFAULT_SHOP = new Dimension(700, 500); + + public QQLoginDialog(Frame frame, BasicPane pane) { + super(frame); + setUndecorated(true); + JPanel panel = (JPanel) getContentPane(); + panel.setLayout(new BorderLayout()); + add(pane, BorderLayout.CENTER); + setSize(DEFAULT_SHOP); + GUICoreUtils.centerWindow(this); + setResizable(false); + setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); + + } + + @Override + public void checkValid() throws Exception { + } + +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/QQLoginPane.java b/designer_base/src/com/fr/design/extra/QQLoginPane.java new file mode 100644 index 0000000000..e93c611fe2 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/QQLoginPane.java @@ -0,0 +1,44 @@ +package com.fr.design.extra; + +import com.fr.design.dialog.BasicPane; +import com.fr.general.Inter; +import com.fr.stable.StableUtils; + +import java.awt.*; +import java.io.File; +import java.net.URL; + +/** + * Created by zhaohehe on 16/7/28. + */ +public class QQLoginPane extends BasicPane { + private static final String LATEST = "latest"; + + public QQLoginPane() { + setLayout(new BorderLayout()); + if (System.getProperty("java.version").startsWith("1.8")) { + String installHome; + if (StableUtils.isDebug()) { + URL url = ClassLoader.getSystemResource(""); + installHome = url.getPath(); + addPane(installHome); + } else { + installHome = StableUtils.getInstallHome(); + File file = new File(StableUtils.pathJoin(installHome, "scripts")); + + } + } else { + } + } + + private void addPane(String installHome) { + QQLoginWebPane webPane = new QQLoginWebPane(new File(installHome).getAbsolutePath()); + add(webPane, BorderLayout.CENTER); + } + + + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer-Plugin_Manager"); + } +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java new file mode 100644 index 0000000000..a038d56ce0 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java @@ -0,0 +1,105 @@ +package com.fr.design.extra; + +import com.fr.design.DesignerEnvManager; +import com.fr.design.dialog.UIDialog; +import com.fr.design.gui.ilable.UILabel; +import javafx.scene.web.WebEngine; +import org.json.JSONObject; + +import javax.swing.*; + +/** + * Created by lp on 2016/8/10. + */ +public class QQLoginWebBridge { + + private static com.fr.design.extra.QQLoginWebBridge helper; + private WebEngine webEngine; + private static String LOGINSUCCESS = "ok"; + private static String LOGINFAILED = "failed"; + private UIDialog uiDialog; + private UILabel uiLabel; + private UIDialog qqDialog; + private String username; + + + private QQLoginWebBridge() { + } + + public static com.fr.design.extra.QQLoginWebBridge getHelper() { + if (helper != null) { + return helper; + } + synchronized (com.fr.design.extra.QQLoginWebBridge.class) { + if (helper == null) { + helper = new com.fr.design.extra.QQLoginWebBridge(); + } + return helper; + } + } + + public void setEngine(WebEngine webEngine) { + this.webEngine = webEngine; + } + + public void setDialogHandle(UIDialog uiDialog) { + this.uiDialog = uiDialog; + } + + public void setQQDialogHandle(UIDialog uiDialog) { + this.qqDialog = uiDialog; + } + + public void setUILabel(UILabel uiLabel) { + this.uiLabel = uiLabel; + } + + public void setLoginlabel() { + username = DesignerEnvManager.getEnvManager().getBBSName(); + } + + public static com.fr.design.extra.QQLoginWebBridge getHelper(WebEngine webEngine) { + getHelper(); + helper.setEngine(webEngine); + return helper; + } + + /** + * 关闭QQ授权窗口 + */ + public void closeQQWindow() { + if (qqDialog != null) { + qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + qqDialog.setVisible(false); + } + } + + /** + * 关闭父窗口 + */ + public void closeParentWindow() { + if (uiDialog != null) { + uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + uiDialog.setVisible(false); + } + } + + /** + * 获取用户信息 + * @param userInfo + */ + public void getLoginInfo(String userInfo) { + JSONObject jo = new JSONObject(userInfo); + String status = jo.get("status").toString(); + if (status.equals(LOGINSUCCESS)) { + String username = jo.get("username").toString(); + closeQQWindow(); + closeParentWindow(); + uiLabel.setText(username); + DesignerEnvManager.getEnvManager().setBBSName(username); + }else if (status.equals(LOGINFAILED)){ + //账号没有QQ授权 + closeQQWindow(); + } + } +} diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java new file mode 100644 index 0000000000..9644f06663 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java @@ -0,0 +1,55 @@ +package com.fr.design.extra; + +import javafx.application.Platform; +import javafx.embed.swing.JFXPanel; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.layout.BorderPane; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebEvent; +import javafx.scene.web.WebView; +import netscape.javascript.JSObject; + +import javax.swing.*; + +/** + * Created by zhaohehe on 16/7/28. + */ +public class QQLoginWebPane extends JFXPanel { + + private WebEngine webEngine; + + public QQLoginWebPane(final String installHome) { + Platform.setImplicitExit(false); + Platform.runLater(new Runnable() { + @Override + public void run() { + BorderPane root = new BorderPane(); + Scene scene = new Scene(root); + QQLoginWebPane.this.setScene(scene); + WebView webView = new WebView(); + webEngine = webView.getEngine(); + webEngine.load("file:///" + installHome + "/scripts/store/web/qqLogin.html"); + webEngine.setOnAlert(new EventHandler>() { + @Override + public void handle(WebEvent event) { + showAlert(event.getData()); + } + }); + JSObject obj = (JSObject) webEngine.executeScript("window"); + obj.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine)); + webView.setContextMenuEnabled(false);//屏蔽右键 + root.setCenter(webView); + } + }); + } + + private void showAlert(final String message) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + JOptionPane.showMessageDialog(QQLoginWebPane.this, message); + } + }); + } +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/UserLoginContext.java b/designer_base/src/com/fr/design/extra/UserLoginContext.java new file mode 100644 index 0000000000..a6d68f076a --- /dev/null +++ b/designer_base/src/com/fr/design/extra/UserLoginContext.java @@ -0,0 +1,28 @@ +package com.fr.design.extra; + +import java.util.ArrayList; + +/** + * Created by lp on 2016/8/16. + */ +public class UserLoginContext { + private static ArrayList fireLoginContextListener = new ArrayList(); + + /** + * 触发登录框弹出的监听器 + */ + public static void fireLoginContextListener() { + for (LoginContextListener l : fireLoginContextListener) { + l.showLoginContext(); + } + } + + /** + * 添加一个弹出登录框的监听事件 + * + * @param l 登录框弹出监听事件 + */ + public static void addLoginContextListener(LoginContextListener l) { + fireLoginContextListener.add(l); + } +} diff --git a/designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java b/designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java new file mode 100644 index 0000000000..79fb20dce5 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java @@ -0,0 +1,37 @@ +package com.fr.design.extra.exe; + +import com.fr.design.DesignerEnvManager; +import com.fr.design.extra.Process; + +/** + * Created by lp on 2016/8/16. + */ +public class GetLoginInfoExecutor implements Executor { + private String result = "[]"; + + @Override + public String getTaskFinishMessage() { + return result; + } + + @Override + public Command[] getCommands() { + return new Command[]{ + new Command() { + @Override + public String getExecuteMessage() { + return null; + } + + @Override + public void run(Process process) { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + if (username == null) { + }else { + result = username; + } + } + } + }; + } +}