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
}
})();