dz-risk.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. riskData: {
  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. offset: 0, color: 'rgba(182, 242, 255,1)' // 0% 处的颜色
  30. }, {
  31. offset: 1, color: 'rgba(95, 228, 255,1)' // 100% 处的颜色
  32. }],
  33. },
  34. {
  35. type: 'radial',
  36. r: 1,
  37. colorStops: [{
  38. offset: 0, color: 'rgba(176, 255, 236,1)' // 0% 处的颜色
  39. }, {
  40. offset: 1, color: 'rgba(86, 255, 171,1)' // 100% 处的颜色
  41. }],
  42. },
  43. {
  44. type: 'radial',
  45. r: 1,
  46. colorStops: [{
  47. offset: 0, color: 'rgba(255, 253, 176,1)' // 0% 处的颜色
  48. }, {
  49. offset: 1, color: 'rgba(255, 255, 86,1)' // 100% 处的颜色
  50. }],
  51. },
  52. {
  53. type: 'radial',
  54. r: 1,
  55. colorStops: [{
  56. offset: 0, color: 'rgba(215, 179, 255,1)' // 0% 处的颜色
  57. }, {
  58. offset: 1, color: 'rgba(134, 88, 255,1)' // 100% 处的颜色
  59. }],
  60. },
  61. ]
  62. let myChart = echarts.init(riskPie.value);
  63. let option = {
  64. color: colorList,
  65. // tooltip: {
  66. // trigger: 'item'
  67. // },
  68. series: [{
  69. type: 'pie',
  70. center: ['50%', '50%'],
  71. radius: ['48%', '70%'],
  72. // clockwise: false,
  73. // avoidLabelOverlap: true,
  74. emphasis: {
  75. label: {
  76. show: true
  77. },
  78. itemStyle: {
  79. color: function (params) {
  80. return colorList[params.dataIndex]
  81. }
  82. }
  83. },
  84. // hoverOffset: 0,
  85. itemStyle: {
  86. normal: {
  87. color: function (params) {
  88. return colorList[params.dataIndex]
  89. }
  90. }
  91. },
  92. label: {
  93. show: true,
  94. position: 'outside',
  95. textStyle: {
  96. color: "#fff",
  97. fontSize: 12
  98. },
  99. formatter: '{a|{b}:{d}%}\n{hr|}',
  100. rich: {
  101. hr: {
  102. backgroundColor: 't',
  103. borderRadius: 3,
  104. width: 3,
  105. height: 3,
  106. padding: [3, 3, 0, -12]
  107. },
  108. a: {
  109. padding: [-10, 5, -15, 5]
  110. }
  111. }
  112. },
  113. labelLine: {
  114. normal: {
  115. length: 20,
  116. length2: 20,
  117. lineStyle: {
  118. width: 1
  119. }
  120. }
  121. },
  122. data: echartData.value,
  123. }]
  124. };
  125. myChart.setOption(option);
  126. window.onresize = function () {
  127. myChart.resize();
  128. };
  129. });
  130. }
  131. watch(() => props.riskData, (newV, oldV) => {
  132. echartData.value = newV
  133. getOption()
  134. }, { immediate: true })
  135. </script>
  136. <style lang="less" scoped>
  137. @import '/@/design/theme.less';
  138. @{theme-deepblue} {
  139. .dz-risk {
  140. --image-model_risk-container: url('@/assets/images/themify/deepblue/home-container/configurable/1400.png');
  141. --image-model_risk-center: url('@/assets/images/themify/deepblue/home-container/configurable/1500.png');
  142. }
  143. }
  144. .dz-risk {
  145. --image-model_risk-container: url('@/assets/images/home-green/1400.png');
  146. --image-model_risk-center: url('@/assets/images/home-green/1500.png');
  147. height: 100%;
  148. .risk-container {
  149. position: relative;
  150. height: 100%;
  151. width: 100%;
  152. height: 210px;
  153. background: var(--image-model_risk-container) no-repeat center;
  154. background-size: auto 100%;
  155. .risk-center {
  156. position: absolute;
  157. left: 50%;
  158. top: 50%;
  159. transform: translate(-50%, -50%);
  160. width: 100%;
  161. height: 80px;
  162. background: var( --image-model_risk-center) no-repeat center;
  163. background-size: auto 100%;
  164. }
  165. .risk-pie {
  166. width: 100%;
  167. height: 100%;
  168. }
  169. }
  170. }
  171. </style>