芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.sksb.smartcon-survey.com/resources/js/app.js
import { Chart } from "chart.js/auto"; import ChartDataLabels from "chartjs-plugin-datalabels"; window.Chart = Chart; window.ChartDataLabels = ChartDataLabels; window.Pikaday = require("pikaday"); window.moment = require("moment"); window.html2canvas = require("html2canvas"); window.JSZip = require("jszip"); window.fileSave = require("file-saver"); window.captureChart = function (topicID, containerId, fileName, chartData) { document.querySelector("#download-icon").style.display = "none"; document.querySelector("#spinner").style.display = "initial"; const zip = new JSZip(); chartData = JSON.parse(chartData); const screenshotTarget = document.getElementById(containerId); html2canvas(screenshotTarget) .then(async (canvas) => { const img = canvas.toDataURL(); const token = document.head.querySelector( 'meta[name="csrf-token"]' ).content; const requestData = { topicId: topicID, filters: chartData }; let excel; await fetch("/dashboard/download", { method: "POST", headers: { "Content-Type": "application/json", "X-CSRF-TOKEN": token, }, body: JSON.stringify(requestData), }) .then((response) => response.blob()) .then((data) => { excel = data; }); zip.file(fileName + " chart.png", atob(img.split(",")[1]), { binary: true, }); zip.file(fileName + " daten.xlsx", excel, { binary: true }); zip.generateAsync({ type: "blob" }).then(function (fileBlob) { fileSave.saveAs(fileBlob, fileName + " gesamt-index daten"); }); }) .finally(() => { document.querySelector("#download-icon").style.display = "initial"; document.querySelector("#spinner").style.display = "none"; }); }; window.chartData2CSV = function (data) { let results = ""; data.labels.forEach(function (label) { results += label + ";"; }); results += "\n"; data.values.forEach(function (lable) { results += lable + ";"; }); return results; };