sameDay.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="_runnin">
  3. <HeadlineTag value="性能统计"></HeadlineTag>
  4. <div class="_runnin_mains">
  5. <!-- 修正引用名称,与脚本里保持一致 -->
  6. <div class="_runnin_mains_item">
  7. <div ref="chartRefCPU" style="width: 140px;height: 140px;"></div>
  8. <span style="margin-top: 10px;font-weight: bold;">CPU</span>
  9. </div>
  10. <div class="_runnin_mains_item">
  11. <div ref="chartRefRAM" style="width: 140px;height: 140px;"></div>
  12. <span style="margin-top: 10px;font-weight: bold;">RAM</span>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { ref, onMounted, nextTick } from "vue";
  19. import * as echarts from 'echarts'
  20. import 'echarts-liquidfill';
  21. import HeadlineTag from '@/components/HeadlineTag'
  22. const chartRefCPU = ref(null);
  23. const chartRefRAM = ref(null);
  24. let chartInstanceCPU = null;
  25. let chartInstanceRAM = null;
  26. const initCPUDrop = () => {
  27. // 检查 DOM 元素是否存在
  28. if (chartRefCPU.value) {
  29. var value = 0.45;
  30. chartInstanceCPU = null
  31. chartInstanceCPU = echarts.init(chartRefCPU.value);
  32. chartInstanceCPU.setOption({
  33. series: [
  34. {
  35. type: 'liquidFill', //水位图
  36. radius: '100%', //显示比例
  37. center: ['50%', '50%'], //中心点
  38. amplitude: 20, //水波振幅
  39. data: [value, value], // data个数代表波浪数
  40. color: [
  41. {
  42. type: 'linear',
  43. x: 0,
  44. y: 0,
  45. x2: 0,
  46. y2: 1,
  47. colorStops: [
  48. {
  49. offset: 0,
  50. color: '#446bf5',
  51. },
  52. {
  53. offset: 1,
  54. color: '#2ca3e2',
  55. },
  56. ],
  57. globalCoord: false,
  58. },
  59. ], //波浪颜色
  60. backgroundStyle: {
  61. borderWidth: 1, //外边框
  62. color: 'RGBA(51, 66, 127, 0.7)',
  63. },
  64. label: {
  65. //标签设置
  66. position: ['50%', '45%'],
  67. formatter: '50%', //显示文本,
  68. textStyle: {
  69. // 修改字体大小,例如改为 20px
  70. fontSize: '20px',
  71. color: '#fff',
  72. },
  73. },
  74. outline: {
  75. borderDistance: 0,
  76. itemStyle: {
  77. borderWidth: 2,
  78. borderColor: '#112165',
  79. },
  80. },
  81. },
  82. ],
  83. });
  84. }
  85. }
  86. const initRAMDrop = () => {
  87. // 检查 DOM 元素是否存在
  88. if (chartRefRAM.value) {
  89. var value = 0.65;
  90. chartInstanceRAM = null
  91. chartInstanceRAM = echarts.init(chartRefRAM.value);
  92. chartInstanceRAM.setOption({
  93. series: [
  94. {
  95. type: 'liquidFill', //水位图
  96. radius: '100%', //显示比例
  97. center: ['50%', '50%'], //中心点
  98. amplitude: 20, //水波振幅
  99. data: [value, value], // data个数代表波浪数
  100. // 修改波浪颜色
  101. color: [
  102. {
  103. type: 'linear',
  104. x: 0,
  105. y: 0,
  106. x2: 0,
  107. y2: 1,
  108. colorStops: [
  109. {
  110. offset: 0,
  111. // 例如改成红色系
  112. color: '#ff4444',
  113. },
  114. {
  115. offset: 1,
  116. // 例如改成橙色系
  117. color: '#ff8800',
  118. },
  119. ],
  120. globalCoord: false,
  121. },
  122. ],
  123. backgroundStyle: {
  124. borderWidth: 1, //外边框
  125. color: 'RGBA(51, 66, 127, 0.7)',
  126. },
  127. label: {
  128. //标签设置
  129. position: ['50%', '45%'],
  130. // 修改 formatter 为函数,动态显示百分比
  131. formatter: () => `${Math.round(value * 100)}%`,
  132. textStyle: {
  133. // 修改字体大小,例如改为 20px
  134. fontSize: '20px',
  135. color: '#fff',
  136. },
  137. },
  138. outline: {
  139. borderDistance: 0,
  140. itemStyle: {
  141. borderWidth: 2,
  142. borderColor: '#112165',
  143. },
  144. },
  145. },
  146. ],
  147. });
  148. }
  149. }
  150. // 生命周期
  151. onMounted(() => {
  152. nextTick(() => {
  153. initCPUDrop()
  154. initRAMDrop()
  155. })
  156. });
  157. onUnmounted(() => {
  158. chartInstanceCPU.clear()
  159. chartInstanceRAM.clear()
  160. chartInstanceCPU = null
  161. chartInstanceRAM = null
  162. })
  163. // 窗口自适应
  164. window.addEventListener('resize', () => {
  165. chartInstanceRAM?.resize();
  166. chartInstanceCPU?.resize();
  167. });
  168. </script>
  169. <style lang="scss" scoped>
  170. ._runnin {
  171. display: flex;
  172. flex-direction: column;
  173. &_mains {
  174. flex: 1;
  175. margin: 30px;
  176. display: flex;
  177. align-items: center;
  178. justify-content: space-around;
  179. gap: 30px;
  180. &_item {
  181. display: flex;
  182. align-items: center;
  183. justify-content: center;
  184. flex-direction: column;
  185. color: #FFF;
  186. }
  187. }
  188. }
  189. </style>