测试 用electron + springboot 构建桌面应用
he wei
2022-03-18 020c6ebe0c43b0a0cedb1b91b3520d223b3415c3
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
    <div class="e-chart-root" @dblclick="fullScreen" :class="{'full-screen': fullScreenState}">
        <div class="e-chart-container">
            <div class="e-chart" :id="id" :ref="id"></div>
            <object ref="resizeBox" tabindex="-1" type="text/html" aria-hidden='true' data="about:blank"
                class="resize-box"></object>
        </div>
    </div>
</template>
 
<script>
    // 引入 ECharts 主模块
    import ECharts from 'echarts'
 
    // 引入自定义主题
    import "./theme/transparent"
 
    export default {
        props: {
            id: {
                type: String,
                required: true,
            },
            name: {
                type: String,
                required: true,
            }
        },
        data() {
            return {
                fullScreenState: false,
            }
        },
        methods: {
            setOption(opt) {
                let geoJson = require(`../../../public/mapJson/${this.name}.json`);
                ECharts.registerMap('map', geoJson);
                // 整体配置项
                let option = {
                    tooltip: {
                        trigger: 'item',
                        formatter: function (params) {
                            if (params.componentSubType == "map") {
                                return ''
                            } else if (params.componentSubType == "scatter") {
                                return params.name;
                            }
                        }
                    },
                    visualMap: {
                        show: false,
                        min: 0,
                        max: 500,
                        left: 'left',
                        top: 'bottom',
                        text: ['高', '低'], // 文本,默认为数值文本
                        calculable: true,
                        seriesIndex: [1],
                        inRange: {}
                    },
                    geo: {
                        map: "map",
                        layoutCenter: ["55%", "50%"],
                        layoutSize: "100%",
                        label: {
                            normal: {
                                show: true,
                                textStyle: {
                                    color: '#fff'
                                }
                            },
                            emphasis: {
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        },
                        roam: true, //是否允许缩放
                        mapLocation: {
                            width: "110%",
                            height: "97%"
                        },
                        itemStyle: {
                            normal: {
                                borderColor: 'rgba(147, 235, 248, 1)',
                                borderWidth: 1,
                                areaColor: {
                                    type: 'radial',
                                    x: 0.5,
                                    y: 0.5,
                                    r: 0.8,
                                    colorStops: [{
                                        offset: 0,
                                        color: 'rgba(147, 235, 248, 0)' // 0% 处的颜色
                                    }, {
                                        offset: 1,
                                        color: 'rgba(147, 235, 248, .2)' // 100% 处的颜色
                                    }],
                                    globalCoord: false // 缺省为 false
                                },
                                shadowColor: 'rgba(128, 217, 248, 1)',
                                shadowOffsetX: -2,
                                shadowOffsetY: 2,
                                shadowBlur: 10
                            },
                            emphasis: {
                                areaColor: '#1ecee5',
                                borderWidth: 0,
                                label: {
                                    show: false
                                }
                            }
                        }
                    },
                    series: this.getSeries(opt)
                };
                // 设置配置项
                this.$G.chartManage.get(this.id).setOption(option);
            },
            getSeries(opt) {
                // 未配置series
                if (!opt || !opt.series) {
                    return [];
                }
                // 设置配置项
                let series = opt.series
                // 返回
                return series;
            },
            fullScreen() {
                this.fullScreenState = this.fullScreenState ? false : true;
                this.$nextTick(() => {
                    // 重置大小
                    this.$G.chartManage.get(this.id).resize();
                });
            },
            resize() {
                // 重置大小
                this.$G.chartManage.get(this.id).resize();
            }
        },
        mounted() {
            // 基于准备好的dom,初始化echarts实例
            let chart = ECharts.init(this.$refs[this.id], 'transparent');
            // 将图表添加到图表管理
            this.$G.chartManage.set(this.id, chart);
            // 容器大小发生变化
            this.$refs.resizeBox.contentDocument.defaultView.addEventListener('resize', () => {
                chart.resize();
            });
        }
    }
</script>
 
<style scoped>
    .e-chart-root,
    .e-chart-container,
    .e-chart {
        height: 100%;
        box-sizing: border-box;
    }
 
    .e-chart-root.full-screen .e-chart-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-size: 100% 100%;
        z-index: 9999;
    }
 
    .resize-box {
        display: block;
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100%;
        height: 100%;
        border: none;
        padding: 0px;
        margin: 0px;
        opacity: 0;
        z-index: -1000;
        pointer-events: none
    }
</style>