123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- <template>
- <div :style="styleObj">
- <v-chart ref="myVChart" :options="options" autoresize/>
- </div>
- </template>
- <script>
- import {targetWidgetLinkageLogic} from "@/views/bigScreenDesigner/designer/linkageLogic";
- import "../../../../../../node_modules/echarts/map/js/china.js";
- import "../../../../../../node_modules/echarts/map/js/world.js";
- import "../../../../../../node_modules/echarts/map/js/province/anhui";
- import "../../../../../../node_modules/echarts/map/js/province/aomen";
- import "../../../../../../node_modules/echarts/map/js/province/beijing";
- import "../../../../../../node_modules/echarts/map/js/province/chongqing";
- import "../../../../../../node_modules/echarts/map/js/province/fujian";
- import "../../../../../../node_modules/echarts/map/js/province/gansu";
- import "../../../../../../node_modules/echarts/map/js/province/guangxi";
- import "../../../../../../node_modules/echarts/map/js/province/guizhou";
- import "../../../../../../node_modules/echarts/map/js/province/hainan";
- import "../../../../../../node_modules/echarts/map/js/province/hebei";
- import "../../../../../../node_modules/echarts/map/js/province/heilongjiang";
- import "../../../../../../node_modules/echarts/map/js/province/henan";
- import "../../../../../../node_modules/echarts/map/js/province/hubei";
- import "../../../../../../node_modules/echarts/map/js/province/hunan";
- import "../../../../../../node_modules/echarts/map/js/province/jiangsu";
- import "../../../../../../node_modules/echarts/map/js/province/jiangxi";
- import "../../../../../../node_modules/echarts/map/js/province/jilin";
- import "../../../../../../node_modules/echarts/map/js/province/liaoning";
- import "../../../../../../node_modules/echarts/map/js/province/neimenggu";
- import "../../../../../../node_modules/echarts/map/js/province/ningxia";
- import "../../../../../../node_modules/echarts/map/js/province/qinghai";
- import "../../../../../../node_modules/echarts/map/js/province/shandong";
- import "../../../../../../node_modules/echarts/map/js/province/shanghai";
- import "../../../../../../node_modules/echarts/map/js/province/shanxi";
- import "../../../../../../node_modules/echarts/map/js/province/shanxi1";
- import "../../../../../../node_modules/echarts/map/js/province/sichuan";
- import "../../../../../../node_modules/echarts/map/js/province/taiwan";
- import "../../../../../../node_modules/echarts/map/js/province/tianjin";
- import "../../../../../../node_modules/echarts/map/js/province/xianggang";
- import "../../../../../../node_modules/echarts/map/js/province/xinjiang";
- import "../../../../../../node_modules/echarts/map/js/province/xizang";
- import "../../../../../../node_modules/echarts/map/js/province/yunnan";
- import "../../../../../../node_modules/echarts/map/js/province/zhejiang";
- import "echarts/map/js/china.js";
- import echarts from "echarts";
- import {conversionCity} from "@/utils/china";
- let geoCoordMap = conversionCity;
- let planePath =
- "path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z";
- export default {
- name: "widgetLineMap",
- props: {
- value: Object,
- ispreview: Boolean,
- },
- data() {
- return {
- options: {
- title: {
- left: "center",
- textStyle: {
- color: "#fff",
- },
- },
- tooltip: {
- trigger: "item",
- formatter: function (params, ticket, callback) {
- if (params.seriesType == "effectScatter") {
- return "线路:" + params.data.name + "" + params.data.value[2];
- } else if (params.seriesType == "lines") {
- return (
- params.data.fromName +
- ">" +
- params.data.toName +
- "<br />" +
- params.data.value
- );
- } else {
- return params.name;
- }
- },
- },
- legend: {
- show: true,
- orient: "vertical",
- top: "bottom",
- left: "right",
- textStyle: {
- color: "#fff",
- },
- selectedMode: "multiple",
- },
- geo: {
- map: "china",
- label: {
- emphasis: {
- show: true,
- color: "white",
- },
- },
- roam: true,
- itemStyle: {
- normal: {
- borderColor: new echarts.graphic.LinearGradient(
- 0,
- 0,
- 0,
- 1,
- [
- {
- offset: 0,
- color: "#00F6FF",
- },
- {
- offset: 1,
- color: "#53D9FF",
- },
- ],
- false
- ),
- borderWidth: 1,
- shadowColor: "rgba(10,76,139,1)",
- shadowOffsetY: 0,
- shadowBlur: 60,
- },
- },
- },
- series: [
- {
- type: "lines",
- zlevel: 1,
- effect: {
- show: false,
- period: 6,
- trailLength: 0.7,
- color: "#fff",
- symbolSize: 3,
- },
- lineStyle: {
- normal: {
- color: "#a6c84c",
- width: 0,
- curveness: 0.2,
- },
- },
- data: [],
- },
- {
- type: "lines",
- zlevel: 2,
- symbol: ["none", "arrow"],
- symbolSize: 10,
- effect: {
- show: true,
- period: 4,
- trailLength: 0,
- symbol: "arrow",
- symbolSize: 5,
- },
- lineStyle: {
- normal: {
- // 颜色+ 线条
- color: "#ffa022",
- width: 1,
- opacity: 0.4,
- curveness: 0.2,
- },
- },
- data: [],
- },
- {
- // 起点
- type: "effectScatter",
- coordinateSystem: "geo",
- zlevel: 2,
- rippleEffect: {
- brushType: "stroke",
- },
- label: {
- normal: {
- show: true,
- position: "right",
- formatter: "{b}",
- fontSize: 22,
- },
- },
- // 点的大小
- symbolSize: 10,
- itemStyle: {
- normal: {
- // 地图点颜色
- color: "#46bee9",
- },
- },
- data: [],
- },
- {
- // 终点
- type: "effectScatter",
- coordinateSystem: "geo",
- zlevel: 2,
- rippleEffect: {
- brushType: "stroke",
- },
- label: {
- normal: {
- show: true,
- position: "right",
- formatter: "{b}",
- fontSize: 22,
- },
- },
- // 点的大小
- symbolSize: 10,
- itemStyle: {
- normal: {
- // 地图点颜色
- color: "#46bee9",
- },
- },
- data: [],
- },
- ],
- },
- optionsSetup: {},
- flagInter: null,
- };
- },
- computed: {
- styleObj() {
- return {
- position: this.ispreview ? "absolute" : "static",
- width: this.optionsStyle.width + "px",
- height: this.optionsStyle.height + "px",
- left: this.optionsStyle.left + "px",
- top: this.optionsStyle.top + "px",
- background: this.optionsSetup.background,
- };
- },
- allComponentLinkage() {
- return this.$store.state.designer.allComponentLinkage;
- },
- },
- watch: {
- value: {
- handler(val) {
- this.optionsStyle = val.position;
- this.optionsData = val.data;
- this.optionsSetup = val.setup;
- this.editorOptions();
- },
- deep: true,
- },
- },
- created() {
- this.optionsStyle = this.value.position;
- this.optionsData = this.value.data;
- this.optionsSetup = this.value.setup;
- },
- mounted() {
- this.editorOptions();
- targetWidgetLinkageLogic(this); // 联动-目标组件逻辑
- },
- methods: {
- convertData(data) {
- let res = [];
- for (let i = 0; i < data.length; i++) {
- let dataItem = data[i];
- let sourceCoord = geoCoordMap[dataItem.source];
- let targetCoord = geoCoordMap[dataItem.target];
- if (sourceCoord && targetCoord) {
- res.push({
- fromName: dataItem.source,
- toName: dataItem.target,
- coords: [sourceCoord, targetCoord],
- value: dataItem.value,
- });
- }
- }
- return res;
- },
- editorOptions() {
- this.setOptionsTitle();
- this.setOptionsGeo();
- this.setOptionsSource();
- this.setOptionsTarget();
- this.setOptionsSymbol();
- this.setOptionsLine();
- this.setOptionsTooltip();
- this.setOptionsData();
- },
- // 标题设置
- setOptionsTitle() {
- const optionsSetup = this.optionsSetup;
- const title = {
- text: optionsSetup.text,
- show: optionsSetup.isShowTitle,
- left: optionsSetup.titleLeft,
- top: optionsSetup.titleTop + "%",
- itemGap: optionsSetup.titleItemGap,
- textStyle: {
- color: optionsSetup.textColor,
- fontSize: optionsSetup.textFontSize,
- fontWeight: optionsSetup.textFontWeight,
- fontStyle: optionsSetup.textFontStyle,
- fontFamily: optionsSetup.textFontFamily,
- },
- subtext: optionsSetup.subtext,
- subtextStyle: {
- color: optionsSetup.subtextColor,
- fontWeight: optionsSetup.subtextFontWeight,
- fontSize: optionsSetup.subtextFontSize,
- fontStyle: optionsSetup.subtextFontStyle,
- fontFamily: optionsSetup.subtextFontFamily
- },
- };
- this.options.title = title;
- },
- // 地图设置
- setOptionsGeo() {
- const optionsSetup = this.optionsSetup;
- const geo = {
- map: this.optionsSetup.mapName == '' ? "china" : this.optionsSetup.mapName,
- show: true,
- roam: true,
- layoutSize: "80%",
- label: {
- //调整数值
- // 地图省市区显隐
- show: optionsSetup.isShowMap,
- color: optionsSetup.fontColor,
- fontSize: optionsSetup.fontSize,
- fontWeight: optionsSetup.fontWeight,
- fontStyle: optionsSetup.fontStyle,
- fontFamily: optionsSetup.fontFamily,
- },
- itemStyle: {
- normal: {
- //地图块颜色
- areaColor: {
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [
- {
- offset: 0,
- color: optionsSetup.fontColor0, // 0% 处的颜色
- },
- {
- offset: 1,
- color: optionsSetup.fontColor100, // 100% 处的颜色
- },
- ],
- },
- borderType: optionsSetup.borderType,
- borderColor: optionsSetup.borderColor,
- borderWidth: optionsSetup.borderWidth,
- shadowColor: optionsSetup.shadowColor,
- shadowBlur: optionsSetup.shadowBlur,
- opacity: optionsSetup.opacity / 100,
- },
- },
- //鼠标放置颜色加深
- emphasis: {
- label: {
- show: optionsSetup.isShowEmphasisLabel,
- color: optionsSetup.emphasisLabelFontColor,
- fontSize: optionsSetup.emphasisLabelFontSize,
- fontWeight: optionsSetup.emphasisLabelFontWeight,
- fontStyle: optionsSetup.emphasisLabelFontStyle,
- fontFamily: optionsSetup.emphasisLabelFontFamily,
- },
- itemStyle: {
- areaColor: {
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [
- {
- offset: 0,
- color: optionsSetup.emphasisLabelFontColor0, // 0% 处的颜色
- },
- {
- offset: 1,
- color: optionsSetup.emphasisLabelFontColor100, // 100% 处的颜色
- },
- ],
- },
- },
- },
- }
- this.options.geo = geo;
- },
- // 起点设置
- setOptionsSource() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[2];
- const normal = {
- show: optionsSetup.isShowSource,
- position: optionsSetup.sourceFontPosition,
- color: optionsSetup.sourceFontColor,
- fontSize: optionsSetup.sourceFontSize,
- fontWeight: optionsSetup.sourceFontWeight,
- fontStyle: optionsSetup.sourceFontStyle,
- fontFamily: optionsSetup.sourceFontFamily
- };
- const itemStyle = {
- normal: {
- color: optionsSetup.sourcePointColor,
- },
- };
- series.symbolSize = optionsSetup.sourceSymbolSize;
- series.label.normal = normal;
- series.itemStyle = itemStyle;
- },
- // 终点设置
- setOptionsTarget() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[3];
- const normal = {
- show: optionsSetup.isShowTarget,
- position: optionsSetup.targetFontPosition,
- color: optionsSetup.targetFontColor,
- fontSize: optionsSetup.targetFontSize,
- fontWeight: optionsSetup.targetFontWeight,
- fontStyle: optionsSetup.sourceFontStyle,
- fontFamily: optionsSetup.sourceFontFamily
- };
- const itemStyle = {
- normal: {
- color: optionsSetup.targetPointColor,
- },
- };
- series.symbolSize = optionsSetup.targetSymbolSize;
- series.label.normal = normal;
- series.itemStyle = itemStyle;
- },
- // 图标设置
- setOptionsSymbol() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[1];
- const effect = {
- show: true,
- period: this.setPeriod(optionsSetup),
- trailLength: 0,
- symbol: this.setSymbol(optionsSetup),
- symbolSize: optionsSetup.symbolSize,
- color: optionsSetup.symbolColor,
- };
- series["effect"] = effect;
- },
- setSymbol(optionsSetup) {
- let symbol;
- if (optionsSetup.symbol == "plane") {
- symbol = planePath;
- } else {
- symbol = "arrow";
- }
- return symbol;
- },
- setPeriod(optionsSetup) {
- let period;
- if (optionsSetup.symbol == "plane") {
- period = optionsSetup.symbolPeriod - 1;
- } else {
- period = optionsSetup.symbolPeriod;
- }
- return period;
- },
- // 线设置
- setOptionsLine() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[1];
- const lineStyle = {
- normal: {
- // 线条颜色
- color: optionsSetup.lineColor,
- width: optionsSetup.lineWidth,
- opacity: 0.4,
- curveness: 0.2,
- },
- };
- series["lineStyle"] = lineStyle;
- },
- // tooltip 设置
- setOptionsTooltip() {
- const optionsSetup = this.optionsSetup;
- const tooltip = {
- trigger: "item",
- show: optionsSetup.isShowTooltip,
- textStyle: {
- color: optionsSetup.tooltipColor,
- fontSize: optionsSetup.tooltipFontSize,
- fontWeight: optionsSetup.tooltipFontWeight,
- fontStyle: optionsSetup.tooltipFontStyle,
- fontFamily: optionsSetup.tooltipFontFamily,
- },
- formatter: function (params, ticket, callback) {
- if (params.seriesType == "effectScatter") {
- return "线路:" + params.data.name + "" + params.data.value[2];
- } else if (params.seriesType == "lines") {
- return (
- params.data.fromName +
- ">" +
- params.data.toName +
- "<br />" +
- params.data.value
- );
- } else {
- return params.name;
- }
- },
- };
- this.options.tooltip = tooltip;
- },
- //数据解析
- setOptionsData(e, paramsConfig) {
- const optionsData = this.optionsData; // 数据类型 静态 or 动态
- // 联动接收者逻辑开始
- optionsData.dynamicData = optionsData.dynamicData || {}; // 兼容 dynamicData undefined
- const myDynamicData = optionsData.dynamicData;
- clearInterval(this.flagInter); // 不管咋,先干掉上一次的定时任务,避免多跑
- if (
- e &&
- optionsData.dataType !== "staticData" &&
- Object.keys(myDynamicData.contextData).length
- ) {
- const keyArr = Object.keys(myDynamicData.contextData);
- paramsConfig.forEach((conf) => {
- if (keyArr.includes(conf.targetKey)) {
- myDynamicData.contextData[conf.targetKey] = e[conf.originKey];
- }
- });
- }
- // 联动接收者逻辑结束
- optionsData.dataType == "staticData"
- ? this.staticDataFn(optionsData.staticData)
- : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
- },
- staticDataFn(val) {
- const series = this.options.series;
- series[0]["data"] = this.convertData(val);
- series[1]["data"] = this.convertData(val);
- series[2]["data"] = val.map(function (dataItem) {
- if (geoCoordMap[dataItem.source] && geoCoordMap[dataItem.target]) {
- return {
- name: dataItem.source,
- value: geoCoordMap[dataItem.source].concat([dataItem.value]),
- };
- }
- });
- series[3]["data"] = val.map(function (dataItem) {
- if (geoCoordMap[dataItem.source] && geoCoordMap[dataItem.target]) {
- return {
- name: dataItem.target,
- value: geoCoordMap[dataItem.target].concat([dataItem.value]),
- };
- }
- });
- },
- dynamicDataFn(val, refreshTime) {
- if (!val) return;
- if (this.ispreview) {
- this.getEchartData(val);
- this.flagInter = setInterval(() => {
- this.getEchartData(val);
- }, refreshTime);
- } else {
- this.getEchartData(val);
- }
- },
- getEchartData(val) {
- const data = this.queryEchartsData(val);
- data.then((res) => {
- this.renderingFn(res);
- });
- },
- renderingFn(val) {
- const series = this.options.series;
- series[0]["data"] = this.convertData(val);
- series[1]["data"] = this.convertData(val);
- series[2]["data"] = val.map(function (dataItem) {
- if (geoCoordMap[dataItem.source] && geoCoordMap[dataItem.target]) {
- return {
- name: dataItem.source,
- value: geoCoordMap[dataItem.source].concat([dataItem.value]),
- };
- }
- });
- series[3]["data"] = val.map(function (dataItem) {
- if (geoCoordMap[dataItem.source] && geoCoordMap[dataItem.target]) {
- return {
- name: dataItem.target,
- value: geoCoordMap[dataItem.target].concat([dataItem.value]),
- };
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .echartMap {
- width: 100%;
- height: 100%;
- }
- .echarts {
- width: 100%;
- height: 100%;
- overflow: hidden;
- }
- </style>
|