diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java index 7be5f1fc2..727539d88 100644 --- a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java @@ -92,6 +92,9 @@ public class UserInfoLabel extends UILabel{ } }); + PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this); + QQLoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this); + UserLoginContext.addLoginContextListener(new LoginContextListener() { @Override public void showLoginContext() { @@ -101,13 +104,13 @@ public class UserInfoLabel extends UILabel{ LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this); QQLoginWebBridge.getHelper().setLoginlabel(); qqdlg.setVisible(true); - clearLoingInformation(); + clearLoginInformation(); updateInfoPane(); } }); } - private void clearLoingInformation(){ + private void clearLoginInformation(){ DesignerEnvManager.getEnvManager().setBBSName(StringUtils.EMPTY); DesignerEnvManager.getEnvManager().setBBSPassword(StringUtils.EMPTY); } diff --git a/designer_base/src/com/fr/design/extra/LoginWebBridge.java b/designer_base/src/com/fr/design/extra/LoginWebBridge.java index 855ed447a..4e1e93b76 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/LoginWebBridge.java @@ -80,7 +80,7 @@ public class LoginWebBridge { */ public void registerHref() { try { - Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); }catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } @@ -119,6 +119,25 @@ public class LoginWebBridge { } } + /* + 插件管理那边的登录 + */ + public String pluginManageLogin(String username, String password, UILabel uiLabel) { + if (!StringUtils.isNotBlank(username) && !StringUtils.isNotBlank(password)) { + return LOGIN_INFO_EMPTY; + } + if (!testConnection()) { + return DISCONNECTED; + } + if (login(username, password)) { + updateUserInfo(username, password); + uiLabel.setText(username); + return LOGININ; + }else { + return LOGININFO_ERROR; + } + } + /** * 关闭窗口 */ @@ -126,6 +145,7 @@ public class LoginWebBridge { if (uiDialog != null) { uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); uiDialog.setVisible(false); + uiDialog.dispose(); } } diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 82dd4cf35..bcd1aea70 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -1,9 +1,11 @@ package com.fr.design.extra; import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; import com.fr.design.RestartHelper; import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; +import com.fr.design.gui.ilable.UILabel; import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.general.SiteCenter; @@ -41,6 +43,13 @@ public class PluginWebBridge { private String KEYWORD = "keyword"; private Map config; + private static final String LOGININ = "0"; + private static final String LOGIN_INFO_EMPTY = "-1"; + private static final String DISCONNECTED = "-2"; + private static final String LOGININFO_ERROR = "-3"; + + private UILabel uiLabel; + /** * 动作枚举 */ @@ -394,10 +403,6 @@ public class PluginWebBridge { }); } - public void getUsername() { - - } - /** * 在本地浏览器里打开url * tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑) @@ -490,4 +495,58 @@ public class PluginWebBridge { JOptionPane.showMessageDialog(null, e1.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); } } + + + /*-------------------------------登录部分的处理----------------------------------*/ + /** + * 注册页面 + */ + public void registerHref() { + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); + }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()); + } + } + + public void setUILabel(UILabel uiLabel) { + this.uiLabel = uiLabel; + } + + /** + * 登录操作的回调 + * @param username + * @param password + * @return + */ + public String defaultLogin(String username, String password) { + return LoginWebBridge.getHelper().pluginManageLogin(username, password, uiLabel); + } + + /** + * 弹出QQ授权页面 + */ + public void showQQ() { + LoginWebBridge.getHelper().showQQ(); + } + + /** + * 清除用户信息 + */ + public void clearUserInfo() { + DesignerEnvManager.getEnvManager().setBBSName(StringUtils.EMPTY); + DesignerEnvManager.getEnvManager().setBBSPassword(StringUtils.EMPTY); + uiLabel.setText(Inter.getLocText("FR-Base_UnSignIn")); + } } diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java index 3ee043493..b386e836c 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java @@ -3,12 +3,14 @@ package com.fr.design.extra; import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.UIDialog; import com.fr.design.gui.ilable.UILabel; +import com.fr.general.FRLogger; import com.fr.general.SiteCenter; import javafx.scene.web.WebEngine; import org.json.JSONObject; import javax.swing.*; import java.awt.*; +import java.io.IOException; import java.net.URI; /** @@ -22,6 +24,7 @@ public class QQLoginWebBridge { private static String LOGINFAILED = "failed"; private UIDialog uiDialog; private UILabel uiLabel; + private UILabel pluginuiLabel; private UIDialog qqDialog; private String username; @@ -57,6 +60,10 @@ public class QQLoginWebBridge { this.uiLabel = uiLabel; } + public void setUILabelInPlugin(UILabel uiLabel) { + this.pluginuiLabel = uiLabel; + } + public void setLoginlabel() { username = DesignerEnvManager.getEnvManager().getBBSName(); } @@ -98,7 +105,7 @@ public class QQLoginWebBridge { String username = jo.get("username").toString(); closeQQWindow(); closeParentWindow(); - uiLabel.setText(username); + pluginuiLabel.setText(username); DesignerEnvManager.getEnvManager().setBBSName(username); }else if (status.equals(LOGINFAILED)){ //账号没有QQ授权 @@ -109,4 +116,29 @@ public class QQLoginWebBridge { } } } + + public void openUrlAtLocalWebBrowser(WebEngine eng, String url) { + if (url.indexOf("qqLogin.html") > 0) { + return; + } + if (Desktop.isDesktopSupported()) { + try { + //创建一个URI实例,注意不是URL + URI uri = URI.create(url); + //获取当前系统桌面扩展 + Desktop desktop = Desktop.getDesktop(); + //判断系统桌面是否支持要执行的功能 + if (desktop.isSupported(Desktop.Action.BROWSE)) { + //获取系统默认浏览器打开链接 + desktop.browse(uri); + } + } catch (NullPointerException e) { + //此为uri为空时抛出异常 + FRLogger.getLogger().error(e.getMessage()); + } catch (IOException e) { + //此为无法获取系统默认浏览器 + FRLogger.getLogger().error(e.getMessage()); + } + } + } } diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java index 229e92f12..cdb1d1748 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java +++ b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java @@ -1,6 +1,11 @@ package com.fr.design.extra; +import com.fr.general.ComparatorUtils; +import com.fr.general.FRLogger; +import com.fr.general.SiteCenter; import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; import javafx.scene.Scene; @@ -30,6 +35,17 @@ public class QQLoginWebPane extends JFXPanel { WebView webView = new WebView(); webEngine = webView.getEngine(); webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html"); + webEngine.locationProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, final String oldValue, String newValue) { + disableLink(webEngine); + // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 + if (ComparatorUtils.equals(newValue, "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html") || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { + return; + } + QQLoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); + } + }); webEngine.setOnAlert(new EventHandler>() { @Override public void handle(WebEvent event) { @@ -52,4 +68,20 @@ public class QQLoginWebPane extends JFXPanel { } }); } + + private void disableLink(final WebEngine eng) { + try { + // webView端不跳转 虽然webView可以指定本地浏览器打开某个链接,但是当本地浏览器跳转到指定链接的同时,webView也做了跳转, + // 为了避免出现在一个600*400的资讯框里加载整个网页的情况,webView不跳转到新网页 + Platform.runLater(new Runnable() { + @Override + public void run() { + eng.executeScript("location.reload()"); + QQLoginWebBridge.getHelper().closeQQWindow(); + } + }); + } catch (Exception e) { + FRLogger.getLogger().error(e.getMessage()); + } + } } \ No newline at end of file