managerjstool-bootstrap.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. //需要引入bootstrap.min.js 和 sweetalert.min.js
  2. /**
  3. * 涉及到文件上传的ajax提交
  4. * @param formId
  5. * @param fun_success
  6. * @param fun_error
  7. */
  8. function ajaxFormUploadForBootStrap(formId,transCode,fun_success, fun_error) {
  9. url = sysWebAppName + 'TransServlet?transCode=' +transCode + '&clientToken='
  10. + $.__token + '&channelNo=service';
  11. var form = new FormData(document.getElementById(formId));
  12. $.ajax({
  13. type : "post",
  14. data : form,
  15. processData : false,
  16. contentType : false,
  17. /*
  18. * $("#" + formId).form( 'submit', {
  19. */
  20. url : encodeURI(url),
  21. timeout : ajaxTimeout,
  22. async : false,
  23. traditional : false,
  24. cache : false,
  25. ajaxSubmit : function() {
  26. return true;
  27. },
  28. success : function(result) {
  29. var data = (new Function("return " + result))();
  30. if (data.returnCode == 'EB8000006') {
  31. swal({
  32. title: "用户异常提示",
  33. text: "用户异常,是否重新登录!",
  34. type: "warning",
  35. showCancelButton: true,
  36. confirmButtonColor: "#DD6B55",
  37. confirmButtonText: "重新登录!",
  38. cancelButtonText: "取消!",
  39. closeOnConfirm: false
  40. },
  41. function(){
  42. $(".leftcurtain", window.parent.document).stop()
  43. .animate({
  44. width : '50%'
  45. }, 1500);
  46. $(".rightcurtain", window.parent.document).stop()
  47. .animate({
  48. width : '51%'
  49. }, 1500);
  50. $(".login", window.parent.document).show("slow").find(
  51. "input[type=password]").val("");
  52. parent.changeImage();
  53. });
  54. } else {
  55. if (data.returnCode == successCode) {
  56. fun_success && fun_success(data);
  57. } else {
  58. if (fun_error) {
  59. fun_error && fun_error(data);
  60. }
  61. }
  62. }
  63. },
  64. onLoadError : function() {
  65. //$.messager.alert('系统错误', '网络或系统忙提交失败,请重试!', 'error');
  66. }
  67. });
  68. }
  69. /**
  70. * ajax 通信工具类(本地)--针对bootstrap的页面
  71. *
  72. * @param transCode
  73. * 交易码
  74. * @param servletName
  75. * servlet名称
  76. * @param proNames
  77. * proName字段
  78. * @param params
  79. * 参数
  80. * @param fun_success
  81. * @param fun_error
  82. * @param isLoginOut
  83. */
  84. function syncAjaxCalllForBootstrap(transCode, servletName, params,
  85. fun_success, fun_error, isLoginOut) {
  86. if (params == null) {
  87. params = {};
  88. }
  89. __mask++;
  90. if (__mask >= 0) {
  91. showLoading(1);
  92. }
  93. url = sysWebAppName + servletName + '?transCode=' + transCode
  94. + '&clientToken=' + $.__token + '&channelNo=service';;
  95. $
  96. .ajax({
  97. url : encodeURI(url),
  98. data : params || "",
  99. type : "POST",
  100. contentType : "application/x-www-form-urlencoded; charset=utf-8",
  101. dataType : "text",
  102. timeout : ajaxTimeout,
  103. success : function(data) {
  104. data = $.parseJSON(data);
  105. __mask--;
  106. if (data == null)
  107. return;
  108. if (__mask == 0) {
  109. showLoading(-1);
  110. }
  111. if (data.returnCode == 'EB8000006') {
  112. if (isLoginOut) {
  113. fun_success && fun_success(data);
  114. } else {
  115. if (__login > 0)
  116. return;
  117. swal({
  118. title: "用户异常提示",
  119. text: "用户异常,是否重新登录!",
  120. type: "warning",
  121. showCancelButton: true,
  122. confirmButtonColor: "#DD6B55",
  123. confirmButtonText: "重新登录!",
  124. cancelButtonText: "取消!",
  125. closeOnConfirm: false
  126. },
  127. function(data){
  128. if(data){
  129. $(".leftcurtain", window.parent.document)
  130. .stop().animate({
  131. width : '50%'
  132. }, 1500);
  133. $(".rightcurtain", window.parent.document)
  134. .stop().animate({
  135. width : '51%'
  136. }, 1500);
  137. $(".login", window.parent.document).show();
  138. $(".login", window.parent.document).find(
  139. "input[type=password]").val("");
  140. $(".login", window.parent.document).find(
  141. "input[type=text]").val("");
  142. parent.changeImage();
  143. __login--;
  144. }else{
  145. __login--;
  146. }
  147. });
  148. __login++;
  149. }
  150. } else {
  151. if (data.returnCode == undefined
  152. || data.returnCode == successCode
  153. || data.success) {
  154. fun_success && fun_success(data);
  155. } else {
  156. if (fun_error) {
  157. fun_error && fun_error(data);
  158. }
  159. }
  160. }
  161. },
  162. error : function(XMLHttpRequest, textStatus, errorThrown) {
  163. __mask--;
  164. if (__mask == 0) {
  165. showLoading(-1);
  166. }
  167. if (fun_error) {
  168. fun_error
  169. && fun_error(XMLHttpRequest, textStatus,
  170. errorThrown);
  171. }
  172. }
  173. });
  174. }
  175. /**
  176. * ajax 通信工具类(本地)--针对bootstrap的页面(调用Manager)
  177. *
  178. * @param transCode
  179. * 交易码
  180. * @param servletName
  181. * servlet名称
  182. * @param proNames
  183. * proName字段
  184. * @param params
  185. * 参数
  186. * @param fun_success
  187. * @param fun_error
  188. * @param isLoginOut
  189. */
  190. function syncAjaxCallManagerForBootstrap(transCode,params,
  191. fun_success, fun_error, isLoginOut) {
  192. if (params == null) {
  193. params = {};
  194. }
  195. __mask++;
  196. if (__mask >= 0) {
  197. showLoading(1);
  198. }
  199. url = sysWebAppName + 'TransServlet?transCode=' + transCode
  200. + '&clientToken=' + $.__token;
  201. $
  202. .ajax({
  203. url : encodeURI(url),
  204. data : params || '',
  205. type : "POST",
  206. contentType : "application/x-www-form-urlencoded; charset=utf-8",
  207. dataType : "text",
  208. timeout : ajaxTimeout,
  209. success : function(data) {
  210. data = $.parseJSON(data);
  211. __mask--;
  212. if (data == null)
  213. return;
  214. if (__mask == 0) {
  215. showLoading(-1);
  216. }
  217. if (data.returnCode == 'EB8000006') {
  218. if (isLoginOut) {
  219. fun_success && fun_success(data);
  220. } else {
  221. if (__login > 0)
  222. return;
  223. swal({
  224. title: "用户异常提示",
  225. text: "用户异常,是否重新登录!",
  226. type: "warning",
  227. showCancelButton: true,
  228. confirmButtonColor: "#DD6B55",
  229. confirmButtonText: "重新登录!",
  230. cancelButtonText: "取消!",
  231. closeOnConfirm: false
  232. },
  233. function(data){
  234. if(data){
  235. $(".leftcurtain", window.parent.document)
  236. .stop().animate({
  237. width : '50%'
  238. }, 1500);
  239. $(".rightcurtain", window.parent.document)
  240. .stop().animate({
  241. width : '51%'
  242. }, 1500);
  243. $(".login", window.parent.document).show();
  244. $(".login", window.parent.document).find(
  245. "input[type=password]").val("");
  246. $(".login", window.parent.document).find(
  247. "input[type=text]").val("");
  248. parent.changeImage();
  249. __login--;
  250. }else{
  251. __login--;
  252. }
  253. });
  254. __login++;
  255. }
  256. } else {
  257. if (data.returnCode == undefined
  258. || data.returnCode == successCode
  259. || data.success) {
  260. fun_success && fun_success(data);
  261. } else {
  262. if (fun_error) {
  263. fun_error && fun_error(data);
  264. }
  265. }
  266. }
  267. },
  268. error : function(XMLHttpRequest, textStatus, errorThrown) {
  269. __mask--;
  270. if (__mask == 0) {
  271. showLoading(-1);
  272. }
  273. if (fun_error) {
  274. fun_error
  275. && fun_error(XMLHttpRequest, textStatus,
  276. errorThrown);
  277. }
  278. }
  279. });
  280. }
  281. //分页相关:
  282. /**
  283. * 对想要跳转的页面进行判断
  284. * @param index
  285. */
  286. function goPage(index){
  287. var toPage;
  288. var currentPage =parseInt($("#page1").val());
  289. var pageRows =parseInt($("#rows1").html());
  290. var total = parseInt($("#total1").html());
  291. var totalPage;
  292. if(total % pageRows == 0){
  293. totalPage = total/pageRows;
  294. }else{
  295. totalPage = parseInt(total/pageRows) + 1;
  296. }
  297. if(index == 'front'){
  298. toPage = 1;
  299. }else if(index == 'sub'){
  300. toPage = currentPage - 1;
  301. if(toPage <= 0){
  302. toPage = 1;
  303. }
  304. }else if(index == 'add'){
  305. toPage = currentPage + 1;
  306. if(toPage >= totalPage){
  307. toPage = totalPage;
  308. }
  309. }else if(index == 'last'){
  310. toPage = totalPage;
  311. }else if(index == 'changerows'){
  312. if(currentPage > totalPage){
  313. toPage = totalPage;
  314. }else{
  315. toPage = currentPage;
  316. }
  317. }else{
  318. if(index < 0){
  319. index = 1;
  320. }else if(index > totalPage){
  321. index = totalPage;
  322. }
  323. toPage = index;
  324. }
  325. $("#page1").val(toPage);
  326. doSearch(true);
  327. }
  328. /**
  329. * 改变分页的参数, 总数,总页数,开始,结束
  330. */
  331. function showPageIndex(total){
  332. var page = parseInt($("#page1").val());
  333. var pageRows =parseInt($("#rows1").html());
  334. var totalPage,startIndex,endIndex;
  335. if(total == 0){
  336. totalPage = 0;
  337. startIndex = 0;
  338. endIndex = 0;
  339. $("#page1").val(0);
  340. }else{
  341. if(total % pageRows == 0){
  342. totalPage = total/pageRows;
  343. }else{
  344. totalPage = parseInt(total/pageRows) + 1;
  345. }
  346. startIndex = (page - 1)*pageRows + 1;
  347. endIndex = page*pageRows;
  348. if(endIndex > total){
  349. endIndex = total;
  350. }
  351. }
  352. $("#total1").html(total);
  353. $("#totalPage1").html(totalPage);
  354. $("#startIndex1").html(startIndex);
  355. $("#endIndex1").html(endIndex);
  356. }
  357. function changeGMKB(numb,n){
  358. if(isNaN(numb)) {
  359. return numb;
  360. }
  361. n = n > 0 && n <= 20 ? n : 2;
  362. if(numb>-1 && numb<1024){
  363. return numb.toFixed(n)+'B';
  364. }else if(numb>1023 && numb<1048576){
  365. return (numb/1024).toFixed(n)+'Kb';
  366. }else if(numb>1048575 && numb<1073741824){
  367. return (numb/1048576).toFixed(n)+'M';
  368. }else if(numb>1073741823){
  369. return (numb/1073741824).toFixed(n)+'G';
  370. } else {
  371. numb = 0;
  372. return numb.toFixed(n)+'B';
  373. }
  374. }
  375. /**
  376. * 更改每页显示的条数
  377. */
  378. function changeRows(index){
  379. $("#rows1").html(index);
  380. goPage('changerows');
  381. }
  382. /**
  383. * 判断钱是否空
  384. * @param id
  385. */
  386. function ifMoneyNull(id){
  387. var tempVal = $("#"+id).val();
  388. var temp= tempVal.substr(0,tempVal.indexOf(".")+3);
  389. var tempNum= parseFloat(temp);
  390. if(temp == "" || temp == undefined || tempNum == 0){
  391. //$('#collapseOne').collapse('hide');
  392. //如果验证不通过,展开
  393. if(! $("#"+id).parents(".panel-collapse").hasClass("in")){
  394. $("#"+id).parents(".panel-collapse").collapse('show');
  395. $("#"+id).focus();
  396. return false;
  397. }
  398. var options={
  399. trigger:'manual',
  400. };
  401. $("#"+id).popover(options);
  402. $("#"+id).popover('show');
  403. $("#"+id).focus();
  404. return false;
  405. }else{
  406. return true;
  407. }
  408. }
  409. /**
  410. * 判断内容是否为空,来显示提示框
  411. * 对应的input必须有popover属性
  412. * @param id
  413. * @returns {Boolean}
  414. */
  415. function ifNull(id){
  416. var temp = $("#"+id).val();
  417. if(temp.replace(/(^\s*)|(\s*$)/g, "") == ""){
  418. //$('#collapseOne').collapse('hide');
  419. //如果验证不通过,展开
  420. if(! $("#"+id).parents(".panel-collapse").hasClass("in")){
  421. $("#"+id).parents(".panel-collapse").collapse('show');
  422. $("#"+id).focus();
  423. return false;
  424. }
  425. var options={
  426. trigger:'manual',
  427. };
  428. $("#"+id).popover(options);
  429. $("#"+id).popover('show');
  430. $("#"+id).focus();
  431. return false;
  432. }else{
  433. return true;
  434. }
  435. }
  436. /**
  437. * 判断用户是否输入,隐藏提示框
  438. * @param index
  439. */
  440. function ifNullInput(index){
  441. var temp = $(index).val();
  442. if(null != temp && undefined != temp){
  443. $(index).popover('hide');
  444. }
  445. };
  446. /**
  447. * 判断用户是否点击文件选择,隐藏提示框
  448. * @param index
  449. */
  450. function fileInpufHide(index){
  451. $(index).popover('hide');
  452. };
  453. /**
  454. * 日期格式化
  455. *
  456. * @param date
  457. * @returns {String}
  458. */
  459. function formatterDate2ss(date) {
  460. var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
  461. var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
  462. + (date.getMonth() + 1);
  463. var hh = date.getHours() > 9 ? date.getHours() : "0" + date.getHours();
  464. var mm = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes();
  465. var ss = date.getSeconds() > 9 ? date.getSeconds() : "0" + date.getSeconds();
  466. return date.getFullYear() + '-' + month + '-' + day + " " + hh+':'+mm+":"+ss;
  467. };