base.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. if (!window.wd)
  2. var wd = {};
  3. (function () {
  4. String.prototype.trim = function () {
  5. return this.replace(/(^\s*)|(\s*$)/g, "");
  6. }
  7. String.prototype.ltrim = function () {
  8. return this.replace(/(^\s*)/g, "");
  9. }
  10. String.prototype.rtrim = function () {
  11. return this.replace(/(\s*$)/g, "");
  12. }
  13. if (!("addEventListener" in Element.prototype)) {
  14. console.log("兼容IE8 addEventListener")
  15. Element.prototype.addEventListener = function (type, listener, useCapture) {
  16. this.attachEvent("on" + type, listener);
  17. };
  18. }
  19. if (!("addEventListener" in document.constructor)) {
  20. console.log("兼容IE8 addEventListener")
  21. document.constructor.addEventListener = function (type, listener, useCapture) {
  22. this.attachEvent("on" + type, listener);
  23. };
  24. }
  25. if (!("addEventListener" in document)) {
  26. console.log("兼容IE8 addEventListener")
  27. document.addEventListener = function (type, listener, useCapture) {
  28. this.attachEvent("on" + type, listener);
  29. };
  30. }
  31. if (!("addEventListener" in window.constructor)) {
  32. console.log("兼容IE8 addEventListener")
  33. window.constructor.addEventListener = function (type, listener, useCapture) {
  34. this.attachEvent("on" + type, listener);
  35. };
  36. }
  37. if (!("addEventListener" in window)) {
  38. console.log("兼容IE8 addEventListener")
  39. window.addEventListener = function (type, listener, useCapture) {
  40. this.attachEvent("on" + type, listener);
  41. };
  42. }
  43. if (!("removeEventListener" in Element.prototype)) {
  44. console.log("兼容IE8 removeEventListener")
  45. Element.prototype.removeEventListener = function (type, listener, useCapture) {
  46. this.detachEvent("on" + type, listener);
  47. };
  48. }
  49. if (!("removeEventListener" in document.constructor)) {
  50. console.log("兼容IE8 removeEventListener")
  51. document.constructor.removeEventListener = function (type, listener, useCapture) {
  52. this.detachEvent("on" + type, listener);
  53. };
  54. }
  55. if (!("removeEventListener" in document)) {
  56. console.log("兼容IE8 removeEventListener")
  57. document.removeEventListener = function (type, listener, useCapture) {
  58. this.detachEvent("on" + type, listener);
  59. };
  60. }
  61. if (!("removeEventListener" in window.constructor)) {
  62. console.log("兼容IE8 removeEventListener")
  63. window.constructor.removeEventListener = function (type, listener, useCapture) {
  64. this.detachEvent("on" + type, listener);
  65. };
  66. }
  67. if (!("removeEventListener" in window)) {
  68. console.log("兼容IE8 removeEventListener")
  69. window.removeEventListener = function (type, listener, useCapture) {
  70. this.detachEvent("on" + type, listener);
  71. };
  72. }
  73. })();
  74. // if ("addEventListener" in _el)
  75. // window.constructor.prototype.addEventListener = document.constructor.prototype.addEventListener = Element.prototype.addEventListener = function (type, listener, useCapture) {
  76. // this.attachEvent("on" + type, listener);
  77. // };
  78. // window.constructor.prototype.removeEventListener = document.constructor.prototype.removeEventListener = Element.prototype.removeEventListener = function (type, listener, useCapture) {
  79. // this.detachEvent("on" + type, listener);
  80. // };
  81. (function () {
  82. var currParent = window;
  83. var i = 1;
  84. while (currParent != top) {
  85. try {
  86. currParent.parent[new Date().getMilliseconds()] = 1; //如果这行不报“没权限错误”,才执行下一行。
  87. currParent = currParent.parent;
  88. } catch (e) {
  89. break;
  90. }
  91. }
  92. /**
  93. * 得到同域的顶层窗口,不直接用top,是因为有把WD的页面嵌入到OA的作子页面的情形
  94. * 如果顶层窗口直接用top,当顶层窗口是另一网站时,就会报错。
  95. */
  96. wd.topWindow = currParent;
  97. })();
  98. //----
  99. if (!wd.base) {
  100. wd.base = {};
  101. }
  102. wd.base.win2FitHeight = function (target, url) {
  103. wd.base.refreshApplyIframeHeight(null, url);
  104. var win2 = wd.base.applyIframeElement;
  105. var height = parseInt(win2.getAttribute("height"));
  106. win2.src = wd.base.setRowCountPerPage(url, height,parseInt(win2.offsetWidth));
  107. }
  108. wd.base.applyIframe = function (bj, url, height, minHeight, maxHeight) {
  109. var high = height
  110. var availbleHeight = wd.topWindow.wd.base.refreshApplyIframeHeight();
  111. if (availbleHeight && availbleHeight > 0) {
  112. high = availbleHeight;
  113. }
  114. if (minHeight || maxHeight) {
  115. var id = bj.getAttribute("id");
  116. var divid = id.replace(/[^0-9]/, "m");
  117. var div = document.querySelector("#" + divid);
  118. if (div) {
  119. div.style.height = high + "px";
  120. }
  121. if (document.querySelector("table")) {
  122. document.querySelector("table").setAttribute("width", div.style.width);
  123. }
  124. bj.setAttribute("width", "100%");
  125. bj.setAttribute("height", "100%");
  126. }
  127. bj.src = wd.base.setRowCountPerPage(url, high);
  128. }
  129. //储存应用窗口使用的iframe
  130. if (!wd.base.applyIframeElement)
  131. wd.base.applyIframeElement = null;
  132. /**
  133. * 刷新应用窗口可用高度
  134. * @param {Object} iframeElement
  135. */
  136. wd.base.refreshApplyIframeHeight = function (iframeElement, url) {
  137. if (iframeElement) {
  138. wd.base.applyIframeElement = iframeElement;
  139. }
  140. //自动修复,未改发布程序时的问题
  141. if (!wd.base.applyIframeElement) {
  142. var win = wd.topWindow.document.getElementsByName("win2")[0];
  143. wd.base.applyIframeElement = win;
  144. }
  145. var pageHeight = wd.topWindow.innerHeight || wd.topWindow.document.documentElement.clientHeight || wd.topWindow.document.body.clientHeight
  146. var ifm = wd.base.applyIframeElement;
  147. if (!url)
  148. url = ifm.getAttribute("src");
  149. //强制平铺iframe
  150. try {
  151. var p = /pageWidth=([0-9]+)/.exec(url);
  152. var miniWidth=1025;
  153. if (p) {
  154. //
  155. // var pageWidth = parseInt(p[1]);
  156. //
  157. // var pwidth = parseInt(ifm.parentNode.style.width);
  158. // var marginLeft = "";
  159. // if (pwidth < pageWidth) {
  160. // marginLeft = (pwidth - pageWidth) * 0.5 + "px";
  161. // ifm.width = pageWidth + "px";
  162. // } else {
  163. // ifm.width = "100%";
  164. // }
  165. //
  166. // ifm.style.marginLeft = marginLeft;
  167. } else {
  168. //
  169. // var ibound = ifm.parentNode.getBoundingClientRect();
  170. //
  171. // ifm.width = window.innerWidth + "px";
  172. // ifm.style.marginLeft = -ibound.left + "px";
  173. //顶部,底部留白
  174. pageHeight -= (28);
  175. }
  176. var ibound = ifm.parentNode.getBoundingClientRect();
  177. var marginLeft = -ibound.left + "px";
  178. var usewidth=Math.max($(wd.topWindow).outerWidth(true),1025);
  179. if(!url||wd.display.isPersonalHomePageUrl(url)){
  180. //个人首页
  181. ifm.width =(usewidth)+ "px";
  182. }else{
  183. //管理2
  184. // wd.topWindow.win2width
  185. var width=usewidth;
  186. ifm.width =width+ "px";
  187. var outerWidth=usewidth;
  188. marginLeft=((outerWidth-width)*0.5-ibound.left) +"px";
  189. }
  190. ifm.style.width=(usewidth)+ "px";
  191. ifm.style.marginLeft = marginLeft;
  192. wd.base.setHomeWidth(usewidth);
  193. } catch (e) {
  194. console.error(e);
  195. }
  196. function getTop(e) {
  197. var offset = e.offsetTop;
  198. if (e.offsetParent != null)
  199. offset += getTop(e.offsetParent);
  200. return offset;
  201. }
  202. var result = (pageHeight - getTop(wd.base.applyIframeElement));
  203. wd.base.applyIframeElement.height = result;
  204. if (!wd.topWindow.resizeFrameFunc) {
  205. wd.topWindow.resizeFrameFunc = wd.base.refreshApplyIframeHeight;
  206. wd.topWindow.addEventListener("resize", function () {
  207. wd.topWindow.resizeFrameFunc(wd.base.applyIframeElement);
  208. });
  209. }
  210. return result;
  211. }
  212. /**
  213. * 加载iframe
  214. * 计算窗口高度
  215. * 初始化内门户显示窗口
  216. *
  217. *
  218. *
  219. * @param {Object} iframeName :"win2"
  220. */
  221. wd.base.initApplyIframe = function (iframeName) {
  222. //原页面js使用代码:
  223. // function getTop(e) {
  224. //var offset = e.offsetTop;
  225. //if (e.offsetParent != null) offset += getTop(e.offsetParent);
  226. //return offset;
  227. //}
  228. //(function() {
  229. //var pageHeight = wd.topWindow.innerHeight;
  230. //if (typeof pageHeight != 'number') {
  231. //if (document.compatMode == 'CSS1Compat') {
  232. //pageHeight = wd.topWindow.document.documentElement.clientHeight;
  233. //} else {
  234. //pageHeight = wd.topWindow.document.body.clientHeight;
  235. //}
  236. //}
  237. //var win = wd.topWindow.document.getElementsByName('win2')[0];
  238. //win.height = (pageHeight - getTop(win)) + 'px';
  239. //var num = '';
  240. //win.src = '/main/sheji/yeMianSheJi.do?ymid=44019441&high=' + (pageHeight - getTop(win));})()
  241. //
  242. //
  243. var win = wd.topWindow.document.getElementsByName(iframeName)[0];
  244. //记住iframe,点击应用菜单时,重新计算高度时计算可用高度用到
  245. wd.topWindow.wd.base.applyIframeElement = win;
  246. var oriSrc = win.getAttribute("oriSrc");
  247. var availbleHeight = wd.base.refreshApplyIframeHeight(win);
  248. // win.height=availbleHeight;
  249. win.src = oriSrc + "&high=" + availbleHeight;
  250. }
  251. wd.base.setRowCountPerPage = function (url, availHeight, availWidth, numOnly) {
  252. var defaultWidth = availWidth || 755;
  253. var allype = {
  254. longCardList: 0,
  255. list: 0,
  256. iconList: 120,
  257. cardList: 245
  258. }
  259. var result = url + "";
  260. var urlparam = {}
  261. var s = url.replace(/.+\?/, "").split("&");
  262. for (var i = 0; i < s.length; i++) {
  263. var aa = s[i].split("=");
  264. if (aa.length == 2)
  265. urlparam[aa[0]] = aa[1];
  266. }
  267. var defaultType = urlparam["rowType"] || "list";
  268. var eachWidth = allype[defaultType] || 0;
  269. var val;
  270. if (urlparam["rowHigh"]) {
  271. // 1、查询是否有&rowCountPerPage字符串
  272. // 1-1、如果有,则删除该属性
  273. // 1-2、如果没有,跳过
  274. // 2、添加&rowCountPerPage属性
  275. var rowHighValue = parseInt(urlparam["rowHigh"]);
  276. var removeHighValue = urlparam["removeHigh"] ? parseInt(urlparam["removeHigh"]) : 0;
  277. var multiple = 1;
  278. if (eachWidth != 0) {
  279. multiple = parseInt(defaultWidth / eachWidth);
  280. }
  281. val =(parseFloat(availHeight) - parseFloat(removeHighValue)) / parseFloat(rowHighValue);
  282. /*
  283. * 运行时行数为整数,如果最终高度超出availHeight就减一行
  284. */
  285. var valInt=parseInt(val);
  286. val=val> valInt?(valInt-1):val;
  287. val=parseInt(multiple *val);
  288. // result = result.replace(/&rowHigh=[0-9]+/, "").replace(/&removeHigh=[0-9]+/, "").replace(/&rowCountPerPage=[0-9]+/, "");
  289. result = result.replace(/&(rowHigh|rowCountPerPage|removeHigh)=[0-9]+/g, "");
  290. result += "&rowCountPerPage=" +val;
  291. }else{
  292. }
  293. //只需要返回数字情况
  294. if (numOnly)
  295. return val;
  296. return result;
  297. }
  298. /**
  299. *设置首页菜单宽度
  300. */
  301. wd.base.setHomeWidth=function(){
  302. var usewidth=Math.max($(wd.topWindow).outerWidth(true),1025);
  303. var maxwidth=usewidth;
  304. //管理2用
  305. wd.topWindow.win2width=maxwidth;
  306. //iconList
  307. wd.topWindow.$("#iconGroup >div").css({width:maxwidth});
  308. //menu
  309. wd.topWindow.$("#menuGroup").css({width:maxwidth});
  310. if(typeof wd.topWindow.initMenuTotally=="function"){
  311. wd.topWindow.initMenuTotally();
  312. }
  313. }