CET-vue-3.0/src/views/cet/cet-ana-2.vue

211 lines
5.7 KiB
Vue
Raw Normal View History

2024-03-26 13:30:08 +08:00
<template>
2024-04-10 21:34:49 +08:00
<div style="background: #ececec; padding: 15px">
<a-card title="按批次对比分析" :loading="loading" :bordered="false">
2024-03-27 17:08:37 +08:00
<template #extra>
2024-04-03 14:36:10 +08:00
<!-- <a-select v-model:value="college" style="width: 300px" :options="collegeOptions"></a-select> -->
<a-cascader v-model:value="collegeMajor" :options="collegeMajorOptions" change-on-select />
2024-05-06 14:28:58 +08:00
<a-button style="margin-left: 10px" type="primary" @click="query">查询</a-button>
2024-03-27 17:08:37 +08:00
</template>
2024-03-27 18:26:50 +08:00
<div>
<a-row :gutter="24">
<a-col :xl="24" :style="{ marginBottom: '24px' }">
<div class="container">
2024-05-06 14:28:58 +08:00
<div id="map1" style="width: 100%; height: 400px"></div>
2024-03-27 18:26:50 +08:00
</div>
</a-col>
</a-row>
</div>
2024-03-27 17:08:37 +08:00
</a-card>
</div>
</template>
<script>
import { defHttp } from '/@/utils/http/axios';
import * as echarts from 'echarts';
export default {
2024-05-06 14:28:58 +08:00
name: 'Analysis',
2024-03-27 17:08:37 +08:00
data() {
return {
Url: {
getBatch: '/cet/getBatch',
getCollege: '/cet/getCollege',
2024-04-10 21:34:49 +08:00
getRate: '/cet/getRateByAllBatch',
2024-05-06 14:28:58 +08:00
getCollegeMajor: '/cet/getCollegeMajor',
2024-03-26 13:30:08 +08:00
},
2024-03-27 18:26:50 +08:00
loading: false,
2024-03-27 17:08:37 +08:00
collegeOptions: [],
2024-04-03 14:36:10 +08:00
collegeMajorOptions: [],
2024-03-27 17:08:37 +08:00
batchOptions: [],
levelOptions: [
{ value: 'cet4', label: '英语四级' },
2024-05-06 14:28:58 +08:00
{ value: 'cet6', label: '英语六级' },
2024-03-27 17:08:37 +08:00
],
level: null,
college: null,
2024-04-03 14:36:10 +08:00
batch: null,
2024-05-06 14:28:58 +08:00
collegeMajor: null,
2024-03-27 17:08:37 +08:00
};
},
methods: {
2024-03-27 19:12:05 +08:00
dataChart(data) {
let xData = [];
let yData = [];
for (let key in data) {
xData.push(key);
// 将数据转换为百分比(加上%
2024-05-06 14:28:58 +08:00
yData.push(data[key].toFixed(1));
2024-03-27 19:12:05 +08:00
}
2024-05-06 14:28:58 +08:00
let myChart = echarts.init(document.getElementById('map1'));
2024-03-27 17:08:37 +08:00
// 指定图表的配置项和数据
let option = {
title: {
2024-05-06 14:28:58 +08:00
text: '学院 / 专业通过率变化',
2024-03-27 19:12:05 +08:00
},
xAxis: {
type: 'category',
data: xData,
2024-04-08 16:41:42 +08:00
axisLabel: {
2024-05-06 14:28:58 +08:00
interval: 0, //代表显示所有x轴标签显示
rotate: -10, //代表倾斜30度显示
},
2024-03-27 17:08:37 +08:00
},
tooltip: {
trigger: 'axis',
axisPointer: {
2024-05-06 14:28:58 +08:00
type: 'shadow',
2024-04-10 21:34:49 +08:00
},
formatter: function (params) {
2024-05-06 14:28:58 +08:00
return (
params[0].name +
'<br/>' +
2024-04-10 21:34:49 +08:00
'<table>' +
2024-05-06 14:28:58 +08:00
'<tr><td>' +
params[0].marker +
'</td><td style="font-weight: bold;">' +
'&nbsp;&nbsp;&nbsp;&nbsp;' +
params[0].value +
'%' +
'</td></tr>' +
'<tr>' +
'</table>'
);
},
2024-03-27 17:08:37 +08:00
},
yAxis: {
2024-04-10 21:34:49 +08:00
type: 'value',
name: '通过率',
axisLabel: {
2024-05-06 14:28:58 +08:00
formatter: '{value} %',
},
2024-03-27 17:08:37 +08:00
},
series: [
{
2024-03-27 19:12:05 +08:00
data: yData,
2024-04-08 16:41:42 +08:00
type: 'line',
itemStyle: {
normal: {
label: {
show: true, //开启显示
position: 'top', //在上方显示
2024-05-06 14:28:58 +08:00
textStyle: {
//数值样式
2024-04-08 16:41:42 +08:00
color: 'black',
2024-05-06 14:28:58 +08:00
fontSize: 12,
2024-04-10 21:34:49 +08:00
},
formatter: '{c}%',
2024-05-06 14:28:58 +08:00
},
},
},
},
],
2024-03-27 17:08:37 +08:00
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
},
// 获取批次数据
async getBatch() {
const getBatch = await defHttp.get({ url: this.Url.getBatch });
2024-04-03 14:36:10 +08:00
// const getCollege = await defHttp.get({ url: this.Url.getCollege });
2024-03-27 17:08:37 +08:00
2024-04-03 14:36:10 +08:00
// this.collegeOptions = getCollege.colleges;
// this.college = this.collegeOptions[0].value;
2024-03-27 17:08:37 +08:00
this.level = this.levelOptions[0].value;
2024-04-03 14:36:10 +08:00
// this.query();
},
//获取学院专业级联数据
async getCollegeMajorData() {
const res = await defHttp.get({ url: this.Url.getCollegeMajor });
//通过map方法将数据转换为级联选择器需要的数据格式
2024-05-06 14:28:58 +08:00
this.collegeMajorOptions = res.collegeMajor.map((item) => {
2024-04-03 14:36:10 +08:00
return {
value: item.college,
label: item.college,
2024-05-06 14:28:58 +08:00
children: item.major.map((major) => {
2024-04-03 14:36:10 +08:00
return {
value: major,
2024-05-06 14:28:58 +08:00
label: major,
};
}),
};
2024-04-03 14:36:10 +08:00
});
this.collegeMajor = this.collegeMajorOptions[0].value;
console.log(this.collegeMajorOptions);
2024-03-26 13:30:08 +08:00
},
2024-03-27 17:08:37 +08:00
// 查询数据
async query() {
2024-03-27 19:12:05 +08:00
let data = null;
2024-05-06 14:28:58 +08:00
console.log(this.collegeMajor, 'collegeMajor');
2024-03-27 18:46:10 +08:00
try {
2024-05-06 14:28:58 +08:00
2024-04-03 14:36:10 +08:00
//如果this.collegeMajor为null则先赋个值
if (!this.collegeMajor) {
this.collegeMajor = ['东语学院'];
}
2024-05-06 14:28:58 +08:00
let major = null;
let college = null;
2024-04-03 14:36:10 +08:00
//如果this.collegeMajor[1]不存在则设为null
2024-05-06 14:28:58 +08:00
college = this.collegeMajor[0];
major=this.collegeMajor.length>1?this.collegeMajor[1]:'';
2024-03-27 18:46:10 +08:00
this.loading = true;
2024-05-06 14:28:58 +08:00
console.log(college, major,"college,major");
2024-03-27 18:46:10 +08:00
let params = {
2024-05-06 14:28:58 +08:00
college: college,
2024-04-03 14:36:10 +08:00
major: major,
level: 'cet4',
2024-05-06 14:28:58 +08:00
};
2024-03-27 19:12:05 +08:00
data = await defHttp.get({ url: this.Url.getRate, params });
2024-03-27 18:46:10 +08:00
} finally {
this.loading = false;
this.$nextTick(() => {
2024-03-27 19:12:05 +08:00
this.dataChart(data);
2024-05-06 14:28:58 +08:00
});
2024-03-27 17:08:37 +08:00
}
2024-05-06 14:28:58 +08:00
},
2024-03-27 17:08:37 +08:00
},
mounted() {
2024-04-03 14:36:10 +08:00
this.getCollegeMajorData();
2024-03-27 17:08:37 +08:00
this.getBatch();
2024-05-06 14:28:58 +08:00
// this.query();
},
};
2024-03-27 17:08:37 +08:00
</script>
<style lang="less" scoped>
.container {
display: flex;
background-color: #fff;
padding: 15px;
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
}
.title {
font-size: 34px;
color: rgb(8, 8, 8);
font-weight: bold;
}
</style>