提示:多表联动、地市下区县数据联动、图表数据还原
例如:
需求一:例如点击南昌市展示该市下所有的区县的系统总数,同时【部门图表】展示对应南昌市下所有区下部门系统数量排行前15;点击南昌市某个区县,【部门图表】展示对于某个区县下所有区下部门系统数量排行前15;
需求二:点击重置按钮,一切回到最初的起点
需求一代码:
需求二代码
- <template>
- <div :id="echartId" :style="{width: '100%', height: '100%'}">div>
- template>
- <script>
- export default {
- name: "EchartPic",
- props:{
- echartId: '',
- echartData:[]
- },
- data() {
- return {};
- },
- mounted() {
- this.drawLine();
- },
- methods: {
- drawLine() {
- let data = new Array();
- for (let x of this.echartData) {
- let y = {
- name : x.name,
- value : x.number
- }
-
- data.push(y)
- }
- var echarts = require("echarts");
- var myChart = echarts.init(document.getElementById(this.echartId));
- let that = this
- myChart.setOption({
- grid: {
- left: "6%",
- right: "4%",
- bottom: "10%",
- top: "8%",
- containLabel: true
- },
- tooltip: {
- //提示框,可以在全局也可以在
- trigger: "item", //提示框的样式
- formatter: "{a}
{b}: {c} ({d}%)", - color: "#000", //提示框的背景色
- textStyle: {
- //提示的字体样式
- color: "#fff"
- }
- },
- toolbox: {
- show: true,
- feature: {
- mark: { show: true },
- dataView: { show: true, readOnly: false },
- myTool1: {
- show: true,
- title: "还原",
- icon:
- "M509.166933 230.4A281.6 281.6 0 1 0 793.6 512a280.302933 280.302933 0 0 0-65.672533-180.770133 25.6 25.6 0 0 1 39.253333-32.904534A331.502933 331.502933 0 0 1 844.8 512c0 183.808-148.992 332.8-332.8 332.8S179.2 695.808 179.2 512c0-177.493333 138.922667-322.491733 313.924267-332.288l-45.056-45.056a25.6 25.6 0 1 1 36.181333-36.215467l96.5632 96.529067a25.6 25.6 0 0 1 0 36.215467l-96.5632 96.529066a25.6 25.6 0 1 1-36.181333-36.181333l61.098666-61.098667z",
- onclick: () => {
- if(that.echartId == 'myChart1'){
- that.$emit("getSystemCityData");
- }else if(that.echartId == 'myChart3'){
- that.$emit("getCatalogCityData");
- }
- },
- },
- saveAsImage: { show: true }
- }
- },
- series: [
- {
- name: "数量",
- type: "pie", //环形图的type和饼图相同
- radius: ["50%", "70%"], //饼图的半径,第一个为内半径,第二个为外半径
- avoidLabelOverlap: false,
- color: ["#02cab3", "#4885ff", "#fec67c", "#54c2fc", "#9991f6"],
- label: {
- normal: {
- //正常的样式
- show: true,
- position: "left"
- },
- emphasis: {
- //选中时候的样式
- show: true,
- textStyle: {
- fontSize: "16",
- fontWeight: "bold"
- }
- }
- }, //提示文字
- labelLine: {
- normal: {
- show: false
- }
- },
- data: data
- }
- ]
- });
- myChart.on('click', function(params) {
- if(that.echartId == 'myChart1'){
- that.$emit("getSystemCityData", params);
- }else if(that.echartId == 'myChart3'){
- that.$emit("getCatalogCityData", params);
- }
- });
- window.addEventListener("resize", function () {
- myChart.resize();
- });
-
- }
- }
- };
- script>
-
- <style scoped="true">
- style>
- <template>
- <div class="mainBox" style="height: 950px;background-color: #fff;">
- <div style="padding-top: 10px">
- <el-row :gutter="100">
- <el-col :span="6" v-for="item in titleData" :key="item.dict_key">
- <div :class="item.className">
- <el-row>
- <el-col :span="10">
- <div class="iconCircle">
- <i class="el-icon-postcard">i>
- div>
- el-col>
- <el-col :span="14">
- <div class="echartsTitleContent">
- <div>{{item.title}}div>
- <div>{{item.number}}div>
- div>
- el-col>
- el-row>
- div>
- el-col>
- el-row>
- div>
- <div class="linebox">
- <div>系统div>
- div>
- <div style="margin-top: 20px;">
- <el-row :gutter="10">
- <el-col :span="12">
- <div class="echartsTopBox">
- <div class="echartsTopTitle">地市div>
- <div class="echartsBox">
- <EchartPic echartId="myChart1" :echartData="systemCity" @getSystemCityData="systemCityMethod" :key="echartKey1"/>
- div>
- div>
- el-col>
- <el-col :span="12">
- <div class="echartsTopBox">
- <div class="echartsTopTitle">部门div>
- <div class="echartsBox" style="padding: 0px 10px 10px 10px;">
- <EchartBar echartId="myChart2" :echartData="systemDept" @getSystemDept="systemDeptMethod" :key="echartKey2"/>
- div>
- div>
- el-col>
- el-row>
- div>
- <div class="linebox">
- <div>资源目录div>
- div>
- <div style="margin-top: 20px;">
- <el-row :gutter="10">
- <el-col :span="12">
- <div class="echartsBottomBox">
- <div class="echartsTopTitle">地市div>
- <div class="echartsBoxBottom">
- <EchartPic echartId="myChart3" :echartData="resourceCity" @getCatalogCityData="resourceCityMethod" :key="echartKey3"/>
- div>
- div>
- el-col>
- <el-col :span="12">
- <div class="echartsBottomBox">
- <div class="echartsTopTitle">部门div>
- <div class="echartsBoxBottom">
- <EchartBar echartId="myChart4" :echartData="resourceDept" @getCatalogDeptData="resourceDeptMethod" :key="echartKey4"/>
- div>
- div>
- el-col>
- el-row>
- div>
- div>
- template>
- <script>
- import {getDataList,getSystemDept,getResourceDept,getResourceCity,getSystemCity} from "@/api/homePage/index";
- import EchartBar from "@/components/echarts/echartBar";
- import EchartPic from "@/components/echarts/echartPic";
- import * as echarts from "echarts";
-
- export default {
- name: "homePage",
- components: {
- EchartBar,
- EchartPic,
- },
- data() {
- return {
- titleData: [],
- systemDept:[],
- systemCity:[],
- resourceDept:[],
- resourceCity:[],
- echartKey1:0,
- echartKey2:0,
- echartKey3:0,
- echartKey4:0,
- };
- },
- created() {
- },
- mounted() {
- this.loadCountNum();
- },
- methods: {
- loadCountNum() {
- getDataList().then(res => {
- let arry = ['echartsTitleBox1',' echartsTitleBox2','echartsTitleBox3','echartsTitleBox4']
- res.data.forEach((item,index) =>{
- item.className = arry[index] //拼接class值
- if(item.name == 'cityCount'){
- item.title = '地市'
- }else if(item.name == 'deptCount'){
- item.title = '部门'
- }else if(item.name == 'systemCount'){
- item.title = '系统'
- }else if(item.name == 'resoureCount'){
- item.title = '资源目录'
- }
- })
- this.titleData = res.data
- });
- this.systemCityMethod();
- this.systemDeptMethod();
- this.resourceCityMethod();
- this.resourceDeptMethod();
- },
- systemCityMethod(param = ''){
- if(param == ''){
- getSystemCity().then(res => {
- this.systemCity = res.data
- this.echartKey1++
- });
- }else{
- getSystemCity(param.data.name).then(res => {
- //市区下可点击区县
- if(res.data.length != 0){
- this.systemCity = res.data
- this.echartKey1++
- }
- });
- }
- this.systemDeptMethod(param);
- },
- systemDeptMethod(param = ''){
- if(param == '') {
- getSystemDept().then(res => {
- this.systemDept = res.data
- this.echartKey2++
- });
- }else{
- getSystemDept(param.data.name).then(res => {
- if(res.data.length != 0) {
- this.systemDept = res.data
- this.echartKey2++
- }
- });
- }
- },
- resourceCityMethod(param = ''){
- if(param == '') {
- getResourceCity().then(res => {
- this.resourceCity = res.data
- this.echartKey3++
- });
- }else{
- getResourceCity(param.data.name).then(res => {
- if(res.data.length != 0) {
- this.resourceCity = res.data
- this.echartKey3++
- }
- });
- }
- this.resourceDeptMethod(param);
- },
- resourceDeptMethod(param = ''){
- if(param == '') {
- getResourceDept().then(res => {
- this.resourceDept = res.data
- this.echartKey4++
- });
- }else{
- getResourceDept(param.data.name).then(res => {
- if(res.data.length != 0) {
- this.resourceDept = res.data
- this.echartKey4++
- }
- });
- }
- },
- }
- };
-
- script>
-
- <style scoped="true">
- .mainBox {
- padding-top: 30px;
- padding-left: 30px;
- padding-right: 30px;
- }
-
- .echartsTitleBox1 {
- width: 100%;
- height: 110px;
- background-color: #00a0e9;
- border-radius: 10px;
- /*margin-top: 20px;*/
- }
-
- .echartsTitleBox2 {
- width: 100%;
- height: 110px;
- background-color: #13b5b1;
- border-radius: 10px;
- /*margin-top: 20px;*/
- }
-
- .echartsTitleBox3 {
- width: 100%;
- height: 110px;
- background-color: #00b7ee;
- border-radius: 10px;
- /*padding-top: 20px;*/
- }
-
- .echartsTitleBox4 {
- width: 100%;
- height: 110px;
- background-color: #f19149;
- border-radius: 10px;
- /*margin-top: 20px;*/
- }
-
- .iconCircle {
- width: 60px;
- height: 60px;
- line-height: 60px;
- border-radius: 50%;
- border: 1px solid #fff;
- margin: 0 auto;
- margin-top: 23px;
- display: flex;
- align-items: center;
- justify-content: center;
- }
-
- .iconCircle > i {
- font-size: 40px;
- color: #fff;
- }
-
- .echartsTitleContent {
- margin-top: 23px;
- }
-
- .echartsTitleContent div {
- font-size: 20px;
- color: #fff;
- }
-
- .echartsTitleContent div:last-child {
- margin-top: 5px;
- }
-
- .linebox {
- height: 60px;
- border-bottom: 1px solid #e5e5e5;
- /*margin-top: 10px;*/
- }
-
- .linebox div {
- font-size: 20px;
- height: 60px;
- width: 100px;
- text-align: center;
- line-height: 60px;
- border-bottom: 3px solid #0059c1;
- color: #0059c1;
- font-weight: 600;
- }
-
- .echartsTopBox {
- height: 300px;
- border: 1px solid #e5e5e5;
- border-radius: 10px;
- }
-
- .echartsBottomBox {
- height: 300px;
- border: 1px solid #e5e5e5;
- border-radius: 10px;
- }
-
- .echartsTopTitle {
- font-size: 18px;
- text-align: center;
- margin-top: 10px;
- font-weight: 600;
- }
-
- .echartsBox {
- width: 100%;
- height: 280px;
- }
-
- .echartsBoxBottom {
- width: 100%;
- height: 280px;
- }
-
- @media screen and (max-width: 1400px) and (min-width: 1300px) {
- .echartsBoxBottom {
- height: 250px;
- }
-
- .echartsBox {
- height: 250px;
- }
- }
- style>