数字督察一体化平台-案件核查浏览器插件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

324 lines
12 KiB

import {
checkUpdateUrl,
supervisionAjhcCheckTrueSituationUrl,
supervisionAjhcDisposalDetailsUrl,
supervisionAjhcDisposalOpinionUrl,
supervisionAjhcFileUploadUrl,
supervisionAjhcIdsUrl,
supervisionAjhcInfoUrl
} from "../../globalConfig";
import { ajax } from "../utils/ajax";
import request = chrome.permissions.request
console.log('后台开始运行');
// 当前申请案件办结的outerId
let curCompletionOuterId: string | null = null;
//捕获请求接口
chrome.webRequest.onBeforeRequest.addListener(
/*
案件核查-上传附件-核查报告
*/
(details) => {
// 检查是否是目标接口
if (details.url === "http://11.33.3.4/api/v5/gzzx/ajhc/hcbg") {
// 获取请求体
const requestBody = details.requestBody;
if (requestBody) {
// 检查请求体是否为JSON格式
if (requestBody.raw && requestBody.raw.length > 0) {
const rawBytes = requestBody.raw[0].bytes;
// 检查 rawBytes 是否为 undefined
if (rawBytes) {
const decoder = new TextDecoder('utf-8');
const requestBodyString = decoder.decode(rawBytes);
try {
const requestBodyJson = JSON.parse(requestBodyString);
const fileUrl = requestBodyJson.wjUrl;
const fileName = requestBodyJson.wjMc;
const outerId = requestBodyJson.ajId;
const fileType = "核查报告";
// 发送wjUrl和ajId到指定接口
ajax(supervisionAjhcFileUploadUrl, {
method: "POST",
body: { fileUrl, fileName, outerId, fileType }
})
.then((data: any) => console.log("Success:", data))
.catch((error: any) => console.error("Error:", error));
} catch (error) {
console.error("上传核查报告Error parsing JSON:", error);
}
} else {
console.error("上传核查报告requestBody.raw[0].bytes is undefined");
}
}
}
}
else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajhc/zjxx") {
/*
案件核查-上传附件-核查证据
*/
// 获取请求体
const requestBody = details.requestBody;
if (requestBody) {
if (requestBody.raw && requestBody.raw.length > 0) {
const rawBytes = requestBody.raw[0].bytes;
if (rawBytes) {
const decoder = new TextDecoder('utf-8');
const requestBodyString = decoder.decode(rawBytes);
try {
const requestBodyJson = JSON.parse(requestBodyString);
if (requestBodyJson.fj && requestBodyJson.fj.length > 0) {
const fileUrl = requestBodyJson.fj[0].wjUrl;
const fileName = requestBodyJson.fj[0].wjMc;
const outerId = requestBodyJson.ajId;
const fileType = "核查证据";
// 发送wjUrl和ajId到指定接口
ajax(supervisionAjhcFileUploadUrl, {
method: "POST",
body: { fileUrl, fileName, outerId, fileType }
})
.then((data: any) => console.log("Success:", data))
.catch((error: any) => console.error("Error:", error));
}
} catch (error) {
console.error("上传核查证据Error parsing JSON:", error);
}
} else {
console.error("上传核查证据requestBody.raw[0].bytes is undefined");
}
}
}
}
else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajcz") {
/*
案件核查-上传处置意见
*/
const requestBody = details.requestBody;
if (requestBody) {
if (requestBody.raw && requestBody.raw.length > 0) {
const rawBytes = requestBody.raw[0].bytes;
if (rawBytes) {
const decoder = new TextDecoder('utf-8');
const requestBodyString = decoder.decode(rawBytes);
try {
const requestBodyJson = JSON.parse(requestBodyString);
const handlingSuggestions = requestBodyJson.cljg;
const outerId = requestBodyJson.ajId;
const trueSituation = requestBodyJson.ssqkMc;
const complaintNature = requestBodyJson.tsWtxz;
ajax(supervisionAjhcDisposalOpinionUrl, {
method: "POST",
body: { handlingSuggestions, outerId, trueSituation, complaintNature }
})
.then((data: any) => console.log("Success:", data))
.catch((error: any) => console.error("Error:", error));
} catch (error) {
console.error("上传处置意见Error parsing JSON:", error);
}
} else {
console.error("上传处置意见requestBody.raw[0].bytes is undefined");
}
}
}
}
else if (details.url === "http://11.33.3.4/api/v5/gzzx/ajcz/czmx") {
/*
案件核查-上传处置明细
*/
const requestBody = details.requestBody;
if (requestBody) {
if (requestBody.raw && requestBody.raw.length > 0) {
const rawBytes = requestBody.raw[0].bytes;
if (rawBytes) {
const decoder = new TextDecoder('utf-8');
const requestBodyString = decoder.decode(rawBytes);
try {
const requestBodyJson = JSON.parse(requestBodyString);
const outerId = requestBodyJson.ajId;
const disposalType = requestBodyJson.czlx;
const disposalDepart = requestBodyJson.czDw;
const disposalAlarm = requestBodyJson.czJh;
const disposalName = requestBodyJson.czMc;
const disposalIdNo = requestBodyJson.czSfz;
const disposalSituation = requestBodyJson.czqk;
const disposalFileUrl = requestBodyJson.flwsUrl;
const disposalFileName = requestBodyJson.flwsMc;
const disposalSituationDescription = requestBodyJson.qksm;
ajax(supervisionAjhcDisposalDetailsUrl, {
method: "POST",
body: { outerId, disposalType, disposalDepart, disposalAlarm, disposalName, disposalIdNo, disposalSituation, disposalFileUrl, disposalFileName, disposalSituationDescription }
})
.then((data: any) => console.log("Success:", data))
.catch((error: any) => console.error("Error:", error));
} catch (error) {
console.error("上传处置明细Error parsing JSON:", error);
}
} else {
console.error("上传处置明细requestBody.raw[0].bytes is undefined");
}
}
}
}
else if (details.url.startsWith("http://11.33.3.4/api/v5/gzzx/bj/anqx/")) {
/*
案件核查-获取案件办结案件id
*/
const url = new URL(details.url);
const pathSegments = url.pathname.split('/');
curCompletionOuterId = pathSegments[pathSegments.length - 1];
}
},
{ urls: ["<all_urls>"] },
["requestBody"] // 显式请求 requestBody
);
/*
案件核查-提供当前申请案件办结的outerId
*/
// 监听来自 contentScript 的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getCurCompletionOuterId') {
console.log('发送getCurCompletionOuterId:' + curCompletionOuterId);
sendResponse(curCompletionOuterId);
}
});
/*
案件核查-ID列表上传
*/
// 监听来自 contentScript 的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'fetchDataRowKeys') {
const dataRowKeyMaps = request.data;
// 使用 ajax 方法发送请求
ajax(supervisionAjhcIdsUrl, {
method: 'POST',
body: dataRowKeyMaps
})
.then((data: any) => {
console.log('ID列表上传Success:', data);
sendResponse({ status: 'success', data });
})
.catch((error: any) => {
console.error('ID列表上传Error:', error);
sendResponse({ status: 'error', error });
});
return true;
}
});
/*
案件核查-投诉受理数据上传
*/
console.log('background-data---------')
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'sendAjhcData') {
console.log('案件核查-投诉受理数据上传')
const { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel } = request.data;
// 使用 ajax 方法发送请求
ajax(supervisionAjhcInfoUrl, {
method: 'POST',
body: { caseNumber, caseSource, complaintTime, reporterName, reporterContact, verifiedObjectUnit, verifiedObjectUnitCode, verifiedObjectName, verifiedObjectPosition, briefCase, organization, complaintIssueNature, acceptanceLevel }
})
.then((data: any) => {
console.log('投诉受理数据上传Success:', data);
sendResponse({ status: 'success', data });
})
.catch((error: any) => {
console.error('投诉受理数据上传Error:', error);
sendResponse({ status: 'error', error });
});
return true;
}
});
/*
* 案件核查-检查是否需要填表
*/
// 监听来自 contentScript 的消息
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'checkTrueSituation') {
// 检查 curCompletionOuterId 是否为 null
if (curCompletionOuterId !== null) {
// 使用 ajax 方法发送请求
ajax(`${supervisionAjhcCheckTrueSituationUrl}${encodeURIComponent(curCompletionOuterId)}`, {
method: 'GET'
})
.then((data: any) => {
console.log('检查是否需要填表Success:', data);
sendResponse({ status: 'success', data });
})
.catch((error: any) => {
console.error('检查是否需要填表Error:', error);
sendResponse({ status: 'error', error });
});
} else {
console.error('curCompletionOuterId is null, cannot send request');
sendResponse({ status: 'error', error: 'curCompletionOuterId is null' });
}
return true;
}
});
/*
插件更新升级
*/
checkUpdate(); // 插件刚打开时立即运行一次检查更新方法
setInterval(checkUpdate, 600000); // 每10分钟检查一次
// 版本检查
async function checkUpdate() {
try {
const response = await fetch(checkUpdateUrl);
const data = await response.json();
const currentVersion = chrome.runtime.getManifest().version;
if (compareVersions(data.version, currentVersion) > 0) {
showUpdateNotification(data.downloadUrl);
}
} catch (error) {
console.error('检测更新失败:', error);
}
}
// 版本号比较
function compareVersions(a: string, b: string): number {
const aParts = a.split('.').map(Number);
const bParts = b.split('.').map(Number);
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
const aVal = aParts[i] || 0;
const bVal = bParts[i] || 0;
if (aVal !== bVal) return aVal - bVal;
}
return 0;
}
// 显示更新通知
function showUpdateNotification(downloadUrl: string) {
console.log('发现新版本,显示更新通知');
chrome.notifications.create({
type: 'basic',
iconUrl: 'img/logo-128.png',
title: '发现新版本,为避免出错,请立即更新!',
message: '点击此处下载数字督查最新版本插件',
priority: 2
});
// 保存下载URL
chrome.storage.local.set({ updateUrl: downloadUrl });
}
// 处理通知点击
chrome.notifications.onClicked.addListener(() => {
chrome.storage.local.get('updateUrl', (result) => {
if (result.updateUrl) {
chrome.tabs.create({ url: result.updateUrl });
}
});
});