#
Junjie
2024-09-12 4f113d1862ee978e7d0756f31af79ad73b1dc6d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<script setup>
import { getCurrentInstance, ref, onMounted } from 'vue';
import { get, post } from '@/utils/request.js'
import * as echarts from "echarts";
const context = getCurrentInstance()?.appContext.config.globalProperties;
 
let chartPie = null;
const chartPieContainer = ref(null);
let chartLine = null;
const chartLineContainer = ref(null);
 
function getPieOptions() {
  post('/api/charts/loc/use', {}).then(resp => {
    let result = resp.data;
    if (result.code == 200) {
      let data = result.data;
 
      let pieOptions = {
        title: {
          text: '库位使用比例',
          left: 'center',
          top: '0%'
        },
        tooltip: {
          trigger: 'item',
          top: '0%'
        },
        grid: {
          top: '0%',
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        // legend: {
        //   orient: 'vertical',
        //   left: 'left'
        // },
        series: [
          {
            type: 'pie',
            radius: '70%',
            data: data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
 
      chartPie.setOption(pieOptions);
 
    }
  })
}
 
function getLineOptions() {
  post('/api/charts/loc/line', {}).then(resp => {
    let result = resp.data;
    if (result.code == 200) {
      let data = result.data;
 
      let lineOptions = {
        title: {
          text: '日出入库数量',
          left: 'center',
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['入库数量', '出库数量'],
          top: '10%'
        },
        grid: {
          top: '20%',
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: data.days
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '入库数量',
            type: 'line',
            data: data.in.value,
            smooth: true
          },
          {
            name: '出库数量',
            type: 'line',
            data: data.out.value,
            smooth: true
          }
        ]
      }
 
      console.log(lineOptions);
      
      chartLine.setOption(lineOptions);
 
    }
  })
}
 
function initChart() {
  chartPie = echarts.init(chartPieContainer.value);
  chartPie.setOption({
    type: Object,
    required: true
  })
 
  chartLine = echarts.init(chartLineContainer.value);
  chartLine.setOption({
    type: Object,
    required: true
  })
}
 
onMounted(() => {
  initChart()
  getPieOptions()
  getLineOptions()
})
 
</script>
 
<script>
export default {
  name: '主页'
}
</script>
 
<template>
  <div style="display: flex;">
    <div ref="chartPieContainer" style="width: 49%;height: 400px;"></div>
    <div ref="chartLineContainer" style="width: 49%;height: 400px;"></div>
    <!-- <EChartView ref="chartChild2" /> -->
  </div>
</template>