chore:平台容器框架升级,修复命令行环境丢失的问题
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
<template>
|
||||
<div :class="className" :style="style" ref="container"></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { Column } from "@antv/g2plot";
|
||||
import { Column } from '@antv/g2plot';
|
||||
|
||||
// hooks
|
||||
import useChart from "./useChart";
|
||||
import useChart from './useChart';
|
||||
|
||||
const props = defineProps({
|
||||
className: {
|
||||
type: String,
|
||||
default: "",
|
||||
default: '',
|
||||
},
|
||||
style: {
|
||||
type: Object,
|
||||
@@ -24,3 +21,7 @@ const props = defineProps({
|
||||
|
||||
const { container } = useChart(Column, props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="className" :style="style" ref="container"></div>
|
||||
</template>
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
<template>
|
||||
<div :class="className" :style="style" ref="container"></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { Line } from '@antv/g2plot';
|
||||
|
||||
import { Line } from "@antv/g2plot";
|
||||
// hooks
|
||||
import useChart from "./useChart";
|
||||
import useChart from './useChart';
|
||||
|
||||
const props = defineProps({
|
||||
className: {
|
||||
type: String,
|
||||
default: "",
|
||||
default: '',
|
||||
},
|
||||
style: {
|
||||
type: Object,
|
||||
@@ -25,3 +21,7 @@ const props = defineProps({
|
||||
|
||||
const { container } = useChart(Line, props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="className" :style="style" ref="container"></div>
|
||||
</template>
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
<template>
|
||||
<div :class="className" :style="style" ref="container"></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { Pie } from "@antv/g2plot";
|
||||
import { Pie } from '@antv/g2plot';
|
||||
|
||||
// hooks
|
||||
import useChart from "./useChart";
|
||||
import useChart from './useChart';
|
||||
|
||||
const props = defineProps({
|
||||
className: {
|
||||
type: String,
|
||||
default: "",
|
||||
default: '',
|
||||
},
|
||||
style: {
|
||||
type: Object,
|
||||
@@ -24,3 +21,7 @@ const props = defineProps({
|
||||
|
||||
const { container } = useChart(Pie, props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div :class="className" :style="style" ref="container"></div>
|
||||
</template>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { cloneDeep } from "lodash-es";
|
||||
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
export default function useChart(ChartClass, props) {
|
||||
const chart = ref(null); // 表格实例
|
||||
@@ -35,12 +36,12 @@ export default function useChart(ChartClass, props) {
|
||||
onEvent(chartInstance, event);
|
||||
}
|
||||
};
|
||||
chartInstance.on("*", handler);
|
||||
chartInstance.on('*', handler);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
chart.value.destroy();
|
||||
chart.value.off("*", handler);
|
||||
chart.value.off('*', handler);
|
||||
chart.value = undefined;
|
||||
});
|
||||
|
||||
@@ -54,32 +55,32 @@ export default function useChart(ChartClass, props) {
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const toDataURL = (type = "image/png", encoderOptions) => {
|
||||
const toDataURL = (type = 'image/png', encoderOptions) => {
|
||||
return chart.value?.chart.canvas.cfg.el.toDataURL(type, encoderOptions);
|
||||
};
|
||||
|
||||
const downloadImage = (
|
||||
name = "download",
|
||||
type = "image/png",
|
||||
encoderOptions
|
||||
name = 'download',
|
||||
type = 'image/png',
|
||||
encoderOptions,
|
||||
) => {
|
||||
let imageName = name;
|
||||
if (name.indexOf(".") === -1) {
|
||||
imageName = `${name}.${type.split("/")[1]}`;
|
||||
if (!name.includes('.')) {
|
||||
imageName = `${name}.${type.split('/')[1]}`;
|
||||
}
|
||||
const base64 = chart.value?.chart.canvas.cfg.el.toDataURL(
|
||||
type,
|
||||
encoderOptions
|
||||
encoderOptions,
|
||||
);
|
||||
let a = document.createElement("a");
|
||||
let a = document.createElement('a');
|
||||
a.href = base64;
|
||||
a.download = imageName;
|
||||
document.body.appendChild(a);
|
||||
document.body.append(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
a.remove();
|
||||
a = null;
|
||||
return imageName;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user