longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<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 isCDSH = this.$CFG.clientName.name == 'cdsh';
      let name = isCDSH ? "chengdushihua" : this.name;
      let geoJson = require(`../../../public/mapJson/${name}.json`);
      ECharts.registerMap("map", geoJson);
      let areaList = geoJson.features || [];
      let data0 = [];
      if (isCDSH) {
        areaList.forEach((v) => {
          data0.push({
            name: v.properties.name,
            // value: Math.floor(Math.random() * 6) * 20,
            value: v.properties.value,
          });
        });
      }
      let series0 = {
        name: "MAP",
        type: "map",
        mapType: "map",
        selectedMode: "false", //是否允许选中多个区域
        label: {
          normal: {
            show: true,
          },
          emphasis: {
            show: true,
          },
        },
        geoIndex: 0,
        data: data0,
        zlevel: 1,
      };
      // 整体配置项
      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: {},
          type: "continuous",
          text: ["", ""],
          showLabel: true,
          left: "50",
          min: 0,
          max: 100,
          inRange: {
            // color: ['#A9D1F2', '#66B7EF', '#66B7EF', '#2F84B5', '#225398']
            color: ['#BAC9B2', '#D4D6ED', '#E1C9BD', '#F5F0BE', '#B8A4D2']
          },
          splitNumber: 0,
        },
        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),
      };
      if (isCDSH) {
        option.series.unshift(series0);
      }
      // 设置配置项
      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>