web: Support export csv

This commit is contained in:
qianmoQ 2022-10-05 12:32:39 +08:00
parent badc6bd57e
commit c93da24ebd
2 changed files with 42 additions and 7 deletions

View File

@ -16,6 +16,7 @@
"ant-design-vue": "^3.2.12", "ant-design-vue": "^3.2.12",
"axios": "^0.27.2", "axios": "^0.27.2",
"core-js": "^3.8.3", "core-js": "^3.8.3",
"export-to-csv": "^0.2.1",
"monaco-editor-vue3": "^0.1.6", "monaco-editor-vue3": "^0.1.6",
"monaco-editor-webpack-plugin": "^7.0.1", "monaco-editor-webpack-plugin": "^7.0.1",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",

View File

@ -64,6 +64,21 @@
</div> </div>
<div style="margin-top: 5px;"> <div style="margin-top: 5px;">
<a-card :loading="tableLoading" :body-style="{padding: '2px'}"> <a-card :loading="tableLoading" :body-style="{padding: '2px'}">
<div v-if="tableConfigure.data" style="margin-bottom: 3px;">
<a-dropdown>
<template #overlay>
<a-menu @click="handlerExport()">
<a-menu-item key="export_csv">
CSV
</a-menu-item>
</a-menu>
</template>
<a-button type="primary" size="small">
Export
<DownloadOutlined />
</a-button>
</a-dropdown>
</div>
<SheetComponent :dataCfg="tableConfigure" :options="tableOptions" :showPagination="true" sheetType="table" /> <SheetComponent :dataCfg="tableConfigure" :options="tableOptions" :showPagination="true" sheetType="table" />
</a-card> </a-card>
</div> </div>
@ -81,6 +96,7 @@ import "@antv/s2-vue/dist/style.min.css";
import { message } from "ant-design-vue"; import { message } from "ant-design-vue";
import "ant-design-vue/dist/antd.css"; import "ant-design-vue/dist/antd.css";
import axios, { CancelTokenSource } from "axios"; import axios, { CancelTokenSource } from "axios";
import { ExportToCsv } from 'export-to-csv';
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
import MonacoEditor from 'monaco-editor-vue3'; import MonacoEditor from 'monaco-editor-vue3';
import { defineComponent } from "vue"; import { defineComponent } from "vue";
@ -88,11 +104,17 @@ import { defineComponent } from "vue";
export default defineComponent({ export default defineComponent({
name: "DashboardConsoleView", name: "DashboardConsoleView",
components: { SheetComponent, SourceSelectComponent, MonacoEditor }, components: { SheetComponent, SourceSelectComponent, MonacoEditor },
unmounted() {
if (this.editorCompletionProvider) {
this.editorCompletionProvider.dispose();
}
},
data() { data() {
return { return {
applySource: null || '', applySource: null || '',
tableConfigure: {}, tableConfigure: {},
tableOptions: {}, tableOptions: {},
tableColumns: [],
tableLoading: false, tableLoading: false,
editorValue: '', editorValue: '',
cancelToken: {} as CancelTokenSource, cancelToken: {} as CancelTokenSource,
@ -101,11 +123,6 @@ export default defineComponent({
editorCompletionProvider: {} as monaco.IDisposable editorCompletionProvider: {} as monaco.IDisposable
} }
}, },
unmounted() {
if (this.editorCompletionProvider) {
this.editorCompletionProvider.dispose();
}
},
methods: { methods: {
handlerEditorDidMount(editor: any) { handlerEditorDidMount(editor: any) {
const suggestions = new LanguageService().transSuggestions([]); const suggestions = new LanguageService().transSuggestions([]);
@ -137,6 +154,7 @@ export default defineComponent({
.then((response) => { .then((response) => {
if (response.status) { if (response.status) {
this.response = response; this.response = response;
this.tableColumns = response.data.columns;
this.tableConfigure = { this.tableConfigure = {
fields: { fields: {
columns: response.data.headers columns: response.data.headers
@ -156,9 +174,10 @@ export default defineComponent({
else { else {
message.error(response.message); message.error(response.message);
} }
}).finally(() => {
this.tableLoading = false;
}) })
.finally(() => {
this.tableLoading = false;
});
}, },
handlerChangeValue(value: string) { handlerChangeValue(value: string) {
this.applySource = value; this.applySource = value;
@ -180,6 +199,21 @@ export default defineComponent({
}, },
handlerCancel() { handlerCancel() {
this.cancelToken.cancel("Cancel query"); this.cancelToken.cancel("Cancel query");
},
handlerExport() {
const options = {
fieldSeparator: ',',
quoteStrings: '',
decimalSeparator: '.',
showLabels: true,
showTitle: false,
useTextFile: false,
useBom: true,
filename: Date.parse(new Date().toString()).toString(),
useKeysAsHeaders: true
};
const csvExporter = new ExportToCsv(options);
csvExporter.generateCsv(this.tableColumns);
} }
} }
}); });