帆软finereport决策系统自定义登录界面

楼主
插件开发者
通过前面对决策系统登录liu'chengliucheng 的梳理,发现通过改变AppearanceConfig的loginType与loginUrl即可实现跳转到自定义的登录界面。
第一步:先创建一个插件项目,结构为:

1 plugin.xml文件如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
    <id>com.fr.plugin.customer.login</id>
    <name><![CDATA[自定义登录界面]]></name>
    <active>yes</active>
    <version>1.1</version>
    <env-version>10.0</env-version>
    <jartime>2018-03-12</jartime>
    <vendor>gb</vendor>
    <description><![CDATA[自定义登录界面]]></description>
    <change-notes><![CDATA[

    ]]></change-notes>
    <lifecycle-monitor class="com.fr.plugin.lifecycle.MyPluginLifecycleMonitor"/>
    <function-recorder class="com.fr.plugin.lifecycle.MyPluginLifecycleMonitor"/>
</plugin>


<lifecycle-monitor class="com.fr.plugin.lifecycle.MyPluginLifecycleMonitor"/> 对插件生命周期的监听类,在该类里面修改AppearanceConfig的值。
<function-recorder class="com.fr.plugin.lifecycle.MyPluginLifecycleMonitor"/> 每个插件都需要一个function-recorder标签。


2 MyPluginLifecycleMonitor如下:


package com.fr.plugin.lifecycle;

import com.fr.decision.config.AppearanceConfig;
import com.fr.decision.webservice.bean.config.LoginAppearanceType;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.record.analyzer.EnableMetrics;

@EnableMetrics
@FunctionRecorder
public class MyPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor{

    @Override
    @Focus(id = "com.fr.plugin.customer.login", text = "自定义登录界面", source = Original.PLUGIN)
    public void afterRun(PluginContext context) {
        //do something
        FineLoggerFactory.getLogger().info("-------------------------  hello plugin PerformancePluginMonitor:afterRun");

        AppearanceConfig.getInstance().setLoginType(LoginAppearanceType.LOGIN_URL.toInteger());
        AppearanceConfig.getInstance().setLoginUrl("/webroot/decision/file?path=com/fr/plugin/customerlogin/index.html");

    }

    @Override
    public void beforeStop(PluginContext context) {
        //release resources
        FineLoggerFactory.getLogger().info("-------------------------  hello plugin PerformancePluginMonitor:beforeStop");
    }

}

我们是在生命周期afterRun里添加的代码,这里添加了对loginType与LoginUrl的修改,其实这个修改跟决策系统里的菜单中 管理系统-外观配置中的登录页中的设置登录页是一个意思,只是这里我们通过代码来修改的,这里修改后就会被保存在数据库里。
通过这里的修改,当需要登录的时候就会重定向到/webroot/decision/file?path=com/fr/plugin/customerlogin/index.html这个地址下,path=com/fr/plugin/customerlogin/index.html就是我们的html页面所在路径。

看一下index.html的内容:
<html>

<head>
    <script type="text/javascript" src="/webroot/decision/file?path=com/fr/plugin/customerlogin/jquery-2.2.2.min.js"></script>
</head>

<body>
    5秒后自动登录
    <script>

        setTimeout(() => {
            var i = {
                "type": "POST", data: {
                    username: "admin",
                    password: "123456",
                    validity: -1,
                    encrypted: 0
                }
            };


            $.ajax({
                url: "/webroot/decision/login", type: i.type, headers: i.headers,
                contentType: "application/json", data: "GET" === i.type ? null : JSON.stringify(i.data),
                dataType: "json", cache: !1, async: !0,
                error: function (err) {
                    console.log(err)
                },
                complete: function (e, t) {
                    console.log(e.responseText)
                    if("success" == t){
                        data = JSON.parse(e.responseText)
                        console.log(data)
                        document.cookie = "fine_auth_token="+data.data.accessToken+"; path=/";
                       // $.cookie('fine_auth_token', data.data.accessToken, {  path: '/' });
                        window.location.href = data.data.originUrlResponse.originUrl
                    }

                }
            })
        }, 5000);
    </script>
</body>

</html>

这里我没写界面,5秒后自动调用方法来自动登录了。这里我没有将密码加密,如果需要加密,需要将encrypted设置为1,并且使用CryptoJS来加密,具体的加密方法可以参考我前面的分析登录流程里有。
这里当登录成功后会将token写入到cookie中,href设置为开始的那个url。


分享扩散:

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部 返回列表