123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- function callResourceAdapter(type, url, requestContent, successCallback, failCallback) {
- if (requestContent == null){
- requestContent = {};
- }
- if (type == null){
- type = 'POST';
- }
- function invocationSuccess(result) {
- var resultJson = result;
- if(resultJson.msgCode == '800'){
- if (successCallback && typeof(successCallback) == "function") {
- successCallback(resultJson.rows,resultJson.map,resultJson.vo,resultJson.msg);
- }
- }
- if(resultJson.msgCode == '801'){
- showToast(resultJson.msg);
- }
- if(resultJson.msgCode == '900'){
- var message = '系统错误,请联系管理员';
- if(resultJson.msg){
- message = resultJson.msg;
- }
- showToast(message);
- if (failCallback && typeof(failCallback) == "function") {
- failCallback();
- }
- }
- }
- function invocationFailure(error) {
- showToast('无法连接至服务器,请稍后再试');
- if (failCallback && typeof(failCallback) == "function") {
- failCallback();
- }
- }
- $.ajax({
- type: type,
- url: serverUrl+url,
- data: JSON.stringify(requestContent),
- crossDomain:true,
- contentType: "application/json; charset=utf-8",
-
- timeout:120000,
- statusCode:{
- 404: function() {
- showToast('服务器无响应,请稍后再试')
- },
- 422: function() {
- showToast('应用程序请求对象错误,请稍后再试')
- },
- 403: function() {
- showToast('无访问权限')
- },
- 400: function() {
- showToast('应用程序请求无效,请稍后再试')
- },
- },
- success: function (data, textStatus, jqXHR) {
- switch (jqXHR.status) {
- case 200:
- invocationSuccess(data);
- break;
- default:
- break;
- }
- },
- error: function (jqXHR, textStatus,errorThrown) {
- invocationFailure(jqXHR);
- }
- })
- }
- function showToast(text,timeout) {
- $(".yui-toast-mask").remove();
- var html = [
- '<div class="yui-toast-mask">',
- '<div class="yui-toast">',
- '<div class="yui-toast-text">'+text+'</div>',
- '</div>',
- '</div>',
- ];
- var dom = $(html.join(''));
- $("body").append(dom);
- if(timeout&&typeof(timeout)=='number'){
- setTimeout(function () {
- dom.remove();
- },timeout);
- }
- $(".yui-toast-mask").click(function () {
- dom.remove();
- });
- }
- function hideToast() {
- $(".yui-toast-mask").remove();
- }
- function loaderShow() {
- var loadPage = $('<div class="loading" style="top:30%;left:50%;position: absolute;background: transparent;text-align: center;">' +
- '<img src="../images/loading.gif" />' +
- '</div>');
- $("#content").append(loadPage);
- }
- function loaderHide() {
- $(".loading").remove();
- }
- function getLocationDom() {
- var that = this;
- var html = "<div id='breadcrumb'>";
- $.each(LOCATION,function(index,data){
- if(index==0){
- html += '<a href="javascript:void(0)" class="tip-bottom"><i class="fa fa-home"></i>'+data+'</a>';
- return ;
- }
- if(index==LOCATION.length-1){
- html += '<a class="current">'+data+'</a>';
- return ;
- }
- html += "<a href='javascript:void(0)'>"+data+"</a>";
- });
- html += "</div>";
- $("#content-header").html(html);
- }
- function getNav(successCallback) {
- var postNav = [];
- postNav.push('<li class="submenu" data-for= "home">','<a href="javascript:void(0)"><span>首页</span></a>');
- postNav.push('<li class="submenu" data-for= "analysis">','<a href="javascript:void(0)"><span>指标统计</span></a>');
- postNav.push('<li class="submenu" data-for= "trend">','<a href="javascript:void(0)"><span>趋势排名</span></a>');
- $("#sidebar ul").html(postNav.join(''));
- if (successCallback&&typeof(successCallback) == 'function'){
- successCallback();
- }
- }
- function bindNav(navId) {
- var HEIGHT = $("body").height()-100;
- $("#content").height(HEIGHT);
- $(".container-fluid").slimScroll({
- height: HEIGHT+'px',
- size: '5px',
- railColor: '#000000',
- railOpacity: 0.3,
- wheelStep: 10,
- disableFadeOut: false
- });
- $("#"+navId).delegate("li[data-for='home']","click",function(){
- window.location.href="home.html"
- }).delegate("li[data-for='analysis']","click",function(){
- window.location.href="analysis.html"
- }).delegate("li[data-for='trend']","click",function(){
- window.location.href="trend.html"
- })
- }
- function last_year_month() {
- var list = [];
- var date = getFormatDate(new Date());
- var year = date.split("-")[0];
- var mouth = date.split("-")[1];
- for (var i=0;i<12;i++){
- var objM = mouth-i;
- var objY = year;
- if(objM<=0){
- objM = objM+12;
- objY = year -1;
- }
- if(objM<10){
- objM = "0"+objM;
- }
- var obj = objY +"-"+objM;
- list.push(obj)
- }
- return list;
- }
- function getFormatDate(date){
- var year = date.getFullYear();
- var month = date.getMonth()+1;
- var day = date.getDate();
- if(month<10){
- month = '0'+month.toString();
- }
- month = month.toString();
- if(day<10){
- day = '0'+day.toString();
- }
- day = day.toString();
- return year+'-'+month+'-'+day;
- }
- function last_month_day() {
- var list = [];
- var date = getFormatDate(new Date());
- var year = date.split("-")[0];
- var mouth = date.split("-")[1];
- var day = date.split("-")[2]-1;
- for (var i=0;i<30;i++){
- var objM = mouth;
- var objD = day-i;
- if(objD<=0){
- objD = objD+30;
- objM = mouth -1;
- objM = "0"+objM
- }
- var obj = year+"-"+objM +"-"+objD;
- list.push(obj)
- }
- return list;
- }
- function getFormatMonth(date){
- var year = date.getFullYear();
- var month = date.getMonth()+1;
- var day = date.getDate();
- if(month<10){
- month = '0'+month.toString();
- }
- month = month.toString();
- if(day<10){
- day = '0'+day.toString();
- }
- day = day.toString();
- return year+'-'+month;
- }
- function paging(totalPage,currentPage) {
- $("#pagination").pagination({
- currentPage: currentPage,
- totalPage: totalPage,
- isShow: true,
- count: 8,
- homePageText: "首页",
- endPageText: "尾页",
- prevPageText: "上一页",
- nextPageText: "下一页",
- callback: function(current) {
- $("#current").text(current)
- }
- });
- }
|