common.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. function callResourceAdapter(type, url, requestContent, successCallback, failCallback) {
  2. if (requestContent == null){
  3. requestContent = {};
  4. }
  5. if (type == null){
  6. type = 'POST';
  7. }
  8. function invocationSuccess(result) {
  9. var resultJson = result;
  10. if(resultJson.msgCode == '800'){
  11. if (successCallback && typeof(successCallback) == "function") {
  12. successCallback(resultJson.rows,resultJson.map,resultJson.vo,resultJson.msg);
  13. }
  14. }
  15. if(resultJson.msgCode == '801'){
  16. showToast(resultJson.msg);
  17. }
  18. if(resultJson.msgCode == '900'){
  19. var message = '系统错误,请联系管理员';
  20. if(resultJson.msg){
  21. message = resultJson.msg;
  22. }
  23. showToast(message);
  24. if (failCallback && typeof(failCallback) == "function") {
  25. failCallback();
  26. }
  27. }
  28. }
  29. function invocationFailure(error) {
  30. showToast('无法连接至服务器,请稍后再试');
  31. if (failCallback && typeof(failCallback) == "function") {
  32. failCallback();
  33. }
  34. }
  35. $.ajax({
  36. type: type,
  37. url: serverUrl+url,
  38. data: JSON.stringify(requestContent),
  39. crossDomain:true,
  40. contentType: "application/json; charset=utf-8",
  41. // dataType: "json",
  42. timeout:120000,
  43. statusCode:{
  44. 404: function() {
  45. showToast('服务器无响应,请稍后再试')
  46. },
  47. 422: function() {
  48. showToast('应用程序请求对象错误,请稍后再试')
  49. },
  50. 403: function() {
  51. showToast('无访问权限')
  52. },
  53. 400: function() {
  54. showToast('应用程序请求无效,请稍后再试')
  55. },
  56. },
  57. success: function (data, textStatus, jqXHR) {
  58. switch (jqXHR.status) {
  59. case 200:
  60. invocationSuccess(data);
  61. break;
  62. default:
  63. break;
  64. }
  65. },
  66. error: function (jqXHR, textStatus,errorThrown) {
  67. invocationFailure(jqXHR);
  68. }
  69. })
  70. }
  71. function showToast(text,timeout) {
  72. $(".yui-toast-mask").remove();
  73. var html = [
  74. '<div class="yui-toast-mask">',
  75. '<div class="yui-toast">',
  76. '<div class="yui-toast-text">'+text+'</div>',
  77. '</div>',
  78. '</div>',
  79. ];
  80. var dom = $(html.join(''));
  81. $("body").append(dom);
  82. if(timeout&&typeof(timeout)=='number'){
  83. setTimeout(function () {
  84. dom.remove();
  85. },timeout);
  86. }
  87. $(".yui-toast-mask").click(function () {
  88. dom.remove();
  89. });
  90. }
  91. function hideToast() {
  92. $(".yui-toast-mask").remove();
  93. }
  94. function loaderShow() {
  95. var loadPage = $('<div class="loading" style="top:30%;left:50%;position: absolute;background: transparent;text-align: center;">' +
  96. '<img src="../images/loading.gif" />' +
  97. '</div>');
  98. $("#content").append(loadPage);
  99. }
  100. function loaderHide() {
  101. $(".loading").remove();
  102. }
  103. function getLocationDom() {
  104. var that = this;
  105. var html = "<div id='breadcrumb'>";
  106. $.each(LOCATION,function(index,data){
  107. if(index==0){
  108. html += '<a href="javascript:void(0)" class="tip-bottom"><i class="fa fa-home"></i>'+data+'</a>';
  109. return ;
  110. }
  111. if(index==LOCATION.length-1){
  112. html += '<a class="current">'+data+'</a>';
  113. return ;
  114. }
  115. html += "<a href='javascript:void(0)'>"+data+"</a>";
  116. });
  117. html += "</div>";
  118. $("#content-header").html(html);
  119. }
  120. function getNav(successCallback) {
  121. var postNav = [];
  122. postNav.push('<li class="submenu" data-for= "home">','<a href="javascript:void(0)"><span>首页</span></a>');
  123. postNav.push('<li class="submenu" data-for= "analysis">','<a href="javascript:void(0)"><span>指标统计</span></a>');
  124. postNav.push('<li class="submenu" data-for= "trend">','<a href="javascript:void(0)"><span>趋势排名</span></a>');
  125. $("#sidebar ul").html(postNav.join(''));
  126. if (successCallback&&typeof(successCallback) == 'function'){
  127. successCallback();
  128. }
  129. }
  130. function bindNav(navId) {
  131. var HEIGHT = $("body").height()-100;
  132. $("#content").height(HEIGHT);
  133. $(".container-fluid").slimScroll({
  134. height: HEIGHT+'px', //容器高度,默认250px
  135. size: '5px', //滚动条宽度,默认7px
  136. railColor: '#000000', //滚动条背景轨迹颜色,默认#333333
  137. railOpacity: 0.3, //滚动条背景轨迹透明度,默认0.2
  138. wheelStep: 10, //滚动条滚动值,默认20
  139. disableFadeOut: false //是否禁用鼠标在内容处一定时间不动隐藏滚动条,当设置alwaysVisible为true时该参数无效,默认false
  140. });
  141. $("#"+navId).delegate("li[data-for='home']","click",function(){
  142. window.location.href="home.html"
  143. }).delegate("li[data-for='analysis']","click",function(){
  144. window.location.href="analysis.html"
  145. }).delegate("li[data-for='trend']","click",function(){
  146. window.location.href="trend.html"
  147. })
  148. }
  149. function last_year_month() {
  150. var list = [];
  151. var date = getFormatDate(new Date());
  152. var year = date.split("-")[0];
  153. var mouth = date.split("-")[1];
  154. for (var i=0;i<12;i++){
  155. var objM = mouth-i;
  156. var objY = year;
  157. if(objM<=0){
  158. objM = objM+12;
  159. objY = year -1;
  160. }
  161. if(objM<10){
  162. objM = "0"+objM;
  163. }
  164. var obj = objY +"-"+objM;
  165. list.push(obj)
  166. }
  167. return list;
  168. }
  169. function getFormatDate(date){
  170. var year = date.getFullYear();
  171. var month = date.getMonth()+1;
  172. var day = date.getDate();
  173. if(month<10){
  174. month = '0'+month.toString();
  175. }
  176. month = month.toString();
  177. if(day<10){
  178. day = '0'+day.toString();
  179. }
  180. day = day.toString();
  181. return year+'-'+month+'-'+day;
  182. }
  183. function last_month_day() {
  184. var list = [];
  185. var date = getFormatDate(new Date());
  186. var year = date.split("-")[0];
  187. var mouth = date.split("-")[1];
  188. var day = date.split("-")[2]-1;
  189. for (var i=0;i<30;i++){
  190. var objM = mouth;
  191. var objD = day-i;
  192. if(objD<=0){
  193. objD = objD+30;
  194. objM = mouth -1;
  195. objM = "0"+objM
  196. }
  197. var obj = year+"-"+objM +"-"+objD;
  198. list.push(obj)
  199. }
  200. return list;
  201. }
  202. function getFormatMonth(date){
  203. var year = date.getFullYear();
  204. var month = date.getMonth()+1;
  205. var day = date.getDate();
  206. if(month<10){
  207. month = '0'+month.toString();
  208. }
  209. month = month.toString();
  210. if(day<10){
  211. day = '0'+day.toString();
  212. }
  213. day = day.toString();
  214. return year+'-'+month;
  215. }
  216. //分页
  217. function paging(totalPage,currentPage) {
  218. $("#pagination").pagination({
  219. currentPage: currentPage,
  220. totalPage: totalPage,
  221. isShow: true,
  222. count: 8,
  223. homePageText: "首页",
  224. endPageText: "尾页",
  225. prevPageText: "上一页",
  226. nextPageText: "下一页",
  227. callback: function(current) {
  228. $("#current").text(current)
  229. }
  230. });
  231. }