rt-sim-training-client/src/views/dashboard/echarts/permission.vue

185 lines
4.5 KiB
Vue
Raw Normal View History

2019-08-16 14:25:20 +08:00
<template>
<div>
<div :id="id" :style="{height: size.height+'px', width: size.width+'px'}" />
<div class="lesson-select">
2019-08-16 16:55:16 +08:00
<el-select v-model="mapName" placeholder="请选择地图线路" size="mini" style="width: 300px">
2019-08-16 14:25:20 +08:00
<el-option v-for="name in mapNameList" :key="name" :label="name" :value="name" />
</el-select>
</div>
</div>
</template>
<script>
import echarts from 'echarts';
import { listUserPermision } from '@/api/management/author';
export default {
props: {
id: {
type: String,
default: 'chart'
},
size: {
type: Object,
required: true
}
},
data() {
return {
option: {
backgroundColor: '#F0F2F5',
2019-08-21 09:14:54 +08:00
title: {
2019-08-16 14:25:20 +08:00
text: '',
subtext: '',
2019-08-16 16:55:16 +08:00
subtextStyle: {
color: '#909399'
},
2019-08-16 14:40:42 +08:00
y: 10,
2019-08-16 14:25:20 +08:00
left: 'center',
textAlign: 'center'
2019-08-21 09:14:54 +08:00
},
2019-08-16 14:25:20 +08:00
tooltip: {
},
grid: [{
2019-08-21 09:14:54 +08:00
top: '17%',
2019-08-21 09:18:52 +08:00
width: '45%',
2019-08-21 09:14:54 +08:00
bottom: '5%',
left: 50,
2019-08-18 21:12:38 +08:00
containLabel: true
2019-08-16 19:09:44 +08:00
}],
2019-08-21 09:14:54 +08:00
xAxis: {
2019-08-16 14:25:20 +08:00
type: 'category',
show: false,
2019-08-16 14:25:20 +08:00
axisLabel: {
interval: 0,
2019-08-21 09:14:54 +08:00
rotate: 60
2019-08-16 14:25:20 +08:00
},
2019-08-18 21:12:38 +08:00
splitLine: {
show: false
},
data: []
2019-08-21 09:14:54 +08:00
},
yAxis: {
type: 'value',
2019-08-16 19:09:44 +08:00
show: false,
2019-08-21 09:14:54 +08:00
minInterval: 1,
name: '权限(个)'
},
2019-08-16 14:25:20 +08:00
series: [{
type: 'bar',
z: 3,
2019-08-18 21:12:38 +08:00
barWidth: 10,
2019-08-16 14:25:20 +08:00
tooltip: {
formatter: params => { return `${params.marker} ${params.name}: ${params.value}`; }
},
data: []
}, {
type: 'pie',
radius: [0, '70%'],
2019-08-19 09:15:25 +08:00
center: ['75%', '52%'],
2019-08-16 14:25:20 +08:00
tooltip: {
2019-08-21 09:20:40 +08:00
formatter: params => { return `${params.marker} ${params.name}: ${params.percent}% ${params.value}个)`; }
2019-08-16 14:25:20 +08:00
},
data: []
}]
},
mapName: null,
2019-08-16 14:25:20 +08:00
mapNameList: [],
permissionList: [],
chart: null
};
},
watch: {
size() {
return this.chart.resize({...this.size, silent: false});
},
async mapName(val) {
await this.loadExamData(val);
}
},
mounted() {
this.initChart();
},
beforeDestroy() {
if (!this.chart) {
return;
}
this.chart.dispose();
this.chart = null;
},
methods: {
initChart() {
listUserPermision({pageSize: 9000, pageNum: 1}).then(resp => {
this.permissionList = resp.data.list.filter(elem => { return parseInt(elem.status) > 0; });
2019-08-18 21:12:38 +08:00
this.mapNameList = [...new Set(this.permissionList.map(elem => { return elem.mapName; }))];
2019-08-16 14:25:20 +08:00
this.$nextTick(() => { this.mapName = this.mapNameList[0] || ''; });
});
this.chart = echarts.init(document.getElementById(this.id));
this.chart.setOption(this.option);
},
async loadExamData(mapName) {
if (mapName) {
2019-08-21 09:14:54 +08:00
var permissionDict = {};
2019-08-16 18:59:19 +08:00
var permissionList = await this.$Dictionary.permissionType();
2019-08-21 09:14:54 +08:00
(permissionList ||[]).forEach(elem => {
permissionDict[elem.code] = elem.name;
});
2019-08-16 18:59:19 +08:00
2019-08-21 09:14:54 +08:00
var permissionMap = {
2019-08-18 21:12:38 +08:00
'ATS现地工作站-课程权限': 0,
2019-08-21 09:14:54 +08:00
'ATS行调工作站-课程权限': 0,
2019-08-18 21:12:38 +08:00
'ATS现地工作站-考试权限': 0,
2019-08-21 09:14:54 +08:00
'ATS行调工作站-考试权限': 0,
2019-08-18 21:12:38 +08:00
'ATS现地工作站-仿真权限': 0,
'ATS行调工作站-仿真权限': 0,
'综合演练云平台-仿真权限': 0,
'司机模拟驾驶系统-仿真权限': 0,
'大屏系统权限': 0
};
2019-08-21 09:14:54 +08:00
2019-08-16 18:16:19 +08:00
(this.permissionList.filter(elem => { return elem.mapName == mapName; })|| []).forEach(elem => {
2019-08-21 09:18:52 +08:00
if (elem.mapProductName == Object.keys(permissionMap)[Object.keys(permissionMap).length -1]) {
permissionMap[`${elem.mapProductName}`] = elem.remains;
} else {
permissionMap[`${elem.mapProductName}-${permissionDict[elem.type]}`] = elem.remains;
}
});
2019-08-21 09:14:54 +08:00
const keys = Object.keys(permissionMap);
const values = Object.values(permissionMap);
2019-08-18 21:12:38 +08:00
const sum = values.reduce((total, num) => total + num);
2019-08-21 09:14:54 +08:00
this.option.title.text = `剩余权限分布图(${mapName}`;
this.option.title.subtext = `权限总计${sum}`;
2019-08-18 21:12:38 +08:00
2019-08-21 09:14:54 +08:00
this.option.xAxis.show = true;
this.option.yAxis.show = true;
2019-08-19 09:15:25 +08:00
2019-08-21 09:14:54 +08:00
this.option.xAxis.data = keys;
2019-08-18 21:12:38 +08:00
2019-08-21 09:14:54 +08:00
this.option.series[0].data = values;
this.option.series[1].data = keys.map(name => { return {name, value: permissionMap[name]}; });
} else {
2019-08-21 09:14:54 +08:00
this.option.title.text = `剩余权限分布图(暂无地图线路数据)`;
this.option.title.subtext = `权限总计0个`;
this.option.xAxis.show = false;
this.option.yAxis.show = false;
this.option.xAxis.data = [];
this.option.series[0].data = [];
this.option.series[1].data = [];
}
2019-08-16 14:25:20 +08:00
this.chart.setOption(this.option);
}
}
};
</script>
<style scoped>
.lesson-select {
position: absolute;
display: flex;
2019-08-16 14:40:42 +08:00
top: 30px;
right: 30px;
2019-08-16 14:25:20 +08:00
}
</style>