Dynamically import exceljs
parent
0a2f51d44d
commit
b11a61f451
|
@ -1,4 +1,3 @@
|
||||||
import { Workbook } from 'exceljs';
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { banners } from '../data/banners';
|
import { banners } from '../data/banners';
|
||||||
|
@ -7,6 +6,8 @@ import { bannersDual } from '../data/bannersDual';
|
||||||
import { getTimeOffset } from '../stores/server';
|
import { getTimeOffset } from '../stores/server';
|
||||||
import { process } from './wish';
|
import { process } from './wish';
|
||||||
|
|
||||||
|
let Workbook;
|
||||||
|
|
||||||
const bannerCategories = {
|
const bannerCategories = {
|
||||||
'character-event': 'Character Event',
|
'character-event': 'Character Event',
|
||||||
'weapon-event': 'Weapon Event',
|
'weapon-event': 'Weapon Event',
|
||||||
|
@ -14,7 +15,9 @@ const bannerCategories = {
|
||||||
beginners: "Beginners' Wish",
|
beginners: "Beginners' Wish",
|
||||||
};
|
};
|
||||||
|
|
||||||
function createWorkbook() {
|
async function createWorkbook() {
|
||||||
|
Workbook = (await import('exceljs')).Workbook;
|
||||||
|
|
||||||
const workbook = new Workbook();
|
const workbook = new Workbook();
|
||||||
workbook.creator = 'Paimon.moe';
|
workbook.creator = 'Paimon.moe';
|
||||||
workbook.created = new Date();
|
workbook.created = new Date();
|
||||||
|
@ -223,7 +226,7 @@ async function downloadFile(workbook) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function exportToExcel() {
|
export async function exportToExcel() {
|
||||||
const workbook = createWorkbook();
|
const workbook = await createWorkbook();
|
||||||
|
|
||||||
addSheet(workbook);
|
addSheet(workbook);
|
||||||
await addBanners(workbook);
|
await addBanners(workbook);
|
||||||
|
|
|
@ -8,16 +8,16 @@
|
||||||
|
|
||||||
import { exportToExcel } from '../../functions/export';
|
import { exportToExcel } from '../../functions/export';
|
||||||
import { pushToast } from '../../stores/toast';
|
import { pushToast } from '../../stores/toast';
|
||||||
import ExcelImportModal from './_excelImport.svelte';
|
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
|
|
||||||
const { open: openModal, close: closeModal } = getContext('simple-modal');
|
const { open: openModal } = getContext('simple-modal');
|
||||||
|
|
||||||
export let setManualInput;
|
export let setManualInput;
|
||||||
export let settings;
|
export let settings;
|
||||||
export let closeImportModal;
|
export let closeImportModal;
|
||||||
|
|
||||||
let loadingExport = false;
|
let loadingExport = false;
|
||||||
|
let loadingImport = false;
|
||||||
|
|
||||||
let enableManual = settings.manualInput;
|
let enableManual = settings.manualInput;
|
||||||
|
|
||||||
|
@ -32,9 +32,13 @@
|
||||||
pushToast($t('wish.help.exportFinish'));
|
pushToast($t('wish.help.exportFinish'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function openImporter() {
|
async function openImporter() {
|
||||||
|
loadingImport = true;
|
||||||
|
const modal = await import('./_excelImport.svelte');
|
||||||
|
loadingImport = false;
|
||||||
|
|
||||||
openModal(
|
openModal(
|
||||||
ExcelImportModal,
|
modal.default,
|
||||||
{
|
{
|
||||||
closeModal: closeImportModal,
|
closeModal: closeImportModal,
|
||||||
},
|
},
|
||||||
|
@ -52,13 +56,18 @@
|
||||||
<h1 class="font-display text-white text-xl mb-2">{$t('wish.help.exportTitle')}</h1>
|
<h1 class="font-display text-white text-xl mb-2">{$t('wish.help.exportTitle')}</h1>
|
||||||
<div class="text-white p-2 bg-background rounded-xl">
|
<div class="text-white p-2 bg-background rounded-xl">
|
||||||
<p class="mb-2">{$t('wish.help.exportMessage')}</p>
|
<p class="mb-2">{$t('wish.help.exportMessage')}</p>
|
||||||
<Button className="mr-2" disabled={loadingExport} on:click={exportFile}>
|
<Button className="mr-2" disabled={loadingExport || loadingImport} on:click={exportFile}>
|
||||||
{#if loadingExport}
|
{#if loadingExport}
|
||||||
<Icon path={mdiLoading} spin size={0.8} className="mr-2" />
|
<Icon path={mdiLoading} spin size={0.8} className="mr-2" />
|
||||||
{/if}
|
{/if}
|
||||||
{$t(loadingExport ? 'wish.help.exporting' : 'wish.help.export')}
|
{$t(loadingExport ? 'wish.help.exporting' : 'wish.help.export')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button disabled={loadingExport} on:click={openImporter}>{$t('wish.help.import')}</Button>
|
<Button disabled={loadingExport || loadingImport} on:click={openImporter}>
|
||||||
|
{#if loadingImport}
|
||||||
|
<Icon path={mdiLoading} spin size={0.8} className="mr-2" />
|
||||||
|
{/if}
|
||||||
|
{$t('wish.help.import')}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<h1 class="font-display text-white text-xl mt-8 mb-2">{$t('wish.help.manualTitle')}</h1>
|
<h1 class="font-display text-white text-xl mt-8 mb-2">{$t('wish.help.manualTitle')}</h1>
|
||||||
<div class="text-white p-2 bg-background rounded-xl">
|
<div class="text-white p-2 bg-background rounded-xl">
|
||||||
|
|
Loading…
Reference in New Issue