console.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. @Name:layuiAdmin 主页控制台
  3. @Author:贤心
  4. @Site:http://www.layui.com/admin/
  5. @License:GPL-2
  6. */
  7. layui.define(function(exports){
  8. /*
  9. 下面通过 layui.use 分段加载不同的模块,实现不同区域的同时渲染,从而保证视图的快速呈现
  10. */
  11. //区块轮播切换
  12. layui.use(['admin', 'carousel'], function(){
  13. var $ = layui.$
  14. ,admin = layui.admin
  15. ,carousel = layui.carousel
  16. ,element = layui.element
  17. ,device = layui.device();
  18. //轮播切换
  19. $('.layadmin-carousel').each(function(){
  20. var othis = $(this);
  21. carousel.render({
  22. elem: this
  23. ,width: '100%'
  24. ,arrow: 'none'
  25. ,interval: othis.data('interval')
  26. ,autoplay: othis.data('autoplay') === true
  27. ,trigger: (device.ios || device.android) ? 'click' : 'hover'
  28. ,anim: othis.data('anim')
  29. });
  30. });
  31. element.render('progress');
  32. });
  33. //数据概览
  34. layui.use(['admin', 'carousel', 'echarts'], function(){
  35. var $ = layui.$
  36. ,admin = layui.admin
  37. ,carousel = layui.carousel
  38. ,echarts = layui.echarts;
  39. var echartsApp = [], options = [
  40. //今日流量趋势
  41. {
  42. title: {
  43. text: '今日流量趋势',
  44. x: 'center',
  45. textStyle: {
  46. fontSize: 14
  47. }
  48. },
  49. tooltip : {
  50. trigger: 'axis'
  51. },
  52. legend: {
  53. data:['','']
  54. },
  55. xAxis : [{
  56. type : 'category',
  57. boundaryGap : false,
  58. data: ['06:00','06:30','07:00','07:30','08:00','08:30','09:00','09:30','10:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30','15:00','15:30','16:00','16:30','17:00','17:30','18:00','18:30','19:00','19:30','20:00','20:30','21:00','21:30','22:00','22:30','23:00','23:30']
  59. }],
  60. yAxis : [{
  61. type : 'value'
  62. }],
  63. series : [{
  64. name:'PV',
  65. type:'line',
  66. smooth:true,
  67. itemStyle: {normal: {areaStyle: {type: 'default'}}},
  68. data: [111,222,333,444,555,666,3333,33333,55555,66666,33333,3333,6666,11888,26666,38888,56666,42222,39999,28888,17777,9666,6555,5555,3333,2222,3111,6999,5888,2777,1666,999,888,777]
  69. },{
  70. name:'UV',
  71. type:'line',
  72. smooth:true,
  73. itemStyle: {normal: {areaStyle: {type: 'default'}}},
  74. data: [11,22,33,44,55,66,333,3333,5555,12666,3333,333,666,1188,2666,3888,6666,4222,3999,2888,1777,966,655,555,333,222,311,699,588,277,166,99,88,77]
  75. }]
  76. },
  77. //访客浏览器分布
  78. {
  79. title : {
  80. text: '访客浏览器分布',
  81. x: 'center',
  82. textStyle: {
  83. fontSize: 14
  84. }
  85. },
  86. tooltip : {
  87. trigger: 'item',
  88. formatter: "{a} <br/>{b} : {c} ({d}%)"
  89. },
  90. legend: {
  91. orient : 'vertical',
  92. x : 'left',
  93. data:['Chrome','Firefox','IE 8.0','Safari','其它浏览器']
  94. },
  95. series : [{
  96. name:'访问来源',
  97. type:'pie',
  98. radius : '55%',
  99. center: ['50%', '50%'],
  100. data:[
  101. {value:9052, name:'Chrome'},
  102. {value:1610, name:'Firefox'},
  103. {value:3200, name:'IE 8.0'},
  104. {value:535, name:'Safari'},
  105. {value:1700, name:'其它浏览器'}
  106. ]
  107. }]
  108. },
  109. //新增的用户量
  110. {
  111. title: {
  112. text: '最近一周新增的用户量',
  113. x: 'center',
  114. textStyle: {
  115. fontSize: 14
  116. }
  117. },
  118. tooltip : { //提示框
  119. trigger: 'axis',
  120. formatter: "{b}<br>新增用户:{c}"
  121. },
  122. xAxis : [{ //X轴
  123. type : 'category',
  124. data : ['11-07', '11-08', '11-09', '11-10', '11-11', '11-12', '11-13']
  125. }],
  126. yAxis : [{ //Y轴
  127. type : 'value'
  128. }],
  129. series : [{ //内容
  130. type: 'line',
  131. data:[200, 300, 400, 610, 150, 270, 380],
  132. }]
  133. }
  134. ]
  135. ,elemDataView = $('#LAY-index-dataview').children('div')
  136. ,renderDataView = function(index){
  137. echartsApp[index] = echarts.init(elemDataView[index], layui.echartsTheme);
  138. echartsApp[index].setOption(options[index]);
  139. //window.onresize = echartsApp[index].resize;
  140. admin.resize(function(){
  141. echartsApp[index].resize();
  142. });
  143. };
  144. //没找到DOM,终止执行
  145. if(!elemDataView[0]) return;
  146. renderDataView(0);
  147. //监听数据概览轮播
  148. var carouselIndex = 0;
  149. carousel.on('change(LAY-index-dataview)', function(obj){
  150. renderDataView(carouselIndex = obj.index);
  151. });
  152. //监听侧边伸缩
  153. layui.admin.on('side', function(){
  154. setTimeout(function(){
  155. renderDataView(carouselIndex);
  156. }, 300);
  157. });
  158. //监听路由
  159. layui.admin.on('hash(tab)', function(){
  160. layui.router().path.join('') || renderDataView(carouselIndex);
  161. });
  162. });
  163. //最新订单
  164. layui.use('table', function(){
  165. var $ = layui.$
  166. ,table = layui.table;
  167. //今日热搜
  168. table.render({
  169. elem: '#LAY-index-topSearch'
  170. ,url: layui.setter.base + 'json/console/top-search.js' //模拟接口
  171. ,page: true
  172. ,cols: [[
  173. {type: 'numbers', fixed: 'left'}
  174. ,{field: 'keywords', title: '关键词', minWidth: 300, templet: '<div><a href="https://www.baidu.com/s?wd={{ d.keywords }}" target="_blank" class="layui-table-link">{{ d.keywords }}</div>'}
  175. ,{field: 'frequency', title: '搜索次数', minWidth: 120, sort: true}
  176. ,{field: 'userNums', title: '用户数', sort: true}
  177. ]]
  178. ,skin: 'line'
  179. });
  180. //今日热贴
  181. table.render({
  182. elem: '#LAY-index-topCard'
  183. ,url: layui.setter.base + 'json/console/top-card.js' //模拟接口
  184. ,page: true
  185. ,cellMinWidth: 120
  186. ,cols: [[
  187. {type: 'numbers', fixed: 'left'}
  188. ,{field: 'title', title: '标题', minWidth: 300, templet: '<div><a href="{{ d.href }}" target="_blank" class="layui-table-link">{{ d.title }}</div>'}
  189. ,{field: 'username', title: '发帖者'}
  190. ,{field: 'channel', title: '类别'}
  191. ,{field: 'crt', title: '点击率', sort: true}
  192. ]]
  193. ,skin: 'line'
  194. });
  195. });
  196. exports('console', {})
  197. });