From 03b14a0fb57c4dceb49bc0e22ebe70a4d4f0e18d Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:04:40 +0800 Subject: [PATCH 1/2] fix(build): wrap top-level await in async function for browser compatibility --- src/main.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.ts b/src/main.ts index 6e08386e..1c56d316 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,12 +33,14 @@ import { fetchGlobalSettings } from './api' // 创建Vue实例 const app = createApp(App) -try { - const globalSettings = await fetchGlobalSettings() - // 使用 provide 传递全局设置 - app.provide('globalSettings', globalSettings) -} catch (error) { - console.error('Failed to initialize app', error) +async function initializeApp() { + try { + const globalSettings = await fetchGlobalSettings() + // 使用 provide 传递全局设置 + app.provide('globalSettings', globalSettings) + } catch (error) { + console.error('Failed to initialize app', error) + } } // 注册全局组件 From 634522d27b0b71a941e7218b74dfbbe4ba74c854 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:18:37 +0800 Subject: [PATCH 2/2] fix(build): ensure app is mounted after global settings are loaded --- src/main.ts | 90 +++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1c56d316..d717a03e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,49 +44,51 @@ async function initializeApp() { } // 注册全局组件 -app - .component('VAceEditor', VAceEditor) - .component('VApexChart', VueApexCharts) - .component('VDialogCloseBtn', DialogCloseBtn) - .component('VMediaCard', MediaCard) - .component('VPosterCard', PosterCard) - .component('VBackdropCard', BackdropCard) - .component('VPersonCard', PersonCard) - .component('VMediaInfoCard', MediaInfoCard) - .component('VTorrentCard', TorrentCard) - .component('VMediaIdSelector', MediaIdSelector) - .component('VTreeview', VTreeview) - .component('VPathField', PathField) +initializeApp().then(() => { + app + .component('VAceEditor', VAceEditor) + .component('VApexChart', VueApexCharts) + .component('VDialogCloseBtn', DialogCloseBtn) + .component('VMediaCard', MediaCard) + .component('VPosterCard', PosterCard) + .component('VBackdropCard', BackdropCard) + .component('VPersonCard', PersonCard) + .component('VMediaInfoCard', MediaInfoCard) + .component('VTorrentCard', TorrentCard) + .component('VMediaIdSelector', MediaIdSelector) + .component('VTreeview', VTreeview) + .component('VPathField', PathField) -// 注册插件 -app - .use(vuetify) - .use(router) - .use(store) - .use(ToastPlugin, { - position: 'bottom-right', - }) - .use(VuetifyUseDialog, { - confirmDialog: { - dialogProps: { - maxWidth: '40rem', + // 注册插件 + app + .use(vuetify) + .use(router) + .use(store) + .use(ToastPlugin, { + position: 'bottom-right', + }) + .use(VuetifyUseDialog, { + confirmDialog: { + dialogProps: { + maxWidth: '40rem', + }, + confirmationButtonProps: { + variant: 'elevated', + color: 'primary', + class: 'me-3 px-5', + 'prepend-icon': 'mdi-check', + }, + cancellationButtonProps: { + variant: 'outlined', + color: 'secondary', + class: 'me-3', + }, + confirmationText: '确认', + cancellationText: '取消', }, - confirmationButtonProps: { - variant: 'elevated', - color: 'primary', - class: 'me-3 px-5', - 'prepend-icon': 'mdi-check', - }, - cancellationButtonProps: { - variant: 'outlined', - color: 'secondary', - class: 'me-3', - }, - confirmationText: '确认', - cancellationText: '取消', - }, - }) - .use(PerfectScrollbarPlugin) - .use(VueApexCharts) - .mount('#app') - .$nextTick(() => removeEl('#loading-bg')) + }) + .use(PerfectScrollbarPlugin) + .use(VueApexCharts) + .mount('#app') + .$nextTick(() => removeEl('#loading-bg')) +})