global.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*全局自适应高度*/
  2. function autoFlashHeight(){
  3. let headerHeight = $(".header").height();
  4. let toolsbarHeight = getToolsbarHeight();
  5. let ftoolsbarHeight = $(".toolsbar-f").height();
  6. let btntoolsbarHeight = $(".btn-toolbar").height();
  7. // var feeRateToolsbarHeight = $(".toolsbar_feeRate").height();
  8. let toolsBarHeightQ = $(".tools-bar-height-q").height();
  9. let toolsBarHeightD = $(".tools-bar-height-d").height();
  10. let toolsBarHeightZ = $(".tools-bar-height-z").height();
  11. //$(".main-data-side-q").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightQ-302);
  12. $(".main-data-side-q").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightQ-$('#qd').find('.bottom-content').find('.p-0').height()-5);
  13. //$(".main-data-side-d").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightD-302);
  14. $(".main-data-side-d").height($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightD-$('#stdSectionRations').height()-5);
  15. $(".main-data-side-zb").height(($(window).height()-headerHeight-toolsbarHeight-toolsBarHeightZ));
  16. /*$(".main-data-side-zi").height($(window).height()-headerHeight-toolsbarHeight- toolsBarHeightZ - $(".main-data-side-zb").height());*/
  17. $('.main-content').width($(window).width()-$('.main-nav').width()-$('.main-side').width()-5);
  18. $('#glj_tree_div .modal-content').width($(window).width() < 1020 + 20 ? $(window).width() - 20 : 1020);
  19. //$("#main .main-data-top").height($(window).height()-headerHeight-toolsbarHeight-bottomContentHeight-1);
  20. typeof(loadMainSize)== 'function' ?loadMainSize():'';//zhang 2018-06-04 统一加载高度方法
  21. typeof(loadProjectGljSize)== 'function'?loadProjectGljSize():'';
  22. typeof(onResize)== 'function'?onResize():'';
  23. $(".main-data-full").height($(window).height()-headerHeight-toolsbarHeight-1);
  24. $(".main-data-full-fl").height($(window).height()-headerHeight-toolsbarHeight-37);
  25. $(".main-data-full-feeRate").height($(window).height()-headerHeight-78);
  26. $(".main-data-full-tender").height($(window).height()-headerHeight-btntoolsbarHeight-10-30);
  27. $(".main-data-full-equipment").height($(window).height()-headerHeight-30);
  28. $(".main-data-not").height($(window).height()-headerHeight-1);
  29. $(".main-data-side-search").height($(window).height()-headerHeight-toolsbarHeight-64);
  30. $(".side-content").height($(window).height()-headerHeight );
  31. $(".poj-list").height($(window).height()-headerHeight-toolsbarHeight);
  32. $(".gc-list").height($(window).height()-headerHeight-toolsbarHeight);
  33. $(".share-list").height($(window).height()-headerHeight-toolsbarHeight);
  34. $(".form-view").height($(window).height()-headerHeight-ftoolsbarHeight);
  35. $(".form-list").height($(window).height()-headerHeight);
  36. $('#comments').find('textarea').height($('#comments').height() - 25);
  37. typeof(adaptiveTzjnrWidth)== 'function' ?adaptiveTzjnrWidth():'';
  38. $('#project-glj-main').width($(window).width()-($('.main-nav').width()+ 2)-($('.filterType').width()+12)-5); //2、12是padding宽度,width 是不算padding宽度的
  39. $('#config_material').width($(window).width()-($('.main-nav').width()+ 2)-($('.filterType').width()+12)-5); //2、12是padding宽度,width 是不算padding宽度的
  40. $('#material_adjust').width($(window).width()-($('.main-nav').width()+ 2)-($('.filterType').width()+12)-5);//材料调差
  41. $('#index_content').width($(window).width()-($('.main-nav').width()+ 2)-($('#index_nav').width()+12)-5);//材料调差
  42. //typeof zmhs_obj === 'object' ? zmhs_obj.loadSideResize() : '';
  43. };
  44. function getToolsbarHeight() {//动态获取toolsbar高度,由于页面有多个toolsbar高度,直接取取不到当前页的toolsbar
  45. for(let t of $(".toolsbar")) {
  46. let height = $(t).height();
  47. if(height != -1) return height;
  48. }
  49. return 0;
  50. }
  51. /*全局自适应高度结束*/
  52. $(function () {
  53. //拖动头部
  54. $('body').on("show.bs.modal", ".modal", function(){
  55. if (typeof $(this).find('.modal-content').draggable === 'function') {
  56. $(this).find('.modal-content').draggable({handle: '.modal-header', cancel: 'a, button'});
  57. }
  58. });
  59. $(window).resize(autoFlashHeight);
  60. /*侧滑*/
  61. /* $(".open-sidebar").click(function () {
  62. $(".slide-sidebar").animate({width: "800"}).addClass("open");
  63. });
  64. $("body").click(function (event) {
  65. var e = event || window.event; //浏览器兼容性
  66. if (!$(event.target).is('a')) {
  67. var elem = event.target || e.srcElement;
  68. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  69. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  70. return false;
  71. }
  72. elem = elem.parentNode;
  73. }
  74. $(".slide-sidebar").animate({width: "0"}).removeClass("open")// 关闭处理
  75. }
  76. });*/
  77. /*侧滑*/
  78. /*显示QQ交流群*/
  79. $("#showqqgroup").hover(function(){
  80. $("#qqgroup").toggle();
  81. });
  82. /*工具提示*/
  83. $(function () {
  84. $('[data-toggle="tooltip"]').tooltip();
  85. if( $('[data-submenu]').submenupicker) $('[data-submenu]').submenupicker();
  86. $('[data-toggle="tooltip"]').click(function () {
  87. $(this).tooltip('hide');
  88. })
  89. });
  90. });
  91. /**
  92. * 设置本地缓存
  93. *
  94. * @param {String} key
  95. * @param {String|Number} value
  96. * @return {void}
  97. */
  98. let storageErrCount = 0;
  99. function setLocalCache(key, value) {
  100. const storage = window.localStorage;
  101. if (!storage || key === '' || value === '') {
  102. return;
  103. }
  104. try {
  105. storage.setItem(key, value);
  106. storageErrCount = 0;
  107. } catch (err) {
  108. storageErrCount++;
  109. if (storageErrCount > 1) {
  110. alert(`字段“${key}”数据过大,存入本地缓存失败。`)
  111. storageErrCount = 0;
  112. return;
  113. }
  114. storage.clear();
  115. setLocalCache(key, value);
  116. }
  117. }
  118. /**
  119. * 获取本地缓存
  120. *
  121. * @param {String} key
  122. * @return {String}
  123. */
  124. function getLocalCache(key) {
  125. const storage = window.localStorage;
  126. if (!storage || key === '') {
  127. return null;
  128. }
  129. return storage.getItem(key);
  130. }
  131. function removeLocalCache(key) {
  132. const storage = window.localStorage;
  133. if (!storage || key === '') {
  134. return null;
  135. }
  136. return storage.removeItem(key);
  137. }
  138. function getFormatter(decimal) {
  139. var pre = "0.";
  140. if (decimal <= 0) {
  141. return "0";
  142. }
  143. for (let i = 0; i < decimal; i++) {
  144. pre += "0"
  145. }
  146. return pre;
  147. }
  148. function getFeeIndex(fees) {
  149. let feesIndex = {};
  150. if (fees) {
  151. for(let fee of fees){
  152. const parsedUnitFee = parseFloat(fee.unitFee);
  153. const parsedTotalFee = parseFloat(fee.totalFee);
  154. const parsedTenderUnitFee = parseFloat(fee.tenderUnitFee);
  155. const parsedTenderTotalFee = parseFloat(fee.tenderTotalFee);
  156. fee.unitFee = parsedUnitFee || 0;
  157. fee.totalFee = parsedTotalFee || 0;
  158. fee.tenderUnitFee = parsedTenderUnitFee || 0;
  159. fee.tenderTotalFee = parsedTenderTotalFee || 0;
  160. feesIndex[fee.fieldName] = fee;
  161. }
  162. }
  163. return feesIndex;
  164. }
  165. function replaceAll(FindText, RepText,str) {
  166. let regExp = new RegExp(FindText, "g");
  167. return str.replace(regExp, RepText);
  168. };
  169. //求余处理成百分号,即乘以0.01
  170. function handlePercent(text){
  171. let arr = text.match(/[\d^%]+%/g);
  172. if(arr){
  173. for(let str of arr){
  174. let tem = str.replace("%"," * 0.01");
  175. text = text.replace(str,`${(tem)}`)
  176. }
  177. }
  178. return text
  179. }
  180. function setTimeoutSync(handle, time) {
  181. return new Promise(function(resolve, reject) {
  182. setTimeout(function () {
  183. if (handle && typeof handle === 'function') {
  184. handle();
  185. }
  186. resolve();
  187. }, time);
  188. });
  189. }