yj_risk.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="dz-risk">
  3. <div class="risk-container">
  4. <div class="risk-center"></div>
  5. <div ref="riskPie" class="risk-pie"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script setup lang="ts">
  10. import { ref, nextTick, onMounted, watch } from 'vue';
  11. import * as echarts from 'echarts';
  12. let props = defineProps({
  13. echartData: {
  14. type: Array,
  15. default: () => {
  16. return [];
  17. },
  18. },
  19. });
  20. let riskPie = ref(null);
  21. let echartData = ref<any[]>([]);
  22. function getOption() {
  23. nextTick(() => {
  24. const colorList = [
  25. {
  26. type: 'radial',
  27. r: 1,
  28. colorStops: [
  29. {
  30. offset: 0,
  31. color: 'rgba(182, 242, 255,1)', // 0% 处的颜色
  32. },
  33. {
  34. offset: 1,
  35. color: 'rgba(95, 228, 255,1)', // 100% 处的颜色
  36. },
  37. ],
  38. },
  39. {
  40. type: 'radial',
  41. r: 1,
  42. colorStops: [
  43. {
  44. offset: 0,
  45. color: 'rgba(176, 255, 236,1)', // 0% 处的颜色
  46. },
  47. {
  48. offset: 1,
  49. color: 'rgba(86, 255, 171,1)', // 100% 处的颜色
  50. },
  51. ],
  52. },
  53. {
  54. type: 'radial',
  55. r: 1,
  56. colorStops: [
  57. {
  58. offset: 0,
  59. color: 'rgba(255, 253, 176,1)', // 0% 处的颜色
  60. },
  61. {
  62. offset: 1,
  63. color: 'rgba(255, 255, 86,1)', // 100% 处的颜色
  64. },
  65. ],
  66. },
  67. {
  68. type: 'radial',
  69. r: 1,
  70. colorStops: [
  71. {
  72. offset: 0,
  73. color: 'rgba(215, 179, 255,1)', // 0% 处的颜色
  74. },
  75. {
  76. offset: 1,
  77. color: 'rgba(134, 88, 255,1)', // 100% 处的颜色
  78. },
  79. ],
  80. },
  81. ];
  82. let myChart = echarts.init(riskPie.value);
  83. let option = {
  84. color: colorList,
  85. // tooltip: {
  86. // trigger: 'item'
  87. // },
  88. series: [
  89. {
  90. type: 'pie',
  91. center: ['50%', '50%'],
  92. radius: ['30%', '50%'],
  93. emphasis: {
  94. label: {
  95. show: true,
  96. },
  97. opacity: 1,
  98. color: function (params) {
  99. return colorList[params.dataIndex];
  100. },
  101. },
  102. itemStyle: {
  103. normal: {
  104. color: function (params) {
  105. return colorList[params.dataIndex];
  106. },
  107. },
  108. },
  109. label: {
  110. show: true,
  111. position: 'outside',
  112. textStyle: {
  113. color: '#fff',
  114. fontSize: 10,
  115. },
  116. formatter: '{b}:{c}',
  117. rich: {
  118. a: {
  119. padding: [-10, 5, -15, 5],
  120. },
  121. },
  122. },
  123. labelLine: {
  124. normal: {
  125. length: 10,
  126. length2: 5,
  127. lineStyle: {
  128. width: 1,
  129. },
  130. },
  131. },
  132. data: echartData.value,
  133. },
  134. ],
  135. };
  136. myChart.setOption(option);
  137. window.onresize = function () {
  138. myChart.resize();
  139. };
  140. });
  141. }
  142. watch(
  143. () => props.echartData,
  144. (newV, oldV) => {
  145. echartData.value = newV;
  146. getOption();
  147. },
  148. { immediate: true }
  149. );
  150. </script>
  151. <style lang="less" scoped>
  152. @import '/@/design/theme.less';
  153. .dz-risk {
  154. --image-model_risk-container: url('@/assets/images/home-warn/2.png');
  155. --image-model_risk-center: url('@/assets/images/home-warn/1.png');
  156. height: 100%;
  157. .risk-container {
  158. position: relative;
  159. height: 100%;
  160. width: 100%;
  161. height: 100%;
  162. background: var(--image-model_risk-container) no-repeat center;
  163. background-size: auto 100%;
  164. .risk-center {
  165. position: absolute;
  166. left: 50%;
  167. top: 50%;
  168. transform: translate(-50%, -50%);
  169. width: 100%;
  170. height: 60px;
  171. background: var(--image-model_risk-center) no-repeat center;
  172. background-size: auto 100%;
  173. }
  174. .risk-pie {
  175. left: -28px;
  176. top: -17px;
  177. position: absolute;
  178. width: 276px;
  179. height: 205px;
  180. }
  181. }
  182. }
  183. </style>