tempTip.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const tempTip={
  2. fadingDuration:4500,
  3. inputType:'input',
  4. index:99,
  5. setIndex:function(index){
  6. this.index=parseInt(index);
  7. },
  8. setDuration:function(milliSec){
  9. this.fadingDuration=parseInt(milliSec);
  10. },
  11. setInputType:function(type){
  12. this.inputType=type;
  13. },
  14. showSuccess:function(text){
  15. let tiper=$("<div class='row' style='color:white;opacity:0.9;position: fixed;top:40%;transform:translateY(-50%);z-index:"+this.index+";width:100%;'>" +
  16. "<div class='col-8 offset-2'><div class='card'><div class='card-body h4 bg-success text-center h-100 m-0'>" +
  17. text +
  18. "</div></div></div></div>");
  19. tiper.animate({opacity:'0'},this.fadingDuration,'swing',function () {
  20. tiper.remove();
  21. });
  22. $('body').append(tiper);
  23. },
  24. show:function(text){
  25. let tiper=$("<div class='row' style='color:white;opacity:0.9;top:40%;position: fixed;transform:translateY(-50%);width:100%;z-index:"+this.index+";'>" +
  26. "<div class='col-8 offset-2'><div class='card'><div class='card-body h2 bg-danger text-center h-100 m-0'>" +
  27. text +
  28. "</div></div></div></div>");
  29. tiper.animate({opacity:'0'},this.fadingDuration,'swing',function () {
  30. tiper.remove();
  31. });
  32. $('body').append(tiper);
  33. },
  34. okWindow:function(text,okText){
  35. let bg=$("<div style='opacity:0.4;position:fixed;top:0;width:100%;height:100%;z-index:"+this.index+";background-color:#000;'></div>" );
  36. if(typeof(okText)=='undefined')okText='确定';
  37. let tiper=$("<div class='row' style='opacity:0.9;position:fixed;top:40%;transform:translateY(-50%);width:100%;z-index:"+(this.index+1)+"'>" +
  38. "<div class='col-8 offset-2'><div class='card'><div class='card-body h2 text-center'>" +
  39. text +
  40. "<p><button class='btn btn-success btn-lg okWindow'>"+okText+"</button></p><div>" +
  41. "</div></div></div>");
  42. tiper.find('.okWindow').on('click',function () {
  43. tiper.off('click');
  44. tiper.remove();
  45. bg.remove();
  46. });
  47. $('html').css('height', '100%').append(bg);
  48. $('body').append(tiper)
  49. },
  50. waitingTip:function(text){
  51. let bg=$("<div style='opacity:0.4;position:fixed;top:0;width:100%;height:100%;z-index:"+this.index+";background-color:#fff;' class='tipperBg'></div>" );
  52. let tipper=$("<div class='row tipper' style='color:white;opacity:0.9;position:fixed;top:40%;transform:translateY(-50%);width:100%;z-index:"+(this.index+1)+";'>" +
  53. "<div class='col-8 offset-2'><div class='card-body h5 bg-dark text-center' style='border-radius: 50px'>" +
  54. text +
  55. "</div></div></div>");
  56. tipper.animate({opacity:'0'},this.fadingDuration,'swing',function () {
  57. tipper.remove();
  58. bg.remove();
  59. });
  60. $('html').css('height', '100%').append(bg);
  61. $('body').append(tipper);
  62. },
  63. cancelWaitingTip:function(){
  64. let bg=$(".tipperBg");
  65. let tipper=$(".tipper");
  66. tipper.remove();
  67. bg.remove();
  68. },
  69. confirm:function(text,yesFunc,noFunc,yesText,noText){
  70. if(typeof(yesText)==='undefined')yesText='确定';
  71. if(typeof(noText)==='undefined')noText='取消';
  72. let bg=$("<div style='opacity:0.4;position:fixed;top:0;width:100%;height:100%;z-index:"+this.index+";background-color:#000;'></div>" );
  73. let tiper=$("<div class='row' style='color:#000;opacity:0.9;position:fixed;top:40%;transform:translateY(-50%);width:100%;z-index:"+(this.index+1)+"'>" +
  74. "<div class='col-8 offset-2'><div class='card'><div class='card-body'><div class='card-title h4'>" +
  75. text +
  76. "</div><div class='card-text'><button class='btn btn-dark btn-lg ok'>"+yesText+"</button>" +
  77. "<button class='btn btn-success btn-lg cancel ml-4'>"+noText+"</button></div>" +
  78. "</div></div></div></div>");
  79. let $ok = tiper.find('.ok');
  80. let $cancel = tiper.find('.cancel');
  81. $ok.on('click',function () {
  82. $ok.off('click');
  83. $cancel.off('click');
  84. tiper.remove();
  85. bg.remove();
  86. yesFunc();
  87. });
  88. $cancel.on('click',function () {
  89. $ok.off('click');
  90. $cancel.off('click');
  91. tiper.remove();
  92. bg.remove();
  93. if(typeof noFunc!='undefined')
  94. noFunc();
  95. });
  96. $('html').css('height', '100%').append(bg);
  97. $('body').append(tiper);
  98. },
  99. inputVal:function(tipText,resultFunc){
  100. let bg=$("<div style='opacity:0.4;position:fixed;top:0;width:100%;height:100%;z-index:"+(this.index-1)+";background-color:#000;'></div>" );
  101. let tiper=$("<div class='row' style='color:#000;opacity:0.9;position:fixed;top:40%;transform:translateY(-50%);width:100%;z-index:"+this.index+"'>" +
  102. "<div class='col-8 offset-2'><div class='card'><div class='card-body'><div class='card-title h5'>" +
  103. tipText +
  104. "</div><div><input type='"+this.inputType+"' class='input form-control mb-3'/></div>" +
  105. "<div class='card-text'><button class='btn btn-outline-success ok'>确定</button></div>" +
  106. "</div></div></div></div>");
  107. let $ok = tiper.find('.ok');
  108. let $input = tiper.find('.input');
  109. $ok.on('click',function () {
  110. $ok.off('click');
  111. tiper.remove();
  112. bg.remove();
  113. resultFunc($input.val())
  114. });
  115. $('html').css('height', '100%').append(bg);
  116. $('body').append(tiper);
  117. $input.focus()
  118. },
  119. postBasicRequest(url, params, successExe, isPriority = false, isMultipart = false) {
  120. if (isPriority)this.setIndex(1099);
  121. let header = {};
  122. if (isMultipart)header = {'Content-Type': 'multipart/form-data'};
  123. window.axios.post(url,params,header).then(res=> {
  124. if (res.data.success){
  125. let successMsg = successExe(res.data.data);
  126. if (successMsg){
  127. this.setDuration(2000);
  128. this.showSuccess(successMsg);
  129. }
  130. return;
  131. }
  132. this.setDuration(3000);
  133. this.show(res.data.data);
  134. }).catch(err=> {
  135. console.log(err);
  136. this.setDuration(3000);
  137. this.show('网络异常:'+err);
  138. });
  139. },
  140. showErrorAudio:function (){
  141. let src='/sound/滴答电子.mp3';
  142. let audio= new Audio(src);
  143. setTimeout(function (){
  144. audio.play();
  145. })
  146. window.navigator.vibrate(1000);
  147. }
  148. };
  149. module.exports=tempTip;