| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- const PUB_STAMP_SIZE_WIDTH = 5 * 96 / 2.54; // 公章大小:宽度(5 CM)
- const PUB_STAMP_SIZE_HEIGHT = 5 * 96 / 2.54; // 公章大小:高度(5 CM)
- function getScreenDPI() {
- if (SCREEN_DPI.length === 0) {
- if (window.screen.deviceXDPI != undefined) {
- SCREEN_DPI.push(window.screen.deviceXDPI);
- SCREEN_DPI.push(window.screen.deviceYDPI);
- } else {
- let tmpNode = document.createElement("DIV");
- tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
- document.body.appendChild(tmpNode);
- SCREEN_DPI.push(parseInt(tmpNode.offsetWidth));
- SCREEN_DPI.push(parseInt(tmpNode.offsetHeight));
- tmpNode.parentNode.removeChild(tmpNode);
- }
- }
- return SCREEN_DPI;
- }
- function setupDateFormat() {
- Date.prototype.Format = function (fmt) {
- let o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (let k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- };
- }
- function dynamicLoadJs(url, type, callback) {
- let head = document.getElementsByTagName('head')[0];
- let script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = url;
- if(callback) {
- script.onload = script.onreadystatechange = function (event) {
- callback(type);
- script.onload = script.onreadystatechange = null;
- };
- }
- head.appendChild(script);
- }
- /**
- * 获取 blob
- * @param {String} url 目标文件地址
- * @return {Promise}
- */
- function getBlobPublic(url) {
- return new Promise(resolve => {
- const xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.responseType = 'blob';
- xhr.onload = () => {
- if (xhr.status === 200) {
- resolve(xhr.response);
- } else {
- resolve('not found!');
- }
- };
- xhr.send();
- });
- }
- function getProperSignatureArea(cell, control, offsetX, offsetY, JV = null) {
- // 约定默认长宽比例是2:1,图片分辨率是600*300
- const rst = [0, 0, 0, 0]; // left, top, right, bottom
- if (JV) {
- if (cell && cell[JV.PROP_AREA]) {
- if (cell.hasOwnProperty('isOrgShow') && cell.isOrgShow) {
- rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
- rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
- rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
- rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
- } else {
- let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
- height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP],
- centerPh = (cell[JV.PROP_AREA][JV.PROP_RIGHT] + cell[JV.PROP_AREA][JV.PROP_LEFT]) / 2,
- centerPv = (cell[JV.PROP_AREA][JV.PROP_BOTTOM] + cell[JV.PROP_AREA][JV.PROP_TOP]) / 2
- ;
- if (width > height * 2) {
- width = height * 2;
- } else {
- height = width / 2;
- }
- switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
- case 'left':
- rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
- rst[JV.IDX_RIGHT] = rst[0] + width;
- break;
- case 'right':
- rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
- rst[JV.IDX_LEFT] = rst[JV.IDX_RIGHT] - width;
- break;
- default:
- //center
- rst[JV.IDX_LEFT] = centerPh - width / 2;
- rst[JV.IDX_RIGHT] = centerPh + width / 2;
- break;
- }
- switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
- case 'top':
- rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
- rst[JV.IDX_BOTTOM] = rst[JV.IDX_TOP] + height;
- break;
- case 'bottom':
- rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
- rst[JV.IDX_TOP] = rst[JV.IDX_BOTTOM] - height;
- break;
- default:
- //center
- rst[JV.IDX_TOP] = centerPv - height / 2;
- rst[JV.IDX_BOTTOM] = centerPv + height / 2;
- break;
- }
- }
- }
- }
- rst[0] = rst[0] + offsetX;
- rst[2] = rst[2] + offsetX;
- rst[1] = rst[1] + offsetY;
- rst[3] = rst[3] + offsetY;
- return rst;
- }
- function resetStampArea(ctrl, stampCell, JV, stampFeature = 'not found!') {
- let pLeft = stampCell.orgArea.Left,
- pTop = stampCell.orgArea.Top;
- if (stampFeature !== 'not found!') {
- let std_stamp_size_width = PUB_STAMP_SIZE_WIDTH, std_stamp_size_height = PUB_STAMP_SIZE_HEIGHT;
- let widthRate = 1, heightRate = 1;
- if (stampFeature) {
- std_stamp_size_width = parseFloat(stampFeature.ImageWidth.value);
- std_stamp_size_height = parseFloat(stampFeature.ImageHeight.value);
- if (stampFeature.ImageWidth.value !== stampFeature.ImageHeight.value) {
- //设置比例
- if (std_stamp_size_width > std_stamp_size_height) {
- heightRate = std_stamp_size_height / std_stamp_size_width;
- } else {
- widthRate = std_stamp_size_width / std_stamp_size_height;
- }
- }
- if (std_stamp_size_width > PUB_STAMP_SIZE_WIDTH || std_stamp_size_height > PUB_STAMP_SIZE_HEIGHT) {
- if (widthRate === 1) {
- std_stamp_size_width = Math.min(std_stamp_size_width, PUB_STAMP_SIZE_WIDTH);
- std_stamp_size_height = std_stamp_size_width * heightRate;
- } else {
- std_stamp_size_height = Math.min(std_stamp_size_height, PUB_STAMP_SIZE_HEIGHT);
- std_stamp_size_width = std_stamp_size_height * widthRate;
- }
- }
- }
- switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
- case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
- pLeft = stampCell.orgArea.Left;
- break;
- case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
- pLeft = (stampCell.orgArea.Left + stampCell.orgArea.Right - std_stamp_size_width) / 2;
- break;
- case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
- pLeft = stampCell.orgArea.Right - std_stamp_size_width;
- break;
- default:break;
- }
- switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
- case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
- pTop = stampCell.orgArea.Top;
- break;
- case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
- pTop = (stampCell.orgArea.Top + stampCell.orgArea.Bottom - std_stamp_size_height) / 2;
- break;
- case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
- pTop = stampCell.orgArea.Bottom - std_stamp_size_height;
- break;
- default:break;
- }
- stampCell.area.Left = pLeft;
- stampCell.area.Top = pTop;
- stampCell.area.Right = pLeft + std_stamp_size_width;
- stampCell.area.Bottom = pTop + std_stamp_size_height;
- // 最后一步,如超过报表范围,则要调整坐标
- if (stampCell.maxRect) {
- const maxRect = stampCell.maxRect;
- if (stampCell.area.Left < maxRect[0]) {
- const width = maxRect[0] - stampCell.area.Left;
- stampCell.area.Left += width;
- stampCell.area.Right += width;
- }
- if (stampCell.area.Top < maxRect[1]) {
- const height = maxRect[1] - stampCell.area.Top;
- stampCell.area.Top += height;
- stampCell.area.Bottom += height;
- }
- if (stampCell.area.Right > maxRect[2]) {
- const width = maxRect[2] - stampCell.area.Right; // 负
- stampCell.area.Left += width;
- stampCell.area.Right += width;
- }
- if (stampCell.area.Bottom > maxRect[3]) {
- const height = maxRect[3] - stampCell.area.Bottom;
- stampCell.area.Top += height;
- stampCell.area.Bottom += height;
- }
- }
- }
- }
- async function getPicFeature(picPath) {
- const rst = await getHttpBlobText(picPath + '?x-oss-process=image/info');
- return rst;
- }
- function getHttpBlobText(url) {
- return new Promise(resolve => {
- const xhr = new XMLHttpRequest();
- // let fullUrl = url + '?x-oss-process=image/info';
- xhr.open('GET', url, true);
- xhr.responseType = 'json';
- xhr.onload = () => {
- if (xhr.status === 200) {
- resolve(xhr.response);
- } else {
- resolve('not found!');
- }
- };
- xhr.send();
- });
- }
- function filterSignCells(pageObj, bkSignCells, bkTxtSignCells, bkPicSignCells, isTextSignature = false, isCloseArchive = false) {
- if (isTextSignature) {
- pageObj.items.forEach((pageItem) => {
- const dtlSignCells = [];
- bkSignCells.push(dtlSignCells);
- for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
- let sCell = pageItem.signature_cells[sCellIdx];
- if (sCell.signature_name.indexOf('dummy_pic') < 0) {
- dtlSignCells.push(sCell);
- pageItem.signature_cells.splice(sCellIdx, 1);
- if (isCloseArchive) {
- // 如果还有closeArchiveSignature标记,那么不显示文本文档(只是清除匹配cell的Value,后续需要恢复)
- const cCell = pageItem.cells.find(cell => cell.area.Left === sCell.area.Left && cell.area.Top === sCell.area.Top && cell.Value === sCell.Value);
- if (cCell) {
- bkTxtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
- cCell.Value = '';
- }
- }
- } else if (isCloseArchive) {
- // 这个跟上面的判断属性不同,是orgArea(签章的)
- for (let cIdx = pageItem.cells.length - 1; cIdx >= 0; cIdx--) {
- const cCell = pageItem.cells[cIdx];
- if (cCell.area.Left === sCell.orgArea.Left && cCell.area.Right === sCell.orgArea.Right &&
- cCell.area.Top === sCell.orgArea.Top && cCell.area.Bottom === sCell.orgArea.Bottom &&
- cCell.Value !== '') {
- bkTxtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
- cCell.Value = '';
- break;
- }
- }
- }
- }
- });
- } else if (isCloseArchive) {
- pageObj.items.forEach((pageItem, pageIdx) => {
- const dtlSignCells = [];
- const dtlDummyCells = [];
- bkSignCells.push(dtlSignCells);
- bkPicSignCells.push(dtlDummyCells);
- for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
- let sCell = pageItem.signature_cells[sCellIdx];
- if (sCell.signature_name.indexOf('dummy_pic') < 0) {
- // IMPORTANT: 所有不是dummy_pic的签名都处理,不用管用户有没有真实选择签名
- dtlSignCells.push(sCell);
- pageItem.signature_cells.splice(sCellIdx, 1);
- // 还得加一个dummy cell,处理边框用的
- const newCell = {
- font: 'Footer',
- control: sCell.control,
- style: sCell.style,
- Value: '',
- area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
- };
- dtlDummyCells.push(newCell);
- pageItem.cells.push(newCell);
- }
- }
- });
- }
- }
- function restoreSignCells(pageObj, bkSignCells, bkTxtSignCells, bkPicSignCells) {
- if (bkSignCells && pageObj.items.length === bkSignCells.length) {
- pageObj.items.forEach((pageItem, pageIdx) => {
- bkSignCells[pageIdx].forEach((srcCell) => {
- pageItem.signature_cells.push(srcCell);
- });
- bkSignCells[pageIdx] = null;
- });
- bkSignCells.splice(0);
- }
- if (bkTxtSignCells && bkTxtSignCells.length) {
- bkTxtSignCells.forEach(txtCellBkObj => {
- txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
- });
- bkTxtSignCells.splice(0);
- }
- if (bkPicSignCells && bkPicSignCells.length === pageObj.items.length) {
- pageObj.items.forEach((pageItem, pageIdx) => {
- bkPicSignCells[pageIdx].forEach((dummyCell) => {
- const idx = pageItem.cells.indexOf(dummyCell);
- if (idx >= 0) pageItem.cells.splice(idx, 1);
- });
- bkPicSignCells[pageIdx] = null;
- });
- bkPicSignCells.splice(0);
- }
- }
- function filterUnchkTplTreeNode(topNode, srcData) {
- const _chkAndSpliceItem = function(pNode, pStr) {
- let rst = false;
- if (srcData.indexOf(pStr + pNode.name) < 0) {
- if (pNode.items && pNode.items.length > 0) {
- for (let subIdx = pNode.items.length - 1; subIdx >= 0; subIdx--) {
- if (!_chkAndSpliceItem(pNode.items[subIdx], pStr + pNode.name + FOLDER_SEPERATER)) {
- pNode.items.splice(subIdx, 1);
- } else {
- rst = true;
- }
- }
- }
- } else {
- rst = true;
- }
- return rst;
- };
- for (let rIdx = topNode.items.length - 1; rIdx >= 0; rIdx--) {
- if (!_chkAndSpliceItem(topNode.items[rIdx], '')) {
- topNode.items.splice(rIdx, 1);
- }
- }
- }
- function filterReportsByType(allCommonTreeNodes, allIndiTreeNodes, current_biz_type, topTreeNodes, custTreeNodes) {
- function _filterBySourceType(nodes, srcType) {
- for (let idx = nodes.length - 1; idx >= 0; idx--) {
- if (!nodes[idx].hasOwnProperty('source_type')) {
- nodes[idx].source_type = 1;
- }
- if (nodes[idx].source_type !== srcType) {
- nodes.splice(idx, 1);
- }
- }
- }
- const newCommonTreeNodes = JSON.parse(JSON.stringify(allCommonTreeNodes));
- const newCustomTreeNodes = JSON.parse(JSON.stringify(allIndiTreeNodes));
- let bizType = 1;
- if (current_biz_type === 'stage') bizType = 1; // 计量期
- if (current_biz_type === 'change_prepay') bizType = 10; // 预付款
- if (current_biz_type === 'change_material_adjustment') bizType = 30; // 材差
- _filterBySourceType(newCommonTreeNodes, bizType);
- _filterBySourceType(newCustomTreeNodes, bizType);
- topTreeNodes[0].items = [];
- topTreeNodes[0].items.push(...newCustomTreeNodes);
- topTreeNodes[1].items = [];
- topTreeNodes[1].items.push(...newCommonTreeNodes);
- if (bizType === 1) {
- filterUnchkTplTreeNode(topTreeNodes[0], custTreeNodes.customize);
- filterUnchkTplTreeNode(topTreeNodes[1], custTreeNodes.common);
- }
- // zTreeOprObj.getReportTemplateTree();
- }
- function chkAndSetNode(parentItem) {
- parentItem.title = '';
- if (parentItem.nodeType === 1) {
- parentItem.isParent = true;
- } else {
- parentItem.title = parentItem.name + '(' + parentItem.refId + ')';
- }
- if (parentItem.items) {
- for (let dtlItem of parentItem.items) {
- chkAndSetNode(dtlItem);
- }
- }
- }
|