增加了多个查询按钮

This commit is contained in:
2025-07-19 20:05:36 +08:00
parent ef5d7d274d
commit 52103f9037

142
main.js
View File

@@ -7,6 +7,7 @@
// @match http://192.168.36.67:7888/shr/dynamic.do?uipk=com.kingdee.eas.hr.ats.app.WorkCalendarItem* // @match http://192.168.36.67:7888/shr/dynamic.do?uipk=com.kingdee.eas.hr.ats.app.WorkCalendarItem*
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAdVBMVEX///////7+/v4kVZ729/lafbO2xd3x8/f5+vz8/Pzd4+4tW6GSp8xnh7nP2OgxXqLK1OZ1kb/s7/UgUZytvdhKcKw+aKgaTZlhgrbU3eqar9Dm6fFVd7CEnsZwjb4VSZfAy+BCbKq3xd58l8OXrM6nudaMo8kyjkGlAAABfklEQVQokT1Si5arIBCLDIqCiogP8FHtWvv/n3iH7vZyDjDMQAIJwLdlpVIlz0L8T0FAxDaTy5JBrWn52ZhxoO6tQ+ZyjT7fJSqRpYJAJte8qbDPmxKPY4vgXOqdhramwzp6B1GTKRJahjjVVdlQI3FauiTahkOmFfHyJ9qJduC2lHf4o69weiZYyLyAYvLWFe3O1apHa80AsZOpGfdhZrLHDfSDwpumFuVO5HqI8xot3xvrM5Qy+DGiqo3fTgbvteRRT36AHmlk2J/R26vlbHmuiMVrWtOlpoGPX2a2wV3BMjQiNSXakezVA50zfvbHyGTMQlcFnRNtRQXEl3u4lklWVRi6FNRuyTRD/5E7sXehvIlCBM6c3zBed3E/dNKqCdlg/bRIlENj/XHMxztphdUGxNxTKNhAPbz3/edjlEC0uRTLc6b81syu5K8fPOhxKtAvm5/NMw/vNRNfy1U9hUKpbnFNsyh8v0Pa0A/O1SyE+LrxV6mSdjH2gsPf/D//7BjTQny+YwAAAABJRU5ErkJggg== // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAdVBMVEX///////7+/v4kVZ729/lafbO2xd3x8/f5+vz8/Pzd4+4tW6GSp8xnh7nP2OgxXqLK1OZ1kb/s7/UgUZytvdhKcKw+aKgaTZlhgrbU3eqar9Dm6fFVd7CEnsZwjb4VSZfAy+BCbKq3xd58l8OXrM6nudaMo8kyjkGlAAABfklEQVQokT1Si5arIBCLDIqCiogP8FHtWvv/n3iH7vZyDjDMQAIJwLdlpVIlz0L8T0FAxDaTy5JBrWn52ZhxoO6tQ+ZyjT7fJSqRpYJAJte8qbDPmxKPY4vgXOqdhramwzp6B1GTKRJahjjVVdlQI3FauiTahkOmFfHyJ9qJduC2lHf4o69weiZYyLyAYvLWFe3O1apHa80AsZOpGfdhZrLHDfSDwpumFuVO5HqI8xot3xvrM5Qy+DGiqo3fTgbvteRRT36AHmlk2J/R26vlbHmuiMVrWtOlpoGPX2a2wV3BMjQiNSXakezVA50zfvbHyGTMQlcFnRNtRQXEl3u4lklWVRi6FNRuyTRD/5E7sXehvIlCBM6c3zBed3E/dNKqCdlg/bRIlENj/XHMxztphdUGxNxTKNhAPbz3/edjlEC0uRTLc6b81syu5K8fPOhxKtAvm5/NMw/vNRNfy1U9hUKpbnFNsyh8v0Pa0A/O1SyE+LrxV6mSdjH2gsPf/D//7BjTQny+YwAAAABJRU5ErkJggg==
// @grant none // @grant none
// @run-at document-idle
// ==/UserScript== // ==/UserScript==
(function() { (function() {
@@ -14727,9 +14728,57 @@
} }
return totalSum; return totalSum;
} }
// 创建并添加按钮
var button = document.createElement('button'); // 方便快速查询前一月、前二月、前三月
var copiedStyles = { function simulateDateInput(elementId, dateValue) {
const inputElement = document.getElementById(elementId);
if (!inputElement) {
console.error(`未找到ID为 ${elementId} 的输入框`);
return;
}
inputElement.focus();
inputElement.value = dateValue;
inputElement.dispatchEvent(new Event('input', {
bubbles: true,
cancelable: true
}));
inputElement.dispatchEvent(new Event('change', {
bubbles: true,
cancelable: true
}));
inputElement.blur();
}
function getCustomMonthRange(monthsAgo) {
const now = new Date();
let year = now.getFullYear();
let month = now.getMonth() - monthsAgo;
while (month < 0) {
month += 12;
year--;
}
const firstDay = new Date(year, month - 1, 20);
const lastDay = new Date(year, month, 19);
const formatLocal = (date) => {
return date.toLocaleDateString('en-CA', {
year: 'numeric',
month: '2-digit',
day: '2-digit'
}).replace(/\//g, '-');
};
return {
firstDay: formatLocal(firstDay),
lastDay: formatLocal(lastDay)
};
}
// 创建菜单按钮
function createMenueButton(text, options = {}) {
const button = document.createElement('button');
button.textContent = text;
const copiedStyles = {
webkitTapHighlightColor: "rgba(0, 0, 0, 0)", webkitTapHighlightColor: "rgba(0, 0, 0, 0)",
fontFamily: '"Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif', fontFamily: '"Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif',
fontSize: "14px", fontSize: "14px",
@@ -14746,15 +14795,84 @@
color: "#e5e5e5", color: "#e5e5e5",
}; };
Object.assign(button.style, copiedStyles); Object.assign(button.style, copiedStyles);
button.textContent = '统计加班时间';
// 添加点击事件监听器 // 处理点击事件回调
button.addEventListener('click', function() { if (typeof options.onClick === 'function') {
var message = sumOfSecondColumn('grid').toFixed(2); button.addEventListener('click', options.onClick);
var table = document.querySelector("#gview_grid > div.ui-state-default.ui-jqgrid-hdiv > div > table > thead > tr") }
var rows = table.getElementsByTagName('th'); return button;
}
// 查询工作时间
function get_work_time() {
const message = sumOfSecondColumn('grid').toFixed(2);
const table = document.querySelector("#gview_grid > div.ui-state-default.ui-jqgrid-hdiv > div > table > thead > tr")
const rows = table.getElementsByTagName('th');
// 修改表头 // 修改表头
rows[5].querySelector('#jqgh_grid_fillCardTimeStr').textContent = `加班时间(${message}小时)`; rows[5].querySelector('#jqgh_grid_fillCardTimeStr').textContent = `加班时间(${message}小时)`;
}
var query_button = document.getElementById("query");
// 创建菜单按钮
const button = createMenueButton("统计加班时间", {
onClick: () => {
get_work_time();
}
})
const button0 = createMenueButton('查当月', {
onClick: () => {
const month = getCustomMonthRange(0);
const firstDay = month.firstDay;
const lastDay = month.lastDay;
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
simulateDateInput('beginDate', firstDay);
simulateDateInput('endDate', lastDay);
query_button.click();
setTimeout(function() {
get_work_time();
}, 500);
}
});
const button1 = createMenueButton('查上月', {
onClick: () => {
const month = getCustomMonthRange(1);
const firstDay = month.firstDay;
const lastDay = month.lastDay;
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
simulateDateInput('beginDate', firstDay);
simulateDateInput('endDate', lastDay);
query_button.click();
setTimeout(function() {
get_work_time();
}, 500);
}
});
const button2 = createMenueButton('查上上月', {
onClick: () => {
const month = getCustomMonthRange(2);
const firstDay = month.firstDay;
const lastDay = month.lastDay;
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
simulateDateInput('beginDate', firstDay);
simulateDateInput('endDate', lastDay);
query_button.click();
setTimeout(function() {
get_work_time();
}, 500);
}
});
const button3 = createMenueButton('查上上上月', {
onClick: () => {
const month = getCustomMonthRange(3);
const firstDay = month.firstDay;
const lastDay = month.lastDay;
console.log(`firstDay: ${firstDay}, lastDay ${lastDay}`)
simulateDateInput('beginDate', firstDay);
simulateDateInput('endDate', lastDay);
query_button.click();
setTimeout(function() {
get_work_time();
}, 500);
}
}); });
// 获取要将按钮添加到其中的容器 // 获取要将按钮添加到其中的容器
@@ -14763,6 +14881,10 @@
container = document.body; container = document.body;
} }
container.appendChild(button); container.appendChild(button);
container.appendChild(button0);
container.appendChild(button1);
container.appendChild(button2);
container.appendChild(button3);
console.log("复旦微加班时间统计脚本已加载"); console.log("复旦微加班时间统计脚本已加载");
console.log("点击按钮后会统计加班时间"); console.log("点击按钮后会统计加班时间");
})(); })()