feat: add telegram mini app (#250)

This commit is contained in:
Dream Hunter
2024-05-19 00:35:10 +08:00
committed by GitHub
parent 46576316e6
commit 870b7b9198
12 changed files with 234 additions and 8 deletions
+21 -1
View File
@@ -8,7 +8,10 @@ import Header from './views/Header.vue';
import Footer from './views/Footer.vue';
const { localeCache, isDark, loading, useSideMargin } = useGlobalState()
const {
localeCache, isDark, loading, useSideMargin,
telegramApp, isTelegram
} = useGlobalState()
const theme = computed(() => isDark.value ? darkTheme : null)
const localeConfig = computed(() => localeCache.value == 'zh' ? zhCN : null)
const isMobile = useIsMobile()
@@ -31,6 +34,23 @@ onMounted(async () => {
document.body.appendChild(script);
}
// check if telegram is enabled
const enableTelegram = import.meta.env.VITE_IS_TELEGRAM;
if (
(typeof enableTelegram === 'boolean' && enableTelegram === true)
||
(typeof enableTelegram === 'string' && enableTelegram === 'true')
) {
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://telegram.org/js/telegram-web-app.js';
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
telegramApp.value = window.Telegram?.WebApp || {};
isTelegram.value = !!window.Telegram?.WebApp?.initData;
}
});
</script>