动态菜单和动态路由的 antd pro

index.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import React from 'react';
  2. import { Chart, Geom, Axis, Coord, Guide, Shape } from 'bizcharts';
  3. import autoHeight from '../autoHeight';
  4. const { Arc, Html, Line } = Guide;
  5. const defaultFormatter = val => {
  6. switch (val) {
  7. case '2':
  8. return '差';
  9. case '4':
  10. return '中';
  11. case '6':
  12. return '良';
  13. case '8':
  14. return '优';
  15. default:
  16. return '';
  17. }
  18. };
  19. Shape.registerShape('point', 'pointer', {
  20. drawShape(cfg, group) {
  21. let point = cfg.points[0];
  22. point = this.parsePoint(point);
  23. const center = this.parsePoint({
  24. x: 0,
  25. y: 0,
  26. });
  27. group.addShape('line', {
  28. attrs: {
  29. x1: center.x,
  30. y1: center.y,
  31. x2: point.x,
  32. y2: point.y,
  33. stroke: cfg.color,
  34. lineWidth: 2,
  35. lineCap: 'round',
  36. },
  37. });
  38. return group.addShape('circle', {
  39. attrs: {
  40. x: center.x,
  41. y: center.y,
  42. r: 6,
  43. stroke: cfg.color,
  44. lineWidth: 3,
  45. fill: '#fff',
  46. },
  47. });
  48. },
  49. });
  50. @autoHeight()
  51. export default class Gauge extends React.Component {
  52. render() {
  53. const {
  54. title,
  55. height,
  56. percent,
  57. forceFit = true,
  58. formatter = defaultFormatter,
  59. color = '#2F9CFF',
  60. bgColor = '#F0F2F5',
  61. } = this.props;
  62. const cols = {
  63. value: {
  64. type: 'linear',
  65. min: 0,
  66. max: 10,
  67. tickCount: 6,
  68. nice: true,
  69. },
  70. };
  71. const data = [{ value: percent / 10 }];
  72. return (
  73. <Chart height={height} data={data} scale={cols} padding={[-16, 0, 16, 0]} forceFit={forceFit}>
  74. <Coord type="polar" startAngle={-1.25 * Math.PI} endAngle={0.25 * Math.PI} radius={0.8} />
  75. <Axis name="1" line={null} />
  76. <Axis
  77. line={null}
  78. tickLine={null}
  79. subTickLine={null}
  80. name="value"
  81. zIndex={2}
  82. gird={null}
  83. label={{
  84. offset: -12,
  85. formatter,
  86. textStyle: {
  87. fontSize: 12,
  88. fill: 'rgba(0, 0, 0, 0.65)',
  89. textAlign: 'center',
  90. },
  91. }}
  92. />
  93. <Guide>
  94. <Line
  95. start={[3, 0.905]}
  96. end={[3, 0.85]}
  97. lineStyle={{
  98. stroke: color,
  99. lineDash: null,
  100. lineWidth: 2,
  101. }}
  102. />
  103. <Line
  104. start={[5, 0.905]}
  105. end={[5, 0.85]}
  106. lineStyle={{
  107. stroke: color,
  108. lineDash: null,
  109. lineWidth: 3,
  110. }}
  111. />
  112. <Line
  113. start={[7, 0.905]}
  114. end={[7, 0.85]}
  115. lineStyle={{
  116. stroke: color,
  117. lineDash: null,
  118. lineWidth: 3,
  119. }}
  120. />
  121. <Arc
  122. zIndex={0}
  123. start={[0, 0.965]}
  124. end={[10, 0.965]}
  125. style={{
  126. stroke: bgColor,
  127. lineWidth: 10,
  128. }}
  129. />
  130. <Arc
  131. zIndex={1}
  132. start={[0, 0.965]}
  133. end={[data[0].value, 0.965]}
  134. style={{
  135. stroke: color,
  136. lineWidth: 10,
  137. }}
  138. />
  139. <Html
  140. position={['50%', '95%']}
  141. html={() => {
  142. return `
  143. <div style="width: 300px;text-align: center;font-size: 12px!important;">
  144. <p style="font-size: 14px; color: rgba(0,0,0,0.43);margin: 0;">${title}</p>
  145. <p style="font-size: 24px;color: rgba(0,0,0,0.85);margin: 0;">
  146. ${data[0].value * 10}%
  147. </p>
  148. </div>`;
  149. }}
  150. />
  151. </Guide>
  152. <Geom
  153. line={false}
  154. type="point"
  155. position="value*1"
  156. shape="pointer"
  157. color={color}
  158. active={false}
  159. />
  160. </Chart>
  161. );
  162. }
  163. }