EKP前端/EKP-V16开发功能强化/快速切换用户 - SSO单点登录方式(public)

1、将【快速切换用户 - 账号密码方式】中的tampermonkey代码【换成】以下代码即可
红色部分需根据实际情况进行修改:
// ==UserScript==
// @name         XPOALogin
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        localhost:10086/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// ==/UserScript==
(function () {
    'use strict';
    /************************************************************ 配置此处变量(注意:通过auto_switchUser触发的函数无法使用) *************************************************/
    const account = "account"; // restservice.Token生成与解析 访问账号
    const password = "password";// restservice.Token生成与解析 访问密码
    const onlyOne = false;// true当搜索结果只有一个时,自动切换;false当搜索结果只有一个时还需输入序号或直接回车才可切换
    const domain = 'localhost:10086';// 域名+端口(例如localhost:10086,同时需将本文件的@match修改成localhost:10086/*)
    const url = window.location.href;// 当前页面url
    /*************************************************************************** 以下代码无需修改 **********************************************************************/
    let innerHtml =
        '<script>' +
        '   let account = \'' + account + '\';' +
        '   let password = \'' + password + '\';' +
        '   let onlyOne = ' + onlyOne + ';' +
        '   let domain = \'' + domain + '\';' +
        '   hideSwitch = ' + hideSwitch + ';' +
        '   auto_switchUser = ' + auto_switchUser + ';' +
        '   single_sign_on = ' + single_sign_on + ';' +
        '   toPage = ' + toPage + ';' +
        '   auto_searchUser = ' + auto_searchUser + ';' +
        '</script>' +
        "<button id='auto_btn_hideswitch' class='lui-component lui_widget_btn lui-praise-btn' style='height: auto;color: #494949;' οnclick='hideSwitch()'>▼</button>" +
        "<button id='auto_btn_switchuser' class='lui-component lui_widget_btn lui-praise-btn' style='height: 20px;visibility: visible; cursor: pointer;font-size: 10px;font-weight:580;color: #919191;' οnclick='auto_switchUser()'>1-用户</button>" +
        "<button id='auto_btn_toPage_0' class='lui-component lui_widget_btn lui-praise-btn' style='height: 20px;visibility: visible; cursor: pointer;font-size: 11px;font-weight:580;color: #919191;' οnclick='toPage(1,false)' >2-流程</button>" +
        "<button id='auto_btn_toPage_1' class='lui-component lui_widget_btn lui-praise-btn' style='height: 20px;visibility: visible; cursor: pointer;font-size: 11px;font-weight:580;color: #919191;' οnclick='toPage(0,true)' >3-模板</button>" +
        "<button id='auto_btn_toPage_2' class='lui-component lui_widget_btn lui-praise-btn' style='height: 20px;visibility: visible; cursor: pointer;font-size: 11px;font-weight:580;color: #919191;' οnclick='toPage(2,true)' >4-组织</button>";
    if (typeof $ !== "undefined") {
        if (url.includes("km/review/km_review_template")) {// 模板设计中禁止使用
            return;
        }
        $("#top").append(innerHtml);
        // 页面快捷方式 alt
        $(document).bind('keydown', function(e) {
            // console.log({e})
            if (e.altKey) {
                switch (e.originalEvent.key) {
                    case "`": $("#auto_btn_hideswitch").click(); break
                    case "1": $("#auto_btn_switchuser").click(); break
                    case "2": $("#auto_btn_toPage_0").click(); break
                    case "3": $("#auto_btn_toPage_1").click(); break
                    case "4": $("#auto_btn_toPage_2").click(); break
                }
            }
        })
    }
    /**
     * 隐藏、显示切换按钮
     */
    function hideSwitch() {
        if (typeof $ === "undefined") return;
        const hideSwitch = $('#auto_btn_hideswitch')[0];
        if (!hideSwitch) return;
        var hideBtnText = hideSwitch.innerText;
        var selectors = ['#auto_btn_switchuser',
            '#auto_btn_toPage_0', '#auto_btn_toPage_1', '#auto_btn_toPage_2',
            '#luiPraiseBtn', '.com_gototop', '.lui-component.lui_widget_btn.com_qrcode']
        for (var i = 0; i < selectors.length; i++) {
            if (hideBtnText === '▼') {
                $(selectors[i]).hide(200);
                continue;
            }
            $(selectors[i]).show(200);
        }
        hideSwitch.innerText = hideBtnText === '▲' ? '▼' : '▲';
    }
    //hideSwitch();// 默认隐藏
    /**
     * [切换用户按钮]click触发函数
     */
    function auto_switchUser() {
        var usersArr = [];
        let searchValue = `${window.prompt('公司||部门||姓名||登录名(模糊、不区分大小写)',)}`;
        do{
            console.log({searchValue})
            if (searchValue == 'null' || searchValue == '') break;
            usersArr = auto_searchUser(searchValue);
            if (usersArr.length == 1 && onlyOne) break;// 只有一个查询结果直接选定执行切换
            let usersStr = '';
            for (let i = 0; i < usersArr.length; i++) {
                usersStr += '(' + i + ')' + usersArr[i].fd_name + '_' + usersArr[i].fd_login_name + '\n'
            }
            searchValue = `${window.prompt('数字序号以选择,回车默认第0个(非数字则重新搜索):\n\n' + usersStr + (usersStr==''?'\n查无结果,请重新输入!':''))}`;
        }while (isNaN(Number(searchValue)));
        const user = usersArr[Number(searchValue) || 0];
        if (searchValue == 'null' || user == null || user == undefined) return;
        single_sign_on(user);// 单点登录
    }
    function single_sign_on(user) {
        const getSesstionId_url = "http://" + domain + "/api/sys-authentication/loginService/getLoginSessionId";
        const login_auto_url = "http://" + domain + "/sys/authentication/sso/login_auto.jsp";
        $.ajax({
            username: account,
            password: password,
            type: "POST",
            url: getSesstionId_url,
            data: {
                "loginName": user.fd_login_name
            },
            async: false,
            dataType:"json",
            success: function(res) {
                if (res.result){
                    window.open(login_auto_url + "?sessionId=" + res.sessionId, "_self");
                }
                else {
                    alert(res);
                }
            }
        });
    }
    /**
     * 跳转页面
     * @param which 哪个页面
     * @param newWin 新建标签页
     */
    function toPage(which, newWin) {
        console.log({which})
        let url = "";
        switch (which) {
            case 0 : url = "sys/profile/index.jsp#app/ekp/km/review";break;// 模板设置
            case 1 : url = "km/review/index.jsp?j_module=true#j_path=%2FlistCreate&mydoc=create";break;// 流程管理
            case 2 : url = "sys/profile/index.jsp#org/organizational";break;// 组织架构
        }
        if (newWin) {// 新建标签页
            window.open(Com_Parameter.ContextPath + url);
            return;
        }
        window.open(Com_Parameter.ContextPath + url, "_self");// 当前页面打开
    }
    /**
     * 搜索
     */
    function auto_searchUser(searchName) {
        const users = JSON.parse(localStorage.xp_oa_users).RECORDS;
        let usersArr = [];
        for (const obj of users) {
            const loginName = obj.fd_login_name;
            const name = obj.fd_name.toLowerCase() + loginName.toLowerCase();
            if (name.indexOf(searchName.toLowerCase()) > -1) {
                usersArr.push(obj);
            }
        }
        return usersArr
    }
})();
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liquid-Li

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值