rpt_public.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. const PUB_STAMP_SIZE_WIDTH = 5 * 96 / 2.54; // 公章大小:宽度(5 CM)
  2. const PUB_STAMP_SIZE_HEIGHT = 5 * 96 / 2.54; // 公章大小:高度(5 CM)
  3. function getScreenDPI() {
  4. if (SCREEN_DPI.length === 0) {
  5. if (window.screen.deviceXDPI != undefined) {
  6. SCREEN_DPI.push(window.screen.deviceXDPI);
  7. SCREEN_DPI.push(window.screen.deviceYDPI);
  8. } else {
  9. let tmpNode = document.createElement("DIV");
  10. tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden";
  11. document.body.appendChild(tmpNode);
  12. SCREEN_DPI.push(parseInt(tmpNode.offsetWidth));
  13. SCREEN_DPI.push(parseInt(tmpNode.offsetHeight));
  14. tmpNode.parentNode.removeChild(tmpNode);
  15. }
  16. }
  17. return SCREEN_DPI;
  18. }
  19. function setupDateFormat() {
  20. Date.prototype.Format = function (fmt) {
  21. let o = {
  22. "M+": this.getMonth() + 1, //月份
  23. "d+": this.getDate(), //日
  24. "h+": this.getHours(), //小时
  25. "m+": this.getMinutes(), //分
  26. "s+": this.getSeconds(), //秒
  27. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  28. "S": this.getMilliseconds() //毫秒
  29. };
  30. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  31. for (let k in o)
  32. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  33. return fmt;
  34. };
  35. }
  36. function dynamicLoadJs(url, type, callback) {
  37. let head = document.getElementsByTagName('head')[0];
  38. let script = document.createElement('script');
  39. script.type = 'text/javascript';
  40. script.src = url;
  41. if(callback) {
  42. script.onload = script.onreadystatechange = function (event) {
  43. callback(type);
  44. script.onload = script.onreadystatechange = null;
  45. };
  46. }
  47. head.appendChild(script);
  48. }
  49. /**
  50. * 获取 blob
  51. * @param {String} url 目标文件地址
  52. * @return {Promise}
  53. */
  54. function getBlobPublic(url) {
  55. return new Promise(resolve => {
  56. const xhr = new XMLHttpRequest();
  57. xhr.open('GET', url, true);
  58. xhr.responseType = 'blob';
  59. xhr.onload = () => {
  60. if (xhr.status === 200) {
  61. resolve(xhr.response);
  62. } else {
  63. resolve('not found!');
  64. }
  65. };
  66. xhr.send();
  67. });
  68. }
  69. function getProperSignatureArea(cell, control, offsetX, offsetY, JV = null) {
  70. // 约定默认长宽比例是2:1,图片分辨率是600*300
  71. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  72. if (JV) {
  73. if (cell && cell[JV.PROP_AREA]) {
  74. if (cell.hasOwnProperty('isOrgShow') && cell.isOrgShow) {
  75. rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  76. rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
  77. rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  78. rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  79. } else {
  80. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  81. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP],
  82. centerPh = (cell[JV.PROP_AREA][JV.PROP_RIGHT] + cell[JV.PROP_AREA][JV.PROP_LEFT]) / 2,
  83. centerPv = (cell[JV.PROP_AREA][JV.PROP_BOTTOM] + cell[JV.PROP_AREA][JV.PROP_TOP]) / 2
  84. ;
  85. if (width > height * 2) {
  86. width = height * 2;
  87. } else {
  88. height = width / 2;
  89. }
  90. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  91. case 'left':
  92. rst[JV.IDX_LEFT] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  93. rst[JV.IDX_RIGHT] = rst[0] + width;
  94. break;
  95. case 'right':
  96. rst[JV.IDX_RIGHT] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  97. rst[JV.IDX_LEFT] = rst[JV.IDX_RIGHT] - width;
  98. break;
  99. default:
  100. //center
  101. rst[JV.IDX_LEFT] = centerPh - width / 2;
  102. rst[JV.IDX_RIGHT] = centerPh + width / 2;
  103. break;
  104. }
  105. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  106. case 'top':
  107. rst[JV.IDX_TOP] = cell[JV.PROP_AREA][JV.PROP_TOP];
  108. rst[JV.IDX_BOTTOM] = rst[JV.IDX_TOP] + height;
  109. break;
  110. case 'bottom':
  111. rst[JV.IDX_BOTTOM] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  112. rst[JV.IDX_TOP] = rst[JV.IDX_BOTTOM] - height;
  113. break;
  114. default:
  115. //center
  116. rst[JV.IDX_TOP] = centerPv - height / 2;
  117. rst[JV.IDX_BOTTOM] = centerPv + height / 2;
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. rst[0] = rst[0] + offsetX;
  124. rst[2] = rst[2] + offsetX;
  125. rst[1] = rst[1] + offsetY;
  126. rst[3] = rst[3] + offsetY;
  127. return rst;
  128. }
  129. function resetStampArea(ctrl, stampCell, JV, stampFeature = 'not found!') {
  130. let pLeft = stampCell.orgArea.Left,
  131. pTop = stampCell.orgArea.Top;
  132. if (stampFeature !== 'not found!') {
  133. let std_stamp_size_width = PUB_STAMP_SIZE_WIDTH, std_stamp_size_height = PUB_STAMP_SIZE_HEIGHT;
  134. let widthRate = 1, heightRate = 1;
  135. if (stampFeature) {
  136. std_stamp_size_width = parseFloat(stampFeature.ImageWidth.value);
  137. std_stamp_size_height = parseFloat(stampFeature.ImageHeight.value);
  138. if (stampFeature.ImageWidth.value !== stampFeature.ImageHeight.value) {
  139. //设置比例
  140. if (std_stamp_size_width > std_stamp_size_height) {
  141. heightRate = std_stamp_size_height / std_stamp_size_width;
  142. } else {
  143. widthRate = std_stamp_size_width / std_stamp_size_height;
  144. }
  145. }
  146. if (std_stamp_size_width > PUB_STAMP_SIZE_WIDTH || std_stamp_size_height > PUB_STAMP_SIZE_HEIGHT) {
  147. if (widthRate === 1) {
  148. std_stamp_size_width = Math.min(std_stamp_size_width, PUB_STAMP_SIZE_WIDTH);
  149. std_stamp_size_height = std_stamp_size_width * heightRate;
  150. } else {
  151. std_stamp_size_height = Math.min(std_stamp_size_height, PUB_STAMP_SIZE_HEIGHT);
  152. std_stamp_size_width = std_stamp_size_height * widthRate;
  153. }
  154. }
  155. }
  156. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  157. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_LEFT]:
  158. pLeft = stampCell.orgArea.Left;
  159. break;
  160. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_CENTER]:
  161. pLeft = (stampCell.orgArea.Left + stampCell.orgArea.Right - std_stamp_size_width) / 2;
  162. break;
  163. case JV.OUTPUT_ALIGN.H[JV.H_ALIGN_IDX_RIGHT]:
  164. pLeft = stampCell.orgArea.Right - std_stamp_size_width;
  165. break;
  166. default:break;
  167. }
  168. switch (ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  169. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_TOP]:
  170. pTop = stampCell.orgArea.Top;
  171. break;
  172. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_CENTER]:
  173. pTop = (stampCell.orgArea.Top + stampCell.orgArea.Bottom - std_stamp_size_height) / 2;
  174. break;
  175. case JV.OUTPUT_ALIGN.H[JV.V_ALIGN_IDX_BOTTOM]:
  176. pTop = stampCell.orgArea.Bottom - std_stamp_size_height;
  177. break;
  178. default:break;
  179. }
  180. stampCell.area.Left = pLeft;
  181. stampCell.area.Top = pTop;
  182. stampCell.area.Right = pLeft + std_stamp_size_width;
  183. stampCell.area.Bottom = pTop + std_stamp_size_height;
  184. // 最后一步,如超过报表范围,则要调整坐标
  185. if (stampCell.maxRect) {
  186. const maxRect = stampCell.maxRect;
  187. if (stampCell.area.Left < maxRect[0]) {
  188. const width = maxRect[0] - stampCell.area.Left;
  189. stampCell.area.Left += width;
  190. stampCell.area.Right += width;
  191. }
  192. if (stampCell.area.Top < maxRect[1]) {
  193. const height = maxRect[1] - stampCell.area.Top;
  194. stampCell.area.Top += height;
  195. stampCell.area.Bottom += height;
  196. }
  197. if (stampCell.area.Right > maxRect[2]) {
  198. const width = maxRect[2] - stampCell.area.Right; // 负
  199. stampCell.area.Left += width;
  200. stampCell.area.Right += width;
  201. }
  202. if (stampCell.area.Bottom > maxRect[3]) {
  203. const height = maxRect[3] - stampCell.area.Bottom;
  204. stampCell.area.Top += height;
  205. stampCell.area.Bottom += height;
  206. }
  207. }
  208. }
  209. }
  210. async function getPicFeature(picPath) {
  211. const rst = await getHttpBlobText(picPath + '?x-oss-process=image/info');
  212. return rst;
  213. }
  214. function getHttpBlobText(url) {
  215. return new Promise(resolve => {
  216. const xhr = new XMLHttpRequest();
  217. // let fullUrl = url + '?x-oss-process=image/info';
  218. xhr.open('GET', url, true);
  219. xhr.responseType = 'json';
  220. xhr.onload = () => {
  221. if (xhr.status === 200) {
  222. resolve(xhr.response);
  223. } else {
  224. resolve('not found!');
  225. }
  226. };
  227. xhr.send();
  228. });
  229. }