2023-04-03 19:05:18 +08:00

127 lines
3.4 KiB
Vue

<template>
<div class="moneyCompare">
<canvas v-if="!comparePath" class="compare" canvas-id="compare" id="compare"/>
<image v-if="comparePath" class="compare" :src="comparePath"></image>
</div>
</template>
<script>
import uCharts from '@/components/u-charts.js';
var uChartsInstance = {};
export default {
name: "moneyCompare",
data() {
return {
width:0,
comparePath:''
}
},
props: {
data: {
type: Object,
default: () => {}
}
},
watch: {
data: {
handler(value) {
console.log('carDatawatch', value)
this.handleCarData(value)
}
}
},
methods: {
// 处理传入的数据
handleCarData(value) {
let res = value
this.drawCharts('compare', res)
},
drawCharts(id, data) {
const ctx = uni.createCanvasContext(id, this);
let _this = this
let phoneInfo = uni.getStorageSync('phoneInfo')
this.width = phoneInfo.screenWidth
uChartsInstance[id] = new uCharts({
type: "column",
context: ctx,
width: _this.width,
height: 208,
categories: data.categories,
series: data.series,
animation: true,
rotate: false,
rotateLock: false,
background: "#FFFFFF",
color: ["#1E80FF", "#00B6FF","#ACB9CD"],
padding: [15, 40, 5, 0],
dataLabel: false,
enableScroll: false,
legend: {
show: true,
position: "bottom",
lineHeight: 25,
float: 'center'
},
xAxis: {
disableGrid: true
},
yAxis: {
showTitle:true,
splitNumber:4,
data: [
{
min: 0,
max: 12,
title:'单位: 千万',
titleOffsetX:8,
titleOffsetY:-5,
fontSize:12,
}
]
},
extra: {
column: {
type: "group",
width: 5,
seriesGap:4,
activeBgColor: "#000000",
activeBgOpacity: 0.08
}
}
});
setTimeout( ()=>{
this.canvasToTempImage('compare')
},2000)
},
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.comparePath = base64
}
})
}
}
},this)
},
}
}
</script>
<style scoped lang="scss">
.moneyCompare{
width: 100%;
.compare{
width: calc(100vw - 32px);
height: 200px;
}
}
</style>