district.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // var myChart = echarts.init(document.getElementById("echarts-map-china"));
  5. var ajax_page=function(memo){
  6. var overtime='<tr><td colspan="8" style="text-align:center;">请求超时,<a href="javascript:;" class="ajax-page" data-memo="'+memo+'">点击重试</a></td></tr>';
  7. $.ajax({
  8. url:url,
  9. type:'post',
  10. data:'memo='+memo,
  11. dataType: "json",
  12. timeout: '10000',
  13. beforeSend:function(){
  14. $(".btn-group .btn-primary").addClass("btn-default");
  15. $(".btn-group .btn-primary").removeClass("btn-primary");
  16. $("#"+memo).addClass("btn-primary");
  17. $("#"+memo).removeClass("btn-default");
  18. $('.visit-district-tbody').html('<tr><td colspan="8" style="text-align: center;"><span><i class="fa fa-spin fa-spinner" aria-hidden="true"></i>&nbsp;&nbsp;数据获取中...<span></td></tr>');
  19. },
  20. success:function(res){
  21. if(res.status){
  22. var map=res.map;
  23. // var option = {
  24. // tooltip : {
  25. // trigger: 'item'
  26. // },
  27. // visualMap: {
  28. // min:'0',
  29. // max:map[0]['value'],
  30. // left: 'left',
  31. // top: 'bottom',
  32. // orient: 'horizontal',
  33. // inverse:true,
  34. // align:'left',
  35. // inRange: {
  36. // color: ['rgba(230,230,230,0.6)', '#3385e3'],
  37. // symbolSize: [30, 100]
  38. // },
  39. // outRange: {
  40. // color: ['#e6e6e6', '#3385e3'],
  41. // symbolSize: [30, 100]
  42. // },
  43. // borderColor:'#ffffff',
  44. // text:['高','低'],
  45. // },
  46. // series : [
  47. // {
  48. // name: '浏览量(PV)',
  49. // type: 'map',
  50. // map: 'china',
  51. // roam: true,
  52. // label: {
  53. // normal: {
  54. // show: false
  55. // },
  56. // emphasis: {
  57. // show: true
  58. // }
  59. // },
  60. // itemStyle:{
  61. // normal:{
  62. // borderColor:'#ffffff',
  63. // areaColor:'#e6e6e6'
  64. // }
  65. // },
  66. // data:map
  67. // },
  68. // ]
  69. // };
  70. // myChart.setOption(option);
  71. $('.pv_count').html(res['sum'][0]);
  72. $('.visitor_count').html(res['sum'][1]);
  73. $('.ip_count').html(res['sum'][2]);
  74. $('.bounce_ratio').html(res['sum'][3]+'%');
  75. $('.avg_visit_time').html(res['sum'][4]);
  76. $('.visit-district-tbody').html(res.html);
  77. }else{
  78. $('.visit-district-tbody').html('<tr><td colspan="8" style="text-align:center;">'+res.msg+'</td></tr>');
  79. }
  80. },
  81. error:function(XMLHttpRequest, textStatus, errorThrown){
  82. $('.visit-district-tbody').html(overtime);
  83. },
  84. complete: function (XMLHttpRequest, textStatus) {
  85. if(textStatus == 'timeout'){
  86. $('.visit-district-tbody').html(overtime);
  87. }
  88. },
  89. });
  90. };
  91. $(document).on("change","#changeSiteId",function(){
  92. var url=$(this).data("url");
  93. var siteid=$(this).val();
  94. $.ajax({
  95. url:url,
  96. data:'siteid='+siteid,
  97. dataType: "json",
  98. type:'post',
  99. success:function(res){
  100. if(res.code){
  101. location.reload();
  102. }else{
  103. layer.alert(res.msg);
  104. }
  105. }
  106. });
  107. })
  108. if(bdtj_show==1){
  109. ajax_page('tody');
  110. }else{
  111. layer.alert("尚未配置,请前往插件管理-百度网站统计-配置");
  112. }
  113. $(document).on("click",".ajax-page",function(){
  114. var memo=$(this).attr("data-memo");
  115. ajax_page(memo);
  116. })
  117. $(document).on("click",".show-district",function(){
  118. var obj=$(this);
  119. var id=obj.attr("data-key");
  120. var fa=obj.find('i');
  121. var plus=fa.hasClass('fa-plus');
  122. if(plus){
  123. var table_tr=$(".table-tr_"+id);
  124. if(table_tr.length>0){
  125. table_tr.show();
  126. obj.html('<i class="fa fa-minus" aria-hidden="true"></i>');
  127. }else{
  128. var tr=obj.closest("tr");
  129. var area=tr.attr("data-area");
  130. var memo=$(".btn-group .btn-primary").attr('id');
  131. var msg='<tr class="sub-line table-tr_'+id+' sub-line-last"><td colspan="8" style="text-align:center;">暂无数据</td></tr>';
  132. $.ajax({
  133. url:"baiduapi/visitDistrictTop",
  134. type:'post',
  135. data:'id='+id+'&area='+area+'&memo='+memo,
  136. dataType: "json",
  137. timeout: '10000',
  138. beforeSend:function(){
  139. obj.html('<i class="fa fa-spin fa-spinner" aria-hidden="true"></i>');
  140. },
  141. success:function(res){
  142. if(res.status){
  143. tr.after(res.html);
  144. }else{
  145. tr.after(msg);
  146. }
  147. },
  148. error:function(XMLHttpRequest, textStatus, errorThrown){
  149. tr.after(msg);
  150. },
  151. complete: function (XMLHttpRequest, textStatus) {
  152. if(textStatus == 'timeout'){
  153. tr.after(msg);
  154. }
  155. $('.table-tr_'+id).show();
  156. obj.html('<i class="fa fa-minus" aria-hidden="true"></i>');
  157. },
  158. });
  159. }
  160. }else{
  161. fa.removeClass('fa-minus');
  162. fa.addClass('fa-plus');
  163. $(".table-tr_"+id).hide();
  164. }
  165. })
  166. }
  167. };
  168. return Controller;
  169. });