mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 09:03:58 +00:00
save PNG chart preview
This commit is contained in:
@@ -118,10 +118,19 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
exportChart_meta: 'post',
|
exportChart_meta: 'post',
|
||||||
async exportChart({ title, config }) {
|
async exportChart({ title, config, image }) {
|
||||||
const html = getChartExport(title, config);
|
|
||||||
const fileName = `${uuidv1()}.html`;
|
const fileName = `${uuidv1()}.html`;
|
||||||
|
const imageFile = `${fileName}.png`;
|
||||||
|
const html = getChartExport(title, config, imageFile);
|
||||||
await fs.writeFile(path.join(uploadsdir(), fileName), html);
|
await fs.writeFile(path.join(uploadsdir(), fileName), html);
|
||||||
|
if (image) {
|
||||||
|
const index = image.indexOf('base64,');
|
||||||
|
if (index > 0) {
|
||||||
|
const data = image.substr(index + 'base64,'.length);
|
||||||
|
const buf = Buffer.from(data, 'base64');
|
||||||
|
await fs.writeFile(path.join(uploadsdir(), imageFile), buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
return fileName;
|
return fileName;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const getChartExport = (title, config) => {
|
const getChartExport = (title, config, imageFile) => {
|
||||||
return `<html>
|
return `<html>
|
||||||
<meta charset='utf-8'>
|
<meta charset='utf-8'>
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ const getChartExport = (title, config) => {
|
|||||||
</html>
|
</html>
|
||||||
|
|
||||||
<body onload="showChart()">
|
<body onload="showChart()">
|
||||||
<img src="img1.png" id="myImage" />
|
<img src="${imageFile}" id="myImage" />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<canvas id="myChart"></canvas>
|
<canvas id="myChart"></canvas>
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
data,
|
data,
|
||||||
options,
|
options,
|
||||||
},
|
},
|
||||||
|
image: domChart.toDataURL(),
|
||||||
});
|
});
|
||||||
|
|
||||||
window.open(`${resolveApi()}/uploads/get?file=${resp.data}`, '_blank');
|
window.open(`${resolveApi()}/uploads/get?file=${resp.data}`, '_blank');
|
||||||
|
|||||||
Reference in New Issue
Block a user