curveCom.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div shadow="never" class="homeBoxCard" v-loading="loading">
  3. <div style="text-align:center">A相电流(A)</div>
  4. <div class="height300" ref="worksChartRef" />
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import {
  9. computed,
  10. defineComponent,
  11. onMounted,
  12. Ref,
  13. ref,
  14. watch,
  15. ComputedRef,
  16. } from "vue";
  17. import { useStore } from "vuex";
  18. import { useI18n } from "vue-i18n";
  19. import { EChartOption } from "echarts";
  20. import useEcharts from "@/composables/useEcharts";
  21. import { StateType as HomeStateType } from "../../home/store";
  22. // import { ChartDataType } from "../../data";
  23. const worksChartOption: EChartOption = {
  24. tooltip: {
  25. trigger: "axis",
  26. axisPointer: {
  27. type: "shadow",
  28. },
  29. },
  30. legend: {
  31. data: ["平均值", "95%", "最大值"],
  32. // align: 'right',
  33. right: 60,
  34. textStyle: {},
  35. itemWidth: 10,
  36. itemHeight: 10,
  37. itemGap: 35,
  38. },
  39. grid: {
  40. left: "3%",
  41. right: "4%",
  42. bottom: "3%",
  43. containLabel: true,
  44. },
  45. xAxis: [
  46. {
  47. type: "category",
  48. data: [
  49. "1次",
  50. "3次",
  51. "5次",
  52. "7次",
  53. "9次",
  54. "11次",
  55. "13次",
  56. "15次",
  57. "17次",
  58. "19次 ",
  59. ],
  60. axisLine: {
  61. show: true,
  62. lineStyle: {
  63. color: "#444",
  64. width: 1,
  65. type: "solid",
  66. },
  67. },
  68. axisTick: {
  69. show: false,
  70. },
  71. axisLabel: {
  72. show: true,
  73. color: "#444",
  74. },
  75. },
  76. ],
  77. yAxis: [
  78. {
  79. type: "value",
  80. name: "A",
  81. nameTextStyle: {
  82. color: "#444",
  83. },
  84. axisLabel: {
  85. formatter: "{value} ",
  86. },
  87. axisTick: {
  88. show: false,
  89. },
  90. axisLine: {
  91. show: false,
  92. lineStyle: {
  93. color: "#444",
  94. width: 1,
  95. type: "solid",
  96. },
  97. },
  98. splitLine: {
  99. lineStyle: {
  100. color: "#444",
  101. },
  102. },
  103. },
  104. ],
  105. series: [
  106. {
  107. name: "平均值",
  108. type: "bar",
  109. data: [20, 50, 80, 58, 83, 68, 57, 80, 42, 66],
  110. barWidth: 10, //柱子宽度
  111. barGap: '1', //柱子之间间距
  112. itemStyle: {
  113. normal: {
  114. color: "#5b82ee",
  115. opacity: 1,
  116. },
  117. },
  118. },
  119. {
  120. name: "95%",
  121. type: "bar",
  122. data: [50, 70, 60, 61, 75, 87, 60, 62, 86, 46],
  123. barWidth: 10,
  124. barGap: '1',
  125. itemStyle: {
  126. normal: {
  127. color: "#f2e251",
  128. opacity: 1,
  129. },
  130. },
  131. },
  132. {
  133. name: "最大值",
  134. type: "bar",
  135. data: [70, 48, 73, 68, 53, 47, 50, 72, 96, 86],
  136. barWidth: 10,
  137. barGap: '1',
  138. itemStyle: {
  139. normal: {
  140. color: "#fe8161",
  141. opacity: 1,
  142. },
  143. },
  144. },
  145. ],
  146. };
  147. interface WorksChartCardSetupData {
  148. t: (key: string | number) => string;
  149. loading: Ref<boolean>;
  150. worksChartRef: Ref;
  151. total: ComputedRef<number>;
  152. num: ComputedRef<number>;
  153. }
  154. export default defineComponent({
  155. name: "CurveCom",
  156. setup(): WorksChartCardSetupData {
  157. const store = useStore<{ Home: HomeStateType }>();
  158. const { t } = useI18n();
  159. // 总数
  160. const total = computed<number>(() => store.state.Home.worksChartData.total);
  161. // num
  162. const num = computed<number>(() => store.state.Home.worksChartData.num);
  163. // chart Data
  164. // const chartData = computed<ChartDataType>(
  165. // () => store.state.Home.worksChartData.chart
  166. // );
  167. // echarts 图表
  168. const worksChartRef = ref<HTMLDivElement>();
  169. const echarts = useEcharts(worksChartRef, worksChartOption);
  170. // watch([echarts, chartData], () => {
  171. // if (echarts.value) {
  172. // const option: EChartOption = {
  173. // xAxis: {
  174. // // data: ["03-01", "03-01", "03-01", "03-01", "03-01", "03-01", "03-01"]
  175. // data: chartData.value.day,
  176. // },
  177. // series: [
  178. // {
  179. // name: "新增",
  180. // // data: [3, 1, 1, 2, 2, 2, 2]
  181. // data: chartData.value.num,
  182. // },
  183. // ],
  184. // };
  185. // echarts.value.setOption(option);
  186. // }
  187. // });
  188. // 读取数据 func
  189. const loading = ref<boolean>(true);
  190. const getData = async () => {
  191. loading.value = true;
  192. await store.dispatch("Home/queryWorksChartData");
  193. loading.value = false;
  194. };
  195. onMounted(() => {
  196. getData();
  197. });
  198. return {
  199. t,
  200. loading,
  201. worksChartRef,
  202. total,
  203. num,
  204. };
  205. },
  206. });
  207. </script>
  208. <style lang="scss" scoped>
  209. .homeBoxCard {
  210. margin-bottom: 24px;
  211. ::v-deep(.el-card__header) {
  212. padding-left: 12px;
  213. padding-right: 12px;
  214. }
  215. ::v-deep(.el-card__body) {
  216. padding: 12px;
  217. font-size: 14px;
  218. line-height: 1.5715;
  219. }
  220. ::v-deep(.el-divider) {
  221. margin: 8px 0;
  222. }
  223. .num {
  224. font-size: 30px;
  225. color: #515a6e;
  226. }
  227. .height300 {
  228. height: 300px;
  229. }
  230. }
  231. </style>