// ==UserScript== // @name Sayyoo-CCBHome-Contract-Export-Script // @namespace http://tampermonkey.net/ // @version SCCES-0.0.0.1 // @description try to take over the world! // @author You // @match https://hess.qiye.ccbhome.cn/* // @icon https://www.google.com/s2/favicons?sz=64&domain=hess.qiye.ccbhome.cn // @grant GM_xmlhttpRequest // @require https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js // ==/UserScript== // http://sygit.sayyoo.cn/public-group/tampermonkey-scripts/blob/master/hess_qiye_ccbhome_cn.monkey.js 'use strict'; function init() { var actions_btn_box = document.querySelector(".actions") if (!actions_btn_box) { console.log("#》#》#》no match actions_btn_box"); }else{ console.log("#》#》#》actions_btn_box:", actions_btn_box); // 创建 Excel 导出页面元素 var export_excel_node = document.createElement("div"); export_excel_node.className = "btn-group pull-right"; export_excel_node.innerHTML = ''+ ''; actions_btn_box.append(export_excel_node); document.querySelector("#sayyooBtnExport").onclick = function(){ DoSayyooExport(); } } } setTimeout(init, 1000); function DoSayyooExport() { var longRentCodeJson = sessionStorage.getItem('zeroCloud-longRentCode'); console.log("#>#>#>#>#>#>#>#>"+longRentCodeJson) var sessionCode = JSON.parse(longRentCodeJson); var dataRequestURL = 'https://hess.qiye.ccbhome.cn/changzu/contract/list-data?draw=2'+ '&start=0&length=20&search[value]=&search[regex]=false'+ '&project_id=?&village_id=?&keyword='+ '&begin_date=2023-12-07'+//TODO '&end_date=2023-12-14'+//TODO '&signed_time=&rentDicountId=&is_expire_contract='+ '&code='+sessionCode.content '&form=1'+ '&_='+sessionCode.datetime; console.log("#>#>#>#>#>#>#>#>"+dataRequestURL) GM_xmlhttpRequest({ headers: {'content-type': 'application/json'}, responseType: 'json', url: dataRequestURL, method: 'GET', onreadystatechange: (res) => { if (res.readyState === 4) { console.log("#>#>#>#>#>#>#>#>"+res.response) var jsonData = rebuildJsonData(res.response.data); var dataSheet = XLSX.utils.json_to_sheet(jsonData); var jsonBlob = sheet2blob(dataSheet); const downloadHref = URL.createObjectURL(jsonBlob); const downloadLink = document.createElement("a"); downloadLink.href = downloadHref; downloadLink.download = "sayyooExport" + ".xlsx"; document.body.appendChild(downloadLink); downloadLink.click(); document.body.removeChild(downloadLink); URL.revokeObjectURL(downloadHref); } }, }) } function rebuildJsonData(jsonData){ var buildJson = []; for(let i = 0; i < jsonData.length; i++) { var buildJsonRow = { 系统合同编号 : jsonData[i].id, 自定义合同编号 : jsonData[i].contract_no, 房源编号 : jsonData[i].room_id, 房号 : jsonData[i].room_num, 月租金 : jsonData[i].monthly_rent, 押金 : jsonData[i].hasDeposite, 押金类型 : jsonData[i].id, 转租服务费_换房服务费 : jsonData[i].id, 签约日期 : jsonData[i].signed_time, 承租日 : jsonData[i].origin_begin_date, 到期日 : jsonData[i].origin_end_date, 实际退房日期 : jsonData[i].end_date, 付款周期 : jsonData[i].id, 客户姓名 : jsonData[i].id, 通讯地址 : jsonData[i].id, 电子邮箱 : jsonData[i].id, 账单交费期限 : jsonData[i].id, 租赁面积 : jsonData[i].id, 折扣方案 : jsonData[i].id, 对外房源编号 : jsonData[i].id, 业务人员姓名 : jsonData[i].id, 业务人员手机号码 : jsonData[i].id, 电费押金 : jsonData[i].id, 出租类型 : jsonData[i].id, 合同备注 : jsonData[i].id, 上上签合同编号 : jsonData[i].id, 房源获取渠道 : jsonData[i].id }; buildJson.push(buildJsonRow); } return buildJson; } function sheet2blob(sheet, sheetName) { sheetName = sheetName || 'sheet1'; var workbook = { SheetNames: [sheetName], Sheets: {} }; workbook.Sheets[sheetName] = sheet; // 生成excel的配置项 var wopts = { bookType: 'xlsx', // 要生成的文件类型 bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性 type: 'binary' }; var wbout = XLSX.write(workbook, wopts); var blob = new Blob([s2ab(wbout)], {type:"application/octet-stream"}); // 字符串转ArrayBuffer function s2ab(s) { var buf = new ArrayBuffer(s.length); var view = new Uint8Array(buf); for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; return buf; } return blob; }