lineEcharts.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="lineEchartsClass">
  3. <div class="titleBg">
  4. <div class="titleFont">驿站库存量</div>
  5. </div>
  6. <div
  7. class="divContent"
  8. style="
  9. display: flex;
  10. flex-direction: row;
  11. justify-content: space-around;
  12. align-items: center;
  13. "
  14. >
  15. <div ref="linechart" style="width: 100%; height: 90%"></div>
  16. </div>
  17. </div>
  18. </template>
  19. <script setup name="Index" lang="ts">
  20. import * as echarts from "echarts";
  21. import moment from "moment";
  22. const linechart = ref();
  23. import { bagCount } from "@/api/data";
  24. const drawEchart = (arryData, total) => {
  25. let echartsObj = echarts.init(linechart.value, "macarons");
  26. var dateArray = getRecentDays();
  27. var option = (option = {
  28. title: [
  29. {
  30. text: "总数",
  31. subtext: total + "",
  32. textStyle: {
  33. fontSize: 15,
  34. color: "#fff",
  35. },
  36. subtextStyle: {
  37. fontSize: 20,
  38. color: "#fff",
  39. },
  40. textAlign: "center",
  41. x: "48%",
  42. y: "35%",
  43. },
  44. ],
  45. series: [
  46. {
  47. name: "Access From",
  48. type: "pie",
  49. radius: ["40%", "70%"],
  50. labelLine: {
  51. // length2: 55,
  52. length: 15,
  53. length2: 85,
  54. lineStyle: {
  55. // type: "dashed",
  56. width: 2,
  57. },
  58. },
  59. label: {
  60. position: "outer",
  61. alignTo: "none",
  62. bleedMargin: 15,
  63. color: "#fff",
  64. formatter: " {b}\n{a|{c}}",
  65. padding: -85,
  66. rich: {
  67. a: {
  68. padding: [18, 0, 5, 0],
  69. fontSize: 14,
  70. color: "#fff",
  71. lineHeight: 20,
  72. },
  73. b: {
  74. padding: [18, 0, 5, 0],
  75. lineHeight: 20,
  76. },
  77. },
  78. },
  79. data: arryData,
  80. emphasis: {
  81. itemStyle: {
  82. shadowBlur: 10,
  83. shadowOffsetX: 0,
  84. shadowColor: "rgba(0, 0, 0, 0.5)",
  85. },
  86. },
  87. },
  88. ],
  89. });
  90. echartsObj.setOption(option);
  91. };
  92. const getRecentDays = () => {
  93. const oneDay = 24 * 60 * 60 * 1000; // 这里定义一天的毫秒数
  94. const resultArray = [];
  95. for (let i = 6; i >= 0; i--) {
  96. const currentDate = new Date(Date.now() - i * oneDay); // 计算出每天的日期
  97. const year = currentDate.getFullYear();
  98. const month = String(currentDate.getMonth() + 1).padStart(2, "0"); // 月份需要补零
  99. const day = String(currentDate.getDate()).padStart(2, "0"); // 日期也需要补零
  100. const formattedDate = `${month}-${day}`; // 格式化日期为 yyyy-mm-dd 的形式
  101. resultArray.push(formattedDate);
  102. }
  103. return resultArray;
  104. };
  105. const getbagCountData = () => {
  106. var param = {
  107. beginCreatedAt: moment().format("YYYY-MM-DD 00:00:00"),
  108. };
  109. var obj = {
  110. params: param,
  111. pageSize: 1000,
  112. };
  113. bagCount(obj).then((res) => {
  114. console.log(res);
  115. var rkCount = 0;
  116. var ckCount = 0;
  117. var ycCount = 0;
  118. var clCount = 0;
  119. var total = res.total;
  120. for (var index in res.rows) {
  121. if (res.rows[index].bagStatus == 0) {
  122. rkCount++;
  123. } else if (res.rows[index].bagStatus == 1) {
  124. ckCount++;
  125. } else if (res.rows[index].bagStatus == 2) {
  126. ycCount++;
  127. } else if (res.rows[index].bagStatus == 3) {
  128. clCount++;
  129. }
  130. }
  131. var arryData = [
  132. { value: rkCount, name: "入库" },
  133. { value: ckCount, name: "出库" },
  134. { value: ycCount, name: "异常" },
  135. { value: clCount, name: "已处理" },
  136. ];
  137. drawEchart(arryData, total);
  138. });
  139. };
  140. onMounted(() => {
  141. getbagCountData();
  142. });
  143. </script>
  144. <style scoped lang="scss">
  145. .lineEchartsClass {
  146. height: 28vh;
  147. min-width: 400px;
  148. .titleBg {
  149. background: url("@/assets/images/homeImages/titleBg.png") no-repeat;
  150. background-size: 100% 100%;
  151. }
  152. .titleFont {
  153. font-family: Source Han Sans CN, Source Han Sans CN;
  154. font-weight: 400;
  155. font-size: 18px;
  156. color: #ffffff;
  157. line-height: 4vh;
  158. text-shadow: 0px 4px 0px rgba(10, 40, 95, 0.69);
  159. text-align: left;
  160. font-style: normal;
  161. text-transform: none;
  162. margin-left: 2vw;
  163. letter-spacing: 5px;
  164. }
  165. .divContent {
  166. background: url("@/assets/images/homeImages/contentBg.png") no-repeat;
  167. background-size: 100% 100%;
  168. width: 20vw;
  169. height: 22vh;
  170. min-width: 400px;
  171. }
  172. }
  173. </style>