OA插件
// ==UserScript==
// @name OA插件
// @namespace http://tampermonkey.net/
// @version 1.9
// @description 增加主办意见显示
// @author You
// @match http://*.zhbg.kjt.gx.gov/*
// @grant none
// @run-at context-menu
// ==/UserScript==
(function() {
'use strict';
// Your code here...
/*
Just draw a border round the document.body.
*/
//获取处室名称
var myouname = "";
var httpRequestouname = new XMLHttpRequest();
httpRequestouname.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/dashboardaction/getRole?isCommondto=true&action2rest=true', true); //第二步:打开连接
httpRequestouname.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequestouname.send('');//发送请求 将情头体写在send中
httpRequestouname.onreadystatechange = function () {
if (httpRequestouname.readyState == 4 && httpRequestouname.status == 200) {
myouname = JSON.parse(httpRequestouname.responseText).custom.ouname;
}
};
//设置列表宽度
updateColSize();
document.body.style.border = "5px solid red";
var username = "";
var boxobserver = null;
var bodyobserver = null;
var paneobserver = null;
var sizeobserver = null;
document.styleSheets[0].addRule('.el-tooltip', 'white-space:normal!important');
document.styleSheets[0].addRule('.titlefont', 'white-space:normal!important');
setTimeout(setobserve, 2000);
UpdateHuibanOpinoin();
function setobserve(){
//监视界面操作,丢失会办页面后重新设置对会办页面的监视
var header = document.getElementById("js-async-header");
var headerconfig = {attributes:true,subtree:true};
var headerobserver = new MutationObserver(function (mutationsList, observer) {
setobserve2();
});
headerobserver.observe(header, headerconfig);
//设置对编辑页面打开、会办页面切换、排序的监视
setobserve2();
}
function setobserve2(){
//监视会办页面切换
if (boxobserver != null){//清理事件,防止重复刷新
boxobserver.disconnect();
}
var box = document.getElementById("tab-hbhq");
var boxconfig = { attributes: true,attributeFilter:["aria-selected"]};
boxobserver = new MutationObserver(function (mutationsList, observer) {
doit(mutationsList, observer);
});
boxobserver.observe(box, boxconfig);
//监视编辑页面打开
if (bodyobserver != null){
bodyobserver.disconnect();
}
var body = document.querySelector("body");
var bodyconfig = { attributes: true,attributeFilter:["class"]};
bodyobserver = new MutationObserver(function (mutationsList, observer) {
doit(mutationsList, observer);
});
bodyobserver.observe(body,bodyconfig);
//监视排序
if (paneobserver != null){
paneobserver.disconnect();
}
var pane = document.getElementById("pane-hbhq");
var paneconfig = { characterData:true,subtree:true};
paneobserver = new MutationObserver(function (mutationsList, observer) {
doit(mutationsList, observer);
});
paneobserver.observe(pane, paneconfig);
}
function doit(mutationsList, observer){
var tabfourth = document.querySelector("div#tab-hbhq_1.is-active");
var body = document.querySelector("body.fullpage");
if (tabfourth != null && body == null ){//如果显示了会办页面
username = document.querySelector("div.async-header__right__name").innerText;
username = username.substring(1);
UpdateHuibanOpinoin();
updateColSize();
setobserve2();
}
return;
}
function UpdateHuibanOpinoin(){
//判断列表是否变化
//http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/arceinboxdaichuliaction/getDataGridDataHuiBan?type=1&isCommondto=true&action2rest=true&controlself=true
//下载处理会办列表(最大100项)
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', ' http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/arceinboxdaichuliaction/getDataGridDataHuiBan?type=1&isCommondto=true&action2rest=true&controlself=true&my=true', true); //第二步:打开连接
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequest.send('params=%7B%22title%22%3A%22%22%2C%22bianhao%22%3A%22%22%2C%22fawendz%22%3A%22%22%2C%22fawenyear%22%3A%22%22%2C%22fawenserialnumber%22%3A%22%22%2C%22laiwennumber%22%3A%22%22%2C%22urgencydegree%22%3A%22%22%2C%22senddate%22%3A%22%22%2C%22processingstatus%22%3A%22%22%2C%22senddeptname%22%3A%22%22%2C%22fullfiletype%22%3A%22%22%2C%22senddatefrom%22%3A%22%22%2C%22senddateto%22%3A%22%22%2C%22pageIndex%22%3A0%2C%22pageSize%22%3A100%2C%22tabtype%22%3A%220%22%7D&cmdParams=%5B%5D');//发送请求 将情头体写在send中
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var huiban = JSON.parse(httpRequest.responseText);
//逐项处理会办文
for (var i = 0; i < huiban.custom.data.length; i++){
if(document.querySelector('span[data-inboxguid="' + huiban.custom.data[i].inboxguid +'"]'))
{//如果在当前页面显示
if(huiban.custom.data[i].huibanfenbanstatustext.indexOf("未分办") >= 0 )
{
HandlezhubanData(huiban.custom.data[i]);
}
else
{
HandleHuibanData(huiban.custom.data[i]);
}
}
}
}
};
}
//处理会办文
function HandleHuibanData(data){
//下载会办意见
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/wd25formhbaction/getDataBean?isCommondto=true&action2rest=true', true); //第二步:打开连接
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");//设置请求头 注:post方式必须设置请求头(在建立连接后设置请求头)
var params = {inboxGuid:data.inboxguid, outboxGuid:data.outboxguid, rowGuid:data.rowguid,istrack:"undefined",fileType:data.filetype};
httpRequest.send("params=" + JSON.stringify(params));
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var databean = JSON.parse(httpRequest.responseText);
var opinion = "未反馈";
//在各处室遍历查找处室意见
for (var i = 0; i < databean.custom.opinionList.length; i++){
var name = document.querySelector('span[data-inboxguid="' + data.inboxguid +'"]');
name.style.whiteSpace="normal";
if(databean.custom.opinionList[i].ouname.indexOf(myouname) >= 0){//查找到处室意见
//汇总处室意见
opinion = HandleOpinions(data.inboxguid, databean.custom.opinionList[i].opinions);
break;
}
}
//显示处室意见
var itemspan = document.querySelector('span[data-inboxguid="' + data.inboxguid +'"]');
var state = itemspan.parentNode.parentNode.parentNode.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.firstElementChild;
var huibanfenbanstatustext = data.huibanfenbanstatustext;
//高亮显示未分办
if (huibanfenbanstatustext.indexOf("未分办") >= 0){
huibanfenbanstatustext = " <mark>" + huibanfenbanstatustext + " </mark>"
}
//高亮显示全部反馈
if (itemspan.getAttribute("data-processingstatus") == "全部反馈"){
state.innerHTML = "<p><mark style=\"background-color: green;\">全部反馈</mark></p>" + opinion;
}
else{
state.innerHTML = "<p>" + huibanfenbanstatustext + "</p>" +opinion;
}
state.style.textAlign = "left";
}
};
}
//汇总高新处意见
function HandleOpinions(inboxguid, opinions){
var opinion = "";
for (var i = 0; i < opinions.length; i++){//高亮显示姓名和时间
let opiniontext = opinions[i].opinion.replace(username, " <mark>" + username + " </mark>");
opiniontext = opiniontext.replace(/\d+月\d+日/g, function(match){
//判断是否当天到期或过期
var now = new Date();
let duedate = new Date(now.getFullYear(),
parseInt(match.substring(0, match.indexOf("月")) - 1),
parseInt(match.substring(match.indexOf("月") + 1, match.indexOf("日")))
);
let difftime = duedate.getTime() - now.getTime();
if( (difftime < 0) && (difftime > - 1000 * 60 * 60 * 24 * 60)){//过期60天就认为是跨年引起的
return " <mark style=\"background-color: red;\">" + match + " </mark>";
}
if( difftime > 1000 * 60 * 60 * 24 * 305){//过期60天就认为是跨年引起的
return " <mark style=\"background-color: red;\">" + match + " </mark>";
}
return " <mark>" + match + " </mark>"
});
opinion = opinion + "<p>" +opinions[i].createtime + " " + opinions[i].username + " : " + opiniontext + "</p>";
}
return opinion;
}
//设置列表宽度
function updateColSize(){
let columnsheader = document.querySelector("#pane-hbhq_1 > div > div > div.el-table__header-wrapper > table").__vue__.columns;
let columnsbody = document.querySelector("#pane-hbhq_1 > div > div > div.el-table__body-wrapper > table").__vue__.columns;
for (let index = 0; index < 9; index++) {
//读取保存的长度index
let sizeheader = localStorage.getItem("table_column_header" + (index + 1));
let sizebody = localStorage.getItem("table_column_body" + (index + 1));
if (index != 2){
columnsheader[index].width = sizeheader;
columnsbody[index].width = sizebody;
}
columnsheader[index].realWidth = sizeheader;
columnsheader[index].minWidth = sizeheader;
columnsbody[index].realWidth = sizebody;
columnsbody[index].minWidth = sizebody;
}
let title= document.querySelectorAll("#pane-hbhq_1 > div > div > div.el-table__body-wrapper > table > tbody > tr > td:nth-child(3) > div");
title.forEach(function (userItem) {
userItem.style.width = (columnsbody[2].realWidth - 2) + "px";
});
}
function HandlezhubanData(data){
let httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/handleframehbaction/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //使用myScript=ShowZhuban标记插件的调用
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
let params = {inboxGuid:data.inboxguid, outboxGuid:data.outboxguid,rowGuid:data.rowguid,fileType:data.filetype};
httpRequest.send("params=" + JSON.stringify(params) + '&cmdParams=%5B%5D');
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
let data0 = JSON.parse(httpRequest.responseText);
downLoadwdtype(data, data0.custom.docguid);
}
};
}
function downLoadwdtype(data1, docguid){
//根据docguid下载wdtype,然后下载主办意见
let httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/handleframeaction/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //第二步:打开连接
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
let params = {guid:docguid, count:"1"};
httpRequest.send("params=" + JSON.stringify(params));
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
let data = JSON.parse(httpRequest.responseText);
downLoadZhuban(data1,docguid, data.custom.wdtype);
}
};
}
function downLoadZhuban(data1, docguid, wdtype){
//根据docguid下载主办意见,主办意见保存在数据的niban和hg字段中
let httpRequest = new XMLHttpRequest();
if (wdtype == 24){
httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/wd24form1action/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //第二步:打开连接
}else{
httpRequest.open('POST', 'http://dzgw.zhbg.kjt.gx.gov/bgtoa/rest/wd25form2action/getDataBean?isCommondto=true&action2rest=true&myScript=ShowZhuban', true); //第二步:打开连接
}
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
let params = {guid:docguid, archivefiletypeguid:""};
httpRequest.send("params=" + JSON.stringify(params));
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
let data = JSON.parse(httpRequest.responseText);
//显示处室意见
let niban = data.custom.niban;
niban = niban.replace(/\d+月\d+日/g, function(match){
//判断是否当天到期或过期
var now = new Date();
let duedate = new Date(now.getFullYear(),
parseInt(match.substring(0, match.indexOf("月")) - 1),
parseInt(match.substring(match.indexOf("月") + 1, match.indexOf("日")))
);
let difftime = duedate.getTime() - now.getTime();
if( (difftime < 0) && (difftime > - 1000 * 60 * 60 * 24 * 60)){//过期60天就认为是跨年引起的
return " <mark style=\"background-color: red;\">" + match + " </mark>";
}
if( difftime > 1000 * 60 * 60 * 24 * 305){//过期60天就认为是跨年引起的
return " <mark style=\"background-color: red;\">" + match + " </mark>";
}
return " <mark>" + match + " </mark>"
});
let opinion = "<details open><summary data-v-7157c1e2 class=\"div_title\"><mark>主办意见:</mark></summary><div style=\"white-space: pre-wrap;\">" + niban + "</div><div style=\"white-space: pre-wrap;\">" + data.custom.hg + "</div></details><HR>";
var itemspan = document.querySelector('span[data-inboxguid="' + data1.inboxguid +'"]');
var state = itemspan.parentNode.parentNode.parentNode.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.firstElementChild;
state.innerHTML = opinion;
state.style.textAlign = "left";
}
};
}
//在页面中查找区域处意见元素
function getOpinionItem(){
let xpathExpression = '//li[@class="opinion-item"]/div/span[contains(text(),"科技成果转化促进处")]';
let result = document.evaluate(xpathExpression, document, null, XPathResult.ANY_TYPE, null);
return result.iterateNext();
}
})();