parent
c35def3014
commit
f405aaa69a
@ -0,0 +1,159 @@
|
||||
<template>
|
||||
<el-card>
|
||||
<div :id="id" :class="className" :style="{height:height,width:width}" />
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as echarts from 'echarts'
|
||||
import resize from '@/components/Charts/mixins/resize'
|
||||
import { chart } from "@/api/user/user";
|
||||
|
||||
export default {
|
||||
mixins: [resize],
|
||||
props: {
|
||||
select: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
className: {
|
||||
type: String,
|
||||
default: 'chart'
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
default: 'chart'
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '200px'
|
||||
},
|
||||
height: {
|
||||
type: String,
|
||||
default: '200px'
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
chart: null,
|
||||
data: [],
|
||||
}
|
||||
},
|
||||
created() {
|
||||
},
|
||||
mounted() {
|
||||
this.getData().then(() => {
|
||||
this.initChart()
|
||||
})
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (!this.chart) {
|
||||
return
|
||||
}
|
||||
this.chart.dispose()
|
||||
this.chart = null
|
||||
},
|
||||
methods: {
|
||||
async getData () {
|
||||
try {
|
||||
const { userAreas } = await chart(this.select)
|
||||
this.data = userAreas;
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
},
|
||||
initChart() {
|
||||
this.chart = echarts.init(document.getElementById(this.id))
|
||||
this.setOption()
|
||||
},
|
||||
setOption () {
|
||||
this.chart.setOption({
|
||||
title: {
|
||||
text: "区域占比统计"
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
},
|
||||
legend: {
|
||||
right: "right",
|
||||
top: "6%",
|
||||
icon: "circle",
|
||||
formatter: name => {
|
||||
let total = this.data.reduce((pre, cur) => pre + (isNaN(Number(cur.total??0)) ? 0 : Number(cur.total??0)), 0)
|
||||
let arr = [
|
||||
'{a|' + name + '}',
|
||||
'{b|' + (Math.round(this.data.find(i => i.area === name)?.total??0 / total) * 100).toFixed(2) + '%}',
|
||||
'{c|' + (this.data.find(i => i.area === name)?.total??0) + '}'
|
||||
]
|
||||
return arr.join(' ')
|
||||
},
|
||||
textStyle: {
|
||||
padding: [0, 0, 0, 0],
|
||||
rich: {
|
||||
a: {
|
||||
fontSize: 15,
|
||||
width: 110
|
||||
},
|
||||
b: {
|
||||
fontSize: 15,
|
||||
width: 70,
|
||||
color: '#c1c1c1'
|
||||
},
|
||||
c: {
|
||||
fontSize: 15
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
toolbox: {
|
||||
show: false,
|
||||
feature: {
|
||||
mark: { show: true },
|
||||
dataView: { show: true, readOnly: false },
|
||||
restore: { show: true },
|
||||
saveAsImage: { show: true }
|
||||
}
|
||||
},
|
||||
color:['#609ff8','#79c97e','#f5d564','#de5567', '#9062de','#73c9ca'],
|
||||
series: [
|
||||
{
|
||||
name: '区域',
|
||||
type: 'pie',
|
||||
radius: ['40%', '70%'],
|
||||
avoidLabelOverlap: false,
|
||||
itemStyle: {
|
||||
borderRadius: 30,
|
||||
borderColor: '#fff',
|
||||
borderWidth: 4
|
||||
},
|
||||
label: {
|
||||
show: false,
|
||||
position: 'center'
|
||||
},
|
||||
emphasis: {
|
||||
label: {
|
||||
show: true,
|
||||
fontSize: 30,
|
||||
fontWeight: 'bold'
|
||||
}
|
||||
},
|
||||
labelLine: {
|
||||
show: false
|
||||
},
|
||||
data: this.data.map(i => ({ value: i.total ?? 0, name: i.area ?? '-' })),
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
select: {
|
||||
handler: function () {
|
||||
this.getData().then(() => {
|
||||
this.initChart()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-card shadow="never" style="margin-top: 20px">
|
||||
<template #header>
|
||||
<slot name="header">
|
||||
<vxe-toolbar ref="toolbar">
|
||||
<template #buttons>
|
||||
<el-date-picker
|
||||
v-model="select.start"
|
||||
align="right"
|
||||
type="date"
|
||||
size="small"
|
||||
placeholder="选择开始日期"
|
||||
style="width: 140px;margin-right: 10px;"
|
||||
:picker-options="pickerOptions">
|
||||
</el-date-picker>
|
||||
<el-date-picker
|
||||
v-model="select.end"
|
||||
align="right"
|
||||
type="date"
|
||||
size="small"
|
||||
placeholder="选择结束日期"
|
||||
style="width: 140px;margin-right: 10px;"
|
||||
:picker-options="pickerOptions">
|
||||
</el-date-picker>
|
||||
<el-button
|
||||
v-if="isHasAuth('search')"
|
||||
icon="el-icon-search"
|
||||
type="primary"
|
||||
plain
|
||||
size="small"
|
||||
@click="$refs['PieChart'].getData()"
|
||||
>搜索</el-button
|
||||
>
|
||||
</template>
|
||||
</vxe-toolbar>
|
||||
</slot>
|
||||
</template>
|
||||
|
||||
<PieChart ref="PieChart" id="pie-chart" :select="select" width="100%" height="64vh"></PieChart>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { authMixin } from "@/mixin/authMixin";
|
||||
import PieChart from "./components/PieChart.vue"
|
||||
export default {
|
||||
components: {
|
||||
PieChart
|
||||
},
|
||||
mixins: [authMixin],
|
||||
data() {
|
||||
return {
|
||||
select: {
|
||||
start: "",
|
||||
end: ""
|
||||
},
|
||||
pickerOptions: {
|
||||
shortcuts: [{
|
||||
text: '今天',
|
||||
onClick(picker) {
|
||||
picker.$emit('pick', new Date());
|
||||
}
|
||||
}, {
|
||||
text: '昨天',
|
||||
onClick(picker) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() - 3600 * 1000 * 24);
|
||||
picker.$emit('pick', date);
|
||||
}
|
||||
}, {
|
||||
text: '一周前',
|
||||
onClick(picker) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
|
||||
picker.$emit('pick', date);
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
},
|
||||
computed: {
|
||||
isHasAuth() {
|
||||
return function (auth) {
|
||||
return this.auths_auth_mixin.indexOf(auth) !== -1;
|
||||
};
|
||||
},
|
||||
},
|
||||
created() {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
::v-deep .el-card__header {
|
||||
padding: 6px 20px;
|
||||
}
|
||||
::v-deep .el-tag + .el-tag {
|
||||
margin-left: 4px;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in new issue