2026-01-20 13:40:04 +08:00

217 lines
5.5 KiB
Vue

<template>
<div class="revenueTrends">
<QiunDataCharts type="area" :opts="opts" :chartData="res" :animation="false" :inScrollView="true" :canvas2d="true"
tooltipFormat="revenueTrends" />
<!-- <canvas style=" width: 100vw;height: 208px;position: fixed;left: 100%" class="trends" canvas-id="trends" id="trends" @tap="handleTap"/>-->
<!-- <image v-if="preferPath" style="width: 100vw;height: 208px;" :src="preferPath"></image>-->
</div>
</template>
<script>
import QiunDataCharts from "../qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue";
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
name: "revenueTrends",
components: { QiunDataCharts },
data() {
return {
trendsPath: '',
preferPath: '',
opts: {},
res: {}
}
},
props: {
data: {
type: Object,
default: () => { }
}
},
watch: {
data: {
handler(value) {
this.trendsPath = ''
this.handleCarData(value)
},
immediate: true,
deep: true
}
},
methods: {
handleTap(e) {
uChartsInstance[e.target.id].showToolTip(e, {
formatter: (item, category, index, opts) => {
const date = new Date()
let month = date.getMonth() + 1
if (item.name === '今年') {
if (index + 1 <= month) {
return item.name + ":" + item.data + ',' + `同比增长${((opts.series[0].data[index] - opts.series[1].data[index]) / opts.series[1].data[index] * 100).toFixed(2)}%`;
} else {
return item.name + ":" + item.data
}
} else {
return item.name + ":" + item.data;
}
}
});
uChartsInstance[e.target.id].touchLegend(e);
},
// 处理传入的数据
handleCarData(value) {
let res = value
this.res = res
this.opts = {
categories: res.categories,
series: res.series,
animation: false,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#1E80FF", "#00B6FF"],
padding: [15, 15, 5, 0],
dataLabel: false,
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 25,
float: 'center'
},
xAxis: {
disableGrid: true,
axisLineColor: '#F2F2F5'
},
yAxis: {
splitNumber: 4,
showTitle: false,
gridColor: '#F2F2F5',
data: [
{
min: 0,
max: this.getNumber(data.max),
titleOffsetY: -5,
titleOffsetX: -5,
fontSize: 12,
axisLineColor: '#F2F2F5'
}
]
},
extra: {
area: {
type: "curve",
opacity: 0.8,
addLine: true,
width: 2,
gradient: true,
activeType: "hollow",
dataPointShape: false // 隐藏数据点上方的数值显示
}
}
}
// if (value && value.series && value.series.length>0){
// this.drawCharts('trends', res)
// }
},
getNumber(value) {
let number = value / 40
number = Math.ceil(number)
return number * 40
},
drawCharts(id, data) {
const ctx = uni.createCanvasContext(id, this);
let _this = this
let phoneInfo = uni.getStorageSync('phoneInfo')
this.width = phoneInfo.screenWidth - 16
uChartsInstance[id] = new uCharts({
type: "area",
context: ctx,
width: _this.width,
height: 213,
categories: data.categories,
series: data.series,
animation: false,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#1E80FF", "#00B6FF"],
padding: [15, 15, 5, 5],
dataLabel: false,
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 25,
float: 'center'
},
xAxis: {
disableGrid: true,
axisLineColor: '#F2F2F5'
},
yAxis: {
splitNumber: 4,
showTitle: false,
gridColor: '#F2F2F5',
data: [
{
min: 0,
max: _this.getNumber(data.max),
titleOffsetY: -5,
titleOffsetX: -5,
fontSize: 12,
axisLineColor: '#F2F2F5'
}
]
},
extra: {
area: {
type: "curve",
opacity: 0.8,
addLine: true,
width: 2,
gradient: true,
activeType: "hollow",
dataLabel: false // 隐藏数据点上方的数值显示
}
}
});
setTimeout(() => {
this.canvasToTempImage('trends')
}, 500)
},
canvasToTempImage(id) {
uni.canvasToTempFilePath({
canvasId: id,
complete: (res) => {
if (res.tempFilePath) {
uni.getFileSystemManager().readFile({
filePath: res.tempFilePath,
encoding: 'base64',
success: res => {
let base64 = 'data:image/png;base64,' + res.data;
this.trendsPath = base64
}
})
}
}
}, this)
},
}
}
</script>
<style scoped lang="scss">
.revenueTrends {
width: calc(100vw - 32px);
height: 210px;
.trends {
width: calc(100vw - 32px);
height: 208px;
}
}
</style>