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. textStyle: {
  74. color: "#444",
  75. },
  76. },
  77. },
  78. ],
  79. yAxis: [
  80. {
  81. type: "value",
  82. name: "A",
  83. nameTextStyle: {
  84. color: "#444",
  85. },
  86. axisLabel: {
  87. formatter: "{value} ",
  88. },
  89. axisTick: {
  90. show: false,
  91. },
  92. axisLine: {
  93. show: false,
  94. lineStyle: {
  95. color: "#444",
  96. width: 1,
  97. type: "solid",
  98. },
  99. },
  100. splitLine: {
  101. lineStyle: {
  102. color: "#444",
  103. },
  104. },
  105. },
  106. ],
  107. series: [
  108. {
  109. name: "平均值",
  110. type: "bar",
  111. data: [20, 50, 80, 58, 83, 68, 57, 80, 42, 66],
  112. barWidth: 10, //柱子宽度
  113. barGap: 1, //柱子之间间距
  114. itemStyle: {
  115. normal: {
  116. color: "#5b82ee",
  117. opacity: 1,
  118. },
  119. },
  120. },
  121. {
  122. name: "95%",
  123. type: "bar",
  124. data: [50, 70, 60, 61, 75, 87, 60, 62, 86, 46],
  125. barWidth: 10,
  126. barGap: 1,
  127. itemStyle: {
  128. normal: {
  129. color: "#f2e251",
  130. opacity: 1,
  131. },
  132. },
  133. },
  134. {
  135. name: "最大值",
  136. type: "bar",
  137. data: [70, 48, 73, 68, 53, 47, 50, 72, 96, 86],
  138. barWidth: 10,
  139. barGap: 1,
  140. itemStyle: {
  141. normal: {
  142. color: "#fe8161",
  143. opacity: 1,
  144. },
  145. },
  146. },
  147. ],
  148. };
  149. interface WorksChartCardSetupData {
  150. t: (key: string | number) => string;
  151. loading: Ref<boolean>;
  152. worksChartRef: Ref;
  153. total: ComputedRef<number>;
  154. num: ComputedRef<number>;
  155. }
  156. export default defineComponent({
  157. name: "CurveCom",
  158. setup(): WorksChartCardSetupData {
  159. const store = useStore<{ Home: HomeStateType }>();
  160. const { t } = useI18n();
  161. // 总数
  162. const total = computed<number>(() => store.state.Home.worksChartData.total);
  163. // num
  164. const num = computed<number>(() => store.state.Home.worksChartData.num);
  165. // chart Data
  166. // const chartData = computed<ChartDataType>(
  167. // () => store.state.Home.worksChartData.chart
  168. // );
  169. // echarts 图表
  170. const worksChartRef = ref<HTMLDivElement>();
  171. const echarts = useEcharts(worksChartRef, worksChartOption);
  172. // watch([echarts, chartData], () => {
  173. // if (echarts.value) {
  174. // const option: EChartOption = {
  175. // xAxis: {
  176. // // data: ["03-01", "03-01", "03-01", "03-01", "03-01", "03-01", "03-01"]
  177. // data: chartData.value.day,
  178. // },
  179. // series: [
  180. // {
  181. // name: "新增",
  182. // // data: [3, 1, 1, 2, 2, 2, 2]
  183. // data: chartData.value.num,
  184. // },
  185. // ],
  186. // };
  187. // echarts.value.setOption(option);
  188. // }
  189. // });
  190. // 读取数据 func
  191. const loading = ref<boolean>(true);
  192. const getData = async () => {
  193. loading.value = true;
  194. await store.dispatch("Home/queryWorksChartData");
  195. loading.value = false;
  196. };
  197. onMounted(() => {
  198. getData();
  199. });
  200. return {
  201. t,
  202. loading,
  203. worksChartRef,
  204. total,
  205. num,
  206. };
  207. },
  208. });
  209. </script>
  210. <style lang="scss" scoped>
  211. .homeBoxCard {
  212. margin-bottom: 24px;
  213. ::v-deep(.el-card__header) {
  214. padding-left: 12px;
  215. padding-right: 12px;
  216. }
  217. ::v-deep(.el-card__body) {
  218. padding: 12px;
  219. font-size: 14px;
  220. line-height: 1.5715;
  221. }
  222. ::v-deep(.el-divider) {
  223. margin: 8px 0;
  224. }
  225. .num {
  226. font-size: 30px;
  227. color: #515a6e;
  228. }
  229. .height300 {
  230. height: 300px;
  231. }
  232. }
  233. </style>