Commit 0d342b95 authored by 吕超's avatar 吕超

feat: 模块二添加子类选择,动态生成颜色段

parent 07bd3ec6
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
</div> --> </div> -->
<div class="item"> <div class="item">
<div class="circle" :style="{ 'background-color': item }"></div> <div class="circle" :style="{ 'background-color': item }"></div>
<label <label>
>{{ range[index - 1] }} {{ getCode(index) }} {{ showLabel(range[index - 1], range[index]) }}
{{ range[index] }}</label </label>
>
</div> </div>
</div> </div>
</template> </template>
...@@ -24,33 +23,35 @@ ...@@ -24,33 +23,35 @@
<script> <script>
export default { export default {
data() { data() {
return {} return {};
}, },
props: { props: {
title: { title: {
type: String type: String,
}, },
colors: { colors: {
type: Array type: Array,
}, },
range: { range: {
type: Array type: Array,
} },
}, },
computed: { computed: {
getCode() { showLabel() {
return function (index) { return function (min, max) {
if (index === 0) { if (max && min) {
return '<' return `${min} - ${max}`;
} }
if (index === this.colors.length - 1) { if (max && !min) {
return '>' return `< ${max}`;
} }
return '-' if (!max && min) {
} return `${min} <`;
} }
} };
} },
},
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
...@@ -73,7 +74,7 @@ export default { ...@@ -73,7 +74,7 @@ export default {
.item { .item {
display: flex; display: flex;
align-items: center; align-items: center;
margin-bottom: .3vh; margin-bottom: 0.3vh;
.circle { .circle {
border-radius: 2px; border-radius: 2px;
width: 30px; width: 30px;
......
...@@ -16,34 +16,34 @@ ...@@ -16,34 +16,34 @@
<script> <script>
// #144683 // #144683
export default { export default {
name: 'statusControl', name: "statusControl",
props: { props: {
list: { list: {
type: Array, type: Array,
default: function () { default: function () {
return [] return [];
} },
}, },
statusStyle: { statusStyle: {
type: [Object, String], type: [Object, String],
default: '' default: "",
}, },
value: { value: {
type: Object, type: Object,
default: function () { default: function () {
return {} return {};
} },
} },
}, },
data() { data() {
return {} return {};
}, },
methods: { methods: {
onStatusChange(item) { onStatusChange(item) {
this.$emit('input', item) this.$emit("input", item);
} },
} },
} };
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
...@@ -52,7 +52,7 @@ export default { ...@@ -52,7 +52,7 @@ export default {
margin-bottom: 10px; margin-bottom: 10px;
border-radius: 15px; border-radius: 15px;
padding: 5px 10px; padding: 5px 10px;
width: 130px; width: 170px;
color: #84c6ff; color: #84c6ff;
// background-color: #fff; // background-color: #fff;
box-shadow: 0 0 5px #fff9; box-shadow: 0 0 5px #fff9;
...@@ -60,7 +60,6 @@ export default { ...@@ -60,7 +60,6 @@ export default {
cursor: pointer; cursor: pointer;
border: 1px solid #84c6ff; border: 1px solid #84c6ff;
&.acitive { &.acitive {
color: #fff; color: #fff;
background-color: #16ceaf; background-color: #16ceaf;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<script> <script>
import Map from "@/components/Map/Map.vue"; import Map from "@/components/Map/Map.vue";
import { BiomassData } from "../config/biomass.config.js"; import { BiomassData } from "../config/biomass.config.js";
import { color, colorLabel } from "../config/legend.config"; import { color } from "../config/legend.config";
import { mapGetters } from "vuex"; import { mapGetters } from "vuex";
export default { export default {
name: "biogasManure", name: "biogasManure",
...@@ -16,6 +16,14 @@ export default { ...@@ -16,6 +16,14 @@ export default {
type: String, type: String,
default: "", default: "",
}, },
itemType: {
type: String,
default: "",
},
colorLabels: {
type: Array,
default: () => [],
},
data: { data: {
type: Array, type: Array,
default: () => [], default: () => [],
...@@ -36,7 +44,7 @@ export default { ...@@ -36,7 +44,7 @@ export default {
computed: { computed: {
getFilterColor() { getFilterColor() {
const obj = BiomassData[this.type].find( const obj = BiomassData[this.type].find(
(item) => item.type === "aggregation" (item) => item.key === this.itemType
); );
const filterCon = ["match", ["get", "code"]]; const filterCon = ["match", ["get", "code"]];
this.data.forEach((item) => { this.data.forEach((item) => {
...@@ -63,11 +71,11 @@ export default { ...@@ -63,11 +71,11 @@ export default {
this.setPaintColor(); this.setPaintColor();
}, },
getCurrentColor(val) { getCurrentColor(val) {
if (val > colorLabel[colorLabel.length - 1]) { if (val > this.colorLabels[this.colorLabels.length - 1]) {
return color[color.length - 1]; return color[color.length - 1];
} else { } else {
let idx = -1; let idx = -1;
colorLabel.find((item, index) => { this.colorLabels.find((item, index) => {
idx = index; idx = index;
return item >= val; return item >= val;
}); });
...@@ -103,6 +111,9 @@ export default { ...@@ -103,6 +111,9 @@ export default {
type() { type() {
this.setPaintColor(); this.setPaintColor();
}, },
itemType() {
this.setPaintColor();
},
data() { data() {
this.setPaintColor(); this.setPaintColor();
}, },
......
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
computed: { computed: {
// 返回当前类型除了总数的信息 // 返回当前类型除了总数的信息
getItemOfType() { getItemOfType() {
return BiomassData[this.type].filter((item) => !/_local$/.test(item.key)); return BiomassData[this.type].filter((item) => !item.type);
}, },
getValOfdata() { getValOfdata() {
const keys = this.getItemOfType; const keys = this.getItemOfType;
......
export const color = [ export const color = [
"#7e82d0", "#7e82d0",
"#818bd4", // "#818bd4",
"#8492d7", "#8492d7",
"#869adb", // "#869adb",
"#89a1de", "#89a1de",
"#8dabe2", // "#8dabe2",
"#95c1e2", "#95c1e2",
"#9bcfe2", // "#9bcfe2",
"#a3e4e3", "#a3e4e3",
]; ];
export const colorLabel = [1, 3, 5, 10, 30, 50, 100, 500]; // export const colorLabel = [1, 3, 5, 10, 30, 50, 100, 500];
export const colorLabel = [1, 30, 50, 100];
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
<LeftPart :type="statusValue.key"></LeftPart> <LeftPart :type="statusValue.key"></LeftPart>
<BiogasManureMap <BiogasManureMap
:type="statusValue.key" :type="statusValue.key"
:itemType="allItemValue.key"
:colorLabels="getRandomColorLabel"
:data="data" :data="data"
:provinceCode="provinceCode" :provinceCode="provinceCode"
></BiogasManureMap> ></BiogasManureMap>
...@@ -26,7 +28,20 @@ ...@@ -26,7 +28,20 @@
</div> </div>
</PartWrap> </PartWrap>
</div> </div>
<Legend class="legendPart" :colors="color" :range="colorLabel"></Legend> <StatusControl
:statusStyle="{
position: 'absolute',
right: '27.7vw',
bottom: '30.5vh',
}"
:list="getAllItemOfType"
v-model="allItemValue"
></StatusControl>
<Legend
class="legendPart"
:colors="color"
:range="getRandomColorLabel"
></Legend>
</div> </div>
</template> </template>
...@@ -59,6 +74,7 @@ export default { ...@@ -59,6 +74,7 @@ export default {
color, color,
colorLabel, colorLabel,
provinceCode: "", provinceCode: "",
allItemValue: { key: "gn_local", value: "数量(处)" },
}; };
}, },
components: { components: {
...@@ -73,10 +89,13 @@ export default { ...@@ -73,10 +89,13 @@ export default {
}, },
computed: { computed: {
getItemOfType() { getItemOfType() {
return BiomassData[this.statusValue.key].find((item) => return BiomassData[this.statusValue.key].find(
/_local$/.test(item.key) (item) => item.type === "aggregation"
); );
}, },
getAllItemOfType() {
return BiomassData[this.statusValue.key];
},
getValOfdata() { getValOfdata() {
const res = { const res = {
[this.getItemOfType.key]: [], [this.getItemOfType.key]: [],
...@@ -94,7 +113,7 @@ export default { ...@@ -94,7 +113,7 @@ export default {
return function (type) { return function (type) {
const data = this.getValOfdata[type] const data = this.getValOfdata[type]
.filter((item) => item.yAxis) .filter((item) => item.yAxis)
.sort((a, b) => b.xAxis - a.xAxis); .sort((a, b) => b.yAxis - a.yAxis);
const xData = data.map((item) => item.xAxis); const xData = data.map((item) => item.xAxis);
const yData = data.map((item) => item.yAxis); const yData = data.map((item) => item.yAxis);
const option = { const option = {
...@@ -113,11 +132,11 @@ export default { ...@@ -113,11 +132,11 @@ export default {
yAxis: [ yAxis: [
{ {
type: "value", type: "value",
splitLine: { // splitLine: {
lineStyle: { // lineStyle: {
color: "rgba(255,255,255,.15)", // color: "rgba(255,255,255,.15)",
}, // },
}, // },
axisLine: { axisLine: {
lineStyle: { lineStyle: {
color: "#fff", color: "#fff",
...@@ -143,7 +162,7 @@ export default { ...@@ -143,7 +162,7 @@ export default {
], ],
series: [ series: [
{ {
name: "入侵报告次数", name: "",
type: "bar", type: "bar",
barWidth: `50%`, barWidth: `50%`,
data: yData, data: yData,
...@@ -152,9 +171,9 @@ export default { ...@@ -152,9 +171,9 @@ export default {
position: "top", position: "top",
}, },
itemStyle: { itemStyle: {
emphasis: { // emphasis: {
color: "rgba(201,59,60)", // color: "rgba(201,59,60)",
}, // },
}, },
}, },
], ],
...@@ -162,11 +181,33 @@ export default { ...@@ -162,11 +181,33 @@ export default {
return option; return option;
}; };
}, },
// 获取所有值
getRandomLabel() {
const obj = BiomassData[this.statusValue.key].find(
(item) => item.key === this.allItemValue.key
);
const res = [];
this.data.forEach((item) => {
res.push(item.properties[obj.key]);
});
return [...new Set(res)].filter((item) => item).sort((a, b) => a - b);
},
// 根据值生产颜色段
getRandomColorLabel() {
const labels = this.getRandomLabel;
const min = labels[0];
const max = labels[labels.length - 1];
const colorLabels = [];
const part = (max - min) / 4;
for (let i = 1; i <= 4; i++) {
colorLabels.push(Number((part * i - 1).toFixed(4)));
}
return colorLabels;
},
...mapGetters(["getMsgOfProvince"]), ...mapGetters(["getMsgOfProvince"]),
}, },
created() { created() {
this.getEnergyWarm(); this.getEnergyWarm();
console.log(this.getMsgOfProvince("14"));
}, },
methods: { methods: {
getEnergyWarm() { getEnergyWarm() {
...@@ -184,6 +225,14 @@ export default { ...@@ -184,6 +225,14 @@ export default {
code && (this.provinceCode = code); code && (this.provinceCode = code);
}, },
}, },
watch: {
statusValue: {
handler(val) {
this.allItemValue = BiomassData[val.key][0];
},
deep: true,
},
},
}; };
</script> </script>
......
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
[135.087387, 53.561602], [135.087387, 53.561602],
], ],
{ {
padding: { bottom: 80, top: 120, left: 80, right: 470 }, padding: { bottom: 80, top: 120, left: 80, right: 270 },
} }
); );
await this.getData(); await this.getData();
......
...@@ -128,11 +128,11 @@ export default { ...@@ -128,11 +128,11 @@ export default {
<style scoped lang="less"> <style scoped lang="less">
.sortList { .sortList {
position: absolute; position: absolute;
top: 100px; top: 11vh;
right: 10px; right: 1vh;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
width: 550px; width: 13vw;
height: calc(100vh - 100px - 37vh - 2vw); height: calc(100vh - 100px - 37vh - 2vw);
.left-part-item { .left-part-item {
height: 100%; height: 100%;
......
...@@ -154,7 +154,7 @@ export default { ...@@ -154,7 +154,7 @@ export default {
.filterProvince { .filterProvince {
position: absolute; position: absolute;
right: calc(3vh + 550px); right: calc(3vh + 13vw);
top: calc(11vh + 44px + 1vh); top: calc(11vh + 44px + 1vh);
} }
...@@ -167,7 +167,7 @@ export default { ...@@ -167,7 +167,7 @@ export default {
.statusControl { .statusControl {
position: absolute; position: absolute;
top: 11vh; top: 11vh;
right: calc(3vh + 550px); right: calc(3vh + 13vw);
} }
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment