This commit is contained in:
xds
2025-10-27 16:55:27 +03:00
parent c5baeb8155
commit 99890102ef
2 changed files with 27 additions and 3 deletions

View File

@@ -13,6 +13,7 @@
}, },
"dependencies": { "dependencies": {
"@amirafa/vue3-pull-to-refresh": "^1.2.13", "@amirafa/vue3-pull-to-refresh": "^1.2.13",
"@grammyjs/web-app": "^1.3.0",
"@primevue/themes": "^4.4.1", "@primevue/themes": "^4.4.1",
"@tailwindcss/postcss": "^4.1.16", "@tailwindcss/postcss": "^4.1.16",
"@tailwindcss/vite": "^4.1.16", "@tailwindcss/vite": "^4.1.16",

View File

@@ -1,14 +1,37 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, computed } from "vue"
import { WebApp } from "@grammyjs/web-app"
import router from "@/router"; // если используешь другой SDK, импорт может отличаться
// необязательно делать реактивным, но удобно для шаблона
const tgData = ref(WebApp.initDataUnsafe)
const tgApp = window.Telegram.WebApp // какие-то удобные вычисления для UI
const userId = computed(() => tgData.value?.user?.id?.toString() ?? "")
const username = computed(() => tgData.value?.user?.username ?? "")
const firstName = computed(() => tgData.value?.user?.first_name ?? "")
onMounted(() => {
// сообщаем Telegram WebApp, что UI готов
WebApp.ready()
// если есть данные пользователя — положим что-то в localStorage
if (tgData.value?.user?.id != null) {
localStorage.setItem("token", tgData.value.user.id.toString())
} else {
localStorage.setItem("token", "123")
}
router.push('/')
})
</script> </script>
<template> <template>
{{tgApp}} <div class="p-4">
<p>Telegram user id: {{ userId || "—" }}</p>
<p>Username: {{ username || "—" }}</p>
<p>First name: {{ firstName || "—" }}</p>
</div>
</template> </template>
<style scoped> <style scoped>
</style> </style>