users.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>用户统计</title>
  8. <link rel="stylesheet" href="/static/antv/f2.style.css" />
  9. <script type="text/javascript" src="/static/jquery-2.2.4.min.js"></script>
  10. <script src="/static/antv/f2.min.js"></script>
  11. <style>
  12. html,body {
  13. margin: 0;
  14. padding: 0;
  15. overflow-y: scroll;
  16. -webkit-overflow-scrolling: touch;
  17. background: #f1f1f1;
  18. }
  19. .chart-wrapper {
  20. margin: 10px;
  21. border-radius: 10px;
  22. }
  23. ul {
  24. margin: 0;
  25. padding: 0;
  26. }
  27. .nav-tabs>li>a {
  28. margin-right: 0;
  29. border-radius: 0;
  30. }
  31. a {
  32. text-align: center;
  33. font-size: 16px;
  34. font-weight:bold;
  35. color: #999;
  36. text-decoration: none;
  37. }
  38. .daily-record {
  39. margin: 0 10px;
  40. background-color: #fff;
  41. border-radius: 10px;
  42. }
  43. .record-data {
  44. display: flex;
  45. display: -webkit-flex;
  46. justify-content: space-between;
  47. align-items: center;
  48. height: 7vh;
  49. }
  50. .line {
  51. margin: 0 15px;
  52. height: 1px;
  53. background-color: #CCCCCC;
  54. }
  55. .daily-title, .daily-nums {
  56. display: inline;
  57. font-size: 17px;
  58. font-weight: 500;
  59. }
  60. .daily-title {
  61. margin-left: 25px;
  62. display: flex;
  63. display: -webkit-flex;
  64. align-items: center;
  65. }
  66. .daily-nums {
  67. margin-right: 25px;
  68. color:rgba(153,153,153,1);
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="chart-wrapper">
  74. <canvas id="mountNode" style="width: 100%;"></canvas>
  75. </div>
  76. <div class="daily-record">
  77. <div class="record-data first" onclick="user(this)" data-rolesId="0" data-orgId="{$orgId}" >
  78. <span class="daily-title" style="color: #148d8f;font-weight: 700;">用户总数</span>
  79. <span class="daily-nums" style="color: #148d8f;font-weight: 700;">{$allcount}</span>
  80. </div>
  81. {foreach $list as $k=>$v}
  82. <div class="line"></div>
  83. <div class="record-data" onclick="user(this)" data-rolesId="{$v['id']}" data-orgId="{$orgId}">
  84. <span class="daily-title"><span style="display: inline-block;margin-right:10px;background: {$v['color']};width: 6px;height: 6px;border-radius:5px;"></span>{$v['name']}</span>
  85. <span class="daily-nums">{$v['cost']}</span>
  86. </div>
  87. {/foreach}
  88. </div>
  89. <script>
  90. var Util = F2.Util;
  91. var G = F2.G;
  92. var Group = G.Group;
  93. function drawLabel(shape, coord, canvas) {
  94. var center = coord.center;
  95. var origin = shape.get('origin');
  96. var points = origin.points;
  97. var x1 = (points[2].x - points[1].x) * 0.75 + points[1].x;
  98. var x2 = (points[2].x - points[1].x) * 1.8 + points[1].x;
  99. var y = (points[0].y + points[1].y) / 2;
  100. var point1 = coord.convertPoint({
  101. x: x1,
  102. y: y
  103. });
  104. var point2 = coord.convertPoint({
  105. x: x2,
  106. y: y
  107. });
  108. var group = new Group();
  109. group.addShape('Line', {
  110. attrs: {
  111. x1: point1.x,
  112. y1: point1.y,
  113. x2: point2.x,
  114. y2: point2.y,
  115. lineDash: [0, 2, 2],
  116. stroke: '#808080'
  117. }
  118. });
  119. var text = group.addShape('Text', {
  120. attrs: {
  121. x: point2.x,
  122. y: point2.y,
  123. text: origin._origin.type + ' ' + origin._origin.cost,
  124. fill: '#808080',
  125. textAlign: 'start',
  126. textBaseline: 'bottom'
  127. }
  128. });
  129. var textWidth = text.getBBox().width;
  130. var baseLine = group.addShape('Line', {
  131. attrs: {
  132. x1: point2.x,
  133. y1: point2.y,
  134. x2: point2.x,
  135. y2: point2.y,
  136. stroke: '#808080'
  137. }
  138. });
  139. if (point2.x > center.x) {
  140. baseLine.attr('x2', point2.x + textWidth);
  141. } else if (point2.x < center.x) {
  142. text.attr('textAlign', 'end');
  143. baseLine.attr('x2', point2.x - textWidth);
  144. } else {
  145. text.attr('textAlign', 'center');
  146. text.attr('textBaseline', 'top');
  147. }
  148. canvas.add(group);
  149. shape.label = group;
  150. }
  151. var data = {:json_encode($list)};
  152. var sum = 0;
  153. data.map(function(obj) {
  154. sum += obj.cost;
  155. });
  156. var chart = new F2.Chart({
  157. id: 'mountNode',
  158. pixelRatio: window.devicePixelRatio
  159. });
  160. chart.source(data);
  161. var lastClickedShape;
  162. chart.legend({
  163. position: 'bottom',
  164. offsetY: -5,
  165. marker: 'circle',
  166. align: 'center',
  167. onClick: function onClick(ev) {
  168. var clickedItem = ev.clickedItem;
  169. var dataValue = clickedItem.get('dataValue');
  170. var canvas = chart.get('canvas');
  171. var coord = chart.get('coord');
  172. var geom = chart.get('geoms')[0];
  173. var container = geom.get('container');
  174. var shapes = geom.get('shapes'); // 只有带精细动画的 geom 才有 shapes 这个属性
  175. var clickedShape;
  176. // 找到被点击的 shape
  177. Util.each(shapes, function(shape) {
  178. var origin = shape.get('origin');
  179. if (origin && origin._origin.type === dataValue) {
  180. clickedShape = shape;
  181. return false;
  182. }
  183. });
  184. if (lastClickedShape) {
  185. lastClickedShape.animate().to({
  186. attrs: {
  187. lineWidth: 0
  188. },
  189. duration: 200
  190. }).onStart(function() {
  191. if (lastClickedShape.label) {
  192. lastClickedShape.label.hide();
  193. }
  194. }).onEnd(function() {
  195. lastClickedShape.set('selected', false);
  196. });
  197. }
  198. if (clickedShape.get('selected')) {
  199. clickedShape.animate().to({
  200. attrs: {
  201. lineWidth: 0
  202. },
  203. duration: 200
  204. }).onStart(function() {
  205. if (clickedShape.label) {
  206. clickedShape.label.hide();
  207. }
  208. }).onEnd(function() {
  209. clickedShape.set('selected', false);
  210. });
  211. } else {
  212. var color = clickedShape.attr('fill');
  213. clickedShape.animate().to({
  214. attrs: {
  215. lineWidth: 5
  216. },
  217. duration: 350,
  218. easing: 'bounceOut'
  219. }).onStart(function() {
  220. clickedShape.attr('stroke', color);
  221. clickedShape.set('zIndex', 1);
  222. container.sort();
  223. }).onEnd(function() {
  224. clickedShape.set('selected', true);
  225. clickedShape.set('zIndex', 0);
  226. container.sort();
  227. lastClickedShape = clickedShape;
  228. if (clickedShape.label) {
  229. clickedShape.label.show();
  230. } else {
  231. drawLabel(clickedShape, coord, canvas);
  232. }
  233. canvas.draw();
  234. });
  235. }
  236. }
  237. });
  238. chart.coord('polar', {
  239. transposed: true,
  240. innerRadius: 0.8,
  241. radius: 1
  242. });
  243. chart.axis(false);
  244. chart.tooltip(false);
  245. chart.interval().position('a*cost').color('name', ['#8ADAC4', '#39C2EA', '#5360DA', '#325699', '#68B15C','#F7B762','#F2735F','#1EC498','#4DA9EB','#4AD1E7']).adjust('stack');
  246. chart.guide().html({
  247. position: ['50%', '50%'],
  248. html: '<div style="width: 250px;height: 40px;text-align: center;">' + '<div style="font-size: 24px;color:#089875;">{$allcount}</div>' + '<div style="font-size: 16px;color:#089875;">用户总数</div>' + '</div>'
  249. });
  250. chart.render();
  251. </script>
  252. </body>
  253. </html>
  254. <script>
  255. function user(obj) {
  256. var rolesId = $(obj).attr('data-rolesId');
  257. var orgId = $(obj).attr('data-orgId');
  258. var url = "{:url('Statistics/userList')}?rolesId="+rolesId+'&orgId='+orgId;
  259. window.location.href=url;
  260. }
  261. </script>