开发自动登录 系统风险折线图

This commit is contained in:
GongDragon 2024-11-29 17:32:58 +08:00
parent d96d3a1025
commit db77dc0708
2 changed files with 421 additions and 17 deletions

View File

@ -0,0 +1,368 @@
<template>
<div style="height: 85%;">
<div style="display: flex;height: 100%;">
<div ref="whole risk" style=" float: left;width: 98%; height: 100%;margin-left: 15px;margin-top: 0px;margin-right: 0px"></div>
<div ref="future" style=" float: left; width: 2%; height: 100%;margin-left: -168px;margin-top: 0px;"></div>
</div>
<!-- <div class="warning-component">
<div class="warning-dates">
<div class="date-item">前日<span>{{ prevDayRisk }}</span></div>
<div class="date-item">昨日<span>{{ yesterdayRisk }}</span></div>
<div class="date-item">今日<span>{{ todayRisk }}</span></div>
<div class="date-item">明日<span>{{ tomorrowRisk }}</span></div>
<div class="warning-recent">
最近预警<span>{{ warningRisk }}</span>
</div>
</div>
</div> -->
</div>
</template>
<script>
import * as echarts from "echarts";
import http from "@/utils/request";
import { color } from "d3";
export default {
data(){
return {
yMax:2,
yMin:0,
prevDayRisk:'',
yesterdayRisk:'',
todayRisk:'',
tomorrowRisk:'',
warningRisk:'',
riskData:[],
markLine: [],
markPoint: [],
markArea:[],
future:[],
datazoom:[]
}
},
props:{
zoom:{
type:Array,
default: function () {
return []
}
}
},
watch:{
zoom(newVal){
this.datazoom=newVal
},
yMax(newVal){
console.log(newVal)
}
},
mounted() {
},
methods:{
getData(){
http.get('/risk/whole/').then((res)=>{
this.riskData=res.data.wholerisk
this.markPoint=res.data.markpoint
this.markLine=res.data.markline
this.markArea=res.data.markarea
this.prevDayRisk=res.data.detail[0]
this.yesterdayRisk=res.data.detail[1]
this.todayRisk=res.data.detail[2]
this.tomorrowRisk=res.data.detail[3]
this.warningRisk=res.data.detail[4]
this.future=res.data.future
// console.log(this.riskData,this.markLine,this.markPoint[0])
this.initChart()
})
// this.initChart(this.dat)
},
initChart(){
/*
示例参考如下
* https://echarts.apache.org/v4/examples/zh/editor.html?c=line-aqi
*
* https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/examples/data/asset/data/aqi-beijing.json
*
* */
let data=this.riskData
const future=this.future
var myChart = echarts.init(this.$refs["whole risk"])
var myChartFuture= echarts.init(this.$refs["future"])
let option = {
title: {
text: '系统性风险指数',
left: 'center',
textStyle: {
color: '#fff'
}
},
tooltip: {
trigger: 'axis'
},
xAxis: {
axisLabel:{
fontSize:5,
color: '#fff'
},
axisLine: {
lineStyle:{
color: '#fff'
}
},
data: data.map(function (item) {
return item[0];
})
},
yAxis: {
axisLabel:{
color: '#fff'
},
axisLine: {
lineStyle:{
color: '#fff'
}
},
scale:true,
splitLine: {
show: false
}
},
//
dataZoom: [{
//
startValue: '2022-07-01',
type: 'slider',
dataBackground:{
lineStyle:{
color: '#fff'
},
areaStyle:{
color: '#fff'
}
},
textStyle:{
color: '#fff'
},
maxSpan:30
}],
//
visualMap: {
top: 10,
right: 0,
precision:2,
pieces: [
{
gt: 0,
lte: parseFloat(this.markLine[0]),
color: '#096'
},
{
gt: parseFloat(this.markLine[0]),
lte: parseFloat(this.markLine[1]),
color: '#ffde33'
},
],
outOfRange: {
color: '#fa0744'
},
textStyle:{
color:'#fff'
}
},
series: {
name: '系统性风险指数',
type: 'line',
data: data.map(function (item) {
return item[1];
}),
//
markPoint:{
symbol:'circle',
symbolSize:10,
data: [{
itemStyle:{
//
color: {
type: 'radial',
x: 0.5,
y: 0.5,
r: 0.5,
colorStops: [{
offset: 0, color: 'purple' // 0%
}, {
offset: 1, color: '#258ddc' // 100%
}],
global: false // false
}
},
//xindexy
coord: this.markPoint[0] // 5 xAxis.data[5] '33'
// coord: ['5', 33.4] // '5' xAxis.data '5'
// 使xAxis.data [number, number, ...]
// [string, string, ...]
}]
},
markLine: {
//线
silent: true,
symbol:'none',
label:{ position:'middle',},
lineStyle:{
color:'#fff'
},
data: [{
yAxis: this.markLine[0]
}, {
yAxis:this.markLine[1]
},
]
},
markArea:{
label: { // 线
// position: 'end',
formatter: '预测值'
},
data:[[{
xAxis:this.markArea[0]},
{
xAxis:this.markArea[1]
// x:'100%'
},
]]
}
}
}
let opt2={
tooltip: {
trigger: 'item',
},
grid:
{backgroundColor: '#eeb0ae',
left:'0%',
show:true,
zlevel:0,
}
,
xAxis:
{
data:[{value:'未来一个月'}],
axisLabel:{
fontSize:5
}
// gridIndex: 0,
},
yAxis: {
min:0.8,
max:2,
type: 'value',
show:false,
// boundaryGap: false,
// gridIndex: 1
},
series: {
type: 'boxplot',
boxWidth : [2, 10],
itemStyle: {
clip: true
},
data:[{value: this.future,} ],
// 线
// zlevel: 3,
// x使nullECharts
// ...
markArea:{
label: { // 线
// position: 'end',
formatter: '预测值'
},
itemStyle:{
color:'yellow'
}
// data: [[ {
// name: '',
// type: 'average'
// },
// {
// type: 'max'
// }]]
},
tooltip: {
formatter: function (param) {
return [
// 'Experiment ' + param.name + ': ',
'最大值: ' + future[4],
'均值+标准差: ' + future[3],
'中位数: ' +future[2],
'均值-标准差: ' + future[1],
'最小值: ' + future[0]
].join('<br/>');
}
}
}
}
myChart.setOption(option);
myChartFuture.setOption(opt2)
const that=this
myChart.on('datazoom', function (params) {
// Y
this.yMax = myChart.getModel().getComponent('yAxis').axis.scale._extent[1];
// Y
this.yMin = myChart.getModel().getComponent('yAxis').axis.scale._extent[0];
that.$nextTick(() => {
// myChartFuture y
myChartFuture.setOption({
yAxis: {
min: this.yMin,
max: this.yMax
}
});
});
});
}
},
}
</script>
<style scoped>
.warning-component {
border: 1px solid #ddd;
border-radius: 8px;
padding: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 100%;
text-align: center;
margin: auto;
}
.warning-dates {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.date-item {
margin: 0 10px;
font-weight: bold;
}
.warning-recent {
color: #ff4d4f;
font-weight: bold;
margin-bottom: 10px;
}
</style>

View File

@ -240,27 +240,18 @@
<div class="box"> <div class="box">
<div class="box-header" style=""> <div class="box-header" style="">
<span style=""></span> <span style=""></span>
板块1 板块3
</div> </div>
<div class=" box-body"> <div class=" box-body">
<!-- 第一行 --> <!-- 第一行 -->
<div class="charts-row" style=""> <div class="charts-row" style="">
<div style="flex:0 1 33%"> <div style="flex:0 1 100%">
<dv-border-box-13 style="width:100%;height:300px;"> <dv-border-box-13 style="width:100%;height:300px;">
<h3 style="padding-top: 15px;padding-left: 15px;padding-right: 15px">类型统计</h3> <h3 style="padding-top: 15px;padding-left: 15px;padding-right: 15px">类型统计</h3>
<div style="display: flex;justify-content: center;align-items: center;"> <systemRiskComponent :zoom="datazoom" @datazoom="changeComp" ref="systemRisk"></systemRiskComponent>
<dv-decoration-9 style="width:120px;height:120px;margin-right:30px;" dur=5><h1 style="color: rgba(255,215,0);">48</h1></dv-decoration-9>
<dv-decoration-9 style="width:120px;height:120px;margin-left: 30px;" dur=5><h1 style="color: rgba(255,215,0);">38</h1></dv-decoration-9>
</div>
<div style="display: flex;justify-content: center;align-items: center;">
<span style="padding-right: 50px;">节点类型总数</span>
<span style="padding-left: 50px;">边类型总数</span>
</div>
</dv-border-box-13> </dv-border-box-13>
</div> </div>
<div style="flex:0 1 34%"> <!-- <div style="flex:0 1 34%">
<dv-border-box-13 style="width:100%;height:300px;"> <dv-border-box-13 style="width:100%;height:300px;">
<h3 style="padding-top: 15px;padding-left: 15px;padding-right: 15px">类型统计</h3> <h3 style="padding-top: 15px;padding-left: 15px;padding-right: 15px">类型统计</h3>
<div style="display: flex;justify-content: center;align-items: center;"> <div style="display: flex;justify-content: center;align-items: center;">
@ -287,7 +278,7 @@
<span style="padding-left: 50px;">边类型总数</span> <span style="padding-left: 50px;">边类型总数</span>
</div> </div>
</dv-border-box-13> </dv-border-box-13>
</div> </div> -->
</div> </div>
<!-- 第二行 --> <!-- 第二行 -->
@ -360,16 +351,22 @@ import LineChart from './components/LineChart.vue'
import http from "@/utils/request"; import http from "@/utils/request";
import * as echarts from "echarts"; import * as echarts from "echarts";
import { color } from 'd3'; import { color } from 'd3';
import systemRiskComponent from './components/systemRiskComponent';// 线
import dimensionComponent from "@/components/dimensionComponent";
export default { export default {
name: 'App', name: 'App',
components: { components: {
Map, Map,
RadarChart, RadarChart,
CapsuleChart, CapsuleChart,
LineChart LineChart,
systemRiskComponent,
dimensionComponent
}, },
data() { data() {
return { return {
compName:'systemRiskComponent',
datazoom:[],
scale: 0, scale: 0,
width: 5760, width: 5760,
height: 1080, height: 1080,
@ -669,6 +666,13 @@ export default {
}, delays); }, delays);
}; };
}, },
changeComp(mesg){
this.datazoom=mesg
console.log(mesg)
},
},
created() {
}, },
mounted() { mounted() {
// //
@ -676,7 +680,26 @@ export default {
window.removeEventListener("resize",this.debounce(this.setScale)) window.removeEventListener("resize",this.debounce(this.setScale))
window.addEventListener("resize", this.debounce(this.setScale)); window.addEventListener("resize", this.debounce(this.setScale));
// //
const params = new URLSearchParams();
params.append('username', 'gongdragon');
params.append('password', 'gwl123');
http.post('/users/login/', params)
.then((res)=>{
if (res.data.message===1){
this.loading = false
let user={token:res.data.data,name:'gongdragon',stats:res.data.stats}
this.$store.commit('login',user)
} else {
this.$message({
showClose: true,
message: res.data.data,
type: 'warning'
});
this.loading = false
}
}).then(()=>{
//
http.get('/warning/get_warning_count/').then((res)=> { http.get('/warning/get_warning_count/').then((res)=> {
// console.log('get_warning_count',res); // console.log('get_warning_count',res);
@ -780,11 +803,19 @@ export default {
name: '上海纳尔实业股份有限公司',// name: '上海纳尔实业股份有限公司',//
date: '2024-01',//+ date: '2024-01',//+
}}).then(response => { }}).then(response => {
console.log('Response',response);
// let radarDatas//
// radarDatas = response.data.data.map(item => {
// // echarts
// let radarData = [item.,item.,item.,item.,item.,item.,item.]
// return radarData
// })
// console.log('radarDatas',radarDatas)
let radarData = [] let radarData = []
for (let i in response.data.data) { for (let i in response.data.data) {
if (i !== '健康指数' && i !== '等级' && typeof response.data.data[i] === 'number') radarData.push(response.data.data[i]) if (i !== '健康指数' && i !== '等级' && typeof response.data.data[i] === 'number') radarData.push(response.data.data[i])
} }
// console.log('radarData',radarData)
const echarts3 = echarts.init(this.$refs.echarts_3) const echarts3 = echarts.init(this.$refs.echarts_3)
const option_3 = { const option_3 = {
title: { title: {
@ -948,6 +979,11 @@ export default {
// } // }
// echarts1.setOption(option_1,true) // echarts1.setOption(option_1,true)
// }) // })
//
this.$refs.systemRisk.getData()
}
)
} }
} }
</script> </script>