index.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $("#TogglePreviewTableBtn").on("click",function(){
  5. if ($(this).hasClass("getoutline-close")){
  6. $(this).removeClass("getoutline-close");
  7. $(this).addClass("getoutline-open");
  8. $(".getoutline-fade").removeClass("toggleable-hidden");
  9. }else{
  10. $(this).removeClass("getoutline-open");
  11. $(this).addClass("getoutline-close");
  12. $(".getoutline-fade").addClass("toggleable-hidden");
  13. }
  14. });
  15. $(document).on("change","#changeSiteId",function(){
  16. var url=$(this).data("url");
  17. var siteid=$(this).val();
  18. $.ajax({
  19. url:url,
  20. data:'siteid='+siteid,
  21. dataType: "json",
  22. type:'post',
  23. success:function(res){
  24. if(res.code){
  25. getOutline();
  26. ajax_page('tody');
  27. }else{
  28. layer.alert(res.msg);
  29. }
  30. }
  31. });
  32. })
  33. $(document).on("click",".ajax-btn",function(){
  34. var memo=$(this).attr("id");
  35. ajax_page(memo);
  36. })
  37. $(document).on("click",".overtime-getOutline",function(){
  38. getOutline();
  39. })
  40. $(document).on("click",".overtime-getTimeTrendRpt",function(){
  41. var memo=$(this).attr("data-memo");
  42. getTimeTrendRpt(memo);
  43. })
  44. $(document).on("click",".overtime-getCommonTrackRpt",function(){
  45. var memo=$(this).attr("data-memo");
  46. getCommonTrackRpt(memo)
  47. })
  48. var ajax_page=function (memo){
  49. $(".btn-group .btn").addClass("btn-default");
  50. $(".btn-group .btn").removeClass("btn-primary");
  51. $("#"+memo).addClass("btn-primary");
  52. $("#"+memo).removeClass("btn-default");
  53. getTimeTrendRpt(memo);
  54. getCommonTrackRpt(memo);
  55. };
  56. var getOutline=function(){
  57. var overtime='<tr><td colspan="7" style="text-align:center;">请求超时,<a href="javascript:;" class="overtime-getOutline">点击重试</a></td></tr>';
  58. $.ajax({
  59. url:url_getoutline,
  60. type:'post',
  61. timeout: '10000',
  62. beforeSend:function(){
  63. $('.getoutline-tbody').html('<tr><td colspan="7" style="text-align:center;"><i class="fa fa-spin fa-spinner" aria-hidden="true"></i>&nbsp;&nbsp;数据获取中...</td></tr>');
  64. },
  65. success:function(res){
  66. $('.getoutline-tbody').html(res.html);
  67. },
  68. error:function(XMLHttpRequest, textStatus, errorThrown){
  69. $('.getoutline-tbody').html(overtime);
  70. },
  71. complete: function (XMLHttpRequest, textStatus) {
  72. if(textStatus == 'timeout'){
  73. $('.getoutline-tbody').html(overtime);
  74. }
  75. },
  76. });
  77. };
  78. var getTimeTrendRpt=function(memo){
  79. $("#echarts-line-chart").css("width",$("#echarts-line-chart").width());
  80. var overtime='请求超时,<a href="javascript:;" class="overtime-getTimeTrendRpt" data-memo="'+memo+'">点击重试</a>';
  81. $.ajax({
  82. url:url_gettimetrendrpt,
  83. type:'post',
  84. data:'memo='+memo,
  85. dataType: "json",
  86. timeout: '10000',
  87. success:function(res){
  88. if(res.status==1){
  89. var echarts_getTimeTrendRpt = echarts.init(document.getElementById("echarts-line-chart")),
  90. option_getTimeTrendRpt = {
  91. tooltip: {
  92. trigger: "axis"
  93. },
  94. grid: {
  95. left: '3%',
  96. right: '5%',
  97. bottom: '3%',
  98. containLabel: true
  99. },
  100. legend: {
  101. data: ['浏览量(PV)','访客数(UV)']
  102. },
  103. calculable: !0,
  104. xAxis: [{
  105. type: "category",
  106. boundaryGap: !1,
  107. data: res.data.date,
  108. axisTick: {
  109. alignWithLabel: true
  110. }
  111. }],
  112. yAxis: {
  113. type: "value",
  114. },
  115. series: [
  116. {
  117. name: "浏览量(PV)",
  118. type: "line",
  119. data: res.data.pv,
  120. areaStyle:{
  121. normal:{
  122. color:['#e5f1fd']
  123. }
  124. }
  125. },
  126. {
  127. name: "访客数(UV)",
  128. type: "line",
  129. data: res.data.uv,
  130. areaStyle:{
  131. normal:{
  132. color:['#e5f1fd']
  133. }
  134. }
  135. }
  136. ],
  137. color:['#4fa8f9','#6ec71e']
  138. };
  139. echarts_getTimeTrendRpt.setOption(option_getTimeTrendRpt);
  140. $(window).resize(function(){
  141. echarts_getTimeTrendRpt.resize({width:$("#echarts-line-chart").closest(".panel-body").width()})
  142. });
  143. }else{
  144. $("#echarts-line-chart span").html('暂无数据');
  145. }
  146. },
  147. error:function(XMLHttpRequest, textStatus, errorThrown){
  148. $("#echarts-line-chart span").html(overtime);
  149. },
  150. complete: function (XMLHttpRequest, textStatus) {
  151. if(textStatus == 'timeout'){
  152. $("#echarts-line-chart span").html(overtime);
  153. }
  154. },
  155. });
  156. };
  157. var getCommonTrackRpt=function(memo){
  158. var overtime='<tr><td colspan="7" style="text-align:center;">请求超时,<a href="javascript:;" class="overtime-getCommonTrackRpt" data-memo="'+memo+'">点击重试</a></td></tr>';
  159. $.ajax({
  160. url:url_getcommontrackrpt,
  161. type:'post',
  162. data:'memo='+memo,
  163. dataType: "json",
  164. timeout: '10000',
  165. beforeSend:function(){
  166. $('.visit-overview-tbody').html('<tr><td colspan="7" class="no-borders text-center"><span style="line-height: 300px;"><i class="fa fa-spin fa-spinner" aria-hidden="true"></i>&nbsp;&nbsp;数据获取中...<span></td></tr>');
  167. },
  168. success:function(res){
  169. if(res.status){
  170. $("#sourceSite").html(res.data.sourceSite);
  171. $("#word").html(res.data.word);
  172. $("#landingPage").html(res.data.landingPage);
  173. $("#visitPage").html(res.data.visitPage);
  174. $(".new_ratio span").html(res.data.visitType.newVisitor.ratio);
  175. $(".old_ratio span").html(res.data.visitType.oldVisitor.ratio);
  176. $(".new_pv_count").html(res.data.visitType.newVisitor.pv_count);
  177. $(".old_pv_count").html(res.data.visitType.oldVisitor.pv_count);
  178. $(".new_visitor_count").html(res.data.visitType.newVisitor.visitor_count);
  179. $(".old_visitor_count").html(res.data.visitType.oldVisitor.visitor_count);
  180. $(".new_bounce_ratio").html(res.data.visitType.newVisitor.bounce_ratio+"%");
  181. $(".old_bounce_ratio").html(res.data.visitType.oldVisitor.bounce_ratio+"%");
  182. $(".new_avg_visit_time").html(res.data.visitType.newVisitor.avg_visit_time);
  183. $(".old_avg_visit_time").html(res.data.visitType.oldVisitor.avg_visit_time);
  184. $(".new_avg_visit_pages").html(res.data.visitType.newVisitor.avg_visit_pages);
  185. $(".old_avg_visit_pages").html(res.data.visitType.oldVisitor.avg_visit_pages);
  186. }else{
  187. var msg='<tr><td colspan="3" class="text-center">暂无数据</td></tr>';
  188. $("#sourceSite").html(msg);
  189. $("#word").html(msg);
  190. $("#landingPage").html(msg);
  191. $("#visitPage").html(msg);
  192. }
  193. },
  194. error:function(XMLHttpRequest, textStatus, errorThrown){
  195. $('.visit-overview-tbody').html(overtime);
  196. },
  197. complete: function (XMLHttpRequest, textStatus) {
  198. if(textStatus == 'timeout'){
  199. $('.visit-overview-tbody').html(overtime);
  200. }
  201. },
  202. });
  203. };
  204. if(bdtj_show==1){
  205. getOutline();
  206. ajax_page('tody');
  207. }else{
  208. layer.alert("尚未配置,请前往插件管理-百度网站统计-配置");
  209. }
  210. }
  211. };
  212. return Controller;
  213. });