提交首页统计代码-liyuchen

This commit is contained in:
李宇辰 2023-04-15 17:08:54 +08:00
parent b897b3bc61
commit efbd270626
2 changed files with 131 additions and 165 deletions

View File

@ -15,4 +15,14 @@ export function review(data) {
method: 'post', method: 'post',
data: data, data: data,
}); });
}
/**
* 首页 dashborad
*/
export function statistics(){
return request({
url: '/api/'+moduleName+'/ui/disasterInfo/statistics',
method: 'get'
});
} }

View File

@ -17,7 +17,7 @@
<div class="flex-auto"> <div class="flex-auto">
<span class="font30">{{ v.num1 }}</span> <span class="font30">{{ v.num1 }}</span>
<span class="ml5 font16" <span class="ml5 font16"
:style="{ color: v.color1 }">{{ v.num2 }}%</span> :style="{ color: v.color1 }">{{ v.num2 }}</span>
<div class="mt10">{{ v.num3 }}</div> <div class="mt10">{{ v.num3 }}</div>
</div> </div>
<div class="home-card-item-icon flex" <div class="home-card-item-icon flex"
@ -114,7 +114,7 @@ import * as echarts from 'echarts';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { useThemeConfig } from '/@/stores/themeConfig'; import { useThemeConfig } from '/@/stores/themeConfig';
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes'; import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
import {statistics} from '/@/api/disasterInfo/index.js';
// //
const homeLineRef = ref(); const homeLineRef = ref();
const homePieRef = ref(); const homePieRef = ref();
@ -125,6 +125,7 @@ const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig); const { themeConfig } = storeToRefs(storesThemeConfig);
const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes); const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
const state = reactive({ const state = reactive({
global: { global: {
homeChartOne: null, homeChartOne: null,
homeChartTwo: null, homeChartTwo: null,
@ -134,8 +135,8 @@ const state = reactive({
}, },
homeOne: [ homeOne: [
{ {
num1: '125,12', num1: '',
num2: '-12.32', num2: '',
num3: 'Number of Disaster Response Applications', num3: 'Number of Disaster Response Applications',
num4: 'fa fa-meetup', num4: 'fa fa-meetup',
color1: '#FF6462', color1: '#FF6462',
@ -143,8 +144,8 @@ const state = reactive({
color3: '--el-color-primary', color3: '--el-color-primary',
}, },
{ {
num1: '653,33', num1: '',
num2: '+42.32', num2: '',
num3: 'Actual times of disaster response', num3: 'Actual times of disaster response',
num4: 'iconfont icon-ditu', num4: 'iconfont icon-ditu',
color1: '#6690F9', color1: '#6690F9',
@ -152,8 +153,8 @@ const state = reactive({
color3: '--el-color-success', color3: '--el-color-success',
}, },
{ {
num1: '125,65', num1: '',
num2: '+17.32', num2: '',
num3: 'User Visits', num3: 'User Visits',
num4: 'iconfont icon-zaosheng', num4: 'iconfont icon-zaosheng',
color1: '#6690F9', color1: '#6690F9',
@ -161,8 +162,8 @@ const state = reactive({
color3: '--el-color-warning', color3: '--el-color-warning',
}, },
{ {
num1: '520,43', num1: '',
num2: '-10.01', num2: '',
num3: 'Data downloads', num3: 'Data downloads',
num4: 'fa fa-github-alt', num4: 'fa fa-github-alt',
color1: '#FF6462', color1: '#FF6462',
@ -235,7 +236,9 @@ const state = reactive({
}); });
// 线 // 线
const initLineChart = () => { const initLineChart = (xData,data) => {
console.log(xData)
console.log(data)
if (!state.global.dispose.some((b) => b === state.global.homeChartOne)) state.global.homeChartOne.dispose(); if (!state.global.dispose.some((b) => b === state.global.homeChartOne)) state.global.homeChartOne.dispose();
state.global.homeChartOne = markRaw(echarts.init(homeLineRef.value, state.charts.theme)); state.global.homeChartOne = markRaw(echarts.init(homeLineRef.value, state.charts.theme));
const option = { const option = {
@ -247,25 +250,25 @@ const initLineChart = () => {
}, },
grid: { top: 70, right: 20, bottom: 30, left: 30 }, grid: { top: 70, right: 20, bottom: 30, left: 30 },
tooltip: { trigger: 'axis' }, tooltip: { trigger: 'axis' },
legend: { data: ['预购队列', '最新成交价'], right: 0 }, legend: { data: ['响应量'], right: 0 },
xAxis: { xAxis: {
data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], data: xData,
}, },
yAxis: [ yAxis: [
{ {
type: 'value', type: 'value',
name: '价格', name: '响应量',
splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } }, splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } },
}, },
], ],
series: [ series: [
{ {
name: '预购队列', name: '响应量',
type: 'line', type: 'line',
symbolSize: 6, symbolSize: 6,
symbol: 'circle', symbol: 'circle',
smooth: true, smooth: true,
data: [0, 41.1, 30.4, 65.1, 53.3, 53.3, 53.3, 41.1, 30.4, 65.1, 53.3, 10], data: data,
lineStyle: { color: '#fe9a8b' }, lineStyle: { color: '#fe9a8b' },
itemStyle: { color: '#fe9a8b', borderColor: '#fe9a8b' }, itemStyle: { color: '#fe9a8b', borderColor: '#fe9a8b' },
areaStyle: { areaStyle: {
@ -275,57 +278,21 @@ const initLineChart = () => {
]), ]),
}, },
}, },
{
name: '最新成交价',
type: 'line',
symbolSize: 6,
symbol: 'circle',
smooth: true,
data: [0, 24.1, 7.2, 15.5, 42.4, 42.4, 42.4, 24.1, 7.2, 15.5, 42.4, 0],
lineStyle: { color: '#9E87FF' },
itemStyle: { color: '#9E87FF', borderColor: '#9E87FF' },
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#9E87FFb3' },
{ offset: 1, color: '#9E87FF03' },
]),
},
emphasis: {
itemStyle: {
color: {
type: 'radial',
x: 0.5,
y: 0.5,
r: 0.5,
colorStops: [
{ offset: 0, color: '#9E87FF' },
{ offset: 0.4, color: '#9E87FF' },
{ offset: 0.5, color: '#fff' },
{ offset: 0.7, color: '#fff' },
{ offset: 0.8, color: '#fff' },
{ offset: 1, color: '#fff' },
],
},
borderColor: '#9E87FF',
borderWidth: 2,
},
},
},
], ],
}; };
state.global.homeChartOne.setOption(option); state.global.homeChartOne.setOption(option);
state.myCharts.push(state.global.homeChartOne); state.myCharts.push(state.global.homeChartOne);
}; };
//homePieRef //homePieRef
const initPieChart = () => { const initPieChart = (data) => {
if (!state.global.dispose.some((b) => b === state.global.homeChartTwo)) state.global.homeChartTwo.dispose(); if (!state.global.dispose.some((b) => b === state.global.homeChartTwo)) state.global.homeChartTwo.dispose();
state.global.homeChartTwo = markRaw(echarts.init(homePieRef.value, state.charts.theme)); state.global.homeChartTwo = markRaw(echarts.init(homePieRef.value, state.charts.theme));
var getname = ['房屋及结构物', '专用设备', '通用设备', '文物和陈列品', '图书、档案']; // var getname = ['', '', '', '', ''];
var getvalue = [34.2, 38.87, 17.88, 9.05, 2.05]; // var getvalue = [34.2, 38.87, 17.88, 9.05, 2.05];
var data = []; // var data = [];
for (var i = 0; i < getname.length; i++) { // for (var i = 0; i < getname.length; i++) {
data.push({ name: getname[i], value: getvalue[i] }); // data.push({ name: getname[i], value: getvalue[i] });
} // }
const colorList = ['#51A3FC', '#36C78B', '#FEC279', '#968AF5', '#E790E8']; const colorList = ['#51A3FC', '#36C78B', '#FEC279', '#968AF5', '#E790E8'];
const option = { const option = {
backgroundColor: state.charts.bgColor, backgroundColor: state.charts.bgColor,
@ -387,11 +354,6 @@ const initPieChart = () => {
type: 'pie', type: 'pie',
radius: ['82', themeConfig.value.isIsDark ? '50' : '102'], radius: ['82', themeConfig.value.isIsDark ? '50' : '102'],
center: ['50%', '50%'], center: ['50%', '50%'],
itemStyle: {
color: function (params) {
return colorList[params.dataIndex];
},
},
label: { show: true }, label: { show: true },
labelLine: { show: true }, labelLine: { show: true },
data: data, data: data,
@ -402,15 +364,16 @@ const initPieChart = () => {
state.myCharts.push(state.global.homeChartTwo); state.myCharts.push(state.global.homeChartTwo);
}; };
//homePieRef2 //homePieRef2
const initPieChart2 = () => { const initPieChart2 = (data) => {
console.log("pie2",data)
if (!state.global.dispose.some((b) => b === state.global.homeChartFour)) state.global.homeChartFour.dispose(); if (!state.global.dispose.some((b) => b === state.global.homeChartFour)) state.global.homeChartFour.dispose();
state.global.homeChartFour = markRaw(echarts.init(homePieRef2.value, state.charts.theme)); state.global.homeChartFour = markRaw(echarts.init(homePieRef2.value, state.charts.theme));
var getname = ['房屋及结构物', '专用设备', '通用设备', '文物和陈列品', '图书、档案']; // var getname = ['', '', '', '', ''];
var getvalue = [34.2, 38.87, 17.88, 9.05, 2.05]; // var getvalue = [34.2, 38.87, 17.88, 9.05, 2.05];
var data = []; // var data = [];
for (var i = 0; i < getname.length; i++) { // for (var i = 0; i < getname.length; i++) {
data.push({ name: getname[i], value: getvalue[i] }); // data.push({ name: getname[i], value: getvalue[i] });
} // }
const colorList = ['#51A3FC', '#36C78B', '#FEC279', '#968AF5', '#E790E8']; const colorList = ['#51A3FC', '#36C78B', '#FEC279', '#968AF5', '#E790E8'];
const option = { const option = {
backgroundColor: state.charts.bgColor, backgroundColor: state.charts.bgColor,
@ -472,11 +435,6 @@ const initPieChart2 = () => {
type: 'pie', type: 'pie',
radius: ['82', themeConfig.value.isIsDark ? '50' : '102'], radius: ['82', themeConfig.value.isIsDark ? '50' : '102'],
center: ['50%', '50%'], center: ['50%', '50%'],
itemStyle: {
color: function (params) {
return colorList[params.dataIndex];
},
},
label: { show: true }, label: { show: true },
labelLine: { show: true }, labelLine: { show: true },
data: data, data: data,
@ -487,9 +445,9 @@ const initPieChart2 = () => {
state.myCharts.push(state.global.homeChartFour); state.myCharts.push(state.global.homeChartFour);
}; };
// //
const initBarChart = () => { const initBarChart = (xData,yData) => {
if (!state.global.dispose.some((b) => b === state.global.homeCharThree)) state.global.homeCharThree.dispose(); if (!state.global.dispose.some((b) => b === state.global.homeCharThree)) state.global.homeCharThree.dispose();
state.global.homeCharThree = markRaw(echarts.init(homeBarRef.value, state.charts.theme)); state.global.homeCharThree = echarts.init(homeBarRef.value, state.charts.theme);
const option = { const option = {
backgroundColor: state.charts.bgColor, backgroundColor: state.charts.bgColor,
title: { title: {
@ -497,29 +455,19 @@ const initBarChart = () => {
x: 'left', x: 'left',
textStyle: { fontSize: '15', color: state.charts.color }, textStyle: { fontSize: '15', color: state.charts.color },
}, },
tooltip: { trigger: 'axis' }, tooltip: { trigger: 'item', formatter: '{c}' },
legend: { data: ['供温', '回温', '压力值(Mpa)'], right: 0 }, legend: { data: ['申请量'], top: 0 },
grid: { top: 70, right: 80, bottom: 30, left: 80 }, grid: { top: 70, right: 80, bottom: 30, left: 80 },
xAxis: [ xAxis: [
{ {
type: 'category', type: 'category',
data: ['1km', '2km', '3km', '4km', '5km', '6km'], data: xData,
boundaryGap: true, boundaryGap: true,
axisTick: { show: false }, axisTick: { show: false },
}, },
], ],
yAxis: [ yAxis: [
{ {
name: '供回温度(℃)',
nameLocation: 'middle',
nameTextStyle: { padding: [3, 4, 50, 6] },
splitLine: { show: true, lineStyle: { type: 'dashed', color: '#f5f5f5' } },
axisLine: { show: false },
axisTick: { show: false },
axisLabel: { color: state.charts.color, formatter: '{value} ' },
},
{
name: '压力值(Mpa)',
nameLocation: 'middle', nameLocation: 'middle',
nameTextStyle: { padding: [50, 4, 5, 6] }, nameTextStyle: { padding: [50, 4, 5, 6] },
splitLine: { show: false }, splitLine: { show: false },
@ -530,71 +478,10 @@ const initBarChart = () => {
], ],
series: [ series: [
{ {
name: '供温', name: '申请量',
type: 'line',
smooth: true,
showSymbol: true,
//
symbol: 'path://M150 0 L80 175 L250 75 L50 75 L220 175 Z',
symbolSize: 12,
yAxisIndex: 0,
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'rgba(250,180,101,0.3)' },
{ offset: 1, color: 'rgba(250,180,101,0)' },
]),
shadowColor: 'rgba(250,180,101,0.2)',
shadowBlur: 20,
},
itemStyle: { color: '#FF8000' },
// data使value
data: [
{ value: 1, stationName: 's1' },
{ value: 3, stationName: 's2' },
{ value: 4, stationName: 's3' },
{ value: 9, stationName: 's4' },
{ value: 3, stationName: 's5' },
{ value: 2, stationName: 's6' },
],
},
{
name: '回温',
type: 'line',
smooth: true,
showSymbol: true,
symbol: 'emptyCircle',
symbolSize: 12,
yAxisIndex: 0,
areaStyle: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{ offset: 0, color: 'rgba(199, 237, 250,0.5)' },
{ offset: 1, color: 'rgba(199, 237, 250,0.2)' },
],
false
),
},
itemStyle: {
color: '#3bbc86',
},
data: [
{ value: 31, stationName: 's1' },
{ value: 36, stationName: 's2' },
{ value: 54, stationName: 's3' },
{ value: 24, stationName: 's4' },
{ value: 73, stationName: 's5' },
{ value: 22, stationName: 's6' },
],
},
{
name: '压力值(Mpa)',
type: 'bar', type: 'bar',
barWidth: 30, barWidth: 30,
yAxisIndex: 1, yAxisIndex: 0,
itemStyle: { itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'rgba(108,80,243,0.3)' }, { offset: 0, color: 'rgba(108,80,243,0.3)' },
@ -603,14 +490,7 @@ const initBarChart = () => {
// //
borderRadius: [30, 30, 0, 0], borderRadius: [30, 30, 0, 0],
}, },
data: [ data: yData,
{ value: 11, stationName: 's1' },
{ value: 34, stationName: 's2' },
{ value: 54, stationName: 's3' },
{ value: 39, stationName: 's4' },
{ value: 63, stationName: 's5' },
{ value: 24, stationName: 's6' },
],
}, },
], ],
}; };
@ -627,6 +507,81 @@ const initEchartsResizeFun = () => {
} }
}); });
}; };
/**
* 设置表头
* @param data
*/
const setHeadData = (data) => {
state.homeOne[0].num1 = data.applyCount
state.homeOne[1].num1 = data.actResponseNum
state.homeOne[2].num1 = data.visitCount
state.homeOne[3].num1 = data.downloadCount
}
/**
* 设置发生区域灾害占比
* @param data
*/
const setDisasterArea = (data) => {
let arr = [];
for(let [k , v] of Object.entries(data)){
arr.push({ name: k, value: v});
}
initPieChart(arr);
}
/**
* 设置灾害响应月份分布量
* @param data
*/
const setResponseDisaster = (data) => {
let xData = [];
let yData = [];
data.forEach(item=>{
for(let [k , v] of Object.entries(item)){
xData.push(k);
yData.push(v.value);
}
})
initLineChart(xData,yData);
}
/**
* 设置灾害申请月份分布量
* @param data
*/
const setApplyDisaster = (data) => {
let xData = [];
let yData = [];
data.forEach(item=>{
for(let [k , v] of Object.entries(item)){
xData.push(k);
yData.push(v.value);
}
})
setTimeout(() => {
initBarChart(xData,yData);
}, 1000);
}
/**
* 设置灾种数量占比
* @param data
*/
const setDisasterType = (data) => {
let arr = [];
for(let [k , v] of Object.entries(data)){
arr.push({ name: k, value: v});
}
initPieChart2(arr)
}
//
const getDashBoradData = () => {
statistics().then(res=>{
console.log(res);
setHeadData(res.header);
setDisasterArea(res.country);
setResponseDisaster(res.responseMonth);
setApplyDisaster(res.applyMonth);
setDisasterType(res.disasterNum);
})
}
// echarts resize // echarts resize
const initEchartsResize = () => { const initEchartsResize = () => {
window.addEventListener('resize', initEchartsResizeFun); window.addEventListener('resize', initEchartsResizeFun);
@ -634,6 +589,7 @@ const initEchartsResize = () => {
// //
onMounted(() => { onMounted(() => {
initEchartsResize(); initEchartsResize();
getDashBoradData();
}); });
// keep-alive // keep-alive
onActivated(() => { onActivated(() => {
@ -655,13 +611,13 @@ watch(
state.charts.bgColor = isIsDark ? 'transparent' : ''; state.charts.bgColor = isIsDark ? 'transparent' : '';
state.charts.color = isIsDark ? '#dadada' : '#303133'; state.charts.color = isIsDark ? '#dadada' : '#303133';
setTimeout(() => { setTimeout(() => {
initLineChart(); //initLineChart();
}, 500); }, 500);
setTimeout(() => { setTimeout(() => {
initPieChart(); //initPieChart();
}, 700); }, 700);
setTimeout(() => { setTimeout(() => {
initPieChart2(); //initPieChart2();
}, 700); }, 700);
setTimeout(() => { setTimeout(() => {
initBarChart(); initBarChart();