users.html 8.7 KB

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